I would like to update the default position value that products are assigned when they are added to a category.

When you create/update a category from the categories editor, new products are saved with a position of 0.

What I want to do is have items save with a position of 100 instead of 1.

Thank you!

  • What is the purpose of it? In which version of Magento you want to achieve the same? – Taran Mar 13 '18 at 20:53
  • My Magento is 1.9.2. I want to do this because everytime I create a new category and I want to sort the products, I have to change all the positions to 100 (or another number different than 0) to realocate the products that I want to show first with a lower number of position. – Vinícius Mar 14 '18 at 12:30
  • You can assign 100 position to product while product creation, let me know if you need more information. – Suman Singh Mar 22 '18 at 5:00

There is no method or event to change this. If you want to change default value you can rewrite Mage_Catalog_Model_Resource_Category::_saveCategoryProducts

 * Add products to category
if (!empty($insert)) {
    $data = array();
    foreach ($insert as $productId => $position) {
        $data[] = array(
            'category_id' => (int)$id,
            'product_id'  => (int)$productId,
            // changed code
            // 'position'    => (int)$position
            'position'    => (int)$position ? (int)$position : 100
    $adapter->insertMultiple($this->_categoryProductTable, $data);

This should set position to 100 if you do not enter a value.

  • Thanks this save my time file path is app/code/core/Mage/Catalog/Model/Resource/Category.php Line No 342, it's better to copy this file to local an edit, if you wish to upgrade Magento version in future – Suneth Kalhara Sep 4 '18 at 17:01
  • I notice this not work when product assign to a category via product edit page category tree, anyone know a solution for that magento.stackexchange.com/questions/241188/… – Suneth Kalhara Sep 7 '18 at 16:59

You can work with negative position numbers too - i.e. since all your products have set position = 0 by default just set those you want to have displayed before them to position = -1.

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.