Product Tier Price add/update in Magento

Magento has strong features to set Tier price. If you are interested to set multiple prices of a product for combination of customer group and product quantities, you can set by Magento Tier price option.

We can handle tier price in many ways. Here I am describing basic logic to add/update tier price in modular way. At first define all tier prices as an array. Ofcourse mind one thing about quantity. Quantity format must be four decimal precision. Like 100.0000. For this you can use below formatting.

$qty = number_format($qty, 4, ‘.’, ”);

01//Define tier price as an array
02$tierPrices[] = array(
03             'website_id'  => 0,
04             'cust_group'  => $customer_group_id,
05             'price_qty'   => $qty,
06             'price'       => $price
07           );
08 
09Ex.
10$tierPrices[0] = array(
11             'website_id'  => 0,
12             'cust_group'  => 1,
13             'price_qty'   => 100.0000,
14             'price'       => 12.0000
15           );
16 
17$tierPrices[1] = array(
18             'website_id'  => 0,
19             'cust_group'  => 2,
20             'price_qty'   => 100.0000,
21             'price'       => 10.0000
22           );
23 
24//get productid for corresponding SKU.
25$productid = Mage::getModel('catalog/product')
26                  ->getIdBySku($sku);
27 
28// Initiate product model
29$product = Mage::getModel('catalog/product');
30 
31// Load specific product whose tier price want to update
32$product ->load($productid);
33 
34// take existing tier prices of that product
35$existingTierPrice = $product->tier_price;
36 
37// Marge existing and new tier prices to update
38$tierPrices=array_merge($existingTierPrice,$newTierPrices);
39 
40// Assign all tier prices to product's tier_price object
41$product->tier_price = $tierPrices;
42 
43// Save you product with all tier prices
44$product->save();

Also Magento has web service API support to handle tier price. If you are expert in web service work then you can do the same thing using Magento API. To handle tier price with api call do something like below.

01$proxy = new SoapClient('http://127.0.0.1/magento/api/soap/?wsdl');
02$sessionId = $proxy->login('apiUser', 'apiKey');
03 
04// Get tier prices
05$tierPrices = $proxy->call($sessionId, 'product_tier_price.info', 'Sku');
06 
07// Add new
08$tierPrices[] = array(
09    'website'           => 'all',
10    'customer_group_id' => 'all',
11    'qty'               => 68,
12    'price'             => 18.20
13);
14 
15// Update tier prices
16$proxy->call($sessionId, 'product_tier_price.update', array('Sku', $tierPrices));

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值