Skip to content

Commit 26c0015

Browse files
committed
ACP2E-1754: Store level URL rewrites are removed after product import
1 parent 7bd6e0f commit 26c0015

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,29 @@ private function categoriesUrlRewriteGenerate(array $products): array
538538
continue;
539539
}
540540
$requestPath = $this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category);
541+
$targetPath = $this->productUrlPathGenerator->getCanonicalUrlPath($product, $category);
542+
if ((int) $storeId !== (int) $product->getStoreId()
543+
&& $this->isGlobalScope($product->getStoreId())) {
544+
if ($this->cachedValues === null) {
545+
$this->cachedValues = $this->getScopeBasedUrlKeyValues($products);
546+
}
547+
if (!empty($this->cachedValues) && isset($this->cachedValues[$productId][$storeId])) {
548+
$storeProduct = clone $product;
549+
$storeProduct->setStoreId($storeId);
550+
$storeProduct->setUrlKey($this->cachedValues[$productId][$storeId]);
551+
$requestPath = $this->productUrlPathGenerator->getUrlPathWithSuffix(
552+
$storeProduct,
553+
$storeId,
554+
$category
555+
);
556+
}
557+
}
541558
$urls[] = [
542559
$this->urlRewriteFactory->create()
543560
->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
544561
->setEntityId($productId)
545562
->setRequestPath($requestPath)
546-
->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath($product, $category))
563+
->setTargetPath($targetPath)
547564
->setStoreId($storeId)
548565
->setMetadata(['category_id' => $category->getId()])
549566
];

0 commit comments

Comments
 (0)