I am creating products in code and adding them to categories. I want to be able to set a position too.

I am familiar with the catalog_category_product table but I see no obvious means of updating a product to have a given position value when using Magento methods (direct SQL seems easy in comparison).

I am creating a product at a time, sometimes I might want to post to more than one category

  • 1
    Seems like, this is duplicate of magento.stackexchange.com/questions/11157/… – user13804 Sep 3 '14 at 14:46
  • How can it be? This is to set the category position of one product in one category. Not to load all of product positions of a category and re save them. Just want to save one number in one database cell, not the whole lot for the category. To do it as suggested would mean reading everything and writing it again. – Henry's Cat Sep 3 '14 at 18:03

If you want to change position only for ONE product, then use something like:


$categoryId = 12;
$newPosition = 100500;
$productId = 123;

$category = Mage::getModel('catalog/category')->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)->load($categoryId);
$products = $category->getProductsPosition();
$products[$productId] = $newPosition;

NOTE: You can find same in Mage_Catalog_Model_Category_Api::assignProduct().

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.