Hi,

i'm using the Ubercart ajax cart module but there's a problem that seems to be theme related. On the product page it works great: ajax pop up message and product gets added to cart. However, on an individual products page, the add to cart button doesn't produce the pop up message but instead reloads page with product added to shopping cart.

I contacted the developers of the module and after some seaching they found out it's theme related:

UC Ajax Cart tries to find Ubercart Add to cart button based on ajax-cart-submit-form class (it's added with a form alter at uc_ajax_cart_alter_cart_form function). In Aqua Prosper, Add to cart buttons from individual product pages do not have this class.

The module locates Add to Cart button with this selector:
form.ajax-cart-submit-form input.ajax-cart-submit-form-button

It works just fine with the Galand theme.

Is there a way i can manually add it? If so, where and how?

Comments

Luki_be’s picture

No takers??

sheena_d’s picture

Luc,

On a fresh install of Acquia prosper, I am getting the same classes on the add-to-cart buttons on the Ubercart catalog pages and on the individual product pages. However, I am not sure what the desired behavior is of Ajax Driven Cart, so I do not know if it is working properly.

The only thing that Fusion does to the add-to-cart button on product pages is to bundle it into a variable on the node template (same as we do with other UC variables) which makes things a bit easier to use. The only bit of code in Fusion that relates to the add-to-cart button is:

$vars['fusion_uc_add_to_cart'] = drupal_render($node->content['add_to_cart']);

Which should not have any adverse effect relating to a class added to that form item by another module.

There is no way to edit the attributes of a form item (such as the classes of the submit button) except by a hook_form_alter function within a module, if that form was built using the Drupal FAPI. I'm not sure how the add-to-cart form is created in Ubercart, but all the rendering of the form items should be completed before that information is passed to the node preprocess function.

Hope this helps.
Sheena

Luki_be’s picture

Here's the class i get on the buttons:

Products page where eveything works:

<input type="submit" name="op" id="edit-submit-3" value="Buy now"  class="form-submit list-add-to-cart ajax-cart-submit-form-button" />

Individual product page:

<input type="submit" name="op" id="edit-submit-57" value="Add to cart"  class="form-submit node-add-to-cart" />

If you want to see it action:

http://www.dzinelabs.com/projects/drupal/products

just click on the buy now button.

And it seems theme related because using the Galand theme, everything works just fine ...

sheena_d’s picture

Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

Luc,

I just realized that there are multiple "ajax cart" modules for Ubercart. Can you be specific as to which module you are using, the version, and the configuration steps necessary to re-create the issue, so that I may test?

Thanks,
Sheena

Luki_be’s picture

My pleasure Sheena,

Module i'm using:
Ubercart ajax cart (http://drupal.org/project/uc_ajax_cart)
version: 6.x-2.0-rc2

Issue with response from developer:
http://drupal.org/node/1210766

Configuration of the module is straight forward but there is an option to assign a special class but that didn't sort any effect for me.

sheena_d’s picture

Status: Postponed (maintainer needs more info) » Active

Thanks, Luc. I'll look into this asap and let you know what I find.

Luki_be’s picture

Awesome,

looking forward to it.

sheena_d’s picture

Luc,

Ok, I took a look at your issue in the Ajax Cart thread, and the information about what actually happens for you on your site would have been very helpful to me earlier :) Everything works fine for me on a clean install of Prosper and Ajax Cart, but the fact that your page is refreshing rather than the modal loading tells me that this is very likely related to an old issue with the Google Analytics module. Are you using that module? Check out this issue: http://drupal.org/node/1057914#comment-4076714

Let me know if that sounds like it could be your issue.

Thanks,
Sheena

Luki_be’s picture

Sheena,

now i'm not using that module. Sorry to bring bad news ;-)

sheena_d’s picture

What do you mean by "now"? Were you using it at one point and are no longer using it? What other modules do you have installed that may be altering the product pages, forms, or using ajax or modal windows?

The fact that I could not replicate this issue on a fresh install of Acquia Prosper and Ubercart suggests that there is something else going on in your site. Have you made any changes or customizations to template.php, node-product.tpl.php or any javascript in your copy of Acquia Prosper?

Luki_be’s picture

'now' should be 'no' ... my mistake

About the modules installed, do you want me to list them all??? I'm not a coder so i don't know what module alters product pages etc...

I did made some customizations to template.php (see http://chalcedony.co.nz/gemsofwisdom/ubercart-2-display-stock-available):

<?php
// $Id: template.php,v 1.5 2010/09/17 21:36:06 eternalistic Exp $

/**
 * Changed breadcrumb separator
 */
function acquia_prosper_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' &rarr; ', $breadcrumb) .'</div>';
  }
}

/**
 *This shows the discount in the catalog. Isn't part of the original template!!!!
 *Display a list of products in grid format().
 *
 * Override theme_uc_catalog_product_grid function from uc_catalog module
 * @ingroup themeable
 */
