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 |
09 |
Ex. |
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)