Forum

Thread tagged as: Problem, Shop

Add to cart issue in safari

I'm experiencing a very specific issue where my add to cart functionality works in all browsers but Safari. What's more, it works in safari locally but not on the server.

I'm handling the cart with ajax, the debug on my page with the perch_shop_cart() function is:

Debug Message - Perch 3.0
[1] SELECT * FROM perch2_pages WHERE pagePath='/get-cart.php' LIMIT 1
[26] 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',103,'standard','[]')
[1] SELECT * FROM perch2_shop_cart WHERE cartID=1023
[1] SELECT * FROM perch2_shop_cart WHERE cartID=1023
------------------------------ Calculating cart ------------------------------
[1] SELECT * FROM perch2_shop_cart WHERE cartID=1023
[1] SELECT * FROM perch2_shop_cart WHERE cartID=1023
[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=103 LIMIT 1
[1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=1023
Tax mode: inc
[nil] SELECT * FROM perch2_shop_cart_items WHERE cartID=1023 ORDER BY itemID ASC
Using template: /templates/shop/cart/cart.html
Array
(
    [type] => 8
    [message] => A session had already been started - ignoring session_start()
    [file] => /nfs/c12/h04/mnt/213490/domains/yarrows.co.nz/html/perch/addons/apps/perch_shop/lib/PerchShop_Session.class.php
    [line] => 15
)

Some googling led me to possible issues with safari cookie policies, curious to know if this has come up before.

Hamish Irving

Hamish Irving 1 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It's not something I'm familiar with. You'd do well to update to the current version though.

I've updated, and now I'm no longer experiencing the issue on Safari desktop, however I still have the issue on Safari mobile, I've tested on 3 different iOS devices. I'm guessing it is something to do with

Array
(
[type] => 8
[message] => A session had already been started - ignoring session_start()
[file] => /nfs/c12/h04/mnt/213490/domains/yarrows.co.nz/html/perch/addons/apps/perch_shop/lib/PerchShop_Session.class.php
[line] => 15
)

Because that message doesn't show when an item is added successfully to the cart?

I've tried clearing my mobile safari browsing data, but it hasn't fixed it. You can see the page and debug here if you have an iOS device:

www.yarrows.co.nz/fundraisers

Tapping 'Add to basket' on any item should add the item to the basket, however basket is returned empty.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd need to give us some insight as to how you've built your shop.

I've had another go at this and found some reference to session.auto_start=1 in the php.ini file which I have now commented out.

This has had the effect of removing the error:

Array
(
[type] => 8
[message] => A session had already been started - ignoring session_start()
[file] => /nfs/c12/h04/mnt/213490/domains/yarrows.co.nz/html/perch/addons/apps/perch_shop/lib/PerchShop_Session.class.php
[line] => 15
)

However the add to cart still does not work.. This is now specific to safari on iOS and IE 11. All other browsers appear to work.

My cart is set up so that I have a page add-to-cart.php which contains

<?php
    $product = perch_get('item');
    $qty = perch_get('qty');
    $update = perch_get('update');
    perch_shop_add_to_cart($product,$qty,$update);
?>

and a get-cart.php page which contains

<?php 
    perch_shop_cart([
        'template' => 'cart/cart.html',
    ]);
?>

I use ajax to add items to the cart and then to retrieve the cart.

To add items:

    function addToCart(productId, qty) {
        $.ajax({
            url: '/add-to-cart?item=' + productId + '&qty=' + qty + '&update=true',
            success: function() {
                getCartItems();
                getCartCount();
                showBasket();
            }
        });
    }

And then to retrieve the cart (getCartItems())

    function getCartItems() {
        $('.cart-module-loading').show();
        $.ajax({
            url: '/get-cart',
            success: function(data) {
                $('.cart-module-loading').hide();
            $('.basket-wrap').html(data);
            }
        });
    }

Debug message on get-cart.php from IE11 (Add to basket not working) - is the problem with the INSERT?

Debug Message - Perch 3.0.3 

[1] SELECT * FROM perch2_pages WHERE pagePath='/get-cart.php' LIMIT 1 
[27] 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',103,'standard','[]') 
[1] SELECT * FROM perch2_shop_cart WHERE cartID=5856 
[1] SELECT * FROM perch2_shop_cart WHERE cartID=5856 
------------------------------ Calculating cart ------------------------------ 
[1] SELECT * FROM perch2_shop_cart WHERE cartID=5856 
[1] SELECT * FROM perch2_shop_cart WHERE cartID=5856 
[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=103 LIMIT 1 
[1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=5856 
Tax mode: inc 
[nil] SELECT * FROM perch2_shop_cart_items WHERE cartID=5856 ORDER BY itemID ASC 
Using template: /templates/shop/cart/cart.html 

Debug message on get-cart.php from Safari Desktop (Add to basket working)

Debug Message - Perch 3.0.3
[1] SELECT * FROM perch2_pages WHERE pagePath='/get-cart.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=5796
[1] SELECT * FROM perch2_shop_cart WHERE cartID=5796
------------------------------ Calculating cart ------------------------------
[1] SELECT * FROM perch2_shop_cart WHERE cartID=5796
[1] SELECT * FROM perch2_shop_cart WHERE cartID=5796
[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=103 LIMIT 1
[1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=5796
[27] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
Tax mode: inc
[1] SELECT * FROM perch2_shop_cart_items WHERE cartID=5796 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 * 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
[nil] SELECT * FROM perch2_shop_promotions WHERE promoFrom<='2017-05-23 07:54:00' AND promoTo>'2017-05-23 07:54:00' AND promoActive=1 AND promoDeleted IS NULL ORDER BY promoOrder ASC
[1] Using template: /templates/shop/cart/cart.html

If I test the add-to-cart.php page via using the URL https://www.yarrows.co.nz/add-to-cart?item=4&qty=1&update=true then it works on IE11, the item is successfully added to the cart, so the issue appears to be with then retrieving the cart via get-cart.php

This can all be tested live on https://www.yarrows.co.nz/fundraisers

Drew McLellan

Drew McLellan 2638 points
Perch Support

If it's specific to certain browsers, you should look at your front end code as the most likely culprit.