예제 #1
0
 /**
  * Stock item saving.
  *
  * @return $this
  */
 protected function _saveStockItem()
 {
     /** @var $stockResource \Magento\CatalogInventory\Model\Resource\Stock\Item */
     $stockResource = $this->_stockResItemFac->create();
     $entityTable = $stockResource->getMainTable();
     while ($bunch = $this->_dataSourceModel->getNextBunch()) {
         $stockData = array();
         $productIdsToReindex = array();
         // Format bunch to stock data rows
         foreach ($bunch as $rowNum => $rowData) {
             if (!$this->isRowAllowedToImport($rowData, $rowNum)) {
                 continue;
             }
             // only SCOPE_DEFAULT can contain stock data
             if (self::SCOPE_DEFAULT != $this->getRowScope($rowData)) {
                 continue;
             }
             $row = array();
             $row['product_id'] = $this->_newSku[$rowData[self::COL_SKU]]['entity_id'];
             $productIdsToReindex[] = $row['product_id'];
             $row['stock_id'] = \Magento\CatalogInventory\Model\Stock\Item::DEFAULT_STOCK_ID;
             $stockItemDo = $this->stockItemService->getStockItem($row['product_id']);
             $existStockData = $stockItemDo->__toArray();
             $row = array_merge($this->defaultStockData, array_intersect_key($existStockData, $this->defaultStockData), array_intersect_key($rowData, $this->defaultStockData), $row);
             $row = $this->stockItemService->processIsInStock($row);
             if ($this->stockItemService->isQty($this->_newSku[$rowData[self::COL_SKU]]['type_id'])) {
                 if ($this->stockItemService->verifyNotification($row['product_id'])) {
                     $row['low_stock_date'] = $this->_localeDate->date(null, null, null, false)->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
                 }
                 $row['stock_status_changed_auto'] = (int) (!$this->stockItemService->verifyStock($row['product_id']));
             } else {
                 $row['qty'] = 0;
             }
             $stockData[] = $row;
         }
         // Insert rows
         if (!empty($stockData)) {
             $this->_connection->insertOnDuplicate($entityTable, $stockData);
         }
         if ($productIdsToReindex) {
             $this->newIndexer->load('catalog_product_category')->reindexList($productIdsToReindex);
         }
     }
     return $this;
 }
예제 #2
0
 /**
  * @param $indexId
  */
 protected function loadIndexer($indexId)
 {
     $this->configMock->expects($this->once())->method('getIndexer')->with($indexId)->will($this->returnValue($this->getIndexerData()));
     $this->model->load($indexId);
 }
예제 #3
0
 /**
  * Starting point for export
  * @throws \Exception
  */
 public function exportStores($exportProducts = true, $exportCustomers = true, $exportTransactions = true)
 {
     if ($this->getIndexerType() == 'delta' && $this->indexerModel->load('boxalino_indexer')->isWorking()) {
         return;
     }
     if ($this->getIndexerType() == 'full' && $this->indexerModel->load('boxalino_indexer_delta')->isWorking()) {
         return;
     }
     if ($this->getIndexerType() == 'delta') {
         if ($this->getDeltaIds() == null) {
             return;
         }
     }
     $this->logger->info("bxLog: starting exportStores");
     $this->config = new BxIndexConfig($this->storeManager->getWebsites());
     $this->logger->info("bxLog: retrieved index config: " . $this->config->toString());
     try {
         foreach ($this->config->getAccounts() as $account) {
             $this->logger->info("bxLog: initialize files on account: " . $account);
             $files = new BxFiles($this->filesystem, $account, $this->config, $this->_response);
             $bxClient = new \com\boxalino\bxclient\v1\BxClient($account, $this->config->getAccountPassword($account), "");
             $this->bxData = new \com\boxalino\bxclient\v1\BxData($bxClient, $this->config->getAccountLanguages($account), $this->config->isAccountDev($account), false);
             $this->logger->info("bxLog: verify credentials for account: " . $account);
             try {
                 $this->bxData->verifyCredentials();
             } catch (\Exception $e) {
                 $this->logger->info($e);
                 throw $e;
             }
             $this->logger->info('bxLog: Preparing the attributes and category data for each language of the account: ' . $account);
             $categories = array();
             foreach ($this->config->getAccountLanguages($account) as $language) {
                 $store = $this->config->getStore($account, $language);
                 $this->logger->info('bxLog: Start getStoreProductAttributes for language . ' . $language . ' on store:' . $store->getId());
                 $this->logger->info('bxLog: Start exportCategories for language . ' . $language . ' on store:' . $store->getId());
                 $categories = $this->exportCategories($store, $language, $categories);
             }
             $this->logger->info('bxLog: Export the customers, transactions and product files for account: ' . $account);
             if ($exportProducts) {
                 $exportProducts = $this->exportProducts($account, $files);
             }
             if ($this->getIndexerType() == 'full') {
                 if ($exportCustomers) {
                     $this->exportCustomers($account, $files);
                 }
                 if ($exportTransactions) {
                     $full = $exportProducts == false ? true : false;
                     $this->exportTransactions($account, $files, $full);
                 }
             }
             $this->prepareData($account, $files, $categories);
             $this->logger->info('prepareData finished');
             if (!$exportProducts) {
                 $this->logger->info('bxLog: No Products found for account: ' . $account);
                 $this->logger->info('bxLog: Finished account: ' . $account);
             } else {
                 if ($this->getIndexerType() == 'full') {
                     $this->logger->info('bxLog: Prepare the final files: ' . $account);
                     $this->logger->info('bxLog: Prepare XML configuration file: ' . $account);
                     try {
                         $this->logger->info('bxLog: Push the XML configuration file to the Data Indexing server for account: ' . $account);
                         $this->bxData->pushDataSpecifications();
                     } catch (\Exception $e) {
                         $value = @json_decode($e->getMessage(), true);
                         if (isset($value['error_type_number']) && $value['error_type_number'] == 3) {
                             $this->logger->info('bxLog: Try to push the XML file a second time, error 3 happens always at the very first time but not after: ' . $account);
                             $this->bxData->pushDataSpecifications();
                         } else {
                             throw $e;
                         }
                     }
                     $this->logger->info('bxLog: Publish the configuration chagnes from the magento2 owner for account: ' . $account);
                     $publish = $this->config->publishConfigurationChanges($account);
                     $changes = $this->bxData->publishChanges($publish);
                     if (sizeof($changes['changes']) > 0 && !$publish) {
                         $this->logger->warning("changes in configuration detected butnot published as publish configuration automatically option has not been activated for account: " . $account);
                     }
                     $this->logger->info('bxLog: Push the Zip data file to the Data Indexing server for account: ' . $account);
                 }
                 $this->logger->info('pushing to DI');
                 try {
                     $this->bxData->pushData();
                 } catch (\Exception $e) {
                     $this->logger->info($e);
                     throw $e;
                 }
                 $this->logger->info('bxLog: Finished account: ' . $account);
             }
         }
     } catch (\Exception $e) {
         $this->logger->info("bxLog: failed with exception: " . $e->getMessage());
     }
     $this->logger->info("bxLog: finished exportStores");
 }