コード例 #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;
 }
コード例 #2
0
ファイル: Orders.php プロジェクト: buttasg/cowgirlk
 /**
  * getting orders for the customer filtered by given data 
  * 
  * @param $customerToken
  * @param $limit
  * @param $offset
  * @param $orderDateFrom
  * @param $sortOrder
  * @return array
  * @throws ShopgateLibraryException
  */
 public function getOrders($customerToken, $limit, $offset, $orderDateFrom, $sortOrder)
 {
     $relation = Mage::getModel('shopgate/customer')->loadByToken($customerToken);
     $response = array();
     if ($relation->getId()) {
         $sort = str_replace('created_', '', $sortOrder);
         $_orders = Mage::getModel('sales/order')->getCollection()->addFieldToSelect('*');
         if ($orderDateFrom) {
             $_orders->addFieldToFilter('created_at', array('from' => date('Y-m-d H:i:s', strtotime($orderDateFrom))));
         }
         $_orders->addFieldToFilter('customer_id', $relation->getCustomerId())->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))->setOrder('created_at', $sort);
         $_orders->getSelect()->limit($limit, $offset);
         if ($_orders->count() > 0) {
             /** @var Mage_Sales_Model_Order $order */
             foreach ($_orders as $order) {
                 /** @var Shopgate_Framework_Model_Shopgate_Order $shopgateOrder */
                 $shopgateOrder = $this->_getShopgateOrderNumber($order->getId());
                 $shopgateExternalOrder = new ShopgateExternalOrder();
                 $shopgateExternalOrder->setOrderNumber($shopgateOrder ? $shopgateOrder->getShopgateOrderNumber() : null);
                 $shopgateExternalOrder->setExternalOrderId($order->getId());
                 $shopgateExternalOrder->setExternalOrderNumber($order->getIncrementId());
                 $shopgateExternalOrder->setCreatedTime(date(DateTime::ISO8601, strtotime($order->getCreatedAt())));
                 $shopgateExternalOrder->setMail($order->getCustomerEmail());
                 $shopgateExternalOrder->setCurrency($order->getOrderCurrencyCode());
                 $shopgateExternalOrder->setPaymentMethod($order->getPayment()->getMethodInstance()->getTitle());
                 $shopgateExternalOrder->setIsPaid($shopgateOrder ? $shopgateOrder->getIsPaid() : null);
                 $shopgateExternalOrder->setPaymentTransactionNumber($this->_getPaymentTransactionNumber($order));
                 $shopgateExternalOrder->setAmountComplete($order->getGrandTotal());
                 $shopgateExternalOrder->setInvoiceAddress($this->_getShopgateAddressFromOrderAddress($order->getBillingAddress()));
                 $shopgateExternalOrder->setDeliveryAddress($this->_getShopgateAddressFromOrderAddress($order->getShippingAddress()));
                 $shopgateExternalOrder->setItems($this->_getOrderItemsFormatted($order));
                 $shopgateExternalOrder->setOrderTaxes($this->_getOrderTaxFormatted($order));
                 $shopgateExternalOrder->setDeliveryNotes($this->_getDeliveryNotes($order));
                 $shopgateExternalOrder->setExternalCoupons($this->_getCouponsFormatted($order));
                 $shopgateExternalOrder->setStatusName(ucwords(str_replace('_', ' ', $order->getStatus())));
                 $shopgateExternalOrder->setExtraCosts($this->_getExtraCost($order));
                 array_push($response, $shopgateExternalOrder);
             }
         }
         return $response;
     } else {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_CUSTOMER_TOKEN_INVALID);
     }
 }
コード例 #3
0
ファイル: core.php プロジェクト: buttasg/cowgirlk
 public function visitExternalOrder(ShopgateExternalOrder $o)
 {
     // get properties
     $properties = $o->buildProperties();
     // iterate the simple variables
     $properties = $this->iterateSimpleProperties($properties);
     // visit invoice address
     if (!empty($properties['invoice_address']) && $properties['invoice_address'] instanceof ShopgateAddress) {
         $properties['invoice_address']->accept($this);
         $properties['invoice_address'] = $this->array;
     }
     // visit delivery address
     if (!empty($properties['delivery_address']) && $properties['delivery_address'] instanceof ShopgateAddress) {
         $properties['delivery_address']->accept($this);
         $properties['delivery_address'] = $this->array;
     }
     // visit the items and delivery notes arrays
     $properties['custom_fields'] = $this->iterateObjectList($properties['custom_fields']);
     $properties['external_coupons'] = $this->iterateObjectList($properties['external_coupons']);
     $properties['items'] = $this->iterateObjectList($properties['items']);
     $properties['delivery_notes'] = $this->iterateObjectList($properties['delivery_notes']);
     $properties['order_taxes'] = $this->iterateObjectList($properties['order_taxes']);
     $properties['extra_costs'] = $this->iterateObjectList($properties['extra_costs']);
     // set last value to converted array
     $this->array = $properties;
 }