0

I was disabled default COD module. Now I am using CashOnDelivery Based on Zipcode from magentocommerce. I need to add two custom fields Minimum order total & Maximum order total in backend. Through xml I was added those fields here the screen. Backend screen Now I need to process the condition minimum & maximum order total.

Here my CashOnDelivery Based on Zipcode module code.`

public function getCashOnDelvery(Varien_Event_Observer $observer) {
        $event           = $observer->getEvent();
        $method          = $event->getMethodInstance();
        $result          = $event->getResult();
        $isModuleEnable = Mage::getStoreConfig('cod/cod/enable');

        if($isModuleEnable) {

            if($method->getCode() == 'cashondelivery' ){

                $quote = Mage::getSingleton('checkout/cart')->getQuote();
                $add = $quote->getShippingAddress();
                $postcode = $add->getData('postcode');

                $comparisonMode = Mage::getStoreConfig('cod/cod/mode');
                $zipCodes = Mage::getStoreConfig('cod/cod/zipcode');
                $isExist = false;

                if(trim($zipCodes) == '') {             
                    $result->isAvailable = true; 
                } else {    

                    if(strpos($zipCodes, $postcode) !==  false) {
                        $isExist = true;
                    }


                    if($isExist != true) {

                        $zipCodesArray = explode(',', nl2br($zipCodes));
                        if(count($elementLineArray) > 1) {
                            foreach($zipCodesArray as $codzipLine) {
                                $elementLineArray = explode('-', $codzipLine);
                                if(count($elementLineArray) == 2 && ( $postcode >= $elementLineArray[0] && $postcode <= $elementLineArray[1] )) {
                                    $isExist = true;
                                    break;
                                } else if($postcode == $codzipLine) { 
                                    $isExist = true; 
                                    break;
                                }
                            }
                        }
                    }

                    $returnValue = '';
                        $returnValue = ($isExist)?true:false; 

                    $result->isAvailable = $returnValue;

                }   

            } 
        }   
    }
}

` Dear Magento Experts can you help me to solve this?

1

Changes:

Instead of taken quote from session

  • Mage::getSingleton('checkout/cart')->getQuote(),You cen get Qoute from event $quote = $observer->getEvent()->getQuote();
  • validate the max and min value with Grand total of quote

if((Mage::app()->getStore()->roundPrice($quote->getGrandTotal()) < $minValue )|| ( Mage::app()->getStore()->roundPrice($quote->getGrandTotal()) > $maXValue)){ $result->isAvailable = false; return; }

Observer:

public function getCashOnDelvery(Varien_Event_Observer $observer) {
        $event           = $observer->getEvent();
        $method          = $event->getMethodInstance();
        $result          = $event->getResult();
        $isModuleEnable = Mage::getStoreConfig('cod/cod/enable');

        if($isModuleEnable) {

            if($method->getCode() == 'cashondelivery' ){

                /* Changing the retrive process */
                //$quote = Mage::getSingleton('checkout/cart')->getQuote();
                $quote = $observer->getEvent()->getQuote();
                $add = $quote->getShippingAddress();
                $postcode = $add->getData('postcode');

                $minValue = Mage::getStoreConfig('cod/cod/min_order_total');
                $maXValue = Mage::getStoreConfig('cod/cod/max_order_total');

                /* add max min validation */
                    if((Mage::app()->getStore()->roundPrice($quote->getGrandTotal()) < $minValue )|| (
                        Mage::app()->getStore()->roundPrice($quote->getGrandTotal()) > $maXValue)){
                        $result->isAvailable = false; 
                        return;
                    }

                $comparisonMode = Mage::getStoreConfig('cod/cod/mode');
                $zipCodes = Mage::getStoreConfig('cod/cod/zipcode');
                $isExist = false;

                if(trim($zipCodes) == '') {             
                    $result->isAvailable = true; 
                } else {    

                    if(strpos($zipCodes, $postcode) !==  false) {
                        $isExist = true;
                    }


                    if($isExist != true) {

                        $zipCodesArray = explode(',', nl2br($zipCodes));
                        if(count($elementLineArray) > 1) {
                            foreach($zipCodesArray as $codzipLine) {
                                $elementLineArray = explode('-', $codzipLine);
                                if(count($elementLineArray) == 2 && ( $postcode >= $elementLineArray[0] && $postcode <= $elementLineArray[1] )) {
                                    $isExist = true;
                                    break;
                                } else if($postcode == $codzipLine) { 
                                    $isExist = true; 
                                    break;
                                }
                            }
                        }
                    }

                    $returnValue = '';
                        $returnValue = ($isExist)?true:false; 

                    $result->isAvailable = $returnValue;

                }   

            } 
        }   
    }
}
  • Sir, I tried your code, But my entire module was not working, In check out page zip code condition was not working. – vijayvanu_gmail Feb 24 '17 at 7:46
  • do you have pur [Your_Min_ieldName] fiel name? – Amit Bera Feb 24 '17 at 7:48
  • Sorry Sir i forget it. Where can I find that field name. Through chrome inspect tool i got "id="cod_cod_min_order_total" name="groups[cod][fields][min_order_total][value]"" – vijayvanu_gmail Feb 24 '17 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.