I have a collection of product I am looping and displaying for E.G
...
$product->getName()
...
$product->getProductUrl()
...
Now Also I am getting it some option like attributeText foreach product E.G
$product->getAttributeText('color') // this gives me red,green,blue so on...
Now My question is how do I get ID:
$product->getAttributeId('color')
I know that in \Magento\Catalog\Model\Product
there is a function like so:
/**
* Get attribute text by its code
*
* @param string $attributeCode Code of the attribute
* @return string
*/
public function getAttributeText($attributeCode)
{
return $this->getResource()->getAttribute($attributeCode)->getSource()->getOptionText(
$this->getData($attributeCode)
);
}
I could and I did test and it worked so potentially I could do a function :
public function getAttributeId($attributeCode)
{
return $this->getResource()->getAttribute($attributeCode)->getSource()->getOptionId(
$this->getData($attributeCode)
);
}
That works but how to implement this outside of vendor folder or if there is another way to get the id even better please share.
Thanks.