Question

I would like to show price without taxes in the catalog for B2B customers but calculate with taxes as normally.

I know this can be done with a second store view but is this possible without a second view?

Was it helpful?

Solution

Even if it's an answer accepted question i want to give some additional advice:

As i haven't created an observer but cloned app/code/core/Mage/Tax/Model/Config.php to local, i've changed the getPriceDisplayType function with some additionals.

The accepted answer checks for the group id only. I gone further and check for the TaxClassId. It's hardcoded by now but could be done via a config setting too in the backend, when wrapped into an observer or extension.

My modified functions looks like

public function getPriceDisplayType($store = null)
{
    $customerGroupId = Mage::getModel('customer/customer')->getGroupId();
    $customerGroup = Mage::getModel('customer/group')->load($customerGroupId);
    $customerTaxId = $customerGroup->getTaxClassId($customerGroupId);

    if ($customerTaxId == 5) {
        $this->changeConfigTemp('tax/cart_display/price', '1');
        $this->changeConfigTemp('tax/cart_display/subtotal', '1');
        $this->changeConfigTemp('tax/display/type', '1');
        $this->changeConfigTemp('tax/sales_display/price', '1');
        $this->changeConfigTemp('tax/sales_display/subtotal', '1');
        $this->changeConfigTemp('tax/display/show_in_catalog', '1');
    } else {
        return (int)$this->_getStoreConfig(self::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE, $store);
    }
}

This has done all i needed and i haven't had an display or logical "error" till now.

The settings are a little bit 'german like' as grandtotals are displayed including tax while other values are w/o tax. Hope this helps others too.

OTHER TIPS

Go to System> Configuration > Tax and there, look for the last tab “Display”. In “Display Product Prices” chooses “Including and excluding tax” and then Save config.

Based on https://github.com/astorm/Chaos I created an observer that does change the config value of tax/calculation/price_includes_tax to temporary show prices without tax depending on page and user group.

This is short on comments but it might help someone:

class YourThing_TaxChanger_Model_Observer
{
    static protected $_hasRun = false;

    public function setup($observer)
    {
        if($this->_shouldBail($observer))
        {
            return;
        }

        $roleId = Mage::getSingleton('customer/session')->getCustomerGroupId();
        //echo Mage::getSingleton('customer/group')->load($roleId)->getData('customer_group_code');
        $page = Mage::app()->getFrontController()->getRequest()->getControllerName();

        // check user group and page
        if ($roleId == 2 && (in_array($page, array('product', 'category', 'result'))))
        {
            // show price without tax
            $this->changeConfigTemp('tax/calculation/price_includes_tax', '1');
            // germansetup tax info
            //$this->changeConfigTemp('tax/sales_display/price', Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX);
        }
    }

    /**
     * Change a config value without saving it.
     */
    protected function changeConfigTemp($path, $value)
    {
        $config = Mage::getConfig();
        $store = Mage::app()->getStore();
        $code  = $store->getCode();
        $config->setNode("stores/$code/" . $path, $value);
    }

    protected function _shouldBail($observer)
    {
        $config = Mage::getConfig();
        if(!$config)
        {
            return true;
        }
        if(Mage::app()->getStore()->isAdmin())
        {
            return true;
        }

        return false;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top