Background: Some products option detail (e.g. text field data) is not correctly held through the process... User enters data on the product page and it is missing in the basket page. A simple fix is to save the product in the admin (no changes)... so am building a script to save all products with product options.
Problem: The script isn't fixing the problem, so it is not performing the same actions as the admin save with the GUI. Why?
Here is my script:
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$instance = \Magento\Framework\App\ObjectManager::getInstance();
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('adminhtml');
$arrProductIDs = [...];
foreach ($arrProductIDs as $iProductID) {
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($iProductID);
$product->save();
echo $iProductID.' saved - ';
}
I have also tried changing some data a little, but no better:
$desc_orig = $product->getDescription();
$product->setDescription($desc_orig.' ');
Can anyone please help me understand fix this so that I can replicate going into the admin and saving all of these products?