Наследование: extends Sonata\CoreBundle\Model\ManagerInterface, extends Sonata\CoreBundle\Model\PageableManagerInterface
 /**
  * {@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);
 }
 /**
  * Get the related Order.
  *
  * @param ConsumerEvent $event
  *
  * @throws \RuntimeException
  *
  * @return OrderInterface
  */
 protected function getOrder(ConsumerEvent $event)
 {
     $orderId = $event->getMessage()->getValue('order_id');
     $order = $this->orderManager->getOrder($orderId);
     if (!$order) {
         throw new \RuntimeException(sprintf('Unable to retrieve Order %d', $orderId));
     }
     return $order;
 }
Пример #3
0
 /**
  * Retrieves order with id $id or throws an exception if it doesn't exist.
  *
  * @param $id
  *
  * @return OrderInterface
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 protected function getOrder($id)
 {
     $order = $this->orderManager->findOneBy(array('id' => $id));
     if (null === $order) {
         throw new NotFoundHttpException(sprintf('Order (%d) not found', $id));
     }
     return $order;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     if (!$childAdmin && !in_array($action, array('edit'))) {
         return;
     }
     $admin = $this->isChild() ? $this->getParent() : $this;
     $id = $admin->getRequest()->get('id');
     $menu->addChild($this->trans('sonata.order.sidemenu.link_order_edit', array(), 'SonataOrderBundle'), array('uri' => $admin->generateUrl('edit', array('id' => $id))));
     $menu->addChild($this->trans('sonata.order.sidemenu.link_order_elements_list', array(), 'SonataOrderBundle'), array('uri' => $admin->generateUrl('sonata.order.admin.order_element.list', array('id' => $id))));
     $order = $this->orderManager->findOneBy(array('id' => $id));
     $invoice = $this->invoiceManager->findOneBy(array('reference' => $order->getReference()));
     if (null === $invoice) {
         $menu->addChild($this->trans('sonata.order.sidemenu.link_order_invoice_generate', array(), 'SonataOrderBundle'), array('uri' => $admin->generateUrl('generateInvoice', array('id' => $id))));
     } else {
         $menu->addChild($this->trans('sonata.order.sidemenu.link_order_invoice_edit', array(), 'SonataOrderBundle'), array('uri' => $admin->getRouteGenerator()->generate('admin_sonata_invoice_invoice_edit', array('id' => $invoice->getId()))));
     }
 }
Пример #5
0
 /**
  * Retrieves the order matching $transaction and adds it to $transaction
  *
  * @param TransactionInterface $transaction The request's transaction (will be linked to the order in the process)
  *
  * @return \Sonata\Component\Order\OrderInterface
  * @throws \Doctrine\ORM\EntityNotFoundException
  * @throws InvalidTransactionException
  */
 protected function getValidOrder(TransactionInterface $transaction)
 {
     $payment = $this->getPayment($transaction->getPaymentCode());
     // retrieve the related order
     $reference = $payment->getOrderReference($transaction);
     if (!$reference) {
         throw new InvalidTransactionException();
     }
     $order = $this->orderManager->findOneby(array('reference' => $reference));
     if (!$order) {
         throw new EntityNotFoundException(sprintf('Order %s', $reference));
     }
     $transaction->setOrder($order);
     // control the handshake value
     if (!$payment->isRequestValid($transaction)) {
         throw new InvalidTransactionException($order->getReference());
     }
     return $order;
 }
