/** * 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; } }
/** * Import data rows * * @return boolean * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ 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 = []; $options = []; $titles = []; $prices = []; $typeValues = []; $typePrices = []; $typeTitles = []; $parentCount = []; $childCount = []; foreach ($bunch as $rowNumber => $rowData) { $multiRowData = $this->_getMultiRowFormat($rowData); foreach ($multiRowData as $optionData) { $combinedData = array_merge($rowData, $optionData); if (!$this->isRowAllowedToImport($combinedData, $rowNumber)) { continue; } if (!$this->_parseRequiredData($combinedData)) { continue; } $optionData = $this->_collectOptionMainData($combinedData, $prevOptionId, $nextOptionId, $products, $prices); if ($optionData != null) { $options[] = $optionData; } $this->_collectOptionTypeData($combinedData, $prevOptionId, $nextValueId, $typeValues, $typePrices, $typeTitles, $parentCount, $childCount); $this->_collectOptionTitle($combinedData, $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; }