diff --git a/src/ViewModel/CheckoutConfigProvider.php b/src/ViewModel/CheckoutConfigProvider.php index 11873d2e..2ba5a40f 100644 --- a/src/ViewModel/CheckoutConfigProvider.php +++ b/src/ViewModel/CheckoutConfigProvider.php @@ -7,6 +7,7 @@ use Magento\Framework\Serialize\SerializerInterface; use Magento\Framework\View\Element\Block\ArgumentInterface; use Magento\Framework\Locale\ResolverInterface as LocaleResolverInterface; +use Hyva\Checkout\ViewModel\CurrencyProvider; class CheckoutConfigProvider implements ArgumentInterface { @@ -74,6 +75,30 @@ public function getConfig(): string 'language' => $this->localeResolver->getLocale(), 'currency' => $this->currencyProvider->getConfig(), 'defaultCountryId' => $checkoutConfig['defaultCountryId'], + // is shipping price ex tax + 'isDisplayShippingPriceExclTax' => + $checkoutConfig['isDisplayShippingPriceExclTax'], + // Display Shipping prices inc and ex tax + 'isDisplayShippingBothPrices' => + $checkoutConfig['isDisplayShippingBothPrices'], + // Shipping Cart Prices display mode inc ex tax or both + 'reviewShippingDisplayMode' => + $checkoutConfig['reviewShippingDisplayMode'], + // Cart Prices display mode inc ex tax or both + 'reviewItemPriceDisplayMode' => + $checkoutConfig['reviewItemPriceDisplayMode'], + // Cart Subtotal Prices display mode inc ex tax or both + 'reviewTotalsDisplayMode' => + $checkoutConfig['reviewTotalsDisplayMode'], + // Grand Total Prices display display tax or not + 'includeTaxInGrandTotal' => + $checkoutConfig['includeTaxInGrandTotal'], + // Show tax details in checkout totals section + 'isFullTaxSummaryDisplayed' => + $checkoutConfig['isFullTaxSummaryDisplayed'], + // Show tax details when its zero + 'isZeroTaxDisplayed' => + $checkoutConfig['isZeroTaxDisplayed'], ]); } } diff --git a/src/reactapp/src/api/cart/fetchGuestCart/modifier.js b/src/reactapp/src/api/cart/fetchGuestCart/modifier.js index fa23ab8c..6ba7a14e 100644 --- a/src/reactapp/src/api/cart/fetchGuestCart/modifier.js +++ b/src/reactapp/src/api/cart/fetchGuestCart/modifier.js @@ -17,6 +17,12 @@ function modifyCartItemsData(cartItems) { const price = formatPrice(priceAmount); const rowTotalAmount = _get(prices, 'row_total.value'); const rowTotal = formatPrice(rowTotalAmount); + const rowTotalAmountIncTax = _get(prices, 'row_total_including_tax.value'); + const priceAmountIncTax = rowTotalAmountIncTax / quantity; + const priceIncTax = formatPrice(priceAmountIncTax); + const rowTotalIncTax = formatPrice(rowTotalAmountIncTax); + const rowTotalDiscountAmount = _get(prices, 'total_item_discount.value'); + const rowTotalDiscount = formatPrice(rowTotalDiscountAmount);; const productId = _get(product, 'id'); const productSku = _get(product, 'sku'); const productName = _get(product, 'name'); @@ -28,8 +34,14 @@ function modifyCartItemsData(cartItems) { quantity, priceAmount, price, + priceAmountIncTax, + priceIncTax, rowTotal, rowTotalAmount, + rowTotalIncTax, + rowTotalAmountIncTax, + rowTotalDiscount, + rowTotalDiscountAmount, productId, productSku, productName, @@ -43,21 +55,33 @@ function modifyCartItemsData(cartItems) { function modifyCartPricesData(cartPrices) { const grandTotal = _get(cartPrices, 'grand_total', {}); - const subTotal = _get(cartPrices, 'subtotal_including_tax', {}); + const subTotalIncTax = _get(cartPrices, 'subtotal_including_tax', {}); + const subTotalExTax = _get(cartPrices, 'subtotal_excluding_tax', {}); const discountPrices = _get(cartPrices, 'discounts', []) || []; const discounts = discountPrices.map(discount => ({ label: discount.label, price: formatPrice(-discount.amount.value, true), amount: discount.amount.value, })); + const appliedTaxes = _get(cartPrices, 'applied_taxes', []) || []; + const taxes = appliedTaxes.map(tax => ({ + label: tax.label, + price: formatPrice(tax.amount.value), + amount: tax.amount.value, + })); const grandTotalAmount = _get(grandTotal, 'value'); - const subTotalAmount = _get(subTotal, 'value'); + const subTotalIncTaxAmount = _get(subTotalIncTax, 'value'); + const subTotalExTaxAmount = _get(subTotalExTax, 'value'); return { discounts, hasDiscounts: !_isArrayEmpty(discountPrices), - subTotal: formatPrice(subTotalAmount), - subTotalAmount, + taxes, + hasTaxes: !_isArrayEmpty(taxes), + subTotalIncTax: formatPrice(subTotalIncTaxAmount), + subTotalExTax: formatPrice(subTotalExTaxAmount), + subTotalIncTaxAmount, + subTotalExTaxAmount, grandTotal: formatPrice(grandTotalAmount), grandTotalAmount, }; diff --git a/src/reactapp/src/api/cart/setShippingAddress/modifier.js b/src/reactapp/src/api/cart/setShippingAddress/modifier.js index 56b92091..f950c641 100644 --- a/src/reactapp/src/api/cart/setShippingAddress/modifier.js +++ b/src/reactapp/src/api/cart/setShippingAddress/modifier.js @@ -40,7 +40,8 @@ export function modifyShippingMethods(addressList) { carrier_title: carrierTitle, method_code: methodCode, method_title: methodTitle, - price_incl_tax: { currency: priceCurrency, value: amount }, + price_incl_tax: { currency: priceCurrencyIncTax, value: amountIncTax }, + price_excl_tax: { currency: priceCurrencyExTax, value: amountExTax }, } = method; const methodId = `${carrierCode}__${methodCode}`; @@ -51,8 +52,10 @@ export function modifyShippingMethods(addressList) { carrierTitle, methodCode, methodTitle, - price: `${_get(config.currencySymbols, priceCurrency, '')}${amount}`, - amount, + priceExTax: `${_get(config.currencySymbols, priceCurrencyExTax, '')}${amountExTax}`, + priceIncTax: `${_get(config.currencySymbols, priceCurrencyIncTax, '')}${amountIncTax}`, + amountExTax, + amountIncTax }; return methodList; diff --git a/src/reactapp/src/api/cart/utility/query/cartItemsInfo.js b/src/reactapp/src/api/cart/utility/query/cartItemsInfo.js index fd2827c8..04b586f4 100644 --- a/src/reactapp/src/api/cart/utility/query/cartItemsInfo.js +++ b/src/reactapp/src/api/cart/utility/query/cartItemsInfo.js @@ -6,11 +6,19 @@ items { price { value currency - }, + } row_total { value currency } + row_total_including_tax { + value + currency + } + total_item_discount { + value + currency + } } product { id diff --git a/src/reactapp/src/api/cart/utility/query/cartPriceInfo.js b/src/reactapp/src/api/cart/utility/query/cartPriceInfo.js index b019a6b7..c5045c69 100644 --- a/src/reactapp/src/api/cart/utility/query/cartPriceInfo.js +++ b/src/reactapp/src/api/cart/utility/query/cartPriceInfo.js @@ -8,6 +8,10 @@ prices { value currency } + subtotal_excluding_tax { + value + currency + } discounts { label amount { @@ -15,6 +19,13 @@ prices { value } } + applied_taxes { + label + amount { + currency + value + } + } } `; diff --git a/src/reactapp/src/api/cart/utility/query/cartShippingMethods.js b/src/reactapp/src/api/cart/utility/query/cartShippingMethods.js index b5dce1bd..54786e25 100644 --- a/src/reactapp/src/api/cart/utility/query/cartShippingMethods.js +++ b/src/reactapp/src/api/cart/utility/query/cartShippingMethods.js @@ -4,6 +4,10 @@ available_shipping_methods { carrier_title method_code method_title + price_excl_tax { + value + currency + } price_incl_tax { currency value diff --git a/src/reactapp/src/components/items/components/CartItem.jsx b/src/reactapp/src/components/items/components/CartItem.jsx index 465513c9..357031e5 100644 --- a/src/reactapp/src/components/items/components/CartItem.jsx +++ b/src/reactapp/src/components/items/components/CartItem.jsx @@ -7,7 +7,7 @@ import Button from '../../common/Button'; import TextInput from '../../common/Form/TextInput'; import { __ } from '../../../i18n'; import { _emptyFunc } from '../../../utils'; -import { CART_ITEMS_FORM } from '../../../config'; +import { CART_ITEMS_FORM, config } from '../../../config'; import useItemsFormContext from '../hooks/useItemsFormContext'; function CartItem({ item, isLastItem, actions }) { @@ -20,6 +20,7 @@ function CartItem({ item, isLastItem, actions }) { const qtyField = `${item.id}.quantity`; const itemQtyField = `${CART_ITEMS_FORM}.${qtyField}`; const isQtyFieldTouched = _get(cartItemsTouched, qtyField); + const displayCartItemPrices = config.displayCartItemPrices; return ( @@ -49,8 +50,14 @@ function CartItem({ item, isLastItem, actions }) { onChange={actions.handleQtyUpdate} /> - {item.price} - {item.rowTotal} + {(displayCartItemPrices === 'including') + ? {item.priceIncTax} + : {item.price} + } + {(displayCartItemPrices === 'including') + ? {item.rowTotalIncTax} + : {item.rowTotal} + }