When adding several products with attributes, publishing them to the front page, and then going to the home page I see odd behaviors. Radio button attributes across multiple products appear linked (changing on one product changes the attribute on a different one) and I also see multiple unneeded AJAX requests firing when a select attribute is changed several times on one product and then a different product has an attribute change.

Probably tied into the comment in the code "TODO: Fix bug where multiple add_to_cart forms on a single page have elements with identical css id's after regenerating the forms" I was thinking maybe the drupal_get_form() might be adding extra jquery code which was putting additional binds on change, click events.

Comments

cyu’s picture

This appears linked to #384992: drupal_html_id does not work correctly in AJAX context with multiple forms on page

I believe this is fixed in d7, but probably requires some messy hackery in d6.

The 1.x branch of this module didn't have this problem because the AJAX request simply filled in element values and didn't replace the form altogether. The problem here is that a page with multiple products containing the same attribute will give those attributes incremental ids on the initial page load, but using drupal_get_form('uc_product_add_to_cart_form', $product); to get a fresh form and place it back onto the page, the element ids will have no knowledge of the already existing ids on the page and will potentially fail to be unique...causing the odd behavior initially reported.

timb’s picture

I was wondering if there has been any further development on this feature. This module works great on the node pages, but I need to have add to cart links in the catalog (view). The 6.x-2.1 version acted poorly (as u claimed it would), while the 2.x-dev had no visible effect on the add to cart forms, but I expect that the javascript is being called but is not working.

Alternately, would it be possible to not override the add to cart forms when displayed in a view (i.e. disable functionality when in a view)?

BTW - I am using Views 6.x-3.x-dev

THX

timb’s picture

Followup on my previous comment. The 6.x-2.x-dev has no visible ill effects in Safari, but it does act crazy on Firefox when there are add to cart forms in views.

I would still be very interested in any help/hints with getting this modules functionality turned off inside views.

beatnikdude’s picture

subscribe

ricky.ybarra’s picture

Here is my hack :( (yeah it's not very pretty or generic) for the multiple node problem. It's not ajax and doesn't concern this module.

It updates the display price when an attribute option radio button is clicked. My products are in a view and there are multiple add-to-cart forms.

I tried a 2d array but abandoned it for scope problems.... so sorry that it's not so clean. Woulda been nicer without the extra markup.

I put this code in my node-product.tpl.php under the condition of !$page.

    <?php
      //get the attribute prices
      $attributes = array();
      $q1 = "SELECT o.oid, o.name, o.price, o.weight FROM {uc_attribute_options} o WHERE o.aid = '1' ORDER BY o.weight ASC";
      $res = db_query($q1);
      while($rec = db_fetch_object($res)){
        $attributes[$rec->oid] = array('name' => $rec->name, 'price' => $rec->price);
      }
      ?>
      
      <script type='text/javascript'>    
      var options<?php print $node->nid; ?> = new Array();      
      <?php foreach($attributes as $key => $attr) :  ?>
      <?php
         //get adjusted prices if they exist
         $q2 = "SELECT o.oid, o.price FROM {uc_product_options} o WHERE o.oid = '%d' AND o.nid = '%d'";
         $res2 = db_query($q2, $key, $node->nid);
         $rec2 = db_fetch_object($res2);
         if($rec2){
          $attributes[$key]['price'] = $rec2->price;
         }
      ?>
         options<?php print $node->nid; ?>[<?php print $node->nid; ?>, <?php print $key; ?>] = <?php print $attributes[$key]['price']; ?>;
      <?php endforeach; ?>

       $(document).ready(function(){
          $('#node-<?php print($node->nid); ?> .form-radio').click(function(){
            var id = $(this).attr('id');
            var data = id.split("-");
            var oid = data.pop();
            var nid = data.pop();
            var price = options<?php print $node->nid; ?>[nid, oid];
             
            $('#node-'+nid).find('.uc-price-display').html('$'+price.toFixed(2));
          });
        });
      </script>