/** * @return Cart|null */ function merx_current_cart() { $cartId = session("merx_cart_id"); if (!$cartId) { return null; } return Cart::where("id", $cartId)->first(); }
/** * @return Cart */ private function getCartOrCreateNew() { $cart = merx_current_cart(); if (!$cart) { $cart = Cart::create(); session()->put("merx_cart_id", $cart->id); } return $cart; }
/** * @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); }
/** * @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(); } }
protected function createCartAndClient() { $cart = Cart::create(); session()->put("merx_cart_id", $cart->id); $cart->addItem(new CartItem($this->itemAttributes())); $this->loginClient(); }
private function newCart() { return Cart::create(); }
/** * @return Cart */ private function newCart() { $cart = Cart::create(); if (config("merx.uses_session", true)) { session()->put("merx_cart_id", $cart->id); } return $cart; }