Magento 属性过滤器使用“like”未按预期运行

发布于 2024-12-21 09:44:30 字数 587 浏览 2 评论 0原文

我遇到了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独留℉清风醉 2024-12-28 09:44:30

Magento 在这里没有错误,_ 是通配符。

我用 Nick 的评论来回显 sql,这正是我所期望的。

固定的:

->addAttributeToFilter('sku',array('like'=>$configurable_product_sku.'\_%'))

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:

->addAttributeToFilter('sku',array('like'=>$configurable_product_sku.'\_%'))
谁对谁错谁最难过 2024-12-28 09:44:30

例子

->addAttributeToFilter('sku',array('like'=>$configurable_product_sku.'_'.'%'))

example

->addAttributeToFilter('sku',array('like'=>$configurable_product_sku.'_'.'%'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文