Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3019,7 +3019,7 @@ protected function getUrlKey($rowData)
{
if (!empty($rowData[self::URL_KEY])) {
$urlKey = (string) $rowData[self::URL_KEY];
return trim(strtolower($urlKey));
return $this->productUrl->formatUrlKey($urlKey);
}

if (!empty($rowData[self::COL_NAME])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
->setAttributeSetId(4)
->setWebsiteIds([1])
->setName('Simple Product')
->setSku('simple1')
->setPrice(10)
->setDescription('Description with <b>html tag</b>')
->setTaxClassId(2)
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setCategoryIds([2])
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->setUrlKey('url with spaces 1')
->save();

/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
->setAttributeSetId(4)
->setWebsiteIds([1])
->setName('Simple Product 2')
->setSku('simple2')
->setPrice(10)
->setDescription('Description with <b>html tag</b>')
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setCategoryIds([2])
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->setUrlKey('url with spaces 2')
->save();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Exception\NoSuchEntityException;

\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize();

/** @var \Magento\Framework\Registry $registry */
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);

$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);

/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
try {
$product = $productRepository->get('simple1', false, null, true);
$productRepository->delete($product);
$product = $productRepository->get('simple2', false, null, true);
$productRepository->delete($product);
} catch (NoSuchEntityException $e) {
}
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ public function testExistingProductWithUrlKeys()
public function testAddUpdateProductWithInvalidUrlKeys() : void
{
$products = [
'simple1' => 'cuvée merlot-cabernet igp pays d\'oc frankrijk',
'simple1' => 'cuvee-merlot-cabernet-igp-pays-d-oc-frankrijk',
'simple2' => 'normal-url',
'simple3' => 'some!wrong\'url'
'simple3' => 'some-wrong-url'
];
// added by _files/products_to_import_with_invalid_url_keys.csv
$this->importedProducts[] = 'simple3';
Expand Down Expand Up @@ -328,10 +328,10 @@ public function testImportWithNonLatinUrlKeys()
{
$productsCreatedByFixture = [
'ukrainian-with-url-key' => 'nove-im-ja-pislja-importu-scho-stane-url-key',
'ukrainian-without-url-key' => 'новий url key після імпорту',
'ukrainian-without-url-key' => 'novij-url-key-pislja-importu',
];
$productsImportedByCsv = [
'imported-ukrainian-with-url-key' => 'імпортований продукт',
'imported-ukrainian-with-url-key' => 'importovanij-produkt',
'imported-ukrainian-without-url-key' => 'importovanij-produkt-bez-url-key',
];
$productSkuMap = array_merge($productsCreatedByFixture, $productsImportedByCsv);
Expand Down Expand Up @@ -362,4 +362,42 @@ public function testImportWithNonLatinUrlKeys()
$this->assertEquals($productUrlKey, $productRepository->get($productSku)->getUrlKey());
}
}

/**
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_spaces_in_url_key.php
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testImportWithSpacesInUrlKeys()
{
$products = [
'simple1' => 'url-with-spaces-1',
'simple2' => 'url-with-spaces-2'
];
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $this->objectManager->create(
\Magento\ImportExport\Model\Import\Source\Csv::class,
[
'file' => __DIR__ . '/../_files/products_to_import_with_spaces_in_url_keys.csv',
'directory' => $directory,
]
);
$errors = $this->_model->setParameters(
['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_ADD_UPDATE, 'entity' => 'catalog_product']
)
->setSource($source)
->validateData();

$this->assertEquals($errors->getErrorsCount(), 0);
$this->_model->importData();

/** @var ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
foreach ($products as $productSku => $productUrlKey) {
$this->assertEquals($productUrlKey, $productRepository->get($productSku)->getUrlKey());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sku,product_type,store_view_code,name,price,attribute_set_code,url_key
simple1,simple,,"simple 1",25,Default,"url with spaces 1"
simple2,simple,,"simple 2",34,Default,"url with spaces 2"