Reputation: 1642
I need to copy all Magento's product names to short_description
attribute. I need to just insert the product names into the correct table but I'm not sure how.
Here is the SQL I use to get the all the product names:
SELECT `value` AS product_name
FROM `mage_catalog_product_entity_varchar`
WHERE entity_type_id = (SELECT entity_type_id FROM mage_eav_entity_type WHERE entity_type_code = 'catalog_product')
AND attribute_id = (SELECT attribute_id FROM mage_eav_attribute WHERE attribute_code = 'name' AND entity_type_id = (SELECT entity_type_id FROM mage_eav_entity_type WHERE entity_type_code = 'catalog_product'))
The short_description attribute_id
is 506:
SELECT * FROM `mage_eav_attribute` WHERE `attribute_id` = 506
Upvotes: 0
Views: 361
Reputation: 1642
I ended up just modifying Munjal's great answer to do it in smaller batches to avoid the server timeouts:
<?php include "app/Mage.php";
Mage::app();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') // select all attributes
->addAttributeToFilter('entity_id', array(
'from' => 1,
'to' => 200
));
// we iterate through the list of products to get attribute values
foreach ($collection as $_product) {
$product = Mage::getModel('catalog/product')->load($_product->getId());
$product->setShortDescription($product->getName());
$product->save();
}
?>
Upvotes: 1
Reputation: 936
This is not the way magento needs to be used, use collections and write a script which would do that, I have scribbled the code below I am not sure if that will work but this is the best approach that comes to mind.:
<?php include "app/Mage.php";
Mage::app();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*'); // select all attributes
// we iterate through the list of products to get attribute values
foreach ($collection as $_product) {
$product = Mage::getModel('catalog/product')->load($_product->getId());
$product->setShortDescription($product->getName());
$product->save();
}
?>
Upvotes: 1