DefaultMagento

How to Get Configurable Attribute for any Configurable Product in Magento 2.x

Posted On
Posted By Praveen Maurya

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 🙂

Related Post

leave a Comment

Latest Post

React Native

How to create/generate ipa file in react native iOS

Read More
Posted On
React Native

How to Set Splash Screen and AppIcon in react native iOS

Read More
Posted On
React Native

Getting Started with React Native First App With Little Information(Course for beginners, start with basics)

Read More
Posted On
React Native

How To Integrating Firebase with iOS in React Native

Read More
Posted On
What's Arround

Companies Preferences on Artificial Intelligence (AI) Jobs position and other Skillsets

Read More
Posted On