0

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: Zero shipping price

The shipping in the right sidebar is displaying correct value. How to make shipping value in Order Review not zero?

Maybe global static code to only return shipping Order price (by passing tax calculation) since the requirement is outputting shipping price without tax.

Any help or lead is highly appreciated. Thank you.


Additional Detail:

Magento version 1.7.0.2

Here are Tax Configuration:

  • Tax Class Shipping = None
  • Shipping price = Excluding tax
  • Display shipping price = Excuding Tax
  • Display shipping amount = Excluding tax
  • Include Tax in Grand Total, Full Tax Summary, Zero Tax Subtotal = No

After tracing the code, function Mage_Tax_Block_Checkout_Shipping::getShippingExcludeTax() is responsible for zero price (tested by return constant value that not zero).

The shipping price in right side bar that returning right value is using Mage_Checkout_Block_Onepage_Progress::getShippingPriceExclTax() (tested by return constant value).

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 12345, front end shipping order review display 12345
        return $this->getTotal()->getAddress()->getShippingAmount();
    }
//... another code ...
}

Here is the code that not return zero shipment price

class Mage_Checkout_Block_Onepage_Progress extends Mage_Checkout_Block_Onepage_Abstract
{
//... another code ...
    public function getShippingPriceExclTax()
    {
        //return 12345, right sidebar display 12345
        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;
    }
}
3
  • 1
    Have you installed 3rd party extensions related to tax, checkout, shipping or payment. Try to disable local modules. And also try to use default Magento theme.
    – mageUz
    Commented Feb 13, 2015 at 17:36
  • Thank you for your lead. I tested checkout process using default Magento theme using default magento shipping method (Flat Rate - Fixed). But it still returning zero. After more investigation, the developer before me is editing some of magento core class. I think I need to compare the edited one with the original one :(
    – nirleka
    Commented Feb 14, 2015 at 8:12
  • There are no 3rd party extension related to tax, checkout, or payment. Only custom extension that I code related to payment that I describe in my question.
    – nirleka
    Commented Feb 14, 2015 at 8:13

1 Answer 1

2

When order review is called it will go get the shipping rates again and then ensure that the shipping method on sales_flat_quote_address matches one of the rates returned from this. It sounds to me like this is going wrong.

Suggest go look at Mage_Sales_Model_Quote_Address::requestShippingRates() and debug this to see how its setting the shipping in here. Also look at Mage_Sales_Model_Quote_Address_Total_Shipping::collect(), this will lead you to answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.