Forum
Testing perch shop—empty cart after adding product to cart
Hi, I’m trying to set up a very simple implementation of perch shop on a standard perch site to sell just the one product. It’s the first time I’ve used perch shop and not got past basic testing of a product page with the simple add to cart form with:
<perch:form id="add_to_cart" app="perch_shop" action="/shop/cart">
<perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" />" env-autofill="false" />
<perch:input type="submit" value="Add to cart" />
</perch:form>
but the cart remains empty. Have tried without the env-autofill="false
which doesn’t work either. And with the add to cart function directly from php product page:
<?php
perch_shop_product('my-product', [
'template' => 'products/product_template.html',
]);
perch_shop_add_to_cart('my-product');
?>
Debug message for the product page is:
SELECT * FROM perch2_pages WHERE pagePath='/buy/index.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=21
[1] SELECT * FROM perch2_shop_cart WHERE cartID=21
[2] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/buy/index.php' LIMIT 1
[1] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-003', '000') ORDER BY pageTreePosition DESC
[2] Using template: /templates/navigation/navitem.html
[1] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='slug' AND idx.indexValue='modelling-on-the-stand-for-intimate-apparel-jmee2')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (productDeleted IS NULL AND productStatus=1 AND parentID IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
[24] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] Using template: /templates/shop/products/product_template.html
[1] SELECT * FROM perch2_shop_currencies WHERE currencyID=47 LIMIT 1
[1] SELECT itemID, itemQty FROM perch2_shop_cart_items WHERE cartID=21 AND productID=0
[1] SELECT * FROM perch2_shop_products WHERE productID=0 AND productDeleted IS NULL LIMIT 1
Limiting based on stock.
------------------------------ Calculating cart ------------------------------
[1] SELECT * FROM perch2_shop_cart WHERE cartID=21
[1] SELECT * FROM perch2_shop_cart WHERE cartID=21
[1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
[1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
[1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_currencies WHERE currencyID=47 LIMIT 1
[1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=21
Tax mode: inc
[nil] SELECT * FROM perch2_shop_cart_items WHERE cartID=21 ORDER BY itemID ASC
UPDATE perch2_shop_cart SET cartTotalItems=NULL, cartTotalProducts='0', cartTotalWithTax='0.00', cartTotalWithoutTax='0.00' WHERE cartID='21'
and from the cart page:
SELECT * FROM perch2_pages WHERE pagePath='/shop/cart/index.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=21
[1] SELECT * FROM perch2_shop_cart WHERE cartID=21
[2] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 ORDER BY pageTreePosition ASC
[0] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/shop/cart/index.php' LIMIT 1
[2] Using template: /templates/navigation/navitem.html
------------------------------ Calculating cart ------------------------------
[1] SELECT * FROM perch2_shop_cart WHERE cartID=21
[1] SELECT * FROM perch2_shop_cart WHERE cartID=21
[1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
[1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
[1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_currencies WHERE currencyID=47 LIMIT 1
[1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=21
[24] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Tax mode: inc
[nil] SELECT * FROM perch2_shop_cart_items WHERE cartID=21 ORDER BY itemID ASC
Using template: /templates/shop/cart/cart.html
Grateful if anyone can tell me where I’m going wrong. The product is in stock. Perch diagnostics:
Perch: 2.8.34, PHP: 5.6.2, MySQL: 5.5.38, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.34), assets (2.8.34), categories (2.8.34), perch_shop_orders (1.0.11), perch_shop_products (1.0.11), perch_shop (1.0.11), perch_members (1.5)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_members', 'perch_shop', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/kirsten/Sites/janice/prototyping280117/site_proto_v1/perch
PERCH_CORE: /Users/kirsten/Sites/janice/prototyping280117/site_proto_v1/perch/core
PERCH_RESFILEPATH: /Users/kirsten/Sites/janice/prototyping280117/site_proto_v1/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 6a33f95eca3667f9e0c39bf5ca2980fe
Resource folder writeable: Yes
HTTP_HOST: localhost:8888
DOCUMENT_ROOT: /Users/kirsten/Sites/janice/prototyping280117/site_proto_v1
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
If you view source on the add to cart form, what does it look like?
That looks ok. When you submit the form, do you end up on
/shop/cart
? Is there any possibility your server is redirecting to something like/shop/cart/
and throwing the post data away in the process?Yes it is going to /shop/cart/ which in my ignorance I thought was correct for the index.php file. I’ve obviously got very confused but still not sure what I need to do to resolve it.
Apologies, I realise I’m obviously not understanding something very basic
Hi Drew, I was just being a bit slow—finally worked out the obvious and got the add to cart working. Thanks for your help
Kirsten, please share how you fixed this? I'm having the same problem. I'd be very grateful!