Forum

Thread tagged as: Error, Shop

Broken cart

Hello,

I'm stuck with broken cart. I've set up all about taxes trough the wizard. This is on an empty card with default template and perch_shop_cart();

Fatal error: Call to a member function groupTaxRate() on a non-object in /var/www/virtuals/perch/cz.rebella/admin/addons/apps/perch_shop/lib/PerchShop_Product.class.php on line 325

Jiri Zavadil

Jiri Zavadil 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Please post your Diagnostics Report.

Since the previous post, I've deleted everything in admin -> tax and added the very same values again and there's a new error:

Catchable fatal error: Argument 4 passed to PerchShop_Product::get_prices() must be an instance of PerchShop_TaxLocation, boolean given, called in /var/www/virtuals/perch/cz.rebella/admin/addons/apps/perch_shop/lib/PerchShop_Cart.class.php on line 713 and defined in /var/www/virtuals/perch/cz.rebella/admin/addons/apps/perch_shop/lib/PerchShop_Product.class.php on line 278

Perch Runway: 2.8.31
Production mode: Production (100)
Installed apps: content (2.8.31), assets (2.8.31), categories (2.8.31), perch_shop_orders (1.0.8), perch_shop_products (PERCH_SHOP_VERSION), perch_shop (1.0.8), perch_members (1.5)
DB driver: PDO
DB tables: perch2_backup_plans (0), perch2_backup_resources (0), perch2_backup_runs (0), perch2_categories (3), perch2_category_counts (0), perch2_category_sets (1), perch2_collection_index (0), perch2_collection_items (0), perch2_collection_revisions (0), perch2_collections (0), perch2_content_index (11), perch2_content_items (6), perch2_content_regions (4), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_routes (6), perch2_page_templates (9), perch2_pages (9), perch2_resource_log (41), perch2_resource_tags (0), perch2_resources (25), perch2_resources_to_tags (0), perch2_settings (25), perch2_shop_addresses (0), perch2_shop_admin_index (30), perch2_shop_brands (1), perch2_shop_cart (12), perch2_shop_cart_data (0), perch2_shop_cart_items (9), perch2_shop_countries (250), perch2_shop_currencies (152), perch2_shop_customers (0), perch2_shop_emails (1), perch2_shop_index (436), perch2_shop_option_values (4), perch2_shop_options (1), perch2_shop_order_items (0), perch2_shop_order_promotions (0), perch2_shop_order_statuses (9), perch2_shop_orders (0), perch2_shop_orders_meta (1), perch2_shop_product_files (0), perch2_shop_product_option_values (12), perch2_shop_product_options (4), perch2_shop_product_tags (0), perch2_shop_products (22), perch2_shop_promotions (0), perch2_shop_search (11), perch2_shop_shipping_zone_countries (1), perch2_shop_shipping_zones (1), perch2_shop_shippings (1), perch2_shop_tax_exhibits (0), perch2_shop_tax_group_rates (2), perch2_shop_tax_groups (2), perch2_shop_tax_locations (2), perch2_shop_tax_rates (3), perch2_shop_variants (12), perch2_user_passwords (0), perch2_user_privileges (66), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1)
Users: 1
App runtimes:
<?php
    $apps_list = array(
        'content', 
        'categories',
        'perch_members',
        'perch_shop',
    );
