如何在最低订单金额magento中包含税

时间:2014-10-17 12:54:28

标签: magento

在法国电子商务中,我们总是显示包含税的价格。

我已启用最低订单金额。

我测试过它,它可以工作,但系统是基于不包含税的小计。 我需要基于此案例的系统全球金额(含税) 有可能吗?

当然,我尝试使用不含税的最低金额,但我管理两个税率。所以它不可能是好的。

感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

有可能:

  1. 将文件app/code/core/Mage/Sales/Model/Quote.php复制到app/code/local/Mage/Sales/Model/Quote.php

  2. 打开复制的文件并找到validateMinimumAmount()函数:

    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. 将此功能替换为下一个:

    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. 清除Magento缓存(System->Configuration->Cache Management)。

  5. 在新函数中,我们使用许多collectTotals()调用来确定Grand Total已经计算了什么但不担心计算开销,因为collectTotals()函数包含对双重总计计算的保护:

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

答案 1 :(得分:0)

重写模型Mage_Sales_Model_Quote_Address并覆盖方法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;
    }

}

有趣的是,$this->getBaseSubtotalInclTax()不起作用。它有时是null - 具体来说,如果您从购物车进入结帐页面。因此,我们自己计算包含税的小计。我希望我的公式是正确的,但似乎有效:

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