1

I recently updated my Magento (Community) installation from version 1.9.3.0 to 1.9.3.2, a minor update with little consequences to the site's functionality, so I thought.

However something I forgot testing before deploying this update on the production server as well is the free shipping.

Now the free shipping is not working correctly, there should be free shipping at 59.95 euros (including taxes), but the free shipping only kicks in at a much higher amount. (Not quite sure which one)

I already created this file /app/code/local/Mage/Shipping/Model/Carrier/Freeshipping.php with the following content.

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage_Shipping
 * @copyright  Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * Free shipping model
 *
 * @category   Mage
 * @package    Mage_Shipping
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Shipping_Model_Carrier_Freeshipping
    extends Mage_Shipping_Model_Carrier_Abstract
    implements Mage_Shipping_Model_Carrier_Interface
{

    /**
     * Carrier's code
     *
     * @var string
     */
    protected $_code = 'freeshipping';

    /**
     * Whether this carrier has fixed rates calculation
     *
     * @var bool
     */
    protected $_isFixed = true;

    /**
     * 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 (!$this->getConfigFlag('active')) {
            return false;
        }

        $result = Mage::getModel('shipping/rate_result');

        $this->_updateFreeMethodQuote($request);
        $totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
        $subtotal = $totals["subtotal"]->getValue();

        if (($request->getFreeShipping())
            || ($subtotal >= $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;
    }

    /**
     * Allows free shipping when all product items have free shipping (promotions etc.)
     *
     * @param Mage_Shipping_Model_Rate_Request $request
     * @return void
     */
    protected function _updateFreeMethodQuote($request)
    {
        $freeShipping = false;
        $items = $request->getAllItems();
        $c = count($items);
        for ($i = 0; $i < $c; $i++) {
            if ($items[$i]->getProduct() instanceof Mage_Catalog_Model_Product) {
                if ($items[$i]->getFreeShipping()) {
                    $freeShipping = true;
                } else {
                    return;
                }
            }
        }
        if ($freeShipping) {
            $request->setFreeShipping(true);
        }
    }

    /**
     * Get allowed shipping methods
     *
     * @return array
     */
    public function getAllowedMethods()
    {
        return array('freeshipping' => $this->getConfigData('name'));
    }

}

But with no success yet.

However when I print out this value $totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals(); $subtotal = $totals["subtotal"]->getValue();

It gives the correct value of the shopping cart.

We use onestepcheckout, which makes debugging impossible with it's AJAX calls.

Should I perhaps look at the /app/code/core/Mage/SalesRule/etc/config.xml?

It mentions the following:

<sales>
            <quote>
                <totals>
                    <freeshipping>
                        <class>salesrule/quote_freeshipping</class>
                        <after>subtotal,tax_subtotal</after>
                        <before>shipping</before>
                    </freeshipping>
                    <discount>
                        <class>salesrule/quote_discount</class>
                        <after>subtotal,shipping</after>
                        <before>grand_total</before>
                    </discount>
                </totals>
                <nominal_totals>
                    <nominal_discount>
                        <class>salesrule/quote_nominal_discount</class>
                        <sort_order>550</sort_order>
                    </nominal_discount>
                </nominal_totals>
            </quote>
        </sales>

I tried changing it to

<freeshipping>
                            <class>salesrule/quote_freeshipping</class>
                            <after>subtotal</after>
                            <before>tax_subtotal,shipping</before>
                        </freeshipping>

But still the free shipping is not being awarded at the correct subtotal amount.

Even after performing the sacred ritual of rebuilding indices, cleaning cache and sacrificing the blood of a virgin the Magento God still remains silent.

Edit: Seems that the difference is the tax. However when I print the subtotal in shopping cart it shows the correct amount. Could is be that Magento assumes the treshhold I set for free shipping is excluding tax?

When I try the following calculation I found

$totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
$rate = Mage::helper('checkout/cart')->getQuote()->getData('base_to_quote_rate');
$subtotalIncTax = $totals["subtotal"]->getValue()/$rate;

I just get the correct 59.95 for the subtotal (when I buy a product of 59.95 incl tax) and rate 1. So this doesn't solve it either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.