This is an easy-to-use Drupal module to replace Ubercart's "Add to Cart" submit button with a custom image based on this Ubercart support post.
Initially I had tried to do this with just CSS, but I could not make it work in IE.
A big shout out to Vince Rowe for providing a workable solution that we could turn into a module, and to Andy over at the Proof Group for helping me with this module.
That's it. Alll your Ubercart "Add to Cart" buttons should now be replaced by the custom image you put in the uc_gfxbtn folder.
This Drupal / Ubercart module has been tested across platforms and the major browsers (Internet Explorer, Firefox, Safari).
I hope this makes your Ubercart experience easier. I look forward to hearing any feedback or improvements on this module.
This is Primal Speak, a blog by Primal Media about web design, SEO, Drupal CMS and marketing trends.
Comments
I agree it would be great to see this for Drupal6. I tried to get it there. A couple of things I know about are:
1) "core = 6.x" needs to be added to uc_gfxbtn.info
2) $form['#base'] has been depreciated in D6. But this replacement should work:
Replace: if($form['#base'] == 'uc_product_add_to_cart_form'){
With: if( $form_id['#validate'][0] == 'uc_product_add_to_cart_form_validate' && $form_id['#submit'][0] == 'uc_product_add_to_cart_form_submit'){
3) But after these changes the module was still not working in D6. I was not able to get it past this. I suspect it has something to do with using $form[] instead of $form_id[]. I also don't know the variable $form['submit_image']. I typically have only seen $form['submit'] variables before. But obviously there is a lot I don't know. Just trying to give food for thought if anyone else wants to step up to the plate.
Thanks, maestrojed
function uc_gfxbtn_form_alter($form_id, &$form) {
if( $form_id['#validate'][0] == 'uc_product_add_to_cart_form_validate' && $form_id['#submit'][0] == 'uc_product_add_to_cart_form_submit'){
$form_id['submit']['#type'] = 'hidden';
// strip '?submit_x=15&submit_y=27' from $_POST
if (isset($_POST['submit_x'])) {
$form_id['submit'] = array(
'#type' => 'submit',
'#value' => 'submit',
);
}
$form_id['submit_image'] = array(
'#value' => '<input name="submit" type="image" width="98" height="26" class="add_to_cart" title="'. t('Add to Shopping Cart') .'" src="/'. drupal_get_path('module', 'uc_gfxbtn') .
'/button.png">',
);
}
}
here's what I did in the .info
;;$Id$ uc_gfxbtn.info,v 1.2 2009/01/27 14:03:28 longwave Exp $
name = Custom Image As Shopping Button
description = Allow administrators to change the display shopping cart button
dependencies[] = uc_store
dependancies[] = uc_product
dependancies[] = uc_cart
package = Ubercart - payment
core = 6.14
; Information added by drupal.org packaging script on 2009-07-30
version = "6.x-1.4"
core = "6.x"
project = "uc_gfxbtn.info"
datestamp = "1248955928"
and for the .module i used broken egg's code :
function uc_gfxbtn_form_alter($form_id, &$form) {
if( $form_id['#validate'][0] == 'uc_product_add_to_cart_form_validate' && $form_id['#submit'][0] == 'uc_product_add_to_cart_form_submit'){
$form_id['submit']['#type'] = 'hidden';
// strip '?submit_x=15&submit_y=27' from $_POST
if (isset($_POST['submit_x'])) {
$form_id['submit'] = array(
'#type' => 'submit',
'#value' => 'submit',
);
}
$form_id['submit_image'] = array(
'#value' => '<input name="submit" type="image" width="98" height="26" class="add_to_cart" title="'. t('Add to Shopping Cart') .'" src="/'. drupal_get_path('module', 'uc_gfxbtn') .
'/button.png">',
);
}
}
Add a comment