Jump to content

Fatal Error in CartRule.php


ukvapeclub

Recommended Posts

Hi guys,

 

I've started having some problems recently when trying to manually create an order for a customer via the back office.

 

Everything's fine unless I try to use a cart rule (voucher) in the order. If I try to confirm an order that has a cart rule applied to it, I get a whitescreen.

 

I enabled debugging and the error causing the whitescreen is:

Fatal error: Call to a member function getOrderTotal() on a non-object in .../public_html/classes/CartRule.php on line 1050

 

I've had a look at CartRule.php and here's the section containing line 1050...

	/**
	 * Return the estimated cart VAT from the difference between the total amount taxes included and taxes excluded.
	 * @return float Estimated VAT rate.
	 */
	public function getCartAverageVatRate()
	{
		$context = Context::getContext();
		$cart_amount_ti = $context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
		$cart_amount_te = $context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);

		$cart_vat_amount = $cart_amount_ti - $cart_amount_te;

		if ($cart_vat_amount == 0 || $cart_amount_te == 0)
			$cart_average_vat_rate = 0;
		else
			$cart_average_vat_rate = Tools::ps_round($cart_vat_amount / $cart_amount_te, 3);

		return (float)$cart_average_vat_rate;
	}

So, can anyone tell me what's going wrong here? I haven't changed anything to do with cart rules or Vat, so I'm at a loss.

 

Thanks in advance!

 

Stu

Edited by ukvapeclub (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

hello,

 

i had this problem this morning

i go to classe CartRule.php and modify the function :

 

 

    public function getCartAverageVatRate()
    {
        //$context = Context::getContext();
        $cart=new Cart(Context::getContext()->cart->id);
        $cart_amount_ti = $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
        $cart_amount_te = $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);

        $cart_vat_amount = $cart_amount_ti - $cart_amount_te;

        if ($cart_vat_amount == 0 || $cart_amount_te == 0)
            $cart_average_vat_rate = 0;
        else
            $cart_average_vat_rate = Tools::ps_round($cart_vat_amount / $cart_amount_te, 3);

        return (float)$cart_average_vat_rate;
    }

 

it works for me now when i add the voucher

  • Like 3
Link to comment
Share on other sites

Hello,

 

I've got the same problem and i use the solution of madmix and it work's fine !

 

If it's a real bug in prestashop 1.6, may be necessary to put il in the Forge ?

 

Thanks a lot madmix.

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...
  • 2 months later...
  • 3 months later...

Hi there

 

I am facing a similar issue - i get the fatal error while clicking on active carts in the backend:

Fatal error: Call to undefined method CartRule::getCartAverageVatRate() in /override/classes/CartRule.php on line 156

Lines arround 156 shows this:

 

/**
     * @see ObjectModel::delete()
     */
    public function delete()
    {
        if (!parent::delete()) {
            return false;
        }


        Configuration::updateGlobalValue('PS_CART_RULE_FEATURE_ACTIVE', CartRule::isCurrentlyUsed($this->def['table'], true));


        $r = Db::getInstance()->delete('cart_cart_rule', '`id_cart_rule` = '.(int)$this->id);
        $r &= Db::getInstance()->delete('cart_rule_carrier', '`id_cart_rule` = '.(int)$this->id);
        $r &= Db::getInstance()->delete('cart_rule_shop', '`id_cart_rule` = '.(int)$this->id);
        $r &= Db::getInstance()->delete('cart_rule_group', '`id_cart_rule` = '.(int)$this->id);
        $r &= Db::getInstance()->delete('cart_rule_country', '`id_cart_rule` = '.(int)$this->id);
        $r &= Db::getInstance()->delete('cart_rule_combination', '`id_cart_rule_1` = '.(int)$this->id.' OR `id_cart_rule_2` = '.(int)$this->id);
        $r &= Db::getInstance()->delete('cart_rule_product_rule_group', '`id_cart_rule` = '.(int)$this->id);
        $r &= Db::getInstance()->delete('cart_rule_product_rule', 'NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'cart_rule_product_rule_group`
WHERE `'._DB_PREFIX_.'cart_rule_product_rule`.`id_product_rule_group` = `'._DB_PREFIX_.'cart_rule_product_rule_group`.`id_product_rule_group`)');
        $r &= Db::getInstance()->delete('cart_rule_product_rule_value', 'NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'cart_rule_product_rule`
WHERE `'._DB_PREFIX_.'cart_rule_product_rule_value`.`id_product_rule` = `'._DB_PREFIX_.'cart_rule_product_rule`.`id_product_rule`)');


        return $r;

I am on 1.6.1.3 right now, the issue started already with 1.6.1.1

 

Any advice?

 

Cheers & thank you 

Dennis

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...