Magento – Change Default Value of ‘Position’ Category Attribute

categorycategory-attributeposition;

I would like to update the default position value that products are assigned when they are added to a category. When you update a category from the categories editor, new products are saved with a position of 0. When you add a product to a category via the tree when filling out the product, it saves with a position value of 1.

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

Best Answer

You need to rewrite the method Mage_Catalog_Model_Resource_Product::_saveCategories
Somewhere in there this is this:

$data[] = array(
    'category_id' => (int)$categoryId,
    'product_id'  => (int)$object->getId(),
    'position'    => 1
);

Replace 1 with 100.
To rewrite the resource model add this to the config.xml of your custom module inside the global tag

<models>
    <catalog_resource>
        <rewrite>
            <product>[Namespace]_[Module]_Model_Resource_Product</product>
        </rewrite>
    </catalog_resource>
</models>

Then create the class [Namespace]_[Module]_Model_Resource_Product that extends Mage_Catalog_Model_Resource_Product, copy the method _saveCategories to it and replace 1 with 100.