您的位置:首页 > 数据库

Magento执行原生SQL,批量修改商品价格

2015-05-26 15:09 411 查看
<?php
/**
* @date 2015年5月26日
* 修改商品价格
* (Special Price商品折扣价为当前商品原价price;原价:小于等于300的价格*1.2,300到600的价格*1.15,600以上的价格*1.2)
*/

define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

//1.查询所有商品原价price
$sql = "select entity_id, value from catalog_product_entity_decimal  where attribute_id=75";
$handle = Mage::getSingleton('core/resource')->getConnection('core_write');
$query = $handle->query($sql);

while ($row = $query->fetch()) {
$row = new Varien_Object($row);
echo $row->getentity_id() . '====' . $row->getValue() . "<br/>";

//2.循环修改(把原价值给Special Price,attribute_id=76的该条记录value值就是商品折扣价)
$sql = "update catalog_product_entity_decimal set `value`= ".$row->getValue()." where attribute_id=76 and entity_id =".$row->getentity_id();

//echo $sql.'<br>';
$handle->query($sql); //执行SQL

//3.修改price的值(原价)
if((int)$row->getValue() >300 && (int)$row->getValue() <=600 ){
$sql = "update catalog_product_entity_decimal set `value`= value*1.15 where attribute_id=75 and entity_id =".$row->getentity_id();
$handle->query($sql); //执行SQL
}else{
$sql = "update catalog_product_entity_decimal set `value`= value*1.2 where attribute_id=75 and entity_id =".$row->getentity_id();
$handle->query($sql); //执行SQL
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: