1

I would like to set all position-numbers in one specific category to 100 instead of 0 (default). Id like to do this once - not for future products in that category.

Thx in forward!

14

Try this:

Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$categoryId = 22; //replace with your category id
$newPosition = 100; //replace with your new position
$category = Mage::getModel('catalog/category')->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)->load($categoryId);
$products = $category->getProductsPosition();
foreach ($products as $id=>$value){
    $products[$id] = $newPosition;
}
$category->setPostedProducts($products);
$category->save();
| improve this answer | |
  • I know I shouldnt, but from time to time I have to tell I LOVE YOU MARIUS :D You are the best of the best of the best! – Stefan Gregori Nov 25 '13 at 13:45
  • 3
    Glad to help, but if my wife sees your comment...well... I cannot guarantee your safety :) – Marius Nov 25 '13 at 13:52
  • Old question, but is there a reason to set store ID on this operation? I don't see store_id in the catalog/category table. – musicliftsme Sep 5 '14 at 22:28
  • @laketuna. It shouldn't even be a store_id field in the category table. That one is used only for loading the correct attribute values. Check the eav models for more info. – Marius Sep 8 '14 at 11:05
  • Also you can use direct SQL query, for all cats UPDATE catalog_category_product AS ccp SET ccp.position = 10000 WHERE cp.position = 1 or for specific category UPDATE catalog_category_product AS ccp SET ccp.position = 10000 WHERE ccp.position = 1 AND ccp.category_id = 23 – Eugene Zubkov May 27 '16 at 12:20

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