0

I have the following php code (running under magento 1.7.0.2) that finds a customer group with a particular code. 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?

$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

thanks

Chiragit007
  • 1,646
  • 2
  • 16
  • 31
Lee Dyche
  • 129
  • 2
  • 12
  • Just made a test in 1.12.0.2 without any problems. ` $groupName = 'test with space'; $theGrous = Mage::getModel('customer/group')->getCollection()->addFilter('customer_group_code', $groupName); var_dump($theGrous->getFirstItem()->debug()); ` Resulting in: ` 'customer_group_id' => string(1) "5" 'customer_group_code' => string(15) "test with space" 'tax_class_id' => string(1) "3" ` – Tim Hofman Jul 02 '13 at 12:54

2 Answers2

0

This is another option to get customer group name.

$group = Mage::getModel('customer/customer_group')->load($groupId);
$group->getName();
502_Geek
  • 2,046
  • 2
  • 22
  • 32
  • I believe MrTea means that he wants to match a customer_group on group_code not just getting the name of a group through loading a group by ID. – Tim Hofman Jul 02 '13 at 12:39
0

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!

Lee Dyche
  • 129
  • 2
  • 12