How to change price for buy all stock for a product in magento

By | April 22, 2017
Spread the love

Default magento  have option to change product price based on qty by tire pricing rules in admin panel. But if any admin wants to give another discount on take all stock then he needs to create module to achieve it.

You can also create product attribute like minimum qty should be exist to apply take all price logic. So based on min qty and discounted price will apply when user will add product to cart. If user will change qty after adding all stock the price will change to regular product price.

Lets explain how you can do it. Create a test module with file. Techgroup_OrderUpdate.xml

<?xml version="1.0"?>

Create a config.xml file in module  etc folder.

		      <last_stock_min_qty />
		       <last_stock_price />
		       <shipping_price />

Create a model class Observer.php


class Techgroup_OrderUpdate_Model_Observer
	public function getNewPrice($quote_item)
		$product  = $quote_item->getProduct();
		$stock    = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
		$_product = Mage::getModel("catalog/product")->load($product->getId());
			return false;
		if(!$_product->getLastStockMinQty() || !$_product->getLastStockPrice()){
			return false;
		$newprice = $_product->getPrice();
		$prices   = $_product->getTierPrice();
		foreach($prices as $group => $price){
			list($name,$qty) = explode("-", $group);
			if($quote_item->getQty() >= $qty){
				$newprice = $price['price'];
		$allStockPrice = false;
		if($_product->getLastStockMinQty() && $_product->getLastStockPrice()){
			if((int)$stock->getQty() == (int)$quote_item->getQty() && $quote_item->getQty() >= $_product->getLastStockMinQty())
				$newprice = $_product->getLastStockPrice();
				$allStockPrice = true;
		return $newprice;
	public function changePrice(Varien_Event_Observer $observer)
			return false;
		$storeId = Mage::app()->getStore()->getStoreId();
		$event  = $observer->getEvent();
		$quote  = $event->getQuote();
		$items  = $quote->getAllVisibleItems();
		foreach($items as $item)
			$new_price  = $this->getNewPrice($item);


Leave a Reply

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

15 − ten =