@omouse's answer pointed us to Magento's API for tier prices. [Updated Link for Magento 1.X's Tier Price API] Note: I'm working with Magento 1.9.2.2.
After looking around for the most efficient way to update a product's tier prices (without using direct SQL), I found the API is the fastest way. It's still slow, but it's better than the other methods I found which recommended doing something like:
// Works, but is slow
$product = Mage::getModel('catalog/product')->load($productId);
$product->unsTierPrice();
$product->save();
$product->load();
$product->setTierPrice($tiers);
$product->save();
Better, I made my array of tier arrays into an array of tier objects, and used the API functions to update the product:
// Build the array of tier level objects
foreach ($tierLevels as $tierLevel) {
$tiers[] = (object) array(
'website' => 'all',
'customer_group_id' => 'all',
'qty' => $tierLevel['min_qty'],
'price' => $tierLevel['unit_price']
);
}
// Use the API to do the update
try {
$tierPriceApi = Mage::getSingleton('catalog/product_attribute_tierprice_api_v2');
$tierPriceApi->update($productId, $tiers);
}
catch (Exception $e) {
// Handle the exception
}
Mage::getModel("catalog/product")->load(123) ->unsTierPrice() ->save() ->load() ->setTierPrice(array( array( 'website_id' => 0, 'all_groups' => 0, 'cust_group' => 4, 'price' => 99.99, 'price_qty' => 1 ), array() // another tier, etc )) ->save();
– Helium