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.

  • $customer is wrong,it should be product object – Amit Bera May 4 '16 at 12:03
  • What is your $customer variable ? Shouldn't it be a $product variable ? – Raphael at Digital Pianism May 4 '16 at 12:03
  • It should be $_product, NOT $customer – Anil Suthar May 4 '16 at 12:04
  • Please share more code? – Amit Bera May 4 '16 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 May 8 '16 at 17:34
3

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); }

| improve this answer | |

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.