3

on a french ecommerce, we always display prices including taxes.

I have enabled the minimum order amount.

I've test it, it works but the system is based on subtotal excluding taxes. I need the system based for the this case on global amount (including taxes) Is it possible ?

Of course I tried to work with a minimum amount excluding taxes, but I manage two tax rates. So It can't be good.

Thanks for your help.

2 Answers 2

3

It's possible:

  1. Copy file app/code/core/Mage/Sales/Model/Quote.php to app/code/local/Mage/Sales/Model/Quote.php

  2. Open copied file and find validateMinimumAmount() function:

    public function validateMinimumAmount($multishipping = false) {
    
    $storeId = $this->getStoreId();
    
    $minOrderActive = Mage::getStoreConfigFlag('sales/minimum_order/active', $storeId);
    
    $minOrderMulti  = Mage::getStoreConfigFlag('sales/minimum_order/multi_address', $storeId);
    
    $minAmount  = Mage::getStoreConfig('sales/minimum_order/amount', $storeId);
    
    
    if (!$minOrderActive) {
        return true;
    }
    
    $addresses = $this->getAllAddresses();
    
    if ($multishipping) {
        if ($minOrderMulti) {
            foreach ($addresses as $address) {
                foreach ($address->getQuote()->getItemsCollection() as $item) {
                    $amount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount();
                    if ($amount < $minAmount) {
                        return false;
                    }
                }
            }
        } else {
            $baseTotal = 0;
            foreach ($addresses as $address) {
                /* @var $address Mage_Sales_Model_Quote_Address */
                $baseTotal += $address->getBaseSubtotalWithDiscount();
            }
            if ($baseTotal < $minAmount) {
                return false;
            }
        }
    } else {
        foreach ($addresses as $address) {
            /* @var $address Mage_Sales_Model_Quote_Address */
            if (!$address->validateMinimumAmount()) {
                return false;
            }
        }
    }
    return true;
    

    }

  3. Replace this function with next:

    public function validateMinimumAmount($multishipping = false)
    {
    
        $storeId = $this->getStoreId();
    
        $minOrderActive = Mage::getStoreConfigFlag('sales/minimum_order/active', $storeId);
    
        $minOrderMulti  = Mage::getStoreConfigFlag('sales/minimum_order/multi_address', $storeId);
    
        $minAmount      = Mage::getStoreConfig('sales/minimum_order/amount', $storeId);
    
    
    if (!$minOrderActive) {
        return true;
    }
    
    $addresses = $this->getAllAddresses();
    
    if ($multishipping) {
        if ($minOrderMulti) {
            foreach ($addresses as $address) {
                $grandTotal = $address->getQuote()->collectTotals()->getGrandTotal();
                if ($grandTotal < $minAmount) {
                    return false;
                }
            }
        } else {
            $grandTotal = 0;
            foreach ($addresses as $address) {
                /* @var $address Mage_Sales_Model_Quote_Address */
                $grandTotal += $address->getQuote()->collectTotals()->getGrandTotal();
            }
            if ($grandTotal < $minAmount) {
                return false;
            }
        }
    } else {
        foreach ($addresses as $address) {
            /* @var $address Mage_Sales_Model_Quote_Address */
            $grandTotal = $address->getQuote()->collectTotals()->getGrandTotal();
            if ($grandTotal < $minAmount) {
                return false;
            }
        }
    }
    return true;
    }
    
  4. Clear Magento Cache (System->Configuration->Cache Management).

In new function we use many collectTotals() calls for be sure what Grand Total already calculated but don't worry about calculations overhead because collectTotals() function contains protect from double totals calculation:

if ($this->getTotalsCollectedFlag()) {
    return $this;
}
1
  • This solution seems to bring problems with PayPal. "Quote totals must be collected before this operation".
    – Webninja
    Aug 18, 2016 at 6:03
0

Rewrite the model Mage_Sales_Model_Quote_Address and override the method validateMinimumAmount:

<?php

class StackExchange_MinimumOrderValue_Model_Quote_Address extends Mage_Sales_Model_Quote_Address
{

    /**
     * Validate minimum amount
     *
     * @return bool
     */
    public function validateMinimumAmount()
    {
        $storeId = $this->getQuote()->getStoreId();
        if (!Mage::getStoreConfigFlag('sales/minimum_order/active', $storeId)) {
            return true;
        }

        if ($this->getQuote()->getIsVirtual() && $this->getAddressType() == self::TYPE_SHIPPING) {
            return true;
        } elseif (!$this->getQuote()->getIsVirtual() && $this->getAddressType() != self::TYPE_SHIPPING) {
            return true;
        }

        $amount = Mage::getStoreConfig('sales/minimum_order/amount', $storeId);
        // $this->getBaseSubtotalInclTax() is sometimes null, so that we calculate it ourselves
        $referenceAmount = $this->getBaseSubtotal() + $this->getBaseTaxAmount() + $this->getBaseHiddenTaxAmount() - $this->getBaseShippingTaxAmount() - abs($this->getBaseDiscountAmount());
        if ($referenceAmount < $amount) {
            return false;
        }
        return true;
    }

}

The interesting thing is that $this->getBaseSubtotalInclTax() does not work. It is sometimes null - specifically, if you proceed from the cart to the checkout page. Hence, we calculate the subtotal inclusive tax ourselves. I hope my formula is correct, but it seems to work:

$referenceAmount = $this->getBaseSubtotal() + $this->getBaseTaxAmount() + $this->getBaseHiddenTaxAmount() - $this->getBaseShippingTaxAmount() - abs($this->getBaseDiscountAmount());

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.