Magento Forum

   
Apply coupon discount on Original Price not on special price in magento programmatically
 
pradeep_kumar67
Sr. Member
 
Avatar
Total Posts:  160
Joined:  2010-06-24
Bangalore
 

Hi,

In Magento Default coupon code will apply to special price if special price is there else it will apply to original price ,
but in some case we need to apply coupon code discount to original price and then apply to special price
EX:- Special price 1000
Original Price :- 2000
Coupon discount is 10%

Then in cart page it will show special price- discountamount( acc to special price) i’t 1000-100 = 900

but we need special price- discountamount( acc to Original price) i’e 1000- 200 =800

for that we need to create a event

add this xml code in config.xml in side events tag i’e <events></events>

<!-- event for default coupon but discount will apply for MRP-->
            <
salesrule_validator_process>
                <
observers>
                    <
new_dicount_coupon>
                        <
type>singleton</type>
                        <class>
Namespcae_Modulename_Model_Observer</class>
                        <
method>newcoupondiscountcal</method>
                    </
new_dicount_coupon>
                </
observers>
            </
salesrule_validator_process>

And created Observer.php inside your module/model if not exists else add only this function newcoupondiscountcal($observer) in side Observer class

class Namespcae_Modulename_Model_Observer
{


        
//event for default coupon but discount will apply for MRP
 
public function newcoupondiscountcal($observer)
    
{
                 
        $item
=$observer['item'];
        
$rule=$observer['rule'];
         
$rulePercent max(0100-$rule->getDiscountAmount());
         
//print_r($rule->getData()); exit;
         
         
if($rule->getSimpleAction()=='by_percent'{
         $disPer
=$rule->getDiscountAmount();
            
$product=Mage::getModel('catalog/product')->load($item->getProductId());
            
$ratdisc=($product->getPrice()*$disPer)/100;
            
$DiscountAmount=$ratdisc+$item->getDiscountAmount();
            
$BaseDiscountAmount=$ratdisc+$item->setBaseDiscountAmount();
            
            
$result $observer['result'];
            
$result->setDiscountAmount($DiscountAmount);
            
$result->setBaseDiscountAmount($BaseDiscountAmount);
                
        
}
    }
    
}
//end: class

clear cache and apply the code

File Attachments
Observer.php  (File Size: 1KB - Downloads: 106)
 
Magento Community Magento Community
Magento Community
Magento Community
 
pankajcse
Jr. Member
 
Total Posts:  3
Joined:  2012-10-03
 

Sir i want to apply prices fetched from my custom table (say my_own_prices). Can you help me with this. I have certain situation where i can’t use the prices of magento (eg. tiered price or special price), i need to fetch data from my table and apply it on shopping cart. Please reply if this is possible.

 
Magento Community Magento Community
Magento Community
Magento Community
 
pradeep_kumar67
Sr. Member
 
Avatar
Total Posts:  160
Joined:  2010-06-24
Bangalore
 

if you need to show Original Price in cart not special price only after apply coupon code follow below steps

1. Open the file app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php
2. override function getPrice() to local folder

public function getPrice()
{
    $productPrice 
$this->_getData('price');
    
$quoteObj=Mage::getModel('sales/quote')->load($this->getQuoteId());
    
$quoteCouponCode $quoteObj->getCouponCode();
    if (
$quoteCouponCode!=''){
         $productId 
$this->getProductId();
         
$product Mage::getModel('catalog/product')->load($productId);
            
         
$item Mage::getModel('sales/Quote_Item')->load($this->getItemId());
         
$discountAmount $item->getDiscountAmount();
         if (
$discountAmount>0){
             $productPrice 
$product->getPrice();
         
}
     } 
     
return $productPrice;
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
pradeep_kumar67
Sr. Member
 
Avatar
Total Posts:  160
Joined:  2010-06-24
Bangalore
 

@pankajcse

in observer you can search this code

$ratdisc=($product->getPrice()*$disPer)/100;

replace

$ratdisc=($my_own_prices*$disPer)/100;

 
Magento Community Magento Community
Magento Community
Magento Community
 
CoastAMS
Member
 
Avatar
Total Posts:  57
Joined:  2011-03-24
Bath
 

Hi,

I have implemented the code above as i need the coupon to disregard the special price and give the discount off the original price.

Original Price: £100
Special Price: £60
Coupon Code: 50%

Outcome - Price: £50 NOT £30

The coupon is taking £50 off of the special price though ending with £10…

Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Zertalx
Jr. Member
 
Total Posts:  22
Joined:  2012-02-23
 
pradeep_kumar67 - 08 January 2013 12:23 AM

if you need to show Original Price in cart not special price only after apply coupon code follow below steps

1. Open the file app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php
2. override function getPrice() to local folder

public function getPrice()
{
    $productPrice 
$this->_getData('price');
    
$quoteObj=Mage::getModel('sales/quote')->load($this->getQuoteId());
    
$quoteCouponCode $quoteObj->getCouponCode();
    if (
$quoteCouponCode!=''){
         $productId 
$this->getProductId();
         
$product Mage::getModel('catalog/product')->load($productId);
            
         
$item Mage::getModel('sales/Quote_Item')->load($this->getItemId());
         
$discountAmount $item->getDiscountAmount();
         if (
$discountAmount>0){
             $productPrice 
$product->getPrice();
         
}
     } 
     
return $productPrice;
}

Hi this doesn’t work when I create an order from the admin, I’m looking for a model that return this in core/Mage/Adminhtml, do you know where I can find that?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
pradeep_kumar67
Sr. Member
 
Avatar
Total Posts:  160
Joined:  2010-06-24
Bangalore
 
CoastAMS - 11 January 2013 01:53 AM

Hi,

I have implemented the code above as i need the coupon to disregard the special price and give the discount off the original price.

Original Price: £100
Special Price: £60
Coupon Code: 50%

Outcome - Price: £50 NOT £30

The coupon is taking £50 off of the special price though ending with £10…

Any ideas?

i am not getting what actually out come is can you share screen shot

 
Magento Community Magento Community
Magento Community
Magento Community
 
pradeep_kumar67
Sr. Member
 
Avatar
Total Posts:  160
Joined:  2010-06-24
Bangalore
 
Zertalx - 16 January 2013 06:42 AM

pradeep_kumar67 - 08 January 2013 12:23 AM
if you need to show Original Price in cart not special price only after apply coupon code follow below steps

1. Open the file app/code/core/Mage/Sales/Model/Quote/Item/Abstract.php
2. override function getPrice() to local folder

public function getPrice()
{
    $productPrice 
$this->_getData('price');
    
$quoteObj=Mage::getModel('sales/quote')->load($this->getQuoteId());
    
$quoteCouponCode $quoteObj->getCouponCode();
    if (
$quoteCouponCode!=''){
         $productId 
$this->getProductId();
         
$product Mage::getModel('catalog/product')->load($productId);
            
         
$item Mage::getModel('sales/Quote_Item')->load($this->getItemId());
         
$discountAmount $item->getDiscountAmount();
         if (
$discountAmount>0){
             $productPrice 
$product->getPrice();
         
}
     } 
     
return $productPrice;
}

Hi this doesn’t work when I create an order from the admin, I’m looking for a model that return this in core/Mage/Adminhtml, do you know where I can find that?

Thanks

implement the code discount is happening for MRp price only else it will not happen in front end also both will call same events

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mounish
Jr. Member
 
Total Posts:  14
Joined:  2010-09-22
 

I checked your posting, and you have applied catalog price rule to original price discarding special price. I wanted it in a bit different way. Please check the scenario below. It would be of a great help if you would be able to give some solution. I am super stuck with this point.

I want to apply Catalog Price Rules to Special Price of Products.

I have a lot of products in my site with special price. Now i want to apply an additional discount using catalog price rules to that same products with special prices. Its not possible by default in magento. Ho to achive this functionality ? Catalog price rules doesnt applies to Special priced product.

Eg:
Price : 1000
Sp Price : 800

Catalog Price Rule : 10% Discount

Final Price : 720 (i.e 10% Discount on Special Price : 800)

How could this be achived ? Is it possible ?

Thanks a lot in Advance for trying. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
pallavis11
Jr. Member
 
Total Posts:  4
Joined:  2011-11-29
 

Hi,

This code is applicable for qty=1,

for multiple qty, add follwing in observer function

$qty = $item->getQty();

Then look for

$ratdisc=($product->getPrice()*$disPer)/100;

and replace with
$ratdisc=($qty*($product->getPrice()*$disPer))/100;

Updated code will look like this

public function couponDiscountCalcInMrp($observer)
{

$item=$observer[’item’];
$rule=$observer[’rule’];

// add qty here
$qty = $item->getQty();
$rulePercent = max(0, 100-$rule->getDiscountAmount());
// print_r($rule->getData()); exit;

if($rule->getSimpleAction()==’by_percent’) {
$disPer=$rule->getDiscountAmount();
$product=Mage::getModel(’catalog/product’)->load($item->getProductId());
$ratdisc=($qty*($product->getPrice()*$disPer))/100;
$DiscountAmount=$ratdisc+$item->getDiscountAmount();
$BaseDiscountAmount=$ratdisc+$item->setBaseDiscountAmount();

$result = $observer[’result’];
$result->setDiscountAmount($DiscountAmount);
$result->setBaseDiscountAmount($BaseDiscountAmount);

}
}

and your code will work for mutiple qtys as well.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top