Magento的API:增加新产品后重建索引 [英] Magento API: Rebuild Indexes after adding new products

查看:229
本文介绍了Magento的API:增加新产品后重建索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个脚本,让我导入多个产品在Magento。

I am currently writing a script that lets me import multiple products in magento.

$product = Mage::getModel('catalog/product');
$product->setSku($data['sku']);
//etc etc
$product->save();

该产品被创造完美,但它不会在我的前端显示,直到我要么把它保存在后端(不改变任何东西!)或I重建索引在后端。

The product gets created perfectly but it won't show up in my frontend until I either save it in the backend (without changing anything!) OR I rebuild the indexes in the backend.

我做了相关的数据库表,看看当我保存的产品,并添加这些字段我的导入脚本什么的改变差异,但它并没有任何影响。进口产品是OK,因为它表明,当我通过手动后端重建索引。

I did a diff on the relevant database tables to see what's changing when I save the product and added those fields to my import script, but it did not have any effect. The imported product has to be OK since it shows up when I rebuild the indexes via the backend manually.

缓存是完全禁止。

现在我的问题是:我如何导入我的产品后重建索引

Now my question is: How can I rebuild the indexes after importing my products?

推荐答案

您可以使用索引模块这样的模式。

You can use such a model in Index module.

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('reindexAll');

由于需要重建所有索引,没有应用。查阅全文收集到过滤器。但是你可以通过一套通过 addFieldToFilter参数(code,最后一次重新索引等)($场,$条件)筛选指标的进程列表方法。

小建议

将是巨大的索引设置为手动模式,而你导入的产品,它会帮助你加快导入过程中,因为他们中的一些观察产品节省事件,所以它需要一些时间。你可以这样做以下列方式:

Would be great to set indexes to manual mode while you importing the products, it will help you to speed up the import process, because some of them observe product saving event , so it takes some time. You can do it in the following way:

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
$processes->walk('save');
// Here goes your
// Importing process
// ................
$processes->walk('reindexAll');
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
$processes->walk('save');

这篇关于Magento的API:增加新产品后重建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