开发者

Set Tax Rate in Magento based on Discount / Coupon Code

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

开发者_StackOverflow

Chris


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