php – 使用’like’的Magento属性过滤器不能按预期运行
发布时间:2020-12-13 17:17:15 所属栏目:PHP教程 来源:网络整理
导读:我遇到addAttributeToFilter()的问题,它没有像我期望的那样工作. $product = Mage::getModel('catalog/product');...snip...$simple_associated_collection = $product-getCollection() -addAttributeToFilter('type_id','simple') -addAttributeToFilter('s
我遇到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相同的结果? 解决方法
Magento在这里没有错,_是一个通配符.
我用Nick的评论回应了我所期望的sql. 固定: ->addAttributeToFilter('sku',array('like'=>$configurable_product_sku.'_%')) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |