cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup Free Shipping with minimum amount for selected Products after Discount? Magento 1.9x

How to setup Free Shipping with minimum amount for selected Products after Discount? Magento 1.9x

My Client needed   to give Free Shipping for some specific categories with orders over 50.

 

I couldn't use Freeshipping from CONFIG because I needed the free shipping  to apply only to some specific  categories.

So I started using a simple filter of a shopping cart rule. But magento calculates the freeshipping  before any discount.

So if I had a $60 worth of elegible categories in my cart it was alegible for freeshipping  but then when I added a 20% coupon.

The Total was $60-$12 = $48 and the free shipping was still applying.

 

This is how I solved, that problem.

 copy the file address.php from \app\code\core\Mage\SalesRule\Model\Rule\Condition\ and copy the file to

 

\app\code\local\Mage\SalesRule\Model\Rule\Condition\

 

 after line 33,add this code 'base_subtotal_with_discount' => Mage::helper('salesrule')->__('Subtotal with discount'),  this will add a dropdown under conditions for shopping cart rules.

 

 

$attributes = array(
'base_subtotal' => Mage::helper('salesrule')->__('Subtotal'),
'base_subtotal_with_discount' => Mage::helper('salesrule')->__('Subtotal with discount'),
'total_qty' => Mage::helper('salesrule')->__('Total Items Quantity'),
'weight' => Mage::helper('salesrule')->__('Total Weight'),

 

 

 

on line 59 add  case 'base_subtotal_with_discount'

 

   case 'base_subtotal': case 'base_subtotal_with_discount': case 'weight': case 'total_qty':
                return 'numeric';

 

 

on line 130 just before return parent::validate($address); add   this code

 

 

 

$rowsTotals=0;
		foreach ($object->getQuote()->getAllItems() as $item) {
			if( $item->getAppliedRuleIds()){	
			  $appliedRulesArray = explode(',',$item->getAppliedRuleIds());
				foreach($appliedRulesArray as $ruleId){
					if ($ruleId=='5') { // $ruleId=='5' number 5 is the ID of the RULE that is going to filter elegible products 
					$rowsTotals+=($item->getRowTotal()-$item->getDiscountAmount()); 
					}	
				}	
			}
		}
		$address->setBaseSubtotalWithDiscount($rowsTotals);

 

 

Then we are going to add to RULE to the shopping cart.

The first one in my case is going to be the one that filter the categories and apply the coupon to the cart.

This coupon the one used to compare in my case this is ID=5   //if ($ruleId=='5') {

There are no conditions.

The actions everything in 0 and NO, on the 

 

Apply the rule only to cart items matching the following conditions (leave blank for all items)

 

If ALL  of these conditions are TRUE :

All the items that are not in these categories now have the coupon applied to them ( the coupon doesn't do anything)

 

Now we add another  coupon, this is the one that is going to apply the free shipping.

We select subtotal wih discount  under conitions that is the new dropdown item that we added on the address.php

  Conditions=

If ALL  of these conditions are TRUE :

Actions =Everything 0 except for

Free ShippingFor matching items only

 

 

and that's it, know the freeshipping is caclulated only on elegible items after all discounts.