I want to offer free shipping on subtotal but after discount is applied. I have added a new price rule called grand total and using this as the condition in price rules but this does not work for me. Here is my code. Wondering where is my mistake.
<?php
class MY_SalesRule_Model_Rule_Condition_Address extends Mage_SalesRule_Model_Rule_Condition_Address {
public function loadAttributeOptions()
{
//added the base_grandtotal
$attributes = array(
'base_subtotal' => Mage::helper('salesrule')->__('Subtotal'),
'base_grandtotal' => Mage::helper('salesrule')->__('Grandtotal'),
'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 getInputType()
{
switch ($this->getAttribute()) {
case 'base_subtotal': case 'base_grandtotal': 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 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());
}
//The below is added for caculating the grandtotal
$quote = Mage::getModel('checkout/session')->getQuote();
$quoteData= $quote->getData();
if( $quote && $quote->getData('base_grandtotal') ){
$basegrandTotal = $quote->getData('base_grandtotal');
if ('base_grandtotal' == $this->getAttribute() && ! $address->hasBaseGrandtotal()) {
$address->setBaseGrandtotal($basegrandTotal);
}
}
return parent::validate($address);
}
}