在Magento 中,如何通过manage_stock 字段过滤产品集合?
我构建了一个库存更新脚本 - 在 Magento 中获取产品集合,并迭代结果集,更新产品库存(基于单独的库存提要)。
我可以毫无问题地获取产品集合。
但是,我只想获取“管理库存”字段(“库存”选项卡下的管理中的下拉列表)设置为“是”的产品。
所以我尝试了:
// get all magento catalog products with "manage stock" field set to yes
$items = Mage::getModel('catalog/product')->getCollection();
$items
->addAttributeToSelect(array(
'id',
'sku'
))
->addFieldToFilter(array(
array(
'attribute' => 'manage_stock',
'eq' => '1'
),
));
但是,收到错误:
属性名称无效:manage_stock。
I've built an inventory update script - where I fetch a product collection in Magento, and iterate through the result set, updating product inventory (based on a separate inventory feed) as I go.
I can fetch the product collection no problem.
However, I only want to get products which have the "Manage Stock" field (a dropdown in the admin under the "inventory" tab) set to "yes".
So I tried:
// get all magento catalog products with "manage stock" field set to yes
$items = Mage::getModel('catalog/product')->getCollection();
$items
->addAttributeToSelect(array(
'id',
'sku'
))
->addFieldToFilter(array(
array(
'attribute' => 'manage_stock',
'eq' => '1'
),
));
But, getting an error:
Invalid attribute name: manage_stock.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,马特,您可能必须使用类似这样的东西,而不是使用 addFieldToFilter ,
manage_stock 不是产品上的属性,而是实际库存商品上的属性。
更新:
假设您的配置设置被设置为管理库存,并且没有人将其设置为不使用配置设置但使其管理库存。
我添加了这一点,
我认为这应该是正确的,并且可以解释任何用户错误,因为如果您将配置设置为管理库存,那么如果您不想管理库存,您应该只说使用配置设置,但用户可以将其设置为是的,无需检查。
Hey Matt, instead of using the addFieldToFilter you will probably have to use soemthing like this
manage_stock is not a attribute on a product but on the actual stock item.
UPDATE:
That assumed that your config settings were set to manage stock and that no one ever set it to not use the config setting but make it manage stock.
I added this
I think this should be correct and accounts for any user error because if you have the config set to manage stock then if you don't want to manage stock you should just say use config settinges, but a user could set it to yes without checking that.