Created
August 31, 2015 15:43
-
-
Save RabeaWahab/c065d478a898c5a454f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function retrieveCoupon($observer) | |
{ | |
$payment = $observer->getEvent()->getPayment(); | |
$order = $payment->getOrder(); | |
if ($code = $order->getCouponCode()) { | |
$coupon = Mage::getModel('salesrule/coupon')->load($code, 'code'); | |
$coupon->setTimesUsed($coupon->getTimesUsed()-1); | |
$coupon->save(); | |
$write = Mage::getSingleton('core/resource')->getConnection('core_write'); | |
$query = "UPDATE salesrule_coupon_usage SET times_used = times_used-1 WHERE customer_id='".$order->getCustomerId()."' AND coupon_id='".$coupon->getId()."'"; | |
$result = $write->query($query); | |
if($customerId = $order->getCustomerId()) { | |
if ($customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $coupon->getRuleId())) { | |
$customerCoupon->setTimesUsed($customerCoupon->getTimesUsed()-1); | |
$customerCoupon->save(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment