/** * {@inheritdoc} */ public function save(BasketInterface $basket) { if ($basket->getCustomerId()) { $this->basketManager->save($basket); } else { $this->session->set(BasketSessionFactory::SESSION_BASE_NAME . 'new', $basket); } }
/** * {@inheritdoc} */ public function load(CustomerInterface $customer) { $basket = $this->getFromSession($customer); if (!$basket) { $basket = $this->basketManager->create(); $basket->setLocale($customer->getLocale()); $basket->setCurrency($this->currencyDetector->getCurrency()); } $basket->setCustomer($customer); $this->basketBuilder->build($basket); return $basket; }
/** * Throws an exception if it already exists a basket with a specific customer id. * * @param $customerId * * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ protected function checkExistingCustomerBasket($customerId) { $basket = $this->basketManager->findOneBy(array('customer' => $customerId)); if ($basket instanceof BasketInterface) { throw new HttpException('400', sprintf('Customer (%d) already has a basket', $customerId)); } }
/** * Retrieves basket with id $id or throws an exception if it doesn't exist * * @param $id * * @return BasketInterface * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ protected function getBasket($id) { $basket = $this->basketManager->findOneBy(array('id' => $id)); if (null === $basket) { throw new NotFoundHttpException(sprintf('Basket (%d) not found', $id)); } return $basket; }
/** * {@inheritdoc} */ public function load(CustomerInterface $customer) { $basket = $this->session->get($this->getSessionVarName($customer)); if (!$basket) { $basket = $this->session->get($this->getSessionVarName()); if (!$basket) { $basket = $this->basketManager->create(); $basket->setLocale($customer->getLocale()); $basket->setCurrency($this->currencyDetector->getCurrency()); } } $basket->setCustomer($customer); $this->basketBuilder->build($basket); // always clone the basket so it can be only saved by calling // the save method return clone $basket; }