我需要将商店中所有商品的价格提高3%,并且已经遇到了这个简单易用的脚本,可以为所有产品添加固定价格:
$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'
)
");
有人知道如何更改此代码以向所有产品添加固定百分比吗?
这是我正在尝试的新代码吗?
<?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();
}
?>
此代码工作正常,但现在想要对数字进行舍入? 非常感谢
答案 0 :(得分:2)
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('price')
;
foreach ($products as $product) {
$product->setPrice($product->getPrice() * 1.03);
$product->save();
}