Пример #6
0
 /**
  * transform a basket into order.
  *
  * @throws \RuntimeException
  *
  * @param null|\Sonata\Component\Basket\BasketInterface $basket
  *
  * @return null|\Sonata\Component\Order\OrderInterface
  */
 public function transformIntoOrder(BasketInterface $basket)
 {
     $event = new BasketTransformEvent($basket);
     $this->eventDispatcher->dispatch(TransformerEvents::PRE_BASKET_TO_ORDER_TRANSFORM, $event);
     // Customer
     $customer = $basket->getCustomer();
     if (!$customer instanceof CustomerInterface) {
         if ($this->getLogger()) {
             $this->getLogger()->emergency('[Sonata\\Component\\Payment\\Transform\\Basket::transform] the customer is not valid');
         }
         throw new \RuntimeException('Invalid customer');
     }
     // Billing
     $billingAddress = $basket->getBillingAddress();
     if (!$billingAddress instanceof AddressInterface) {
         if ($this->getLogger()) {
             $this->getLogger()->emergency('[Sonata\\Component\\Payment\\Transform\\Basket::transform] the billing address is not valid');
         }
         throw new \RuntimeException('Invalid billing address');
     }
     $paymentMethod = $basket->getPaymentMethod();
     if (!$paymentMethod instanceof PaymentInterface) {
         if ($this->getLogger()) {
             $this->getLogger()->emergency('[Sonata\\Component\\Payment\\PaymentInterface::transform] the payment method is not valid');
         }
         throw new \RuntimeException('Invalid payment method');
     }
     // Shipping
     $deliveryMethod = $basket->getDeliveryMethod();
     if (!$deliveryMethod instanceof ServiceDeliveryInterface) {
         if ($this->getLogger()) {
             $this->getLogger()->emergency('[Sonata\\Component\\Delivery\\ServiceDeliveryInterface::transform] the delivery method is not valid');
         }
         throw new \RuntimeException('Invalid delivery method');
     }
     $deliveryAddress = $basket->getDeliveryAddress();
     if ($deliveryMethod->isAddressRequired() && !$deliveryAddress instanceof AddressInterface) {
         if ($this->getLogger()) {
             $this->getLogger()->emergency('[Sonata\\Component\\Delivery\\ServiceDeliveryInterface::transform] the shipping address is not valid');
         }
         throw new \RuntimeException('Invalid delivery address');
     }
     // add a custom class_instance for testing purpose.
     $order = $this->orderManager->create();
     $order->setCustomer($customer);
     $order->setUsername($customer->getFullname());
     $order->setLocale($customer->getLocale());
     if ($deliveryMethod->isAddressRequired()) {
         $order->setShippingAddress1($deliveryAddress->getAddress1());
         $order->setShippingAddress2($deliveryAddress->getAddress2());
         $order->setShippingAddress3($deliveryAddress->getAddress3());
         $order->setShippingPostcode($deliveryAddress->getPostcode());
         $order->setShippingCity($deliveryAddress->getCity());
         $order->setShippingCountryCode($deliveryAddress->getCountryCode());
         $order->setShippingName($deliveryAddress->getFirstname() . ' ' . $deliveryAddress->getLastname());
         $order->setShippingPhone($deliveryAddress->getPhone());
     }
     $order->setBillingAddress1($billingAddress->getAddress1());
     $order->setBillingAddress2($billingAddress->getAddress2());
     $order->setBillingAddress3($billingAddress->getAddress3());
     $order->setBillingPostcode($billingAddress->getPostcode());
     $order->setBillingCity($billingAddress->getCity());
     $order->setBillingCountryCode($billingAddress->getCountryCode());
     $order->setBillingName($billingAddress->getFirstname() . ' ' . $billingAddress->getLastname());
     $order->setBillingPhone($billingAddress->getPhone());
     $order->setTotalExcl($basket->getTotal());
     $order->setTotalInc($basket->getTotal(true));
     $order->setDeliveryVat($basket->getDeliveryVat());
     $order->setDeliveryCost($basket->getDeliveryPrice(true));
     $order->setDeliveryMethod($basket->getDeliveryMethod()->getCode());
     $order->setDeliveryStatus(ServiceDeliveryInterface::STATUS_OPEN);
     $order->setCreatedAt(new \DateTime());
     $order->setCurrency($basket->getCurrency());
     $order->setStatus(OrderInterface::STATUS_OPEN);
     $order->setPaymentStatus(TransactionInterface::STATUS_OPEN);
     $order->setPaymentMethod($basket->getPaymentMethod()->getCode());
     foreach ($basket->getBasketElements() as $basketElement) {
         $orderElement = $basketElement->getProductProvider()->createOrderElement($basketElement);
         if (!$orderElement instanceof OrderElementInterface) {
             continue;
         }
         $order->addOrderElement($orderElement);
     }
     $event = new OrderTransformEvent($order);
     $this->eventDispatcher->dispatch(TransformerEvents::POST_BASKET_TO_ORDER_TRANSFORM, $event);
     return $order;
 }
Пример #7
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));
 }