/** * Generate list based on current url rewrites * * @param int $storeId * @param \Magento\Catalog\Model\Category $category * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] */ public function generate($storeId, Category $category) { $this->category = $category; $currentUrlRewrites = $this->urlFinder->findAllByData([UrlRewrite::STORE_ID => $storeId, UrlRewrite::ENTITY_ID => $category->getId(), UrlRewrite::ENTITY_TYPE => CategoryUrlRewriteGenerator::ENTITY_TYPE]); $urlRewrites = []; foreach ($currentUrlRewrites as $rewrite) { if ($rewrite->getIsAutogenerated()) { $urlRewrites = array_merge($urlRewrites, $this->generateForAutogenerated($rewrite, $storeId)); } else { $urlRewrites = array_merge($urlRewrites, $this->generateForCustom($rewrite, $storeId)); } } return $urlRewrites; }
/** * Generate list based on current rewrites * * @param int $storeId * @param Product $product * @param ObjectRegistry $productCategories * @return UrlRewrite[] */ public function generate($storeId, Product $product, ObjectRegistry $productCategories) { $this->product = $product; $this->productCategories = $productCategories; $currentUrlRewrites = $this->urlFinder->findAllByData([UrlRewrite::STORE_ID => $storeId, UrlRewrite::ENTITY_ID => $this->product->getId(), UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE]); $urlRewrites = []; foreach ($currentUrlRewrites as $currentUrlRewrite) { $category = $this->retrieveCategoryFromMetadata($currentUrlRewrite); if ($category === false) { continue; } $url = $currentUrlRewrite->getIsAutogenerated() ? $this->generateForAutogenerated($currentUrlRewrite, $storeId, $category) : $this->generateForCustom($currentUrlRewrite, $storeId, $category); $urlRewrites = array_merge($urlRewrites, $url); } $this->product = null; $this->productCategories = null; return $urlRewrites; }
/** * Generate list based on current rewrites * * @return UrlRewrite[] */ protected function currentUrlRewritesRegenerate() { $currentUrlRewrites = $this->urlFinder->findAllByData([UrlRewrite::STORE_ID => array_keys($this->storesCache), UrlRewrite::ENTITY_ID => array_keys($this->products), UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE]); $urlRewrites = []; foreach ($currentUrlRewrites as $currentUrlRewrite) { $category = $this->retrieveCategoryFromMetadata($currentUrlRewrite); if ($category === false) { continue; } $url = $currentUrlRewrite->getIsAutogenerated() ? $this->generateForAutogenerated($currentUrlRewrite, $category) : $this->generateForCustom($currentUrlRewrite, $category); $urlRewrites = array_merge($urlRewrites, $url); } $this->product = null; $this->productCategories = null; return $urlRewrites; }
/** * Update suffix for url rewrites * * @return $this */ protected function updateSuffixForUrlRewrites() { $map = [ProductUrlPathGenerator::XML_PATH_PRODUCT_URL_SUFFIX => ProductUrlRewriteGenerator::ENTITY_TYPE, CategoryUrlPathGenerator::XML_PATH_CATEGORY_URL_SUFFIX => CategoryUrlRewriteGenerator::ENTITY_TYPE]; if (!isset($map[$this->getPath()])) { return $this; } $dataFilter = [UrlRewrite::ENTITY_TYPE => $map[$this->getPath()]]; $storesIds = $this->getStoreIds(); if ($storesIds) { $dataFilter[UrlRewrite::STORE_ID] = $storesIds; } $entities = $this->urlFinder->findAllByData($dataFilter); $oldSuffixPattern = '~' . preg_quote($this->getOldValue()) . '$~'; $suffix = $this->getValue(); foreach ($entities as $urlRewrite) { $bind = $urlRewrite->getIsAutogenerated() ? [UrlRewrite::REQUEST_PATH => preg_replace($oldSuffixPattern, $suffix, $urlRewrite->getRequestPath())] : [UrlRewrite::TARGET_PATH => preg_replace($oldSuffixPattern, $suffix, $urlRewrite->getTargetPath())]; $this->connection->update(DbStorage::TABLE_NAME, $bind, $this->connection->quoteIdentifier(UrlRewrite::URL_REWRITE_ID) . ' = ' . $urlRewrite->getUrlRewriteId()); } return $this; }
/** * @param \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $urls * @return \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] */ protected function filterUrls(array $urls) { $filteredUrls = []; /** @var UrlRewrite $url */ foreach ($urls as $url) { if ($this->isCorrectUrl($url)) { $filteredUrls[] = $url; } } $data = []; foreach ($filteredUrls as $url) { foreach ([UrlRewrite::REQUEST_PATH, UrlRewrite::STORE_ID] as $key) { $fieldValue = $url->getByKey($key); if (!isset($data[$key]) || !in_array($fieldValue, $data[$key])) { $data[$key][] = $fieldValue; } } } return $data ? $this->urlFinder->findAllByData($data) : []; }