Magento 属性过滤器使用“like”未按预期运行
我遇到了 addAttributeToFilter()
问题,它没有按我的预期工作。
$product = Mage::getModel('catalog/product');
...snip...
$simple_associated_collection = $product->getCollection()
->addAttributeToFilter('type_id', 'simple')
->addAttributeToFilter('sku',array('like'=>$configurable_product_sku.'_%'))
->load();
传入 4_%
我期望得到
4_1
4_2
但我也得到
42_1
420_1
目标是获取简单产品的集合,以便我可以在导入后将它们与其可配置的父项关联起来。
我应该如何使用 LIKE
才能获得与 MySQL
中相同的结果?
I am having a problem with addAttributeToFilter()
where it is not working as I expect.
$product = Mage::getModel('catalog/product');
...snip...
$simple_associated_collection = $product->getCollection()
->addAttributeToFilter('type_id', 'simple')
->addAttributeToFilter('sku',array('like'=>$configurable_product_sku.'_%'))
->load();
Passing in 4_%
I expect to get
4_1
4_2
But I also get
42_1
420_1
The goal is to get a collection of simple products so that I can associate them with their configurable parent after an import.
How should I be using LIKE
to get the same results I would in MySQL
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Magento 在这里没有错误,
_
是通配符。我用 Nick 的评论来回显 sql,这正是我所期望的。
固定的:
Magento was not at fault here,
_
is a wildcard character.I used Nick's comment to echo the sql which was what I expected.
Fixed:
例子
example