From 06b566ad07df4b8bdc959181bfa867d969bdba13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cho=C5=82aj?= Date: Fri, 6 Sep 2024 09:22:52 +0200 Subject: [PATCH] B2B-158 (#52) * B2B-158 --- app/Http/Controllers/ProductController.php | 11 +- app/Http/Resources/OrderShortResource.php | 4 + app/Models/Order.php | 1 + app/Repositories/DiscountRepository.php | 2 +- app/Services/DiscountService.php | 154 +- app/Services/OrderService.php | 65 +- app/Services/ProductService.php | 19 +- ...024_09_04_000001_add_vat_rate_to_order.php | 37 + routes/product.php | 5 +- src/Domain/Order/Dtos/OrderPriceDto.php | 67 + .../Order/Resources/CartItemResource.php | 13 +- src/Domain/Order/Resources/CartResource.php | 24 +- .../Order/Resources/OrderProductResource.php | 5 +- .../Order/Resources/OrderPublicResource.php | 11 +- src/Domain/Order/Resources/OrderResource.php | 13 +- src/Domain/Price/Dtos/PriceDto.php | 2 +- src/Domain/PriceMap/PriceMapService.php | 8 + .../Product/Dtos/ProductVariantPriceDto.php | 7 +- .../Dtos/ProductVariantPriceDtoCollection.php | 25 + .../Resources/ProductVariantPriceResource.php | 1 + tests/Feature/CartTest.php | 1722 ++++++++++++++--- tests/Feature/Discounts/DiscountOrderTest.php | 92 +- tests/Feature/Discounts/DiscountTest.php | 16 +- tests/Feature/OrderCreateTest.php | 42 +- tests/Feature/OrderTest.php | 14 +- .../SalesChannels/SalesChannelsTest.php | 49 +- tests/Unit/DiscountApplyTest.php | 58 +- 27 files changed, 1991 insertions(+), 476 deletions(-) create mode 100644 database/migrations/2024_09_04_000001_add_vat_rate_to_order.php create mode 100644 src/Domain/Order/Dtos/OrderPriceDto.php create mode 100644 src/Domain/Product/Dtos/ProductVariantPriceDtoCollection.php diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 6efddddb3..2ccfaf79c 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -25,7 +25,7 @@ use Domain\Product\Dtos\ProductCreateDto; use Domain\Product\Dtos\ProductSearchDto; use Domain\Product\Dtos\ProductUpdateDto; -use Domain\Product\Dtos\ProductVariantPriceDto; +use Domain\Product\Dtos\ProductVariantPriceDtoCollection; use Heseya\Dto\DtoException; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; @@ -196,8 +196,13 @@ public function deleteAttachment(Product $product, MediaAttachment $attachment): return Response::noContent(); } - public function process(Request $request, Product $product, ProductVariantPriceDto $dto): HttpResponse + public function processSingle(Request $request, Product $product): HttpResponse { - return $this->productService->getPriceForVariant($product, $dto)->toResponse($request); + return $this->productService->getPriceForVariant($product, $request->input('schemas', []))->toResponse($request); + } + + public function process(Request $request, ProductVariantPriceDtoCollection $collection): HttpResponse + { + return $this->productService->getPricesForVariants($collection)->toResponse($request); } } diff --git a/app/Http/Resources/OrderShortResource.php b/app/Http/Resources/OrderShortResource.php index 242b2498f..a37ff9821 100644 --- a/app/Http/Resources/OrderShortResource.php +++ b/app/Http/Resources/OrderShortResource.php @@ -2,10 +2,14 @@ namespace App\Http\Resources; +use App\Models\Order; use App\Traits\MetadataResource; use Domain\Order\Resources\OrderStatusResource; use Illuminate\Http\Request; +/** + * @property Order $resource + */ class OrderShortResource extends Resource { use MetadataResource; diff --git a/app/Models/Order.php b/app/Models/Order.php index 81a92c37d..7c09b8695 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -77,6 +77,7 @@ final class Order extends Model implements SortableContract 'language', 'payment_method_type', 'organization_id', + 'vat_rate', ]; protected array $criteria = [ diff --git a/app/Repositories/DiscountRepository.php b/app/Repositories/DiscountRepository.php index 777b2f2e6..bf11747ef 100644 --- a/app/Repositories/DiscountRepository.php +++ b/app/Repositories/DiscountRepository.php @@ -38,7 +38,7 @@ public static function setDiscountAmounts(string $discountId, array $amounts): v 'currency' => $amount->value->getCurrency()->getCurrencyCode(), 'value' => $amount->value->getMinorAmount(), 'gross' => $amount->value->getMinorAmount(), - 'is_net' => false, + 'is_net' => true, ]; Cache::driver('array')->forget(self::getCacheKey($discountId, Currency::from($amount->value->getCurrency()->getCurrencyCode()))); } diff --git a/app/Services/DiscountService.php b/app/Services/DiscountService.php index d0cb8a826..b70a9affc 100644 --- a/app/Services/DiscountService.php +++ b/app/Services/DiscountService.php @@ -63,6 +63,7 @@ use Brick\Money\Exception\UnknownCurrencyException; use Brick\Money\Money; use Domain\Currency\Currency; +use Domain\Order\Dtos\OrderPriceDto; use Domain\Order\Resources\CartItemResource; use Domain\Order\Resources\CartResource; use Domain\Order\Resources\CouponShortResource; @@ -338,6 +339,9 @@ public function calcOrderShippingDiscounts(Order $order, OrderDto $orderDto): Or } /** + * Calculate prices and discounts in Cart + * All discounts are applied to Net prices. + * * @param Collection $products * * @throws MathException @@ -384,20 +388,27 @@ public function calcCartDiscounts(CartDto $cart, Collection $products, BigDecima } $price = $product->mappedPriceForPriceMap($priceMap)->value; + if (!$priceMap->is_net) { + $price = $this->salesChannelService->removeVat($price, $vat_rate); + } foreach ($cartItem->getSchemas() as $schemaId => $value) { /** @var Schema $schema */ $schema = $product->schemas()->findOrFail($schemaId); - $price = $price->plus( - $schema->getPrice($value, $cartItem->getSchemas(), $currency), - ); + $option_price = $schema->getPrice($value, $cartItem->getSchemas(), $priceMap); + if (!$priceMap->is_net) { + $option_price = $this->salesChannelService->removeVat($option_price, $vat_rate); + } + + $price = $price->plus($option_price); } $cartValue = $cartValue->plus($price->multipliedBy($cartItem->getQuantity())); + $cartItems[] = new CartItemResource( $cartItem->getCartItemId(), - $price, - $price, + OrderPriceDto::from($price, $vat_rate), + OrderPriceDto::from($price, $vat_rate), Currency::from($price->getCurrency()->getCurrencyCode()), $cartItem->getQuantity(), ); @@ -413,11 +424,11 @@ public function calcCartDiscounts(CartDto $cart, Collection $products, BigDecima CartItemResource::collection($cartItems), CouponShortResource::collection([]), SalesShortResource::collection([]), - $cartValue, - $cartValue, - $shippingPrice, - $shippingPrice, - $summary, + OrderPriceDto::from($cartValue, $vat_rate), + OrderPriceDto::from($cartValue, $vat_rate), + OrderPriceDto::from($shippingPrice, $vat_rate), + OrderPriceDto::from($shippingPrice, $vat_rate), + OrderPriceDto::from($summary, $vat_rate), $currency, $cartShippingTimeAndDate['shipping_time'] ?? null, $cartShippingTimeAndDate['shipping_date'] ?? null, @@ -430,10 +441,10 @@ public function calcCartDiscounts(CartDto $cart, Collection $products, BigDecima foreach ($discounts as $discount) { if ( $this->checkDiscountTarget($discount, $cart) - && $this->checkConditionGroups($discount, $cart, $cartResource->cart_total) + && $this->checkConditionGroups($discount, $cart, $cartResource->cart_total->net) ) { $cartResource = $this->applyDiscountOnCart($discount, $cart, $cartResource); - $newSummary = $cartResource->cart_total->plus($cartResource->shipping_price); + $newSummary = $cartResource->cart_total->net->plus($cartResource->shipping_price->net); $appliedDiscount = $summary->minus($newSummary); $cartResource = $this->addDiscountToCartResource($appliedDiscount, $discount, $cartResource); @@ -441,38 +452,32 @@ public function calcCartDiscounts(CartDto $cart, Collection $products, BigDecima } } - $shippingPrice = $shippingMethod?->getPrice($summary) ?? Money::zero($currency->value); - $shippingPrice = $shippingPrice->plus( - $shippingMethodDigital?->getPrice($summary) ?? Money::zero($currency->value), - ); + $shippingPrice = Money::zero($currency->value); + if ($shippingMethod !== null) { + $shippingPrice = $shippingPrice->plus($shippingMethod->getPrice($summary)); + } + if ($shippingMethodDigital !== null) { + $shippingPrice = $shippingPrice->plus($shippingMethodDigital->getPrice($summary)); + } + $shippingPrice = $this->salesChannelService->removeVat($shippingPrice, $vat_rate); - $cartResource->summary = $cartValue->plus($shippingPrice); - $cartResource->shipping_price_initial = $shippingPrice; - $cartResource->shipping_price = $shippingPrice; + $cartResource->summary = OrderPriceDto::from($cartValue->plus($shippingPrice), $vat_rate); + $cartResource->shipping_price_initial = OrderPriceDto::from($shippingPrice, $vat_rate); + $cartResource->shipping_price = OrderPriceDto::from($shippingPrice, $vat_rate); foreach ($discounts->filter(fn ($discount) => $discount->target_type === DiscountTargetType::SHIPPING_PRICE) as $discount) { if ( $this->checkShippingPriceTarget($discount, $cart) - && $this->checkConditionGroups($discount, $cart, $cartResource->cart_total) + && $this->checkConditionGroups($discount, $cart, $cartResource->cart_total->net) ) { $oldShipping = $cartResource->shipping_price; $cartResource = $this->applyDiscountOnCart($discount, $cart, $cartResource); - $appliedDiscount = $oldShipping->minus($cartResource->shipping_price); + $appliedDiscount = $oldShipping->net->minus($cartResource->shipping_price->net); $cartResource = $this->addDiscountToCartResource($appliedDiscount, $discount, $cartResource); } } - foreach ($cartResource->items as $item) { - $item->price = $this->salesChannelService->addVat($item->price, $vat_rate); - $item->price_discounted = $this->salesChannelService->addVat($item->price_discounted, $vat_rate); - } - - $cartResource->cart_total_initial = $this->salesChannelService->addVat( - $cartResource->cart_total_initial, - $vat_rate, - ); - $cartResource->cart_total = $this->salesChannelService->addVat($cartResource->cart_total, $vat_rate); - $cartResource->summary = $cartResource->cart_total->plus($cartResource->shipping_price); + $cartResource->summary = OrderPriceDto::from($cartResource->cart_total->net->plus($cartResource->shipping_price->net), $vat_rate); return $cartResource; } @@ -651,10 +656,13 @@ public function applyDiscountOnCartItem( fn (CartItemResource $value) => $value->cartitem_id === $cartItem->getCartItemId(), )->first(); - $result->price_discounted = $this->calcPrice( - $result->price_discounted, - $cartItem->getProductId(), - $discount, + $result->price_discounted = OrderPriceDto::from( + $this->calcPrice( + $result->price_discounted->net, + $cartItem->getProductId(), + $discount, + ), + $result->price_discounted->vat_rate, ); return $result; @@ -727,7 +735,7 @@ public function applyAllDiscountsOnProduct( $newPrice = $this->calcAllDiscountsOnProduct($product, $sales, $salesChannel); - if ($oldPrice === null || !$oldPrice->gross->isEqualTo($newPrice->gross)) { + if ($oldPrice === null || !$oldPrice->net->isEqualTo($newPrice->net)) { $allNewPrices[] = $newPrice; } } @@ -1102,24 +1110,24 @@ public function calcAllDiscountsOnProductVariant( if ($initialPrice === null) { $basePrice = $product->mappedPriceForPriceMap($priceMap); - $gross = $priceMap->is_net ? $this->salesChannelService->addVat($basePrice->value, $this->salesChannelService->getVatRate($salesChannel)) : $basePrice->value; + $net = $priceMap->is_net ? $basePrice->value : $this->salesChannelService->removeVat($basePrice->value, $this->salesChannelService->getVatRate($salesChannel)); } else { - $gross = $initialPrice->gross; + $net = $initialPrice->net; } foreach ($schemas as $schemaId => $optionId) { /** @var Schema $schema */ $schema = $product->schemas()->findOrFail($schemaId); - $schema_price = $schema->getPrice($optionId, $schemas, $priceMap->currency); - if ($priceMap->is_net) { - $schema_price = $this->salesChannelService->addVat($schema_price, $this->salesChannelService->getVatRate($salesChannel)); + $schema_price = $schema->getPrice($optionId, $schemas, $priceMap); + if (!$priceMap->is_net) { + $schema_price = $this->salesChannelService->removeVat($schema_price, $this->salesChannelService->getVatRate($salesChannel)); } - $gross = $gross->plus($schema_price); + $net = $net->plus($schema_price); } - $minPrice = $gross; + $minPrice = $net; foreach ($sales as $sale) { if ($minPrice->isGreaterThan($minimalProductPrice)) { $minPrice = $this->calcProductPriceDiscount($sale, $minPrice, $minimalProductPrice); @@ -1127,8 +1135,8 @@ public function calcAllDiscountsOnProductVariant( } return ProductCachedPriceDto::from([ - 'net' => $this->salesChannelService->removeVat($minPrice, $this->salesChannelService->getVatRate($salesChannel)), - 'gross' => $minPrice, + 'net' => $minPrice, + 'gross' => $this->salesChannelService->addVat($minPrice, $this->salesChannelService->getVatRate($salesChannel)), 'currency' => $priceMap->currency, 'sales_channel_id' => $salesChannel->id, ]); @@ -1188,8 +1196,6 @@ private function calcOrderDiscounts(Order $order, OrderDto $orderDto, array $tar $order = $this->roundProductPrices($order); } - // $order->cart_total = round($order->cart_total, 2, PHP_ROUND_HALF_UP); - // $order->shipping_price = round($order->shipping_price, 2, PHP_ROUND_HALF_UP); $order->summary = $order->cart_total->plus($order->shipping_price); $order->paid = $order->summary->isLessThanOrEqualTo(0); @@ -1209,7 +1215,6 @@ private function roundProductPrices(Order $order): Order $order->refresh(); $totalPrice = Money::zero($order->currency->value); foreach ($order->products as $product) { - // $product->price = round($product->price, 2, PHP_ROUND_HALF_UP); $totalPrice = $totalPrice->plus($product->price->multipliedBy($product->quantity)); } @@ -1354,7 +1359,7 @@ private function applyDiscountOnOrderCheapestProduct(Order $order, Discount $dis 'price_initial' => $product->price_initial, 'base_price' => $product->price, 'base_price_initial' => $product->price, - 'vat_rate' => 0, // TODO: add VAT form sales channel + 'vat_rate' => $product->vat_rate, ]); foreach ($product->schemas as $schema) { @@ -1420,14 +1425,16 @@ private function applyDiscountOnCartShipping( $discount->shippingMethods->pluck('id')->toArray(), ) === $discount->target_is_allow_list ) { - $cartResource->shipping_price = $cartResource->shipping_price->minus( - $this->calcAppliedDiscount( - $cartResource->shipping_price, - $this->calc($cartResource->shipping_price, $discount), - 'minimal_shipping_price', + $cartResource->shipping_price = OrderPriceDto::from( + $cartResource->shipping_price->net->minus( + $this->calcAppliedDiscount( + $cartResource->shipping_price->net, + $this->calc($cartResource->shipping_price->net, $discount), + 'minimal_shipping_price', + ), ), + $cartResource->shipping_price->vat_rate, ); - // $cartResource->shipping_price = round($cartResource->shipping_price, 2, PHP_ROUND_HALF_UP); } return $cartResource; @@ -1443,16 +1450,17 @@ private function applyDiscountOnCartShipping( */ private function applyDiscountOnCartTotal(Discount $discount, CartResource $cartResource): CartResource { - $cartResource->cart_total = $cartResource->cart_total->minus( - $this->calcAppliedDiscount( - $cartResource->cart_total, - $this->calc($cartResource->cart_total, $discount), - 'minimal_order_price', + $cartResource->cart_total = OrderPriceDto::from( + $cartResource->cart_total->net->minus( + $this->calcAppliedDiscount( + $cartResource->cart_total->net, + $this->calc($cartResource->cart_total->net, $discount), + 'minimal_order_price', + ), ), + $cartResource->cart_total->vat_rate, ); - // $cartResource->cart_total = round($cartResource->cart_total, 2, PHP_ROUND_HALF_UP); - return $cartResource; } @@ -1482,11 +1490,11 @@ private function applyDiscountOnCartItems(Discount $discount, CartDto $cartDto, $cartItems[] = $cartItem; - $cartValue = $cartValue->plus($cartItem->price_discounted->multipliedBy($item->getQuantity())); + $cartValue = $cartValue->plus($cartItem->price_discounted->net->multipliedBy($item->getQuantity())); } $cart->items = CartItemResource::collection($cartItems); - $cart->cart_total = $cartValue; + $cart->cart_total = OrderPriceDto::from($cartValue, $cart->cart_total->vat_rate); return $cart; } @@ -1512,9 +1520,9 @@ private function applyDiscountOnCartCheapestItem( return $cart; } - $minimalProductPrice = Money::ofMinor(1, $cartItem->price_discounted->getCurrency()); + $minimalProductPrice = Money::ofMinor(1, $cartItem->price_discounted->currency->toCurrencyInstance()); - if ($cartItem->quantity > 1 && !$cartItem->price_discounted->isEqualTo($minimalProductPrice)) { + if ($cartItem->quantity > 1 && !$cartItem->price_discounted->net->isLessThanOrEqualTo($minimalProductPrice)) { $cart->items = $cart->items->through(function (CartItemResource $value) use ($cartItem): CartItemResource { if ($value->cartitem_id === $cartItem->cartitem_id && $value->quantity === $cartItem->quantity) { $value->quantity = $cartItem->quantity - 1; @@ -1533,18 +1541,14 @@ private function applyDiscountOnCartCheapestItem( $cart->items[] = $cartItem; } - $price = $cartItem->price_discounted; + $price = $cartItem->price_discounted->net; - if (!$price->isEqualTo($minimalProductPrice)) { - // $newPrice = round($price - $this->calc($priceAsMoney, $discount)->getAmount()->toFloat(), 2, PHP_ROUND_HALF_UP); + if (!$price->isLessThanOrEqualTo($minimalProductPrice)) { $newPrice = $price->minus($this->calc($price, $discount)); - $cartItem->price_discounted = Money::max($newPrice, $minimalProductPrice); + $cartItem->price_discounted = OrderPriceDto::from(Money::max($newPrice, $minimalProductPrice), $cartItem->price_discounted->vat_rate); - // $cart->cart_total -= ($price - $cartItem->price_discounted) * $cartItem->quantity; - $cart->cart_total = $cart->cart_total->minus( - $price->minus($cartItem->price_discounted)->multipliedBy($cartItem->quantity), - ); + $cart->cart_total = OrderPriceDto::from($cart->cart_total->net->minus($price->minus($cartItem->price_discounted->net)->multipliedBy($cartItem->quantity)), $cart->cart_total->vat_rate); } return $cart; diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index c31c78ccf..efb3c5a3d 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -28,6 +28,7 @@ use App\Models\Option; use App\Models\Order; use App\Models\OrderProduct; +use App\Models\OrderSchema; use App\Models\Payment; use App\Models\Product; use App\Models\Status; @@ -206,6 +207,7 @@ public function store(OrderDto $dto): Order 'shipping_place' => $shippingPlace, 'shipping_type' => $shippingMethod->shipping_type ?? $digitalShippingMethod->shipping_type ?? null, 'payment_method_type' => $paymentMethod->type, + 'vat_rate' => $vat_rate, ] + $dto->toArray(), ); @@ -221,6 +223,9 @@ public function store(OrderDto $dto): Order $product = $products->firstWhere('id', $item->getProductId()); $price = $product->mappedPriceForPriceMap($priceMap)->value; + if (!$priceMap->is_net) { + $price = $this->salesChannelService->removeVat($price, $vat_rate); + } $orderProduct = new OrderProduct([ 'product_id' => $item->getProductId(), @@ -243,14 +248,19 @@ public function store(OrderDto $dto): Order foreach ($item->getSchemas() as $schemaId => $value) { /** @var Schema $schema */ $schema = $product->schemas()->findOrFail($schemaId); - $price = $schema->getPrice($value, $item->getSchemas(), $currency); + + $price = $schema->getPrice($value, $item->getSchemas(), $priceMap); + if (!$priceMap->is_net) { + $price = $this->salesChannelService->removeVat($price, $vat_rate); + } /** @var Option $option */ $option = $schema->options()->findOrFail($value); $tempSchemaOrderProduct[$schema->name . '_' . $item->getProductId()] = [$schemaId, $value]; $value = $option->name; - $orderProduct->schemas()->create([ + /** @var OrderSchema $orderSchema */ + $orderSchema = $orderProduct->schemas()->create([ 'name' => $schema->getTranslation('name', $language), 'value' => $value, 'price_initial' => $price, @@ -279,10 +289,13 @@ public function store(OrderDto $dto): Order // Apply discounts to order/products $order = $this->discountService->calcOrderProductsAndTotalDiscounts($order, $dto); - $shippingPrice = $shippingMethod?->getPrice($order->cart_total) ?? Money::zero($currency->value); - $shippingPrice = $shippingPrice->plus( - $digitalShippingMethod?->getPrice($order->cart_total) ?? Money::zero($currency->value), - ); + $shippingPrice = Money::zero($currency->value); + if ($shippingMethod !== null) { + $shippingPrice = $shippingPrice->plus($shippingMethod->getPrice($order->cart_total)); + } + if ($digitalShippingMethod !== null) { + $shippingPrice = $shippingPrice->plus($digitalShippingMethod->getPrice($order->cart_total)); + } // Always gross $order->shipping_price_initial = $shippingPrice; @@ -298,30 +311,15 @@ public function store(OrderDto $dto): Order throw new OrderException(Exceptions::ORDER_NOT_ENOUGH_ITEMS_IN_WAREHOUSE); } - $orderProduct->base_price_initial = $this->salesChannelService->addVat( - $orderProduct->base_price_initial, - $vat_rate, - ); - $orderProduct->base_price = $this->salesChannelService->addVat( - $orderProduct->base_price, - $vat_rate, - ); - $orderProduct->price_initial = $this->salesChannelService->addVat( - $orderProduct->price_initial, - $vat_rate, - ); - $orderProduct->price = $this->salesChannelService->addVat( - $orderProduct->price, - $vat_rate, - ); + $orderProduct->base_price_initial = $this->salesChannelService->addVat($orderProduct->base_price_initial, $vat_rate); + $orderProduct->base_price = $this->salesChannelService->addVat($orderProduct->base_price, $vat_rate); + $orderProduct->price_initial = $this->salesChannelService->addVat($orderProduct->price_initial, $vat_rate); + $orderProduct->price = $this->salesChannelService->addVat($orderProduct->price, $vat_rate); /** @var Discount $discount */ foreach ($orderProduct->discounts as $discount) { if ($discount->order_discount?->applied !== null) { - $discount->order_discount->applied = $this->salesChannelService->addVat( - $discount->order_discount->applied, - $vat_rate, - ); + $discount->order_discount->applied = $this->salesChannelService->addVat($discount->order_discount->applied, $vat_rate); $discount->order_discount->save(); } } @@ -330,22 +328,13 @@ public function store(OrderDto $dto): Order /** @var Discount $discount */ foreach ($order->discounts as $discount) { if ($discount->order_discount?->applied !== null) { - $discount->order_discount->applied = $this->salesChannelService->addVat( - $discount->order_discount->applied, - $vat_rate, - ); + $discount->order_discount->applied = $this->salesChannelService->addVat($discount->order_discount->applied, $vat_rate); $discount->order_discount->save(); } } - $order->cart_total_initial = $this->salesChannelService->addVat( - $order->cart_total_initial, - $vat_rate, - ); - $order->cart_total = $this->salesChannelService->addVat( - $order->cart_total, - $vat_rate, - ); + $order->cart_total_initial = $this->salesChannelService->addVat($order->cart_total_initial, $vat_rate); + $order->cart_total = $this->salesChannelService->addVat($order->cart_total, $vat_rate); // shipping price magic 🙈 $order->summary = $order->shipping_price->plus($order->cart_total); diff --git a/app/Services/ProductService.php b/app/Services/ProductService.php index 4ebb5f386..1e3701165 100644 --- a/app/Services/ProductService.php +++ b/app/Services/ProductService.php @@ -30,7 +30,7 @@ use Domain\Product\Dtos\ProductCreateDto; use Domain\Product\Dtos\ProductSearchDto; use Domain\Product\Dtos\ProductUpdateDto; -use Domain\Product\Dtos\ProductVariantPriceDto; +use Domain\Product\Dtos\ProductVariantPriceDtoCollection; use Domain\Product\Models\ProductBannerMedia; use Domain\Product\Resources\ProductVariantPriceResource; use Domain\ProductAttribute\Models\Attribute; @@ -192,7 +192,17 @@ public function updateInitialPricesForSalesChannels(Product $product, Collection $this->priceService->setCachedProductPrices($product->getKey(), [ProductPriceType::PRICE_INITIAL->value => $prices]); } - public function getPriceForVariant(Product $product, ProductVariantPriceDto $dto, bool $calculateForCurrentUser = false): ProductVariantPriceResource + public function getPricesForVariants(ProductVariantPriceDtoCollection $collection, bool $calculateForCurrentUser = false): DataCollection + { + $items = []; + foreach ($collection->items() as $dto) { + $items[] = $this->getPriceForVariant(Product::query()->findOrFail($dto->product_id), is_array($dto->schemas) ? $dto->schemas : [], $calculateForCurrentUser); + } + + return ProductVariantPriceResource::collection($items); + } + + public function getPriceForVariant(Product $product, array $schemas, bool $calculateForCurrentUser = false): ProductVariantPriceResource { $salesChannel = $this->salesChannelService->getCurrentRequestSalesChannel(); $priceMap = $salesChannel->priceMap; @@ -203,14 +213,15 @@ public function getPriceForVariant(Product $product, ProductVariantPriceDto $dto $price_initial = $product->mappedPriceForPriceMap($priceMap); - if (is_array($dto->schemas) && !empty($dto->schemas)) { + if (!empty($schemas)) { $sales = $this->discountService->getAllAplicableSalesForProduct($product, $this->discountService->getSalesWithBlockList(), $calculateForCurrentUser); - $price = $this->discountService->calcAllDiscountsOnProductVariant($product, $sales, $salesChannel, $dto->schemas); + $price = $this->discountService->calcAllDiscountsOnProductVariant($product, $sales, $salesChannel, $schemas); } else { $price = ProductCachedPriceDto::from($price_initial, $salesChannel); } return ProductVariantPriceResource::from([ + 'product_id' => $product->id, 'price_initial' => ProductCachedPriceDto::from($price_initial, $salesChannel), 'price' => $price, ]); diff --git a/database/migrations/2024_09_04_000001_add_vat_rate_to_order.php b/database/migrations/2024_09_04_000001_add_vat_rate_to_order.php new file mode 100644 index 000000000..5730c3c17 --- /dev/null +++ b/database/migrations/2024_09_04_000001_add_vat_rate_to_order.php @@ -0,0 +1,37 @@ +string('vat_rate', 9)->default('0'); + }); + + Order::query()->with('salesChannel')->chunkById(100, function (Collection $orders) { + /** @var Order $order */ + foreach ($orders as $order) { + $order->update(['vat_rate' => $order->salesChannel?->vat_rate ?? '0']); + } + }); + + Schema::table('prices', function (Blueprint $table) { + $table->boolean('is_net')->default(true)->change(); + }); + } + + public function down(): void + { + Schema::table('orders', function (Blueprint $table) { + $table->dropColumn('vat_rate'); + }); + } +}; diff --git a/routes/product.php b/routes/product.php index 2b1598c8f..9f7f22ff9 100644 --- a/routes/product.php +++ b/routes/product.php @@ -31,6 +31,9 @@ Route::delete('id:{product:id}/attachments/id:{attachment:id}', [ProductController::class, 'deleteAttachment']) ->middleware('can:products.edit'); - Route::post('id:{product:id}/process', [ProductController::class, 'process']) + Route::post('id:{product:id}/process', [ProductController::class, 'processSingle']) + ->middleware('can:products.show', 'can:cart.verify'); + + Route::post('/process', [ProductController::class, 'process']) ->middleware('can:products.show', 'can:cart.verify'); }); diff --git a/src/Domain/Order/Dtos/OrderPriceDto.php b/src/Domain/Order/Dtos/OrderPriceDto.php new file mode 100644 index 000000000..d7ac38b7d --- /dev/null +++ b/src/Domain/Order/Dtos/OrderPriceDto.php @@ -0,0 +1,67 @@ +vat_rate = $this->vat_rate->toScale(2, RoundingMode::HALF_UP); + } + + public static function fromMoneyAndSalesChannel(Money $price, SalesChannel $salesChannel, bool $is_net = true): self + { + if ($salesChannel->priceMap === null) { + throw new InvalidArgumentException(); + } + + return self::fromMoneyAndVatRate($price, app(SalesChannelService::class)->getVatRate($salesChannel), $is_net); + } + + public static function fromMoneyAndVatRate(Money $price, BigDecimal|float|string $vat_rate, bool $is_net = true): self + { + if (!$vat_rate instanceof BigDecimal) { + $vat_rate = BigDecimal::of($vat_rate)->multipliedBy(0.01)->abs(); + } + + if ($is_net) { + $net = $price; + $gross = app(SalesChannelService::class)->addVat($price, $vat_rate); + } else { + $net = app(SalesChannelService::class)->removeVat($price, $vat_rate); + $gross = $price; + } + + return self::from([ + 'net' => $net, + 'gross' => $gross, + 'currency' => $price->getCurrency()->getCurrencyCode(), + 'vat_rate' => $vat_rate, + ]); + } +} diff --git a/src/Domain/Order/Resources/CartItemResource.php b/src/Domain/Order/Resources/CartItemResource.php index 2dff6c7d6..44d687cfd 100644 --- a/src/Domain/Order/Resources/CartItemResource.php +++ b/src/Domain/Order/Resources/CartItemResource.php @@ -4,25 +4,18 @@ namespace Domain\Order\Resources; -use Brick\Money\Money; use Domain\Currency\Currency; +use Domain\Order\Dtos\OrderPriceDto; use Spatie\LaravelData\Attributes\WithCast; -use Spatie\LaravelData\Attributes\WithTransformer; use Spatie\LaravelData\Casts\EnumCast; use Support\Dtos\DataWithGlobalMetadata; -use Support\LaravelData\Casts\MoneyCast; -use Support\LaravelData\Transformers\MoneyToAmountTransformer; final class CartItemResource extends DataWithGlobalMetadata { public function __construct( public string $cartitem_id, - #[WithTransformer(MoneyToAmountTransformer::class)] - #[WithCast(MoneyCast::class)] - public Money $price, - #[WithTransformer(MoneyToAmountTransformer::class)] - #[WithCast(MoneyCast::class)] - public Money $price_discounted, + public OrderPriceDto $price, + public OrderPriceDto $price_discounted, #[WithCast(EnumCast::class, Currency::class)] public Currency $currency, public float $quantity, diff --git a/src/Domain/Order/Resources/CartResource.php b/src/Domain/Order/Resources/CartResource.php index a105f6d26..b191fe726 100644 --- a/src/Domain/Order/Resources/CartResource.php +++ b/src/Domain/Order/Resources/CartResource.php @@ -4,9 +4,9 @@ namespace Domain\Order\Resources; -use Brick\Money\Money; use Carbon\Carbon; use Domain\Currency\Currency; +use Domain\Order\Dtos\OrderPriceDto; use Illuminate\Http\Request; use Illuminate\Http\Response; use Spatie\LaravelData\Attributes\DataCollectionOf; @@ -16,8 +16,6 @@ use Spatie\LaravelData\Casts\EnumCast; use Spatie\LaravelData\DataCollection; use Support\Dtos\DataWithGlobalMetadata; -use Support\LaravelData\Casts\MoneyCast; -use Support\LaravelData\Transformers\MoneyToAmountTransformer; use Support\LaravelData\Transformers\WithoutWrappingTransformer; final class CartResource extends DataWithGlobalMetadata @@ -37,21 +35,11 @@ public function __construct( #[WithTransformer(WithoutWrappingTransformer::class)] #[DataCollectionOf(SalesShortResource::class)] public DataCollection $sales, - #[WithTransformer(MoneyToAmountTransformer::class)] - #[WithCast(MoneyCast::class)] - public Money $cart_total_initial, - #[WithTransformer(MoneyToAmountTransformer::class)] - #[WithCast(MoneyCast::class)] - public Money $cart_total, - #[WithTransformer(MoneyToAmountTransformer::class)] - #[WithCast(MoneyCast::class)] - public Money $shipping_price_initial, - #[WithTransformer(MoneyToAmountTransformer::class)] - #[WithCast(MoneyCast::class)] - public Money $shipping_price, - #[WithTransformer(MoneyToAmountTransformer::class)] - #[WithCast(MoneyCast::class)] - public Money $summary, + public OrderPriceDto $cart_total_initial, + public OrderPriceDto $cart_total, + public OrderPriceDto $shipping_price_initial, + public OrderPriceDto $shipping_price, + public OrderPriceDto $summary, #[WithCast(EnumCast::class, Currency::class)] public Currency $currency, public ?float $shipping_time = null, diff --git a/src/Domain/Order/Resources/OrderProductResource.php b/src/Domain/Order/Resources/OrderProductResource.php index 260226e23..855fd9060 100644 --- a/src/Domain/Order/Resources/OrderProductResource.php +++ b/src/Domain/Order/Resources/OrderProductResource.php @@ -8,6 +8,7 @@ use App\Http\Resources\OrderSchemaResource; use App\Http\Resources\Resource; use App\Models\OrderProduct; +use Domain\Order\Dtos\OrderPriceDto; use Illuminate\Http\Request; /** @@ -24,8 +25,8 @@ public function base(Request $request): array 'id' => $this->resource->getKey(), 'name' => $this->resource->name, 'quantity' => (float) $this->resource->quantity, - 'price' => $this->resource->price->getAmount(), - 'price_initial' => $this->resource->price_initial->getAmount(), + 'price' => OrderPriceDto::from($this->resource->price, $this->resource->vat_rate, false), + 'price_initial' => OrderPriceDto::from($this->resource->price_initial, $this->resource->vat_rate, false), 'vat_rate' => $this->resource->vat_rate, 'schemas' => OrderSchemaResource::collection($this->resource->schemas), 'deposits' => OrderDepositResource::collection($this->resource->deposits), diff --git a/src/Domain/Order/Resources/OrderPublicResource.php b/src/Domain/Order/Resources/OrderPublicResource.php index ad506bc24..542efb700 100644 --- a/src/Domain/Order/Resources/OrderPublicResource.php +++ b/src/Domain/Order/Resources/OrderPublicResource.php @@ -7,6 +7,7 @@ use App\Http\Resources\Resource; use App\Models\Order; use App\Traits\MetadataResource; +use Domain\Order\Dtos\OrderPriceDto; use Illuminate\Http\Request; /** @@ -27,11 +28,11 @@ public function base(Request $request): array 'status' => OrderStatusResource::make($this->resource->status), 'paid' => $this->resource->paid, 'payable' => $this->resource->payable, - 'cart_total_initial' => $this->resource->cart_total_initial->getAmount(), - 'cart_total' => $this->resource->cart_total->getAmount(), - 'shipping_price_initial' => $this->resource->shipping_price_initial->getAmount(), - 'shipping_price' => $this->resource->shipping_price->getAmount(), - 'summary' => $this->resource->summary->getAmount(), + 'cart_total_initial' => OrderPriceDto::from($this->resource->cart_total_initial, $this->resource->vat_rate, false), + 'cart_total' => OrderPriceDto::from($this->resource->cart_total, $this->resource->vat_rate, false), + 'shipping_price_initial' => OrderPriceDto::from($this->resource->shipping_price_initial, $this->resource->vat_rate, false), + 'shipping_price' => OrderPriceDto::from($this->resource->shipping_price, $this->resource->vat_rate, false), + 'summary' => OrderPriceDto::from($this->resource->summary, $this->resource->vat_rate, false), 'currency' => $this->resource->currency, 'shipping_method' => OrderShippingMethodResource::make($this->resource->shippingMethod), 'digital_shipping_method' => OrderShippingMethodResource::make($this->resource->digitalShippingMethod), diff --git a/src/Domain/Order/Resources/OrderResource.php b/src/Domain/Order/Resources/OrderResource.php index 1ad87ee5d..9b611d589 100644 --- a/src/Domain/Order/Resources/OrderResource.php +++ b/src/Domain/Order/Resources/OrderResource.php @@ -17,6 +17,7 @@ use App\Traits\MetadataResource; use Brick\Math\Exception\MathException; use Brick\Money\Exception\MoneyMismatchException; +use Domain\Order\Dtos\OrderPriceDto; use Domain\Organization\Resources\OrganizationResource; use Domain\PaymentMethods\Resources\PaymentMethodResource; use Illuminate\Http\Request; @@ -40,10 +41,10 @@ public function base(Request $request): array 'email' => $this->resource->email, 'payable' => $this->resource->payable, 'currency' => $this->resource->currency, - 'summary' => $this->resource->summary->getAmount(), - 'summary_paid' => $this->resource->paid_amount->getAmount(), - 'shipping_price_initial' => $this->resource->shipping_price_initial->getAmount(), - 'shipping_price' => $this->resource->shipping_price->getAmount(), + 'summary' => OrderPriceDto::from($this->resource->summary, $this->resource->vat_rate, false), + 'summary_paid' => OrderPriceDto::from($this->resource->paid_amount, $this->resource->vat_rate, false), + 'shipping_price_initial' => OrderPriceDto::from($this->resource->shipping_price_initial, $this->resource->vat_rate, false), + 'shipping_price' => OrderPriceDto::from($this->resource->shipping_price, $this->resource->vat_rate, false), 'comment' => $this->resource->comment, 'status' => $this->resource->status ? OrderStatusResource::make($this->resource->status) : null, 'shipping_method' => $this->resource->shippingMethod ? @@ -58,8 +59,8 @@ public function base(Request $request): array : $this->resource->shipping_place, 'documents' => OrderDocumentResource::collection($this->resource->documents->pluck('pivot')), 'paid' => $this->resource->paid, - 'cart_total' => $this->resource->cart_total->getAmount(), - 'cart_total_initial' => $this->resource->cart_total_initial->getAmount(), + 'cart_total' => OrderPriceDto::from($this->resource->cart_total, $this->resource->vat_rate, false), + 'cart_total_initial' => OrderPriceDto::from($this->resource->cart_total_initial, $this->resource->vat_rate, false), 'created_at' => $this->resource->created_at, 'sales_channel' => OrderSalesChannelResource::make($this->resource->salesChannel), 'language' => $this->resource->language, diff --git a/src/Domain/Price/Dtos/PriceDto.php b/src/Domain/Price/Dtos/PriceDto.php index cd77e36db..d8d809e50 100644 --- a/src/Domain/Price/Dtos/PriceDto.php +++ b/src/Domain/Price/Dtos/PriceDto.php @@ -22,7 +22,7 @@ public function __construct( public Money $value, #[WithCast(EnumCast::class, Currency::class)] public Currency $currency, - public bool $is_net = false, + public bool $is_net = true, ) {} public static function fromModel(Price $price): self diff --git a/src/Domain/PriceMap/PriceMapService.php b/src/Domain/PriceMap/PriceMapService.php index 044dc44f5..72fe428cf 100644 --- a/src/Domain/PriceMap/PriceMapService.php +++ b/src/Domain/PriceMap/PriceMapService.php @@ -101,6 +101,14 @@ public function update(PriceMap $priceMap, PriceMapUpdateDto $dto): PriceMap { $priceMap->fill($dto->toArray())->save(); + if ($priceMap->wasChanged('currency')) { + $priceMap->productPrices()->update([ + 'currency' => $priceMap->currency->value, + ]); + $priceMap->schemaOptionsPrices()->update([ + 'currency' => $priceMap->currency->value, + ]); + } if ($priceMap->wasChanged('is_net')) { foreach ($priceMap->salesChannels as $salesChannel) { dispatch(new RefreshCachedPricesForSalesChannel($salesChannel)); diff --git a/src/Domain/Product/Dtos/ProductVariantPriceDto.php b/src/Domain/Product/Dtos/ProductVariantPriceDto.php index 3de5f0617..6fb9f4f48 100644 --- a/src/Domain/Product/Dtos/ProductVariantPriceDto.php +++ b/src/Domain/Product/Dtos/ProductVariantPriceDto.php @@ -4,15 +4,18 @@ namespace Domain\Product\Dtos; +use Spatie\LaravelData\Attributes\Validation\Exists; use Spatie\LaravelData\Data; use Spatie\LaravelData\Optional; final class ProductVariantPriceDto extends Data { /** - * @param array|Optional $schemas + * @param array|Optional|null $schemas */ public function __construct( - public array|Optional $schemas, + #[Exists('products', 'id')] + public string $product_id, + public array|Optional|null $schemas, ) {} } diff --git a/src/Domain/Product/Dtos/ProductVariantPriceDtoCollection.php b/src/Domain/Product/Dtos/ProductVariantPriceDtoCollection.php new file mode 100644 index 000000000..b43efdcdd --- /dev/null +++ b/src/Domain/Product/Dtos/ProductVariantPriceDtoCollection.php @@ -0,0 +1,25 @@ + + */ +final class ProductVariantPriceDtoCollection extends DataCollection +{ + /** + * @param DataCollection|array|array> $items + */ + public function __construct( + string $dataClass = ProductVariantPriceDto::class, + array|DataCollection|Enumerable|null $items = null, + ) { + $dataClass = ProductVariantPriceDto::class; + parent::__construct($dataClass, $items); + } +} diff --git a/src/Domain/Product/Resources/ProductVariantPriceResource.php b/src/Domain/Product/Resources/ProductVariantPriceResource.php index 711c9e03e..08e0dba17 100644 --- a/src/Domain/Product/Resources/ProductVariantPriceResource.php +++ b/src/Domain/Product/Resources/ProductVariantPriceResource.php @@ -12,6 +12,7 @@ final class ProductVariantPriceResource extends Data { public function __construct( + public string $product_id, public ProductCachedPriceDto $price, public ProductCachedPriceDto $price_initial, ) {} diff --git a/tests/Feature/CartTest.php b/tests/Feature/CartTest.php index 257bb5924..c80a2b7ae 100644 --- a/tests/Feature/CartTest.php +++ b/tests/Feature/CartTest.php @@ -241,18 +241,53 @@ public function testCartProcessSimple($user): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '9200.00', - 'cart_total' => '9200.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '9200.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -294,23 +329,68 @@ public function testCartProcessWithMultipleSchemas(string $user): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '300.00', - 'cart_total' => '300.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '300.00', + 'cart_total_initial' => [ + 'net' => '300.00', + 'gross' => '300.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '300.00', + 'gross' => '300.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '300.00', + 'gross' => '300.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '100.00', - 'price_discounted' => '100.00', + 'price' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '2', - 'price' => '200.00', - 'price_discounted' => '200.00', + 'price' => [ + 'net' => '200.00', + 'gross' => '200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '200.00', + 'gross' => '200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -394,17 +474,52 @@ public function testCartProcess(string $user, bool $coupon): void ->assertValid()->assertOk() ->assertJsonFragment( [ - 'cart_total_initial' => '9200.00', - 'cart_total' => '8280.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '8280.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '8280.00', + 'gross' => '8280.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '8280.00', + 'gross' => '8280.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ] + $result ) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment( [ @@ -458,22 +573,67 @@ public function testCartProcessProductNotAvailable($user): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '9200.00', - 'cart_total' => '9200.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '9200.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ])->assertJsonMissing([ 'cartitem_id' => '2', - 'price' => '100.00', - 'price_discounted' => '100.00', + 'price' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -509,18 +669,53 @@ public function testCartProcessSameProductNotAvailableWithSchema($user): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '9200.00', - 'cart_total' => '9200.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '9200.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ])->assertJsonMissing([ 'cartitem_id' => '2', ]); @@ -707,20 +902,65 @@ public function testCartProcessFull($user): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '9200.00', - 'cart_total' => '7780.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '7780.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '7780.00', + 'gross' => '7780.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '7780.00', + 'gross' => '7780.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4140.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4140.00', + 'gross' => '4140.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ])->assertJsonMissing([ 'cartitem_id' => '2', - 'price' => '100.00', - 'price_discounted' => '100.00', + 'price' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'id' => $saleApplied->getKey(), @@ -824,16 +1064,51 @@ public function testCartProcessLessThanMinimal($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '4600.00', - 'cart_total' => '0.01', - 'shipping_price_initial' => '10.00', - 'shipping_price' => '0.00', - 'summary' => '0.01', + 'cart_total_initial' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '0.01', + 'gross' => '0.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '10.00', + 'gross' => '10.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '0.01', + 'gross' => '0.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '46.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '46.00', + 'gross' => '46.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'id' => $saleApplied->getKey(), @@ -936,16 +1211,51 @@ public function testCartProcessLessThanMinimalCustom($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '4600.00', - 'cart_total' => '0.01', - 'shipping_price_initial' => '10.00', - 'shipping_price' => '0.01', - 'summary' => '0.02', + 'cart_total_initial' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '0.01', + 'gross' => '0.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '10.00', + 'gross' => '10.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.01', + 'gross' => '0.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '0.02', + 'gross' => '0.02', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '0.01', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '0.01', + 'gross' => '0.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'id' => $couponProduct->getKey(), @@ -995,17 +1305,52 @@ public function testCartProcessWithNotExistingCoupon(string $user, bool $coupon) ->assertValid()->assertOk() ->assertJsonFragment( [ - 'cart_total_initial' => '9200.00', - 'cart_total' => '8280.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '8280.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '8280.00', + 'gross' => '8280.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '8280.00', + 'gross' => '8280.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ] + $result ) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment( [ @@ -1088,23 +1433,68 @@ public function testCartProcessCheapestProduct(string $user, bool $coupon): void ->assertValid()->assertOk() ->assertJsonFragment( [ - 'cart_total_initial' => '9200.00', - 'cart_total' => '8073.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '8073.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '8073.00', + 'gross' => '8073.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '8073.00', + 'gross' => '8073.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ] + $result ) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4140.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4140.00', + 'gross' => '4140.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'quantity' => 1, ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '3933.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '3933.00', + 'gross' => '3933.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'quantity' => 1, ]) ->assertJsonFragment( @@ -1189,17 +1579,52 @@ public function testCartProcessCheapestProductWithSamePrice(string $user, bool $ ->assertOk() ->assertJsonFragment( [ - 'cart_total_initial' => '9200.00', - 'cart_total' => '0.02', - 'shipping_price_initial' => '8.11', - 'shipping_price' => '8.11', - 'summary' => '8.13', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '0.02', + 'gross' => '0.02', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '8.11', + 'gross' => '8.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '8.11', + 'gross' => '8.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '8.13', + 'gross' => '8.13', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ] + $result ) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '0.01', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '0.01', + 'gross' => '0.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'quantity' => 2, ]) ->assertJsonFragment( @@ -1287,7 +1712,12 @@ public function testCartProcessWithDiscountValueAmountExtendPrice($user): void $response->assertValid() ->assertOk() - ->assertJsonFragment(['summary' => '108.12']); // (10 (price) - 20 (discount)) + 100 + 8.11 (shipping) + ->assertJsonFragment(['summary' => [ + 'net' => '108.12', + 'gross' => '108.12', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // (10 (price) - 20 (discount)) + 100 + 8.11 (shipping) } /** @@ -1351,7 +1781,12 @@ public function testCartProcessWithPromotionOnMultiProductWithSchema($user): voi $response->assertValid() ->assertValid()->assertOk() - ->assertJsonFragment(['summary' => '23.11']); // 3*((10(price) +20(schema)) -25(discount)) +8.11(shipping) + ->assertJsonFragment(['summary' => [ + 'net' => '23.11', + 'gross' => '23.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // 3*((10(price) +20(schema)) -25(discount)) +8.11(shipping) } /** @@ -1555,17 +1990,52 @@ public function testCartProcessRoundedValues(string $user, bool $coupon): void ->assertValid()->assertOk() ->assertJsonFragment( [ - 'cart_total_initial' => '9202.00', - 'cart_total' => '8074.76', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '8074.76', + 'cart_total_initial' => [ + 'net' => '9202.00', + 'gross' => '9202.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '8074.76', + 'gross' => '8074.76', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '8074.76', + 'gross' => '8074.76', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ] + $result ) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4601.00', - 'price_discounted' => '4485.98', + 'price' => [ + 'net' => '4601.00', + 'gross' => '4601.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4485.98', + 'gross' => '4485.98', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment( [ @@ -1657,22 +2127,67 @@ public function testCartProcessRoundedValuesCheapestProduct(string $user, bool $ ->assertValid()->assertOk() ->assertJsonFragment( [ - 'cart_total_initial' => '90.00', - 'cart_total' => '83.48', - 'shipping_price_initial' => '8.11', - 'shipping_price' => '8.11', - 'summary' => '91.59', + 'cart_total_initial' => [ + 'net' => '90.00', + 'gross' => '90.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '83.48', + 'gross' => '83.48', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '8.11', + 'gross' => '8.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '8.11', + 'gross' => '8.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '91.59', + 'gross' => '91.59', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ] + $result ) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '45.00', - 'price_discounted' => '45.00', + 'price' => [ + 'net' => '45.00', + 'gross' => '45.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '45.00', + 'gross' => '45.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '45.00', - 'price_discounted' => '38.48', + 'price' => [ + 'net' => '45.00', + 'gross' => '45.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '38.48', + 'gross' => '38.48', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment( [ @@ -2021,18 +2536,53 @@ public function testCartProcessProductWithSchemaAndItemNotAvailable($user): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '0.00', - 'cart_total' => '0.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '0.00', + 'cart_total_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonMissing([ 'cartitem_id' => '1', - 'price' => '100.00', - 'price_discounted' => '100.00', + 'price' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -2066,18 +2616,53 @@ public function testCartProcessProductWithItemNotAvailable($user): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '0.00', - 'cart_total' => '0.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '0.00', + 'cart_total_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonMissing([ 'cartitem_id' => '1', - 'price' => '100.00', - 'price_discounted' => '100.00', + 'price' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -2113,18 +2698,53 @@ public function testCartProcessProductWithSchemaAndItemAvailable($user): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '200.00', - 'cart_total' => '200.00', - 'shipping_price_initial' => '8.11', - 'shipping_price' => '8.11', - 'summary' => '208.11', + 'cart_total_initial' => [ + 'net' => '200.00', + 'gross' => '200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '200.00', + 'gross' => '200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '8.11', + 'gross' => '8.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '8.11', + 'gross' => '8.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '208.11', + 'gross' => '208.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '100.00', - 'price_discounted' => '100.00', + 'price' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -2219,17 +2839,52 @@ public function testCartProcessProductInChildrenSet(string $user, bool $coupon): ->assertValid()->assertOk() ->assertJsonFragment( [ - 'cart_total_initial' => '4600.00', - 'cart_total' => '4140.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '4140.00', + 'cart_total_initial' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '4140.00', + 'gross' => '4140.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '4140.00', + 'gross' => '4140.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ] + $result, ) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4140.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4140.00', + 'gross' => '4140.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment( [ @@ -2311,19 +2966,54 @@ public function testCartProcessSaleWithTargetProduct($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '9200.00', - 'cart_total' => '9200.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '9200.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonCount(0, 'data.sales') ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonMissing( [ @@ -2402,17 +3092,52 @@ public function testCartProcessInactive(string $user, bool $coupon): void ->assertValid()->assertOk() ->assertJsonFragment( [ - 'cart_total_initial' => '9200.00', - 'cart_total' => '9200.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '9200.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ] + $result, ) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonMissing( [ @@ -2449,18 +3174,53 @@ public function testCartProcessPurchaseLimitMoreAvailable($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '9200.00', - 'cart_total' => '9200.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '9200.00', + 'cart_total_initial' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '9200.00', + 'gross' => '9200.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'quantity' => 2, ]); } @@ -2491,18 +3251,53 @@ public function testCartProcessPurchaseLimitLessAvailable($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '4600.00', - 'cart_total' => '4600.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '4600.00', + 'cart_total_initial' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -2576,11 +3371,36 @@ public function testCartProcessPurchaseLimitWithSale($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '1000.00', - 'cart_total' => '1000.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '1000.00', + 'cart_total_initial' => [ + 'net' => '1000.00', + 'gross' => '1000.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '1000.00', + 'gross' => '1000.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '1000.00', + 'gross' => '1000.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], ]) ->assertJsonCount(1, 'data.items') @@ -2591,13 +3411,33 @@ public function testCartProcessPurchaseLimitWithSale($user): void ]) ->assertJsonFragment([ 'cartitem_id' => '2', - 'price' => '1000.00', - 'price_discounted' => '1000.00', + 'price' => [ + 'net' => '1000.00', + 'gross' => '1000.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '1000.00', + 'gross' => '1000.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonMissing([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -2639,11 +3479,36 @@ public function testCartProcessPurchaseLimitAlreadyPurchased($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '0.00', - 'cart_total' => '0.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '0.00', + 'cart_total_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], 'items' => [], @@ -2689,11 +3554,36 @@ public function testCartProcessPurchaseLimitAlreadyPurchasedNotPaid($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '4600.00', - 'cart_total' => '4600.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '4600.00', + 'cart_total_initial' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonCount(1, 'data.items'); } @@ -2736,11 +3626,36 @@ public function testCartProcessPurchaseLimitSetAfterPurchase($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '0.00', - 'cart_total' => '0.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '0.00', + 'cart_total_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], 'items' => [], @@ -2790,18 +3705,53 @@ public function testCartProcessPurchaseLimitCanceledOrder($user): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '4600.00', - 'cart_total' => '4600.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '4600.00', + 'cart_total_initial' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -2840,18 +3790,53 @@ public function testCartProcessPurchaseLimitProductWithSchema($user): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '100.00', - 'cart_total' => '100.00', - 'shipping_price_initial' => '8.11', - 'shipping_price' => '8.11', - 'summary' => '108.11', + 'cart_total_initial' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '8.11', + 'gross' => '8.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '8.11', + 'gross' => '8.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '108.11', + 'gross' => '108.11', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '100.00', - 'price_discounted' => '100.00', + 'price' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonMissing([ 'cartitem_id' => '2', @@ -2882,18 +3867,53 @@ public function testCartProcessPurchaseLimitNoAccount(): void ]) ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '4600.00', - 'cart_total' => '4600.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '4600.00', + 'cart_total_initial' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -2927,16 +3947,51 @@ public function testCartProcessWithZeroSale(): void $response ->assertValid()->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '4600.00', - 'cart_total' => '4600.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '4600.00', + 'cart_total_initial' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'id' => $discountApplied->getKey(), @@ -3014,26 +4069,71 @@ public function testCartProcessWithNotAvailable(string $user, int $first, int $s ->assertValid() ->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '9700.00', - 'cart_total' => '9700.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '9700.00', + 'cart_total_initial' => [ + 'net' => '9700.00', + 'gross' => '9700.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '9700.00', + 'gross' => '9700.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '9700.00', + 'gross' => '9700.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '4600.00', - 'price_discounted' => '4600.00', + 'price' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '4600.00', + 'gross' => '4600.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '3', - 'price' => '500.00', + 'price' => [ + 'net' => '500.00', + 'gross' => '500.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonMissing([ 'cartitem_id' => '2', - 'price' => '2000.00', + 'price' => [ + 'net' => '2000.00', + 'gross' => '2000.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } @@ -3129,11 +4229,36 @@ public function testCartProcessWithRequiredSchema(string $user): void ->assertValid() ->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '0.00', - 'cart_total' => '0.00', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '0.00', + 'cart_total_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'coupons' => [], 'sales' => [], 'items' => [], @@ -3198,16 +4323,51 @@ public function testCartProcessShippingMethodPriceRanges($user): void ->assertValid() ->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '49.00', - 'cart_total' => '24.50', - 'shipping_price_initial' => '10.00', - 'shipping_price' => '10.00', - 'summary' => '34.50', + 'cart_total_initial' => [ + 'net' => '49.00', + 'gross' => '49.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '24.50', + 'gross' => '24.50', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '10.00', + 'gross' => '10.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '10.00', + 'gross' => '10.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '34.50', + 'gross' => '34.50', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '49.00', - 'price_discounted' => '24.50', + 'price' => [ + 'net' => '49.00', + 'gross' => '49.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '24.50', + 'gross' => '24.50', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); $this @@ -3228,16 +4388,51 @@ public function testCartProcessShippingMethodPriceRanges($user): void ->assertValid() ->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '98.00', - 'cart_total' => '49.00', - 'shipping_price_initial' => '10.00', - 'shipping_price' => '10.00', - 'summary' => '59.00', + 'cart_total_initial' => [ + 'net' => '98.00', + 'gross' => '98.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '49.00', + 'gross' => '49.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '10.00', + 'gross' => '10.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '10.00', + 'gross' => '10.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '59.00', + 'gross' => '59.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '49.00', - 'price_discounted' => '24.50', + 'price' => [ + 'net' => '49.00', + 'gross' => '49.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '24.50', + 'gross' => '24.50', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); $this @@ -3258,16 +4453,51 @@ public function testCartProcessShippingMethodPriceRanges($user): void ->assertValid() ->assertOk() ->assertJsonFragment([ - 'cart_total_initial' => '147.00', - 'cart_total' => '73.50', - 'shipping_price_initial' => '0.00', - 'shipping_price' => '0.00', - 'summary' => '73.50', + 'cart_total_initial' => [ + 'net' => '147.00', + 'gross' => '147.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '73.50', + 'gross' => '73.50', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '73.50', + 'gross' => '73.50', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]) ->assertJsonFragment([ 'cartitem_id' => '1', - 'price' => '49.00', - 'price_discounted' => '24.50', + 'price' => [ + 'net' => '49.00', + 'gross' => '49.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'price_discounted' => [ + 'net' => '24.50', + 'gross' => '24.50', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } diff --git a/tests/Feature/Discounts/DiscountOrderTest.php b/tests/Feature/Discounts/DiscountOrderTest.php index 56de26870..3ceeb7375 100644 --- a/tests/Feature/Discounts/DiscountOrderTest.php +++ b/tests/Feature/Discounts/DiscountOrderTest.php @@ -122,8 +122,12 @@ public function testOrderCreateDiscountOrderValuePercentage($user): void $response ->assertValid() ->assertCreated() - ->assertJsonFragment(['summary' => '95.00']); // 100 - 100 * 15% + 10 (delivery) - + ->assertJsonFragment(['summary' => [ + 'net' => '95.00', + 'gross' => '95.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // 100 - 100 * 15% + 10 (delivery) $order = Order::query()->find($response->getData()->data->id)->first(); $this->assertDatabaseHas('order_discounts', [ @@ -168,7 +172,12 @@ public function testOrderCreateOrderValueAmount($user): void $response ->assertCreated() - ->assertJsonFragment(['summary' => '60.00']); // 100 - 50 + 10 (delivery) + ->assertJsonFragment(['summary' => [ + 'net' => '60.00', + 'gross' => '60.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // 100 - 50 + 10 (delivery) } /** @@ -199,7 +208,12 @@ public function testOrderCreateChangeDiscountOrderValue($user): void $response ->assertCreated() - ->assertJsonFragment(['summary' => '100.00']); // 100 - 100 * 10% + 10 (delivery) + ->assertJsonFragment(['summary' => [ + 'net' => '100.00', + 'gross' => '100.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // 100 - 100 * 10% + 10 (delivery) $orderId = $response->getData()->data->id; @@ -442,7 +456,12 @@ public function testCreateOrderMultipleDiscounts($user): void 'payment_method_id' => $this->paymentMethod->getKey(), ]) ->assertCreated() - ->assertJsonFragment(['summary' => '542.00']); + ->assertJsonFragment(['summary' => [ + 'net' => '542.00', + 'gross' => '542.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); $orderId = $response->getData()->data->id; @@ -526,7 +545,12 @@ public function testOrderCreateDiscountCheapestProduct($user): void $response ->assertCreated() - ->assertJsonFragment(['summary' => '185.50']); // 90 (first product) + 85,5 (second product) + 10 (delivery) + ->assertJsonFragment(['summary' => [ + 'net' => '185.50', + 'gross' => '185.50', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // 90 (first product) + 85,5 (second product) + 10 (delivery) $order = Order::query()->find($response->getData()->data->id); @@ -667,7 +691,12 @@ public function testCreateOrderPriceRoundWithOrderValueDiscount($user): void $response ->assertCreated() - ->assertJsonFragment(['summary' => '1817.60']); + ->assertJsonFragment(['summary' => [ + 'net' => '1817.60', + 'gross' => '1817.60', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); $orderId = $response->getData()->data->id; @@ -723,7 +752,12 @@ public function testCreateOrderPriceRound($user): void $response ->assertCreated() - ->assertJsonFragment(['summary' => '7275.38']); + ->assertJsonFragment(['summary' => [ + 'net' => '7275.38', + 'gross' => '7275.38', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); $orderId = $response->getData()->data->id; @@ -788,7 +822,12 @@ public function testOrderCreateMultiItemWithDiscountValueAmount($user): void 'payment_method_id' => $this->paymentMethod->getKey(), ]) ->assertCreated() - ->assertJsonFragment(['summary' => '34.00']); // 3 * (10 - 2) + 10 (delivery) + ->assertJsonFragment(['summary' => [ + 'net' => '34.00', + 'gross' => '34.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // 3 * (10 - 2) + 10 (delivery) } /** @@ -848,7 +887,12 @@ public function testOrderCreateItemWithDiscountValueAmountExtendPrice($user): vo 'payment_method_id' => $this->paymentMethod->getKey(), ]) ->assertCreated() - ->assertJsonFragment(['summary' => '110.01']); // (10 (price) - 20 (discount)) + 100 + 10 (delivery) + ->assertJsonFragment(['summary' => [ + 'net' => '110.01', + 'gross' => '110.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // (10 (price) - 20 (discount)) + 100 + 10 (delivery) } /** @@ -918,7 +962,12 @@ public function testOrderCreateSchemaProductWithDiscountValueAmount($user): void 'payment_method_id' => $this->paymentMethod->getKey(), ]) ->assertCreated() - ->assertJsonFragment(['summary' => '20.00']); // (10 + 20 - 20) + 10 (delivery) + ->assertJsonFragment(['summary' => [ + 'net' => '20.00', + 'gross' => '20.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // (10 + 20 - 20) + 10 (delivery) } /** @@ -988,7 +1037,12 @@ public function testOrderCreateMultiSchemaProductWithDiscountValueAmount($user): 'payment_method_id' => $this->paymentMethod->getKey(), ]) ->assertCreated() - ->assertJsonFragment(['summary' => '70.00']); // 3 * (30 - 10) + 10 (delivery) + ->assertJsonFragment(['summary' => [ + 'net' => '70.00', + 'gross' => '70.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // 3 * (30 - 10) + 10 (delivery) } /** @@ -1056,7 +1110,12 @@ public function testOrderCreateSchemaProductWithDiscountValueAmountExtendPrice($ 'payment_method_id' => $this->paymentMethod->getKey(), ]) ->assertCreated() - ->assertJsonFragment(['summary' => '110.01']); // (20 (schema price) - 30 (discount)) + 100 + 10 (delivery) + ->assertJsonFragment(['summary' => [ + 'net' => '110.01', + 'gross' => '110.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // (20 (schema price) - 30 (discount)) + 100 + 10 (delivery) } /** @@ -1110,7 +1169,12 @@ public function testOrderCreateDiscountCheapestProductAndCheckDeposits($user): v $response ->assertCreated() - ->assertJsonFragment(['summary' => '300.00']); // 100 * 2 + (100 - 10%) * 1 + 10 (delivery) + ->assertJsonFragment(['summary' => [ + 'net' => '300.00', + 'gross' => '300.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ]]); // 100 * 2 + (100 - 10%) * 1 + 10 (delivery) $order = Order::find($response->getData()->data->id); diff --git a/tests/Feature/Discounts/DiscountTest.php b/tests/Feature/Discounts/DiscountTest.php index f130e2673..eb51a5e8a 100644 --- a/tests/Feature/Discounts/DiscountTest.php +++ b/tests/Feature/Discounts/DiscountTest.php @@ -1346,7 +1346,7 @@ public function testCreateMaxValueAmount($user, $discountKind): void $discount['amounts'] = Arr::map($discount['amounts'], fn(array $amount) => [ 'currency' => $amount['currency'], 'value' => $amount['value'], - 'is_net' => false, + 'is_net' => true, ]); $response @@ -1534,12 +1534,12 @@ public function testCreateFull($user, $discountKind): void 'min_values' => array_map(fn($value) => [ 'currency' => $value['currency'], 'value' => $value['value'], - 'is_net' => false, + 'is_net' => true, ], $this->minValues), 'max_values' => array_map(fn($value) => [ 'currency' => $value['currency'], 'value' => $value['value'], - 'is_net' => false, + 'is_net' => true, ], $this->maxValues), ]) ->assertJsonFragment([ @@ -2207,12 +2207,12 @@ public function testUpdateFull($user, $discountKind): void 'min_values' => array_map(fn($value) => [ 'currency' => $value['currency'], 'value' => $value['value'], - 'is_net' => false, + 'is_net' => true, ], $this->minValues), 'max_values' => array_map(fn($value) => [ 'currency' => $value['currency'], 'value' => $value['value'], - 'is_net' => false, + 'is_net' => true, ], $this->maxValues), ]) ->assertJsonFragment([ @@ -2364,7 +2364,7 @@ public function testUpdateOrderValueConditionWithNull($user, $discountKind): voi 'max_values' => array_map(fn($value) => [ 'currency' => $value['currency'], 'value' => $value['value'], - 'is_net' => false, + 'is_net' => true, ], $this->maxValues), ]); @@ -2414,7 +2414,7 @@ public function testUpdateWithPartialData($user, $discountKind): void 'amounts' => array_map(fn(string $currency) => [ 'currency' => $currency, 'value' => '50.00', - 'is_net' => false, + 'is_net' => true, ], Currency::values()), 'metadata' => [], ] + $code @@ -2621,7 +2621,7 @@ public function testUpdateSaleWithProduct($user): void ->assertJsonFragment($discountNew + [ 'id' => $discount->getKey(), 'amounts' => array_map(fn(string $currency) => [ - 'is_net' => false, + 'is_net' => true, 'value' => '10.00', 'currency' => $currency, ], Currency::values()), diff --git a/tests/Feature/OrderCreateTest.php b/tests/Feature/OrderCreateTest.php index 1456e7f1a..04d98f0fc 100644 --- a/tests/Feature/OrderCreateTest.php +++ b/tests/Feature/OrderCreateTest.php @@ -417,7 +417,12 @@ public function testCreateSimpleOrderPaid($user): void $response->assertJsonFragment([ 'id' => $order->id, - 'summary' => '0.00', + 'summary' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], 'paid' => true, 'payable' => false, ]); @@ -1160,11 +1165,36 @@ public function testCreateOrderWithDiscountMinimalPrices($user): void $response->assertCreated() ->assertJsonFragment([ - 'cart_total_initial' => '150.00', - 'cart_total' => '0.01', - 'shipping_price_initial' => '10.00', - 'shipping_price' => '0.00', - 'summary' => '0.01', + 'cart_total_initial' => [ + 'net' => '150.00', + 'gross' => '150.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'cart_total' => [ + 'net' => '0.01', + 'gross' => '0.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price_initial' => [ + 'net' => '10.00', + 'gross' => '10.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'shipping_price' => [ + 'net' => '0.00', + 'gross' => '0.00', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], + 'summary' => [ + 'net' => '0.01', + 'gross' => '0.01', + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); $order = Order::find($response->getData()->data->id); diff --git a/tests/Feature/OrderTest.php b/tests/Feature/OrderTest.php index e21704aca..736a06fdc 100644 --- a/tests/Feature/OrderTest.php +++ b/tests/Feature/OrderTest.php @@ -1138,7 +1138,12 @@ public function testViewOverpaid($user): void ->assertOk() ->assertJsonFragment([ 'paid' => true, - 'summary_paid' => $summaryPaid->getAmount(), + 'summary_paid' => [ + 'net' => $summaryPaid->getAmount(), + 'gross' => $summaryPaid->getAmount(), + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); $this->assertQueryCountLessThan(40); @@ -1763,7 +1768,12 @@ public function testViewUnderpaid($user): void ->assertOk() ->assertJsonFragment([ 'paid' => false, - 'summary_paid' => $summaryPaid->getAmount(), + 'summary_paid' => [ + 'net' => $summaryPaid->getAmount(), + 'gross' => $summaryPaid->getAmount(), + 'vat_rate' => '0.00', + 'currency' => 'PLN', + ], ]); } diff --git a/tests/Feature/SalesChannels/SalesChannelsTest.php b/tests/Feature/SalesChannels/SalesChannelsTest.php index 332dc877c..29a222faf 100644 --- a/tests/Feature/SalesChannels/SalesChannelsTest.php +++ b/tests/Feature/SalesChannels/SalesChannelsTest.php @@ -76,11 +76,42 @@ public function testCartProcess(string $user): void ], ]) ->assertOk() - ->assertJsonFragment(['shipping_price' => '10.00']) // shipping price should remain the same - ->assertJsonFragment(['price_discounted' => '12.30']) // single product price - ->assertJsonFragment(['cart_total_initial' => '24.60']) - ->assertJsonFragment(['cart_total' => '24.60']) - ->assertJsonFragment(['summary' => '34.60']); + ->assertJsonFragment(['shipping_price' => [ + 'net' => '8.13', + 'gross' => '10.00', + 'vat_rate' => '0.23', + 'currency' => 'PLN', + ]]) // shipping price should remain the same + ->assertJsonFragment(['price' => [ + 'net' => '10.00', + 'gross' => '12.30', + 'vat_rate' => '0.23', + 'currency' => 'PLN', + ]]) // single product price + ->assertJsonFragment(['price_discounted' => [ + 'net' => '10.00', + 'gross' => '12.30', + 'vat_rate' => '0.23', + 'currency' => 'PLN', + ]]) // single product price + ->assertJsonFragment(['cart_total_initial' => [ + 'net' => '20.00', + 'gross' => '24.60', + 'vat_rate' => '0.23', + 'currency' => 'PLN', + ]]) + ->assertJsonFragment(['cart_total' => [ + 'net' => '20.00', + 'gross' => '24.60', + 'vat_rate' => '0.23', + 'currency' => 'PLN', + ]]) + ->assertJsonFragment(['summary' => [ + 'net' => '28.13', + 'gross' => '34.60', + 'vat_rate' => '0.23', + 'currency' => 'PLN', + ]]); } /** @@ -132,7 +163,8 @@ public function testOrderCreate(string $user): void ); $this->{$user}->givePermissionTo('orders.add'); - $this + + $response = $this ->actingAs($this->{$user}) ->json('POST', '/orders', [ 'currency' => $currency, @@ -155,8 +187,9 @@ public function testOrderCreate(string $user): void ], ], 'payment_method_id' => $paymentMethod->getKey(), - ]) - ->assertCreated(); + ]); + + $response->assertCreated(); $this->assertDatabaseHas('orders', [ 'shipping_price' => '1000', // shipping price should remain the same diff --git a/tests/Unit/DiscountApplyTest.php b/tests/Unit/DiscountApplyTest.php index 02088811f..93f5402dd 100644 --- a/tests/Unit/DiscountApplyTest.php +++ b/tests/Unit/DiscountApplyTest.php @@ -10,6 +10,7 @@ use App\Models\Order; use App\Models\OrderProduct; use App\Models\PriceRange; +use App\Models\Product; use App\Repositories\DiscountRepository; use App\Services\DiscountService; use App\Services\ProductService; @@ -19,6 +20,7 @@ use Brick\Money\Exception\UnknownCurrencyException; use Brick\Money\Money; use Domain\Currency\Currency; +use Domain\Order\Dtos\OrderPriceDto; use Domain\Order\Resources\CartItemResource; use Domain\Order\Resources\CartResource; use Domain\Order\Resources\CouponShortResource; @@ -45,21 +47,24 @@ class DiscountApplyTest extends TestCase private DiscountService $discountService; private SchemaCrudService $schemaCrudService; private OptionService $optionService; - private $product; - private $productToOrderProduct; + private DiscountRepository $discountRepository; + + private Product $product; + private Product $productToOrderProduct; private Schema $schema; - private $set; - private $order; - private $shippingMethod; + private ProductSet $set; + private Order $order; + private ShippingMethod $shippingMethod; private CartResource $cart; private CartItemDto $cartItemDto; private CartItemResource $cartItemResource; private CartResource $cartResource; private OrderProductDto $orderProductDto; private OrderProductDto $orderProductDtoWithSchemas; - private $orderProduct; + private OrderProduct $orderProduct; + + private SalesChannel $salesChannel; private Currency $currency; - private DiscountRepository $discountRepository; public static function discountProductDataProvider(): array { @@ -138,6 +143,7 @@ public function setUp(): void $this->schemaCrudService = App::make(SchemaCrudService::class); $this->optionService = App::make(OptionService::class); $this->discountRepository = App::make(DiscountRepository::class); + $this->salesChannel = SalesChannel::query()->where('default', '=', 1)->first(); $this->product = $this->productService->create( FakeDto::productCreateDto([ @@ -165,8 +171,8 @@ public function setUp(): void $this->cartItemResource = new CartItemResource( 1, - Money::of(120.0, $this->currency->value), - Money::of(120.0, $this->currency->value), + OrderPriceDto::from(Money::of(120.0, $this->currency->value), $this->salesChannel), + OrderPriceDto::from(Money::of(120.0, $this->currency->value), $this->salesChannel), $this->currency, 1, ); @@ -175,11 +181,11 @@ public function setUp(): void CartItemResource::collection([$this->cartItemResource]), CouponShortResource::collection([]), SalesShortResource::collection([]), - Money::of(120.0, $this->currency->value), - Money::of(120.0, $this->currency->value), - Money::zero($this->currency->value), - Money::zero($this->currency->value), - Money::zero($this->currency->value), + OrderPriceDto::from(Money::of(120.0, $this->currency->value), $this->salesChannel), + OrderPriceDto::from(Money::of(120.0, $this->currency->value), $this->salesChannel), + OrderPriceDto::from(Money::zero($this->currency->value), $this->salesChannel), + OrderPriceDto::from(Money::zero($this->currency->value), $this->salesChannel), + OrderPriceDto::from(Money::zero($this->currency->value), $this->salesChannel), $this->currency, ); @@ -328,7 +334,7 @@ public function testApplyDiscountsOnCart(): void $cartDto = CartDto::fromArray([ 'currency' => $this->currency, - 'sales_channel_id' => SalesChannel::query()->value('id'), + 'sales_channel_id' => $this->salesChannel->id, 'items' => [ [ 'cartitem_id' => 0, @@ -365,8 +371,8 @@ public function testApplyDiscountsOnCart(): void BigDecimal::zero(), ); - $this->assertEquals(162, $cartResource->cart_total->getAmount()->toInt()); - $this->assertEquals(182, $cartResource->summary->getAmount()->toInt()); + $this->assertEquals(162, $cartResource->cart_total->net->getAmount()->toInt()); + $this->assertEquals(182, $cartResource->summary->net->getAmount()->toInt()); $this->assertTrue(count($cartResource->sales) === 1); $this->assertTrue(count($cartResource->coupons) === 3); } @@ -394,7 +400,7 @@ public function testMinimalProductPrice(): void $cartItemResponse = $this->discountService->applyDiscountOnCartItem($discount, $this->cartItemDto, $this->cart); - $this->assertEquals(0.01, $cartItemResponse->price_discounted->getAmount()->toFloat()); + $this->assertEquals(0.01, $cartItemResponse->price_discounted->net->getAmount()->toFloat()); } /** @@ -894,7 +900,7 @@ public function testApplyDiscountToCartItem($type, $value, $result, $discountKin $cartItemResponse = $this->discountService->applyDiscountOnCartItem($discount, $this->cartItemDto, $this->cart); - $this->assertTrue($cartItemResponse->price_discounted->isEqualTo($result)); + $this->assertTrue($cartItemResponse->price_discounted->net->isEqualTo($result)); } /** @@ -924,7 +930,7 @@ public function testApplyDiscountToCartItemNotAllowList($type, $value, $result, $cartItemResponse = $this->discountService->applyDiscountOnCartItem($discount, $this->cartItemDto, $this->cart); - $this->assertTrue($cartItemResponse->price_discounted->isEqualTo($result)); + $this->assertTrue($cartItemResponse->price_discounted->net->isEqualTo($result)); } /** @@ -948,7 +954,7 @@ public function testApplyDiscountToCartItemInProductSets($type, $value, $result, $cartItemResponse = $this->discountService->applyDiscountOnCartItem($discount, $this->cartItemDto, $this->cart); - $this->assertTrue($cartItemResponse->price_discounted->isEqualTo($result)); + $this->assertTrue($cartItemResponse->price_discounted->net->isEqualTo($result)); } /** @@ -975,7 +981,7 @@ public function testApplyDiscountToCartItemInProductSetsNotAllowList($type, $val $cartItemResponse = $this->discountService->applyDiscountOnCartItem($discount, $this->cartItemDto, $this->cart); - $this->assertTrue($cartItemResponse->price_discounted->isEqualTo($result)); + $this->assertTrue($cartItemResponse->price_discounted->net->isEqualTo($result)); } /** @@ -995,7 +1001,7 @@ public function testDiscountNotApplyToCartItem($type, $value, $result, $discount $cartItemResponse = $this->discountService->applyDiscountOnCartItem($discount, $this->cartItemDto, $this->cart); - $this->assertTrue($cartItemResponse->price_discounted->isEqualTo(120.0)); + $this->assertTrue($cartItemResponse->price_discounted->net->isEqualTo(120.0)); } /** @@ -1017,7 +1023,7 @@ public function testDiscountNotApplyToCartItemNotAllowList($type, $value, $resul $cartItemResponse = $this->discountService->applyDiscountOnCartItem($discount, $this->cartItemDto, $this->cart); - $this->assertTrue($cartItemResponse->price_discounted->isEqualTo(120.0)); + $this->assertTrue($cartItemResponse->price_discounted->net->isEqualTo(120.0)); } /** @@ -1039,7 +1045,7 @@ public function testDiscountNotApplyToCartItemInProductSets($type, $value, $resu $cartItemResponse = $this->discountService->applyDiscountOnCartItem($discount, $this->cartItemDto, $this->cart); - $this->assertTrue($cartItemResponse->price_discounted->isEqualTo(120.0)); + $this->assertTrue($cartItemResponse->price_discounted->net->isEqualTo(120.0)); } /** @@ -1063,7 +1069,7 @@ public function testDiscountNotApplyToCartItemInProductSetsNotAllowList($type, $ $cartItemResponse = $this->discountService->applyDiscountOnCartItem($discount, $this->cartItemDto, $this->cart); - $this->assertTrue($cartItemResponse->price_discounted->isEqualTo(120.0)); + $this->assertTrue($cartItemResponse->price_discounted->net->isEqualTo(120.0)); } public function testApplyDiscountOnOrderValueAmount(): void