function phptemplate_uc_catalog_product_grid($products) {
  $product_table = '<div class="category-grid-products"><table>';
  $count = 0;
  $context = array(
    'revision' => 'themed',
    'type' => 'product',
  );
  foreach ($products as $nid) {
    $product = node_load($nid);
    $context['subject'] = array('node' => $product);

    if ($count == 0) {
      $product_table .= "<tr>";
    }
    elseif ($count % variable_get('uc_catalog_grid_display_width', 3) == 0) {
      $product_table .= "</tr><tr>";
    }

    $titlelink = l($product->title, "node/$nid", array('html' => TRUE));
    if (module_exists('imagecache') && ($field = variable_get('uc_image_'. $product->type, '')) && isset($product->$field) && file_exists($product->{$field}[0]['filepath'])) {
      $imagelink = l(theme('imagecache', 'product_list', $product->{$field}[0]['filepath'], $product->title, $product->title), "node/$nid", array('html' => TRUE));
    }
    else {
      $imagelink = '';
    }

    $product_table .= '<td>';
    if (variable_get('uc_catalog_grid_display_title', TRUE)) {
      $product_table .= '<span class="catalog-grid-title">'. $titlelink .'</span>';
    }
    if (variable_get('uc_catalog_grid_display_model', TRUE)) {
      $product_table .= '<span class="catalog-grid-ref">'. $product->model .'</span>';
    }
    $product_table .= '<span class="catalog-grid-image">'. $imagelink .'</span>';
    if (module_exists('uc_discounts')) {
        $discounted_price = theme("get_discounted_price", $product);
        if (!is_null($discounted_price) && $product->sell_price > $discounted_price) {
            if (variable_get('uc_catalog_grid_display_sell_price', TRUE)) {
              $product_table .= '<p class="original-sell-price">'. uc_price($product->sell_price, $context) .'</p>';
            }
            $product_table .= '<span class="field-type-discounted-price">'. theme("product_discounted_price", $product, uc_price($discounted_price, $context)) .'</span>';
            }
            else {
            if (variable_get('uc_catalog_grid_display_sell_price', TRUE)) {
              $product_table .= '<span class="catalog-grid-sell-price">'. uc_price($product->sell_price, $context) .'</span>';
            }
            }
            theme("add_product_price_altering_css", $product);
            theme("add_product_price_altering_javascript", $product);
        }
        else {
           if (variable_get('uc_catalog_grid_display_sell_price', TRUE)) {
             $product_table .= '<span class="catalog-grid-sell-price">'. uc_price($product->sell_price, $context) .'</span>';
           }
        }

    if (module_exists('uc_cart') && variable_get('uc_catalog_grid_display_add_to_cart', TRUE)) {
      if (variable_get('uc_catalog_grid_display_attributes', TRUE)) {
        $product_table .= theme('uc_product_add_to_cart', $product);
      }
      else {
        $product_table .= drupal_get_form('uc_catalog_buy_it_now_form_'. $product->nid, $product);
      }
    }
    $product_table .= '</td>';

    $count++;
  }
  $product_table .= "</tr></table></div>";
  return $product_table;
}

 // ######### BEGIN CUSTOM CODING RELATED TO STOCK DISPLAY *This shows the stock available on the product. Isn't part of the original template!!!!###############



function acquia_prosper_uc_product_add_to_cart( $node ) {
 // REPLACE acquia_prosper with your theme's name
// look up all sku's for this product
  $skus=uc_stock_attribute_uc_product_models($node); 

  if(!empty(
$skus)){  // if there are multiple sku's, then list stock availability of options.
    $avail = array();
    foreach($skus as $val) {
      $sl = uc_stock_level($val);
      if (is_numeric($sl)) {
        $name=lookup_option_name($val);  // get the pretty name of option sku
        $avail[] =  " " .$name." (".$sl.")";   
      }
    }
    if(!empty($avail)) { $avail_string = "<br><div class=\"stock_level\">Number Available: ". implode(",",$avail) ."</div>"; }
    return( $avail_string ). drupal_get_form('uc_product_add_to_cart_form', $node);
  }
  else {  // no options on this product 

    // Check if stock tracking is active
   
$stockactive = uc_stock_level($node->model);
    if (is_numeric($stockactive)) { //stock active
      if ($stockactive == 0) {
        return( '<div class="out_of_stock">' . t('Sold Out') . '</div>' );
      } else {
        return( '<div class="stock_level">' . t('Number available: ') . $stockactive . '</div>' ) . drupal_get_form('uc_product_add_to_cart_form', $node);
      }
    }
    else { // stock not active
      return drupal_get_form('uc_product_add_to_cart_form', $node);
    }
  }
} 

function 
uc_stock_attribute_uc_product_models($node) {
  $models = array(); 

// Get all the SKUs for all the attriibutes.
  $adjustments = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = %d", $node->nid);
  while ($adjustment = db_fetch_object($adjustments)) {
    if (!in_array($adjustment->model, $models)) {
      $models[$adjustment->model] = $adjustment->model;
    }
  }
  return $models;
} 

function 
lookup_option_name($sku){
  //uc_attribute_options: name,oid
  //uc_product_adjustments: combination (number in "quotes" equals oid above),model 

$query = "SELECT combination FROM {uc_product_adjustments} WHERE model =  '$sku'";
  $result = db_query($query);
  while ($row = db_fetch_array($result)) {
    $combo = $row[combination];
    list($stuff, $oid, $junk) = split('"', $combo);
    $query2="SELECT name FROM {uc_attribute_options} WHERE oid = '$oid'";
    $result2=db_query($query2);
    while($row2=db_fetch_array($result2)){$name=$row2[name];}
    return $name;
  }
}
?>

But i don't think there's a problem with it.

The only thing i can think of is that i upgraded to Aqua 6.x-1.1 ...

sheena_d’s picture

function acquia_prosper_uc_product_add_to_cart( $node ) {

This function alters the add to cart button on product pages. Try removing that entire function (don't forget to clear cache) and let me know if the issue is resolved.

Luki_be’s picture

Yeah !!! Problem solved sheena :-)

Ofcourse, removing the function means the stock isn't displayed anymore for a product ... something so basic that seems to be impossible with ubercart :-(

Anyways,

tnx a bunch :-)

sheena_d’s picture

Category: bug » support
Status: Active » Closed (fixed)