Reputation: 7481
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
Reputation: 8836
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('price')
;
foreach ($products as $product) {
$product->setPrice($product->getPrice() * 1.03);
$product->save();
}
Upvotes: 2