コード例 #1
0
ファイル: Option.php プロジェクト: pradeep-wagento/magento2
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Get new supper attribute id.
  *
  * @return int
  */
 protected function _getNextAttrId()
 {
     if (!$this->_nextAttrId) {
         $mainTable = $this->_resource->getTableName('catalog_product_super_attribute');
         $this->_nextAttrId = $this->_resourceHelper->getNextAutoincrement($mainTable);
     }
     $this->_nextAttrId++;
     return $this->_nextAttrId;
 }
コード例 #3
0
 /**
  * Validate data rows and save bunches to DB.
  *
  * @return $this|void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _saveValidatedBunches()
 {
     $source = $this->_getSource();
     $currentDataSize = 0;
     $bunchRows = [];
     $startNewBunch = false;
     $nextRowBackup = [];
     $maxDataSize = $this->_resourceHelper->getMaxDataSize();
     $bunchSize = $this->_importExportData->getBunchSize();
     $source->rewind();
     $this->_dataSourceModel->cleanBunches();
     while ($source->valid() || $bunchRows) {
         if ($startNewBunch || !$source->valid()) {
             $this->_dataSourceModel->saveBunch($this->getEntityTypeCode(), $this->getBehavior(), $bunchRows);
             $bunchRows = $nextRowBackup;
             $currentDataSize = strlen(serialize($bunchRows));
             $startNewBunch = false;
             $nextRowBackup = [];
         }
         if ($source->valid()) {
             try {
                 $rowData = $source->current();
             } catch (\InvalidArgumentException $e) {
                 $this->addRowError($e->getMessage(), $this->_processedRowsCount);
                 $this->_processedRowsCount++;
                 $source->next();
                 continue;
             }
             $this->_processedRowsCount++;
             if ($this->validateRow($rowData, $source->key())) {
                 // add row to bunch for save
                 $rowData = $this->_prepareRowForDb($rowData);
                 $rowSize = strlen($this->jsonHelper->jsonEncode($rowData));
                 $isBunchSizeExceeded = $bunchSize > 0 && count($bunchRows) >= $bunchSize;
                 if ($currentDataSize + $rowSize >= $maxDataSize || $isBunchSizeExceeded) {
                     $startNewBunch = true;
                     $nextRowBackup = [$source->key() => $rowData];
                 } else {
                     $bunchRows[$source->key()] = $rowData;
                     $currentDataSize += $rowSize;
                 }
             }
             $source->next();
         }
     }
     return $this;
 }
コード例 #4
0
ファイル: Address.php プロジェクト: whoople/magento2-testing
 /**
  * Get next address entity ID
  *
  * @return int
  */
 protected function _getNextEntityId()
 {
     if (!$this->_nextEntityId) {
         /** @var $addressResource \Magento\Customer\Model\ResourceModel\Address */
         $addressResource = $this->_addressFactory->create()->getResource();
         $addressTable = $addressResource->getEntityTable();
         $this->_nextEntityId = $this->_resourceHelper->getNextAutoincrement($addressTable);
     }
     return $this->_nextEntityId++;
 }
コード例 #5
0
 /**
  * @param \Magento\Framework\Stdlib\StringUtils $string
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\ImportExport\Model\ImportFactory $importFactory
  * @param \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper
  * @param \Magento\Framework\App\ResourceConnection $resource
  * @param ProcessingErrorAggregatorInterface $errorAggregator
  * @param array $data
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function __construct(\Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\ImportExport\Model\ImportFactory $importFactory, \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper, ResourceConnection $resource, ProcessingErrorAggregatorInterface $errorAggregator, array $data = [])
 {
     $this->_scopeConfig = $scopeConfig;
     $this->_dataSourceModel = isset($data['data_source_model']) ? $data['data_source_model'] : $importFactory->create()->getDataSourceModel();
     $this->_connection = isset($data['connection']) ? $data['connection'] : $resource->getConnection();
     $this->string = $string;
     $this->_pageSize = isset($data['page_size']) ? $data['page_size'] : (static::XML_PATH_PAGE_SIZE ? (int) $this->_scopeConfig->getValue(static::XML_PATH_PAGE_SIZE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) : 0);
     $this->_maxDataSize = isset($data['max_data_size']) ? $data['max_data_size'] : $resourceHelper->getMaxDataSize();
     $this->_bunchSize = isset($data['bunch_size']) ? $data['bunch_size'] : (static::XML_PATH_BUNCH_SIZE ? (int) $this->_scopeConfig->getValue(static::XML_PATH_BUNCH_SIZE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) : 0);
     $this->errorAggregator = $errorAggregator;
     foreach ($this->errorMessageTemplates as $errorCode => $message) {
         $this->getErrorAggregator()->addErrorMessageTemplate($errorCode, $message);
     }
 }
コード例 #6
0
ファイル: Customer.php プロジェクト: tingyeeh/magento2
 /**
  * Retrieve next customer entity id
  *
  * @return int
  */
 protected function _getNextEntityId()
 {
     if (!$this->_nextEntityId) {
         $this->_nextEntityId = $this->_resourceHelper->getNextAutoincrement($this->_entityTable);
     }
     return $this->_nextEntityId++;
 }