Skip to content

Commit ca68e6e

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #580 from magento-east/pr-2.0
[EAST] Bugfixes 2.0.11
2 parents 0d31c3e + 6aa98c0 commit ca68e6e

File tree

11 files changed

+173
-53
lines changed

11 files changed

+173
-53
lines changed

app/code/Magento/BundleImportExport/Model/Export/RowCustomizer.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Magento\CatalogImportExport\Model\Export\RowCustomizerInterface;
1010
use Magento\CatalogImportExport\Model\Import\Product as ImportProductModel;
1111
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
12-
use Magento\ImportExport\Controller\Adminhtml\Import;
1312
use Magento\ImportExport\Model\Import as ImportModel;
1413

1514
/**
@@ -291,10 +290,7 @@ protected function getPriceTypeValue($type)
291290
protected function cleanNotBundleAdditionalAttributes($dataRow)
292291
{
293292
if (!empty($dataRow['additional_attributes'])) {
294-
$additionalAttributes = explode(
295-
ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
296-
$dataRow['additional_attributes']
297-
);
293+
$additionalAttributes = $this->parseAdditionalAttributes($dataRow['additional_attributes']);
298294
$dataRow['additional_attributes'] = $this->getNotBundleAttributes($additionalAttributes);
299295
}
300296

@@ -309,17 +305,35 @@ protected function cleanNotBundleAdditionalAttributes($dataRow)
309305
*/
310306
protected function getNotBundleAttributes($additionalAttributes)
311307
{
312-
$cleanedAdditionalAttributes = '';
313-
foreach ($additionalAttributes as $attribute) {
314-
list($attributeCode, $attributeValue) = explode(ImportProductModel::PAIR_NAME_VALUE_SEPARATOR, $attribute);
315-
if (!in_array('bundle_' . $attributeCode, $this->bundleColumns)) {
316-
$cleanedAdditionalAttributes .= $attributeCode
317-
. ImportProductModel::PAIR_NAME_VALUE_SEPARATOR
318-
. $attributeValue
319-
. ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR;
308+
$filteredAttributes = [];
309+
foreach ($additionalAttributes as $code => $value) {
310+
if (!in_array('bundle_' . $code, $this->bundleColumns)) {
311+
$filteredAttributes[] = $code . ImportProductModel::PAIR_NAME_VALUE_SEPARATOR . $value;
320312
}
321313
}
314+
return implode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $filteredAttributes);
315+
}
322316

323-
return rtrim($cleanedAdditionalAttributes, ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR);
317+
/**
318+
* Retrieves additional attributes as array code=>value.
319+
*
320+
* @param string $additionalAttributes
321+
* @return array
322+
*/
323+
private function parseAdditionalAttributes($additionalAttributes)
324+
{
325+
$attributeNameValuePairs = explode(ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $additionalAttributes);
326+
$preparedAttributes = [];
327+
$code = '';
328+
foreach ($attributeNameValuePairs as $attributeData) {
329+
//process case when attribute has ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR inside its value
330+
if (strpos($attributeData, ImportProductModel::PAIR_NAME_VALUE_SEPARATOR) === false && $code) {
331+
$preparedAttributes[$code] .= ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . $attributeData;
332+
} else {
333+
list($code, $value) = explode(ImportProductModel::PAIR_NAME_VALUE_SEPARATOR, $attributeData, 2);
334+
$preparedAttributes[$code] = $value;
335+
}
336+
}
337+
return $preparedAttributes;
324338
}
325339
}

