I have added a custom option in product from the back-end.

enter image description here

After that when I tried to update the product programmatically but Facing an issue: When I edited the product all the custom options of product has been deleted.

enter image description here

It removes all options while editing a product. I have checked all entries in the database that's also get deleted.

2 Answers 2


Finally I found the solution of this. Not great solution but it's working fine for me.

I have first getting all options of the product before save.

protected function getProductOptions($productObj)
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $customOptions = $objectManager->get('Magento\Catalog\Model\Product\Option')->getProductOptionCollection($productObj);

        $options = [];
        if($customOptions->count() > 0) {
            foreach($customOptions as $customOption) {

                $optionsValue = [];
                $customOptionValues = $objectManager->get('Magento\Catalog\Model\Product\Option\Value')->getValuesCollection($customOption);
                if($customOptionValues->count() > 0) {
                    foreach($customOptionValues as $customOptionValue) {
                        $optionsValue[] = array(
                            'record_id' => $customOptionValue->getRecordId(),
                            'title' => $customOptionValue->getTitle(),
                            'price' => $customOptionValue->getPrice(),
                            'price_type' => $customOptionValue->getPriceType(),
                            'sort_order' => $customOptionValue->getSortOrder(),
                            'sku' => $customOptionValue->getSku(),
                            'is_delete' => 0,

                $sku = $customOption->getSku();
                $title = $customOption->getTitle();
                $type = $customOption->getType();
                $price = $customOption->getPrice();
                $price_type = $customOption->getPriceType();
                $record_id = $customOption->getRecordId();

                $options[] = array(
                    'sort_order' => $customOption->getSortOrder(),
                    'title' => $title,
                    'price_type' => $price_type,
                    'price' => $price,
                    'type' => $type,
                    'values' => $optionsValue,
                    'is_require' => 1,


        return $options;        

After that I have added that all options after save the product.

protected function addProductCustomOptions($product, $productOption) 
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

        foreach ($productOption as $arrayOption) {
            $option = $objectManager->create('\Magento\Catalog\Model\Product\Option')


Now I am getting my all product options same as before.

  • How you manage products option while you are trying to import new products with custom options? Your code is working fine when there are already products available with custom options.
    – Indian
    Commented Nov 17, 2018 at 10:03

We can say it was an issue with older version less than 2.4.x

That fix has been available with PR

public function execute($entity, $arguments = [])
        if ($entity->getOptionsSaved() || !$entity->getCanSaveCustomOptions()) {
            return $entity;

Recommending to use the latest version or use relevant patch or you may override the logic by plugin or preference.

  • Still this issue is not fixed in Magento 2.4.2, if found any solution, please let me know.
    – shyopat
    Commented Jan 26, 2022 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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