Home » Magento, Magento 27 August 2018

Magento 2: Get Simple Product ID & Quantity in Configurable Product using Swatches

This article shows how you can get the associated Simple Product ID and Quantity (Qty) / inventory from a Configurable Product in frontend product detail page in Magento 2.x.

– The below code assumes that Swatches have been used in the product detail page.
– Suppose you have two configurable attributes (color and size) for your configurable product.
– When you click on any color swatch and then click on the size swatch:
– then the available stock quantity of that particular color & size associated product will be displayed.

You can add the below code Javascript and PHP at the beginning of this file: app/design/frontend/Theme_Namespace/Theme_Name/Magento_Catalog/ templates/product/view/addtocart.phtml.

Here’s the full code:

References:

Magento 2 Get selected simple product id in configurable product
Show available inventory on configurable product magento 2
Magento 2: Extract Currently Selected Product ID or SKU

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

Comments are closed.