app/code/Magento/BundleImportExport/Test/Unit/Model/Export/Product/RowCustomizerTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ protected function setUp()
5959
{
6060
$this->objectManagerHelper = new ObjectManagerHelper($this);
6161
$this->rowCustomizerMock = $this->objectManagerHelper->getObject(
62-
'\Magento\BundleImportExport\Model\Export\RowCustomizer'
62+
\Magento\BundleImportExport\Model\Export\RowCustomizer::class
6363
);
6464
$this->productResourceCollection = $this->getMock(
65-
'\Magento\Catalog\Model\ResourceModel\Product\Collection',
65+
\Magento\Catalog\Model\ResourceModel\Product\Collection::class,
6666
['addAttributeToFilter', 'getIterator'],
6767
[],
6868
'',
6969
false
7070
);
7171
$this->product = $this->getMock(
72-
'\Magento\Catalog\Model\Product',
72+
\Magento\Catalog\Model\Product::class,
7373
[
7474
'getId',
7575
'getPriceType',
@@ -91,7 +91,7 @@ protected function setUp()
9191
$this->product->expects($this->any())->method('getWeightType')->willReturn(1);
9292
$this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
9393
$this->optionsCollection = $this->getMock(
94-
'\Magento\Bundle\Model\ResourceModel\Option\Collection',
94+
\Magento\Bundle\Model\ResourceModel\Option\Collection::class,
9595
['setOrder', 'getIterator'],
9696
[],
9797
'',
@@ -100,7 +100,7 @@ protected function setUp()
100100
$this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
101101
$this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
102102
$this->option = $this->getMock(
103-
'\Magento\Bundle\Model\Option',
103+
\Magento\Bundle\Model\Option::class,
104104
['getId', 'getTitle', 'getType', 'getRequired'],
105105
[],
106106
'',
@@ -114,7 +114,7 @@ protected function setUp()
114114
$this->returnValue(new \ArrayIterator([$this->option]))
115115
);
116116
$this->selection = $this->getMock(
117-
'\Magento\Catalog\Model\Product',
117+
\Magento\Catalog\Model\Product::class,
118118
['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'],
119119
[],
120120
'',
@@ -125,7 +125,7 @@ protected function setUp()
125125
$this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
126126
$this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
127127
$this->selectionsCollection = $this->getMock(
128-
'\Magento\Bundle\Model\ResourceModel\Selection\Collection',
128+
\Magento\Bundle\Model\ResourceModel\Selection\Collection::class,
129129
['getIterator', 'addAttributeToSort'],
130130
[],
131131
'',
@@ -175,14 +175,16 @@ public function testAddHeaderColumns()
175175
public function testAddData()
176176
{
177177
$preparedData = $this->rowCustomizerMock->prepareData($this->productResourceCollection, [1]);
178+
$attributes = 'attribute=1,sku_type=1,attribute2="Text",price_type=1,price_view=1,weight_type=1,'
179+
. 'values=values,attribute3=One,Two,Three';
178180
$dataRow = [
179181
'sku' => 'sku1',
180-
'additional_attributes' => 'attribute=1,sku_type=1,price_type=1,price_view=1,weight_type=1,values=values'
182+
'additional_attributes' => $attributes
181183
];
182184
$preparedRow = $preparedData->addData($dataRow, 1);
183185
$expected = [
184186
'sku' => 'sku1',
185-
'additional_attributes' => 'attribute=1',
187+
'additional_attributes' => 'attribute=1,attribute2="Text",attribute3=One,Two,Three',
186188
'bundle_price_type' => 'fixed',
187189
'bundle_sku_type' => 'fixed',
188190
'bundle_price_view' => 'As low as',

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,15 +2394,12 @@ private function parseAttributesWithoutWrappedValues($attributesData)
23942394
$code = '';
23952395
foreach ($attributeNameValuePairs as $attributeData) {
23962396
//process case when attribute has ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR inside its value
2397-
if (strpos($attributeData, self::PAIR_NAME_VALUE_SEPARATOR) === false) {
2398-
if (!$code) {
2399-
continue;
2400-
}
2397+
if (strpos($attributeData, self::PAIR_NAME_VALUE_SEPARATOR) === false && $code) {
24012398
$preparedAttributes[$code] .= $this->getMultipleValueSeparator() . $attributeData;
2402-
continue;
2399+
} else {
2400+
list($code, $value) = explode(self::PAIR_NAME_VALUE_SEPARATOR, $attributeData, 2);
2401+
$preparedAttributes[$code] = $value;
24032402
}
2404-
list($code, $value) = explode(self::PAIR_NAME_VALUE_SEPARATOR, $attributeData, 2);
2405-
$preparedAttributes[$code] = $value;
24062403
}
24072404
return $preparedAttributes;
24082405
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "magento/module-sample-test",
3+
"description": "test sample module",
4+
"require": {
5+
"php": "~5.5.0|~5.6.0|~7.0.0",
6+
"magento/framework": "100.0.*",
7+
"magento/module-integration": "100.0.*"
8+
},
9+
"type": "magento2-module",
10+
"version": "1.0",
11+
"extra": {
12+
"map": [
13+
[
14+
"*",
15+
"Magento/TestModuleSample"
16+
]
17+
]
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_TestModuleSample" setup_version="0.0.1" active="true">
10+
</module>
11+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
$registrar = new ComponentRegistrar();
10+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleSample') === null) {
11+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleSample', __DIR__);
12+
}

dev/tests/integration/framework/bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
define('TESTS_TEMP_DIR', $testsBaseDir . '/tmp');
1616
}
1717

18+
$testFrameworkDir = __DIR__;
19+
require_once __DIR__ . '/deployTestModules.php';
20+
1821
try {
1922
/* Bootstrap the application */
2023
$settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants());
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* @var $testFrameworkDir string - Must be defined in parent script.
9+
*/
10+
11+
/** Copy test modules to app/code/Magento to make them visible for Magento instance */
12+
$pathToCommittedTestModules = $testFrameworkDir . '/../_files/Magento';
13+
$pathToInstalledMagentoInstanceModules = $testFrameworkDir . '/../../../../app/code/Magento';
14+
$iterator = new RecursiveIteratorIterator(
15+
new RecursiveDirectoryIterator($pathToCommittedTestModules, RecursiveDirectoryIterator::FOLLOW_SYMLINKS)
16+
);
17+
/** @var SplFileInfo $file */
18+
foreach ($iterator as $file) {
19+
if (!$file->isDir()) {
20+
$source = $file->getPathname();
21+
$relativePath = substr($source, strlen($pathToCommittedTestModules));
22+
$destination = $pathToInstalledMagentoInstanceModules . $relativePath;
23+
$targetDir = dirname($destination);
24+
if (!is_dir($targetDir)) {
25+
mkdir($targetDir, 0755, true);
26+
}
27+
copy($source, $destination);
28+
}
29+
}
30+
unset($iterator, $file);
31+
32+
// Register the modules under '_files/'
33+
$pathPattern = $pathToInstalledMagentoInstanceModules . '/TestModule*/registration.php';
34+
$files = glob($pathPattern, GLOB_NOSORT);
35+
if ($files === false) {
36+
throw new \RuntimeException('glob() returned error while searching in \'' . $pathPattern . '\'');
37+
}
38+
foreach ($files as $file) {
39+
include $file;
40+
}

dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Export/RowCustomizerTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function setUp()
2424
{
2525
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
2626
$this->model = $this->objectManager->create(
27-
'Magento\BundleImportExport\Model\Export\RowCustomizer'
27+
\Magento\BundleImportExport\Model\Export\RowCustomizer::class
2828
);
2929
}
3030

@@ -33,16 +33,26 @@ protected function setUp()
3333
*/
3434
public function testPrepareData()
3535
{
36-
$collection = $this->objectManager->get('Magento\Catalog\Model\ResourceModel\Product\Collection');
36+
$parsedAdditionalAttributes = 'text_attribute=!@#$%^&*()_+1234567890-=|\\:;"\'<,>.?/'
37+
. ',text_attribute2=,';
38+
$allAdditionalAttributes = $parsedAdditionalAttributes . ',weight_type=0,price_type=1';
39+
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
40+
$collection = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
41+
$select = $collection->getConnection()->select()
42+
->from(['p' => $collection->getTable('catalog_product_entity')], ['sku', 'entity_id'])
43+
->where('sku IN(?)', ['simple', 'custom-design-simple-product', 'bundle-product']);
44+
$ids = $collection->getConnection()->fetchPairs($select);
3745
$select = (string)$collection->getSelect();
3846
$this->model->prepareData($collection, [1, 2, 3, 4]);
3947
$this->assertEquals($select, (string)$collection->getSelect());
40-
$result = $this->model->addData([], 3);
48+
$result = $this->model->addData(['additional_attributes' => $allAdditionalAttributes], $ids['bundle-product']);
4149
$this->assertArrayHasKey('bundle_price_type', $result);
4250
$this->assertArrayHasKey('bundle_sku_type', $result);
4351
$this->assertArrayHasKey('bundle_price_view', $result);
4452
$this->assertArrayHasKey('bundle_weight_type', $result);
4553
$this->assertArrayHasKey('bundle_values', $result);
4654
$this->assertContains('sku=simple,', $result['bundle_values']);
55+
$this->assertEquals([], $this->model->addData([], $ids['simple']));
56+
$this->assertEquals($parsedAdditionalAttributes, $result['additional_attributes']);
4757
}
4858
}

0 commit comments

Comments
 (0)