修改产品的group price的值,修改为如下形式: 41.78 => 41.95 55.88 => 55.95

本文介绍了一种在Magento中批量修改产品组价(groupprice)的方法,通过PHP脚本实现将catalog_product_entity_group_price表中的value字段统一更新为以'.95'结尾的价格格式。
<?php

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


/*
需求:修改产品的group price的值(catalog_product_entity_group_price表value字段的值),
      修改为如下形式:
        41.78 => 41.95
        55.88 => 55.95
分析: 先取出原先的值,然后设置成 xxx.95的形式        
*/
$handle = Mage::getSingleton('core/resource')->getConnection('core_write');


//1.遍历所有产品
$sql = "SELECT * FROM catalog_product_entity_group_price";
$query = $handle->query($sql);
while ($row = $query->fetch()) {
    $row = new Varien_Object($row);
    $entity_id =  $row->getentity_id(); //产品id
    $value = $row->getValue(); //value值也就是我们要的group price的值

    //2.分割
    $extArray = explode( '.' ,$value );
    $newValue = $extArray[0].'.9500';
    echo  $value.'====='.$newValue.'<br>';

    //3.修改
     $sql = "update catalog_product_entity_group_price set `value`=".$newValue."WHERE entity_id=".$entity_id;
     $handle->query($sql);  
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值