コード例 #1
0
 /**
  * Get the name of the session variable
  *
  * @param  \Sonata\Component\Customer\CustomerInterface $customer
  * @return string
  */
 protected function getSessionVarName(CustomerInterface $customer = null)
 {
     if (null === $customer || null === $customer->getId()) {
         return self::SESSION_BASE_NAME . "new";
     }
     return self::SESSION_BASE_NAME . $customer->getId();
 }
コード例 #2
0
ファイル: BasketManager.php プロジェクト: lzdv/ecommerce
 /**
  * {@inheritdoc}
  */
 public function loadBasketPerCustomer(CustomerInterface $customer)
 {
     try {
         return $this->getRepository()->createQueryBuilder('b')->leftJoin('b.basketElements', 'be', null, null, 'be.position')->where('b.customer = :customer')->setParameter('customer', $customer->getId())->getQuery()->getSingleResult();
     } catch (NoResultException $e) {
         return null;
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function load(CustomerInterface $customer)
 {
     $basket = null;
     if ($customer->getId()) {
         $basket = $this->basketManager->loadBasketPerCustomer($customer);
     }
     if (!$basket) {
         $basket = $this->loadFromSession();
         if (!$basket) {
             $basket = $this->basketManager->create();
             $basket->setLocale($customer->getLocale());
             $basket->setCurrency($this->currencyDetector->getCurrency());
         }
     }
     $basket->setCustomer($customer);
     $this->basketBuilder->build($basket);
     return $basket;
 }
コード例 #4
0
 /**
  * Checks that the current logged in user has access to given invoice
  *
  * @param CustomerInterface $customer The linked customer
  *
  * @throws AccessDeniedException
  */
 protected function checkAccess(CustomerInterface $customer)
 {
     if (!($user = $this->getUser()) || !$customer->getUser() || $customer->getUser()->getId() !== $user->getId()) {
         throw new AccessDeniedException();
     }
 }
コード例 #5
0
ファイル: Basket.php プロジェクト: Dicoding/ecommerce
 /**
  * {@inheritdoc}
  */
 public function setCustomer(CustomerInterface $customer = null)
 {
     $this->customer = $customer;
     $this->customerId = $customer ? $customer->getId() : null;
 }