At product details page we have product name, price, sku etc... for related products but how can we get custom options?
-
You can Refer this one.. magento.stackexchange.com/questions/147935/…– Magento2 DevloperCommented Mar 7, 2017 at 6:34
-
@Jimit Bhavsar, have you solved your problem? if yes then please share your solution here. I have too get custom options in related product section.– Harshil ParekhCommented Jan 28, 2019 at 10:49
-
@H_Parekh using product id we can get custom option as given below code, but my requirement is different and for that i haven't found any solution.– Jimit BhavsarCommented Jan 29, 2019 at 9:08
Add a comment
|
2 Answers
You can use below code.
$_product = $block->getProduct();
foreach ($_product->getOptions() as $o) {
if ($o->getTitle() != 'Color') { // or another title of option
continue;
}
foreach ($o->getValues() as $value) {
print_r($value->getData());
}
}
Step 1: Create object manager
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
Step 2: Generate the product Generate the product that need to be assigned custom options.
$product = $_objectManager->get('\Magento\Catalog\Model\Product')->load($id);
Step 3: Custom options
$customOptions = $_objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($product);
Step 4: Configurable Options
$productTypeInstance = $_objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable');
$productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product);
Thank you.