0

I'm using the module Amasty's customer Attributes to create custom customer attributes, I like to get custom attribute displayed value but i got the option value. I like to get the value in data-title attribute enter image description here

I tried this

  if ($customAttribute = $customer->getCustomAttribute('custom_value')){
            $regrouper = $customAttribute->getValue();
            
            var_dump(regrouper);exit; //it returns 615 instead of 'Ok'
            
  }

1 Answer 1

1

This is an ugly way of doing it but having been struggling myself doing it I ended up with this workaround creating this method that will take as parameter the getValue return.

If you found a better way of doing thing, please share :)

/**
 * TODO Rework method with collection or repository ?
 * @param $option_id
 * @return string
 */
public function getAttributeValueLabel($option_id){
    $connection = $this->resource->getConnection();
    $select = $connection->select()
        ->from(
            ['ol' => 'eav_attribute_option_value'],
            ['value']
        )
        ->where('option_id = ?',$option_id);
    return $connection->fetchOne($select);
}
4
  • How to get option id? Feb 16, 2022 at 20:05
  • 1
    As I said the option_id should match the value that is already returned by your custom attribute getValue 615 is actually the option id 615. You can pre check the request doing it by hand select * from eav_attribute_option_value where option_id = 615 and you should be able to retrieve the label data in the result request.
    – Claims
    Feb 17, 2022 at 8:25
  • I contacted Amasty, i'm waiting for their answer, otherwise i tested you query and it returns the right result Feb 17, 2022 at 16:13
  • Glad to hear it's working for you. It's not really amasty specific, the issue would be the same with every custom attribues. Now may be the people from amasty will came out with a better solution or even the right way of doing things. Hope !
    – Claims
    Feb 17, 2022 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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