Example #1
0
 /**
  * @return $this
  */
 protected function _initTypeModels()
 {
     $entityTypes = ['simple' => ['model' => 'simple_product', 'params' => []]];
     $productTypeInstance = $this->getMockBuilder('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\AbstractType')->disableOriginalConstructor()->getMock();
     $productTypeInstance->expects($this->once())->method('isSuitable')->willReturn(true);
     $productTypeInstance->expects($this->once())->method('getParticularAttributes')->willReturn([]);
     $productTypeInstance->expects($this->once())->method('getCustomFieldsMapping')->willReturn([]);
     $this->_importConfig->expects($this->once())->method('getEntityTypes')->with(self::ENTITY_TYPE_CODE)->willReturn($entityTypes);
     $this->_productTypeFactory->expects($this->once())->method('create')->willReturn($productTypeInstance);
     return $this;
 }
Example #2
0
 /**
  * Initialize product type models.
  *
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _initTypeModels()
 {
     $productTypes = $this->_importConfig->getEntityTypes($this->getEntityTypeCode());
     foreach ($productTypes as $productTypeName => $productTypeConfig) {
         $params = [$this, $productTypeName];
         if (!($model = $this->_productTypeFactory->create($productTypeConfig['model'], ['params' => $params]))) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Entity type model \'%1\' is not found', $productTypeConfig['model']));
         }
         if (!$model instanceof \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Entity type model must be an instance of ' . 'Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\AbstractType'));
         }
         if ($model->isSuitable()) {
             $this->_productTypeModels[$productTypeName] = $model;
         }
         $this->_fieldsMap = array_merge($this->_fieldsMap, $model->getCustomFieldsMapping());
         $this->_specialAttributes = array_merge($this->_specialAttributes, $model->getParticularAttributes());
     }
     $this->_initErrorTemplates();
     // remove doubles
     $this->_specialAttributes = array_unique($this->_specialAttributes);
     return $this;
 }
Example #3
0
 /**
  * Initialize product type models.
  *
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _initTypeModels()
 {
     $productTypes = $this->_importConfig->getEntityTypes($this->getEntityTypeCode());
     foreach ($productTypes as $productTypeName => $productTypeConfig) {
         $params = array($this, $productTypeName);
         if (!($model = $this->_productTypeFactory->create($productTypeConfig['model'], array('params' => $params)))) {
             throw new \Magento\Framework\Model\Exception(sprintf("Entity type model '%s' is not found", $productTypeConfig['model']));
         }
         if (!$model instanceof \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType) {
             throw new \Magento\Framework\Model\Exception(__('Entity type model must be an instance of ' . 'Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\AbstractType'));
         }
         if ($model->isSuitable()) {
             $this->_productTypeModels[$productTypeName] = $model;
         }
         $this->_specialAttributes = array_merge($this->_specialAttributes, $model->getParticularAttributes());
     }
     // remove doubles
     $this->_specialAttributes = array_unique($this->_specialAttributes);
     return $this;
 }