0

Is there anyway to display price with and without vAT in cart summary bloxk in cart page please

1 Answer 1

0

Total Price

Total Solution 1 (affects Checkout)

You can show the total in the cart in the summary block with and without tax using the store configuration.

The section that you want to adjust is Stores -> Configuration -> Sales -> Tax -> Shopping Cart Display Settings

There you can set Include Tax In Order Total to Yes.

enter image description here

Note: This will also show the total in the checkout summary with including and excluding tax.

Solution 2 (Cart Summary only)

Showing the total incl. and exl. tax in the cart only is a bit more complex and requires some customization.

First create a module (if not already done) for your logic. In that module you can write a plugin for \Magento\Tax\Model\Config that will simulate that tax/cart_display/subtotal has been set to Including and Excluding Tax for the cart only.

app/code/Vendor/CartBothTaxes/Plugin/ShowBothSubtotalsInCart.php:

<?php
declare(strict_types=1);

namespace Vendor\CartBothTaxes\Plugin;

use Magento\Framework\App\Request\Http;
use Magento\Tax\Model\Config;

class ShowBothSubtotalsInCart
{
    /**
     * Name of the controller for the cart
     */
    private const CONTROLLER_CART = 'cart';

    /**
     * @var Http
     */
    private Http $request;

    /**
     * ShowBothSubtotalsInCart constructor
     *
     * @param Http $request
     */
    public function __construct(Http $request)
    {
        $this->request = $request;
    }

    /**
     * When current controller is cart, always display both subtotals (incl. and exl. tax)
     *
     * @param Config $subject
     * @param bool $result
     * @param $storeId
     * @return bool
     */
    public function afterDisplayCartTaxWithGrandTotal(Config $subject, bool $result, $storeId = null): bool
    {
        // Condition could also be $this->request->getFullActionName() === 'checkout_cart_index'
        if ($this->request->getControllerName() === self::CONTROLLER_CART) {
            return true;
        }

        return $result;
    }
}

app/code/Vendor/CartBothTaxes/etc/frontend/di.xml:

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Tax\Model\Config">
        <plugin name="show_both_subtotals_in_cart" type="\Vendor\CartBothTaxes\Plugin\ShowBothSubtotalsInCart"/>
    </type>
</config>

This should cause the total to be displayed incl. and excl. tax only on cart related pages. Note that you should disable Stores -> Configuration -> Sales -> Tax -> Shopping Cart Display Settings -> Include Tax In Order Summary to only show both totals in the cart and not in the checkout.

Subtotal

Subtotal Solution 1 (affects Checkout Summary)

You can show the prices in the cart and the subtotal in the summary block with and without tax using the store configuration.

The section that you want to adjust is Stores -> Configuration -> Sales -> Tax -> Shopping Cart Display Settings -> Display Subtotal

There you can set Display Subtotal to Including and Excluding Tax. Display Subtotal tax configuration Note: This will also show the subtotal in the checkout summary with including and excluding tax.

Subtotal Solution 2 (Cart Summary only)

Showing the subtotal incl. and exl. tax in the cart only is a bit more complex and requires some customization.

First create a module (if not already done) for your logic. In that module you can write a plugin for \Magento\Tax\Model\Config that will simulate that tax/cart_display/subtotal has been set to Including and Excluding Tax for the cart only.

app/code/Vendor/CartBothTaxes/Plugin/ShowBothSubtotalsInCart.php:

<?php
declare(strict_types=1);

namespace Vendor\CartBothTaxes\Plugin;

use Magento\Framework\App\Request\Http;
use Magento\Tax\Model\Config;

class ShowBothSubtotalsInCart
{
    /**
     * Name of the controller for the cart
     */
    private const CONTROLLER_CART = 'cart';

    /**
     * @var Http
     */
    private Http $request;

    /**
     * ShowBothSubtotalsInCart constructor
     *
     * @param Http $request
     */
    public function __construct(Http $request)
    {
        $this->request = $request;
    }

    /**
     * When current controller is cart, always display both subtotals (incl. and exl. tax)
     *
     * @param Config $subject
     * @param bool $result
     * @param $storeId
     * @return bool
     */
    public function afterDisplayCartSubtotalBoth(Config $subject, bool $result, $storeId = null): bool
    {
        // Condition could also be $this->request->getFullActionName() === 'checkout_cart_index'
        if ($this->request->getControllerName() === self::CONTROLLER_CART) {
            return true;
        }

        return $result;
    }
}

app/code/Vendor/CartBothTaxes/etc/frontend/di.xml:

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Tax\Model\Config">
        <plugin name="show_both_subtotals_in_cart" type="\Vendor\CartBothTaxes\Plugin\ShowBothSubtotalsInCart"/>
    </type>
</config>

This should cause the subtotal to be displayed incl. and excl. tax only on cart related pages. Note that you should disable Including and Excluding Tax in Stores -> Configuration -> Sales -> Tax -> Shopping Cart Display Settings -> Display Subtotal to only show both subtotals in the cart and not in the checkout.

Summary

All values from Stores -> Configuration -> Sales -> Tax -> Shopping Cart Display Settings can be altered for the cart scope with a simple plugin. You can find the functions to create after plugins for example for the shipping price that is not covered in this answer in \Magento\Tax\Model\Config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.