4 Benchmark added
source | link

There are 2 ways to go about this, one is by getting the Magento catalog/product model and loading the product by ID which will give you the whole product, then setting the name and saving it.

$product = Mage::getModel('catalog/product')->load(1);
$product->setName('foobar!');

try {
   $product->save();
} catch(Exception $e) {
  echo "{$e}";
}

As OP pointed out, this is quite heavy just for changing one attribute. I kind of figured that the attribute mass update tool should use a cleaner way to do this and found the Mage_Catalog_Model_Resource_Product_Action class

$product_id = 1;
$store_id = 0;

$action = Mage::getModel('catalog/resource_product_action');
$action->updateAttributes(array($product_id), array(
    'name' => 'foobar!'
), $store_id);

A small and[UPDATE] benchmark

So did a quick benchmark will follow in a few secondsscript and the results speak for itself.

$starttime = microtime(true);

for ($i=20; $i>0; $i--)
{
    $action = Mage::getModel('catalog/resource_product_action');
    $action->updateAttributes(array(1), array(
        'name' => 'foobar!'
    ), 0);
}

echo "Time: " . (microtime(true) - $starttime) . " seconds\n";

$starttime = microtime(true);

for ($i=20; $i>0; $i--)
{
    $product = Mage::getModel('catalog/product')->load(1);
    $product->setName('foobar!');
    $product->save();
    unset($product);
}

echo "Time: " . (microtime(true) - $starttime) . " seconds\n";

Time: 0.076527833938599 seconds

Time: 4.757472038269 seconds

There are 2 ways to go about this, one is by getting the Magento catalog/product model and loading the product by ID which will give you the whole product, then setting the name and saving it.

$product = Mage::getModel('catalog/product')->load(1);
$product->setName('foobar!');

try {
   $product->save();
} catch(Exception $e) {
  echo "{$e}";
}

As OP pointed out, this is quite heavy just for changing one attribute. I kind of figured that the attribute mass update tool should use a cleaner way to do this and found the Mage_Catalog_Model_Resource_Product_Action class

$product_id = 1;
$store_id = 0;

$action = Mage::getModel('catalog/resource_product_action');
$action->updateAttributes(array($product_id), array(
    'name' => 'foobar!'
), $store_id);

A small and quick benchmark will follow in a few seconds.

There are 2 ways to go about this, one is by getting the Magento catalog/product model and loading the product by ID which will give you the whole product, then setting the name and saving it.

$product = Mage::getModel('catalog/product')->load(1);
$product->setName('foobar!');

try {
   $product->save();
} catch(Exception $e) {
  echo "{$e}";
}

As OP pointed out, this is quite heavy just for changing one attribute. I kind of figured that the attribute mass update tool should use a cleaner way to do this and found the Mage_Catalog_Model_Resource_Product_Action class

$product_id = 1;
$store_id = 0;

$action = Mage::getModel('catalog/resource_product_action');
$action->updateAttributes(array($product_id), array(
    'name' => 'foobar!'
), $store_id);

[UPDATE] benchmark

So did a quick benchmark script and the results speak for itself.

$starttime = microtime(true);

for ($i=20; $i>0; $i--)
{
    $action = Mage::getModel('catalog/resource_product_action');
    $action->updateAttributes(array(1), array(
        'name' => 'foobar!'
    ), 0);
}

echo "Time: " . (microtime(true) - $starttime) . " seconds\n";

$starttime = microtime(true);

for ($i=20; $i>0; $i--)
{
    $product = Mage::getModel('catalog/product')->load(1);
    $product->setName('foobar!');
    $product->save();
    unset($product);
}

echo "Time: " . (microtime(true) - $starttime) . " seconds\n";

Time: 0.076527833938599 seconds

Time: 4.757472038269 seconds

3 added 659 characters in body
source | link

The following code should work well for you inThere are 2 ways to go about this case:, one is by getting the Magento catalog/product model and loading the product by ID which will give you the whole product, then setting the name and saving it.

$product = Mage::getModel('catalog/product')->load(1);
$product->setName('foobar!');

try {
   $product->save();
} catch(Exception $e) {
  echo "{$e}";
}

As OP pointed out, this is quite heavy just for changing one attribute. I kind of figured that the attribute mass update tool should use a cleaner way to do this and found the Mage_Catalog_Model_Resource_Product_Action class

$product_id = 1;
$store_id = 0;

$action = Mage::getModel('catalog/resource_product_action');
$action->updateAttributes(array($product_id), array(
    'name' => 'foobar!'
), $store_id);

A small and quick benchmark will follow in a few seconds.

The following code should work well for you in this case:

$product = Mage::getModel('catalog/product');
$product->setName('foobar!');

try {
   $product->save();
} catch(Exception $e) {
  echo "{$e}";
}

There are 2 ways to go about this, one is by getting the Magento catalog/product model and loading the product by ID which will give you the whole product, then setting the name and saving it.

$product = Mage::getModel('catalog/product')->load(1);
$product->setName('foobar!');

try {
   $product->save();
} catch(Exception $e) {
  echo "{$e}";
}

As OP pointed out, this is quite heavy just for changing one attribute. I kind of figured that the attribute mass update tool should use a cleaner way to do this and found the Mage_Catalog_Model_Resource_Product_Action class

$product_id = 1;
$store_id = 0;

$action = Mage::getModel('catalog/resource_product_action');
$action->updateAttributes(array($product_id), array(
    'name' => 'foobar!'
), $store_id);

A small and quick benchmark will follow in a few seconds.

2 added 14 characters in body; deleted 25 characters in body
source | link

The following code should work well for you in this case:

$product = Mage::getModel('catalog/product')->load(1);
$product->setName('foobar!');

try {
   $product->save();
} catch(Exception $e) {
  echo "{$e}";
}

The following code should work well for you in this case:

$product = Mage::getModel('catalog/product')->load(1);
$product->setName('foobar!');

try {
   $product->save();
} catch(Exception $e) {
  echo "{$e}";
}

The following code should work well for you in this case:

$product = Mage::getModel('catalog/product');
$product->setName('foobar!');

try {
   $product->save();
} catch(Exception $e) {
  echo "{$e}";
}
1
source | link