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了
(责任编辑:最模板) |