Example #1
0
 /**
  * Get next bunch of validated rows.
  *
  * @return array|null
  */
 public function getNextBunch()
 {
     $bunchRows = parent::getNextBunch();
     if ($bunchRows != null) {
         $rows = [];
         foreach ($bunchRows as $rowNumber => $rowData) {
             $rowData = $this->_prepareRow($rowData);
             if ($rowData !== null) {
                 unset($rowData['_scope']);
                 $rows[$rowNumber] = $rowData;
             }
         }
         return $rows;
     } else {
         return $bunchRows;
     }
 }
Example #2
0
 /**
  * Import data rows
  *
  * @return boolean
  */
 protected function _importData()
 {
     $this->_initProductsSku();
     $nextOptionId = $this->_resourceHelper->getNextAutoincrement($this->_tables['catalog_product_option']);
     $nextValueId = $this->_resourceHelper->getNextAutoincrement($this->_tables['catalog_product_option_type_value']);
     $prevOptionId = 0;
     while ($bunch = $this->_dataSourceModel->getNextBunch()) {
         $products = array();
         $options = array();
         $titles = array();
         $prices = array();
         $typeValues = array();
         $typePrices = array();
         $typeTitles = array();
         foreach ($bunch as $rowNumber => $rowData) {
             if (!$this->isRowAllowedToImport($rowData, $rowNumber)) {
                 continue;
             }
             if (!$this->_parseRequiredData($rowData)) {
                 continue;
             }
             $optionData = $this->_collectOptionMainData($rowData, $prevOptionId, $nextOptionId, $products, $prices);
             if ($optionData != null) {
                 $options[] = $optionData;
             }
             $this->_collectOptionTypeData($rowData, $prevOptionId, $nextValueId, $typeValues, $typePrices, $typeTitles);
             $this->_collectOptionTitle($rowData, $prevOptionId, $titles);
         }
         // Save prepared custom options data !!!
         if ($this->getBehavior() != \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND) {
             $this->_deleteEntities(array_keys($products));
         }
         if ($this->_isReadyForSaving($options, $titles, $typeValues)) {
             if ($this->getBehavior() == \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND) {
                 $this->_compareOptionsWithExisting($options, $titles, $prices, $typeValues);
             }
             $this->_saveOptions($options)->_saveTitles($titles)->_savePrices($prices)->_saveSpecificTypeValues($typeValues)->_saveSpecificTypePrices($typePrices)->_saveSpecificTypeTitles($typeTitles)->_updateProducts($products);
         }
     }
     return true;
 }