2

I am working on magento2 and i am try to access product all custom option. For now i have added to text box and for access custom option bellow code i have use.

        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $product = $objectManager->get('Magento\Catalog\Model\Product')->load(1001);
        $productOption = $product->getOptions();
        foreach($productOption as $op)
        {
            echo "<pre>";
            print_r($op);
            die;
        }
1

I have found the solutions.

Here is my code.

class Data extends AbstractHelper
{
    public function __construct(Context $context,
        \Magento\Catalog\Model\ProductRepository $productRepository
    ) {
        $this->_productRepository = $productRepository;
        parent::__construct($context);
    }
    protected function _saveCustomOption($sku, $qty, $code, $_options)
    {

        $product = $this->_productRepository->get(1001);
        $productOption = $product->getOptions();
        foreach($productOption as $op)
        {
            echo "<pre>";
            print_r($op->getData());
            die;
        }
    }
}

I hope this code help to other people.

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.