How to Change Default Value of ‘Position’ Category Attribute in Magento 1.9

categorycategory-productsmagento-1.9

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!

Best Answer

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.

Related Topic