Esempio n. 1
0
 /**
  * Converts the status of an order.
  *
  * @param ApiOrderInterface $apiOrder
  * @param int $statusId
  * @param bool $flush
  * @param bool $persist
  *
  * @throws EntityNotFoundException
  */
 public function convertStatus(ApiOrderInterface $apiOrder, $statusId, $flush = false, $persist = true)
 {
     if ($apiOrder instanceof Order) {
         $order = $apiOrder->getEntity();
     }
     // Get current status.
     $currentStatus = $order->getStatus();
     if ($currentStatus) {
         if ($currentStatus instanceof \Massive\Bundle\Purchase\OrderBundle\Api\OrderStatus) {
             $currentStatus = $order->getStatus()->getEntity();
         }
         // If status has not changed, skip.
         if ($currentStatus->getId() === $statusId) {
             return;
         }
     }
     // Get desired status.
     $statusEntity = $this->em->getRepository(self::$orderStatusEntityName)->find($statusId);
     if (!$statusEntity) {
         throw new EntityNotFoundException(self::$orderStatusEntityName, $statusId);
     }
     // ACTIVITY LOG.
     $orderActivity = new OrderActivityLog();
     $orderActivity->setOrder($order);
     if ($currentStatus) {
         $orderActivity->setStatusFrom($currentStatus);
     }
     $orderActivity->setStatusTo($statusEntity);
     $orderActivity->setCreated(new \DateTime());
     if ($persist) {
         $this->em->persist($orderActivity);
     }
     // BITMASK.
     $currentBitmaskStatus = $order->getBitmaskStatus();
     // If desired status already is in bitmask, remove current state
     // since this is a step back.
     if ($currentBitmaskStatus && $currentBitmaskStatus & $statusEntity->getId()) {
         $order->setBitmaskStatus($currentBitmaskStatus & ~$currentStatus->getId());
     } else {
         // Else increment bitmask status.
         $order->setBitmaskStatus($currentBitmaskStatus | $statusEntity->getId());
     }
     $order->setStatus($statusEntity);
     if ($flush === true) {
         $this->em->flush();
     }
     $this->eventDispatcher->dispatch(SalesOrderEvents::STATUS_CHANGED, new SalesOrderStatusChangedEvent($apiOrder));
 }
Esempio n. 2
0
 /**
  * Function that sets data array for pdf rendering.
  *
  * @param ApiOrderInterface $apiOrder
  *
  * @return array
  */
 protected function getContentForPdf(ApiOrderInterface $apiOrder)
 {
     $order = $apiOrder->getEntity();
     $customerNumber = null;
     if ($order->getCustomerAccount()) {
         $customerNumber = $order->getCustomerAccount()->getNumber();
     } else {
         $customerNumber = sprintf('%05d', $order->getCustomerContact()->getId());
     }
     $data = ['recipient' => $order->getDeliveryAddress(), 'responsibleContact' => $order->getResponsibleContact(), 'deliveryAddress' => $order->getDeliveryAddress(), 'customerContact' => $order->getCustomerContact(), 'billingAddress' => $order->getInvoiceAddress(), 'order' => $order, 'customerNumber' => $customerNumber, 'orderApiEntity' => $apiOrder, 'itemApiEntities' => $apiOrder->getItems(), 'templateBasePath' => $this->templateBasePath, 'templateMacrosPath' => $this->templateMacrosPath, 'website_locale' => $this->websiteLocale];
     return $data;
 }
 /**
  * @return OrderInterface
  */
 public function getOrder()
 {
     return $this->order->getEntity();
 }