1

I'm trying to show all available sizes for one product on list.phtml

I've set up a custom attribute size_age (id:142) but when I try use the code

$attributeLabel = $customer->getResource() ->getAttribute('size_age') ->getFrontend() ->getAttribute() ->getFrontendLabel();

I get this error:

Fatal error: Call to a member function getResource() on null


UPDATE:

thank you for your answers. I changed the code to:

$attributeLabel = $_product->getResource() ->getAttribute('size_age') ->getFrontend() ->getAttribute() ->getFrontendLabel();

I dont have any error right now.

But I dont get any output. I'm trying to echo all available sizes for the product.

5
  • $customer is wrong,it should be product object
    – Amit Bera
    Commented May 4, 2016 at 12:03
  • What is your $customer variable ? Shouldn't it be a $product variable ? Commented May 4, 2016 at 12:03
  • It should be $_product, NOT $customer Commented May 4, 2016 at 12:04
  • Please share more code?
    – Amit Bera
    Commented May 4, 2016 at 12:04
  • thank you for your answers. I changed the code like you said and I dont have any error right now. But I dont get any output. I'm trying to echo all available sizes for the product
    – marc
    Commented May 8, 2016 at 17:34

1 Answer 1

4

You can get the value of custom attribute using following:

$attribute = $_product->getResource()->getAttribute('custom_attribute_code');
if ($attribute) {
    echo $attribute_value = $attribute->getFrontend()->getValue($_product);
}

Your Answer

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

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