Categories: How To

How to Set Tier Price Programmatically in Magento

By default, Magento comes with many core functionalities & features that makes it perfect CMS for easy management of products as well as an enhanced e-commerce solution. Magento comes with a promotional tier price solution which is very helpful when you want to give discounts based on the quantity of the products that encourages customers to purchase more quantity. Magento displays tier price on both catalog pages as well as the product page just by adding quantity and price from the admin backend.

Recently, while working on one of the Magento stores, I came up with a situation to change tier price of all the store products. After a sip of coffee, I started coding and ended up with a small piece of code that will save my time as well as helped me to update tier price for products. So, today I would like to share the easiest way to set tier price programmatically in Magento.

All you need to do is pass the product ID and tier price to below code and it will work like a charm to set tier price programmatically for the product.

try
{
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
 
 $Mytierprices[] = array(
                     'website_id'  => 0, 
                     'cust_group'  => 1,
                     'price_qty'   => 5,
            'price'    => 32
 );
 $product_id = 2; //PASS YOUR PRODUCT ID HERE  
 $product = Mage::getModel('catalog/product')->load($product_id);
            $product->setTierPrice($Mytierprices);
            $product->save();
} catch (Exception $e) {
 echo $e->getMessage();
}

You can try and use this code according to your need of setting up tier price for one product or more than one products simply by customizing this code. You can feel free to ask any question regarding this code. Don’t forget to hit down stars and you can also get in touch with us on our social media for more blogs as well as extension updates.
Until that Happy Coding!

Click to rate this post!
[Total: 19 Average: 1.8]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

View Comments

  • Hi
    I need to get tier price as table structure in product detail page and when the qty was changed respective price needs to be replaced in product detail page.

Recent Posts

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

2 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

2 days ago

Magento 2: How to Add Header and Footer in Checkout

Hello Magento Friends, In today’s blog, we will discuss adding a header and footer to…

3 days ago

Understanding Flexbox Layout in React Native

Hello React Native Friends, Building a visually appealing and responsive mobile app is crucial in…

5 days ago

HYVÄ Themes Releases: 1.3.6 & 1.3.7 – What’s New

We're thrilled to announce the release of Hyvä Themes 1.3.6 and 1.3.7! These latest updates…

5 days ago

How Modern E-Commerce Platforms Leverage Docker & Kubernetes for Scalability

Your e-commerce platform is surging - orders are rolling in, traffic spikes are becoming the…

6 days ago