phpmagentoproductcategoriesmass-assignment

Magento mass-assign products to category


As the title says,i need to mass-assign products to a category and from the admin i can only edit one product at a time; i dont know why it just doesnt work to mass add them from the "category products" tab in the category page.
Thats why i need another method that's fast,like using phpMyAdmin or something alike.

Any help?

Thanks in advance!


Solution

  • I managed to resolve the problem with the following code :

    $write = Mage::getSingleton('core/resource')->getConnection('core_write');
    $x = 1171;
    $y = 2000;
    $categoryID = 4;
    $productPosition = 0;
    while($x <= $y) {
    $write->query("REPLACE INTO `catalog_category_product` (`category_id`, `product_id`,  `position`) VALUES ($categoryID, $x++, $productPosition)");
    }
    echo "The job is done";
    ?>
    

    I hope the code is clear for everyone,if it's not,reply and i'll try to explain it.

    @nachito : here it is.