Magento API:添加新产品后重建索引
我目前正在编写一个脚本,可以让我在 magento 中导入多个产品。
$product = Mage::getModel('catalog/product');
$product->setSku($data['sku']);
//etc etc
$product->save();
该产品被完美创建,但它不会显示在我的前端,直到我将其保存在后端(不更改任何内容!)或者我在后端重建索引。
我对相关数据库表进行了比较,以查看保存产品并将这些字段添加到导入脚本时发生的变化,但它没有任何效果。导入的产品必须没问题,因为当我通过后端手动重建索引时它会显示出来。
缓存已完全禁用。
现在我的问题是:导入产品后如何重建索引?
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();
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.
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.
Caching is completely disabled.
Now my question is: How can I rebuild the indexes after importing my products?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 Index 模块中使用这样的模型。
由于您需要重建所有索引,因此没有应用于集合的过滤器。但是您可以通过
addFieldToFilter($field, $condition)
方法按参数集(代码、上次重新索引等)过滤索引进程列表。小建议
在导入产品时将索引设置为手动模式会很好,这将帮助您加快导入过程,因为其中一些会观察产品保存事件,因此需要一些时间。您可以通过以下方式进行操作:
You can use such a model in Index module.
Since you need to rebuild all the indexes, there is no filters aplied to collection. But you can filter index processes list by set of parameters (code, last time re-indexed, etc) via
addFieldToFilter($field, $condition)
method.Small Suggestion
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:
至少有两种情况会阻止索引器在保存时重新索引产品。
一:索引属性中的“手动更新”设置,您可以在“系统”、“索引管理”下找到。如果您希望在保存时对产品建立索引,则应将其设置为“保存时更新”。
二:setIsMassupdate 产品标志,例如在 DataFlow 批量导入过程中使用,以防止在每次产品保存方法调用时触发索引器。
希望这有帮助。
问候, 亚历山德罗
There are at least two circumstances that prevent indexer to reindex a product on save.
One: the "Manual update" setting in the Indexes properties you find under System, Index Management. You should set it to "Update on Save" if you want a product to be indexed upon a save.
Two: the setIsMassupdate product flag that is used, for example, in DataFlow batch import procedures in order to prevent indexer to be triggered upon each product save method call.
Hope this helps.
Regards, Alessandro