Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MC-30528' into 2.4-develop-pr11
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-balko committed Feb 4, 2020
2 parents e5c1979 + 57a8587 commit 3fb3420
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

namespace Magento\CatalogImportExport\Model\Import\Product;

use Magento\CatalogImportExport\Model\Import\Product;
use Magento\Framework\App\ResourceConnection;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\Collection as ProductOptionValueCollection;
use Magento\Catalog\Model\ResourceModel\Product\Option\Value\CollectionFactory as ProductOptionValueCollectionFactory;
use Magento\Store\Model\Store;
use Magento\CatalogImportExport\Model\Import\Product;
use Magento\Framework\App\ResourceConnection;
use Magento\ImportExport\Model\Import;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
use Magento\Store\Model\Store;

/**
* Entity class which provide possibility to import product custom options
Expand Down Expand Up @@ -110,6 +110,13 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
'file' => ['sku', 'file_extension', 'image_size_x', 'image_size_y'],
];

/**
* Invalid rows list
*
* @var array
*/
private $_invalidRows;

/**
* Keep product id value for every row which will be imported
*
Expand Down Expand Up @@ -433,7 +440,7 @@ protected function _initMessageTemplates()
self::ERROR_INVALID_TYPE,
__(
'Value for \'type\' sub attribute in \'custom_options\' attribute contains incorrect value, acceptable values are: %1',
'\''.implode('\', \'', array_keys($this->_specificTypes)).'\''
'\'' . implode('\', \'', array_keys($this->_specificTypes)) . '\''
)
);
$this->_productEntity->addMessageTemplate(self::ERROR_EMPTY_TITLE, __('Please enter a value for title.'));
Expand Down Expand Up @@ -1251,7 +1258,9 @@ protected function _importData()
$childCount = [];
$optionsToRemove = [];
foreach ($bunch as $rowNumber => $rowData) {
if (isset($optionId, $valueId) && empty($rowData[PRODUCT::COL_STORE_VIEW_CODE])) {
if (isset($optionId, $valueId) &&
(empty($rowData[PRODUCT::COL_STORE_VIEW_CODE]) || empty($rowData['custom_options']))
) {
$nextOptionId = $optionId;
$nextValueId = $valueId;
}
Expand Down Expand Up @@ -1548,8 +1557,8 @@ protected function _collectOptionTitle(array $rowData, $prevOptionId, array &$ti
if (!empty($rowData[self::COLUMN_TITLE])) {
if (!isset($titles[$prevOptionId][$defaultStoreId])) {
if (isset($this->lastOptionTitle[$prevOptionId])) {
$titles[$prevOptionId] = $this->lastOptionTitle[$prevOptionId];
unset($this->lastOptionTitle);
$titles[$prevOptionId] = $this->lastOptionTitle[$prevOptionId];
unset($this->lastOptionTitle);
} else {
$titles[$prevOptionId][$defaultStoreId] = $rowData[self::COLUMN_TITLE];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
use Magento\ImportExport\Model\Import\Source\Csv;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap as BootstrapHelper;
use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection;
use Psr\Log\LoggerInterface;
use Magento\TestFramework\Helper\Bootstrap as BootstrapHelper;

/**
* Class ProductTest
Expand Down Expand Up @@ -403,7 +403,7 @@ public function testSaveCustomOptionsWithMultipleStoreViews()
$pathToFile = __DIR__ . '/_files/' . $importFile;
$importModel = $this->createImportModel($pathToFile);
$errors = $importModel->validateData();
$this->assertTrue($errors->getErrorsCount() == 0);
$this->assertTrue($errors->getErrorsCount() == 0, 'Import File Validation Failed');
$importModel->importData();
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
Expand All @@ -422,20 +422,41 @@ public function testSaveCustomOptionsWithMultipleStoreViews()
$actualOptions = $actualData['options'];
sort($expectedOptions);
sort($actualOptions);
$this->assertEquals($expectedOptions, $actualOptions);
$this->assertEquals(
$expectedOptions,
$actualOptions,
'Expected and actual options arrays does not match'
);

// assert of options data
$this->assertCount(count($expectedData['data']), $actualData['data']);
$this->assertCount(count($expectedData['values']), $actualData['values']);
$this->assertCount(
count($expectedData['data']),
$actualData['data'],
'Expected and actual data count does not match'
);
$this->assertCount(
count($expectedData['values']),
$actualData['values'],
'Expected and actual values count does not match'
);

foreach ($expectedData['options'] as $expectedId => $expectedOption) {
$elementExist = false;
// find value in actual options and values
foreach ($actualData['options'] as $actualId => $actualOption) {
if ($actualOption == $expectedOption) {
$elementExist = true;
$this->assertEquals($expectedData['data'][$expectedId], $actualData['data'][$actualId]);
$this->assertEquals(
$expectedData['data'][$expectedId],
$actualData['data'][$actualId],
'Expected data does not match actual data'
);
if (array_key_exists($expectedId, $expectedData['values'])) {
$this->assertEquals($expectedData['values'][$expectedId], $actualData['values'][$actualId]);
$this->assertEquals(
$expectedData['values'][$expectedId],
$actualData['values'][$actualId],
'Expected values does not match actual data'
);
}
unset($actualData['options'][$actualId]);
// remove value in case of duplicating key values
Expand All @@ -448,7 +469,11 @@ public function testSaveCustomOptionsWithMultipleStoreViews()
// Make sure that after importing existing options again, option IDs and option value IDs are not changed
$customOptionValues = $this->getCustomOptionValues($sku);
$this->createImportModel($pathToFile)->importData();
$this->assertEquals($customOptionValues, $this->getCustomOptionValues($sku));
$this->assertEquals(
$customOptionValues,
$this->getCustomOptionValues($sku),
'Option IDs changed after second import'
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ sku,website_code,store_view_code,attribute_set_code,product_type,name,descriptio
simple,base,,Default,simple,New Product,,,9,1,"Catalog, Search","base,secondwebsite",,10,,,,Taxable Goods,new-product,,,,,,,,,,,,,,,,,,,,,,,,"name=Test Field Title,type=field,required=1,sku=1-text,price=100|name=Test Date and Time Title,type=date_time,required=1,sku=2-date,price=200|name=Test Select,type=drop_down,required=1,sku=3-1-select,price=310,option_title=Select Option 1|name=Test Select,type=drop_down,required=1,sku=3-2-select,price=320,option_title=Select Option 2|name=Test Checkbox,type=checkbox,required=1,sku=4-1-select,price=410,option_title=Checkbox Option 1|name=Test Checkbox,type=checkbox,required=1,sku=4-2-select,price=420,option_title=Checkbox Option 2|name=Test Radio,type=radio,required=1,sku=5-1-radio,price=510,option_title=Radio Option 1|name=Test Radio,type=radio,required=1,sku=5-2-radio,price=520,option_title=Radio Option 2",,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,Block after Info Column,,,
simple,,default,Default,simple,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"name=Test Field Title_default,type=field,sku=1-text|name=Test Date and Time Title_default,type=date_time,sku=2-date|name=Test Select_default,type=drop_down,sku=3-1-select,option_title=Select Option 1_default|name=Test Select_default,type=drop_down,sku=3-2-select,option_title=Select Option 2_default|name=Test Checkbox_default,type=checkbox,sku=4-1-select,option_title=Checkbox Option 1_default|name=Test Checkbox_default,type=checkbox,sku=4-2-select,option_title=Checkbox Option 2_default|name=Test Radio_default,type=radio,sku=5-1-radio,option_title=Radio Option 1_default|name=Test Radio_default,type=radio,sku=5-2-radio,option_title=Radio Option 2_default",,,,,,,,,,,,,,,,,,,,,,,,,,,
simple,,secondstore,Default,simple,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"name=Test Field Title_fixture_second_store,type=field,sku=1-text,price=101|name=Test Date and Time Title_fixture_second_store,type=date_time,sku=2-date,price=201|name=Test Select_fixture_second_store,type=drop_down,sku=3-1-select,price=311,option_title=Select Option 1_fixture_second_store|name=Test Select_fixture_second_store,type=drop_down,sku=3-2-select,price=321,option_title=Select Option 2_fixture_second_store|name=Test Checkbox_second_store,type=checkbox,sku=4-1-select,price=411,option_title=Checkbox Option 1_second_store|name=Test Checkbox_second_store,type=checkbox,sku=4-2-select,price=421,option_title=Checkbox Option 2_second_store|name=Test Radio_fixture_second_store,type=radio,sku=5-1-radio,price=511,option_title=Radio Option 1_fixture_second_store|name=Test Radio_fixture_second_store,type=radio,sku=5-2-radio,price=521,option_title=Radio Option 2_fixture_second_store",,,,,,,,,,,,,,,,,,,,,,,,,,,
newprod2,base,secondstore,Default,configurable,New Product 2,,,9,1,"Catalog, Search","base,secondwebsite",,10,,,,Taxable Goods,new-product-2,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,Block after Info Column,,,
newprod3,base,,Default,configurable,New Product 3,,,9,1,"Catalog, Search","base,secondwebsite",,10,,,,Taxable Goods,new-product-3,,,,,,,,,,,,,,,,,,,,,,,,"name=Line 1,type=field,max_characters=30,required=1,option_title=Line 1|name=Line 2,type=field,max_characters=30,required=0,option_title=Line 2",,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,Block after Info Column,,,
newprod4,base,secondstore,Default,configurable,New Product 4,,,9,1,"Catalog, Search","base,secondwebsite",,10,,,,Taxable Goods,new-product-4,,,,,,,,,,,,,,,,,,,,,,,,,,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,Block after Info Column,,,
newprod5,base,,Default,configurable,New Product 5,,,9,1,"Catalog, Search","base,secondwebsite",,10,,,,Taxable Goods,new-product-5,,,,,,,,,,,,,,,,,,,,,,,,"name=Line 3,type=field,max_characters=30,required=1,option_title=Line 3|name=Line 4,type=field,max_characters=30,required=0,option_title=Line 4",,1,1,999,0,0,0,1,10000,1,1,0,0,,,,,,,,,,,Block after Info Column,,,

0 comments on commit 3fb3420

Please sign in to comment.