I want to enable/disable free shipping based on my custom quote conditions, it works fine when free shipping is enabled from admin but I want it to work also when free shipping is disabled from admin. I tried the following solutions but none of them worked for me - How do I enable free shipping in backend only (for order entry)
-
If you only provide shipping with an amount of 0, you can use shopping cart rules to achieve this. However it's applied to another shipping method than "free shipping".– luemicCommented May 11, 2016 at 6:44
-
I have added a custom column in quote table and I want to allow free shipping condition on that column's value.– PiyushCommented May 11, 2016 at 6:48
Add a comment
|
1 Answer
You need to rewrite the following class:
Mage_Shipping_Model_Shipping
and modify the following method to:
/**
* Get carrier by its code
*
* @param string $carrierCode
* @param null|int $storeId
* @return bool|Mage_Core_Model_Abstract
*/
public function getCarrierByCode($carrierCode, $storeId = null)
{
if (($carrierCode == 'freeshipping' && $customCondition) || !Mage::getStoreConfigFlag('carriers/'.$carrierCode.'/'.$this->_availabilityConfigField, $storeId)) {
return false;
}
$className = Mage::getStoreConfig('carriers/'.$carrierCode.'/model', $storeId);
if (!$className) {
return false;
}
$obj = Mage::getModel($className);
if ($storeId) {
$obj->setStore($storeId);
}
return $obj;
}
and you need to rewrite
Mage_Shipping_Model_Carrier_Freeshipping
(or better create a new carrier based on freeshipping)
and make the following changes:
/**
* FreeShipping Rates Collector
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$customCondition && !$this->getConfigFlag('active')) {
return false;
}
$result = Mage::getModel('shipping/rate_result');
$this->_updateFreeMethodQuote($request);
if (($request->getFreeShipping())
|| ($request->getBaseSubtotalInclTax() >=
$this->getConfigData('free_shipping_subtotal'))
) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('freeshipping');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('freeshipping');
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice('0.00');
$method->setCost('0.00');
$result->append($method);
}
return $result;
}
-
Can You please explain what changes I have to made in rewrite files?– PiyushCommented May 11, 2016 at 9:37
-
In
Mage_Shipping_Model_Shipping
the first if condition is extended:if (($carrierCode == 'freeshipping' && $customCondition) ||..
which ignores the active flag if your custom condition is met. The same is applied toMage_Shipping_Model_Carrier_Freeshipping
in the first ifif (!$customCondition &&..
which ignores the active flag if your custom condition is met. Please note that you need to implement the calculation of the condition for yourself, but that's another question.– luemicCommented May 11, 2016 at 11:09 -
Please let me know if there's some confusion left or mark this issue as solved. Thanks.– luemicCommented May 12, 2016 at 9:54
-
Thank You Michael , I Created a custom shipping method to meet the requirements.– PiyushCommented May 12, 2016 at 11:16