/** * 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(); }
/** * {@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; } }
/** * {@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; }
/** * 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(); } }
/** * {@inheritdoc} */ public function setCustomer(CustomerInterface $customer = null) { $this->customer = $customer; $this->customerId = $customer ? $customer->getId() : null; }