{"id":54706,"date":"2016-07-15T17:23:53","date_gmt":"2016-07-15T17:23:53","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=54706"},"modified":"2024-02-20T09:10:04","modified_gmt":"2024-02-20T09:10:04","slug":"get-configurable-associated-products-id-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/","title":{"rendered":"How to get configurable associated products id  in magento2"},"content":{"rendered":"\n<p>Here we&#8217;ll learn that how to get configurable associated products id&nbsp; in magento2<\/p>\n\n\n\n<p>Step1# : We&#8217;ll create Demo.php class file in app\/code\/NameSpace\/ModuleName\/Controller\/Product<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nnamespace NameSpace\\Modulename\\Controller\\Product;\n\nuse Magento\\Catalog\\Model\\Product;\n\nclass Demo extends \\Magento\\Framework\\App\\Action\\Action\n{\n    \/**\n     * Product $product\n     *\/\n    private $product;\n\n    public function __construct(\n        \\Magento\\Framework\\App\\Action\\Context $context,\n        Product $product\n    ) {\n        parent::__construct($context);\n        $this-&gt;product = $product;\n    }\n\n    public function execute()\n    {\n        $id = 1; \/\/ id of a configurable product\n        $configurable = $this-&gt;product-&gt;load($id);\n        $children = $configurable\n                      -&gt;getTypeInstance()\n                      -&gt;getUsedProducts($configurable);\n        foreach ($children as $child) {\n            echo $child-&gt;getEntityId();\n        }\n    }\n}<\/pre>\n\n\n\n<p>Here&nbsp;<em>$child-&gt;getEntityId()&nbsp;<\/em>will print the associated product ids.<\/p>\n\n\n\n<p>But by using&nbsp;<em>getUsedProducts()<\/em> we will not get those associated products that are out of stock or disabled. So in place of it if we write<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">$children = $configurable\n              -&gt;getTypeInstance()\n              -&gt;getChildrenIds($configurable-&gt;getId());<\/pre>\n\n\n\n<p>then we can get all the associated product ids of that configurable product.<\/p>\n\n\n\n<p>Thanks \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here we&#8217;ll learn that how to get configurable associated products id&nbsp; in magento2 Step1# : We&#8217;ll create Demo.php class file in app\/code\/NameSpace\/ModuleName\/Controller\/Product Here&nbsp;$child-&gt;getEntityId()&nbsp;will print the associated product ids. But by using&nbsp;getUsedProducts() we will not get those associated products that are out of stock or disabled. So in place of it if we write then we <a href=\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":4,"featured_media":52441,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,3286],"tags":[3366,3367,2070],"class_list":["post-54706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","category-magento2-1","tag-associated","tag-configurable","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to get configurable associated products id in magento2 - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to get configurable associated products id in magento2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Here we&#8217;ll learn that how to get configurable associated products id&nbsp; in magento2 Step1# : We&#8217;ll create Demo.php class file in app\/code\/NameSpace\/ModuleName\/Controller\/Product Here&nbsp;$child-&gt;getEntityId()&nbsp;will print the associated product ids. But by using&nbsp;getUsedProducts() we will not get those associated products that are out of stock or disabled. So in place of it if we write then we [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-15T17:23:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-20T09:10:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Abhishek Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abhishek Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/\"},\"author\":{\"name\":\"Abhishek Singh\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/573e459f54796eb4195511990de4bfd0\"},\"headline\":\"How to get configurable associated products id in magento2\",\"datePublished\":\"2016-07-15T17:23:53+00:00\",\"dateModified\":\"2024-02-20T09:10:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/\"},\"wordCount\":90,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png\",\"keywords\":[\"Associated\",\"configurable\",\"Magento2\"],\"articleSection\":[\"Magento2\",\"Magento2.1\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/\",\"name\":\"How to get configurable associated products id in magento2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png\",\"datePublished\":\"2016-07-15T17:23:53+00:00\",\"dateModified\":\"2024-02-20T09:10:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to get configurable associated products id in magento2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/573e459f54796eb4195511990de4bfd0\",\"name\":\"Abhishek Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d4ac7e0e671bf743359d7e3f140c262d1b16d71106f0a1aeaecca327a2805ae4?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d4ac7e0e671bf743359d7e3f140c262d1b16d71106f0a1aeaecca327a2805ae4?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Abhishek Singh\"},\"description\":\"Adobe Commerce certified Magento developer with over 12 years of experience at Webkul. Passionate about scalable Magento 2-based webshops, AI, and multi-channel integrations, Abhishek consistently delivers innovative and efficient e-commerce solutions that propel businesses forward.\",\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/abhishek\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to get configurable associated products id in magento2 - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/","og_locale":"en_US","og_type":"article","og_title":"How to get configurable associated products id in magento2 - Webkul Blog","og_description":"Here we&#8217;ll learn that how to get configurable associated products id&nbsp; in magento2 Step1# : We&#8217;ll create Demo.php class file in app\/code\/NameSpace\/ModuleName\/Controller\/Product Here&nbsp;$child-&gt;getEntityId()&nbsp;will print the associated product ids. But by using&nbsp;getUsedProducts() we will not get those associated products that are out of stock or disabled. So in place of it if we write then we [...]","og_url":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-07-15T17:23:53+00:00","article_modified_time":"2024-02-20T09:10:04+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png","type":"image\/png"}],"author":"Abhishek Singh","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Abhishek Singh","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/"},"author":{"name":"Abhishek Singh","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/573e459f54796eb4195511990de4bfd0"},"headline":"How to get configurable associated products id in magento2","datePublished":"2016-07-15T17:23:53+00:00","dateModified":"2024-02-20T09:10:04+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/"},"wordCount":90,"commentCount":3,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png","keywords":["Associated","configurable","Magento2"],"articleSection":["Magento2","Magento2.1"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/","url":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/","name":"How to get configurable associated products id in magento2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png","datePublished":"2016-07-15T17:23:53+00:00","dateModified":"2024-02-20T09:10:04+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/06\/Magneto-Code-Snippet-1.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/get-configurable-associated-products-id-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to get configurable associated products id in magento2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/573e459f54796eb4195511990de4bfd0","name":"Abhishek Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d4ac7e0e671bf743359d7e3f140c262d1b16d71106f0a1aeaecca327a2805ae4?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d4ac7e0e671bf743359d7e3f140c262d1b16d71106f0a1aeaecca327a2805ae4?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Abhishek Singh"},"description":"Adobe Commerce certified Magento developer with over 12 years of experience at Webkul. Passionate about scalable Magento 2-based webshops, AI, and multi-channel integrations, Abhishek consistently delivers innovative and efficient e-commerce solutions that propel businesses forward.","sameAs":["http:\/\/webkul.com"],"url":"https:\/\/webkul.com\/blog\/author\/abhishek\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/54706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=54706"}],"version-history":[{"count":4,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/54706\/revisions"}],"predecessor-version":[{"id":423102,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/54706\/revisions\/423102"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/52441"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=54706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=54706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=54706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}