Editor plug-ins: markitup
H1: 109a69624a248c0385f9f4b5d6640edd
L1: 68699d7536715fcdd89d78099c7e37d5
F1: 2edba60ed1f613d6dd804feb202456a2
headerColour: rgb(54,54,54)
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 1
content_collapseList: 1
lang: en-gb
update_2.8.31: done
headerScheme: dark
update_runway_2.8.31: done
latest_version: 2.8.15
on_sale_version: 2.8.31
dashboard: 1
hide_pwd_reset: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
perch_shop_update: 1.0.8
perch_shop_price_tax_mode: exc
perch_shop_trade_price_tax_mode: exc
perch_shop_site_url: https://
perch_shop_product_url: /shop/products/{slug}
perch_shop_default_currency: 36
perch_shop_reporting_currency: 36
perch_shop_invoice_number_format: Faktura_Rebella_%d
perch_members_login_page: /members/login.php?r={returnURL}
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_SITEPATH: /var/www/virtuals/perch/cz.rebella
PERCH_SCHEDULE_SECRET: samdbCS7soBYl6BE
PERCH_DB_USERNAME: rebella
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: virtuals_perch_cz_rebella
PERCH_DB_PREFIX: perch2_
PERCH_EMAIL_FROM: jiri@pixelpromo.cz
PERCH_EMAIL_FROM_NAME: Jiří Zavadil
PERCH_LOGINPATH: /admin
PERCH_PATH: /var/www/virtuals/perch/cz.rebella/admin
PERCH_CORE: /var/www/virtuals/perch/cz.rebella/admin/core
PERCH_RESFILEPATH: /var/www/virtuals/perch/cz.rebella/admin/resources
PERCH_RESPATH: /admin/resources
PERCH_HTML5: 1
PERCH_TZ: Europe/Prague
PERCH_IMAGE_LIB: imagick
PERCH_DEBUG: 1
PERCH_RUNWAY: 1
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /var/www/virtuals/perch/cz.rebella/admin/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20
PERCH_SHOP_VERSION: 1.0.8
PERCH_APPS_EDITOR_PLUGIN: markitup
PERCH_APPS_EDITOR_MARKUP_LANGUAGE: textile
HOSTING SETTINGS

PHP: 5.4.45-0+deb7u4
Zend: 2.4.0
OS: Linux
SAPI: apache2handler
Safe mode: not detected
MySQL client: 5.5.44
MySQL server: 5.5.44-0+deb7u1
Free disk space: 10.67 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, zlib, bcmath, bz2, calendar, ctype, dba, dom, hash, fileinfo, filter, ftp, gettext, SPL, iconv, json, mbstring, session, posix, Reflection, standard, shmop, SimpleXML, soap, sockets, Phar, exif, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xml, xmlreader, xmlwriter, zip, apache2handler, PDO, curl, intl, mysql, mysqli, pdo_mysql, imagick, mhash
GD: No
ImageMagick: Yes
PHP max upload size: 1024M
PHP max form post size: 128M
PHP memory limit: 128M
Total max uploadable file size: 128M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: Yes
SCRIPT_URL: /admin/core/settings/diagnostics/
SCRIPT_URI: https://rebella-cz.test.pixelpromo.cz/admin/core/settings/diagnostics/
HTTP_HOST: rebella-cz.test.pixelpromo.cz
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_CONNECTION: keep-alive
HTTP_COOKIE: PHPSESSID=jcpsk69n0euq7s2cp4phnvnej1; cmsa=1; cmssb=1; _ga=GA1.2.743219518.1450130232; intercom-id=b35cef17-2c54-4047-9b46-698fa1c338d5
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7
HTTP_ACCEPT_LANGUAGE: en-us
HTTP_REFERER: https://rebella-cz.test.pixelpromo.cz/admin/core/settings/diagnostics/
HTTP_ACCEPT_ENCODING: gzip, deflate
PATH: /usr/local/bin:/usr/bin:/bin
SERVER_SIGNATURE: <address>Apache/2.2.22 (Debian) Server at rebella-cz.test.pixelpromo.cz Port 80</address>
SERVER_SOFTWARE: Apache/2.2.22 (Debian)
SERVER_NAME: rebella-cz.test.pixelpromo.cz
SERVER_ADDR: 89.185.250.67
SERVER_PORT: 80
REMOTE_ADDR: 80.95.250.163
DOCUMENT_ROOT: /var/www/virtuals/perch/cz.rebella
SERVER_ADMIN: [no address given]
SCRIPT_FILENAME: /var/www/virtuals/perch/cz.rebella/admin/core/settings/diagnostics/index.php
REMOTE_PORT: 38851
GATEWAY_INTERFACE: CGI/1.1
SERVER_PROTOCOL: HTTP/1.1
REQUEST_METHOD: GET
QUERY_STRING: extended
REQUEST_URI: /admin/core/settings/diagnostics/?extended
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php
PHP_SELF: /admin/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1472069211.986
REQUEST_TIME: 1472069211
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you describe how your shop is configured?

