Magento has quite a big bug which enables the shipping module to calculate shipping costs without discount or shipping rules (if they are applied).
It cost me hours to find a workaround, so if you use it, I’d really appreciate it if you refer to this blog.
How I fixed it
Go to:
/app/code/local/Mage/Shipping/Model/Carrier/Tablerate.php
Add the following code at around line 77 (in the collectRates function):
$s_price = $request->getPackageValueWithDiscount();
$request->setPackageValue($s_price);
Now, the shipping rates are calculated on the subtotal minus the discount. I hope this solves the problem (it does in 1.7)
Indeed, this solved the problem in Magento 1.7
Thank you, this solved our problem with calculating shipping costs when using discount coupons in Magento 1.6.1.
Thanks for this. Works in 1.8.1.0
Was surprised this sort of thing needed a ‘hack’ really! 🙂
Hello, sorry, I am having some problems to apply those lines. I am using a free extension for shipping rates “MATRIXRATE”. May it be different because this extension?
Hello,
finally it worked for me using a matrixshipping rates when changing the “PackageValue” for “PackageValueWithDiscount” and when I notice you have to have the \’tablerates\’ shipping method active (in sytem – shipping methods) , even if the spreadsheet is empty, then the \’matrixrates\’ plugin also gets the correct subtotal.
thanks, best regards.
Fantastic, thanks for the help, this little snippet about enabling table rates solved my problems.
Works like a charm.
Muchas gracias amigo.
Where to add ?????/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag(‘active’)) {
return false;
}
// exclude Virtual products price from Package value if pre-configured
if (!$this->getConfigFlag(‘include_virtual_price’) && $request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValue() – $child->getBaseRowTotal());
}
}
} elseif ($item->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValue() – $item->getBaseRowTotal());
}
I….I love you. Many hours spent fighting with this, thanks!
You are The Dude!!! Thanks mate 🙂
its working fine.
Thanks.
Did you get this to work in 1.9?
Did not work for me in 1.9. Maybe I’m missing somthing? If someone has it working in 1.9 can you post like to file and code? Thank
replace getPackageValue with getPackageValueWithDiscount in all file. Tested on 1.9 and work
I can confirm this fix works on 1.9.2 as well.
Hi.
I’m using a promotion cart rule:
– Free Shipping when the country is Spain
– Subtotal is equal or greater than 49.59 Euros.
When the people have 49.59 Euros in the cart, this works fine.
I have promotion cart rule:
– Discount code 10%
But when is applied a discount coupon of 10% then still the free shipping and the subtotal is minus than 49.59 with the coupon applied.
How i can solve it?
Thank you very much.
PD: I’m using 2 modules with tablerates.csv configured.
I created this thread. This is exactly what you need.
I used for magento 1.9.2
https://community.magento.com/t5/Admin-Configuration-Questions/How-to-setup-Free-Shipping-with-minimum-amount-for-selected/td-p/17674
Pingback: Magento, Versand per Table-Rates & Rabattgutschein - alexander-steireif.com
Great, it even works in 1.5.1 🙂
Hi ,
Great Thanks, saved my lots of time. It worked for me in magento 1.9.0.1. Thanks mate.
I had replaced getPackageValue with getPackageValueWithDiscount in Tablerate.php file.
Hi,
When i submit the order getting error message after chnaged the code, “There was an error processing your order… please specify shipping method error in magento with table rate”. Please help me to solve this.
Getting crazy, doing exactly like above but it will not work in 1.9.2.4
public function collectRates(Mage_Shipping_Model_Rate_Request $request->getPackageValueWithDiscount())
{
if (!$this->getConfigFlag(‘active’)) {
return false;
}
// exclude Virtual products price from Package value if pre-configured
if (!$this->getConfigFlag(‘include_virtual_price’) && $request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValueWithDiscount() – $child->getBaseRowTotal());
}
}
} elseif ($item->getProduct()->isVirtual()) {
$request->setPackageValue($request->getPackageValueWithDiscount() – $item->getBaseRowTotal());
}
}
}
Just to clarify what Raul said for Matrixrate.php, this is a webshopapps plugin. This hack works perfect on Magento 1.9.2.4
add this code at the top of the collectRates function
$s_price = $request->getPackageValueWithDiscount();
$request->setPackageValue($s_price);
Then change all the “getPackageValue” code to “getPackageValueWithDiscount”
Thank you for this thread.
-J
thank you so much, this has fixed this perplexing problem!
Works perfect in Magento 1.9.3.8
Thank you so much!!
IS there any solution for magento 2?