Day: April 22, 2011

  • Change Magento configurable product to take associated products tax class

    Where and how to change the code?

    At first, I thought overriding Mage_Catalog_Model_Product_Type_Configurable::getOrderOptions().
    Original code

    $options['product_calculations'] = self::CALCULATE_PARENT;
    

    change to

    $options['product_calculations'] = self::CALCULATE_CHILD;
    

    However, it does not work.

    Then I tried to observe the event tax_rate_data_fetch and modify the rateRequest object. But inside rateRequest there is no reference to quoteItem. Only product tax_class_id is there. In the observer class, I do not know when to modify it without reference to quoteItem.

    At last, I had to modify the code in class Mage_Tax_Model_Sales_Total_Quote_Tax. There are several places to change depends on System Configuration. Change where is appropriate.
    Original code

    $taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId());
    

    change to

    if ($item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
    	$child = current($item->getChildren());
    	$taxRateRequest->setProductClassId($child->getProduct()->getTaxClassId());
    }
    else {
    	$taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId());
    }
    

    It is not a neat approach. Let me know if you have a better idea.