2

On catalog page, I want to display custom attribute near each product (e.g. shoes_model). When I try to fetch it:

$_product->getAttributeText('shoes_model'); // returns nothing

... it returns empty value. But when I try to get another attribute, e.g. brand, it returns correct value:

$_product->getAttributeText('brand'); // returns brand name

Can anyone explain why is this happening and how to include custom attribute in catalog products collection.

p.s. Option "Used in Product Listing" is set to Yes for both attributes, and I'm 100% sure that shoes_model is defined.

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Jun 1, 2013 at 7:24
0

4 Answers 4

7

Everything was simpler than I thought, as shoes_model is text-based attribute, I should get it like so:

$_product->getShoesModel();

or like so:

$_product->getData('shoes_model');
Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
answered Jun 1, 2013 at 8:46
1

Follow this code

 $attribute = $_product->getResource()->getAttribute('custom_attribute_code');
 if ($attribute)
 {
 echo $attribute_value = $attribute ->getFrontend()->getValue($_product);
 }
answered Apr 3, 2015 at 10:38
0

Try this:

<?php $_product = $this->getProduct(); ?>
<?php echo $_product->getData('attributename'); ?>

And also make sure you have included the attributes in layout, and that they are set to "visible on frontend".

answered Jun 1, 2013 at 13:09
0

Try using below code:

<?php 
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $_helper = $this->helper('Magento\Catalog\Helper\Output');
 $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product 
 $shoes = $product->getResource()->getAttribute('shoes_model')->getFrontend()->getValue($product); ?>

Now you can use this variable $shoes anywhere you like

Hope it will work for you.

answered Aug 14, 2018 at 3:49

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.