pooja.gadkari Posted January 31, 2014 Share Posted January 31, 2014 Hi I am using prestashop 1.5.6.0. When user clicks on add to cart button, I am creating cart rule and assigning it to cart, if I click on "Cart" link at the top right, I am getting Fatal error: Call to a member function getProducts() on a non-object in /classes/CartRule.php on line 565 for the first time when cart is empty. But if cart is not empty then I am not getting error. For creating cat rule I had taken help from below link http://www.prestashop.com/forums/topic/282032-solved-problem-in-creating-cart-rule-dynamically/ For assigning cart rule to shopping cart, i had used below code: public function hookActionCartSave($params){ $code = $this->context->cookie->__get('token'); if (($cartRule = new CartRule(CartRule::getIdByCode($code))) && Validate::isLoadedObject($cartRule)) { if ($error = $cartRule->checkValidity($this->context, false, true)) { $this->errors[] = $error; } else { $this->context->cart->addCartRule($cartRule->id); } } } Can anyone help in fixing this issue Thanks Link to comment Share on other sites More sharing options...
vekia Posted January 31, 2014 Share Posted January 31, 2014 so, after "add to cart" you see some error messages? ($this->errors[] = $error;) ? Link to comment Share on other sites More sharing options...
pooja.gadkari Posted January 31, 2014 Author Share Posted January 31, 2014 (edited) no. When I click on cart link present at the top right I am getting Fatal error: Call to a member function getProducts() on a non-object in classes/CartRule.php on line 565 I also tried to check the products in cart using below code in hookActionCartSave: $cart = $params['cart']; $prods = $cart->getProducts(); print("<pre>");print_r($cart); But when cart is empty there are no products in [products:protected] section and when I click on cart link, I am getting error on this statement "$prods = $cart->getProducts();" But if cart is not empty then I can see the product list in [products:protected]. And also I am not getting above error. Can you tell when does the code inside hookActionCartSave gets executed after the product is added in cart or before that. I guess the code is getting executed before adding the product to cart and so this is happening. Edited January 31, 2014 by pooja.gadkari (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts