一切似乎都是正确的,但我的压倒一切不起作用
尝试覆盖模型
vendor/magento/module-catalog-url-rewrite/Model/ProductUrlPathGenerator.php
di.xml的路径app/code/Rltsquare/Customrewrite/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator" type="Rltsquare\Customrewrite\Model\CatalogUrlRewrite\ProductUrlPathGenerator" />
</config>
覆盖后模型文件的路径
app/code/Rltsquare/Customrewrite/Model/CatalogUrlRewrite/ProductUrlPathGenerator.php
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Rltsquare\Customrewrite\Model\CatalogUrlRewrite;
use Magento\Store\Model\Store;
class ProductUrlPathGenerator extends \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator
{
protected function prepareProductUrlKey(\Magento\Catalog\Model\Product $product)
{
$urlKey = $product->getUrlKey();
return 'products/'.$product->formatUrlKey($urlKey === '' || $urlKey === null ? $product->getName() : $urlKey);
}
}
在这种覆盖(首选项)
之后,我是否必须编译或运行任何其他命令