How to Set Tier Price Programmatically in Magento

img How to Programetically Set Product Tier Price 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!

Previous Article

How to Override “payment\methods.phtml” in Magento Custom Extension

Next Article

How to Add Color Picker in Magento 2 System Configuration

Write a Comment
  1. 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