I have work on Custom Module. In Our Module I had use
<event name="catalog_product_save_after">
<observer name="add_custom_option" instance="Namespace\Modulename\Observer\AddCustomOption" />
</event>
In observer i Had Generate Product Custom Option Programmatically
$product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
foreach ($options as $arrayOption) {
$isHasOptions = $product->getTypeInstance()->hasOptions($product);
$option = \Magento\Framework\App\ObjectManager::getInstance()
->create('\Magento\Catalog\Model\Product\Option')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($arrayOption);
$this->customoptionOperation($option, 'save');
$product->addOption($option);
//$product->save();
}
i have use this code for generate Product custom Option.
//$product->save();
i had comment this code because it provide me Error
No Such Entity
After saving Product.
Product Options are generated Successfully in Product But Not Display in Front-end
I had Run All Commands
- setup:upgrade
- setup:static-content:deploy -f
- indexer:reindex
- cache:flush
But Custom Option Not Appears in Front-end
But When i have save product second time after saving product the Options are Appears in Front-end Without need Run any Commands.
I Need Solution to save Product One time and Get Product Option Front End
Is This Possible ?