concretecms-community-store / community_store

An open, free and community developed eCommerce system for Concrete CMS
https://concretecms-community-store.github.io/community_store/
MIT License
106 stars 66 forks source link

Undefined variable $taxCalc when logged in #701

Closed ajenkins-dev closed 1 year ago

ajenkins-dev commented 1 year ago

This is on the latest releases of ConcreteCMS 9.1.3 and Community Store, running on PHP 8.0.25.

The error occurs when logged into the website and clicking the clear cart button from the cart page but it doesn't happen when the user isn't logged in.

Undefined variable $taxCalc /packages/community_store/src/CommunityStore/Tax/TaxRate.php

    if ('grandtotal' == $this->getTaxBasedOn()) {
        $shippingTotal = floatval(Calculator::getShippingTotal());

        if ('extract' == $taxCalc) {
            $taxrate = 1 + ($this->getTaxRate() / 100);
            $shippingtaxtotal = $shippingTotal - ($shippingTotal / $taxrate);
        } else {
            $taxrate = $this->getTaxRate() / 100;
            $shippingtaxtotal = $taxrate * $shippingTotal;
        }
    }

I changed it to:

    if ('grandtotal' == $this->getTaxBasedOn()) {
        $shippingTotal = floatval(Calculator::getShippingTotal());
        $taxCalc = Config::get('community_store.calculation');
        if ('extract' == $taxCalc) {
            $taxrate = 1 + ($this->getTaxRate() / 100);
            $shippingtaxtotal = $shippingTotal - ($shippingTotal / $taxrate);
        } else {
            $taxrate = $this->getTaxRate() / 100;
            $shippingtaxtotal = $taxrate * $shippingTotal;
        }
    }

and it seems to have resolved the issue.