paolo@bimodesign.com | +34 608 61 64 10

E-Commerce

        

Magento, how to manage when discount coupon set price to zero

Starting with this post I'm going to explain the functionality concept about the price zero in Magento Checkout.
I don't know if this is a bug, but I had an issue when I apply a discount coupon code to the total price and the final price was 0. This issue didn'n happen when I set to zero the total product price.

During the debugging, I noticed that the payment method looks NULL, instead of "Free" as when the product is defined with 0 price. (in case of the product was set with a price different to 0, the payment method is Adyen_Hpp, cause I was using the Adyen payment platform).
The exception error was in this part of code of the AitocCheckout Controller's file:
app/code/local/Aitoc/Aitcheckout/controllers/CheckoutController.php

if (!($this->_getOnepage()->getQuote()->getPayment()->getMethod())) {
    Mage::throwException(Mage::helper('aitcheckout')->__('Please select valid payment method.'));
}

I solved this error adding this an if condition, where I assign the value "free" to the Payment Method, that also it requieres where I complete the payment procedure.

if ($this->_getOnepage()->getQuote()->getCouponCode() &&
    number_format($this->_getOnepage()->getQuote()->getGrandTotal(), 0) == 0) {
    $this->_getOnepage()->getQuote()->getPayment()->setMethod("free");
} else {
    if (!($this->_getOnepage()->getQuote()->getPayment()->getMethod())) {
        Mage::throwException(Mage::helper('aitcheckout')->__('Please select valid payment method.'));
    }
}

Note: I had to use the number_format function, cause, only in that case I use a discount coupon , the price looks with more decimals "0.00000" than in the normal case.