Skip to content

Commit b9b7c9c

Browse files
authored
Merge pull request #3208 from magento-epam/EPAM-PR-13
[epam] MAGETWO-95105: [2.3] URL Key column with accented characters not converted after importing the CSV file
2 parents 9c4e95d + 540c786 commit b9b7c9c

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2839,7 +2839,7 @@ protected function getProductUrlSuffix($storeId = null)
28392839
protected function getUrlKey($rowData)
28402840
{
28412841
if (!empty($rowData[self::URL_KEY])) {
2842-
return strtolower($rowData[self::URL_KEY]);
2842+
return $this->productUrl->formatUrlKey($rowData[self::URL_KEY]);
28432843
}
28442844

28452845
if (!empty($rowData[self::COL_NAME])) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
/** @var $product \Magento\Catalog\Model\Product */
9+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
10+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
11+
->setAttributeSetId(4)
12+
->setWebsiteIds([1])
13+
->setName('Simple Product')
14+
->setSku('simple1')
15+
->setPrice(10)
16+
->setDescription('Description with <b>html tag</b>')
17+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
18+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
19+
->setCategoryIds([2])
20+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
21+
->setUrlKey('cuvee-merlot-cabernet-igp-pays-d-oc-frankrijk')
22+
->save();
23+
24+
/** @var $product \Magento\Catalog\Model\Product */
25+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
26+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
27+
->setAttributeSetId(4)
28+
->setWebsiteIds([1])
29+
->setName('Simple Product 2')
30+
->setSku('simple2')
31+
->setPrice(10)
32+
->setDescription('Description with <b>html tag</b>')
33+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
34+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
35+
->setCategoryIds([2])
36+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
37+
->setUrlKey('normal-url')
38+
->save();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Framework\Exception\NoSuchEntityException;
9+
10+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize();
11+
12+
/** @var \Magento\Framework\Registry $registry */
13+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
14+
15+
$registry->unregister('isSecureArea');
16+
$registry->register('isSecureArea', true);
17+
18+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
19+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
20+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
21+
try {
22+
$product = $productRepository->get('simple1', false, null, true);
23+
$productRepository->delete($product);
24+
$product = $productRepository->get('simple2', false, null, true);
25+
$productRepository->delete($product);
26+
} catch (NoSuchEntityException $e) {
27+
}
28+
$registry->unregister('isSecureArea');
29+
$registry->register('isSecureArea', false);

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,46 @@ public function testExistingProductWithUrlKeys()
15661566
}
15671567
}
15681568

1569+
/**
1570+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_wrong_url_key.php
1571+
* @magentoDbIsolation disabled
1572+
* @magentoAppIsolation enabled
1573+
*/
1574+
public function testAddUpdateProductWithInvalidUrlKeys() : void
1575+
{
1576+
$products = [
1577+
'simple1' => 'cuvee-merlot-cabernet-igp-pays-d-oc-frankrijk',
1578+
'simple2' => 'normal-url',
1579+
'simple3' => 'some-wrong-url'
1580+
];
1581+
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
1582+
->create(\Magento\Framework\Filesystem::class);
1583+
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
1584+
$source = $this->objectManager->create(
1585+
\Magento\ImportExport\Model\Import\Source\Csv::class,
1586+
[
1587+
'file' => __DIR__ . '/_files/products_to_import_with_invalid_url_keys.csv',
1588+
'directory' => $directory
1589+
]
1590+
);
1591+
1592+
$errors = $this->_model->setParameters(
1593+
['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_ADD_UPDATE, 'entity' => 'catalog_product']
1594+
)->setSource(
1595+
$source
1596+
)->validateData();
1597+
1598+
$this->assertTrue($errors->getErrorsCount() == 0);
1599+
$this->_model->importData();
1600+
1601+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
1602+
\Magento\Catalog\Api\ProductRepositoryInterface::class
1603+
);
1604+
foreach ($products as $productSku => $productUrlKey) {
1605+
$this->assertEquals($productUrlKey, $productRepository->get($productSku)->getUrlKey());
1606+
}
1607+
}
1608+
15691609
/**
15701610
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
15711611
* @magentoDbIsolation disabled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sku,product_type,store_view_code,name,price,attribute_set_code,url_key
2+
simple1,simple,,"simple 1",25,Default,cuvée merlot-cabernet igp pays d'oc frankrijk
3+
simple2,simple,,"simple 2",34,Default,normal-url
4+
simple3,simple,,"simple 3",58,Default,some!wrong'url

0 commit comments

Comments
 (0)