/**
  * {@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);
 }
Пример #2
0
 /**
  * Returns a paginated list of orders.
  *
  * @ApiDoc(
  *  resource=true,
  *  output={"class"="Sonata\Component\Order\OrderInterface", "groups"="sonata_api_read"}
  * )
  *
  * @QueryParam(name="page", requirements="\d+", default="1", description="Page for orders list pagination (1-indexed)")
  * @QueryParam(name="count", requirements="\d+", default="10", description="Number of orders by page")
  * @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query orders order by clause (key is field, value is direction")
  * @QueryParam(name="status", requirements="\d+", nullable=true, strict=true, description="Filter on order statuses")
  *
  * @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
  *
  * @param ParamFetcherInterface $paramFetcher
  *
  * @return OrderInterface[]
  */
 public function getOrdersAction(ParamFetcherInterface $paramFetcher)
 {
     $supportedFilters = array('status' => "");
     $page = $paramFetcher->get('page') - 1;
     $count = $paramFetcher->get('count');
     $orderBy = $paramFetcher->get('orderBy');
     $filters = array_intersect_key($paramFetcher->all(), $supportedFilters);
     foreach ($filters as $key => $value) {
         if (null === $value) {
             unset($filters[$key]);
         }
     }
     return $this->orderManager->findBy($filters, $orderBy, $count, $page);
 }
Пример #3
0
 /**
  * Retrieves a specific customer's orders
  *
  * @ApiDoc(
  *  requirements={
  *      {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="customer id"}
  *  },
  *  output={"class"="Sonata\Component\Order\OrderInterface", "groups"="sonata_api_read"},
  *  statusCodes={
  *      200="Returned when successful",
  *      404="Returned when customer is not found"
  *  }
  * )
  *
  * @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
  *
  * @param $id
  *
  * @return OrderInterface
  */
 public function getCustomerOrdersAction($id)
 {
     $customer = $this->getCustomer($id);
     return $this->orderManager->findBy(array('customer' => $customer));
 }