Hello Magento Folks 👋,

Welcome to Magento 2 How-To blog series by MageComp. Today’s article describes Magento 2: Add Swatch Data in Layered Navigation Aggregations in GraphQL. Not to miss out on our previous blog, Magento 2: How to Get System Configurations Value in Email Templates.

Swatch data comes to help in increasing the shopping experience of your store and let the user purchase with ease from your store. Providing the option of swatching data, the user can select color, size, and other options for a particular product just by selection instead of reloading the page. Magento 2 offers adding swatch data in layered navigation aggregations in GraphQL. The query searches for the products that match the specified search criteria.

Let’s get started 🚀

Magento 2: Add Swatch Data in Layered Navigation Aggregations in GraphQL

Step 1: Create file app/code/VENDOR/EXTENSION/registration.php and add the following code:

 Step 2: Create file app/code/VENDOR/EXTENSION/etc/module.xml and add the following code: 

 Step 3: Create file app/code/VENDOR/EXTENSION/etc/schema.graphqls and add the following code:

 Step 4: Create file app/code/VENDOR/EXTENSION/etc/graphql/di.xml and add the following code:

Step 5: Create file app/code/VENDOR/EXTENSION/DataProvider/Product/LayeredNavigation/DataProviderAggregationPlugin.php and add the following code:

GraphQL Request:

GraphQL Response:

Conclusion:

With the help of the above code, you will be able to add swatch data in layered navigation aggregations in GraphQL. If you stuck anywhere while executing the above code, let me know in the comment section. Help your Magento friends to implement the same by sharing the article with them. Stay connected!

Happy Swatching 😊

[Total: 5   Average: 4.2/5]