How to include tax in the magento minimum order

on French e-commerce, we always show prices including taxes.

I have included a minimum order amount.

I tested it, it works, but the system is based on subtotals, excluding taxes. I need a system based on this case for a global amount (including taxes) Is this possible?

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

Thank you for your help.

+3


source to share


2 answers


Maybe:

  • Copy file app/code/core/Mage/Sales/Model/Quote.php

    toapp/code/local/Mage/Sales/Model/Quote.php

  • Open the copied file and find the validitMinimumAmount () 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;
    
          

    }

  • Replace this function with the following:

    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;
    }
    
          

  • Clear Magento Cache ( System->Configuration->Cache Management

    ).



In the new function, we use many calls to collectTotals () to make sure the Grand Total has already been calculated, but not to worry about the computation cost, because the collectTotals () function contains protection against calculating double totals:

if ($this->getTotalsCollectedFlag()) {
    return $this;
}

      

+2


source


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;
    }

}

      



I wonder what $this->getBaseSubtotalInclTax()

doesn't work. Sometimes null

- in particular, if you go from shopping cart to checkout page. Therefore, we ourselves calculate the subtotal inclusive tax. I hope my formula is correct, but it seems to work:

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

      

0


source







All Articles