magento2: Why doesn't shipping total segment respect tax settings like e.g. subtotal does?

Preconditions

  1. 2.1.9

Steps to reproduce

  1. Choose “Including Tax” setting for Display Shipping Prices and Display Shipping Amount.
  2. Create a (guest) cart
  3. Call /rest/V1/guest-carts/<the_id_here>/totals-information for the cart

Expected result

  1. The value property for shipping segment in responseData.total_segments includes the tax.

Actual result

  1. The value property of shipping segment in responseData.total_segments excludes the tax.
  2. Below is a screenshot of /checkout/cart page and the totals-information response.
screen shot 2018-01-26 at 16 52 31

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Created this patch, use with precaution however as this is only tested with Including tax config settings…

--- a/vendor/magento/module-tax/Model/Sales/Total/Quote/Shipping.php	2020-10-28 10:15:59.000000000 +0200
+++ b/vendor/magento/module-tax/Model/Sales/Total/Quote/Shipping.php	2020-10-28 10:16:44.000000000 +0200
@@ -72,12 +72,22 @@
      */
     public function fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)
     {
-        if ($total->getShippingInclTax()) {
+        if (!$total->getShippingInclTax()) {
+            return null;
+        }
+
+        if ($this->_config->displayCartShippingBoth() || $this->_config->displayCartShippingInclTax()) {
             return [
                 'code' => 'shipping',
-                'shipping_incl_tax' => $total->getShippingInclTax()
+                'shipping_incl_tax' => $total->getShippingInclTax(),
+                'value' => $total->getShippingInclTax(),
+                'value_incl_tax' => $total->getShippingInclTax()
             ];
         }
-        return null;
+
+        return [
+            'code' => 'shipping',
+            'shipping_incl_tax' => $total->getShippingInclTax()
+        ];
     }
 }

For subtotal there seems to be own logic inside: \Magento\Tax\Model\Sales\Total\Quote\Tax::fetch line 341

        /**
         * Modify subtotal
         */
        if ($this->_config->displayCartSubtotalBoth($store) || $this->_config->displayCartSubtotalInclTax($store)) {
            if ($total->getSubtotalInclTax() > 0) {
                $subtotalInclTax = $total->getSubtotalInclTax();
            } else {
                $subtotalInclTax = $total->getSubtotal() + $taxAmount - $total->getShippingTaxAmount();
            }

            $totals[] = [
                'code' => 'subtotal',
                'title' => __('Subtotal'),
                'value' => $subtotalInclTax,
                'value_incl_tax' => $subtotalInclTax,
                'value_excl_tax' => $total->getSubtotal(),
            ];
        }

This logic however is missing for shipping reader

Hello All

I am not able to reproduce this issue on the 2.4-develop branch by provided steps.

Testing scenario:

  1. Choose “Including Tax” setting for Display Shipping Prices and Display Shipping Amount.
  2. Create a (guest) cart
  3. Call /rest/V1/guest-carts/<the_id_here>/totals-information for the cart

Result The value property for shipping segment in responseData.total_segments includes the tax. Screenshot_9 So I have to close this issue. Thanks for your report!