11 use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
19 use Magento\UrlRewrite\Model\MergeDataProviderFactory;
24 use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory;
143 private $mergeDataProviderPrototype;
150 private $categoryCollectionFactory;
157 private $categoriesCache = [];
181 MergeDataProviderFactory $mergeDataProviderFactory =
null,
182 CategoryCollectionFactory $categoryCollectionFactory =
null 192 if (!isset($mergeDataProviderFactory)) {
195 $this->mergeDataProviderPrototype = $mergeDataProviderFactory->create();
196 $this->categoryCollectionFactory = $categoryCollectionFactory ?:
210 $this->
import = $observer->
getEvent()->getAdapter();
217 $this->urlPersist->replace($productUrls);
232 $newSku = $this->
import->getNewSku($rowData[ImportProduct::COL_SKU]);
233 if (empty($newSku) || !isset($newSku[
'entity_id'])) {
236 if ($this->import->getRowScope($rowData) == ImportProduct::SCOPE_STORE
237 && empty($rowData[self::URL_KEY_ATTRIBUTE_CODE])) {
240 $rowData[
'entity_id'] = $newSku[
'entity_id'];
242 $product = $this->catalogProductFactory->create();
243 $product->setId($rowData[
'entity_id']);
245 foreach ($this->vitalForGenerationFields as $field) {
246 if (isset($rowData[$field])) {
247 $product->setData($field, $rowData[$field]);
251 $this->categoryCache[$rowData[
'entity_id']] = $this->
import->getProductCategories($rowData[
'sku']);
252 $this->websiteCache[$rowData[
'entity_id']] = $this->
import->getProductWebsites($rowData[
'sku']);
253 foreach ($this->websiteCache[$rowData[
'entity_id']] as
$websiteId) {
254 if (!isset($this->websitesToStoreIds[
$websiteId])) {
255 $this->websitesToStoreIds[
$websiteId] = $this->storeManager->getWebsite(
$websiteId)->getStoreIds();
276 if (!empty($rowData[ImportProduct::COL_STORE])
277 && (
$storeId = $this->import->getStoreIdByCode($rowData[ImportProduct::COL_STORE]))
297 if (!isset($this->products[
$product->getId()])) {
298 $this->products[
$product->getId()] = [];
314 $this->storesCache[
$storeId] =
true;
330 $mergeDataProvider = clone $this->mergeDataProviderPrototype;
334 $this->productCategories =
null;
336 unset($this->products);
337 $this->products = [];
339 return $mergeDataProvider->getData();
361 foreach ($this->products as
$productId => $productsByStores) {
363 if ($this->productUrlPathGenerator->getUrlPath(
$product)) {
364 $urls[] = $this->urlRewriteFactory->create()
367 ->setRequestPath($this->productUrlPathGenerator->getUrlPathWithSuffix(
$product,
$storeId))
368 ->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath(
$product))
385 foreach ($this->products as
$productId => $productsByStores) {
387 foreach ($this->categoryCache[
$productId] as $categoryId) {
393 $urls[] = $this->urlRewriteFactory->create()
396 ->setRequestPath($requestPath)
397 ->setTargetPath($this->productUrlPathGenerator->getCanonicalUrlPath(
$product,
$category))
399 ->setMetadata([
'category_id' =>
$category->getId()]);
413 $currentUrlRewrites = $this->urlFinder->findAllByData(
422 foreach ($currentUrlRewrites as $currentUrlRewrite) {
427 $url = $currentUrlRewrite->getIsAutogenerated()
430 $urlRewrites = array_merge($urlRewrites,
$url);
433 $this->product =
null;
434 $this->productCategories =
null;
449 if (!
$product->getData(
'save_rewrites_history')) {
453 if (
$url->getRequestPath() === $targetPath) {
457 $this->urlRewriteFactory->create()
460 ->setRequestPath(
$url->getRequestPath())
461 ->setTargetPath($targetPath)
464 ->setDescription(
$url->getDescription())
465 ->setIsAutogenerated(0)
466 ->setMetadata(
$url->getMetadata())
483 $targetPath =
$url->getRedirectType()
485 :
$url->getTargetPath();
486 if (
$url->getRequestPath() === $targetPath) {
490 $this->urlRewriteFactory->create()
493 ->setRequestPath(
$url->getRequestPath())
494 ->setTargetPath($targetPath)
495 ->setRedirectType(
$url->getRedirectType())
497 ->setDescription(
$url->getDescription())
498 ->setIsAutogenerated(0)
499 ->setMetadata(
$url->getMetadata())
511 $metadata =
$url->getMetadata();
512 if (isset($metadata[
'category_id'])) {
513 $category = $this->
import->getCategoryProcessor()->getCategoryById($metadata[
'category_id']);
526 if (isset($this->acceptableCategories[
$storeId]) &&
535 if (!isset($this->acceptableCategories[
$storeId])) {
536 $this->acceptableCategories[
$storeId] = [];
549 private function getCategoryById($categoryId,
$storeId)
551 if (!isset($this->categoriesCache[$categoryId][
$storeId])) {
556 ->addAttributeToSelect(
'name')
557 ->addAttributeToSelect(
'url_key')
558 ->addAttributeToSelect(
'url_path');
562 return $this->categoriesCache[$categoryId][
$storeId];
categoriesUrlRewriteGenerate()
setStoreToProduct(\Magento\Catalog\Model\Product $product, array $rowData)
elseif(isset( $params[ 'redirect_parent']))
addProductToImport($product, $storeId)
generateForCustom($url, $category)
currentUrlRewritesRegenerate()
canonicalUrlRewriteGenerate()
generateForAutogenerated($url, $category)
execute(Observer $observer)
isCategoryProperForGenerating($category, $storeId)
const URL_KEY_ATTRIBUTE_CODE
$vitalForGenerationFields
populateGlobalProduct($product)
_populateForUrlGeneration($rowData)
const VISIBILITY_NOT_VISIBLE
__construct(\Magento\Catalog\Model\ProductFactory $catalogProductFactory, \Magento\CatalogUrlRewrite\Model\ObjectRegistryFactory $objectRegistryFactory, \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator $productUrlPathGenerator, \Magento\CatalogUrlRewrite\Service\V1\StoreViewService $storeViewService, \Magento\Store\Model\StoreManagerInterface $storeManager, UrlPersistInterface $urlPersist, UrlRewriteFactory $urlRewriteFactory, UrlFinderInterface $urlFinder, MergeDataProviderFactory $mergeDataProviderFactory=null, CategoryCollectionFactory $categoryCollectionFactory=null)
retrieveCategoryFromMetadata($url)