更改为magento索引器进程

时间:2016-09-26 11:45:28

标签: magento url-rewriting

我需要制作这样的产品网址" attribute1 / attribute2 / product-url-key"动态。我发现每个产品的网址都在enterprise_url_rewrite表中,请求路径字段。

我也希望对索引器进程进行更改,因此更改将在重新运行时保留,但我不知道它在哪里?

1 个答案:

答案 0 :(得分:1)

下午好!让我们打破这个:

  

我需要动态制作这样的产品网址“attribute1 / attribute2 / product-url-key”

是 - 您可以使用代表您已识别的数据库表的Magento模型动态创建URL重写:

/** @var Enterprise_UrlRewrite_Model_Redirect $rewrite */
$rewrite = Mage::getSingleton('enterprise_urlrewrite/redirect');

// Create new record or load the existing one
$rewrite->loadByRequestPath($requestUrl, $store->getId());

$rewrite
    ->setStoreId($store->getId()) // define which store the rewrite should be
    ->setOptions(null) // specify any rewrite/redirect/custom options
    ->setRequestPath($requestUrl) // specify the request URL
    ->setIdentifier($requestUrl)
    ->setTargetPath($targetPath)  // specify the redirect target
    ->setEntityType(Mage_Core_Model_Url_Rewrite::TYPE_CUSTOM)
    ->setDescription('Add a comment if you want to');

$rewrite->save();

这将尝试加载$requestUrl的现有网址重写/重定向,如果找不到,则会返回一个空模型,您可以使用该数据修饰并保存。

“选项”定义它是临时的还是永久的重定向(302 vs 301)。

More information here通过Magento EE用户指南。

  

我也希望对索引器进程进行更改,因此更改将在重新运行时保留,但我不知道它在哪里?

不要担心。 (现代)Magento数据库在需要索引记录的任何地方都有表触发器,并将检测这些表上的创建,更新和删除。索引器将检测到需要进行的更改,并根据需要为您生成更改。

如果您看到URL重写消失,则很可能是因为您一直使用SQL将它们直接添加到索引表中,因此只要索引器运行,就会重写该表。为避免这种情况,请使用上述模型,并将所有内容保存到正确的位置并正确编入索引。

相关问题