Add to cart image and text when product already in cart

Posts: 18
Joined: 02/03/2008

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

Posts: 1290
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

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).

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 18
Joined: 02/03/2008

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

Posts: 924
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

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>.

Posts: 18
Joined: 02/03/2008

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

thank you Smiling

Posts: 11
Joined: 08/21/2008

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

Posts: 5245
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

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.