Magento 2 Get Product Total, Subtotal, Coupon, Tax Details Via REST API

Often when we create an application, we have to get all the data of the customers via cart totals API so that we can successfully make the payment to the customer by counting the total at checkout correctly.

In this post, I will tell you how to get the total of customer's cart items how you can get all data through Magento rest api.

First of all, you add the item to the cart, after that you will get the details of all the products added to that cart through the endpoint given below.

Now you will not see subtotals, coupons discounts, tax details, etc in the cart details. For this, we have to follow other Rest API.

 

Step 1: Get Cart Items Details Via Cart Totals API

Method: GET

Endpoint:

https://wishusucess.com/rest/V1/carts/mine/

Payload: Not required

customer Cart products in Magento 2 Api

Response:

{

"id": 133,

"created_at": "2021-12-06 12:37:31",

"updated_at": "2021-12-08 08:57:31",

"is_active": true,

"is_virtual": false,

"items": [

{

"item_id": 283,

"sku": "test-product-3",

"qty": 1,

"name": "test-product-3",

"price": 3,

"product_type": "simple",

"quote_id": "133",

"extension_attributes": {

"image": "/1/_/1_1_2.png"

}

},

{

"item_id": 284,

"sku": "test-product-4",

"qty": 1,

"name": "test-product-4",

"price": 5,

"product_type": "simple",

"quote_id": "133",

"extension_attributes": {

"image": "/1/_/1_5.jpg"

}

},

{

"item_id": 285,

"sku": "Chilli Happy 10gm",

"qty": 2,

"name": "Indus Happy Hybrid Chilli seeds 10gm + 10gm - Offer Buy 1 Get 1",

"price": 900,

"product_type": "simple",

"quote_id": "133",

"extension_attributes": {

"image": "/2/_/2_7.jpg"

}

},

{

"item_id": 290,

"sku": "Kalichakra – Metarhizium anisopliae",

"qty": 3,

"name": "Kalichakra – Metarhizium anisopliae (Wettable Powder) BioInsecticide (IPL)",

"price": 200,

"product_type": "simple",

"quote_id": "133",

"extension_attributes": {

"image": "/k/a/kalichakra_ipl_455x455.jpg"

}

}

],

"items_count": 4,

"items_qty": 7,

"customer": {

"id": 58,

"group_id": 1,

"default_billing": "35",

"default_shipping": "35",

"created_at": "2021-11-29 06:44:25",

"updated_at": "2021-12-06 11:36:53",

"created_in": "Default Store View",

"email": "test@test.test",

"firstname": "Test 11",

"lastname": "Test",

"store_id": 1,

"website_id": 1,

"addresses": [

{

"id": 35,

"customer_id": 58,

"region": {

"region_code": "UP",

"region": "Uttar Pradesh",

"region_id": 566

},

"region_id": 566,

"country_id": "IN",

"street": [

"H-21",

"First Floor",

"Sector 63"

],

"company": "Wishusucess.com ",

"telephone": "+91987654321",

"postcode": "201301",

"city": "Noida",

"firstname": "Test 11",

"lastname": "Test",

"default_shipping": true,

"default_billing": true

}

],

"disable_auto_group_change": 0,

"extension_attributes": {

"is_subscribed": false

},

"custom_attributes": [

{

"attribute_code": "device_token",

"value": "caXHLarRSmqWWq8pXPRJfR:APA91bFYIxmFVF-ouwEKvmIMVV04dXki2o2LOh5ysG9Hk7BA05VqSV491i83LafAFSmCOhVAC8ZRcJVXSH_NNNdOGunSQHIHRSl0rbIbWDypCvLvxLCZZnu74s3dHwaABiIqtXGE9wB2"

},

{

"attribute_code": "is_approved",

"value": "approved"

}

]

},

"billing_address": {

"id": 495,

"region": "Uttar Pradesh",

"region_id": 566,

"region_code": "UP",

"country_id": "IN",

"street": [

"H-21",

"null - First Floor"

],

"telephone": "+9187787888",

"postcode": "201301",

"city": "Noida",

"firstname": "Test 11",

"lastname": "Test",

"customer_id": 58,

"email": "test@test.test",

"same_as_billing": 1,

"save_in_address_book": 0

},

"orig_order_id": 0,

"currency": {

"global_currency_code": "USD",

"base_currency_code": "USD",

"store_currency_code": "USD",

"quote_currency_code": "USD",

"store_to_base_rate": 0,

"store_to_quote_rate": 0,

"base_to_global_rate": 1,

"base_to_quote_rate": 1

},

"customer_is_guest": false,

"customer_note_notify": true,

"customer_tax_class_id": 3,

"store_id": 1,

"extension_attributes": {

"shipping_assignments": [

{

"shipping": {

"address": {

"id": 496,

"region": "Uttar Pradesh",

"region_id": 566,

"region_code": "UP",

"country_id": "IN",

"street": [

"H-21",

"null - First Floor"

],

"telephone": "+9198878898",

"postcode": "201301",

"city": "Noida",

"firstname": "Test 11",

"lastname": "Test",

"customer_id": 58,

"email": "test@test.test",

"same_as_billing": 1,

"save_in_address_book": 0

},

"method": "freeshipping_freeshipping"

},

"items": [

{

"item_id": 283,

"sku": "test-product-3",

"qty": 1,

"name": "test-product-3",

"price": 3,

"product_type": "simple",

"quote_id": "133",

"extension_attributes": {

"image": "/1/_/1_1_2.png"

}

},

{

"item_id": 284,

"sku": "test-product-4",

"qty": 1,

"name": "test-product-4",

"price": 5,

"product_type": "simple",

"quote_id": "133",

"extension_attributes": {

"image": "/1/_/1_5.jpg"

}

},

{

"item_id": 285,

"sku": "Chilli Happy 10gm",

"qty": 2,

"name": "Indus Happy Hybrid Chilli seeds 10gm + 10gm - Offer Buy 1 Get 1",

"price": 900,

"product_type": "simple",

"quote_id": "133",

"extension_attributes": {

"image": "/2/_/2_7.jpg"

}

},

{

"item_id": 290,

"sku": "Kalichakra – Metarhizium anisopliae",

"qty": 3,

"name": "Kalichakra – Metarhizium anisopliae (Wettable Powder) BioInsecticide (IPL)",

"price": 200,

"product_type": "simple",

"quote_id": "133",

"extension_attributes": {

"image": "/k/a/kalichakra_ipl_455x455.jpg"

}

}

]

}

]

}

}

 

