0

I have configure product with 3 colors.How to get Current Child product_id from Configurable Product in Magento2?

If anyone knows please explain me

  • 1
    On which page? there might be possible that configurable product has more than one child – Keyur Shah Dec 21 '17 at 8:35
  • Sorry ,don't understood your question , what i means by Current Child product id? – Amit Bera Dec 21 '17 at 8:36
  • In product page... – Mano M Dec 21 '17 at 8:40
0

Not sure what you mean by "Current child product_id" A configurable product could have more than 1 child

$children = array();
foreach($collection as $_product) {
        $productName = $_product->getName());
        $_children = $_product->getTypeInstance()->getUsedProducts($_product);
        foreach ($_children as $child){
            $children[] = $child->getID());
        }
    }

And $children would contain all the child ids in an array. Maybe this gives you enough to go on to do what you are trying to achieve?

To get the Simple product based on the selected configurable options you will want to take a look at this answer by obscure: https://magento.stackexchange.com/a/28912/2671

  • EX:Configurable product have 3 colors.If i have select red color. how to get that red color product id in product view page – Mano M Dec 21 '17 at 8:51
  • In that case @MahalakshmiM it looks like you need something like this: magento.stackexchange.com/a/28912/2671 – DanCarlyon Dec 21 '17 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.