0

I used the following code to retrieve the coupon code for the current order:

$Coupon_Code = $order->getCouponCode();

It works fine, but I want to get the discount amount for a certain coupon code, using this code:

$Coupon_Code = $order->getCouponCode();
            
$oCoupon = Mage::getModel('salesrule/coupon')->load($Coupon_Code, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
var_dump($oRule->getData());
$Coupon_Discount =$Coupon_Code['Discount Amount'];
        
SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Mo Salah
  • 3
  • 1
  • 7
  • Did you try doing a Google search for `getCouponCode()`? I found code that would give you what you need at http://freegento.com/doc/d0/d40/_validator_8php-source.html – Enigmativity May 31 '17 at 00:50
  • @Enigmativity I am new in magento , It's hard to me to check the link code – Mo Salah May 31 '17 at 00:59
  • Are you saying you can't click the link or are you saying that you couldn't read the code to find where it is getting the discount amount? – Enigmativity May 31 '17 at 01:01
  • Actually I checked the codes but I could not get what I need I used this line of codes : $Coupon_Discount=Mage::getModel('sales/order')->load($order); $Coupon_Discount->getDiscountAmount(); – Mo Salah May 31 '17 at 01:11
  • Do you expect that line to give you the discount amount of the coupon or the discount applied to the particular order? – Enigmativity May 31 '17 at 01:14
  • Possible duplicate of [Magento - get rule from coupon code](https://stackoverflow.com/questions/10531765/magento-get-rule-from-coupon-code) – Enigmativity May 31 '17 at 01:20
  • I edited the question but it doesn't work – Mo Salah May 31 '17 at 01:46
  • When you say it doesn't work can you explain what happens and how you know it doesn't work? – Enigmativity May 31 '17 at 02:15

2 Answers2

0

You can get the discount amount for a certain coupon code by using this:

$couponCode = '**YOUR COUPONCODE**';
$oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
print_r($oRule->getData());exit();

In the response you can get all of the details regarding COUPONCODE.

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
  • The coupon amount return empty: $oCoupon = Mage::getModel('salesrule/coupon')->load($Coupon_Code, 'code'); $oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId()); $Coupon_Number=$oRule->getData('discount_amount'); echo "$Coupon_Numbe"; exit(); – Mo Salah May 31 '17 at 10:05
  • Thanks.! Can you please check your $Coupon_Code variable contain Value or NULL and if yes(Value) then check that coupon code in the admin is exist and Active? – Elsner Magento Development May 31 '17 at 12:12
0

Refer to the following code to get the discount amount from the order:

$orderNumber = 145000006; 
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
$orderDetails = $order->getData();

$couponCode = $orderDetails['coupon_code'];
$discountAmt = $orderDetails['discount_amount'];
SuperStormer
  • 4,997
  • 5
  • 25
  • 35