deuterit Posted September 30, 2014 Share Posted September 30, 2014 (edited) Hi all. I have trouble understanding behaviour of method Customer::getLastCart(). Could anyone explain me why this method returns false if cart has products number >0? Here's body of method: public function getLastCart($with_order = true) { $carts = Cart::getCustomerCarts((int)$this->id, $with_order); if (!count($carts)) return false; $cart = array_shift($carts); $cart = new Cart((int)$cart['id_cart']); return ($cart->nbProducts() === 0 ? (int)$cart->id : false); } It's a bug or feature? Edited September 30, 2014 by deuterit (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted September 30, 2014 Share Posted September 30, 2014 It seems the getLastCart function is only used by the Admin Carts Controller in the back office. It searches to see if a cart exists for a selected customer prior to allowing you to edit this cart. If I had to guess, it is designed this way to prevent you from changing a cart that may be used by a customer. So if there are products in the "last cart", then it will return false and would prevent the Admin Cart Controller from using it. 1 Link to comment Share on other sites More sharing options...
deuterit Posted September 30, 2014 Author Share Posted September 30, 2014 Yeah, I also noticed that this method is use in only one place. Your explanation make sense. This behaviour is just strange for me considering methods name and lack of description - it's not obvious. Thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts