Configurable Product - Get child product id

Clash 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.
magento2 configurable-product
add a comment |Â
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.
magento2 configurable-product
Please check my answer and let me know.
â Rohan Hapani
7 hours ago
Please accept and upvote answer.
â Rohan Hapani
6 hours ago
add a comment |Â
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.
magento2 configurable-product
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
magento2 configurable-product
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
add a comment |Â
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
add a comment |Â
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.
yes i have injected model and working fine. Thanks @sukumar
â Sanjay Vadadoriya
5 hours ago
Welcome. Happy Coding :)
â Sukumar Gorai
5 hours ago
add a comment |Â
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();
add a comment |Â
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.
yes i have injected model and working fine. Thanks @sukumar
â Sanjay Vadadoriya
5 hours ago
Welcome. Happy Coding :)
â Sukumar Gorai
5 hours ago
add a comment |Â
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.
yes i have injected model and working fine. Thanks @sukumar
â Sanjay Vadadoriya
5 hours ago
Welcome. Happy Coding :)
â Sukumar Gorai
5 hours ago
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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();
add a comment |Â
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();
add a comment |Â
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();
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();
edited 7 hours ago
answered 7 hours ago
Rohan Hapani
3,36911456
3,36911456
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password

Please check my answer and let me know.
â Rohan Hapani
7 hours ago
Please accept and upvote answer.
â Rohan Hapani
6 hours ago