Jump to content

Add to cart from category page, more than one item


nathanbright

Recommended Posts

My version of the Foundation skin (CC6) ignores the count of products to add to the cart when doing so from the category page, in list mode (but it works if the page is in grid mode)

This works in the Foundation skin so I suspect there's been a fix since I copied it

My "diff juju" is not working, I cannot figure out where the item count is being read. Can anyone point me in the right direction please? I expect it's somewhere in either the 2.cubecart.js or perhaps an attribute in the css / html. But I can't see it for looking

 

Link to comment
Share on other sites

Amazing no one has caught this.

In the Foundation template content.category.php, compare these two ranges of statements. The first is for list view, the second for grid view.

Lines 111-120:
      {elseif $product.ctrl_stock && !$CATALOGUE_MODE}
      <div class="row collapse">
         <div class="small-4 columns">
            <input type="text" name="quantity" value="1" class="quantity text-center">
         </div>
         <div class="small-8 columns">
            <button type="submit" value="{$LANG.catalogue.add_to_basket}" class="button small postfix">{$LANG.catalogue.add_to_basket}</button>
         </div>
      </div>
      {elseif !$CATALOGUE_MODE}

Lines 170-180
      {elseif $product.ctrl_stock && !$CATALOGUE_MODE}
      <div class="row collapse marg-top">
         <div class="small-3 columns">
           <input type="text" name="quantity" value="1" class="quantity text-center" disabled>
         </div>
         <div class="small-9 columns ">
            <button type="submit" value="{$LANG.catalogue.add_to_basket}" class="button small postfix">{$LANG.catalogue.add_to_basket}</button>
            <input type="hidden" name="add" value="{$product.product_id}">
         </div>
      </div>
      {elseif !$CATALOGUE_MODE}

Note that there is a missing

            <input type="hidden" name="add" value="{$product.product_id}">

in the list view statements. Please add it.

While you are there, near line 130:

Make the change to:

    <div class="product_grid_view hide">
       {* Issue 708 <!-- <form action="{$VAL_SELF}" method="post" class="panel add_to_basket"> --> *}
        <div data-equalizer-watch>

 

Note that Kurouto's View category code is:

<form>
<input type="text" name="add[{$product.product_id}][quantity]" value="1" class="quantity" />
<input type="submit" value="{$LANG.catalogue.add_to_basket}" class="button_white" />
</form>
--repeat--

From a page where the customer sees more than one product (sale items, category, latest products), the implication is that the customer can make changes to the quantity on all products displayed, and click Add to Basket on any of them, and all products will be added to the basket. But that's not the case.

Link to comment
Share on other sites

  • 2 weeks later...

Hi Al et al

Apologies for the "radio silence", I tried bsmithers solution, did not solve my issue, then went on holiday

You are quite right Al, I took a copy of Foundation back in late March (2015). Unfortunately for me there have been significant changes since, so "diff"ing gives me a "snow" of changes. So much so I feel I am unable to reverse them all in (as well as not being able to determine which is the solution to my issue)

It feels like that missing ID input field is relevant

I appreciate this is effectively an unsupported branch of the Foundation code, but would appreciate if someone could point me at the javascript that reads the quantity field during the add-to-cart action

 

Link to comment
Share on other sites

Generally, there is no specific javascript statement that reads the quantity field. What happens in 2.cubecart.js, near line 339 (function add_to_basket), is that the form's complete set of input elements are 'serialized'. This is a jQuery function that collects the values from all the child <input> elements of the respective form.

Thus, if there is no form element for add=product_id, that product will not get added to the cart. Yes, the quantity will get sent to CubeCart, but not the product_id.

On the other hand... as opposed to my previous experiments, the unrendered input that has the 'add' key is getting sent properly. Both the rendered section (list or grid) and the unrendered section, all the form elements are within the one form block and all non-disabled elements will get serialized.

Link to comment
Share on other sites

Got it. Typically enough, staring me in the face

I doubt this will help anyone but for the sake of completeness. I had this

<input type="text" name="add[{$product.product_id}][quantity]" value="1" class="quantity text-center">

which should have been this

<input type="text" name="quantity" value="1" class="quantity text-center">

I.e. it was being serialised fine, just being given the wrong name

Thanks for the help, good learning going on here

 

Link to comment
Share on other sites

There was a version of CubeCart a few years back where name="add[{$product.product_id}][quantity]" value="1" is a valid configuration for any page where more than one product was listed -- View Category (includes Sale Items and Search Results) and Latest Products. These also had code that gave only one all-encompassing <form> block - not a separate <form> block for each product panel.

The class function Cart->add() has code to determine if $_POST['add'] is an array (multi add to basket) or something else (scalar: single add to basket).

However, I suspect your customizations affected how other parts of the <form> data was being interpreted by the class function.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...