Jump to content

Customer::getLastCart()


deuterit

Recommended Posts

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 by deuterit (see edit history)
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...