You mean this? :) tax locations tax groups product

I've just tried to clear cookies and when I go to /cart it shows empty cart. When I add a product with this snippet I get a 500 error.

<div class="productImages">
    <img src="<perch:shop id="image" type="image" label="Main image" order="9" />">
</div>


<div class="productInfo">
    <h2>#<perch:shop id="sku" type="text" label="SKU" required="true" order="1" /></h2>


    <!--* <h2>#<perch:shop id="title" type="text" label="Title" required="true" order="2" /></h2> *-->
    <p class="price"><perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="m" min="0" step="any" order="4" /></p>

    <perch:shop id="slug" type="slug" editable="true" indelible="true" label="Slug" for="sku title" order="2" suppress="true" />

    <perch:shop id="status" type="shop_status" label="Status" suppress="true" order="5" />

    <perch:categories id="category" set="produkty" label="Category" suppress="true" order="6">
        <perch:category id="catTitle" />
    </perch:categories>

    <perch:form id="add_to_cart" app="perch_shop" action="/cart">

      <perch:if exists="has_variants">
        <perch:productopts>
        <fieldset>
          <legend><perch:productopt id="title" /></legend>
          <perch:productvalues>
            <perch:before><ul></perch:before>
              <li>
                <label>
                  <perch:input id="options" name="opt-<perch:productvalue id="optionID" />[]" 
                    value="<perch:productvalue id="valueID" />" type="radio" required="required" />
                  <perch:productvalue id="valueTitle" />
                </label>
              </li>
            <perch:after></ul></perch:after>
          </perch:productvalues>
          </fieldset>
        </perch:productopts>
      </perch:if>
      <perch:input id="product" type="hidden" value="<perch:shop id="productID" type="hidden" env-autofill="false" />" />
      <perch:input type="submit" class="cart-submit" value="Koupit" />
    </perch:form>   

    <perch:shop id="description" type="textarea" label="Description" order="3" markdown="true" size="s" />




    <perch:shop id="stock_status" type="shop_stock_status" label="Stock status" divider-before="Stock" required="true" suppress="true" order="7" />
    <perch:shop id="stock_level" type="number" label="Stock level" size="s" suppress="true" order="8" />


    <perch:shop id="sale_price" type="shop_currency_value" label="Sale price" size="m" min="0" step="any" />
    <perch:shop id="trade_price" type="shop_currency_value" label="Trade price" size="m" min="0" step="any" runway="true" />
    <perch:shop id="on_sale" type="checkbox" value="1" label="Use sale price" />
    <perch:shop id="tax_group" type="shop_tax_group" label="Tax group" required="true" />


    <perch:repeater id="otherimages" label="Other images" order="10">
        <img src="<perch:shop id="otherimage" type="image"  label="Image" />" />
    </perch:repeater>

</div>

And then when I go directly to /cart (without the POST) I get the PHP error above.

I've found this unresolved thread with the very same problem: https://forum.grabaperch.com/forum/08-17-2016-error-when-selecting-add-to-cart

Yes, I posted the above thread Jiri and I still haven't been able to figure out a resolution :(

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which is exactly why I'm asking for more information, so I can help figure it out.

When you get a 500 status, what error message is logged with that?

Jiri Zavadil said:

