Magento free shipping after discount

If you have free shipping after x on magento then apply a discount coupon code that brings the total below x the customer still gets free shipping. Here is a corrected file for magento 1.9

This was based on a post that I can’t find anymore.

You will need to change this to the ID of the shopping cart promotion that you are using for the free shipping rule. if ($ruleId==’2′)

/app/code/local/Mage/SalesRule/Model/Rule/Condition/Address.php

 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'),
            'payment_method' => Mage::helper('salesrule')->__('Payment Method'),
            'shipping_method' => Mage::helper('salesrule')->__('Shipping Method'),
            'postcode' => Mage::helper('salesrule')->__('Shipping Postcode'),
            'region' => Mage::helper('salesrule')->__('Shipping Region'),
            'region_id' => Mage::helper('salesrule')->__('Shipping State/Province'),
            'country_id' => Mage::helper('salesrule')->__('Shipping Country'),
        );

        $this->setAttributeOption($attributes);

        return $this;
    }

    public function getAttributeElement()
    {
        $element = parent::getAttributeElement();
        $element->setShowAsText(true);
        return $element;
    }

    public function getInputType()
    {
        switch ($this->getAttribute()) {
            case 'base_subtotal': case 'base_subtotal_with_discount': case 'weight': case 'total_qty':
                return 'numeric';

            case 'shipping_method': case 'payment_method': case 'country_id': case 'region_id':
                return 'select';
        }
        return 'string';
    }

    public function getValueElementType()
    {
        switch ($this->getAttribute()) {
            case 'shipping_method': case 'payment_method': case 'country_id': case 'region_id':
                return 'select';
        }
        return 'text';
    }

    public function getValueSelectOptions()
    {
        if (!$this->hasData('value_select_options')) {
            switch ($this->getAttribute()) {
                case 'country_id':
                    $options = Mage::getModel('adminhtml/system_config_source_country')
                        ->toOptionArray();
                    break;

                case 'region_id':
                    $options = Mage::getModel('adminhtml/system_config_source_allregion')
                        ->toOptionArray();
                    break;

                case 'shipping_method':
                    $options = Mage::getModel('adminhtml/system_config_source_shipping_allmethods')
                        ->toOptionArray();
                    break;

                case 'payment_method':
                    $options = Mage::getModel('adminhtml/system_config_source_payment_allmethods')
                        ->toOptionArray();
                    break;

                default:
                    $options = array();
            }
            $this->setData('value_select_options', $options);
        }
        return $this->getData('value_select_options');
    }

    /**
     * Validate Address Rule Condition
     *
     * @param Varien_Object $object
     * @return bool
     */
    public function validate(Varien_Object $object)
    {
        $address = $object;
        if (!$address instanceof Mage_Sales_Model_Quote_Address) {
            if ($object->getQuote()->isVirtual()) {
                $address = $object->getQuote()->getBillingAddress();
            }
            else {
                $address = $object->getQuote()->getShippingAddress();
            }
        }

        if ('payment_method' == $this->getAttribute() && ! $address->hasPaymentMethod()) {
            $address->setPaymentMethod($object->getQuote()->getPayment()->getMethod());
        }
		$rowsTotals=0;
		foreach ($object->getQuote()->getAllItems() as $item) {
			if( $item->getAppliedRuleIds()){	
			  $appliedRulesArray = explode(',',$item->getAppliedRuleIds());
				foreach($appliedRulesArray as $ruleId){
				
					/* $rowsTotals+=($item->getRowTotal()-$item->getDiscountAmount());  */
					if ($ruleId=='2') { // $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);
		if ($ruleId=='2')
			$address->setBaseSubtotal($rowsTotals);
        return parent::validate($address);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *