Skip to content

Commit c68f310

Browse files
Merge branch '2.4-develop' into Tier4-Kings-PR-01-20-2025
2 parents c0023b2 + d4de472 commit c68f310

File tree

32 files changed

+925
-407
lines changed

32 files changed

+925
-407
lines changed

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

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\CatalogImportExport\Model\Import;
@@ -181,6 +181,8 @@ class Product extends AbstractEntity
181181
*/
182182
public const URL_KEY = 'url_key';
183183

184+
private const ERROR_DUPLICATE_URL_KEY_BY_CATEGORY = 'duplicatedUrlKeyByCategory';
185+
184186
/**
185187
* @var array
186188
*/
@@ -316,6 +318,7 @@ class Product extends AbstractEntity
316318
ValidatorInterface::ERROR_MEDIA_URL_NOT_ACCESSIBLE => 'Imported resource (image: %s) at row %s could not be downloaded from external resource due to timeout or access permissions',
317319
ValidatorInterface::ERROR_INVALID_WEIGHT => 'Product weight is invalid',
318320
ValidatorInterface::ERROR_DUPLICATE_URL_KEY => 'Url key: \'%s\' was already generated for an item with the SKU: \'%s\'. You need to specify the unique URL key manually',
321+
self::ERROR_DUPLICATE_URL_KEY_BY_CATEGORY => 'Url key: \'%s\' was already generated for a %s with the ID: %s. You need to specify the unique URL key manually',
319322
ValidatorInterface::ERROR_DUPLICATE_MULTISELECT_VALUES => 'Value for multiselect attribute %s contains duplicated values',
320323
'invalidNewToDateValue' => 'Make sure new_to_date is later than or the same as new_from_date',
321324
// Can't add new translated strings in patch release
@@ -933,7 +936,7 @@ public function __construct(
933936
$this->stockProcessor = $stockProcessor ?: ObjectManager::getInstance()
934937
->get(StockProcessor::class);
935938
$this->linkProcessor = $linkProcessor ?? ObjectManager::getInstance()
936-
->get(LinkProcessor::class);
939+
->get(LinkProcessor::class);
937940
$this->linkProcessor->addNameToIds($this->_linkNameToId);
938941
$this->hashAlgorithm = (version_compare(PHP_VERSION, '8.1.0') >= 0) ? 'xxh128' : 'crc32c';
939942
parent::__construct(
@@ -949,17 +952,17 @@ public function __construct(
949952
$this->_optionEntity = $data['option_entity'] ??
950953
$optionFactory->create(['data' => ['product_entity' => $this]]);
951954
$this->skuStorage = $skuStorage ?? ObjectManager::getInstance()
952-
->get(SkuStorage::class);
955+
->get(SkuStorage::class);
953956
$this->_initAttributeSets()
954957
->_initTypeModels()
955958
->_initSkus()
956959
->initImagesArrayKeys();
957960
$this->validator->init($this);
958961
$this->dateTimeFactory = $dateTimeFactory ?? ObjectManager::getInstance()->get(DateTimeFactory::class);
959962
$this->productRepository = $productRepository ?? ObjectManager::getInstance()
960-
->get(ProductRepositoryInterface::class);
963+
->get(ProductRepositoryInterface::class);
961964
$this->stockItemProcessor = $stockItemProcessor ?? ObjectManager::getInstance()
962-
->get(StockItemProcessorInterface::class);
965+
->get(StockItemProcessorInterface::class);
963966
$this->fileDriver = $fileDriver ?? ObjectManager::getInstance()
964967
->get(File::class);
965968
}
@@ -3117,7 +3120,7 @@ protected function _saveValidatedBunches()
31173120
}
31183121

31193122
/**
3120-
* Check that url_keys are not assigned to other products in DB
3123+
* Check that url_keys are not already assigned to others entities in DB
31213124
*
31223125
* @return void
31233126
* @since 100.0.3
@@ -3129,21 +3132,36 @@ protected function checkUrlKeyDuplicates()
31293132
$urlKeyDuplicates = $this->_connection->fetchAssoc(
31303133
$this->_connection->select()->from(
31313134
['url_rewrite' => $resource->getTable('url_rewrite')],
3132-
['request_path', 'store_id']
3135+
[
3136+
'request_path',
3137+
'store_id',
3138+
'entity_type'
3139+
]
31333140
)->joinLeft(
31343141
['cpe' => $resource->getTable('catalog_product_entity')],
31353142
"cpe.entity_id = url_rewrite.entity_id"
31363143
)->where('request_path IN (?)', array_map('strval', array_keys($urlKeys)))
31373144
->where('store_id IN (?)', $storeId)
31383145
->where('cpe.sku not in (?)', array_values($urlKeys))
31393146
);
3147+
31403148
foreach ($urlKeyDuplicates as $entityData) {
31413149
$rowNum = $this->rowNumbers[$entityData['store_id']][$entityData['request_path']];
3142-
$message = sprintf(
3143-
$this->retrieveMessageTemplate(ValidatorInterface::ERROR_DUPLICATE_URL_KEY),
3144-
$entityData['request_path'],
3145-
$entityData['sku']
3146-
);
3150+
if ($entityData['entity_type'] === 'category') {
3151+
$message = sprintf(
3152+
$this->retrieveMessageTemplate(self::ERROR_DUPLICATE_URL_KEY_BY_CATEGORY),
3153+
$entityData['request_path'],
3154+
$entityData['entity_type'],
3155+
$entityData['entity_id'],
3156+
);
3157+
} else {
3158+
$message = sprintf(
3159+
$this->retrieveMessageTemplate(ValidatorInterface::ERROR_DUPLICATE_URL_KEY),
3160+
$entityData['request_path'],
3161+
$entityData['sku']
3162+
);
3163+
}
3164+
31473165
$this->addRowError(ValidatorInterface::ERROR_DUPLICATE_URL_KEY, $rowNum, 'url_key', $message);
31483166
}
31493167
}

0 commit comments

Comments
 (0)