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
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
2. Generate the Product
$product = $_objectManager->get('\Magento\Catalog\Model\Product')->load($id);
3. Custom Options
$customOptions = $_objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);
4. Configurable Options
$productTypeInstance = $_objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable'); $productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray ($product);
5. Grouped Childs
$typeInstance = $_objectManager->get('Magento\GroupedProduct\Model\Product\Type\Grouped');$childs = $typeInstance->getAssociatedProducts($product);
6. Bundle Selection
$store_id = $_storeManager->getStore()->getId(); $options = $_objectManager->get('Magento\Bundle\Model\Option') ->getResourceCollection() ->setProductIdFilter($product->getId()) ->setPositionOrder(); $options->joinValues($store_id); $typeInstance = $_objectManager->get('Magento\Bundle\Model\Product\Type'); $selections = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);
Following these steps will enable Product Options in your Magento 2 Store.
If you have faced any issue while using this guide, do let us know by commenting below and we will help you out.