/** * Process a single order * * @param ZenMagick\StoreBundle\Entity\Order\Order order The order. * @return array List of rows. */ protected function processOrder(Order $order) { $orderTotalLines = $order->getOrderTotalLines(); $shippingAmount = 0; $couponAmount = 0; $gvAmount = 0; foreach ($orderTotalLines as $orderTotalLine) { if ('ot_shipping' == $orderTotalLine->getType()) { $shippingAmount = $orderTotalLine->getAmount(); } elseif ('ot_coupon' == $orderTotalLine->getType()) { $couponAmount = $orderTotalLine->getAmount(); } elseif ('ot_gv' == $orderTotalLine->getType()) { $gvAmount = $orderTotalLine->getAmount(); } } unset($orderTotalLines); $shippingCountry = null; if (null != ($shippingAddress = $order->getShippingAddress())) { $shippingCountry = $shippingAddress->getCountry(); } $rows = array(); // each line has a product, // first line also the general details, // last line the totals $firstRow = true; $lastRow = false; $productsTotal = 0; $orderItems = $order->getOrderItems(); for ($ii = 0; $ii < count($orderItems); ++$ii) { $orderItem = $orderItems[$ii]; $lastRow = $ii == count($orderItems) - 1; $row = array(); if ($firstRow) { $row[] = $this->container->get('localeService')->shortDate($order->getOrderDate()); $row[] = $order->getId(); $row[] = trim($order->getAccount()->getFullName()); $row[] = null != $shippingCountry ? $shippingCountry->getName() : ''; } else { $row[] = ''; $row[] = ''; $row[] = ''; $row[] = ''; } $firstRow = false; $quantity = $orderItem->getQuantity(); $itemTotal = $orderItem->getCalculatedPrice(false); // no tax $lineTotal = $itemTotal * $quantity; $productsTotal += $lineTotal; $row[] = $products[] = $orderItem->getProductId() . ':' . $orderItem->getName(); $row[] = $quantity; $row[] = $lineTotal / $quantity; $row[] = $lineTotal; if ($lastRow) { $row[] = $productsTotal; $row[] = $shippingAmount; $row[] = $couponAmount; $row[] = $order->get('coupon_code'); $row[] = $gvAmount; $row[] = $order->get('payment_method'); $row[] = $order->get('order_tax'); $row[] = $order->getTotal(); } else { $row[] = ''; $row[] = ''; $row[] = ''; $row[] = ''; $row[] = ''; $row[] = ''; $row[] = ''; $row[] = ''; } $rows[] = $row; } return $rows; }
/** * Create new instance. */ public function __construct() { parent::__construct(); $this->setId(3); $this->setOrderDate(time()); }