Greeting, i created custom shipping method and it working good.
But, in one page checkout order review the shipping price is zero.
Here is the picture of that:
The shipping in the right sidebar is displaying correct value.
How to make shipping value in Order Review not zero?
Any help or lead is highly appreciated.
Thank you.
--
Additional Detail:
I set Tax Class Shipping as None, shipping price excluding tax, and display shipping amount excluding tax in Tax Configuration.
After tracing the code, function Mage_Tax_Block_Checkout_Shipping::getShippingExcludeTax() returning zero. But, the shipping price in right side bar is not zero Mage_Checkout_Block_Onepage_Progress::getShippingPriceExclTax().
Here is the code of Mage_Tax_Block_Checkout_Shipping::getShippingExcludeTax()
class Mage_Tax_Block_Checkout_Shipping extends Mage_Checkout_Block_Total_Default
{
//... another code ...
/**
* Get shipping amount exclude tax
*
* @return float
*/
public function getShippingExcludeTax()
{
//return zero
return $this->getTotal()->getAddress()->getShippingAmount();
}
//... another code ...
}
Here is the code that not return zero
class Mage_Checkout_Block_Onepage_Progress extends Mage_Checkout_Block_Onepage_Abstract
{
//... another code ...
public function getShippingPriceExclTax()
{
return $this->formatPrice($this->getQuote()->getShippingAddress()->getShippingAmount());
}
//... another code ...
}
Basically, my custom shipping is fetching price from table of city name and price field.
It use country_id, region_code, and city name from customer order to get price.
Here are the code of my custom shipping carrier
class Nirsoft_CityPrice_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
protected $_code = 'nirsoft_cityprice';
private $destination_city;
private $region;
private $country;
private $countryName;
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$result = Mage::getModel('shipping/rate_result');
/* @var $result Mage_Shipping_Model_Rate_Result */
$this->destination_city = $request->getDestCity();
$this->region = $request->getDestRegionId();
$this->country = $request->getDestCountryId();
$countryModel = Mage::getModel('directory/country')->loadByCode($this->country);
$this->countryName = $countryModel->getName();
$result->append($this->_calculateRate());
if ($request->getFreeShipping()) {
/**
* If the request has the free shipping flag,
* append a free shipping rate to the result.
*/
$freeShippingRate = $this->_getFreeShippingRate();
$result->append($freeShippingRate);
}
return $result;
}
protected function _calculateRate()
{
//get price from database
$cityprice = Mage::getModel('nirsoft_cityprice/city')->getCollection();
$cityprice->addFieldToFilter('country_id', array('eq' => $this->country))
->addFieldToFilter('region_id', array('eq' => $this->region))
->addFieldToFilter('name', array('eq' => ucwords($this->destination_city)));
$city = $cityprice->getFirstItem();
$price = $city->getPrice();
if (!empty($price)) {
if ($price > 0) {
$rate = Mage::getModel('shipping/rate_result_method');
/* @var $rate Mage_Shipping_Model_Rate_Result_Method */
$rate->setCarrier($this->_code);
$rate->setMethod('indonesia_shipping');
if (Mage::app()->getLocale()->getLocaleCode() == 'ID' ) {
$rate->setCarrierTitle('Pengiriman '.$this->countryName);
$rate->setMethodTitle('Pengiriman '.$this->countryName);
} else {
$rate->setCarrierTitle($this->countryName.' Shipping');
$rate->setMethodTitle($this->countryName.' Shipping');
}
$rate->setPrice($price);
$rate->setCost(0);
return $rate;
} else {
return $this->_getFreeShippingRate();
}
} else {
return $this->_calculateRateNotListed();
}
}
protected function _calculateRateNotListed()
{
$rate = Mage::getModel('shipping/rate_result_method');
/* @var $rate Mage_Shipping_Model_Rate_Result_Method */
$rate->setCarrier($this->_code);
$rate->setMethod('indonesia_shipping');
$rate->setCarrierTitle("Shipping Not Listed");
if (Mage::app()->getLocale()->getLocaleCode() == 'ID' ) {
$rate->setMethodTitle($this->getConfigData('message_checkout'));
} else {
$rate->setMethodTitle($this->getConfigData('message_eng_checkout'));
}
// $rate->setPrice(0);
return $rate;
}
protected function _getFreeShippingRate()
{
$rate = Mage::getModel('shipping/rate_result_method');
/* @var $rate Mage_Shipping_Model_Rate_Result_Method */
$rate->setCarrier($this->_code);
$rate->setCarrierTitle(Mage::helper('nirsoft_cityprice')->__('Free Shipping'));
$rate->setMethod('free_shipping');
$rate->setMethodTitle(Mage::helper('nirsoft_cityprice')->__('Free Shipping for ').$this->destination_city);
$rate->setPrice(0);
$rate->setCost(0);
return $rate;
}
public function getAllowedMethods()
{
if (Mage::app()->getLocale()->getLocaleCode() == 'ID' ) {
$shipMethod = 'Pengiriman Indonesia';
} else {
$shipMethod = $this->countryName.' Shipping';
}
return array(
'free_shipping' => 'Free Shipping',
'indonesia_shipping' => $shipMethod
);
}
public function isTrackingAvailable()
{
return true;
}
}