Read more: How to Get Image URL in Customer Cart Using RESTb API

Step 2: Magento 2 Cart Totals API

Now, here you have to hit the following endpoint in order to get the total, subtotals, grand totals, discount amount, shipping details, tax detail, etc. via rest API.

Method: GET

Endpoint:

https://wishusucess.com/rest/V1/carts/mine/totals

Payload: Not required

Get Cart Totals APIResponse:

{

"grand_total": 2408,

"base_grand_total": 2408,

"subtotal": 2408,

"base_subtotal": 2408,

"discount_amount": 0,

"base_discount_amount": 0,

"subtotal_with_discount": 2408,

"base_subtotal_with_discount": 2408,

"shipping_amount": 0,

"base_shipping_amount": 0,

"shipping_discount_amount": 0,

"base_shipping_discount_amount": 0,

"tax_amount": 0,

"base_tax_amount": 0,

"weee_tax_applied_amount": null,

"shipping_tax_amount": 0,

"base_shipping_tax_amount": 0,

"subtotal_incl_tax": 2408,

"shipping_incl_tax": 0,

"base_shipping_incl_tax": 0,

"base_currency_code": "USD",

"quote_currency_code": "USD",

"items_qty": 7,

"items": [

{

"item_id": 283,

"price": 3,

"base_price": 3,

"qty": 1,

"row_total": 3,

"base_row_total": 3,

"row_total_with_discount": 0,

"tax_amount": 0,

"base_tax_amount": 0,

"tax_percent": 0,

"discount_amount": 0,

"base_discount_amount": 0,

"discount_percent": 0,

"price_incl_tax": 3,

"base_price_incl_tax": 3,

"row_total_incl_tax": 3,

"base_row_total_incl_tax": 3,

"options": "[]",

"weee_tax_applied_amount": null,

"weee_tax_applied": null,

"name": "test-product-3"

},

{

"item_id": 284,

"price": 5,

"base_price": 5,

"qty": 1,

"row_total": 5,

"base_row_total": 5,

"row_total_with_discount": 0,

"tax_amount": 0,

"base_tax_amount": 0,

"tax_percent": 0,

"discount_amount": 0,

"base_discount_amount": 0,

"discount_percent": 0,

"price_incl_tax": 5,

"base_price_incl_tax": 5,

"row_total_incl_tax": 5,

"base_row_total_incl_tax": 5,

"options": "[]",

"weee_tax_applied_amount": null,

"weee_tax_applied": null,

"name": "test-product-4"

},

{

"item_id": 285,

"price": 900,

"base_price": 900,

"qty": 2,

"row_total": 1800,

"base_row_total": 1800,

"row_total_with_discount": 0,

"tax_amount": 0,

"base_tax_amount": 0,

"tax_percent": 0,

"discount_amount": 0,

"base_discount_amount": 0,

"discount_percent": 0,

"price_incl_tax": 900,

"base_price_incl_tax": 900,

"row_total_incl_tax": 1800,

"base_row_total_incl_tax": 1800,

"options": "[]",

"weee_tax_applied_amount": null,

"weee_tax_applied": null,

"name": "Indus Happy Hybrid Chilli seeds 10gm + 10gm - Offer Buy 1 Get 1"

},

{

"item_id": 290,

"price": 200,

"base_price": 200,

"qty": 3,

"row_total": 600,

"base_row_total": 600,

"row_total_with_discount": 0,

"tax_amount": 0,

"base_tax_amount": 0,

"tax_percent": 0,

"discount_amount": 0,

"base_discount_amount": 0,

"discount_percent": 0,

"price_incl_tax": 200,

"base_price_incl_tax": 200,

"row_total_incl_tax": 600,

"base_row_total_incl_tax": 600,

"options": "[]",

"weee_tax_applied_amount": null,

"weee_tax_applied": null,

"name": "Kalichakra – Metarhizium anisopliae (Wettable Powder) BioInsecticide (IPL)"

}

],

"total_segments": [

{

"code": "subtotal",

"title": "Subtotal",

"value": 2408

},

{

"code": "shipping",

"title": "Shipping & Handling (Free Shipping - Free)",

"value": 0

},

{

"code": "tax",

"title": "Tax",

"value": 0,

"extension_attributes": {

"tax_grandtotal_details": []

}

},

{

"code": "grand_total",

"title": "Grand Total",

"value": 2408,

"area": "footer"

}

]

}
Similar Posts:

 

As a Magento 2 developer, while creating your store, you have to get much information through APIs such as shopping cart item, subtotal, grand total, billing and shipping address, etc., and all we can be get through the above endpoints.

 

Conclusion of Cart Totals API

By following the above steps you can get detailed data on the cart items of a customer such as subtotal, grand total, and billing & shipping address. Here are four approaches:

  • Get items information of your carts.
  • Get items quantity in the cart and the total products in the cart.
  • Get items total price and grand total price in customer cart.
  • Get the billing and shipping addresses of the customer.

Wishusucess GitHub

Leave a Reply