/**
  * {@inheritdoc}
  */
 public function execute(BlockContextInterface $blockContext, Response $response = null)
 {
     $criteria = array();
     if ('admin' !== $blockContext->getSetting('mode')) {
         $criteria['customer'] = $this->customerManager->findOneBy(array('user' => $this->securityContext->getToken()->getUser()));
     }
     return $this->renderPrivateResponse($blockContext->getTemplate(), array('context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'orders' => $this->orderManager->findBy($criteria, array('createdAt' => 'DESC'), $blockContext->getSetting('number'))), $response);
 }
Beispiel #2
0
 /**
  * Get the customer.
  *
  * @throws \RuntimeException
  *
  * @return \Sonata\Component\Customer\CustomerInterface
  */
 public function get()
 {
     $customer = null;
     $user = null;
     if (true === $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         // user is authenticated
         $user = $this->securityContext->getToken()->getUser();
         if (!$user instanceof UserInterface) {
             throw new \RuntimeException('User must be an instance of FOS\\UserBundle\\Model\\UserInterface');
         }
         $customer = $this->customerManager->findOneBy(array('user' => $user->getId()));
     }
     if (!$customer) {
         $basket = $this->getBasket();
         if ($basket && $basket->getCustomer()) {
             $customer = $basket->getCustomer();
         }
     }
     if (!$customer) {
         $customer = $this->customerManager->create();
     }
     if (!$customer->getLocale()) {
         $customer->setLocale($this->locale);
     }
     if ($user && $customer) {
         $customer->setUser($user);
     }
     return $customer;
 }
 /**
  * Retrieves customer with id $id or throws an exception if it doesn't exist
  *
  * @param $id
  *
  * @return CustomerInterface
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 protected function getCustomer($id)
 {
     $customer = $this->customerManager->findOneBy(array('id' => $id));
     if (null === $customer) {
         throw new NotFoundHttpException(sprintf('Customer (%d) not found', $id));
     }
     return $customer;
 }