I have to get all products which price is greater than 15000INR and assign those products into specific category in Admin panel programmatically.

Looking forward this answer.


*To assign this collection to the category use the following code example (I assume your category id is 1509, just for example

foreach($collection as $prd){
    $product = Mage::getModel('catalog/product')->load($prd->getId()); $categories = $product->getCategoryIds(); $categories[] = 1509;$product->setCategoryIds($categories);


  • Hi, Its not working. – Mesk May 11 '17 at 9:59
  • I have tried below : $model = Mage::getModel('catalog/product') ->getCollection() ->addFieldToFilter('price',array('from' => '1000','to' => '10000'))->getData(); $productId = array(); foreach($model as $key => $val) { foreach($val as $v) { $productId[$key] = $val['entity_id']; } } foreach($productId as $prd){ $product = Mage::getModel('catalog/product')->load($prd->getId()); $categories = $product->getCategoryIds(); $categories[] = 11; $product->setCategoryIds($categories); $product->save(); } – Mesk May 11 '17 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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