예제 #1
0
 public function getOrders($customerToken, $customerLanguage, $limit, $offset, $orderDateFrom, $sortOrder)
 {
     $shopgateCustomerModel = new ShopgateCustomerPrestashop();
     $this->_currentCustomer = $shopgateCustomerModel->getCustomerByToken($customerToken);
     if (!$this->_currentCustomer->validateFields(false)) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_CUSTOMER_TOKEN_INVALID);
     }
     $orders = $this->getCustomerOrders($this->_currentCustomer->id, $limit, $offset, $orderDateFrom, $sortOrder);
     foreach ($orders as $orderItem) {
         /** @var OrderCore $orderCore */
         $orderCore = new Order($orderItem['id_order']);
         $order = new ShopgateExternalOrder();
         $order->setOrderNumber($orderCore->id);
         $order->setExternalOrderNumber($orderCore->reference);
         $order->setExternalOrderId($orderCore->id);
         /** @var OrderStateCore $orderStatus */
         $orderStatus = new OrderState($orderCore->getCurrentState());
         $order->setStatusName($orderStatus->name[$this->getPlugin()->getLanguageId()]);
         $order->setStatusColor($orderStatus->color);
         $order->setCreatedTime($orderCore->date_add);
         $order->setMail($this->_currentCustomer->email);
         $order->setDeliveryAddress($this->_getAddress($orderCore->id_address_delivery, ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_DELIVERY));
         $order->setInvoiceAddress($this->_getAddress($orderCore->id_address_invoice, ShopgateCustomerPrestashop::DEFAULT_CUSTOMER_ADDRESS_IDENTIFIER_DELIVERY));
         $order->setItems($this->_getOrderItems($orderCore));
         $order->setExternalCoupons($this->_getCartRules($orderCore));
         /** @var CurrencyCore $currency */
         $currency = Currency::getCurrency($orderCore->id_currency);
         $order->setCurrency($currency['iso_code']);
         $order->setAmountComplete(isset($orderCore->total_paid_tax_incl) ? $orderCore->total_paid_tax_incl : $orderCore->total_paid);
         $order->setIsPaid($orderCore->hasBeenPaid());
         $order->setPaymentMethod($orderCore->payment);
         $order->setIsShippingCompleted($orderCore->hasBeenShipped());
         $order->setShippingCompletedTime($orderCore->hasBeenShipped() ? $orderCore->delivery_date : null);
         $order->setDeliveryNotes($this->_getDeliveryNotes($orderCore));
         $order->setExtraCosts($this->_getExtraCost($orderCore));
         $order->setOrderTaxes($this->_getOrderTaxes());
         $this->_result[] = $order;
     }
     return $this->_result;
 }