Hi,
If you want to add wholesale price and you want to do some calculations on total price to change subtotal, than follow below steps:
Step1: Create one attribute `wholesale_price` .
Step2: Add getWholesalePrice() function defined bellow in
yourproject/app/code/local/Mage/Checkout/Model/Cart.php
public function getWholesalePrice($pID)
{
$_product = Mage::getModel(‘catalog/product’);
$_product->load($pID);
return $_product->getResource()->getAttribute(‘wholesale_price’)
->getFrontend()->getValue($_product);
}
Step3: Open file yourproject/app/code/local/Mage/Sales/Model/Quote/item.php
– Add below line in function setProduct ->setWholesalePrice(Mage::getModel(‘checkout/cart’)
->getWholesalePrice($product->getId()))
after ->setCost($product->getCost()) statement in function
Step4: To change subtotal open below path file
/yourproject/app/code/local/Mage/Sales/Model/Quote/Address/Total/Subtotal.php
public function collect(Mage_Sales_Model_Quote_Address $address)
{
/**
* Reset subtotal information
*/
$address->setSubtotal(0);
$address->setBaseSubtotal(0);
$address->setTotalQty(0);
$address->setBaseTotalPriceIncTax(0);
/**
* Process address items
*/
$items = $address->getAllItems();
/*******Start:: Changes for wholesale price calculation********/
$isWholesalePrice = false;
$finaltotal = ”;
/*******END:: Changes for wholesale price calculation********/
foreach ($items as $item) {
if (!$this->_initItem($address, $item) || $item->getQty()<=0) {
$this->_removeItem($address, $item);
}
/******START:: Changes for wholesale price calculation*******/
$_totWholesalePrice = $item->getWholesalePrice() * $item->getQty();
$_totPrice = $item->getPrice() * $item->getQty();
if($_totWholesalePrice >= 500 || $_totPrice >= 1000)
{
$isWholesalePrice = true;
}
$finaltotal += $_totWholesalePrice;
/*******END::Changes for wholesale price calculation*******/
}
/******START::Changes for wholesale price calculation******/
if($isWholesalePrice)
{
$address->setSubtotal($finaltotal);
}
/******END:: Changes for wholesale price calculation********/
/*** Initialize grand totals***/
$address->setGrandTotal($address->getSubtotal());
$address->setBaseGrandTotal($address->getBaseSubtotal());
Mage::helper(‘sales’)->checkQuoteAmount($address->getQuote(),
$address->getSubtotal());
Mage::helper(‘sales’)->checkQuoteAmount($address->getQuote(),
$address->getBaseSubtotal());
return $this;
}
Explaination of above function:: In above function we changed calculation of subtotal, here condition is if total wholesale price(wholesale price * Qty) of any product is more than 500 or total price(Sale price * Qty) is more than 1000 than subtotal is calculated on wholesale price.
Above four step will help u to change subtotal and grand total according to subtotal for only one page checkout. To reflect the above calculation to multishipping than follow step5also.
Step5: Open file /yourproject/app/code/local/Mage/Sales/Model/Quote/Address/Item.php
– Add below line in function importQuoteItem
->setWholesalePrice($quoteItem->getWholesalePrice())
after ->setPrice($quoteItem->getPrice()) statement.
If this post is helpful to you than please do write feedback.
Thanks
-Bijal Bhavsar 🙂