Forum
Cart - New cart created on each page load
I am having a problem on my local development environment where a new empty cart is being created and stored each time the page refreshes. This new cart has it's id incremented by 10 each time and though it is stored in the db, it is not returned.
Here is the content of my diagnostics immediately after I have installed perch_shop 1.0.9 and perch 2.8.32:
Diagnostics report
HEALTH CHECK
Setup folder is present and should be deleted
Perch is up to date
PHP 5.5.9-1ubuntu4.16 is up to date
MySQL 5.7.14 is up to date
No image processing library. Consider installing GD or ImageMagick for resizing images.
SUMMARY INFORMATION
Perch: 2.8.32, PHP: 5.5.9-1ubuntu4.16, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $, with PDO
Server OS: Linux, fpm-fcgi
Installed apps: content (2.8.32), assets (2.8.32), categories (2.8.32), perch_forms (1.8.3), perch_gallery (2.8.6), perch_mailchimp (2.0.2), perch_shop_orders (1.0.9), perch_shop_products (1.0.9), perch_shop (1.0.9), perch_members (1.5)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_members', 'perch_shop', 'perch_gallery', 'perch_mailchimp', 'perch_forms', 'sl_shop', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /home/vagrant/Repositories/speechlink-shop/public/perch
PERCH_CORE: /home/vagrant/Repositories/speechlink-shop/public/perch/core
PERCH_RESFILEPATH: /home/vagrant/Repositories/speechlink-shop/public/perch/resources
Image manipulation:
PHP limits: Max upload 100M, Max POST 125M, Memory: 128M, Total max file upload: 100M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
REQUEST_URI: /perch/core/settings/diagnostics/
DOCUMENT_ROOT: /home/vagrant/Repositories/speechlink-shop/public
HTTP_HOST: sl-dev-speechlink-shop.co.uk
Below you can find the output of the debug messages on the index page. This is typical of a page which has cart functionality:
SELECT * FROM perch2_pages WHERE pagePath='/index.php' LIMIT 1
[35] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
INSERT INTO perch2_shop_cart(memberID,locationID,currencyID,cartPricing,cartProperties) VALUES(NULL,'1',47,'standard','[]')
[1] SELECT * FROM perch2_shop_cart WHERE cartID=6412
[1] SELECT * FROM perch2_shop_cart WHERE cartID=6412
[1] SELECT itemID, itemQty FROM perch2_shop_cart_items WHERE cartID=6412 AND productID=3
[1] SELECT * FROM perch2_shop_products WHERE productID=3 AND productDeleted IS NULL LIMIT 1
INSERT INTO perch2_shop_cart_items(productID,itemQty,cartID) VALUES('3','1','6412')
------------------------------ Calculating cart ------------------------------
[1] SELECT * FROM perch2_shop_cart WHERE cartID=6412
[1] SELECT * FROM perch2_shop_cart WHERE cartID=6412
[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=6412
Tax mode: exc
[1] SELECT * FROM perch2_shop_cart_items WHERE cartID=6412 ORDER BY itemID ASC
[1] SELECT * FROM perch2_shop_products WHERE productID=3 AND productDeleted IS NULL LIMIT 1
[1] SELECT * FROM perch2_shop_tax_groups WHERE groupID=1 AND groupDeleted IS NULL LIMIT 1
[1] SELECT r.rateValue FROM perch2_shop_tax_group_rates gr, perch2_shop_tax_rates r WHERE gr.rateID=r.rateID AND gr.groupID=1 AND gr.locationID=1
[1] SELECT z.* FROM perch2_shop_shipping_zones z LEFT JOIN perch2_shop_shipping_zone_countries c ON z.zoneID=c.zoneID WHERE z.zoneActive=1 AND z.zoneDeleted IS NULL AND (c.countryID=236 OR zoneIsDefault=1) ORDER BY zoneIsDefault ASC LIMIT 1
[1] SELECT * FROM perch2_shop_shippings WHERE shippingDeleted IS NULL ORDER BY shippingOrder ASC
Rejecting shipping method ‘Standard Delivery’ because: no price available for chosen shipping zone
[nil] SELECT * FROM perch2_shop_promotions WHERE promoFrom<='2016-10-25 13:45:00' AND promoTo>'2016-10-25 13:45:00' AND promoActive=1 AND promoDeleted IS NULL ORDER BY promoOrder ASC
UPDATE perch2_shop_cart SET cartTotalItems='1', cartTotalProducts='1', cartTotalWithTax='15.00', cartTotalWithoutTax='12.50' WHERE cartID='6412'
[4] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/index.php' OR regionPage='*' ORDER BY regionPage DESC
[10] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='status' AND idx.indexValue='1')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[10] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='parentID' AND idx.indexValue='')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[10] 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='title' AND idx.itemID IN ('1', '10', '2', '3', '4', '5', '6', '7', '8', '9') AND idx.itemID IN ('1', '10', '2', '3', '4', '5', '6', '7', '8', '9') WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey ) as tbl WHERE (productDeleted IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
[10] Using template: /templates/shop/products/list.html
Using cart from cache.
[1] Using template: /templates/shop/cart/sidebar_cart.html
[1] SELECT pageID FROM perch2_pages WHERE pagePath='/index.php' LIMIT 1
INSERT INTO perch2_content_regions(regionKey,regionPage,regionHTML,regionOptions,pageID) SELECT 'Legal' AS regionKey,'/index.php' AS regionPage,'<!-- Undefined content: Legal -->' AS regionHTML,'' AS regionOptions,'1' AS pageID FROM (SELECT 1) AS dtable WHERE ( SELECT COUNT(*) FROM perch2_content_regions WHERE regionKey='Legal' AND (regionPage='/index.php' OR regionPage='*') )=0 LIMIT 1
UPDATE perch2_content_regions SET regionOrder=0 WHERE regionPage='/index.php' AND regionKey='Homepage Heading' LIMIT 1
UPDATE perch2_content_regions SET regionOrder=1 WHERE regionPage='/index.php' AND regionKey='Homepage Intro' LIMIT 1
UPDATE perch2_content_regions SET regionOrder=2 WHERE regionPage='/index.php' AND regionKey='Legal' LIMIT 1
Array
(
[type] => 2
[message] => in_array() expects parameter 2 to be array, null given
[file] => /home/vagrant/Repositories/speechlink-shop/public/perch/addons/apps/perch_shop/lib/PerchShop_Shippings.class.php
[line] => 31
)
I am in the process of upgrading from perch_shop 1.0.g23. As 1.0.g23 was missing some important functionality, a number of bespoke changes were made to perch_shop code during the build.
However, this problem with the cart no-longer working seems to be a problem with my development environment as it does not appear to be effecting the live system when both are running the same 1.0.g23 branch. My questions are:
1) How does the shop track the cart? (is it session based? cached?) Where can i place debug to determine whether a cart is available before a new cart is created? 2) What could cause a user to be logged out of the perch backend when an item is added to a cart on the frontend?
It uses a session cookie. Check your sessions are working correctly.
Messed up sessions. There should be no interaction between the backend and frontend sessions, so something is badly wrong there.