要添加等级价格,请勿触摸tier.phtml 文件。
为产品添加等级价格:
1*/ 使用这 4 个必需键设置一个数组:website、customer_group_id、qty、price。
$tierPrice = array(
'website' => 'all', // or website ID
'customer_group_id' => 2, // or 'all'
'qty' => 20, // required & not null, 1 = for not manage qty
'price' => 19.99,
);
2*/ 使用Mage_Catalog_Model_Product_Attribute_Tierprice_Api 中的update 方法更新产品价格。
该方法需要一个具有 1,n 层价格的数组:
$tierPrices[] = $tierPrice;
// in example the product ID is 123
try
{
$api = new Mage_Catalog_Model_Product_Attribute_Tierprice_Api();
$api->update( 123 , $tierPrices );
}
catch (Exception $ex)
{
echo "Error when tier price creation: {$e->getMessage()} \n";
}
显示您的管理面板,等级价格与产品一起存储。
更改现有产品的等级价格。
1*/获取产品价格数组:
$api = new Mage_Catalog_Model_Product_Attribute_Tierprice_Api();
$tiersPrices = $api->info( 123 ); // 123 is the product ID
如果你 var_dump($tiersPrices); 你会得到这样的东西:
array(1) {
[0]=>
array(4) {
["customer_group_id"]=>
int(1) "2"
["website"]=>
string(3) "all"
["qty"]=>
string(7) "20.0000"
["price"]=>
string(7) "19.9900"
}
}
2.1*/ 更改现有等级价格:
$tiersPrices[0]['customer_group_id'] = 'all';
2.2*/要添加另一个,设置一个数组:
$tiersPrices[] = array(
'website' => 'all',
'customer_group_id' => 'all',
'qty' => 50,
'price' => 14.99,
);
3*/ 并更新:
$api->update( 123 , $tiersPrices );
等级价格已更新!
核心代码可读且构建良好,足以查找和理解流程。
这是french articledbrugne 写于 2010 年 1 月 22 日的快速翻译。