elgentos / regenerate-catalog-urls
重新生成目录URL重写(产品、分类、CMS页面)
Requires
- php: ~7.4|~8.0|~8.1|~8.2|~8.3
- magento/framework: ^102.0|^103.0
- magento/module-catalog-url-rewrite: ^100.3|^100.4
- magento/module-url-rewrite: ^101.1|^102.0
Requires (Dev)
- mediact/coding-standard-magento2: @stable
- mediact/testing-suite: ^2.9
Suggests
- baldwin/magento2-module-url-data-integrity-checker: Magento 2 module which can find potential url related problems in your catalog data
- fisheye/module-url-rewrite-optimiser: A Magento module that stops URL rewrites with category paths being generated for products when 'Use Categories Path for Product URLs' setting is disabled in config.
Replaces
This package is auto-updated.
Last update: 2024-09-08 13:52:09 UTC
README
该扩展做什么
此扩展添加控制台命令,以便能够重新生成:
- 基于URL路径的产品重写URL;
- 基于URL路径的分类重写URL;
- 基于URL路径的CMS页面重写URL;
- 基于URL键和父分类的分类URL路径。
安装
使用Composer;
composer require elgentos/regenerate-catalog-urls php bin/magento setup:upgrade
或下载并将 src
目录复制到 app/code/Elgentos/RegenerateCatalogUrls
,然后运行 php bin/magento setup:upgrade
。
如何使用
Usage:
regenerate:product:url [-s|--store="..."] [pids1] ... [pidsN]
regenerate:category:url [-s]--store="..."] [-r]--root="..."] [cids1] ... [cidsN]
regenerate:category:path [-s]--store="..."] [-r]--root="..."] [cids1] ... [cidsN]
regenerate:cms-page:url [-s]--store="..."] [pids1] ... [pidsN]
Arguments:
pids Products (or Pages) to regenerate
cids Categories to regenerate
Options:
--store (-s) Use a specific store (store Id, store code or 'all')
--root (-r) Regenerate for root category and its children, ignoring cids.
--verbose (-v) Verbose mode to display the errors. Eg: duplicated product urls
--help (-h) Display this help message
例如
# Regenerate url for all products and the global store php bin/magento regenerate:product:url # Regenerate url for products with id (1, 2, 3, 4) for store 1 php bin/magento regenerate:product:url -s1 1 2 3 4 # Regenerate url for all CMS pages php bin/magento regenerate:cms-page:url -s all # Regenerate url for root category 4 and its children for store 1 php bin/magento regenerate:category:url -s1 -r4
常见问题解答
url_key 和 url_path 之间的区别是什么?
url_key
包含键,例如产品 "Joust Duffle Bag" 的 joust-duffle-bag
。 url_path
是通过将 url_key
与后缀(对于产品,存储在 catalog/seo/product_url_suffix
中,默认为 .html
)相加而生成的。因此,默认情况下 url_path
将成为 joust-duffle-bag.html
。它还添加了父分类的类别别名,因此 url_path
可能成为 bags/joust-duffle-bag.html
。然而,从早期 Magento 2.1 版本开始,url_path
的使用已被弃用(见这里)。如果您正在运行较新的 Magento 2 版本,您可以通过运行以下命令安全地删除这些值:DELETE FROM catalog_product_entity_varchar WHERE attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'url_path' AND entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product'))
。
尽管如此,分类中仍然使用URL路径,所以不要删除这些。
为什么我在运行命令时收到 '重复的URL' 警告?
如果您看到此错误,则 catalog_product_entity_varchar
中存在重复的 url_key
值(在商店内)。您可以使用此扩展来检查这些值(您需要手动修复它们):baldwin/magento2-module-url-data-integrity-checker。