As we're updating product attributes, a traditional approach is as follows:
<?php
//Load the Product
$product = Mage::getModel('catalog/product')->load($product_id)); //By ID
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $oldSku);//By SKU
//Update product attributes via Setters
$product->setSku($newSku);
$product->setName('New product name');
$product->setShortDescription(addslashes("short description here."));
$product->setDescription(addslashes("long description"));
//Perform Save
$product->save();
?>
或
$product = Mage::getModel('catalog/product')->load(1);
$product->setName('Some Random Name');
$product->getResource()->saveAttribute($product, 'name');
please review the following as another reference: Magento getSingleton() vs getModel() issue
-- Update --
Double check the array syntax for the attributes being passed.
<?php
Mage::getSingleton('catalog/product_action')
->updateAttributes(array(
$data['product_id']),
array("sku" => $data['sku'], 'price' => $data['price']),
$storeId);
?>
原文:http://stackoverflow.com/a/21071759/602382
Mage::getSingleton('catalog/product_action')->updateAttributes(...)
本文介绍如何使用PHP脚本更新Magento平台上的产品属性,包括通过ID或SKU加载产品、更新属性值并保存更改的方法。此外还提供了批量更新产品属性的示例。
675

被折叠的 条评论
为什么被折叠?



