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 } }
相关文章推荐
- ThinkPHP实现对数据库中表的修改删除以及两种原生SQL语句的执行
- C#保留2位小数几种场景总结 游标遍历所有数据库循环执行修改数据库的sql命令 原生js轮盘抽奖实例分析(幸运大转盘抽奖) javascript中的typeof和类型判断
- magento -- 修改所有商品的价格为原来的1.2倍示例
- magento批量修改价格
- 如何检测mysql 数据库执行了哪些sql语句 ecshop如何添加商品属性 ecshop 商品属性批量采集入库
- [Magento SQL] 根据SKU修改商品的某个属性的值
- zencart+magento 如何清空商品演示数据和没有商品数据的sql执行语句
- shopnc数据库 批量修改商品价格
- hibernate执行原生sql以及对结果集处理.
- [转]c#实现用SQL池(多线程),定时批量执行SQL语句
- 通过SqlClr制作Sql自动化批量执行脚本
- django中的connection.cursor执行原生sql
- 真正实现批量插入和批量修改的SQL实例
- 在windows cgywinportable上,通过执行linux命令,批量修改文件名称。
- Thinkphp原生的sql查询及执行操作
- ThinkPHP--删除数据及原生sql语句执行
- SQL批量执行存储过程
- 批量执行Sql语句,MySQL存储过程Java复现
- magento,批量修改产品名称
- Hibernate直接执行原生SQL