7 replies [Last post]
krunar's picture
Offline
Joined: 02/03/2008
Juice: 54
Was this information Helpful?

im sure that this is something simple and probably already posted but i can not find it.
1. i want to replace the "add to cart' text with a cart image.
in my custom node i have
<?php print $node->content['add_to_cart']["#value"] ?>
how do i replace this with an image?

2. is it possible when one product is already in cart to replace the 'add to cart' text with something like 'already in cart' link that will point to the cart view?

thank you very much

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Add to cart image and text when product already in cart

In your custom node you'd have to call hook_form_alter and have it look for that form's form_id. Then you would say:

<?php
$node
->content['add_to_cart']['#value'] = ...
?>

followed by however you want to control it - form button or cart link.

2. You can do, I'm not sure the easiest way but I did it with my Content Template. Here's how I did it:

<?php
$cartitems
= uc_cart_get_contents();

$allNids = array();

foreach(

$cartitems as $cartitem) {
     
$allNids[]=$cartitem->nid; // Probably an easier way to do this.
   
}

if(

in_array($node->nid, $allNids)) {       

?>

<img src="/<?php echo path_to_theme(); ?>/images/in-your-cart.jpg" border="0">

<?php } else { ?>

<a href="/cart/add">[ADD TO CART]</a>

<?php } ?>

So it basically cycles through the nids in your cart, and if the nid of the product you're looking at is found in your cart's content nids array, then it displays the "already in your cart" image and disables the add to cart functionality (which I have done here using Cart Links).

--
Help directly fund development: Donate via PayPal!

krunar's picture
Offline
Joined: 02/03/2008
Juice: 54
Re: Re: Add to cart image and text when product already in cart

First of all thank you very much for trying to help me.
For case 1, unfortunately i haven't understand much Sad
I will try to look around for hook_form_alter but if you have an example please post it
For case 2...well, lets first understand 1 and then we will see Smiling

and again, thank you very much

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
krunar wrote: I will try to
krunar wrote:

I will try to look around for hook_form_alter but if you have an example please post it

http://www.ubercart.org/faq

<tr>.
krunar's picture
Offline
Joined: 02/03/2008
Juice: 54
Re: krunar wrote: I will try to

erm...it was there all the time? i feel ashame Sad

thank you Smiling

memenoje's picture
Offline
Joined: 02/11/2010
Juice: 0
Re: Re: Add to cart image and text when product already in cart

2. Your code is very good, but it is not works, when two users add to cart one product at the same time. Both can add product (there is only 1 in the stock).
in-your-cart.jpg displays only always only to one user but no displays for other users.

Is any idea for displaing image for others users, when one user add product to cart ?

Thank you.

primal's picture
Offline
Joined: 08/21/2008
Juice: 39
1. i want to replace the
1. i want to replace the "add to cart' text with a cart image.
in my custom node i have
<?php print $node->content['add_to_cart']["#value"] ?>
how do i replace this with an image?

I'm trying to figure out the same thing. I read about the hook_form_alter thingy, and I still cannot figure it out. All I want to do is replace the Add to cart with an image.

I really wish Ubercart was more theme-able, but so far I'm finding that some serious PHP and core hacks are necessary to get Ubercart to do what you want. Not very Drupal friendly!

Adam Hegi
Primal Media

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: 1. i want to replace the

fwiw, having images for buttons is a Drupal core issue. We know we have our faults for theming, but this isn't one of them. Eye-wink You can search d.o for several different examples on how to turn buttons into images, but overriding theme elements will always require some PHP somewhere.