Magento 批量修改属性 Magento Bulk update attributes

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(...)

 

你可能感兴趣的:(attribute)