0

I am trying to get attribute set in dropdown in my custom module. I have override Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract class in my custom module.
There is one line, in the code which says

$value = (string) '#{' . $columnName . '}';

If I echo $value it displays me 10 as value but when I try to compare it in if condition

if($value == '10')

It returns false.
I have tried using temp variable to store value for $value but without success. Please guide how to get value for $value in if condition.

2

The #{ } is a PrototypeJS template expression. Without knowing exactly your case, it is hard to say for sure, but I'm wondering if you did this echo $value within the Javascript Template() rendering function? If that is the case, #{ $columnName } would have been evaluated to 10.

Since you are working in PHP though, where the PrototypeJS template expression hasn't been evaluated, what about accommodating for the expression statement? Would something like this work in your case?

if (strpos($value, '10') !== false) {
    // ...
}

Or even:

$colName = ltrim($value, '#{');
$colName = rtrim($value, '}');

if (strpos($colName, '10') !== false) {
    // ...
}

This, however, leaves me wondering if it would be possible to simply use the $columnName variable?

  • @basspayer7, value for $columnName variable is attribute_set, it is a string variable but when used as $value = (string) '#{' . $columnName . '}'; it shows '10'. – John Dec 28 '16 at 5:18
  • Yes, it sounds to me like PrototypeJS is evaluating #{attribute_set} to 10 in your case. So based on that, you may need to either load the attribute sets with your ResourceModel to determine how many there are or do the work on the front end - in JS. – bassplayer7 Dec 28 '16 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.