0

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 Devloper Mar 7 '17 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. – H_Parekh Jan 28 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 Bhavsar Jan 29 at 9:08
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, privacy policy and cookie policy

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