Skip to content

Commit 42d3b53

Browse files
committed
MAGETWO-61025: Product export duplicate rows for product with html special chars in data
1 parent a2cf9b8 commit 42d3b53

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ protected function collectRawData()
961961

962962
if ($storeId != Store::DEFAULT_STORE_ID
963963
&& isset($data[$itemId][Store::DEFAULT_STORE_ID][$fieldName])
964-
&& $data[$itemId][Store::DEFAULT_STORE_ID][$fieldName] == $attrValue
964+
&& $data[$itemId][Store::DEFAULT_STORE_ID][$fieldName] == htmlspecialchars_decode($attrValue)
965965
) {
966966
continue;
967967
}
@@ -1000,7 +1000,7 @@ protected function collectRawData()
10001000
$data[$itemId][$storeId][self::COL_ATTR_SET] = $this->_attrSetIdToName[$attrSetId];
10011001
$data[$itemId][$storeId][self::COL_TYPE] = $item->getTypeId();
10021002
}
1003-
$data[$itemId][$storeId][self::COL_SKU] = $item->getSku();
1003+
$data[$itemId][$storeId][self::COL_SKU] = htmlspecialchars_decode($item->getSku());
10041004
$data[$itemId][$storeId]['store_id'] = $storeId;
10051005
$data[$itemId][$storeId]['product_id'] = $itemId;
10061006
$data[$itemId][$storeId]['product_link_id'] = $productLinkId;

dev/tests/integration/testsuite/Magento/Catalog/_files/products_with_multiselect_attribute.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
'simple_ms_1'
4040
)->setPrice(
4141
10
42+
)->setDescription(
43+
'Hello " &" Bring the water bottle when you can!'
4244
)->setVisibility(
4345
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
4446
)->setMultiselectAttribute(

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/AbstractProductExportImportTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ abstract class AbstractProductExportImportTestCase extends \PHPUnit_Framework_Te
5656
'custom_design_from',
5757
'updated_in',
5858
'tax_class_id',
59+
'description'
5960
];
6061

6162
protected function setUp()

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ public function testExport()
8787
$this->assertContains('test_option_code_2', $exportData);
8888
$this->assertContains('max_characters=10', $exportData);
8989
$this->assertContains('text_attribute=!@#$%^&*()_+1234567890-=|\\:;""\'<,>.?/', $exportData);
90+
$occurrencesCount = substr_count($exportData, 'Hello "" &"" Bring the water bottle when you can!');
91+
$this->assertEquals(1, $occurrencesCount);
92+
}
93+
94+
/**
95+
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data_special_chars.php
96+
* @magentoDbIsolationEnabled
97+
*/
98+
public function testExportSpecialChars()
99+
{
100+
$this->model->setWriter(
101+
$this->objectManager->create(
102+
\Magento\ImportExport\Model\Export\Adapter\Csv::class
103+
)
104+
);
105+
$exportData = $this->model->export();
106+
$this->assertContains('simple ""1""', $exportData);
90107
}
91108

92109
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
/** Create category */
7+
require dirname(dirname(__DIR__)) . '/Catalog/_files/category.php';
8+
/** Create fixture store */
9+
require dirname(dirname(__DIR__)) . '/Store/_files/second_store.php';
10+
/** Create product with multiselect attribute and values */
11+
require dirname(dirname(__DIR__)) . '/Catalog/_files/products_with_multiselect_attribute.php';
12+
/** Create dummy text attribute */
13+
require dirname(dirname(__DIR__)) . '/Catalog/_files/product_text_attribute.php';
14+
15+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
16+
17+
/** @var \Magento\Catalog\Model\Product $productModel */
18+
$productModel = $objectManager->create(\Magento\Catalog\Model\Product::class);
19+
20+
$productModel->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
21+
->setId(1)
22+
->setAttributeSetId(4)
23+
->setName('New Product')
24+
->setSku('simple &quot;1&quot;')
25+
->setPrice(10)
26+
->addData(['text_attribute' => '!@#$%^&*()_+1234567890-=|\\:;"\'<,>.?/'])
27+
->setTierPrice([0 => ['website_id' => 0, 'cust_group' => 0, 'price_qty' => 3, 'price' => 8]])
28+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
29+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
30+
->setWebsiteIds([1])
31+
->setCateroryIds([])
32+
->setStockData(['qty' => 100, 'is_in_stock' => 1])
33+
->setCanSaveCustomOptions(true)
34+
->setCategoryIds([333])
35+
->setUpSellLinkData([$product->getId() => ['position' => 1]]);
36+
37+
$productModel->setOptions([])->save();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** Delete all products */
8+
require dirname(dirname(__DIR__)) . '/Catalog/_files/products_with_multiselect_attribute_rollback.php';
9+
/** Delete text attribute */
10+
require dirname(dirname(__DIR__)) . '/Catalog/_files/text_attribute_rollback.php';

0 commit comments

Comments
 (0)