2012-06-23 46 views
0

我需要根据产品的数量增量显示(层级)价格。例如。一个简单的产品,正常的价格为50美分,不含税和20的数量增量应该在产品视图上显示,“每20美元10美元”。以数量增量和税金显示(层级)价格

没有使用税款,这应该很容易。但是似乎没有“默认”帮手或模型可以使用赋税和不同的计算算法(例如Mage_Tax_Model_Calculation::CALC_UNIT_BASE);期望报价在Mage_Tax_Model_Sales_Total_Quote_TaxMage_Tax_Model_Sales_Total_Quote_Subtotal

我是否错过了这里的东西,还是我必须编写业务逻辑来自己计算价格?我如何最好地封装它?

回答

0

我现在解决了我的问题非常简单。为此,我使用的<rewrite>元件的自定义模块中与另外的实例方法扩大辅助Mage_Tax_Helper_Data

class My_Module_Helper_Tax_Data extends Mage_Tax_Helper_Data { 

    /** 
    * Get product price based on stock quantity increments 
    * 
    * @param Mage_Catalog_Model_Product $product 
    * @param float $price inputed product price 
    * @param null|int $qtyIncrements inputed stock quantity increments 
    * @param null|bool $includingTax return price include tax flag 
    * @param null|Mage_Customer_Model_Address $shippingAddress 
    * @param null|Mage_Customer_Model_Address $billingAddress 
    * @param null|int $customerTaxClass customer tax class 
    * @param mixed $store 
    * @param bool $priceIncludesTax flag what price parameter contain tax 
    * @return float 
    */ 
    public function getQtyIncrementsPrice($product, $price, $qtyIncrements = 1, 
     $includingTax = null, $shippingAddress = null, $billingAddress = null, 
     $customerTaxClass = null, $store = null, $priceIncludesTax = null) { 

     $store = Mage::app()->getStore($store); 
     $qtyIncrements *= 1; 

     if ($this->_config->getAlgorithm($store) 
      == Mage_Tax_Model_Calculation::CALC_UNIT_BASE) { 
      $price = $this->getPrice(
       $product, $price, $includingTax, $shippingAddress, 
       $billingAddress, $customerTaxClass, $store, $priceIncludesTax 
      ); 
      $price *= $qtyIncrements; 
      $price = $store->roundPrice($price); 
     } else { 
      $price *= $qtyIncrements; 
      $price = $this->getPrice(
       $product, $price, $includingTax, $shippingAddress, 
       $billingAddress, $customerTaxClass, $store, $priceIncludesTax 
      ); 
     } 

     return $price; 
    } 
} 

它可以在方法如Mage_Catalog_Block_Product_Price::getTierPrices()定制重写以后使用。