diff --git a/README.md b/README.md index 899c64fed77..ecc1ce160bb 100755 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Develop and deploy your next headless commerce storefronts with Next JS and Bagi Revolutionize Your Online Store with Bagisto's Open Source eCommerce Mobile -![enter image description here](https://raw.githubusercontent.com/bagisto/temp-media/master/git-hub-banner.png) +![enter image description here](https://raw.githubusercontent.com/bagisto/temp-media/master/open-source-ecommerce-mobile.png) Mobile eCommerce powered by Flutter & Laravel: https://github.com/bagisto/opensource-ecommerce-mobile-app diff --git a/UPGRADE.md b/UPGRADE.md index e3583e153d3..0370ff06193 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,54 +2,46 @@ - [Upgrading To v2.2.0 From v2.1.0](#upgrade-2.2.0) - ## High Impact Changes -
@lang('admin::app.catalog.attributes.create.title')
@@ -60,12 +60,12 @@ class="primary-button" id="v-create-attributes-template" > -@@ -357,14 +357,14 @@ class="h-[120px] w-[120px] dark:mix-blend-exclusion dark:invert"
@lang('admin::app.catalog.attributes.create.general')
-@lang('admin::app.catalog.attributes.edit.title')
@@ -54,9 +54,9 @@ class="primary-button" id="v-edit-attributes-template" > -@lang('admin::app.catalog.attributes.edit.general')
-@lang('admin::app.catalog.families.create.title')
@@ -32,11 +32,11 @@ class="primary-button"@lang('admin::app.catalog.families.edit.title')
@@ -35,14 +35,14 @@ class="primary-button"@{{ $admin.formatPrice(element.product.price) }}
@@ -363,7 +363,7 @@ class="relative h-[60px] max-h-[60px] w-full max-w-[60px] overflow-hidden rounde />+ @{{ message }} +
++
@{{ $admin.formatPrice(element.associated_product.price) }}
@@ -104,7 +104,7 @@ class="relative h-[60px] max-h-[60px] w-full max-w-[60px] overflow-hidden rounde />- @lang('admin::app.catalog.attributes.create.general') -
+- @lang('admin::app.catalog.attributes.create.validations') -
- - +- @lang('admin::app.catalog.attributes.edit.configuration') -
- - -+ @lang('admin::app.marketing.promotions.cart-rules.create.title') +
+ +- @lang('admin::app.marketing.promotions.cart-rules.create.title') + +
+ @lang('admin::app.marketing.promotions.cart-rules.create.general')
-+ @lang('admin::app.marketing.promotions.cart-rules.create.uses-per-customer-control-info') +
+ @lang('admin::app.marketing.promotions.cart-rules.create.conditions') +
+ +- @lang('admin::app.marketing.promotions.cart-rules.create.general') -
++ @lang('admin::app.marketing.promotions.cart-rules.create.actions') +
- +- @lang('admin::app.marketing.promotions.cart-rules.create.uses-per-customer-control-info') -
+- @lang('admin::app.marketing.promotions.cart-rules.create.conditions') -
- -- @lang('admin::app.marketing.promotions.cart-rules.create.actions') -
- -- @lang('admin::app.marketing.promotions.cart-rules.create.settings') -
- - -- @lang('admin::app.marketing.promotions.cart-rules.create.marketing-time') -
- + {!! view_render_event('bagisto.admin.marketing.promotions.cart_rules.create.card.conditions.after') !!} -+ @lang('admin::app.marketing.promotions.cart-rules.create.settings') +
+ + ++ @lang('admin::app.marketing.promotions.cart-rules.create.marketing-time') +
+ + +@lang('admin::app.sales.invoices.invoice-pdf.' . $item) | @endforeach{!! core()->formatBasePrice($item->base_price, true) !!} | - -{{ $item->qty }} | - -{!! core()->formatBasePrice($item->base_total, true) !!} | ++ @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {!! core()->formatBasePrice($item->base_price_incl_tax, true) !!} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {!! core()->formatBasePrice($item->base_price_incl_tax, true) !!} + + + @lang('admin::app.sales.invoices.invoice-pdf.excl-tax') + + + {{ core()->formatPrice($item->base_price) }} + + + @else + {!! core()->formatBasePrice($item->base_price, true) !!} + @endif + | -{!! core()->formatBasePrice($item->base_tax_amount, true) !!} | ++ {{ $item->qty }} + | -{!! core()->formatBasePrice($item->base_total + $item->base_tax_amount, true) !!} | ++ @if (core()->getConfigData('sales.taxes.sales.display_subtotal') == 'including_tax') + {!! core()->formatBasePrice($item->base_total_incl_tax, true) !!} + @elseif (core()->getConfigData('sales.taxes.sales.display_subtotal') == 'both') + {!! core()->formatBasePrice($item->base_total_incl_tax, true) !!} + + + @lang('admin::app.sales.invoices.invoice-pdf.excl-tax') + + + {{ core()->formatPrice($item->base_total) }} + + + @else + {!! core()->formatBasePrice($item->base_total, true) !!} + @endif + | @endforeach @@ -373,17 +413,57 @@
---|
@lang('admin::app.sales.invoices.invoice-pdf.subtotal') | -- | -{!! core()->formatBasePrice($invoice->base_sub_total, true) !!} | -||||
@lang('admin::app.sales.invoices.invoice-pdf.subtotal') | +- | +{!! core()->formatBasePrice($invoice->base_sub_total_incl_tax, true) !!} | +||||
@lang('admin::app.sales.invoices.invoice-pdf.subtotal-incl-tax') | +- | +{!! core()->formatBasePrice($invoice->base_sub_total_incl_tax, true) !!} | +||||
@lang('admin::app.sales.invoices.invoice-pdf.subtotal-excl-tax') | +- | +{!! core()->formatBasePrice($invoice->base_sub_total, true) !!} | +||||
@lang('admin::app.sales.invoices.invoice-pdf.subtotal') | +- | +{!! core()->formatBasePrice($invoice->base_sub_total, true) !!} | +||||
@lang('admin::app.sales.invoices.invoice-pdf.shipping-handling') | -- | -{!! core()->formatBasePrice($invoice->base_shipping_amount, true) !!} | -||||
@lang('admin::app.sales.invoices.invoice-pdf.shipping-handling') | +- | +{!! core()->formatBasePrice($invoice->base_shipping_amount_incl_tax, true) !!} | +||||
@lang('admin::app.sales.invoices.invoice-pdf.shipping-handling-incl-tax') | +- | +{!! core()->formatBasePrice($invoice->base_shipping_amount_incl_tax, true) !!} | +||||
@lang('admin::app.sales.invoices.invoice-pdf.shipping-handling-excl-tax') | +- | +{!! core()->formatBasePrice($invoice->base_shipping_amount, true) !!} | +||||
@lang('admin::app.sales.invoices.invoice-pdf.shipping-handling') | +- | +{!! core()->formatBasePrice($invoice->base_shipping_amount, true) !!} | +||||
@lang('admin::app.sales.invoices.invoice-pdf.tax') | diff --git a/packages/Webkul/Admin/src/Resources/views/sales/invoices/view.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/invoices/view.blade.php index 1709af6e737..e17002b93c7 100755 --- a/packages/Webkul/Admin/src/Resources/views/sales/invoices/view.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/sales/invoices/view.blade.php @@ -166,7 +166,7 @@ class="relative h-[60px] max-h-[60px] w-full max-w-[60px] rounded"- @lang('shop::app.customers.account.orders.view.information.tax-percent') - | - -- @lang('shop::app.customers.account.orders.view.information.tax-amount') - | - -- @lang('shop::app.customers.account.orders.view.information.grand-total') - | |||
---|---|---|---|---|---|---|
- {{ core()->formatPrice($item->price, $order->order_currency_code) }} + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + + + @lang('shop::app.customers.account.orders.view.information.excl-tax') + + + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + @endif | - {{ core()->formatPrice($item->total, $order->order_currency_code) }} - | - -- {{ number_format($item->tax_percent, 2) }}% - | - -- {{ core()->formatPrice($item->tax_amount, $order->order_currency_code) }} - | - -- {{ core()->formatPrice($item->total + $item->tax_amount - $item->discount_amount, $order->order_currency_code) }} + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->total_incl_tax, $order->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->total_incl_tax, $order->order_currency_code) }} + + + @lang('shop::app.customers.account.orders.view.information.excl-tax') + + + {{ core()->formatPrice($item->total, $order->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->total, $order->order_currency_code) }} + @endif | - @lang('shop::app.customers.account.orders.view.invoices.tax-amount') - | - -- @lang('shop::app.customers.account.orders.view.invoices.grand-total') - | @@ -460,10 +465,24 @@ class="px-6 py-4 font-medium text-black"- {{ core()->formatPrice($item->price, $order->order_currency_code) }} + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + + + @lang('shop::app.customers.account.orders.view.information.excl-tax') + + + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + @endif | - {{ core()->formatPrice($item->total, $order->order_currency_code) }} - | - -- {{ core()->formatPrice($item->tax_amount, $order->order_currency_code) }} - | - -- {{ core()->formatPrice($item->total + $item->tax_amount, $order->order_currency_code) }} + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->total_incl_tax, $order->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->total_incl_tax, $order->order_currency_code) }} + + + @lang('shop::app.customers.account.orders.view.invoices.excl-tax') + + + {{ core()->formatPrice($item->total, $order->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->total, $order->order_currency_code) }} + @endif | @endforeach @@ -502,77 +521,121 @@ class="px-6 py-4 font-medium text-black"- @lang('shop::app.customers.account.orders.view.refunds.tax-amount') - | - -- @lang('shop::app.customers.account.orders.view.refunds.grand-total') - | @@ -744,10 +793,24 @@ class="px-6 py-4 font-medium text-black"- {{ core()->formatPrice($item->price, $order->order_currency_code) }} + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + + + @lang('shop::app.customers.account.orders.view.information.excl-tax') + + + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + @endif | - {{ core()->formatPrice($item->total, $order->order_currency_code) }} - | - -- {{ core()->formatPrice($item->tax_amount, $order->order_currency_code) }} - | - -- {{ core()->formatPrice($item->total + $item->tax_amount, $order->order_currency_code) }} + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->total_incl_tax, $order->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->total_incl_tax, $order->order_currency_code) }} + + + @lang('shop::app.customers.account.orders.view.information.excl-tax') + + + {{ core()->formatPrice($item->total, $order->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->total, $order->order_currency_code) }} + @endif | @endforeach @@ -792,107 +855,143 @@ class="px-6 py-4 font-medium text-black"
{{ $item->getTypeInstance()->getOrderedItem($item)->sku }} | +||||||
+ {{ $item->getTypeInstance()->getOrderedItem($item)->sku }} + | {{ $item->name }} @@ -127,10 +129,28 @@ @endif | -{{ core()->formatPrice($item->price, $order->order_currency_code) }} + + | + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + + + @lang('shop::app.emails.orders.excl-tax') + + + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + @endif | -{{ $item->qty_canceled }} | ++ {{ $item->qty_canceled }} + | |
{{ $item->getTypeInstance()->getOrderedItem($item)->sku }} | +||||||
+ {{ $item->getTypeInstance()->getOrderedItem($item)->sku }} + | {{ $item->name }} @@ -128,10 +131,27 @@ @endif | -{{ core()->formatPrice($item->price, $order->order_currency_code) }} + | + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->price_incl_tax, $order->order_currency_code) }} + + + @lang('shop::app.emails.orders.excl-tax') + + + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->price, $order->order_currency_code) }} + @endif | -{{ $item->qty_ordered }} | ++ {{ $item->qty_ordered }} + | |
{{ $item->getTypeInstance()->getOrderedItem($item)->sku }} | +||||||
+ {{ $item->getTypeInstance()->getOrderedItem($item)->sku }} + | {{ $item->name }} @@ -128,10 +130,27 @@ @endif | -{{ core()->formatPrice($item->price, $invoice->order_currency_code) }} + | + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->price_incl_tax, $invoice->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->price_incl_tax, $invoice->order_currency_code) }} + + + @lang('shop::app.emails.orders.excl-tax') + + + {{ core()->formatPrice($item->price, $invoice->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->price, $invoice->order_currency_code) }} + @endif | -{{ $item->qty }} | ++ {{ $item->qty }} + | |
{{ $item->name }}
@if (isset($item->additional['attributes']))
-
@foreach ($item->additional['attributes'] as $attribute)
{{ $attribute['attribute_name'] }} : {{ $attribute['option_label'] }}
@endforeach
-
@endif
|
- {{ core()->formatPrice($item->price, $refund->order_currency_code) }} + | + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->price_incl_tax, $refund->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->price_incl_tax, $refund->order_currency_code) }} + + + @lang('shop::app.emails.orders.excl-tax') + + + {{ core()->formatPrice($item->price, $refund->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->price, $refund->order_currency_code) }} + @endif | -{{ $item->qty }} | ++ {{ $item->qty }} + | ||
{{ $item->getTypeInstance()->getOrderedItem($item)->sku }} | +||||||
+ {{ $item->sku }} + | {{ $item->name }} @@ -139,71 +141,30 @@ @endif | -{{ core()->formatPrice($item->price, $shipment->order_currency_code) }} + | + @if (core()->getConfigData('sales.taxes.sales.display_prices') == 'including_tax') + {{ core()->formatPrice($item->price_incl_tax, $shipment->order->order_currency_code) }} + @elseif (core()->getConfigData('sales.taxes.sales.display_prices') == 'both') + {{ core()->formatPrice($item->price_incl_tax, $shipment->order->order_currency_code) }} + + + @lang('shop::app.emails.orders.excl-tax') + + + {{ core()->formatPrice($item->price, $shipment->order->order_currency_code) }} + + + @else + {{ core()->formatPrice($item->price, $shipment->order->order_currency_code) }} + @endif | -{{ $item->qty }} | ++ {{ $item->qty }} + |
+
{{ $prices['regular']['formatted_price'] }}
\ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php index 6c2490b378d..6e60490c841 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php @@ -270,12 +270,6 @@ class="h-5 min-h-5 w-5 min-w-5" v-model="is_buy_now" > - -{!! $product->getTypeInstance()->getPriceHtml() !!} +
- - @if ( - (bool) core()->getConfigData('taxes.catalogue.pricing.tax_inclusive') - && $product->getTypeInstance()->getTaxCategory() - ) - @lang('shop::app.products.view.tax-inclusive') - @endif + @if (\Webkul\Tax\Facades\Tax::isInclusiveTaxProductPrices()) + + @lang('shop::app.products.view.tax-inclusive') - + @endif @if (count($product->getTypeInstance()->getCustomerGroupPricingOffers()))@@ -202,143 +199,87 @@ class="text-sm text-gray-600 max-sm:text-xs" data() { return { - defaultVariant: @json($product->getTypeInstance()->getDefaultVariant()), - config: @json(app('Webkul\Product\Helpers\ConfigurableOption')->getConfigurationConfig($product)), childAttributes: [], - selectedProductId: '', + possibleOptionVariant: null, - simpleProduct: null, + selectedOptionVariant: '', galleryImages: [], } }, - watch: { - simpleProduct: { - deep: true, - - handler(selectedProduct) { - if (selectedProduct) { - return; - } - - this.$parent.$parent.$refs.gallery.media.images = @json(product_image()->getGalleryImages($product)); - }, - }, - }, - mounted() { - this.prepareAttributes(); + let attributes = JSON.parse(JSON.stringify(this.config)).attributes.slice(); - this.prepareDefaultSelection(); - }, + let index = attributes.length; - methods: { - prepareAttributes() { - let config = JSON.parse(JSON.stringify(this.config)); + while (index--) { + let attribute = attributes[index]; - let childAttributes = this.childAttributes, - attributes = config.attributes.slice(), - index = attributes.length, - attribute; + attribute.options = []; - while (index--) { - attribute = attributes[index]; - - attribute.options = []; - - if (index) { - attribute.disabled = true; - } else { - this.fillSelect(attribute); - } - - attribute = Object.assign(attribute, { - childAttributes: childAttributes.slice(), - prevAttribute: attributes[index - 1], - nextAttribute: attributes[index + 1] - }); - - childAttributes.unshift(attribute); + if (index) { + attribute.disabled = true; + } else { + this.fillAttributeOptions(attribute); } - }, - prepareDefaultSelection() { - if (this.defaultVariant) { - this.childAttributes.forEach((attribute) => { - let attributeValue = this.defaultVariant[attribute.code]; - - this.configure(attribute, attributeValue); - }); - } - }, + attribute = Object.assign(attribute, { + childAttributes: this.childAttributes.slice(), + prevAttribute: attributes[index - 1], + nextAttribute: attributes[index + 1] + }); - configure(attribute, value) { - this.simpleProduct = this.getSelectedProductId(attribute, value); + this.childAttributes.unshift(attribute); + } + }, - if (value) { - attribute.selectedIndex = this.getSelectedIndex(attribute, value); + methods: { + configure(attribute, optionId) { + this.possibleOptionVariant = this.getPossibleOptionVariant(attribute, optionId); + if (optionId) { + attribute.selectedValue = optionId; + if (attribute.nextAttribute) { attribute.nextAttribute.disabled = false; - this.fillSelect(attribute.nextAttribute); + this.clearAttributeSelection(attribute.nextAttribute); - this.resetChildren(attribute.nextAttribute); + this.fillAttributeOptions(attribute.nextAttribute); + + this.resetChildAttributes(attribute.nextAttribute); } else { - this.selectedProductId = this.simpleProduct; + this.selectedOptionVariant = this.possibleOptionVariant; } } else { - attribute.selectedIndex = 0; + this.clearAttributeSelection(attribute); - this.resetChildren(attribute); + this.clearAttributeSelection(attribute.nextAttribute); - this.clearSelect(attribute.nextAttribute) + this.resetChildAttributes(attribute); } this.reloadPrice(); - this.changeProductImages(); - }, - - getSelectedIndex(attribute, value) { - let selectedIndex = 0; - - attribute.options.forEach(function(option, index) { - if (option.id == value) { - selectedIndex = index; - } - }) - - return selectedIndex; + + this.reloadImages(); }, - getSelectedProductId(attribute, value) { - let options = attribute.options, - matchedOptions; - - matchedOptions = options.filter(function (option) { - return option.id == value; - }); + getPossibleOptionVariant(attribute, optionId) { + let matchedOptions = attribute.options.filter(option => option.id == optionId); - if (matchedOptions[0] != undefined && matchedOptions[0].allowedProducts != undefined) { + if (matchedOptions[0]?.allowedProducts) { return matchedOptions[0].allowedProducts[0]; } return undefined; }, - fillSelect(attribute) { - let options = this.getAttributeOptions(attribute.id), - prevOption, - index = 1, - allowedProducts, - i, - j; - - this.clearSelect(attribute) + fillAttributeOptions(attribute) { + let options = this.config.attributes.find(tempAttribute => tempAttribute.id === attribute.id)?.options; attribute.options = [{ 'id': '', @@ -346,134 +287,94 @@ class="text-sm text-gray-600 max-sm:text-xs" 'products': [] }]; - if (attribute.prevAttribute) { - prevOption = attribute.prevAttribute.options[attribute.prevAttribute.selectedIndex]; + if (! options) { + return; } - if (options) { - for (i = 0; i < options.length; i++) { - allowedProducts = []; - - if (prevOption) { - for (j = 0; j < options[i].products.length; j++) { - if (prevOption.allowedProducts && prevOption.allowedProducts.indexOf(options[i].products[j]) > -1) { - allowedProducts.push(options[i].products[j]); - } - } - } else { - allowedProducts = options[i].products.slice(0); - } + let prevAttributeSelectedOption = attribute.prevAttribute?.options.find(option => option.id == attribute.prevAttribute.selectedValue); - if (allowedProducts.length > 0) { - options[i].allowedProducts = allowedProducts; + let index = 1; - attribute.options[index] = options[i]; + for (let i = 0; i < options.length; i++) { + let allowedProducts = []; - index++; + if (prevAttributeSelectedOption) { + for (let j = 0; j < options[i].products.length; j++) { + if (prevAttributeSelectedOption.allowedProducts && prevAttributeSelectedOption.allowedProducts.includes(options[i].products[j])) { + allowedProducts.push(options[i].products[j]); + } } + } else { + allowedProducts = options[i].products.slice(0); } - } - }, - resetChildren(attribute) { - if (attribute.childAttributes) { - attribute.childAttributes.forEach(function (set) { - set.selectedIndex = 0; - set.disabled = true; - }); + if (allowedProducts.length > 0) { + options[i].allowedProducts = allowedProducts; + + attribute.options[index++] = options[i]; + } } }, - clearSelect (attribute) { - if (! attribute) + resetChildAttributes(attribute) { + if (! attribute.childAttributes) { return; + } - if (! attribute.swatch_type || attribute.swatch_type == '' || attribute.swatch_type == 'dropdown') { - let element = document.getElementById("attribute_" + attribute.id); - - if (element) { - element.selectedIndex = "0"; - } - } else { - let elements = document.getElementsByName('super_attribute[' + attribute.id + ']'); - - let self = this; + attribute.childAttributes.forEach(function (set) { + set.selectedValue = null; - elements.forEach(function(element) { - element.checked = false; - }) - } + set.disabled = true; + }); }, - getAttributeOptions (attributeId) { - let self = this, - options; + clearAttributeSelection (attribute) { + if (! attribute) { + return; + } - this.config.attributes.forEach(function(attribute, index) { - if (attribute.id == attributeId) { - options = attribute.options; - } - }) + attribute.selectedValue = null; - return options; + this.selectedOptionVariant = null; }, reloadPrice () { - let selectedOptionCount = 0; - - this.childAttributes.forEach(function(attribute) { - if (attribute.selectedIndex) { - selectedOptionCount++; - } - }); - - let priceLabelElement = document.querySelector('.price-label'); - let priceElement = document.querySelector('.special-price') ? document.querySelector('.special-price') : document.querySelector('.final-price'); - let regularPriceElement = document.querySelector('.regular-price'); + let selectedOptionCount = this.childAttributes.filter(attribute => attribute.selectedValue).length; if (this.childAttributes.length == selectedOptionCount) { - priceLabelElement.style.display = 'none'; + document.querySelector('.price-label').style.display = 'none'; - if (regularPriceElement) { - regularPriceElement.style.display = 'none'; - } - - priceElement.innerHTML = this.config.variant_prices[this.simpleProduct].final.formatted_price; - - if (regularPriceElement && this.config.variant_prices[this.simpleProduct].final.price < this.config.variant_prices[this.simpleProduct].regular.price) { - regularPriceElement.innerHTML = this.config.variant_prices[this.simpleProduct].regular.formatted_price; - regularPriceElement.style.display = 'inline-block'; - } + document.querySelector('.final-price').innerHTML = this.config.variant_prices[this.possibleOptionVariant].final.formatted_price; - this.$emitter.emit('configurable-variant-selected-event',this.simpleProduct); + this.$emitter.emit('configurable-variant-selected-event',this.possibleOptionVariant); } else { - priceLabelElement.style.display = 'inline-block'; + document.querySelector('.price-label').style.display = 'inline-block'; - priceElement.innerHTML = this.config.regular.formatted_price; + document.querySelector('.final-price').innerHTML = this.config.regular.formatted_price; this.$emitter.emit('configurable-variant-selected-event', 0); } }, - changeProductImages () { + reloadImages () { galleryImages.splice(0, galleryImages.length) - if (this.simpleProduct) { - this.config.variant_images[this.simpleProduct].forEach(function(image) { - galleryImages.push(image) + if (this.possibleOptionVariant) { + this.config.variant_images[this.possibleOptionVariant].forEach(function(image) { + galleryImages.push(image); }); - this.config.variant_videos[this.simpleProduct].forEach(function(video) { - galleryImages.push(video) + this.config.variant_videos[this.possibleOptionVariant].forEach(function(video) { + galleryImages.push(video); }); } this.galleryImages.forEach(function(image) { - galleryImages.push(image) + galleryImages.push(image); }); if (galleryImages.length) { - this.$parent.$parent.$refs.gallery.media.images = { ...galleryImages }; + this.$parent.$parent.$refs.gallery.media.images = [...galleryImages]; } this.$emitter.emit('configurable-variant-update-images-event', galleryImages); diff --git a/packages/Webkul/Shop/tests/Feature/Checkout/CartTest.php b/packages/Webkul/Shop/tests/Feature/Checkout/CartTest.php index faa0952584b..5a85481e266 100644 --- a/packages/Webkul/Shop/tests/Feature/Checkout/CartTest.php +++ b/packages/Webkul/Shop/tests/Feature/Checkout/CartTest.php @@ -1,12 +1,18 @@ refresh(); - $response->assertJsonPath('data.base_sub_total', core()->formatPrice($cart->base_sub_total)); + $response->assertJsonPath('data.formatted_discount_amount', core()->currency($cart->discount_amount)); - $response->assertJsonPath('data.base_tax_amounts.0', core()->currency($cart->base_tax_amounts)); + $this->assertPrice(! empty($cart->tax_total) ? $cart->tax_total : 0, $response['data']['tax_total']); - $response->assertJsonPath('data.formatted_base_discount_amount', core()->currency($cart->base_discount_amount)); - - $this->assertPrice(! empty($cart->base_tax_total) ? $cart->base_tax_total : 0, $response['data']['base_tax_total']); - - $this->assertPrice(! empty($cart->base_discount_amount) ? $cart->base_discount_amount : 0, $response['data']['base_discount_amount']); + $this->assertPrice(! empty($cart->discount_amount) ? $cart->discount_amount : 0, $response['data']['discount_amount']); $this->assertPrice($cart->grand_total, $response['data']['grand_total']); @@ -167,15 +169,11 @@ $cart->refresh(); - $response->assertJsonPath('data.base_sub_total', core()->formatPrice($cart->base_sub_total)); - - $response->assertJsonPath('data.base_tax_amounts.0', core()->currency($cart->base_tax_amounts)); + $response->assertJsonPath('data.formatted_discount_amount', core()->currency($cart->discount_amount)); - $response->assertJsonPath('data.formatted_base_discount_amount', core()->currency($cart->base_discount_amount)); + $this->assertPrice(! empty($cart->tax_total) ? $cart->tax_total : 0, $response['data']['tax_total']); - $this->assertPrice(! empty($cart->base_tax_total) ? $cart->base_tax_total : 0, $response['data']['base_tax_total']); - - $this->assertPrice(! empty($cart->base_discount_amount) ? $cart->base_discount_amount : 0, $response['data']['base_discount_amount']); + $this->assertPrice(! empty($cart->discount_amount) ? $cart->discount_amount : 0, $response['data']['discount_amount']); $this->assertPrice($cart->grand_total, $response['data']['grand_total']); @@ -658,15 +656,11 @@ $cartItem2->refresh(); - $response->assertJsonPath('data.base_sub_total', core()->formatPrice($cart->base_sub_total)); - - $response->assertJsonPath('data.base_tax_amounts.0', core()->currency($cart->base_tax_amounts)); + $response->assertJsonPath('data.formatted_discount_amount', core()->currency($cart->discount_amount)); - $response->assertJsonPath('data.formatted_base_discount_amount', core()->currency($cart->base_discount_amount)); + $this->assertPrice(! empty($cart->tax_total) ? $cart->tax_total : 0, $response['data']['tax_total']); - $this->assertPrice(! empty($cart->base_tax_total) ? $cart->base_tax_total : 0, $response['data']['base_tax_total']); - - $this->assertPrice(! empty($cart->base_discount_amount) ? $cart->base_discount_amount : 0, $response['data']['base_discount_amount']); + $this->assertPrice(! empty($cart->discount_amount) ? $cart->discount_amount : 0, $response['data']['discount_amount']); $this->assertPrice($cart->grand_total, $response['data']['grand_total']); @@ -803,15 +797,11 @@ $cartItem2->refresh(); - $response->assertJsonPath('data.base_sub_total', core()->formatPrice($cart->base_sub_total)); - - $response->assertJsonPath('data.base_tax_amounts.0', core()->currency($cart->base_tax_amounts)); + $response->assertJsonPath('data.formatted_discount_amount', core()->currency($cart->discount_amount)); - $response->assertJsonPath('data.formatted_base_discount_amount', core()->currency($cart->base_discount_amount)); + $this->assertPrice(! empty($cart->tax_total) ? $cart->tax_total : 0, $response['data']['tax_total']); - $this->assertPrice(! empty($cart->base_tax_total) ? $cart->base_tax_total : 0, $response['data']['base_tax_total']); - - $this->assertPrice(! empty($cart->base_discount_amount) ? $cart->base_discount_amount : 0, $response['data']['base_discount_amount']); + $this->assertPrice(! empty($cart->discount_amount) ? $cart->discount_amount : 0, $response['data']['discount_amount']); $this->assertPrice($cart->grand_total, $response['data']['grand_total']); @@ -1137,15 +1127,11 @@ $cartItem2->refresh(); - $response->assertJsonPath('data.base_sub_total', core()->formatPrice($cart->base_sub_total)); - - $response->assertJsonPath('data.base_tax_amounts.0', core()->currency($cart->base_tax_amounts)); + $response->assertJsonPath('data.formatted_discount_amount', core()->currency($cart->discount_amount)); - $response->assertJsonPath('data.formatted_base_discount_amount', core()->currency($cart->base_discount_amount)); + $this->assertPrice(! empty($cart->tax_total) ? $cart->tax_total : 0, $response['data']['tax_total']); - $this->assertPrice(! empty($cart->base_tax_total) ? $cart->base_tax_total : 0, $response['data']['base_tax_total']); - - $this->assertPrice(! empty($cart->base_discount_amount) ? $cart->base_discount_amount : 0, $response['data']['base_discount_amount']); + $this->assertPrice(! empty($cart->discount_amount) ? $cart->discount_amount : 0, $response['data']['discount_amount']); $this->assertPrice($cart->grand_total, $response['data']['grand_total']); @@ -1278,15 +1264,11 @@ $cartItem2->refresh(); - $response->assertJsonPath('data.base_sub_total', core()->formatPrice($cart->base_sub_total)); - - $response->assertJsonPath('data.base_tax_amounts.0', core()->currency($cart->base_tax_amounts)); - - $response->assertJsonPath('data.formatted_base_discount_amount', core()->currency($cart->base_discount_amount)); + $response->assertJsonPath('data.formatted_discount_amount', core()->currency($cart->discount_amount)); - $this->assertPrice(! empty($cart->base_tax_total) ? $cart->base_tax_total : 0, $response['data']['base_tax_total']); + $this->assertPrice(! empty($cart->tax_total) ? $cart->tax_total : 0, $response['data']['tax_total']); - $this->assertPrice(! empty($cart->base_discount_amount) ? $cart->base_discount_amount : 0, $response['data']['base_discount_amount']); + $this->assertPrice(! empty($cart->discount_amount) ? $cart->discount_amount : 0, $response['data']['discount_amount']); $this->assertPrice($cart->grand_total, $response['data']['grand_total']); @@ -1377,8 +1359,8 @@ ->assertJsonPath('data.is_guest', 1) ->assertJsonPath('data.customer_id', null) ->assertJsonPath('data.items_qty', $quantity) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0) + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.items.0.type', $product->type) ->assertJsonPath('data.items.0.name', $product->name) @@ -1429,8 +1411,8 @@ ->assertJsonPath('data.is_guest', 0) ->assertJsonPath('data.customer_id', $customer->id) ->assertJsonPath('data.items_qty', $quantity) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0) + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.items.0.type', $product->type) ->assertJsonPath('data.items.0.name', $product->name) @@ -1562,8 +1544,8 @@ ->assertJsonPath('data.items.0.name', $product->name) ->assertJsonPath('data.is_guest', 1) ->assertJsonPath('data.customer_id', null) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0) + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.billing_address', null) ->assertJsonPath('data.shipping_address', null) @@ -1634,8 +1616,8 @@ ->assertJsonPath('data.items.0.name', $product->name) ->assertJsonPath('data.is_guest', 0) ->assertJsonPath('data.customer_id', $customer->id) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0) + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.billing_address', null) ->assertJsonPath('data.shipping_address', null) @@ -1736,8 +1718,8 @@ ->assertJsonPath('data.items.0.type', $product->type) ->assertJsonPath('data.items.0.name', $product->name) ->assertJsonPath('data.is_guest', 1) - ->assertJsonPath('data.base_discount_amount', 0) - ->assertJsonPath('data.base_tax_total', 0) + ->assertJsonPath('data.discount_amount', 0) + ->assertJsonPath('data.tax_total', 0) ->assertJsonPath('data.have_stockable_items', true) ->assertJsonPath('data.customer_id', null) ->assertJsonPath('data.coupon_code', null) @@ -1802,8 +1784,8 @@ ->assertJsonPath('data.customer_id', $customer->id) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.billing_address', null) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0); + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0); $this->assertPrice($childProduct->price, $response['data']['grand_total']); @@ -1893,8 +1875,8 @@ ->assertJsonPath('data.customer_id', null) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.billing_address', null) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0); + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0); $this->assertPrice($product->price, $response['data']['items'][0]['price']); @@ -1946,8 +1928,8 @@ ->assertJsonPath('data.customer_id', $customer->id) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.billing_address', null) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0); + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0); $this->assertPrice($product->price, $response['data']['items'][0]['price']); @@ -2060,8 +2042,8 @@ ->assertJsonPath('data.customer_id', null) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.billing_address', null) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0); + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0); foreach ($groupedProducts as $key => $groupedProduct) { $response->assertJsonPath('data.items.'.$key.'.quantity', $groupedProduct->qty) @@ -2133,8 +2115,8 @@ ->assertJsonPath('data.customer_id', $customer->id) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.billing_address', null) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0); + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0); foreach ($groupedProducts as $key => $groupedProduct) { $response->assertJsonPath('data.items.'.$key.'.quantity', $groupedProduct->qty) @@ -2224,8 +2206,8 @@ ->assertJsonPath('data.customer_id', null) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.billing_address', null) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0); + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0); $this->assertPrice($product->price, $response['data']['items'][0]['price']); @@ -2274,10 +2256,627 @@ ->assertJsonPath('data.customer_id', $customer->id) ->assertJsonPath('data.coupon_code', null) ->assertJsonPath('data.billing_address', null) - ->assertJsonPath('data.base_tax_total', 0) - ->assertJsonPath('data.base_discount_amount', 0); + ->assertJsonPath('data.tax_total', 0) + ->assertJsonPath('data.discount_amount', 0); $this->assertPrice($product->price, $response['data']['items'][0]['price']); $this->assertPrice($product->price * $quantity, $response['data']['grand_total']); }); + +it('should check including tax rate when add a product to the cart based on shipping address', function () { + // Arrange. + $product = (new ProductFaker([ + 'attributes' => [ + 5 => 'new', + 6 => 'featured', + 11 => 'price', + ], + 'attribute_value' => [ + 'new' => [ + 'boolean_value' => true, + ], + 'featured' => [ + 'boolean_value' => true, + ], + 'price' => [ + 'float_value' => 100, + ], + ], + ]))->getSimpleProductFactory()->create(); + + $taxRate = TaxRate::factory()->create([ + 'country' => 'IN', + 'state' => fake()->randomElement(['UP', 'DL', 'HR', 'PB', 'RJ']), + ]); + + $taxCategory = TaxCategory::factory()->create(); + + TaxMap::factory()->create([ + 'tax_category_id' => $taxCategory->id, + 'tax_rate_id' => $taxRate->id, + ]); + + CoreConfig::factory()->create([ + 'code' => 'sales.taxes.categories.shipping', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.categories.product', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.calculation.based_on', + 'value' => 'shipping_address', + ])->create([ + 'code' => 'sales.taxes.calculation.product_prices', + 'value' => 'including_tax', + ])->create([ + 'code' => 'sales.taxes.calculation.shipping_prices', + 'value' => 'including_tax', + ]); + + $cart = cart()->addProduct($product, [ + 'product_id' => $product->id, + 'quantity' => 1, + ]); + + $inclTax = $product->price - ($product->price / (1 + ($taxRate->tax_rate / 100))); + + // Act and Assert. + $response = postJson(route('shop.api.checkout.cart.estimate_shipping'), [ + 'country' => $taxRate->country, + 'state' => $taxRate->state, + 'postcode' => fake()->postcode(), + ]) + ->assertOk() + ->assertJsonPath('data.cart.id', $cart->id) + ->assertJsonPath('data.cart.formatted_tax_total', core()->formatPrice($inclTax)) + ->assertJsonPath('data.cart.formatted_sub_total_incl_tax', core()->formatPrice($product->price)) + ->assertJsonPath('data.cart.formatted_grand_total', core()->formatPrice($product->price)) + ->assertJsonPath('data.cart.formatted_sub_total', core()->formatPrice($product->price - $inclTax)) + ->assertJsonPath('data.cart.items.0.id', $cart->items->first()->id) + ->assertJsonPath('data.cart.items.0.quantity', 1) + ->assertJsonPath('data.cart.items.0.type', $product->type); + + $this->assertPrice($inclTax, $response->json('data.cart.tax_total')); + + $this->assertPrice($product->price, $response->json('data.cart.sub_total_incl_tax')); + + $this->assertPrice($product->price - $inclTax, $response->json('data.cart.sub_total')); + + $this->assertPrice($product->price, $response->json('data.cart.grand_total')); + + $this->assertPrice($product->price, $response->json('data.cart.items.0.price_incl_tax')); + + $this->assertPrice($product->price - $inclTax, $response->json('data.cart.items.0.price')); +}); + +it('should check including tax rate when add a product to the cart based on billing address', function () { + // Arrange. + $product = (new ProductFaker([ + 'attributes' => [ + 5 => 'new', + 6 => 'featured', + 11 => 'price', + ], + 'attribute_value' => [ + 'new' => [ + 'boolean_value' => true, + ], + 'featured' => [ + 'boolean_value' => true, + ], + 'price' => [ + 'float_value' => 100, + ], + ], + ]))->getSimpleProductFactory()->create(); + + $taxRate = TaxRate::factory()->create([ + 'country' => 'IN', + 'state' => fake()->randomElement(['UP', 'DL', 'HR', 'PB', 'RJ']), + ]); + + $taxCategory = TaxCategory::factory()->create(); + + TaxMap::factory()->create([ + 'tax_category_id' => $taxCategory->id, + 'tax_rate_id' => $taxRate->id, + ]); + + CoreConfig::factory()->create([ + 'code' => 'sales.taxes.categories.shipping', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.categories.product', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.calculation.based_on', + 'value' => 'billing_address', + ])->create([ + 'code' => 'sales.taxes.calculation.product_prices', + 'value' => 'including_tax', + ])->create([ + 'code' => 'sales.taxes.calculation.shipping_prices', + 'value' => 'including_tax', + ]); + + $cart = cart()->addProduct($product, [ + 'product_id' => $product->id, + 'quantity' => 1, + ]); + + CartAddress::factory()->create([ + 'cart_id' => $cart->id, + 'country' => $taxRate->country, + 'state' => $taxRate->state, + 'address_type' => CartAddress::ADDRESS_TYPE_BILLING, + 'use_for_shipping' => true, + ]); + + CartAddress::factory()->create([ + 'cart_id' => $cart->id, + 'country' => $taxRate->country, + 'state' => $taxRate->state, + 'address_type' => CartAddress::ADDRESS_TYPE_BILLING, + 'use_for_shipping' => true, + ]); + + cart()->setCart($cart); + + cart()->collectTotals(); + + $inclTax = $product->price - ($product->price / (1 + ($taxRate->tax_rate / 100))); + + // Act and Assert. + $response = getJson(route('shop.checkout.onepage.summary')) + ->assertOk() + ->assertJsonPath('data.id', $cart->id) + ->assertJsonPath('data.formatted_tax_total', core()->formatPrice($inclTax)) + ->assertJsonPath('data.formatted_sub_total_incl_tax', core()->formatPrice($product->price)) + ->assertJsonPath('data.formatted_grand_total', core()->formatPrice($product->price)) + ->assertJsonPath('data.formatted_sub_total', core()->formatPrice($product->price - $inclTax)) + ->assertJsonPath('data.items.0.id', $cart->items->first()->id) + ->assertJsonPath('data.items.0.quantity', 1) + ->assertJsonPath('data.items.0.type', $product->type); + + $this->assertPrice($inclTax, $response->json('data.tax_total')); + + $this->assertPrice($product->price, $response->json('data.sub_total_incl_tax')); + + $this->assertPrice($product->price - $inclTax, $response->json('data.sub_total')); + + $this->assertPrice($product->price, $response->json('data.grand_total')); + + $this->assertPrice($product->price, $response->json('data.items.0.price_incl_tax')); + + $this->assertPrice($product->price - $inclTax, $response->json('data.items.0.price')); +}); + +it('should check including tax rate when add a product to the cart based on shipping origin', function () { + // Arrange. + $product = (new ProductFaker([ + 'attributes' => [ + 5 => 'new', + 6 => 'featured', + 11 => 'price', + ], + 'attribute_value' => [ + 'new' => [ + 'boolean_value' => true, + ], + 'featured' => [ + 'boolean_value' => true, + ], + 'price' => [ + 'float_value' => 100, + ], + ], + ]))->getSimpleProductFactory()->create(); + + $taxRate = TaxRate::factory()->create([ + 'country' => 'IN', + 'state' => fake()->randomElement(['UP', 'DL', 'HR', 'PB', 'RJ']), + ]); + + $taxCategory = TaxCategory::factory()->create(); + + TaxMap::factory()->create([ + 'tax_category_id' => $taxCategory->id, + 'tax_rate_id' => $taxRate->id, + ]); + + CoreConfig::factory()->create([ + 'code' => 'sales.shipping.origin.country', + 'value' => $taxRate->country, + 'channel_code' => 'default', + 'locale_code' => 'en', + ])->create([ + 'code' => 'sales.shipping.origin.state', + 'value' => $taxRate->state, + 'channel_code' => 'default', + 'locale_code' => 'en', + ])->create([ + 'code' => 'sales.shipping.origin.city', + 'value' => fake()->city(), + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.address', + 'value' => fake()->address(), + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.store_name', + 'value' => 'DEMO STORE', + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.contact', + 'value' => '1234567890', + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.bank_details', + 'value' => 'TEST BANK', + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.zipcode', + 'value' => '123456', + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.taxes.categories.shipping', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.categories.product', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.calculation.based_on', + 'value' => 'shipping_origin', + ])->create([ + 'code' => 'sales.taxes.calculation.product_prices', + 'value' => 'including_tax', + ])->create([ + 'code' => 'sales.taxes.calculation.shipping_prices', + 'value' => 'including_tax', + ]); + + $cart = cart()->addProduct($product, [ + 'product_id' => $product->id, + 'quantity' => 1, + ]); + + $inclTax = $product->price - ($product->price / (1 + ($taxRate->tax_rate / 100))); + + // Act and Assert. + $response = postJson(route('shop.api.checkout.cart.estimate_shipping'), [ + 'country' => $taxRate->country, + 'state' => $taxRate->state, + 'postcode' => '123456', + ]); + + $response->assertOk() + ->assertJsonPath('data.cart.id', $cart->id) + ->assertJsonPath('data.cart.formatted_tax_total', core()->formatPrice($inclTax)) + ->assertJsonPath('data.cart.formatted_sub_total_incl_tax', core()->formatPrice($product->price)) + ->assertJsonPath('data.cart.formatted_grand_total', core()->formatPrice($product->price)) + ->assertJsonPath('data.cart.formatted_sub_total', core()->formatPrice($product->price - $inclTax)) + ->assertJsonPath('data.cart.items.0.id', $cart->items->first()->id) + ->assertJsonPath('data.cart.items.0.quantity', 1) + ->assertJsonPath('data.cart.items.0.type', $product->type); + + $this->assertPrice($inclTax, $response->json('data.cart.tax_total')); + + $this->assertPrice($product->price, $response->json('data.cart.sub_total_incl_tax')); + + $this->assertPrice($product->price - $inclTax, $response->json('data.cart.sub_total')); + + $this->assertPrice($product->price, $response->json('data.cart.grand_total')); + + $this->assertPrice($product->price, $response->json('data.cart.items.0.price_incl_tax')); + + $this->assertPrice($product->price - $inclTax, $response->json('data.cart.items.0.price')); +}); + +it('should check excluding tax rate when add a product to the cart based on billing address', function () { + // Arrange. + $product = (new ProductFaker([ + 'attributes' => [ + 5 => 'new', + 6 => 'featured', + 11 => 'price', + ], + 'attribute_value' => [ + 'new' => [ + 'boolean_value' => true, + ], + 'featured' => [ + 'boolean_value' => true, + ], + 'price' => [ + 'float_value' => 100, + ], + ], + ]))->getSimpleProductFactory()->create(); + + $taxRate = TaxRate::factory()->create([ + 'country' => 'IN', + 'state' => fake()->randomElement(['UP', 'DL', 'HR', 'PB', 'RJ']), + ]); + + $taxCategory = TaxCategory::factory()->create(); + + TaxMap::factory()->create([ + 'tax_category_id' => $taxCategory->id, + 'tax_rate_id' => $taxRate->id, + ]); + + CoreConfig::factory()->create([ + 'code' => 'sales.taxes.categories.shipping', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.categories.product', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.calculation.based_on', + 'value' => 'billing_address', + ])->create([ + 'code' => 'sales.taxes.calculation.product_prices', + 'value' => 'excluding_tax', + ])->create([ + 'code' => 'sales.taxes.calculation.shipping_prices', + 'value' => 'excluding_tax', + ]); + + $cart = cart()->addProduct($product, [ + 'product_id' => $product->id, + 'quantity' => 1, + ]); + + CartAddress::factory()->create([ + 'cart_id' => $cart->id, + 'country' => $taxRate->country, + 'state' => $taxRate->state, + 'address_type' => CartAddress::ADDRESS_TYPE_BILLING, + 'use_for_shipping' => true, + ]); + + CartAddress::factory()->create([ + 'cart_id' => $cart->id, + 'country' => $taxRate->country, + 'state' => $taxRate->state, + 'address_type' => CartAddress::ADDRESS_TYPE_BILLING, + 'use_for_shipping' => true, + ]); + + cart()->setCart($cart); + + cart()->collectTotals(); + + $exclTax = ($taxRate->tax_rate / 100) * $product->price; + + // Act and Assert. + $response = getJson(route('shop.checkout.onepage.summary')) + ->assertOk() + ->assertJsonPath('data.id', $cart->id) + ->assertJsonPath('data.formatted_tax_total', core()->formatPrice($exclTax)) + ->assertJsonPath('data.formatted_sub_total_incl_tax', core()->formatPrice($product->price + $exclTax)) + ->assertJsonPath('data.formatted_grand_total', core()->formatPrice($product->price + $exclTax)) + ->assertJsonPath('data.formatted_sub_total', core()->formatPrice($product->price)) + ->assertJsonPath('data.items.0.id', $cart->items->first()->id) + ->assertJsonPath('data.items.0.quantity', 1) + ->assertJsonPath('data.items.0.type', $product->type); + + $this->assertPrice($exclTax, $response->json('data.tax_total')); + + $this->assertPrice($product->price + $exclTax, $response->json('data.sub_total_incl_tax')); + + $this->assertPrice($product->price, $response->json('data.sub_total')); + + $this->assertPrice($product->price + $exclTax, $response->json('data.grand_total')); + + $this->assertPrice($product->price + $exclTax, $response->json('data.items.0.price_incl_tax')); + + $this->assertPrice($product->price, $response->json('data.items.0.price')); +}); + +it('should check excluding tax rate when add a product to the cart based on shipping address', function () { + // Arrange. + $product = (new ProductFaker([ + 'attributes' => [ + 5 => 'new', + 6 => 'featured', + 11 => 'price', + ], + 'attribute_value' => [ + 'new' => [ + 'boolean_value' => true, + ], + 'featured' => [ + 'boolean_value' => true, + ], + 'price' => [ + 'float_value' => 100, + ], + ], + ]))->getSimpleProductFactory()->create(); + + $taxRate = TaxRate::factory()->create([ + 'country' => 'IN', + 'state' => fake()->randomElement(['UP', 'DL', 'HR', 'PB', 'RJ']), + ]); + + $taxCategory = TaxCategory::factory()->create(); + + TaxMap::factory()->create([ + 'tax_category_id' => $taxCategory->id, + 'tax_rate_id' => $taxRate->id, + ]); + + CoreConfig::factory()->create([ + 'code' => 'sales.taxes.categories.shipping', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.categories.product', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.calculation.based_on', + 'value' => 'shipping_address', + ])->create([ + 'code' => 'sales.taxes.calculation.product_prices', + 'value' => 'excluding_tax', + ])->create([ + 'code' => 'sales.taxes.calculation.shipping_prices', + 'value' => 'excluding_tax', + ]); + + $cart = cart()->addProduct($product, [ + 'product_id' => $product->id, + 'quantity' => 1, + ]); + + $exclTax = ($taxRate->tax_rate / 100) * $product->price; + + // Act and Assert. + $response = postJson(route('shop.api.checkout.cart.estimate_shipping'), [ + 'country' => $taxRate->country, + 'state' => $taxRate->state, + 'postcode' => fake()->postcode(), + ]) + ->assertOk() + ->assertJsonPath('data.cart.id', $cart->id) + ->assertJsonPath('data.cart.formatted_tax_total', core()->formatPrice($exclTax)) + ->assertJsonPath('data.cart.formatted_sub_total_incl_tax', core()->formatPrice($product->price + $exclTax)) + ->assertJsonPath('data.cart.formatted_grand_total', core()->formatPrice($product->price + $exclTax)) + ->assertJsonPath('data.cart.formatted_sub_total', core()->formatPrice($product->price)) + ->assertJsonPath('data.cart.items.0.id', $cart->items->first()->id) + ->assertJsonPath('data.cart.items.0.quantity', 1) + ->assertJsonPath('data.cart.items.0.type', $product->type); + + $this->assertPrice($exclTax, $response->json('data.cart.tax_total')); + + $this->assertPrice($product->price + $exclTax, $response->json('data.cart.sub_total_incl_tax')); + + $this->assertPrice($product->price, $response->json('data.cart.sub_total')); + + $this->assertPrice($product->price + $exclTax, $response->json('data.cart.grand_total')); + + $this->assertPrice($product->price + $exclTax, $response->json('data.cart.items.0.price_incl_tax')); + + $this->assertPrice($product->price, $response->json('data.cart.items.0.price')); +}); + +it('should check excluding tax rate when add a product to the cart based on shipping origin', function () { + // Arrange. + $product = (new ProductFaker([ + 'attributes' => [ + 5 => 'new', + 6 => 'featured', + 11 => 'price', + ], + 'attribute_value' => [ + 'new' => [ + 'boolean_value' => true, + ], + 'featured' => [ + 'boolean_value' => true, + ], + 'price' => [ + 'float_value' => 100, + ], + ], + ]))->getSimpleProductFactory()->create(); + + $taxRate = TaxRate::factory()->create([ + 'country' => 'IN', + 'state' => fake()->randomElement(['UP', 'DL', 'HR', 'PB', 'RJ']), + ]); + + $taxCategory = TaxCategory::factory()->create(); + + TaxMap::factory()->create([ + 'tax_category_id' => $taxCategory->id, + 'tax_rate_id' => $taxRate->id, + ]); + + CoreConfig::factory()->create([ + 'code' => 'sales.shipping.origin.country', + 'value' => $taxRate->country, + 'channel_code' => 'default', + 'locale_code' => 'en', + ])->create([ + 'code' => 'sales.shipping.origin.state', + 'value' => $taxRate->state, + 'channel_code' => 'default', + 'locale_code' => 'en', + ])->create([ + 'code' => 'sales.shipping.origin.city', + 'value' => fake()->city(), + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.address', + 'value' => fake()->address(), + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.store_name', + 'value' => 'DEMO STORE', + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.contact', + 'value' => '1234567890', + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.bank_details', + 'value' => 'TEST BANK', + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.shipping.origin.zipcode', + 'value' => '123456', + 'channel_code' => 'default', + ])->create([ + 'code' => 'sales.taxes.categories.shipping', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.categories.product', + 'value' => $taxCategory->id, + ])->create([ + 'code' => 'sales.taxes.calculation.based_on', + 'value' => 'shipping_origin', + ])->create([ + 'code' => 'sales.taxes.calculation.product_prices', + 'value' => 'excluding_tax', + ])->create([ + 'code' => 'sales.taxes.calculation.shipping_prices', + 'value' => 'excluding_tax', + ]); + + $cart = cart()->addProduct($product, [ + 'product_id' => $product->id, + 'quantity' => 1, + ]); + + $exclTax = ($taxRate->tax_rate / 100) * $product->price; + + // Act and Assert. + $response = postJson(route('shop.api.checkout.cart.estimate_shipping'), [ + 'country' => $taxRate->country, + 'state' => $taxRate->state, + 'postcode' => '123456', + ]) + ->assertOk() + ->assertJsonPath('data.cart.id', $cart->id) + ->assertJsonPath('data.cart.formatted_tax_total', core()->formatPrice($exclTax)) + ->assertJsonPath('data.cart.formatted_sub_total_incl_tax', core()->formatPrice($product->price + $exclTax)) + ->assertJsonPath('data.cart.formatted_grand_total', core()->formatPrice($product->price + $exclTax)) + ->assertJsonPath('data.cart.formatted_sub_total', core()->formatPrice($product->price)) + ->assertJsonPath('data.cart.items.0.id', $cart->items->first()->id) + ->assertJsonPath('data.cart.items.0.quantity', 1) + ->assertJsonPath('data.cart.items.0.type', $product->type); + + $this->assertPrice($exclTax, $response->json('data.cart.tax_total')); + + $this->assertPrice($product->price + $exclTax, $response->json('data.cart.sub_total_incl_tax')); + + $this->assertPrice($product->price, $response->json('data.cart.sub_total')); + + $this->assertPrice($product->price + $exclTax, $response->json('data.cart.grand_total')); + + $this->assertPrice($product->price + $exclTax, $response->json('data.cart.items.0.price_incl_tax')); + + $this->assertPrice($product->price, $response->json('data.cart.items.0.price')); +}); diff --git a/packages/Webkul/Shop/tests/Feature/Checkout/CheckoutTest.php b/packages/Webkul/Shop/tests/Feature/Checkout/CheckoutTest.php index 1d44b95d1fa..d313beb304b 100644 --- a/packages/Webkul/Shop/tests/Feature/Checkout/CheckoutTest.php +++ b/packages/Webkul/Shop/tests/Feature/Checkout/CheckoutTest.php @@ -52,20 +52,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); cart()->setCart($cart); @@ -124,20 +127,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); cart()->setCart($cart); @@ -195,24 +201,29 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $customerAddress = CustomerAddress::factory()->create()->toArray(); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); // Act and Assert. @@ -298,24 +309,29 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $customerAddress = CustomerAddress::factory()->create()->toArray(); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); // Act and Assert. @@ -406,24 +422,29 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $customerAddress = CustomerAddress::factory()->create()->toArray(); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); // Act and Assert. @@ -496,24 +517,29 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $customerAddress = CustomerAddress::factory()->create()->toArray(); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); // Act and Assert. @@ -604,24 +630,29 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $customerAddress = CustomerAddress::factory()->create()->toArray(); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); // Act and Assert. @@ -717,24 +748,29 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $customerAddress = CustomerAddress::factory()->create()->toArray(); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); // Act and Assert. @@ -809,24 +845,29 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $customerAddress = CustomerAddress::factory()->create()->toArray(); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); // Act and Assert. @@ -879,24 +920,29 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $customerAddress = CustomerAddress::factory()->create()->toArray(); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); // Act and Assert. @@ -947,20 +993,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); CartAddress::factory()->create([ @@ -1015,20 +1064,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); CartAddress::factory()->create([ @@ -1082,20 +1134,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); CartAddress::factory()->create([ @@ -1167,20 +1222,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); CartAddress::factory()->create([ @@ -1251,20 +1309,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); CartAddress::factory()->create([ @@ -1316,20 +1377,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -1361,7 +1425,6 @@ ->assertJsonPath('cart.customer_id', null) ->assertJsonPath('cart.items_count', 1) ->assertJsonPath('cart.items_qty', 1) - ->assertJsonPath('cart.base_sub_total', core()->formatBasePrice($product->price)) ->assertJsonPath('cart.items.0.id', $cartItem->id) ->assertJsonPath('cart.items.0.quantity', 1) ->assertJsonPath('cart.items.0.type', $cartItem->type) @@ -1454,20 +1517,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -1499,7 +1565,6 @@ ->assertJsonPath('cart.customer_id', $customer->id) ->assertJsonPath('cart.items_count', 1) ->assertJsonPath('cart.items_qty', 1) - ->assertJsonPath('cart.base_sub_total', core()->formatBasePrice($product->price)) ->assertJsonPath('cart.items.0.id', $cartItem->id) ->assertJsonPath('cart.items.0.quantity', 1) ->assertJsonPath('cart.items.0.type', $cartItem->type) @@ -1589,20 +1654,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -1747,20 +1815,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -1913,20 +1984,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -2075,20 +2149,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -2963,20 +3040,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -3097,20 +3177,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -3240,20 +3323,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -3382,20 +3468,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -3531,20 +3620,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -3669,20 +3761,23 @@ ]; $cartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -3811,20 +3906,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); CartAddress::factory()->create([ @@ -3841,6 +3939,8 @@ 'method_title' => core()->getConfigData('sales.payment_methods.'.$paymentMethod.'.title'), ]); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); cart()->collectTotals(); @@ -3908,20 +4008,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); CartAddress::factory()->create([ @@ -3938,6 +4041,8 @@ 'method_title' => core()->getConfigData('sales.payment_methods.'.$paymentMethod.'.title'), ]); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); cart()->collectTotals(); @@ -4004,20 +4109,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); CartAddress::factory()->create([ @@ -4034,6 +4142,8 @@ 'method_title' => core()->getConfigData('sales.payment_methods.'.$paymentMethod.'.title'), ]); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); cart()->collectTotals(); @@ -4101,20 +4211,23 @@ ]; CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $product->id, - 'sku' => $product->sku, - 'quantity' => $additional['quantity'], - 'name' => $product->name, - 'price' => $convertedPrice = core()->convertPrice($price = $product->price), - 'base_price' => $price, - 'total' => $convertedPrice * $additional['quantity'], - 'base_total' => $price * $additional['quantity'], - 'weight' => $product->weight ?? 0, - 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], - 'type' => $product->type, - 'additional' => $additional, + 'cart_id' => $cart->id, + 'product_id' => $product->id, + 'sku' => $product->sku, + 'quantity' => $additional['quantity'], + 'name' => $product->name, + 'price' => $convertedPrice = core()->convertPrice($price = $product->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $total = $convertedPrice * $additional['quantity'], + 'total_incl_tax' => $total, + 'base_total' => $price * $additional['quantity'], + 'weight' => $product->weight ?? 0, + 'total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'base_total_weight' => ($product->weight ?? 0) * $additional['quantity'], + 'type' => $product->type, + 'additional' => $additional, ]); CartAddress::factory()->create([ @@ -4131,6 +4244,8 @@ 'method_title' => core()->getConfigData('sales.payment_methods.'.$paymentMethod.'.title'), ]); + $customerAddress = CustomerAddress::factory()->create()->toArray(); + cart()->setCart($cart); cart()->collectTotals(); @@ -4231,37 +4346,43 @@ ]; $configurableProductCartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $childProduct->id, - 'sku' => $childProduct->sku, - 'quantity' => $configurableProductAdditional['quantity'], - 'name' => $childProduct->name, - 'price' => $convertedPrice = core()->convertPrice($price = $childProduct->price), - 'base_price' => $price, - 'total' => $convertedPrice * $configurableProductAdditional['quantity'], - 'base_total' => $price * $configurableProductAdditional['quantity'], - 'weight' => $childProduct->weight ?? 0, - 'total_weight' => ($childProduct->weight ?? 0) * $configurableProductAdditional['quantity'], - 'base_total_weight' => ($childProduct->weight ?? 0) * $configurableProductAdditional['quantity'], - 'type' => $childProduct->type, - 'additional' => $configurableProductAdditional, + 'cart_id' => $cart->id, + 'product_id' => $childProduct->id, + 'sku' => $childProduct->sku, + 'quantity' => $configurableProductAdditional['quantity'], + 'name' => $childProduct->name, + 'price' => $convertedPrice = core()->convertPrice($price = $childProduct->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $convertedPrice * $configurableProductAdditional['quantity'], + 'total_incl_tax' => $convertedPrice * $configurableProductAdditional['quantity'], + 'base_total' => $price * $configurableProductAdditional['quantity'], + 'weight' => $childProduct->weight ?? 0, + 'total_weight' => ($childProduct->weight ?? 0) * $configurableProductAdditional['quantity'], + 'base_total_weight' => ($childProduct->weight ?? 0) * $configurableProductAdditional['quantity'], + 'type' => $childProduct->type, + 'additional' => $configurableProductAdditional, ]); $simpleProductCartItem = CartItem::factory()->create([ - 'cart_id' => $cart->id, - 'product_id' => $simpleProduct->id, - 'sku' => $simpleProduct->sku, - 'quantity' => $simpleProductAdditional['quantity'], - 'name' => $simpleProduct->name, - 'price' => $convertedPrice = core()->convertPrice($price = $simpleProduct->price), - 'base_price' => $price, - 'total' => $convertedPrice * $simpleProductAdditional['quantity'], - 'base_total' => $price * $simpleProductAdditional['quantity'], - 'weight' => $simpleProduct->weight ?? 0, - 'total_weight' => ($simpleProduct->weight ?? 0) * $simpleProductAdditional['quantity'], - 'base_total_weight' => ($simpleProduct->weight ?? 0) * $simpleProductAdditional['quantity'], - 'type' => $simpleProduct->type, - 'additional' => $simpleProductAdditional, + 'cart_id' => $cart->id, + 'product_id' => $simpleProduct->id, + 'sku' => $simpleProduct->sku, + 'quantity' => $simpleProductAdditional['quantity'], + 'name' => $simpleProduct->name, + 'price' => $convertedPrice = core()->convertPrice($price = $simpleProduct->price), + 'price_incl_tax' => $convertedPrice, + 'base_price' => $price, + 'base_price_incl_tax' => $price, + 'total' => $convertedPrice * $simpleProductAdditional['quantity'], + 'total_incl_tax' => $convertedPrice * $simpleProductAdditional['quantity'], + 'base_total' => $price * $simpleProductAdditional['quantity'], + 'weight' => $simpleProduct->weight ?? 0, + 'total_weight' => ($simpleProduct->weight ?? 0) * $simpleProductAdditional['quantity'], + 'base_total_weight' => ($simpleProduct->weight ?? 0) * $simpleProductAdditional['quantity'], + 'type' => $simpleProduct->type, + 'additional' => $simpleProductAdditional, ]); $cartBillingAddress = CartAddress::factory()->create([ @@ -4468,7 +4589,6 @@ 'grand_total' => $price = array_sum($data['grand_total']), 'base_grand_total' => $price, 'sub_total' => $price, - 'base_sub_total' => $price, 'shipping_method' => 'free_free', 'customer_id' => $customer->id, 'is_active' => 1, diff --git a/packages/Webkul/Shop/tests/Feature/Product/Prices/BundleTest.php b/packages/Webkul/Shop/tests/Feature/Product/Prices/BundleTest.php index 14caa3c997b..9edf75f2358 100644 --- a/packages/Webkul/Shop/tests/Feature/Product/Prices/BundleTest.php +++ b/packages/Webkul/Shop/tests/Feature/Product/Prices/BundleTest.php @@ -1750,8 +1750,6 @@ $this->assertPrice($cart->tax_total, $response['data']['tax_total']); - $this->assertPrice($cart->base_tax_total, $response['data']['tax_total']); - $this->assertPrice($cart->grand_total, $response['data']['grand_total']); $this->assertPrice($cart->sub_total, $response['data']['sub_total']); diff --git a/packages/Webkul/Shop/tests/Feature/Product/Prices/ConfigurableTest.php b/packages/Webkul/Shop/tests/Feature/Product/Prices/ConfigurableTest.php index 20bbc0d6874..2759308c2a0 100644 --- a/packages/Webkul/Shop/tests/Feature/Product/Prices/ConfigurableTest.php +++ b/packages/Webkul/Shop/tests/Feature/Product/Prices/ConfigurableTest.php @@ -1615,8 +1615,6 @@ $this->assertPrice($cart->tax_total, $response['data']['tax_total']); - $this->assertPrice($cart->base_tax_total, $response['data']['base_tax_total']); - $this->assertPrice($cart->grand_total, $response['data']['grand_total']); $this->assertPrice($cart->sub_total, $response['data']['sub_total']); diff --git a/packages/Webkul/Shop/tests/Feature/Product/Prices/DownloadableTest.php b/packages/Webkul/Shop/tests/Feature/Product/Prices/DownloadableTest.php index a9af46af0eb..507bf0a6ef6 100644 --- a/packages/Webkul/Shop/tests/Feature/Product/Prices/DownloadableTest.php +++ b/packages/Webkul/Shop/tests/Feature/Product/Prices/DownloadableTest.php @@ -1553,8 +1553,6 @@ ->assertOk() ->assertJsonPath('data.id', $cart->id); - $this->assertPrice($cart->base_tax_total, $response['data']['base_tax_total']); - $this->assertPrice($cart->grand_total, $response['data']['grand_total']); $this->assertPrice($product->price, $response['data']['sub_total']); diff --git a/packages/Webkul/Shop/tests/Feature/Product/Prices/GroupedTest.php b/packages/Webkul/Shop/tests/Feature/Product/Prices/GroupedTest.php index f637fd04ac5..f5056807e50 100644 --- a/packages/Webkul/Shop/tests/Feature/Product/Prices/GroupedTest.php +++ b/packages/Webkul/Shop/tests/Feature/Product/Prices/GroupedTest.php @@ -1708,8 +1708,6 @@ $this->assertPrice($cart->tax_total, $response['data']['tax_total']); - $this->assertPrice($cart->base_tax_total, $response['data']['base_tax_total']); - $this->assertPrice($cart->grand_total, $response['data']['grand_total']); $this->assertPrice($cart->sub_total, $response['data']['sub_total']); diff --git a/packages/Webkul/Shop/tests/Feature/Product/Prices/SimpleTest.php b/packages/Webkul/Shop/tests/Feature/Product/Prices/SimpleTest.php index bfc6d4753d8..406525f4f9e 100644 --- a/packages/Webkul/Shop/tests/Feature/Product/Prices/SimpleTest.php +++ b/packages/Webkul/Shop/tests/Feature/Product/Prices/SimpleTest.php @@ -1491,8 +1491,6 @@ ->assertOk() ->assertJsonPath('data.id', $cart->id); - $this->assertPrice($cart->base_tax_total, $response['data']['base_tax_total']); - $this->assertPrice($cart->tax_total, $response['data']['tax_total']); $this->assertPrice($product->price, $response['data']['sub_total']); diff --git a/packages/Webkul/Shop/tests/Feature/Product/Prices/VirtualTest.php b/packages/Webkul/Shop/tests/Feature/Product/Prices/VirtualTest.php index d4727e01a00..5db0cf2456e 100644 --- a/packages/Webkul/Shop/tests/Feature/Product/Prices/VirtualTest.php +++ b/packages/Webkul/Shop/tests/Feature/Product/Prices/VirtualTest.php @@ -1510,8 +1510,6 @@ $this->assertPrice($cart->tax_total, $response['data']['tax_total']); - $this->assertPrice($cart->base_tax_total, $response['data']['base_tax_total']); - $this->assertPrice($cart->grand_total, $response['data']['grand_total']); }); diff --git a/packages/Webkul/SocialShare/src/Resources/views/share.blade.php b/packages/Webkul/SocialShare/src/Resources/views/share.blade.php index 74eee84d8c3..3dcad170f04 100644 --- a/packages/Webkul/SocialShare/src/Resources/views/share.blade.php +++ b/packages/Webkul/SocialShare/src/Resources/views/share.blade.php @@ -9,7 +9,7 @@
@@ -28,4 +28,24 @@ {!! view_render_event('bagisto.shop.products.view.share.after', ['product' => $product]) !!}