{"id":43,"date":"2017-12-19T06:38:09","date_gmt":"2017-12-19T06:38:09","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2017\/12\/19\/get-product-options-in-magento-2\/"},"modified":"2025-03-17T06:27:14","modified_gmt":"2025-03-17T06:27:14","slug":"get-product-options-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-product-options-in-magento-2\/","title":{"rendered":"How to Get Product Options in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 supports the functionality for creating and assigning the custom options to the products. The process to add new custom product options is simple for any store owner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the steps given below for getting Product Options in Magento 2:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Generate Object Manager<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$_objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Generate the Product<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$product = $_objectManager->get('\\Magento\\Catalog\\Model\\Product')->load($id);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Custom Options<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$customOptions = $_objectManager->get('Magento\\Catalog\\Model\\Product\\Option')->getProductOptionCollection($product);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Configurable Options<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$productTypeInstance = $_objectManager->get('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable');\n$productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray\n($product);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">5. Grouped Childs<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$typeInstance = $_objectManager->get('Magento\\GroupedProduct\\Model\\Product\\Type\\Grouped');$childs = $typeInstance->getAssociatedProducts($product);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">6. Bundle Selection<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$store_id = $_storeManager->getStore()->getId();\n            $options = $_objectManager->get('Magento\\Bundle\\Model\\Option')\n         ->getResourceCollection()\n                          ->setProductIdFilter($product->getId())\n                          ->setPositionOrder();\n         $options->joinValues($store_id);\n$typeInstance = $_objectManager->get('Magento\\Bundle\\Model\\Product\\Type');\n$selections = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Following these steps will enable Product Options in your Magento 2 Store.<br>If you have faced any issue while using this guide, do let us know by commenting below and we will help you out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 supports the functionality for creating and assigning the custom options to the products. The process to add new custom product options is simple for any store owner. Follow the steps given below for getting Product Options in Magento 2: 1. Generate Object Manager 2. Generate the Product 3. Custom Options 4. Configurable Options [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-magento"],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":9382,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions\/9382"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}