0

How can I get the list of attributes that a product has?

Foe example: Product "camiseta" has color and size as available attributes.

enter image description here

  • Where you want to get these attributes? – Prince Patel Jun 11 '17 at 5:46
  • In a controller – Miguel Jun 11 '17 at 9:40
  • Do you want get the value the attributes for one product? or the entity "attribute"? – raumatbel Jun 11 '17 at 10:04
  • I want check if the product has size or color or both as attributes – Miguel Jun 11 '17 at 16:42
0

can you please inject Magento\Eav\Model\ResourceModel\Entity\Attribute check if attributeid is available.

/**
 * @var \Magento\Eav\Model\ResourceModel\Entity\Attribute
 */
protected $_eavAttribute;
/**
 * @param   Context                                           $context
 * @param   \Magento\Eav\Model\ResourceModel\Entity\Attribute $eavAttribute
 */
public function __construct(
    Context $context,
    \Magento\Eav\Model\ResourceModel\Entity\Attribute $eavAttribute
)
{
    $this->_eavAttribute = $eavAttribute;
    parent::__construct($context);
}

Call the getIdByCode method of Attribute in any method

$attributeIdcolor = $this->_eavAttribute->getIdByCode('catalog_product', 'color');
$attributeIdsize = $this->_eavAttribute->getIdByCode('catalog_product', 'size');
  • please check and let me know it is work :) – Rama Chandran M Jun 11 '17 at 17:29
  • 1
    What I need is the list of available attributes for a given product. For example: product camiseta has color and size as available attributes. – Miguel Jun 11 '17 at 19:17
  • 1
    okey i understand. you need each product what are the attribute are available? am i correct? – Rama Chandran M Jun 11 '17 at 19:28
  • What you are asking is written in blog.chapagain.com.np/… – Rama Chandran M Jun 11 '17 at 19:40
  • if i use $product->getAttributes() i obtain a lot of attributes. I only need check if has attibutes as in the image – Miguel Jun 11 '17 at 20:31

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.