Catchable fatal error: Argument 4 passed to PerchShop_Product::get_prices() must be an instance of PerchShop_TaxLocation, boolean given, called in /var/www/virtuals/perch/cz.rebella/admin/addons/apps/perch_shop/lib/PerchShop_Cart.class.php on line 713 and defined in /var/www/virtuals/perch/cz.rebella/admin/addons/apps/perch_shop/lib/PerchShop_Product.class.php on line 278

I've found a temporary workaround:

in /addons/apps/perch_shop/lib/PerchShop_Product.class.php

change line 278 from:

public function get_prices($qty=1, $pricing='standard', $price_tax_mode='exc', PerchShop_TaxLocation $CustomerTaxLocation, PerchShop_TaxLocation $HomeTaxLocation, PerchShop_Currency $Currency, PerchShop_CartTotaliser &$Totaliser, $customer_pays_tax=true)

to:

public function get_prices($qty=1, $pricing='standard', $price_tax_mode='exc',  $CustomerTaxLocation,  $HomeTaxLocation, PerchShop_Currency $Currency, PerchShop_CartTotaliser &$Totaliser, $customer_pays_tax=true)

and it throws a new error: PHP Fatal error: Call to a member function id() on a non-object in /var/www/virtuals/perch/cz.rebella/admin/addons/apps/perch_shop/lib/PerchShop_Product.class.php on line 332, referer: https://rebella-cz.test.pixelpromo.cz/kabaty/k4b4t1-k4b4t1-tmave-modry/

so then changing line 332 from:

$tax_rate = $TaxRates->get_rate_for_location((int)$TaxGroup->id(), (int)$TaxLocation->id());

to:

$tax_rate = $TaxRates->get_rate_for_location(2,2);

(2 and 2 are ids of my tax group and tax location in DB)

profit!

Drew McLellan

Drew McLellan 2638 points
Perch Support

We don't advise doing that and do not offer support to anyone who has hacked at the application.

Drew, hacking the application is not my pleasure nor intention, but untill you fix the error or provide a solution, it is my only option, since the shop has to be live in 5 days and the products won't sell without working cart. Of course I've backed the original file and I can't wait to put it back.

Thanks for understanding

I'd prefer not to hack at the application either - Drew what other information do you need to help with this error?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm going to have to set something up to see if I can reproduce the issue. That won't be until next week.

Hey guys, so after some digging around on the forums and looking at solutions to other problems, I've cleared out my perch2_shop_tax_groups, perch2_shop_tax_groups_rates, perch2_shop_tax_locations and perch2_shop_tax_rates databases, and it seems to have fixed the issue. I'll let you know if it comes up again though. It looks like I had some old data in there. I don't know if the old data was the issue or something else was causing it, but thought I'd let you know where to look anyway.

Hello, I've done little digging now and here's the result:

  • Rate never gets the rateDeleted flag in perch2_shop_tax_rates when you delete it's Location.
  • When there's two locations, the shop always uses the first one, even if it has locationDeleted flag set and the second is default. (I'm not forcing the location anywhere in the code, since I don't know how)

this error (first post) happens, when at least one product's tax_group doesn't match the working locationID of the shop:

Fatal error: Call to a member function groupTaxRate() on a non-object in /var/www/virtuals/perch/cz.rebella/admin/addons/apps/perch_shop/lib/PerchShop_Product.class.php on line 325

this error (second post) happens, when the shop uses the first locationID in DB which has locationDeleted flag set (and sets it to cart):

Catchable fatal error: Argument 4 passed to PerchShop_Product::get_prices() must be an instance of PerchShop_TaxLocation, boolean given, called in /var/www/virtuals/perch/cz.rebella/admin/addons/apps/perch_shop/lib/PerchShop_Cart.class.php on line 713 and defined in /var/www/virtuals/perch/cz.rebella/admin/addons/apps/perch_shop/lib/PerchShop_Product.class.php on line 278

When there's just one Tax Location, one Tax Group, one Tax Rate and the all the products are set to this Tax Rate, everything works fine.

I'm going to kill myself now :)