コード例 #1
0
 /**
  * Get all orders to import.
  *
  * @param            $website
  * @param int        $limit
  * @param bool|false $modified
  *
  * @return array
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getConnectorOrders($website, $limit = 100, $modified = false)
 {
     $orders = [];
     $storeIds = $website->getStoreIds();
     $orderModel = $this->orderFactory->create();
     if (empty($storeIds)) {
         return [];
     }
     $orderStatuses = $this->helper->getConfigSelectedStatus($website);
     //any statuses found
     if ($orderStatuses) {
         if ($modified) {
             $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses, true);
         } else {
             $orderCollection = $orderModel->getOrdersToImport($storeIds, $limit, $orderStatuses);
         }
     } else {
         return [];
     }
     try {
         //email_order order ids
         $orderIds = $orderCollection->getColumnValues('order_id');
         //get the order collection
         $salesOrderCollection = $this->salesOrderFactory->create()->getCollection()->addFieldToFilter('entity_id', ['in' => $orderIds]);
         foreach ($salesOrderCollection as $order) {
             $storeId = $order->getStoreId();
             $websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
             /**
              * Add guest to contacts table.
              */
             if ($order->getCustomerIsGuest() && $order->getCustomerEmail()) {
                 //add guest to the list
                 $this->guests[] = ['email' => $order->getCustomerEmail(), 'website_id' => $websiteId, 'store_id' => $storeId, 'is_guest' => 1];
             }
             if ($order->getId()) {
                 $connectorOrder = $this->connectorOrderFactory->create();
                 $connectorOrder->setOrderData($order);
                 $orders[] = $connectorOrder;
             }
             if ($modified) {
                 $this->orderIdsForSingleSync[] = $order->getId();
             } else {
                 $this->orderIds[] = $order->getId();
             }
         }
     } catch (\Exception $e) {
         $this->helper->debug((string) $e, []);
     }
     return $orders;
 }