2011-11-17 23 views
7

Ürün kataloğumu güncellemek için bir kaç tane veya daha fazla parametreye dayanan bir kaç tane komut yazdım. Bunların her birinde baz mantık SQL güncelleştirme sorgusu her kurtarmak, bu işin rağmenMagento: Ürün kataloglarını daha hızlı güncelleme

 //Get collection 
    $collection = Mage::getModel('catalog/product')->getCollection(); 
    $collection->addAttributeToSelect('sku'); 
$collection->addAttributeToSelect('publihser'); 
    $collection->addFieldToFilter(array(array('attribute'=>'publisher','eq'=>$publisher))); 

    // for each product in collection do a individual save 
    foreach ($collection as $product) { 
    $product->setSKU($newValue); 
    $product->save(); 
      } 

... Buna simillar şey olduğunu ve aslında çok büyük bir katalog sahip bu oldukça yavaş olmasıdır.

Bunun yerine ürün üzerinde koleksiyon üzerinde tek bir tasarruf yaparak hızlandırılabileceğini merak ediyorum.

+0

Bu tarayıcıda mı yoksa cli'de mi çalışıyor? – djdy

+2

[MAGMI] 'yı deneyin (http://sourceforge.net/apps/mediawiki/magmi/index.php?title=Magmi_Wiki). –

+0

@djdy Bu, CLI. Üzerinde çalışıyor ancak Web arabiriminde de çalıştırılabilir. – TheVyom

cevap

21

Çok daha hızlı bir güncelleştirme komut dosyası yazmak için yapabileceğiniz birkaç şey var. Değişkenlerinizden bazılarını nasıl aldığınızı bilmiyorum, böylece sizin durumunuzda çalışmasını sağlamak için değiştirmeniz gerekecek, ancak aşağıdaki kod şu anda yaptığınız gibi olduğundan daha hızlı olmalıdır. e.g:

// Set indexing to manual before starting updates, otherwise it'll continually get slower as you update 
$processes = Mage::getSingleton('index/indexer')->getProcessesCollection(); 
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL)); 
$processes->walk('save'); 

// Get Collection 
$collection = Mage::getModel('catalog/product')->getCollection() 
    ->addAttributeToSelect('sku') 
    ->addAttributeToSelect('publihser') 
    ->addFieldToFilter(array(array('attribute'=>'publisher','eq'=>$publisher))); 


function productUpdateCallback($args){ 
    $product = Mage::getModel('catalog/product'); 

    $product->setData($args['row']); 

    $productId = $product->getId(); 

    $sku = 'yourSku'; 

    // Updates a single attribute, much faster than calling a full product save 
    Mage::getSingleton('catalog/product_action') 
     ->updateAttributes(array($productId), array('sku' => $sku), 0); 
} 

// Walk through collection, for large collections this is much faster than using foreach 
Mage::getSingleton('core/resource_iterator')->walk($collection->getSelect(), array('productUpdateCallback')); 


// Reindex all 
$processes->walk('reindexAll'); 
// Set indexing back to realtime, if you have it set to manual normally you can comment this line out 
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME)); 
$processes->walk('save'); 
+0

Teşekkürler @Jasuten. Cevabınız, hızı artırmak için kullanabileceğim fikirler ile doludur. – TheVyom

+2

'' category_ids' öğesini güncellemeye çalışırken '69' satırında \ app \ code \ core \ Mage \ Catalog \ Model \ Resource \ Product \ Action.php içinde nesne olmayan bir getAttributeId() işlevine çağrı alıyorum. Bu "özniteliği" (bu gerçekten bir özellik değil) veya "$ product-> setCategoryIds ('1,2,3') -> save();' den daha hızlı bir şekilde değiştirmenin bir yolu yoktur. –