PHOENIX-MEDIA / Magento-CashOnDelivery

Cash on Delivery allows to book additional fee on delivery depending on inland or international delivery.
43 stars 46 forks source link

Disallowed shipping methods not working #7

Closed emiliolodigiani closed 10 years ago

emiliolodigiani commented 10 years ago

If I select a disallowed shipping method, the corresponding shipping method is still available in customer checkout.

Tested with ParadoxLabs_StorePickup extension

emiliolodigiani commented 10 years ago

I found where the problem is.

In /app/code/community/Phoenix/CashOnDelivery/Model/CashOnDelivery.php

at line 171 and following

$shippingMethodCode        = explode('_', $quote->getShippingAddress()->getShippingMethod());
$shippingMethodCode        = $shippingMethodCode[0];

have an issue with shipping methods containing _ in the name, as ParadoxLabs_StorePickup (pl_store_pickup). Exploding and getting the first array value returns "pl" instead of "pl_store_pickup".

I think there are two possible solutions:

emiliolodigiani commented 10 years ago

I cannot fork and send you a pull request because I already have an other fork of this repository, working for fixing the invoice tax problem.

Anyway I have tested a fix for this issue:

in file /app/code/community/Phoenix/CashOnDelivery/Model/CashOnDelivery.php

remove lines 172-178

                $shippingMethodCode        = explode('_', $quote->getShippingAddress()->getShippingMethod());
                $shippingMethodCode        = $shippingMethodCode[0];
                $disallowedShippingMethods = $this->getConfigData('disallowedshippingmethods', $quote->getStoreId());

                if (in_array($shippingMethodCode, explode(',', $disallowedShippingMethods))) {
                    return false;
                }

and replace with lines:

                $shippingMethodCode        = $quote->getShippingAddress()->getShippingMethod();
                $disallowedShippingMethods = $this->getConfigData('disallowedshippingmethods', $quote->getStoreId());
                $disallowedShippingMethods = explode(',', $disallowedShippingMethods);

                foreach($disallowedShippingMethods as $disallowedShippingMethod){
                    if(strpos($shippingMethodCode, $disallowedShippingMethod) !== false){
                        return false;
                    }
                }
PHOENIX-MEDIA commented 10 years ago

fixed, thank you!