Forum

Thread tagged as: Problem, Error, Shop

Error when selecting Add to Cart

So I am getting a PHP error when trying to add to or view my cart. I'm sure it's something simple, but as I am not a PHP developer, and this is my first time using Runway and Perch Shop I'm a bit stuck.

The error I am getting is as follows:

Catchable fatal error: Argument 4 passed to PerchShop_Product::get_prices() must be an instance of PerchShop_TaxLocation, boolean given, called in /chroot/home/qof/dev.quilteronfire.com/html/perch/addons/apps/perch_shop/lib/PerchShop_Cart.class.php on line 713 and defined in /chroot/home/qof/dev.quilteronfire.com/html/perch/addons/apps/perch_shop/lib/PerchShop_Product.class.php on line 264

I am using the default cart template, and using <?php perch_shop_cart(); ?>

My guess is that it's something from the Control Panel, but I've selected both a Home and Default Tax location.

I'm hitting "Add to Cart" from my product display page - the code for the template which is here:

<div class="product_view-wrap">
    <h1><perch:shop id="title" type="text" label="Title" required="true" order="2" /></h1>
    <div class="product_view-flex_wrap">
        <div class="product_view-img"><img src="<perch:shop id="image" type="image" width="350" height="350" crop="true" />"></div>
        <div class="product_view-copy">
            <perch:shop id="description" type="textarea" label="Description" editor="markitup" order="3" markdown="true" size="s" />

            <perch:categories id="category" set="products" label="Category">
                <perch:category id="catTitle" />
            </perch:categories>
            <div class="product_view-price_wrap">
                <div><strong>Price: </strong><perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="m" min="0" step="any" /></div>

                <perch:shop id="tax_group" type="hidden" label="Tax group" />

                <div><strong>Stock Status:</strong> <perch:shop id="stock_status" type="shop_stock_status" label="Stock status" divider-before="Stock" required="true" /></div>

                <div class="product_view-shipping_info">
                    <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" />
                </div>
                <div class="product_view-cart_wrap">
                    <perch:form id="add_to_cart" app="perch_shop" action="/cart">
                        <perch:input id="product" type="hidden" env-autofill="false" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />
                        <perch:input type="submit" value="Add to cart" />
                    </perch:form>
                </div>
            </div>
        </div>
    </div>
    <div class="product_view-link"><a href="/shop">Back to Shop</a></div>
</div>

My diagnostics report is:

Perch Runway: 2.8.31, PHP: 5.6.24, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: Linux, fpm-fcgi
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_forms (1.8.3), perch_shop_orders (1.0.6), perch_shop_products (1.0.6), perch_shop (1.0.6), perch_members (1.5)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_members', 'perch_shop', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /chroot/home/qof/dev.quilteronfire.com/html/perch
PERCH_CORE: /chroot/home/qof/dev.quilteronfire.com/html/perch/core
PERCH_RESFILEPATH: /chroot/home/qof/dev.quilteronfire.com/html/perch/resources
Image manipulation: GD
PHP limits: Max upload 50M, Max POST 50M, Memory: 128M, Total max file upload: 50M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
HTTP_HOST: dev.quilteronfire.com
DOCUMENT_ROOT: /home/qof/dev.quilteronfire.com/html
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

My development server URL for the cart is dev.quilteronfire.com/cart where you will be able to see the error code as well.

Let me know if you need any other details, Thank you for your time in advance.

Herman Steuernagel

Herman Steuernagel 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like a tax location hasn't been identified. How do you have things configured?

I have one tax location called Canada, with currently one Tax Rate, titled "GST". And one tax group titled "Federal" with the GST selected.

I have just tried to go for a basic configuration right now.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have tax groups assigned to your products?

Yes, both have the "Federal" tax group selected.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have a tax location set up as your home location? Under Shop > Tax > Locations, one should have a green tick in the Home location column.

