I am creating product custom options using the following code
foreach ($options as $arrayOption) {
$product->setHasOptions(1);
$product->setCanSaveCustomOptions(true);
$option = $objectManager->create('\Magento\Catalog\Model\Product\Option')
->setProductId($product->getData('row_id'))
->setStoreId(2)
->addData($arrayOption);
$option->save();
$product->addOption($option);
}
But it is resulting in duplication of the same custom option
There is a similar question but in magento 1: Product custom option duplication on save within loop
How to resolve the same for Magento 2?