Forum

Thread tagged as: Problem, Shop

What would cause my cart to be empty?

If I click on add to cart, the cart page says "Your Cart is Empty."

If I remove the section of the add to cart form for my variations:

<perch:productopts>
  <fieldset>
    <legend><perch:productopt id="title" /></legend>
<perch:input type="select" required="true" id="<perch:shop id="optionKey" />" name="os<perch:shop id="perch_item_index" />" options="  <perch:productvalues><perch:productvalue id="valueTitle" />|<perch:productvalue id="valueID" />,</perch:productvalues>" />

  </fieldset>
</perch:productopts>

Products get added to the cart just fine. If I include the above code, nowt happens.

Lisa Morena

Lisa Morena 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does debug output for your cart page?

SELECT * FROM perch2_members_sessions WHERE sessionID='68caf2324cfe51cb77939ac1367ee5d0b4b5f2f7' AND sessionHttpFootprint='2631419c2f44dc27e3c8e69d0ef9cab3556b788e' AND sessionExpires>'2016-08-11 20:04:13' LIMIT 1 User is logged in [1] SELECT * FROM perch2_pages WHERE pagePath='/cms/shop/cart/index.php' LIMIT 1 [1] SELECT * FROM perch2_shop_cart WHERE cartID=2 [1] SELECT * FROM perch2_shop_cart WHERE cartID=2 [24] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0

Array ( [0] => required )

[nil] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC Using cart from cache. Using template: \templates\shop\cart\cart.html

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you setting the productID anywhere in the form? e.g.

<perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />

Yep:

<perch:input env-autofill="false" id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you setting an action on the add to cart form? Does the value resolve to your cart page without a redirect?

Yes and there are no redirects:

<perch:form id="add_to_cart" app="perch_shop" action="/shop/cart/">

It works fine it I remove the product options form the form. Just doesn't seem to like them for some reason.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the full template?

To be honest, it is mostly just the default template as I am only just working out some functionality at the moment (sorting out that whole hiding stuff from certain members thing). This is the list.html template - I am not using individual products pages so all are listed on one page with their add to cart buttons. I basically just copied the product.html template into list.html and added the options bit:

<perch:before>
    <div class="wrapper cols2-nav-right">

        <div class="primary-content">
<h1>Products</h1>
<ul class="listing">
</perch:before>
<li>
<perch:shop id="sku" type="text" label="SKU" required="true" order="1" />
<perch:shop id="title" type="text" label="Title" required="true" order="2" />
<perch:shop id="slug" type="slug" editable="true" indelible="true" label="Slug" for="title sku" order="10" divider-before="Meta data" />
<perch:shop id="description" type="textarea" label="Description" editor="markitup" order="3" markdown="true" size="s" />
<perch:shop id="image" type="image" label="Main product image" order="4" width="800" />
<perch:shop id="image" type="image" width="80" height="80" density="1.6" crop="true" />
<perch:shop id="status" type="shop_status" label="Status" />

<perch:shop id="brand" type="shop_brand" label="Brand" allowempty="true" />

<perch:categories id="category" set="products" label="Category">
    <perch:category id="catTitle" />
</perch:categories>

<perch:shop id="catalog_only" type="shop_catalog_only" label="Catalog only" />
<perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="m" min="0" step="any" />
<perch:shop id="sale_price" type="shop_currency_value" label="Sale price" size="m" min="0" step="any" />
<perch:shop id="trade_price" type="shop_currency_value" label="Trade price" size="m" min="0" step="any" runway="true" />
<perch:shop id="on_sale" type="checkbox" value="1" label="Use sale price" />
<perch:shop id="tax_group" type="shop_tax_group" label="Tax group" required="true" />


<perch:shop id="stock_status" type="shop_stock_status" label="Stock status" divider-before="Stock" required="true" />
<perch:shop id="stock_level" type="number" label="Stock level" size="s" />
<perch:shop id="stock_location" type="shop_stock_location" label="Count stock" />
<perch:shop id="max_in_cart" type="number" label="Max quantity in cart" size="s" />

<perch:shop id="requires_shipping" type="shop_requires_shipping" label="Requires shipping" divider-before="Shipping" />
<perch:shop id="weight" type="number" label="Shipping weight" size="s" />
<perch:shop id="width" type="number" label="Width" size="s" />
<perch:shop id="height" type="number" label="Height" size="s" />
<perch:shop id="depth" type="number" label="Depth" size="s" />

<perch:form id="add_to_cart" app="perch_shop" action="/Vanilla-CMS/shop/cart/">
<perch:productopts>
  <fieldset>
    <legend><perch:productopt id="title" /></legend>
<perch:input type="select" required="true" name="os<perch:productopt id="optionID" />" options="<perch:productvalues><perch:productvalue id="valueTitle" />|<perch:productvalue id="valueID" />,</perch:productvalues>" />

  </fieldset>
</perch:productopts>
     <perch:input env-autofill="false" id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />
    <perch:input type="submit" value="Add to cart" />
</perch:form>

</li>
<perch:after>
</ul>
</div>
</div>
</perch:after>


Drew McLellan

Drew McLellan 2638 points
Perch Support

You've got the action set to action="/Vanilla-CMS/shop/cart/" - is that what you thought it was? It's not what you told me above.

Sorry, yes that is correct. I trimmed the first one to make things clearer since it is in a subdirectory on my test server for now called Vanilla-CMS. I wouldn't normally work like that as it makes a headache transferring to a live server but like I said, I just did a very quick install to test out the whole member access thing then came across this.

Sorry to confuse things!

Why would adding in the product options bit stop the cart from working?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like you've changed the name of the inputs. Those are special values that the app is looking for. I'd suggest trying the example from the documentation:

https://docs.grabaperch.com/addons/shop/products/template-tags/options/

Hmm, I see. OK, well If I put the name as :

opt-<perch:productopt id="optionID" />[]

It outputs the name as opt-1[], op-2[] for each of my select boxes. However, the cart is still empty when I add ot cart!

Is it because I am using a series of selct boxes rather than groups of radio buttons? Radio buttons are no good as there are 62 colours ot choose from! I also cannot use the default option of a single select box as it is just far too confusing for the user (they have 62 material colours and 62 feather colours to choose from) so a series of select boxes is the only option for me.

Also when I use the default perch select box (with all variations listed), the item may be added to the cart but the selected product options do not show. I am using this:

<perch:cartitem id="variant_desc" />

If I put name="product" as is output by the default select box, the item is added to the cart. However, if I have many select boxes per product then surely they cannot all be named the same?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you as a test use the radio buttons, do those work?

Right, so yes, product is added to cart, so no empty cart. Still no reference on the cart or in the order as to what the selected product options were though

(literaly just copied and pasted from the product options docs page)

Drew McLellan

Drew McLellan 2638 points
Perch Support

What tags do you have in your cart template? Have you turned on <perch:showall /> in the template to see what you've got available to you?

OK, so with the radio buttons it does include [variant_desc] => Blue, Pink but doesn't show it in the template or in the order

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is variant_desc not the description of your selection that you're looking for?

Oh for God's sake. All this faffing I had deleted the variant_desc from my template. OK, so yes, with radio buttons everything works as it should. Just can't get it to work with my multiple select box version