/**
  * @return mixed
  * @throws Exception
  * @throws \Exception
  */
 public function getCart()
 {
     if (!isset($this->cart)) {
         $number = $this->_getSessionCartNumber();
         if ($cart = $this->_getCartRecordByNumber($number)) {
             $this->cart = Market_OrderModel::populateModel($cart);
         } else {
             $this->cart = new Market_OrderModel();
             $this->cart->number = $number;
         }
         $this->cart->lastIp = craft()->request->getIpAddress();
         // Update the cart if the customer has changed and recalculate the cart.
         $customer = craft()->market_customer->getCustomer();
         if ($customer->id) {
             if (!$this->cart->isEmpty() && $this->cart->customerId != $customer->id) {
                 $this->cart->customerId = $customer->id;
                 $this->cart->email = $customer->email;
                 $this->cart->billingAddressId = null;
                 $this->cart->shippingAddressId = null;
                 $this->cart->billingAddressData = null;
                 $this->cart->shippingAddressData = null;
                 craft()->market_order->save($this->cart);
             }
         }
     }
     return $this->cart;
 }