Table rates shipping Method not working after migration to magento v1.6
Hello
Table rates shipping method is not working properly in magento 1.6 or after migration to magento v1.6.
To resolve this follow below points:
1)Open file Mage/Shipping/Model/Resources/Carrier/Tablerate.php and copy it in app/code/local folder
2)Find getRate() function and replace given code in that function:
public function getRate(Mage_Shipping_Model_Rate_Request $request)
{
$adapter = $this->_getReadAdapter();
$bind = array(
‘website_id’ => (int)$request->getWebsiteId(),
‘country_id’ => $request->getDestCountryId(),
‘region_id’ => (int)$request->getDestRegionId(),
‘postcode’ => $request->getDestPostcode()
);
$select = $adapter->select()
->from($this->getMainTable())
->where(‘website_id = ‘.$bind[‘website_id’])
->order(array(‘dest_country_id DESC’, ‘dest_region_id DESC’, ‘dest_zip DESC’,’condition_value DESC’))
->limit(1);
// render destination condition
$orWhere = ‘(‘ . implode(‘) OR (‘, array(
“dest_country_id = ‘”.$bind[‘country_id’].”‘ AND dest_region_id = ‘”.$bind[‘region_id’].”‘ AND dest_zip = “.$bind[‘postcode’],
“dest_country_id = ‘”.$bind[‘country_id’].”‘ AND dest_region_id = ‘”.$bind[‘region_id’].”‘ AND dest_zip = ””,
“dest_country_id = ‘”.$bind[‘country_id’].”‘ AND dest_region_id = ‘”.$bind[‘region_id’].”‘ AND dest_zip = ‘0’”,
“dest_country_id = ‘”.$bind[‘country_id’].”‘ AND dest_region_id = ‘”.$bind[‘region_id’].”‘ AND dest_zip = ‘*'”,
//”dest_country_id = ‘0’ AND dest_region_id = 0 AND dest_zip = ‘*'”,
)) . ‘)’;
$select->where($orWhere);
// render condition by condition name
if (is_array($request->getConditionName())) {
$orWhere = array();
$i = 0;
foreach ($request->getConditionName() as $conditionName) {
$bindNameKey = sprintf(‘:condition_name_%d’, $i);
$bindValueKey = sprintf(‘:condition_value_%d’, $i);
$orWhere[] = “(condition_name = {$bindNameKey} AND condition_value getData($conditionName);
$i++;
}
if ($orWhere) {
$select->where(implode(‘ OR ‘, $orWhere));
}
} else {
$bind[‘condition_name’] = $request->getConditionName();
$bind[‘condition_value’] = $request->getData($request->getConditionName());
$select->where(‘condition_name = “‘.$bind[‘condition_name’].'”‘);
$select->where(‘condition_value fetchRow($select, $bind);
// normalize destination zip code
if ($result && $result[‘dest_zip’] == ‘*’) {
$result[‘dest_zip’] = ”;
}
return $result;
}
This works for me like a charm. Hope it works for you also.
If it helps you don’t forget to comment me.
Regards,
Meghna Vora