Tag Archives: magento product update fast way

Fastest way to update magento products

When we Sync our Magento product Inventory and stock any third party API, we need to update whole product through cron and we simply use below method to update the product Data. which is slow product update in magento.




// Slow because load all product attribute

$sku = 'PSKU';

$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
if ($product) {
 $product->setPrice(10);
 $product->setName('PRODUCT TITLE');
 $product->setDescription('PRODUCT DESCRIPTION');
 $product->save();
}
 unset($product);

// Fastest way to update magento product By Attribute

             

$sku = 'PSKU';
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);            
  if ($product) {                    
                    
                
    $product->setPrice(10);
    $product->getResource()->saveAttribute($product, 'price'); 
                    
    /** set product Disable/Enable **/           
                 
    $product->setStatus(1); // 1 => enabled, 0 => disabled     
    $product->getResource()->saveAttribute($product, 'status');              
                
    /** set product Tax  **/                
             
    $product->setTaxClassId('2'); // 2 => Taxable Goods, 0 => None,  4 => Shipping   
    $product->getResource()->saveAttribute($product, 'tax_class_id');
                     
              
  }    
                   
 unset($product);