Magento导入Tier Price

Magento默认无法导入Tier Price,需要在app/code/local/YOURMODULE/Catalog/Model/Convert/Adapter/Product.php 继续加入扩展方法。

已有的脚本里已实现过导入多图/多属性,自动创建目录,自动采集远程图片,现在再加导入Tier Price的功能。

核心函数:

private function _editTierPrices(&$product, $tier_prices_field = false)
{
if (($tier_prices_field) && !empty($tier_prices_field)) {
    if(trim($tier_prices_field) == 'REMOVE'){
        $product->setTierPrice(array());
    } else {
        $existing_tps = $product->getTierPrice();
        foreach($existing_tps as $key => $etp){
            $etp_lookup[$etp['price_qty']] = $key;
        }
        $incoming_tierps = explode('|',$tier_prices_field);
        foreach($incoming_tierps as $tier_str){
            $tmp = explode('=',$tier_str);
            $tps_toAdd[$tmp[0]] = array(
                                'website_id' => 0, // !!!! this is hard-coded for now
                                'cust_group' => 32000, // !!! so is this
                                'price_qty' => $tmp[0],
                                'price' => $tmp[1],
                                'delete' => ''
                            );
            if(isset($etp_lookup[$tmp[0]])){
                unset($existing_tps[$etp_lookup['price_qty']]);
            }
        }
        $tps_toAdd =  array_merge($existing_tps, $tps_toAdd);
        $product->setTierPrice($tps_toAdd);
    }
}
}

然后在saveRow函数里找地方加入:

if(
    isset($importData['tier_prices'])
    && !empty($importData['tier_prices'])
){
    $this->_editTierPrices($product, $importData['tier_prices']);
}

CSV文件里要有字段”tier_prices“,值的格式例子:qty=price|qty=price|qty=price

比如:50=12.25|500=11.70|5000=11.00

这样Magento就能导入Tier Price了

作者: Sjolzy | Google+

--EOF--

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值