0

Is it possible to increase product position automatically for specific category. For example, when Product 1 is added under Category A, then the position of Product 1 will be 1 in the Position Column under Category Products. When Product 2 is added under Category A, then the position of Product 2 will be 2 in the Position Column under Category Products and so on. Is there a way to do so?

1 Answer 1

0

A way to do it is to add an attribute like Position.

Then set position to say 1.

Then you can run the script getting the attribute value to whatever categoryId you want

Something like this might help.

Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$categoryId = '3'; //replace with your category id
$newPosition = 'getattribute position'; //replace with your new position
$category =    Mage::getModel('catalog/category')->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)->load($categoryId);
$products = $category->getProductsPosition();
foreach ($products as $id=>$value){
    $products[$id] = $newPosition;
}
$category->setPostedProducts($products);
$category->save();

This can be a way if you set the script on cron to update automatically, ofcourse the script will need to modify.

5
  • Hi, as I am new to the magento, I don't know where to add your code. Could you please provide the path to put your code. In admin panel, Catalog > Manage Categories > Category Products, I want position under position column to be increased 1 automatically when new product is added under the specific category. Thank you so much!
    – May18
    Aug 1, 2014 at 10:09
  • You can place your file on root this link can help you out: louisjohn.wordpress.com/category/magento/… But you need to read magento to get this working Aug 1, 2014 at 10:11
  • Please share if it worked? Aug 8, 2014 at 8:15
  • Thanks a lot :) It works. But I still need to run that external script manually. I don't want to run the script manually. Could you please provide me the way how to auto execute/load the external script without manual? For example, I have to run www.myexample/my_external_script.php manually to load the product position. Is there a way to auto-load the external script without executing manually. Thank you so much. So far, I could overcome one step because of your help.
    – May18
    Aug 10, 2014 at 17:25
  • Hi,it works for me. Thank you so much dear! Your answer has been accepted. Thanks!
    – May18
    Aug 26, 2014 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.