根据折扣/优惠券代码在 Magento 中设置税率

发布于 2024-10-11 20:27:06 字数 120 浏览 1 评论 0原文

我一直在尝试根据使用的折扣代码为 magento 设置税率或客户等级税率。我只使用折扣代码,因为我可以使用它作为输入。

有谁知道如何实现这一点或有任何指示吗?

亲切的问候

克里斯

I've been trying to set a tax rate or customer class rate for magento based on the discount code used. Im only using the discount code as I can use it for a input.

Does anyone have any idea how this can achieved or any pointers?

Kind Regards

Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千笙结 2024-10-18 20:27:06

没有默认的方法可以做到这一点。您应该通过管理员为他们设置客户的类别,这样他们就可以始终获得特定的税率,而无需输入任何内容。

There is no default way of doing this. You should set the customer's class for them through admin, that way they get their specific tax rate always without having to input anything.

み格子的夏天 2024-10-18 20:27:06

这就是我最终为此所做的。应该证明非常有用。将此文件 app/code/core/Mage/Tax/Model/Calculation.php 复制到 app/code/local/Mage/Tax/Model/Calculation.php 然后在第 178 行有这个函数,

 public function getRate($request)
    {
        if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
            return 0;
        }

    $cacheKey = $this->_getRequestCacheKey($request);
    if (!isset($this->_rateCache[$cacheKey])) {
        $this->unsRateValue();
        $this->unsCalculationProcess();
        $this->unsEventModuleId();
        Mage::dispatchEvent('tax_rate_data_fetch', array('request'=>$request));
        if (!$this->hasRateValue()) {
            $rateInfo = $this->_getResource()->getRateInfo($request);
            $this->setCalculationProcess($rateInfo['process']);
            $this->setRateValue($rateInfo['value']);
        } else {
            $this->setCalculationProcess($this->_formCalculationProcess());
        }
        $this->_rateCache[$cacheKey] = $this->getRateValue();
        $this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
    }
    return $this->_rateCache[$cacheKey];
}

我已将其更改为此。根据我对此项目的要求,它是一个硬编码的折扣代码和产品税类别 ID。

public function getRate($request)
    {
        if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
            return 0;
        }

    $cacheKey = $this->_getRequestCacheKey($request);
    if (!isset($this->_rateCache[$cacheKey])) {
        $this->unsRateValue();
        $this->unsCalculationProcess();
        $this->unsEventModuleId();
        Mage::dispatchEvent('tax_rate_data_fetch', array('request'=>$request));
        if (!$this->hasRateValue()) {
            $rateInfo = $this->_getResource()->getRateInfo($request);
            $this->setCalculationProcess($rateInfo['process']);
            $thisDiscountCode = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
            $thisProductClassCode = $request->getProductClassId();
            if($thisDiscountCode == "0000" && $thisProductClassCode == "5"):
            $this->setRateValue(0);
            else:    
            $this->setRateValue($rateInfo['value']);
            endif;            
        } else {
            $this->setCalculationProcess($this->_formCalculationProcess());
        }
        $this->_rateCache[$cacheKey] = $this->getRateValue();
        $this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
    }
    return $this->_rateCache[$cacheKey];
}

干杯对此的帮助

This is what I ended up doing for this. Should prove quite useful. Copy this file app/code/core/Mage/Tax/Model/Calculation.php to app/code/local/Mage/Tax/Model/Calculation.php then on line 178 theres this function

 public function getRate($request)
    {
        if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
            return 0;
        }

    $cacheKey = $this->_getRequestCacheKey($request);
    if (!isset($this->_rateCache[$cacheKey])) {
        $this->unsRateValue();
        $this->unsCalculationProcess();
        $this->unsEventModuleId();
        Mage::dispatchEvent('tax_rate_data_fetch', array('request'=>$request));
        if (!$this->hasRateValue()) {
            $rateInfo = $this->_getResource()->getRateInfo($request);
            $this->setCalculationProcess($rateInfo['process']);
            $this->setRateValue($rateInfo['value']);
        } else {
            $this->setCalculationProcess($this->_formCalculationProcess());
        }
        $this->_rateCache[$cacheKey] = $this->getRateValue();
        $this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
    }
    return $this->_rateCache[$cacheKey];
}

I've changed this to this. Its a hardcoded Discount Code and Product Tax Class Id based on my requirements for this project.

public function getRate($request)
    {
        if (!$request->getCountryId() || !$request->getCustomerClassId() || !$request->getProductClassId()) {
            return 0;
        }

    $cacheKey = $this->_getRequestCacheKey($request);
    if (!isset($this->_rateCache[$cacheKey])) {
        $this->unsRateValue();
        $this->unsCalculationProcess();
        $this->unsEventModuleId();
        Mage::dispatchEvent('tax_rate_data_fetch', array('request'=>$request));
        if (!$this->hasRateValue()) {
            $rateInfo = $this->_getResource()->getRateInfo($request);
            $this->setCalculationProcess($rateInfo['process']);
            $thisDiscountCode = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
            $thisProductClassCode = $request->getProductClassId();
            if($thisDiscountCode == "0000" && $thisProductClassCode == "5"):
            $this->setRateValue(0);
            else:    
            $this->setRateValue($rateInfo['value']);
            endif;            
        } else {
            $this->setCalculationProcess($this->_formCalculationProcess());
        }
        $this->_rateCache[$cacheKey] = $this->getRateValue();
        $this->_rateCalculationProcess[$cacheKey] = $this->getCalculationProcess();
    }
    return $this->_rateCache[$cacheKey];
}

Cheers for the help on this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文