I am trying to get product attribute in product listing page based on attribute set id but its not working properly. can anyone help on this.
$attributes = $_product->getAttributes(); foreach ($attributes as $attribute) { // var_dump($attribute->getAttributeModel()); $value = $attribute->getFrontend()->getValue($_product); if ($attribute->getIsVisibleOnFront()) { echo $attribute->getFrontendLabel().' : '.$attribute->getFrontend()->getValue($_product) . '
'; } }
Best Answer
I suggest you should use Magento\Eav\Api\AttributeManagementInterface to get all attributes by attribute set id
To do this, we need to override Magento\Catalog\Block\Product\ListProduct class and inject this class into the constructor. See more detail here:
Hopefully this will solve your issue
Regards