As caption, I would like get the product attributes as attribute code like 'Label_x' for example 'Label_Hot', 'Label_Big_Sale'
can't create Attributes object with all attribute
I try the code as following:
public function label ($product)
{
$attributes = $product->getAttribute();
foreach ($attributes as $attribute) {
if (stristr($attribute, 'label')==true)
{
...........logic..........
}
}
}
Best Answer
Change $product->getAttribute() to $product->getAttributes():
Now you would be able to loop through the attributes and have access to the attribute object. You are able to use $attribute->getCode() to get the code.