From 038fd1877006a6494b8428f7cca7b7684f05bdaa Mon Sep 17 00:00:00 2001 From: mamazu Date: Sun, 21 Feb 2021 13:32:51 +0100 Subject: [PATCH] Adding a subtotal property to the cart endpoint --- doc/swagger.yml | 5 +++++ spec/Factory/Cart/CartItemViewFactorySpec.php | 2 ++ src/Factory/Cart/CartItemViewFactory.php | 1 + src/View/ItemView.php | 3 +++ .../cart/add_multiple_products_to_cart_response.json | 3 +++ .../cart/add_multiple_products_to_new_cart_response.json | 3 +++ ...ant_based_on_options_multiple_times_to_cart_response.json | 1 + ...dd_product_variant_based_on_options_to_cart_response.json | 1 + .../add_product_variant_multiple_times_to_cart_response.json | 1 + .../Expected/cart/add_product_variant_to_cart_response.json | 1 + .../add_simple_product_multiple_times_to_cart_response.json | 1 + .../Expected/cart/add_simple_product_to_cart_response.json | 1 + .../cart/add_simple_product_to_new_cart_response.json | 1 + .../cart_with_coupon_based_promotion_applied_response.json | 1 + .../filled_cart_with_product_variant_summary_response.json | 2 ++ .../filled_cart_with_simple_product_summary_response.json | 1 + ...an_filled_cart_with_product_variant_summary_response.json | 1 + ...man_filled_cart_with_simple_product_summary_response.json | 1 + .../Expected/cart/recalculated_cart_after_log_in.json | 1 + .../cart/reprocessed_cart_after_deleting_an_item.json | 1 + .../Responses/Expected/checkout/cart_addressed_response.json | 1 + ...with_different_shipping_and_billing_address_response.json | 1 + .../cart_addressed_with_province_codes_response.json | 1 + .../Expected/checkout/cart_with_chosen_payment_response.json | 1 + .../checkout/cart_with_chosen_shipment_response.json | 1 + ...art_with_chosen_shipment_with_per_item_rate_response.json | 1 + ...art_with_chosen_shipment_with_per_item_rate_response.json | 1 + tests/Responses/Expected/order/order_details_response.json | 1 + .../Expected/order/order_details_response_guest.json | 1 + tests/Responses/Expected/order/orders_list_response.json | 1 + 30 files changed, 42 insertions(+) diff --git a/doc/swagger.yml b/doc/swagger.yml index 8fb0384fe..5348b230c 100644 --- a/doc/swagger.yml +++ b/doc/swagger.yml @@ -1322,9 +1322,14 @@ definitions: quantity: type: "integer" example: 2 + subtotal: + type: "integer" + example: 2000 + description: "Raw subtotal without the distributed order discounts (unit price * quantity + unit discount)" total: type: "integer" example: 1000 + description: "The total also includes the distributed discount" product: type: "object" allOf: diff --git a/spec/Factory/Cart/CartItemViewFactorySpec.php b/spec/Factory/Cart/CartItemViewFactorySpec.php index a5d2e34d8..2e0719490 100644 --- a/spec/Factory/Cart/CartItemViewFactorySpec.php +++ b/spec/Factory/Cart/CartItemViewFactorySpec.php @@ -41,6 +41,7 @@ function it_builds_cart_item_view( $cartItem->getId()->willReturn(2); $cartItem->getQuantity()->willReturn(3); $cartItem->getTotal()->willReturn(900); + $cartItem->getSubtotal()->willReturn(800); $cartItem->getProduct()->willReturn($tShirt); $cartItem->getVariant()->willReturn($tShirtVariant); @@ -51,6 +52,7 @@ function it_builds_cart_item_view( $cartItemView = new ItemView(); $cartItemView->id = 2; $cartItemView->quantity = 3; + $cartItemView->subTotal = 800; $cartItemView->total = 900; $cartItemView->product = new ProductView(); $cartItemView->product->variants = [new ProductVariantView()]; diff --git a/src/Factory/Cart/CartItemViewFactory.php b/src/Factory/Cart/CartItemViewFactory.php index 2d80a3b53..b41dae710 100644 --- a/src/Factory/Cart/CartItemViewFactory.php +++ b/src/Factory/Cart/CartItemViewFactory.php @@ -40,6 +40,7 @@ public function create(OrderItemInterface $item, ChannelInterface $channel, stri $itemView->id = $item->getId(); $itemView->quantity = $item->getQuantity(); $itemView->total = $item->getTotal(); + $itemView->subTotal = $item->getSubtotal(); $itemView->product = $this->productViewFactory->create($item->getProduct(), $channel, $locale); $itemView->product->variants = [$this->productVariantViewFactory->create($item->getVariant(), $channel, $locale)]; diff --git a/src/View/ItemView.php b/src/View/ItemView.php index bf7576431..6cc835a06 100644 --- a/src/View/ItemView.php +++ b/src/View/ItemView.php @@ -17,6 +17,9 @@ class ItemView /** @var int */ public $total; + /** @var int */ + public $subTotal; + /** @var ProductView */ public $product; diff --git a/tests/Responses/Expected/cart/add_multiple_products_to_cart_response.json b/tests/Responses/Expected/cart/add_multiple_products_to_cart_response.json index b3fda1fa7..f9222a18d 100644 --- a/tests/Responses/Expected/cart/add_multiple_products_to_cart_response.json +++ b/tests/Responses/Expected/cart/add_multiple_products_to_cart_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 5997, "total": 5997, "product": { "code": "LOGAN_MUG_CODE", @@ -69,6 +70,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 5997, "total": 5997, "product": { "code": "LOGAN_T_SHIRT_CODE", @@ -127,6 +129,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 1500, "total": 1500, "product": { "code": "LOGAN_HAT_CODE", diff --git a/tests/Responses/Expected/cart/add_multiple_products_to_new_cart_response.json b/tests/Responses/Expected/cart/add_multiple_products_to_new_cart_response.json index 973460cdf..85e8ff29b 100644 --- a/tests/Responses/Expected/cart/add_multiple_products_to_new_cart_response.json +++ b/tests/Responses/Expected/cart/add_multiple_products_to_new_cart_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 5997, "total": 5997, "product": { "code": "LOGAN_MUG_CODE", @@ -69,6 +70,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 5997, "total": 5997, "product": { "code": "LOGAN_T_SHIRT_CODE", @@ -127,6 +129,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 1500, "total": 1500, "product": { "code": "LOGAN_HAT_CODE", diff --git a/tests/Responses/Expected/cart/add_product_variant_based_on_options_multiple_times_to_cart_response.json b/tests/Responses/Expected/cart/add_product_variant_based_on_options_multiple_times_to_cart_response.json index 56690545a..a1bfda1dc 100644 --- a/tests/Responses/Expected/cart/add_product_variant_based_on_options_multiple_times_to_cart_response.json +++ b/tests/Responses/Expected/cart/add_product_variant_based_on_options_multiple_times_to_cart_response.json @@ -9,6 +9,7 @@ "id": @integer@, "quantity": 6, "total": 3000, + "subTotal": 3000, "product": { "code": "LOGAN_HAT_CODE", "name": "Logan Hat", diff --git a/tests/Responses/Expected/cart/add_product_variant_based_on_options_to_cart_response.json b/tests/Responses/Expected/cart/add_product_variant_based_on_options_to_cart_response.json index aa2d19760..b71e491f9 100644 --- a/tests/Responses/Expected/cart/add_product_variant_based_on_options_to_cart_response.json +++ b/tests/Responses/Expected/cart/add_product_variant_based_on_options_to_cart_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 1500, "total": 1500, "product": { "code": "LOGAN_HAT_CODE", diff --git a/tests/Responses/Expected/cart/add_product_variant_multiple_times_to_cart_response.json b/tests/Responses/Expected/cart/add_product_variant_multiple_times_to_cart_response.json index 57aac9d49..3854a3855 100644 --- a/tests/Responses/Expected/cart/add_product_variant_multiple_times_to_cart_response.json +++ b/tests/Responses/Expected/cart/add_product_variant_multiple_times_to_cart_response.json @@ -9,6 +9,7 @@ "id": @integer@, "quantity": 6, "total": 11994, + "subTotal": 11994, "product": { "code": "LOGAN_T_SHIRT_CODE", "name": "Logan T-Shirt", diff --git a/tests/Responses/Expected/cart/add_product_variant_to_cart_response.json b/tests/Responses/Expected/cart/add_product_variant_to_cart_response.json index 96f2a1dbb..3b3a1a4dd 100644 --- a/tests/Responses/Expected/cart/add_product_variant_to_cart_response.json +++ b/tests/Responses/Expected/cart/add_product_variant_to_cart_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 5997, "total": 5997, "product": { "code": "LOGAN_T_SHIRT_CODE", diff --git a/tests/Responses/Expected/cart/add_simple_product_multiple_times_to_cart_response.json b/tests/Responses/Expected/cart/add_simple_product_multiple_times_to_cart_response.json index 3802d5d9f..aaee6ae83 100644 --- a/tests/Responses/Expected/cart/add_simple_product_multiple_times_to_cart_response.json +++ b/tests/Responses/Expected/cart/add_simple_product_multiple_times_to_cart_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 2, + "subTotal": 3998, "total": 3998, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/cart/add_simple_product_to_cart_response.json b/tests/Responses/Expected/cart/add_simple_product_to_cart_response.json index 5c2171711..da7409e2c 100644 --- a/tests/Responses/Expected/cart/add_simple_product_to_cart_response.json +++ b/tests/Responses/Expected/cart/add_simple_product_to_cart_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 5997, "total": 5997, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/cart/add_simple_product_to_new_cart_response.json b/tests/Responses/Expected/cart/add_simple_product_to_new_cart_response.json index ce294177e..555112cb1 100644 --- a/tests/Responses/Expected/cart/add_simple_product_to_new_cart_response.json +++ b/tests/Responses/Expected/cart/add_simple_product_to_new_cart_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 5997, "total": 5997, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/cart/cart_with_coupon_based_promotion_applied_response.json b/tests/Responses/Expected/cart/cart_with_coupon_based_promotion_applied_response.json index bc7fbe796..eadbcaacf 100644 --- a/tests/Responses/Expected/cart/cart_with_coupon_based_promotion_applied_response.json +++ b/tests/Responses/Expected/cart/cart_with_coupon_based_promotion_applied_response.json @@ -9,6 +9,7 @@ "id": @integer@, "quantity": 5, "total": 8995, + "subTotal": 9995, "product": { "code": "LOGAN_MUG_CODE", "name": "Logan Mug", diff --git a/tests/Responses/Expected/cart/filled_cart_with_product_variant_summary_response.json b/tests/Responses/Expected/cart/filled_cart_with_product_variant_summary_response.json index ee86e1e35..f4e901e4e 100644 --- a/tests/Responses/Expected/cart/filled_cart_with_product_variant_summary_response.json +++ b/tests/Responses/Expected/cart/filled_cart_with_product_variant_summary_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 5997, "total": 5997, "product": { "code": "LOGAN_T_SHIRT_CODE", @@ -66,6 +67,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 1500, "total": 1500, "product": { "code": "LOGAN_HAT_CODE", diff --git a/tests/Responses/Expected/cart/filled_cart_with_simple_product_summary_response.json b/tests/Responses/Expected/cart/filled_cart_with_simple_product_summary_response.json index 504d37093..40adb2a21 100644 --- a/tests/Responses/Expected/cart/filled_cart_with_simple_product_summary_response.json +++ b/tests/Responses/Expected/cart/filled_cart_with_simple_product_summary_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/cart/german_filled_cart_with_product_variant_summary_response.json b/tests/Responses/Expected/cart/german_filled_cart_with_product_variant_summary_response.json index 105c183f0..1f36ec537 100644 --- a/tests/Responses/Expected/cart/german_filled_cart_with_product_variant_summary_response.json +++ b/tests/Responses/Expected/cart/german_filled_cart_with_product_variant_summary_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 3, + "subTotal": 1770, "total": 1770, "product": { "code": "LOGAN_HAT_CODE", diff --git a/tests/Responses/Expected/cart/german_filled_cart_with_simple_product_summary_response.json b/tests/Responses/Expected/cart/german_filled_cart_with_simple_product_summary_response.json index 74be97b1f..5dc9b6621 100644 --- a/tests/Responses/Expected/cart/german_filled_cart_with_simple_product_summary_response.json +++ b/tests/Responses/Expected/cart/german_filled_cart_with_simple_product_summary_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 10495, "total": 10495, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/cart/recalculated_cart_after_log_in.json b/tests/Responses/Expected/cart/recalculated_cart_after_log_in.json index 9d44f93f2..8a9873b2f 100644 --- a/tests/Responses/Expected/cart/recalculated_cart_after_log_in.json +++ b/tests/Responses/Expected/cart/recalculated_cart_after_log_in.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 1, + "subTotal": 1999, "total": 1599, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/cart/reprocessed_cart_after_deleting_an_item.json b/tests/Responses/Expected/cart/reprocessed_cart_after_deleting_an_item.json index 01adafacc..d4ee166be 100644 --- a/tests/Responses/Expected/cart/reprocessed_cart_after_deleting_an_item.json +++ b/tests/Responses/Expected/cart/reprocessed_cart_after_deleting_an_item.json @@ -9,6 +9,7 @@ "id": @integer@, "quantity": 1, "total": 1999, + "subTotal": 1999, "product": { "code": "LOGAN_MUG_CODE", "name": "Logan Mug", diff --git a/tests/Responses/Expected/checkout/cart_addressed_response.json b/tests/Responses/Expected/checkout/cart_addressed_response.json index 4e81287c5..08bdacec2 100644 --- a/tests/Responses/Expected/checkout/cart_addressed_response.json +++ b/tests/Responses/Expected/checkout/cart_addressed_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/checkout/cart_addressed_with_different_shipping_and_billing_address_response.json b/tests/Responses/Expected/checkout/cart_addressed_with_different_shipping_and_billing_address_response.json index fd92411f6..34c14a763 100644 --- a/tests/Responses/Expected/checkout/cart_addressed_with_different_shipping_and_billing_address_response.json +++ b/tests/Responses/Expected/checkout/cart_addressed_with_different_shipping_and_billing_address_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/checkout/cart_addressed_with_province_codes_response.json b/tests/Responses/Expected/checkout/cart_addressed_with_province_codes_response.json index 8970e63e7..7fbe8abbc 100644 --- a/tests/Responses/Expected/checkout/cart_addressed_with_province_codes_response.json +++ b/tests/Responses/Expected/checkout/cart_addressed_with_province_codes_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/checkout/cart_with_chosen_payment_response.json b/tests/Responses/Expected/checkout/cart_with_chosen_payment_response.json index 0b9e0ef60..b2723241b 100644 --- a/tests/Responses/Expected/checkout/cart_with_chosen_payment_response.json +++ b/tests/Responses/Expected/checkout/cart_with_chosen_payment_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/checkout/cart_with_chosen_shipment_response.json b/tests/Responses/Expected/checkout/cart_with_chosen_shipment_response.json index db52bf6fd..25d1a3b17 100644 --- a/tests/Responses/Expected/checkout/cart_with_chosen_shipment_response.json +++ b/tests/Responses/Expected/checkout/cart_with_chosen_shipment_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/checkout/cart_with_chosen_shipment_with_per_item_rate_response.json b/tests/Responses/Expected/checkout/cart_with_chosen_shipment_with_per_item_rate_response.json index 5476ebfbc..845a46db2 100644 --- a/tests/Responses/Expected/checkout/cart_with_chosen_shipment_with_per_item_rate_response.json +++ b/tests/Responses/Expected/checkout/cart_with_chosen_shipment_with_per_item_rate_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/checkout/modified_cart_with_chosen_shipment_with_per_item_rate_response.json b/tests/Responses/Expected/checkout/modified_cart_with_chosen_shipment_with_per_item_rate_response.json index b15a747ac..ae24b1fd6 100644 --- a/tests/Responses/Expected/checkout/modified_cart_with_chosen_shipment_with_per_item_rate_response.json +++ b/tests/Responses/Expected/checkout/modified_cart_with_chosen_shipment_with_per_item_rate_response.json @@ -8,6 +8,7 @@ { "id": @integer@, "quantity": 2, + "subTotal": 3998, "total": 3998, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/order/order_details_response.json b/tests/Responses/Expected/order/order_details_response.json index 7c233f4eb..4c4d6ed53 100644 --- a/tests/Responses/Expected/order/order_details_response.json +++ b/tests/Responses/Expected/order/order_details_response.json @@ -9,6 +9,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/order/order_details_response_guest.json b/tests/Responses/Expected/order/order_details_response_guest.json index a1d44cea6..a83cdc47e 100644 --- a/tests/Responses/Expected/order/order_details_response_guest.json +++ b/tests/Responses/Expected/order/order_details_response_guest.json @@ -9,6 +9,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE", diff --git a/tests/Responses/Expected/order/orders_list_response.json b/tests/Responses/Expected/order/orders_list_response.json index 4068a47d7..3f24ad93d 100644 --- a/tests/Responses/Expected/order/orders_list_response.json +++ b/tests/Responses/Expected/order/orders_list_response.json @@ -10,6 +10,7 @@ { "id": @integer@, "quantity": 5, + "subTotal": 9995, "total": 9995, "product": { "code": "LOGAN_MUG_CODE",