Magento 2 : get product custom option base on sku
-
04-10-2020 - |
Вопрос
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;
}
Решение
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.
Не связан с magento.stackexchange