1

I am saving products fetched from an XML document. I am using $product->save() but I need to do an update after the first save. But the $product->save() method is too much slow for update. I also tried updateAttribute to update product like:

public function productUpdate($productSkus=array(), $data, $storeId = 1){
            $ids=array();
            foreach($productSkus as $sku){
                $id = $this->_getid($sku);
                $attributesData = array("price" => $data['price']);
                array_push($ids,$id);
            }
             Mage::getSingleton('catalog/product_action')
                    ->updateAttributes($ids, $attributesData, $storeId);
        }

        public function _getid($sku){
        $product=Mage::getModel('catalog/product')->loadByAttribute('sku',$sku); 
        if (!$product){
            return false;
        }
            return $product->getId();        
    }

What should I do? How can I update products faster? Imagine there is an XML document that is keeping data of 8000 products (including custom attributes), and it is dynamic, which means it can change anytime. So I need to update products fast, but $product->save() and the above code are not suitable for this situation.

closed as too broad by Pratik bhatt, Amit Bera, 7ochem, Rajeev K Tomy, Keyul Shah Oct 13 '15 at 1:43

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Are you trying to give all products the same price? – Milan Simek Oct 12 '15 at 18:42
4

Firstly you could change _getid($sku) with Mage::getModel('catalog/product')->getIdBySku() which would be a bit more efficient.

Basically your function updates a group of products price yeah? When reading your code I can see that it should be able to simplify it to:

public function productUpdate($productSkus = array(), $data, $storeId = 1)
{
    $ids = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToFilter('sku', aray('in' => $productSkus))
        ->getAllIds();

    Mage::getSingleton('catalog/product_action')->updateAttributes(
        $ids,
        array('price' => $data['price']),
        $storeId
    );
}
  • thank you for your answer but this is not fast enough. I showed that function for an example . ıt can be anything to update product, but fast. Thats all i matter.Need faster update per product. – sj_magento Oct 12 '15 at 16:00
  • Oh right. Well you're not going to get a faster "magento" way to update the products. This way will be faster than your example as it doesnt need to load every product individually before applying the update. – Luke Rodgers Oct 12 '15 at 16:10
1

You can try to make a external sql-request with INSERT ... ON DUPLICATE KEY UPDATE ... to the mage tables and call the reindex procedure. That's the fastet way. But: you need Deep knowing about the structure of the Database. In this case all internal update rules disabled. I think this is a Option, but not recommendable.

Not the answer you're looking for? Browse other questions tagged or ask your own question.