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.

Manashvi Birla
8,8739 gold badges29 silver badges53 bronze badges
asked May 4, 2016 at 12:02
5
  • $customer is wrong,it should be product object 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? 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 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);
}
circlesix
4,3413 gold badges29 silver badges57 bronze badges
answered May 9, 2016 at 21:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.