Configurable Product - Get child product id

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
6
down vote

favorite












How to get child product id's from parent product id in magento2 for configurable product?



I want to get child product id of parent product in magento based on parent product id.










share|improve this question





















  • Please check my answer and let me know.
    – Rohan Hapani
    7 hours ago










  • Please accept and upvote answer.
    – Rohan Hapani
    6 hours ago
















up vote
6
down vote

favorite












How to get child product id's from parent product id in magento2 for configurable product?



I want to get child product id of parent product in magento based on parent product id.










share|improve this question





















  • Please check my answer and let me know.
    – Rohan Hapani
    7 hours ago










  • Please accept and upvote answer.
    – Rohan Hapani
    6 hours ago












up vote
6
down vote

favorite









up vote
6
down vote

favorite











How to get child product id's from parent product id in magento2 for configurable product?



I want to get child product id of parent product in magento based on parent product id.










share|improve this question













How to get child product id's from parent product id in magento2 for configurable product?



I want to get child product id of parent product in magento based on parent product id.







magento2 configurable-product






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 7 hours ago









Sanjay Vadadoriya

335




335











  • Please check my answer and let me know.
    – Rohan Hapani
    7 hours ago










  • Please accept and upvote answer.
    – Rohan Hapani
    6 hours ago
















  • Please check my answer and let me know.
    – Rohan Hapani
    7 hours ago










  • Please accept and upvote answer.
    – Rohan Hapani
    6 hours ago















Please check my answer and let me know.
– Rohan Hapani
7 hours ago




Please check my answer and let me know.
– Rohan Hapani
7 hours ago












Please accept and upvote answer.
– Rohan Hapani
6 hours ago




Please accept and upvote answer.
– Rohan Hapani
6 hours ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










Try the below solution:



<?php
$productId = 5; //Configurable product ID
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_product = $_objectManager->create('MagentoCatalogModelProduct')->load($productId);
$_childProducts = $_product->getTypeInstance()->getUsedProducts($_product);
foreach ($_childProducts as $simpleProduct)
echo $simpleProduct->getId();

?>


Suggestion: Don't use object manager directly in your code as its not a best practice. You need to inject the product model class to your respective class then use it.






share|improve this answer




















  • yes i have injected model and working fine. Thanks @sukumar
    – Sanjay Vadadoriya
    5 hours ago










  • Welcome. Happy Coding :)
    – Sukumar Gorai
    5 hours ago

















up vote
2
down vote













Try to use this code :



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$configProduct = $objectManager->create('MagentoCatalogModelProduct')->load($product_id);

$_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);

foreach ($_children as $child)
echo $child->getID();






share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f242072%2fconfigurable-product-get-child-product-id%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    Try the below solution:



    <?php
    $productId = 5; //Configurable product ID
    $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $_product = $_objectManager->create('MagentoCatalogModelProduct')->load($productId);
    $_childProducts = $_product->getTypeInstance()->getUsedProducts($_product);
    foreach ($_childProducts as $simpleProduct)
    echo $simpleProduct->getId();

    ?>


    Suggestion: Don't use object manager directly in your code as its not a best practice. You need to inject the product model class to your respective class then use it.






    share|improve this answer




















    • yes i have injected model and working fine. Thanks @sukumar
      – Sanjay Vadadoriya
      5 hours ago










    • Welcome. Happy Coding :)
      – Sukumar Gorai
      5 hours ago














    up vote
    2
    down vote



    accepted










    Try the below solution:



    <?php
    $productId = 5; //Configurable product ID
    $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $_product = $_objectManager->create('MagentoCatalogModelProduct')->load($productId);
    $_childProducts = $_product->getTypeInstance()->getUsedProducts($_product);
    foreach ($_childProducts as $simpleProduct)
    echo $simpleProduct->getId();

    ?>


    Suggestion: Don't use object manager directly in your code as its not a best practice. You need to inject the product model class to your respective class then use it.






    share|improve this answer




















    • yes i have injected model and working fine. Thanks @sukumar
      – Sanjay Vadadoriya
      5 hours ago










    • Welcome. Happy Coding :)
      – Sukumar Gorai
      5 hours ago












    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    Try the below solution:



    <?php
    $productId = 5; //Configurable product ID
    $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $_product = $_objectManager->create('MagentoCatalogModelProduct')->load($productId);
    $_childProducts = $_product->getTypeInstance()->getUsedProducts($_product);
    foreach ($_childProducts as $simpleProduct)
    echo $simpleProduct->getId();

    ?>


    Suggestion: Don't use object manager directly in your code as its not a best practice. You need to inject the product model class to your respective class then use it.






    share|improve this answer












    Try the below solution:



    <?php
    $productId = 5; //Configurable product ID
    $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $_product = $_objectManager->create('MagentoCatalogModelProduct')->load($productId);
    $_childProducts = $_product->getTypeInstance()->getUsedProducts($_product);
    foreach ($_childProducts as $simpleProduct)
    echo $simpleProduct->getId();

    ?>


    Suggestion: Don't use object manager directly in your code as its not a best practice. You need to inject the product model class to your respective class then use it.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 7 hours ago









    Sukumar Gorai

    4,3042424




    4,3042424











    • yes i have injected model and working fine. Thanks @sukumar
      – Sanjay Vadadoriya
      5 hours ago










    • Welcome. Happy Coding :)
      – Sukumar Gorai
      5 hours ago
















    • yes i have injected model and working fine. Thanks @sukumar
      – Sanjay Vadadoriya
      5 hours ago










    • Welcome. Happy Coding :)
      – Sukumar Gorai
      5 hours ago















    yes i have injected model and working fine. Thanks @sukumar
    – Sanjay Vadadoriya
    5 hours ago




    yes i have injected model and working fine. Thanks @sukumar
    – Sanjay Vadadoriya
    5 hours ago












    Welcome. Happy Coding :)
    – Sukumar Gorai
    5 hours ago




    Welcome. Happy Coding :)
    – Sukumar Gorai
    5 hours ago












    up vote
    2
    down vote













    Try to use this code :



    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $configProduct = $objectManager->create('MagentoCatalogModelProduct')->load($product_id);

    $_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);

    foreach ($_children as $child)
    echo $child->getID();






    share|improve this answer


























      up vote
      2
      down vote













      Try to use this code :



      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $configProduct = $objectManager->create('MagentoCatalogModelProduct')->load($product_id);

      $_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);

      foreach ($_children as $child)
      echo $child->getID();






      share|improve this answer
























        up vote
        2
        down vote










        up vote
        2
        down vote









        Try to use this code :



        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $configProduct = $objectManager->create('MagentoCatalogModelProduct')->load($product_id);

        $_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);

        foreach ($_children as $child)
        echo $child->getID();






        share|improve this answer














        Try to use this code :



        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        $configProduct = $objectManager->create('MagentoCatalogModelProduct')->load($product_id);

        $_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);

        foreach ($_children as $child)
        echo $child->getID();







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 7 hours ago

























        answered 7 hours ago









        Rohan Hapani

        3,36911456




        3,36911456



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f242072%2fconfigurable-product-get-child-product-id%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            How to decode/decipher Mozilla Firefox proprietary .jsonlz4 format? (sessionstore-backups/recovery.jsonlz4)

            White Anglo-Saxon Protestant

            How to be valuable when automation & IT are stealing my job (and maybe my whole career)? [closed]