Enable Free Shipping Promotion Code

Posted Date: November 29, 2010

I was looking the way to create Free Shipping promotion code and came to know that there is no way in magento. I searched and found the very nice solution, which may help someone else as well.

So, I searched and found the very good solution to create the promotion code which can work just like any other promotion code, but for that you need to modify your code.
Here is the complete code:

The shipping is calculated in the following code (Table Rate method), as every shipping method has its own model:

app/code/core/Mage/Shipping/Model/Carrier/Tablerate.php

Go to the collectRates method:


if (!empty($rate) && $rate['price'] >= 0) {
$method = Mage::getModel('shipping/rate_result_method');

$method->setCarrier('tablerate');
$method->setCarrierTitle($this->getConfigData('title'));

$method->setMethod('bestway');
$method->setMethodTitle($this->getConfigData('name'));

$shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);

$method->setPrice($shippingPrice);
$method->setCost($rate['cost']);

$result->append($method);
}

And change it to:


if (!empty($rate) && $rate['price'] >= 0) {
$method = Mage::getModel('shipping/rate_result_method');

$method->setCarrier('tablerate');
$method->setCarrierTitle($this->getConfigData('title'));

$method->setMethod('bestway');

// If the free shipping promo condition is met
if($request->getFreeShipping() === true) {
$shippingPrice = '0.00'; // we set the shipping price to zero
// then we change the method title to indicate shipping is free
$method->setMethodTitle(Mage::helper('shipping')->__('Free Shipping'));
} else { // else we continue as normal
$shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
$method->setMethodTitle($this->getConfigData('name'));
}

$method->setPrice($shippingPrice);
$method->setCost($rate['cost']);

$result->append($method);
}

Create promotion code and select “For shipment with matching items” in action area, please see below image for more detail.

free shipping