3 replies [Last post]
plainprogrammer's picture
Offline
Not Kulvik
Joined: 03/05/2008
Juice: 29
Was this information Helpful?

I am attempting to theme the 'Continue Shopping,' 'Update Cart' and 'Checkout' buttons and having a problem. The buttons are showing up as images now, but they are not triggering the right actions on submit. I modified the uc_imgsubmit module to do the following:

<?php

/**
* @file
* Replaces the default Add to Cart button with an image button
* @author Will Vincent (tcindie) <tcindie at gmail dot com>
*/

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

function uc_imgsubmit_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('module', 'uc_imgsubmit').'/images/addtocartbutton.gif',
      '#attributes' => array(
        'class' => 'node-add-to-cart'
      )
    );
  }
 
  if ($form_id == 'uc_cart_view_form') {
    global $theme;
   
    $form['continue_shopping']['#type'] = 'image_button';
    $form['continue_shopping']['#src'] = drupal_get_path('module', 'uc_imgsubmit') .'/images/continue-shopping.gif';
    $form['continue_shopping']['#attributes']['op'] = 'Continue shopping';
   
    $form['update']['#type'] = 'image_button';
    $form['update']['#src'] = drupal_get_path('module', 'uc_imgsubmit') .'/images/update-cart.gif';
    $form['update']['#attributes']['op'] = 'Update cart';
   
    $form['checkout']['#type'] = 'image_button';
    $form['checkout']['#src'] = drupal_get_path('module', 'uc_imgsubmit') .'/images/check-out.gif';
    $form['checkout']['#attributes']['op'] = 'Checkout';
  }
 
  if ($form_id == 'uc_cart_pane_quotes') {
    global $theme;
   
    $form['get_quote']['#type'] = 'image_button';
    $form['get_quote']['#src'] = drupal_get_path('module', 'uc_imgsubmit') .'/images/calculate-shipping.gif';
  }
}

The quotes tweak works, and in general the update cart one works. But Continue Shopping and Checkout just bring you back to the cart. It looked to me like the submit action is checking for an 'op' attribute, so I attempted to add those to trigger the right actions, but to no avail. Help!?

"Even if I knew that tomorrow the world would go to pieces, I would still plant my apple tree."
-Martin Luther

stephthegeek's picture
Offline
Theminator
Joined: 10/20/2007
Juice: 575
Re: Problem Theming Cart Buttons

You can also target buttons with CSS to add the style as a background image instead of replacing them with an image submit. Much more straightforward and less prone to issues.

Gorgeous original Drupal themes (and Ubercart themes!) ~ Psst: more Ubercart themes on our new site

plainprogrammer's picture
Offline
Not Kulvik
Joined: 03/05/2008
Juice: 29
Re: Re: Problem Theming Cart Buttons

That is the route I will have to go down on this project because of the deadline. However, I do not believe this is an odd scenario and it should probably be supported to have image buttons supported.

"Even if I knew that tomorrow the world would go to pieces, I would still plant my apple tree."
-Martin Luther

stephthegeek's picture
Offline
Theminator
Joined: 10/20/2007
Juice: 575
Re: Re: Re: Problem Theming Cart Buttons

I guess I'm saying there's no real reason to use an image submit when you can do the exact same thing in CSS. That's the preferred way.

Gorgeous original Drupal themes (and Ubercart themes!) ~ Psst: more Ubercart themes on our new site