How to programmatically set description in simple associated products?
-
14-03-2021 - |
Question
I need set description in all associated products of specific configurable product and with this code all it's ok except part of code where I insert description in associated products on database.
What command do I use on "how to set description in database"
<?php
define('MAGENTO_ROOT', getcwd());
require "app/Mage.php";
Mage::init();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
umask(0);
Mage::app('admin');
set_time_limit(0);
ini_set('memory_limit', '2048M');
try {
$configProductIds = [1462];
foreach ($configProductIds as $product_id) {
$configProduct = Mage::getModel('catalog/product')->load($product_id);
$description = $configProduct->getDescription();
$childIds = Mage::getModel('catalog/product_type_configurable');
$childIds = $childIds->getChildrenIds($configProduct->getId())[0];
foreach ($childIds as $childId) {
$childProduct = Mage::getModel('catalog/product')->load($childId);
// how to set description in database
$childProduct->save();
}
}
} catch (Exception $e) {
print_r($e->getMessage());
echo "<br><br>";
}
Solution
To set the description, you just simply add below code:
$childProduct->setDescription('your description here');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange