Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6828885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:26:07+00:00 2026-05-26T22:26:07+00:00

I have written quite a few scripts to update my product catalog based on

  • 0

I have written quite a few scripts to update my product catalog based on some or other parameter. In each of them the base logic is something simillar to this…

     //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();   
            }

Though this work, each save is a SQL update query and the fact is that having a very large catalog, this is fairly slow.

I was wondering if this could be sped up by doing single save on the collection instead on the product.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:26:08+00:00Added an answer on May 26, 2026 at 10:26 pm

    There are several things you can do to write a much faster update script. I don’t know how you are getting some of your variables so you’ll need to modify to get it working in your case, but the code below should be much faster than the way you are currently doing it. 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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written quite a few Ruby programs, but if I need to show
I have written quite a bit of code of the past few years. I've
it's late, I'm tired, and probably being quite dense.... I have written an application
I have a written a very simple UDP Server using Netty - it quite
I have a quite old templating system written on top of ERB. It relies
I have written a small web app to collect some data and store it
I'm working with some SQL 2005 CLR code written in C#. We have recently
I'm quite new to programming larger applications. I have now written a command line
I have written some C++ code that generates a std::vector. I also have a
I have a few set of templates written with Twig . I have then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.