0

At product details page we have product name, price, sku etc... for related products but how can we get custom options?

3
  • You can Refer this one.. magento.stackexchange.com/questions/147935/… Commented 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. Commented 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. Commented Jan 29, 2019 at 9:08

2 Answers 2

0

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());
    }
}
-1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.