Yes the "Canada" location is set up as both the Home and Default location (It is the only location I've created).

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you changed the locations since the cart was created?

For some reason the tax location isn't being found for the customer. What should then happen is the home location should be used instead. Somehow neither of those is working, which isn't something I've ever seen before.

I have changed the locations, as I was learning how my client charges taxes.
Is there a way for me to "reset" everything and start again? I've tried deleting the locations and adding them again, thinking it may reset what the cart was grabbing. I've also tried deleting the cart page and adding it again.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try emptying the cart.

perch_shop_empty_cart();

Ok, so the cart empties. If I go to the cart page directly. It tells me "Your cart is empty".

It still won't let me add a product though, I get the same error.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you turn debug on, what does it output at the bottom of the cart page?

When the cart is empty this is what shows up. When I hit add to cart there is no debug because of the PHP error:

Time    Δ   Debug Message
0.0309  0   [10] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
0.039   0.0081  Matched page: /cart, so not using routes.
0.0393  0.0003  Using master page: /templates/pages/cart.php
0.0411  0.0018  [1] SELECT * FROM perch2_pages WHERE pagePath='/cart' LIMIT 1
0.045   0.0039  [1] SELECT * FROM perch2_shop_cart WHERE cartID=20
0.0466  0.0016  [1] SELECT * FROM perch2_shop_cart WHERE cartID=20
0.0499  0.0033  Using template: /templates/pages/attributes/default.html
0.0505  0.0006  Using sub-template: /templates/pages/attributes/seo.html
0.0507  0.0002  Using sub-template: /templates/pages/attributes/facebook.html
0.0508  0.0001  Using sub-template: /templates/pages/attributes/twitter.html
0.0575  0.0066  [3] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/cart' OR regionPage='*' ORDER BY regionPage DESC
0.0589  0.0014  DELETE FROM perch2_shop_cart WHERE cartID='20'
0.0616  0.0027  ------------------------------ Calculating cart ------------------------------
0.0617  0.0001  [1] SELECT * FROM perch2_shop_cart WHERE cartID=0
0.0644  0.0026  [1] SELECT * FROM perch2_shop_cart WHERE cartID=0
0.0655  0.0011  [1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=0 AND locationDeleted IS NULL LIMIT 1
0.0663  0.0008  [1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
0.0669  0.0006  [1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
0.0682  0.0013  [1] SELECT * FROM perch2_shop_currencies WHERE currencyID=0 LIMIT 1
0.0692  0.001   [26] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
0.0758  0.0066  [1] SELECT * FROM perch2_shop_currencies WHERE currencyActive=1 AND currencyID=26
0.0774  0.0016  [1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=0
0.078   0.0006  Tax mode: exc
0.0783  0.0004  [nil] SELECT * FROM perch2_shop_cart_items WHERE cartID=0 ORDER BY itemID ASC
0.0801  0.0018  [1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
0.0806  0.0005  INSERT INTO perch2_shop_cart(memberID,locationID,currencyID,cartPricing,cartProperties) VALUES(NULL,'1',26,'standard','[]')
0.0872  0.0066  [1] SELECT * FROM perch2_shop_cart WHERE cartID=22
0.0901  0.0029  ------------------------------ Calculating cart ------------------------------
0.0902  0.0001  [1] SELECT * FROM perch2_shop_cart WHERE cartID=22
0.091   0.0008  [1] SELECT * FROM perch2_shop_cart WHERE cartID=22
0.0919  0.0009  [1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
0.0926  0.0007  [1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
0.0933  0.0007  [1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
0.0946  0.0013  [1] SELECT * FROM perch2_shop_currencies WHERE currencyID=26 LIMIT 1
0.0953  0.0007  [1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=22
0.0968  0.0015  Tax mode: exc
0.097   0.0002  [nil] SELECT * FROM perch2_shop_cart_items WHERE cartID=22 ORDER BY itemID ASC
0.0995  0.0025  Using template: /templates/shop/cart/cart.html
0.1036  0.0041  
Array
(
    [type] => 8192
    [message] => Comments starting with '#' are deprecated in Unknown on line 1
    [file] => Unknown
    [line] => 0
)
Time    Δ   Debug Message
0.0309  0   [10] SELECT p.pagePath, pr.routePattern, pr.routeRegExp, p.pageTemplate FROM perch2_pages p LEFT JOIN perch2_page_routes pr ON p.pageID=pr.pageID ORDER BY pr.routeOrder ASC, p.pagePath ASC
0.039   0.0081  Matched page: /cart, so not using routes.
0.0393  0.0003  Using master page: /templates/pages/cart.php
0.0411  0.0018  [1] SELECT * FROM perch2_pages WHERE pagePath='/cart' LIMIT 1
0.045   0.0039  [1] SELECT * FROM perch2_shop_cart WHERE cartID=20
0.0466  0.0016  [1] SELECT * FROM perch2_shop_cart WHERE cartID=20
0.0499  0.0033  Using template: /templates/pages/attributes/default.html
0.0505  0.0006  Using sub-template: /templates/pages/attributes/seo.html
0.0507  0.0002  Using sub-template: /templates/pages/attributes/facebook.html
0.0508  0.0001  Using sub-template: /templates/pages/attributes/twitter.html
0.0575  0.0066  [3] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/cart' OR regionPage='*' ORDER BY regionPage DESC
0.0589  0.0014  DELETE FROM perch2_shop_cart WHERE cartID='20'
0.0616  0.0027  ------------------------------ Calculating cart ------------------------------
0.0617  0.0001  [1] SELECT * FROM perch2_shop_cart WHERE cartID=0
0.0644  0.0026  [1] SELECT * FROM perch2_shop_cart WHERE cartID=0
0.0655  0.0011  [1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=0 AND locationDeleted IS NULL LIMIT 1
0.0663  0.0008  [1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
0.0669  0.0006  [1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
0.0682  0.0013  [1] SELECT * FROM perch2_shop_currencies WHERE currencyID=0 LIMIT 1
0.0692  0.001   [26] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
0.0758  0.0066  [1] SELECT * FROM perch2_shop_currencies WHERE currencyActive=1 AND currencyID=26
0.0774  0.0016  [1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=0
0.078   0.0006  Tax mode: exc
0.0783  0.0004  [nil] SELECT * FROM perch2_shop_cart_items WHERE cartID=0 ORDER BY itemID ASC
0.0801  0.0018  [1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
0.0806  0.0005  INSERT INTO perch2_shop_cart(memberID,locationID,currencyID,cartPricing,cartProperties) VALUES(NULL,'1',26,'standard','[]')
0.0872  0.0066  [1] SELECT * FROM perch2_shop_cart WHERE cartID=22
0.0901  0.0029  ------------------------------ Calculating cart ------------------------------
0.0902  0.0001  [1] SELECT * FROM perch2_shop_cart WHERE cartID=22
0.091   0.0008  [1] SELECT * FROM perch2_shop_cart WHERE cartID=22
0.0919  0.0009  [1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
0.0926  0.0007  [1] SELECT locationID FROM perch2_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
0.0933  0.0007  [1] SELECT * FROM perch2_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
0.0946  0.0013  [1] SELECT * FROM perch2_shop_currencies WHERE currencyID=26 LIMIT 1
0.0953  0.0007  [1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch2_shop_cart_items WHERE cartID=22
0.0968  0.0015  Tax mode: exc
0.097   0.0002  [nil] SELECT * FROM perch2_shop_cart_items WHERE cartID=22 ORDER BY itemID ASC
0.0995  0.0025  Using template: /templates/shop/cart/cart.html
0.1036  0.0041  
Array
(
    [type] => 8192
    [message] => Comments starting with '#' are deprecated in Unknown on line 1
    [file] => Unknown
    [line] => 0
)
0.106   0.0023  Request time: 0.106
0.106   0   Process time: 0.1029
0.106   0   Memory: 1.8081
0.1061  0   
Array
(
    [type] => 8192
    [message] => Comments starting with '#' are deprecated in Unknown on line 1
    [file] => Unknown
    [line] => 0
)
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you try with the current version of Shop?

I've updated Shop and unfortunately still am getting the same error. I've tried using the cart.html template from the new version as well (and saved within the control panel). no change.

Thank you again for trying to help me out here.

Any other thoughts on this and what may be happening here? I'm kind of stuck without being able to add items to the cart.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have any rows in your perch2_shop_cart table?

Hi Drew,

I essentially cleared out the database tables and started over again with the tax information. It must have been trying to pull deleted tax info, as this fixed the problem. However I can see this running into issues in the future if a client tries to delete/add a tax location or rate.

I also had mentioned this in - forum.grabaperch.com/forum/08-24-2016-broken-cart - but never added my fix on this thread