3

Hello I have created one dropdown attribute with code "custom_collection"

I want to show it on product listing page under each product so in list.phtml file i added this code

$attr_m = $_product->getData('custom_collection');

echo $attr_m;

It returns some id but its not showing the attribute value

1

1 Answer 1

1

I did not find anywhere so i tried custom query and it works

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

 $collection_attr_id = $_product->getData('custom_collection');

 if(!empty($collection_attr_id)):
    $this->_resources = \Magento\Framework\App\ObjectManager::getInstance()
    ->get('Magento\Framework\App\ResourceConnection');
    $connection= $this->_resources->getConnection();
    $themeTable = $this->_resources->getTableName('eav_attribute_option_value');
    $sql = "Select value FROM " . $themeTable . " WHERE option_id = " . $collection_attr_id . ";";
    $result = $connection->fetchAll($sql); 
    echo $result[0]['value'];


 endif;

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.