0

In Magento 2.4.2, when i am going to update products programmatically, it's removed customizable options automatically Below code for your reference:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$collection = $productCollection->addAttributeToSelect('*')->load();
foreach ($collection as $product){
   $product->save();
}

It's automatically removed existing customizable options

Before executing above code enter image description here After executing above code enter image description here

1 Answer 1

0

got the resolution for this issue

Need to update product using product repository model

\Magento\Catalog\Model\ProductRepository

Like below

$objectManager      = \Magento\Framework\App\ObjectManager::getInstance();
    $productCollection  = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
    $productRepository  = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
    $collection         = $productCollection->addAttributeToSelect('*')
                                            ->addFieldToFilter('type_id','simple')
                                            ->load();

    foreach ($collection as $product){
        
        $productRepository->save($product);     
    }

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.