Forum

Thread tagged as: Shop

Add to cart, working in one place, not another...

So when I use:

<perch:form id="add_to_cart" app="perch_shop" action="/cart">
...
<perch:if exists="has_variants">     
    <perch:input id="product" type="select" class="variants" options="<perch:shop id="_variant_opts" type="hidden" />" placeholder="Please choose" required="true" class="sm-form-control" />
     <perch:else />
           <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" />
</perch:if>
...
</perch:form>

from content that is called in by:

<?php   perch_shop_products([
    'template' => 'products/list.html',
          'category' => array('products/posters'),
          'category-match' => 'all'


    ]); ?>

the item gets added to the cart correctly and I see in the debug:

INSERT INTO perch2_shop_cart_items(productID,itemQty,cartID) VALUES('13',1,'88')

buy when I use the same form code that is called into a page to display a single product using:


<?php perch_shop_product(perch_get('product'), [ 'template' => 'products/single_product' ]); ?>

Add to cart advances to the cart as expected but does not add the item, diplaying in debug:

SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] SELECT itemID, itemQty FROM perch2_shop_cart_items WHERE cartID=88 AND productID=0
[1] SELECT * FROM perch2_shop_products WHERE productID=0 AND productDeleted IS NULL LIMIT 1

So even though I can see the product id in the when I display it in the layout, the form is not passing it to the cart.

And, btw, where I would hope to find help in the github template pages, the /templates/pages/shop/product.php document is blank.

Any help would be much appreciated. thanks, Monty

Monty Lewis

Monty Lewis 2 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What is the value of perch_get('product') ?

It is the slug value.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's got the same name as the hidden product field, so I imagine that field is being autofilled from the environment.

Add env-autofill="false" to that field in the template.

Oh! Thank you, Drew!

So I just picked an unlucky name for the slug value?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Not unlucky, just symbiotic.