简体   繁体   English

Magento Collection过滤器不适用于空格

[英]Magento Collection Filter not working with spaces

I have the following php code (running under magento 1.7.0.2) that finds a customer group with a particular code. 我有以下php代码(在magento 1.7.0.2下运行),用于查找具有特定代码的客户组。 The code works fine for groups that have no spaces in the code value, however it will not find any groups with a space in the code value, Can you locate the reason? 该代码适用于代码值中没有空格的组,但是找不到代码值中有空格的组,您能找到原因吗?

I don't want to change the code to use the group ID as this is not practical in this situation, can anyone help? 我不想更改代码以使用组ID,因为在这种情况下这不切实际,有人可以帮忙吗?

$theGrous = Mage::getModel('customer/group')->getCollection()->addFilter('customer_group_code', $groupName);

For example when the variable $groupName is 'Standard' I find results, when it is 'Standard Rate' I don't get it as it, this happens for any codes with spaces in them 例如,当变量$ groupName为'Standard'时,我找到结果;当变量为'Standard Rate'时,我没有得到它,对于其中带有空格的任何代码,都会发生这种情况

thanks 谢谢

This is another option to get customer group name. 这是获取客户组名称的另一种方法。

$group = Mage::getModel('customer/customer_group')->load($groupId);
$group->getName();

thanks for looking into it, in the end I changed the code to iterate over collection and manually compare each code, and it still didn't work! 感谢您的研究,最后我更改了代码以遍历集合并手动比较每个代码,但仍然无法正常工作! Turns out that there was a slight difference in the names which for reason I didn't notice so the original filter was working correctly after all! 事实证明,名称略有不同,出于我没有注意到的原因,所以原始过滤器毕竟可以正常工作!

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM