Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I used below function in admin controller to update multiple store status. Its working fine. why code ->setIsMassupdate(true) is used? What it does?

public function massStatusAction()
{
    //Get store ids from selected checkbox
    $storeIds = $this->getRequest()->getParam('storeIds');

    if (!is_array($storeIds)) {
        Mage::getSingleton('adminhtml/session')->addError($this->__('Please select store(s)'));
    } else {
        try {
            foreach ($storeIds as $storeId) {
                Mage::getSingleton('clarion_storelocator/storelocator')
                ->load($storeId)
                ->setStatus($this->getRequest()->getParam('status'))
                **->setIsMassupdate(true)**
                ->save();
            }
            Mage::getSingleton('adminhtml/session')->addSuccess(
                $this->__('Total of %d record(s) were successfully updated', count($storeIds))
            );
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        }
    }
    $this->_redirect('*/*/index');
}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

I guess in your own entity it doesn't make sense.
But for products is useful.
If you have some indexes set on 'Update on save' and you perform a mass update, there is no need to rebuild those indexes for each product that is updated in bulk. You can just rebuild the indexes when everything product is updated.

For example this piece of code from Mage_CatalogIndex_Model_Observer::processAfterSaveEvent uses that flag.

    if (!$eventProduct->getIsMassupdate()) {
        $this->_getIndexer()->plainReindex($eventProduct);
    } else {
        $this->_productIdsMassupdate[] = $eventProduct->getId();
    }

If the getIsMassupdate returns false, then it reindexes the product, If it's true then just marks it for reindex to process it when everything is done.

Same goes for Mage_CatalogRule_Model_Observer::applyAllRulesOnProduct()

    if ($product->getIsMassupdate()) {
        return;
    }

It does not apply the catalog rules for each product when in mass update mode.

share|improve this answer
    
@ Marius thanks great answer –  PMB Jun 12 at 11:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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