diff --git a/.travis.yml b/.travis.yml index a8dbba1..757b5f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ php: - 7.1 - 7.2 - 7.3 +- 7.4 before_script: - sudo apt-get install libxml2-utils diff --git a/Model/Product/Attribute.php b/Model/Product/Attribute.php index 21a1491..5c3030d 100644 --- a/Model/Product/Attribute.php +++ b/Model/Product/Attribute.php @@ -28,6 +28,11 @@ class Attribute implements \Mygento\ImportExport\Api\AttributeInterface */ private $repository; + /** + * @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface + */ + private $productAttributeRepository; + /** * @param \Magento\Catalog\Model\Product\Attribute\OptionManagement $repository * @param \Magento\Eav\Api\Data\AttributeOptionLabelInterfaceFactory $optionLabelFactory @@ -36,11 +41,13 @@ class Attribute implements \Mygento\ImportExport\Api\AttributeInterface public function __construct( \Magento\Catalog\Model\Product\Attribute\OptionManagement $repository, \Magento\Eav\Api\Data\AttributeOptionLabelInterfaceFactory $optionLabelFactory, - \Magento\Eav\Api\Data\AttributeOptionInterfaceFactory $optionFactory + \Magento\Eav\Api\Data\AttributeOptionInterfaceFactory $optionFactory, + \Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository ) { $this->repository = $repository; $this->optionLabelFactory = $optionLabelFactory; $this->optionFactory = $optionFactory; + $this->productAttributeRepository = $productAttributeRepository; } /** @@ -84,7 +91,6 @@ public function createDropdownAttributeOptions( } /** - * TODO * @param \Magento\ImportExport\Model\Import\AbstractSource $source * @param array $attibutes */ @@ -92,6 +98,34 @@ public function createMultiselectAttributeOptions( \Magento\ImportExport\Model\Import\AbstractSource $source, array $attibutes ) { + $source->rewind(); + + while ($source->valid()) { + $row = $source->current(); + + foreach ($attibutes as $attributeCode) { + $attribute = $this->productAttributeRepository->get($attributeCode); + + if ($attribute->getFrontendInput() == 'multiselect') { + $options = $this->getAttributeOptions($attributeCode); + $newOptions = explode(\Magento\ImportExport\Model\Import::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $row[$attributeCode]); + + foreach ($newOptions as $newOption) { + if (!isset($newOption) || !strlen(trim($newOption))) { + continue; + } + if (in_array($newOption, $options)) { + continue; + } + $this->createAttributeOption($attributeCode, $row[$attributeCode]); + } + + } + } + + $source->next(); + } + unset($source); unset($attibutes); } diff --git a/README.md b/README.md index 8e14e2e..18a4210 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ Magento 2 Import Export Array Adapter ## Configuration ## Compability -The module is tested on magento version 2.3.x +The module is tested on magento version 2.4.x diff --git a/composer.json b/composer.json index e41adb4..0af11b1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mygento/module-import-export", "type": "magento2-module", - "version": "2.3.1", + "version": "2.4.0", "license": "OSL-3.0", "homepage": "https://github.com/mygento/module-import-export", "description": "Magento 2 import export array adapter", @@ -23,12 +23,11 @@ "mygento" ], "require": { - "magento/module-catalog-import-export": "101.0.*", - "magento/module-configurable-import-export": "100.3.*" + "magento/module-catalog-import-export": "101.1.*", + "magento/module-configurable-import-export": "100.4.*" }, "require-dev": { - "mygento/coding-standard": "~2.13.5", - "magento/magento-coding-standard": "~4.0.0" + "mygento/coding-standard": "~2.14.0-beta1" }, "autoload": { "files": [ diff --git a/etc/module.xml b/etc/module.xml index e07fdc8..47ff1c6 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,4 +1,4 @@ - +