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 Answer
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();
}
}
?>
-
-
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 Commented Jan 26, 2017 at 1:20
-
-
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) Commented Jan 27, 2017 at 9:46
-
@CostasSaloubardos you can get special price $pid->getSpecialPrice() and do whatever you want with this Commented Jan 27, 2017 at 10:17