Today I had to reorder products in a category. Basically, our client wanted to put the products with special price at the end. After trying to do this with the category model in Magento, I finally run into the Category Api. It worked like a charm, even though it works kind of slow. Here you have the solution (with an example):

$categories = Mage::getModel('catalog/category')->getCollection();
$new_order = 300;
foreach($categories as $category){
    
    $cat_api = new Mage_Catalog_Model_Category_Api;
    $products = $category->getProductCollection();

    foreach ($products as $product){
       $cat_api->assignProduct($category->getId(), $product->getId(), $new_order);
    }
    
}
Categories: Shell

1 Comment

amelojunior · February 14, 2013 at 3:46 pm

Perfect !!!!!!!!!!!!!!!!!!!! thanks

Leave a Reply

Your email address will not be published. Required fields are marked *