0

I want to change the position value of the category product tab in the category page from 0 to 2. When the newly created product is created, its default position value was 0.

This is my progress as off now.

Category ID is 218

I already found the position attribute_id = 53

SELECT * FROM eav_attribute WHERE frontend_label = 'Position';

I want to change all the position value of the specific category.

What tables do I need to look at?

1
  • Why don't you do it directly via the backend using the position field ? Commented Jun 2, 2016 at 8:03

1 Answer 1

1

commonly you may try to use

$adminStore = Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::app()->setCurrentStore($adminStore);
$categoryId = 218; 
$defaultPosition = 0; 
$newPosition = 2; 
$category = Mage::getModel('catalog/category')->setStoreId(Mage_Core_Model_App::ADMIN_STORE_ID)->load($categoryId);
$productPossitions = $category->getProductsPosition();
foreach ($productPossitions as $id => $value){
    if($value == $defaultPosition){
        $productPossitions[$id] = $newPosition;
    }
}
$category->setPostedProducts($productPossitions);
$category->save();

This script will update all positions and change them from 0 to 2. If you need you may add additional check for product id. You may include it in your logic, create observer or cron job. Hope it will helpful for you.

Your Answer

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

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