Showing Prices Ex/Inc Tax/VAT Depending on Customer Group in Magento
As an experienced developer, I understand your requirement of displaying prices both including and excluding tax for specific customer groups while keeping the billing process unchanged. This functionality can be achieved without creating a new storefront by making some adjustments to your existing setup.
Understanding the Current Setup
In your current implementation, you have a ‘trade only’ storefront that shows both in-VAT and ex-VAT prices for trade customers. The catalog displays prices including VAT, but the billing process still charges the regular inc-VAT price. You want to extend this functionality to other customer groups without creating separate storefronts.
Challenges and Limitations
Before proceeding with the solution, it’s important to address some potential challenges:
-
Magento’s pricing logic is tightly integrated with tax calculation and cannot be easily overridden for specific customer groups.
-
Modifying the core files directly can lead to compatibility issues with future updates or other extensions.
-
Displaying both in-VAT and ex-VAT prices requires additional information to be stored and displayed accurately.
Proposed Solution
To implement this functionality, we will create a custom module that extends Magento’s tax configuration and price display logic. Here is an outline of the steps involved:
-
Create a new module using the Magento extension builder or by following the official documentation: https://developer.adobe.com/commerce/contributor/guide/magento-core/module-builder/
-
Override the
tax/configfile with your custom tax configuration. This allows you to define custom tax rates and rules specific to certain customer groups. -
Create a new price display type in your module’s
etc/config.xmlfile. For example:
<config>
<global>
<tax>
<price_display_type>
<value>both</value>
<label>Both IN/EX Tax</label>
</price_display_type>
</tax>
</global>
</config>
-
In your module, override the
tax/model/config.phpfile to modify the price display type based on the customer group. -
Add conditional logic in your custom
getPriceDisplayType()function to change the price display type for specific customer groups:
public function getPriceDisplayType($store = null)
{
$customer = Mage::helper('customer')->getCustomer();
if ($customer->getGroupId() > 1) {
return self::DISPLAY_TYPE_BOTH;
} else {
return (int)Mage::getStoreConfig(self::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE, $store);
}
}
- Update your theme’s template files to handle the custom price display labels and formatting for both in-VAT and ex-VAT prices.
Implementation Steps
To implement this solution, follow these steps:
-
Create a new module folder structure under
app/code/local/Mage/Tax/. -
Copy the
tax/model/config.phpfile from the core Magento directory to your new module’s model directory (app/code/local/Mage/Tax/Model/). -
Open the
config.phpfile and update thegetPriceDisplayType()function as shown in step 5 above. -
Save the changes and clear the cache using the command
php bin/magento cache:clean.
Conclusion
By following this approach, you can display prices including and excluding tax for specific customer groups without creating separate storefronts. This solution allows you to maintain a single catalog with customized pricing logic based on the customer’s group.
Remember that modifying core files directly should be avoided whenever possible. Consider using an extension builder or consulting with an experienced Magento developer to ensure the stability and long-term maintainability of your custom implementation.
Don’t forget to explore the extensive resources available at LaravelCompany for more advanced Magento development techniques and best practices.
Let’s connect on LinkedIn to discuss further enhancements or any other Magento-related questions you may have.