Exemple #1
0
/**
 * @return Cart|null
 */
function merx_current_cart()
{
    $cartId = session("merx_cart_id");
    if (!$cartId) {
        return null;
    }
    return Cart::where("id", $cartId)->first();
}
Exemple #2
0
 /**
  * @return Cart
  */
 private function getCartOrCreateNew()
 {
     $cart = merx_current_cart();
     if (!$cart) {
         $cart = Cart::create();
         session()->put("merx_cart_id", $cart->id);
     }
     return $cart;
 }
Exemple #3
0
/**
 * @return Cart|null
 */
function merx_current_cart()
{
    if (!config("merx.uses_session", true)) {
        // If Merx can't use the session, there is no way
        // he could find the current Cart from nowhere
        return null;
    }
    $cartId = session("merx_cart_id");
    if (!$cartId) {
        return null;
    }
    return Cart::find($cartId);
}
Exemple #4
0
 /**
  * @param Cart $cart
  * @param bool $checkIfEmpty
  * @throws CartClosedException
  * @throws EmptyCartException
  * @throws NoCurrentCartException
  */
 private static function checkCartIsValid($cart, $checkIfEmpty = false)
 {
     if (!$cart) {
         throw new NoCurrentCartException();
     }
     if (!$cart->isOpened()) {
         throw new CartClosedException();
     }
     if ($checkIfEmpty && $cart->isEmpty()) {
         throw new EmptyCartException();
     }
 }
Exemple #5
0
 protected function createCartAndClient()
 {
     $cart = Cart::create();
     session()->put("merx_cart_id", $cart->id);
     $cart->addItem(new CartItem($this->itemAttributes()));
     $this->loginClient();
 }
Exemple #6
0
 private function newCart()
 {
     return Cart::create();
 }
Exemple #7
0
 /**
  * @return Cart
  */
 private function newCart()
 {
     $cart = Cart::create();
     if (config("merx.uses_session", true)) {
         session()->put("merx_cart_id", $cart->id);
     }
     return $cart;
 }