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, ‘.’, ”);
//Define tier price as an array
$tierPrices[] = array(
'website_id' => 0,
'cust_group' => $customer_group_id,
'price_qty' => $qty,
'price' => $price
);
Ex.
$tierPrices[0] = array(
'website_id' => 0,
'cust_group' => 1,
'price_qty' => 100.0000,
'price' => 12.0000
);
$tierPrices[1] = array(
'website_id' => 0,
'cust_group' => 2,
'price_qty' => 100.0000,
'price' => 10.0000
);
//get productid for corresponding SKU.
$productid = Mage::getModel('catalog/product')
->getIdBySku($sku);
// Initiate product model
$product = Mage::getModel('catalog/product');
// Load specific product whose tier price want to update
$product ->load($productid);
// take existing tier prices of that product
$existingTierPrice = $product->tier_price;
// Marge existing and new tier prices to update
$tierPrices=array_merge($existingTierPrice,$newTierPrices);
// Assign all tier prices to product's tier_price object
$product->tier_price = $tierPrices;
// Save you product with all tier prices
$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.
$proxy = new SoapClient('http://127.0.0.1/magento/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
// Get tier prices
$tierPrices = $proxy->call($sessionId, 'product_tier_price.info', 'Sku');
// Add new
$tierPrices[] = array(
'website' => 'all',
'customer_group_id' => 'all',
'qty' => 68,
'price' => 18.20
);
// Update tier prices
$proxy->call($sessionId, 'product_tier_price.update', array('Sku', $tierPrices));
Hi,
I have extend trie price module and created one new filed everything works fine but unable to inert or update data.
Please do help me and if possible explain me with example beacause above mentioned example is not clear for me like where to start and end.
Please do help me.
Best Regards,
Swathi Chilukuri
I know this post is a bit old, but THANK YOU! I thought the task I was working on would be a full day or so, but it ended up being half that
I tried to set tier price with $product->setData(‘tier_price’,$tierPrices) but it didn’t work. But when I tried $product->tier_price = $tierPrices as you have said it worked. its strange.
when we do $product->setData(‘tier_price’,$tierPrices) why doesnot it work in local module. But same thing is working in core .
I found that it only works when value of Catalog Price Scope in configuration is website
my mistake actually it works when value of catalog price scope is global
Please try our extension for group prices “Customer Group Prices” http://www.webtexsoftware.com/customer-group-prices-magento-extension