/** * Find and fetches saved cart. * If cart is not found - returns new empty one. * * @param $id string Id of cart to fetch. * * @return \Jigoshop\Entity\Cart Prepared cart instance. */ public function get($id) { if (!isset($this->carts[$id])) { $cart = new Cart($this->options->get('tax.classes')); $cart->setCustomer($this->customerService->getCurrent()); $cart->getCustomer()->selectTaxAddress($this->options->get('taxes.shipping') ? 'shipping' : 'billing'); // Fetch data from session if available $cart->setId($id); $state = $this->getStateFromSession($id); if (isset($_POST['jigoshop_order']) && Pages::isCheckout()) { $state = $this->getStateFromCheckout($state); } // TODO: Support for transients? $cart = $this->orderFactory->fill($cart, $state); $this->carts[$id] = $this->wp->applyFilters('jigoshop\\service\\cart\\get', $cart, $state); } return $this->carts[$id]; }
/** * Checks whether user is allowed to see checkout page. * * @param CartEntity $cart The cart. * * @return bool Is user allowed to enter checkout page? */ private function isAllowedToCheckout(CartEntity $cart) { return $this->options->get('shopping.guest_purchases') || $this->wp->isUserLoggedIn() || $this->options->get('shopping.allow_registration') && $cart->getCustomer()->getId() > 0; }