/** * 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; }
/** * Sets OrderType on an order. * * @param array $data * @param ApiOrderInterface $order * @param bool $patch * * @throws EntityNotFoundException * @throws OrderException */ private function setOrderType(array $data, ApiOrderInterface $order, $patch = false) { // Get OrderType. $type = $this->getProperty($data, 'type', $order->getType()); // Set order type. if (isset($data['type'])) { if (is_array($type) && isset($type['id'])) { // If provided as array. $typeId = $type['id']; } elseif (is_numeric($type)) { // If is numeric. $typeId = $type; } else { throw new OrderException('No typeid given'); } } elseif (!$patch) { // Default type is manual. $typeId = OrderType::MANUAL; } else { // Keep current type. return; } // Get entity. $orderType = $this->getOrderTypeEntityById($typeId); if (!$orderType) { throw new EntityNotFoundException(static::$orderTypeEntityName, $typeId); } // Set order type. $order->setType($orderType); }
/** * @return OrderInterface */ public function getOrder() { return $this->order->getEntity(); }
/** * @param ApiOrderInterface $apiOrder * * @return \Swift_Mime_Attachment */ protected function createXMLAttachment(ApiOrderInterface $apiOrder) { $xmlFilename = 'PA_OrderConfirmation-' . $apiOrder->getNumber() . '.xml'; $context = SerializationContext::create()->setGroups(['xmlOrder']); $context->setSerializeNull(true); $serialized = $this->serializer->serialize($apiOrder, 'xml', $context); return \Swift_Attachment::newInstance($serialized, $xmlFilename, 'application/xml'); }
/** * Remove all item delivery-addresses that are the same as the default * delivery address of the order * * @param ApiOrderInterface $order */ protected function removeItemAddressesThatAreEqualToOrderAddress($order) { $deliveryAddressId = $order->getDeliveryAddress()->getContactAddress()->getId(); foreach ($order->getItems() as $item) { $itemEntity = $item->getEntity(); $this->removeOrderAddressIfContactAddressIdIsEqualTo($itemEntity, $deliveryAddressId); } }