12 replies [Last post]
dave80's picture
Offline
Joined: 02/12/2009
Juice: 11
Was this information Helpful?
/**
* Implementation of hook_form_alter().
*/

function MODULE_form_alter(&$form, $form_state, $form_id) {

$form_nid = $form['nid']['#value'];

if ($form_id == 'uc_product_add_to_cart_form_'.$form_nid) {
 
  global $theme;

  $form['submit'] = array(
'#type' => 'image_button',
'#value' => t('Add to Cart'),
'#src' => drupal_get_path('theme', $theme).'/images/submit.gif',
  );

}
}

Anand yrh's picture
Offline
Joined: 03/06/2009
Juice: 315
Re: Add to cart button to image

Because i am new to this please say me where to add this code to change the Add to cart button?

drupalmind's picture
Offline
Joined: 01/06/2009
Juice: 46
Re: Re: Add to cart button to image

possibly, Add this code to your theme's template file
or in uc_product.module file

splash112@drupal.org's picture
Offline
Joined: 03/31/2008
Juice: 413
Re: Re: Re: Add to cart button to image

This kinds of function should imho be in a new module. I always employ a extremely small module for functions like these. If you add/change code in a core file, you changes will be lost every time you update to a new version. So absolutely not in any core (uc_product) or theme file (if possible, Drupal 5 CSS is a small exeption?).

Added a small example (but not tested, I think the hook_form_alter is drupal 6 and my module file was intended for drupal 5, so you might need to check)

AttachmentSize
dinilu.zip 699 bytes
drupalmind's picture
Offline
Joined: 01/06/2009
Juice: 46
Re: Re: Add to cart button to image
parrottvision's picture
Offline
Joined: 03/02/2009
Juice: 33
Re: Add to cart button to image

I tried the change one for all but didn't work. Changed MODULE to phptemplate and tried the name of my theme and no joy. Is it UC1 or UC2?

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15450
Re: Re: Add to cart button to image
parrottvision's picture
Offline
Joined: 03/02/2009
Juice: 33
Re: Re: Re: Add to cart button to image

I didn't see that - but that is very cool. Will have a look. I did it with CSS in the end but may change back.

http://mydrupalblog.lhmdesign.com/theming-search-submit-button-css-cross...

dave80's picture
Offline
Joined: 02/12/2009
Juice: 11
Re: Re: Re: Add to cart button to image

That module http://www.ubercart.org/contrib/9512 (uc_imgsubmit)
looks exactly the same as the code i pasted above in feb09, the uc_imgsubmit module was uploaded
march09. Smiling

Anyhow use uc_imgsubmit, if u want it quickly installed.
I would normaly create one specific module, called themes and edits. etc.
Where i would dump little form and node alters like this one, inside of, instead of having so many little modules.

Anand yrh's picture
Offline
Joined: 03/06/2009
Juice: 315
Re: Add to cart button to image

I tried using the below code it did not work for me, Is that because i am using Ubercart 2.0-beta5?

/**
* Implementation of hook_form_alter().
*/

function MODULE_form_alter(&$form, $form_state, $form_id) {

$form_nid = $form['nid']['#value'];

if ($form_id == 'uc_product_add_to_cart_form_'.$form_nid) {
 
  global $theme;

  $form['submit'] = array(
'#type' => 'image_button',
'#value' => t('Add to Cart'),
'#src' => drupal_get_path('theme', $theme).'/images/submit.gif',
  );

}
}

splash112@drupal.org's picture
Offline
Joined: 03/31/2008
Juice: 413
@Anand yrh Yes, you are

@Anand yrh

Yes, you are right. The api for hook_form_alter() changed from 5.x to 6.x.

Anand yrh's picture
Offline
Joined: 03/06/2009
Juice: 315
It got fixed! Chick this out

It got fixed!

Chick this out http://www.ubercart.org/contrib/9512

make-online-shop's picture
Offline
Joined: 01/01/2011
Juice: 356
Modify Ubercart BUY THIS button

Hello,

I managed to change ADD TO CART button image thanks to this:

http://www.primalmedia.com/blog/how-to-replace-the-add-to-cart-button-wi...

But I would also like to put this button (or a second one) on top of the product page, could you tell me how to do ?

Thanks a lot.