We often get all child attributes of any configurable product instead of getting only configurable attribute (like Size, Color etc). So if we want to show all the variation of product on the search page, we can get array of configurable attribute using below code..
public function getChildConfigurableAttribute($product)
{
$data = $product->getTypeInstance()->getConfigurableOptions($product);
$options = array();
$attributes = [];
foreach($data as $attributes){
foreach($attributes as $atrribute) {
$configurableAttributes[$atrribute['attribute_code']][] = $atrribute['option_title'];
}
return $configurableAttributes;
}
Output (is like):
[color] Array ( [0]=>red [1]=>blue [2]=>green ) [size] Array( [0]=>S [1]=>M [2]=>L [3]=>XL )
Happy Coding 🙂
Praveen Maurya work in e-commerce domain having knowledge of Plugin development in Magento 1.x/2.x, Drupal, Woo-Commerce, PrestaShop, Opencart and other e-commerce solution. When he is not engrossed with anything related to these, he loves to explore new things.