0

I have a Magento store with 16.000 products and I would like to make some change to all product prices. First of all I have only Regural Prices so I want to copy all the regural prices to special prices and then increase the regural prices +20%

1

Save this code in a file priceupdate.php on your root and run it via url e.g http://www.example.com/priceupdate.php

   <?php
    error_reporting(E_ALL | E_STRICT);
    $mageFilename = 'app/Mage.php';
    require_once $mageFilename;
    Mage::app('admin'); 
        $products_model =  Mage::getModel('catalog/product')
                            ->getCollection()    
                            ->addAttributeToselect('id')             
                            ->addAttributeToselect('price')  
                            ->addAttributeToselect('special_price')            
                             ->load();
    foreach ($products_model as $pid)
    {

        if(!$pid->getSpecialPrice()){

            $regularPrice = $pid->getPrice();
            $_product = Mage::getModel('catalog/product')->load($pid->getId()); 
            $percentage = (20 / 100) * $regularPrice;
            $newPrice = $regularPrice+$percentage;
            $_product->setPrice($newPrice);
            $_product->setSpecialPrice($regularPrice);
            $_product->save();
        }
    }   

    ?>
12
  • You are perfect! It worked like a charm! Jan 23 '17 at 18:38
  • One more question: This rule must be run only if Special Price is not set, beacause after importing new products it changes the already fixed prices Jan 26 '17 at 1:20
  • @CostasSaloubardos I have updated the code please check
    – Arunendra
    Jan 27 '17 at 5:51
  • hello and thanks for the response. It icreases and the old products as the first script posted. The point is to increase only if special price is 0 or not set (blank) Jan 27 '17 at 9:46
  • @CostasSaloubardos you can get special price $pid->getSpecialPrice() and do whatever you want with this
    – Arunendra
    Jan 27 '17 at 10:17

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.