Is there an easy way to swap the long and short descriptions in the mysql database for a magento 2.2.0 installation for all products?
1 Answer
- Make a New File in Magento Root name it 'swap-product-desc.php'
Add Below Code in that file and run it by url : 'your-site-url/swap-product-desc.php'.
<?php use \Magento\Framework\App\Bootstrap; include('app/bootstrap.php'); // add bootstrap $bootstraps = Bootstrap::create(BP, $_SERVER); $object_Manager = $bootstraps->getObjectManager(); $app_state = $object_Manager->get('\Magento\Framework\App\State'); $app_state->setAreaCode('frontend'); $productCollection = $object_Manager->create('\Magento\Catalog\Model\Product')->getCollection(); foreach($productCollection as $product){ $productObject = $object_Manager->create('\Magento\Catalog\Model\Product')->load($product->getId()); try{ $productDesc = $productObject->getDescription(); $productShortDesc = $productObject->getShortDescription(); $productObject->setDescription($productShortDesc); $productObject->setShortDescription($productDesc); $productObject->save(); echo "Product ID :".$productObject->getId()." DESCRIPTIONS Swapped Successfully.<br>"; } catch(Exception $e) { // errro in exception/code print_r('Error in Product Desc Swapping For Product ID : '.$productObject->getId().' : '.$e->getMessage().'<br>'); } }
-
Thanks for your awesome reply.. But for some reason it didn't quite work? The script ran for several hours (about 10K products in shop), and outputted each products as it should. But all the descriptions are still all under the short description field.– MichaelCommented Nov 15, 2017 at 8:45
-
-
-
did you have an idea why the script isn't swapping the descriptions? It ran for several hours and posted ID after each item was processed, but no descriptions was changed though.– MichaelCommented Nov 27, 2017 at 15:26
-
Yes it is actually Swapping product description but it is doing it for Default store view if you swap store view in backend you can see that Descriptions are swapped. Commented Nov 28, 2017 at 6:20