Ledgemonkey
Ledgemonkey

Reputation: 7481

how do I add a percentage increase to all product prices in Magento 1.4?

I need to increase the prices of all products in the store by 3% and have come across this nice and simple script for adding a fixed price to all products:

 $priceToAdd = 6;

 $write = Mage::getSingleton('core/resource')->getConnection('core_write');
 $write->query("
 UPDATE catalog_product_entity_decimal val
 SET  val.value = (val.value + $priceToAdd)
 WHERE  val.attribute_id = (
 SELECT attribute_id FROM eav_attribute eav
 WHERE eav.entity_type_id = 4
   AND eav.attribute_code = 'price'
 )
");

Does anybody know how i would alter this code to add a fixed percentage to all products ?

This is the new code that I'm trying ?

<?php require 'app/Mage.php'; Mage::app();

 $products = Mage::getModel('catalog/product')->getCollection()
 ->addAttributeToSelect('price')
 ;
 foreach ($products as $product) {
 $roundup = $product->setPrice($product->getPrice()* 1.03);
 echo ceil($roundup);
 $product->save();
 }

 ?>

This code works fine but now looking to round up the number ? Many thanks

Upvotes: 0

Views: 4270

Answers (1)

Max
Max

Reputation: 8836

 $products = Mage::getModel('catalog/product')->getCollection()
     ->addAttributeToSelect('price')
     ;
 foreach ($products as $product) {
     $product->setPrice($product->getPrice() * 1.03);
     $product->save();
 }

Upvotes: 2

Related Questions