Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To get product collections by some range of ids in magento

Tags:

php

magento

I want to update all product price by specific percentage from current price.I got the following line of code update price by percentage wise

$products = Mage::getModel('catalog/product')->getCollection()
 ->addAttributeToSelect('price');
 foreach ($products as $product) {

 $product->setPrice($product->getPrice() * 1.03);
 $product->save();
 echo $product->getId()."updated Sucess";
 }

Its working well. But it will take so much time to complete the above process because we have a lot of products in our store. Some times it will return time out error too. So i want to perform this above operation by split those product collections like if we have 1000 products, do this operation by like below

Collect 1st 100 products from product collections
Update price of those products
Then collect next 100 products
Update price of those products

Anybody have an idea to get product collections by some range of ids?

like image 655
DRAJI Avatar asked Apr 08 '14 06:04

DRAJI


1 Answers

$_productCOllection = Mage::getModel('catalog/product')->getCollection()
   ->addAttributeToSelect('*')
   ->addAttributeToFilter('entity_id', array(
    'from' => $startPrOID,
    'to' => $EndPrOID
    ))
    ->load();
like image 186
Amit Bera Avatar answered Oct 20 '22 00:10

Amit Bera