Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.
Solved

Discounted Cart Total in CarrierService API

manujames
Shopify Partner
2 0 0

We have a Shopify app which is using CarrierService API to display shipping rates to the customers. 

If a buyer applies a discount coupon at checkout page, we are not getting any information about the discount in the data received in callback url. 

Is there any way to get the discounted cart total, and calculate and return shipping charges based on that to the checkout page?

Accepted Solution (1)

jon551
Shopify Staff
28 7 5

This is an accepted solution.

Hi Manujames,

 

Thanks for your post. The [CarrierService API] does not currently have a way to provide information about cart level discounts in the information sent to the callback url.

 

It's important to keep in mind that buyers can still add or remove discount codes on the payment step of checkout after the CarrierService API has acquired a rate on the shipping step so the total cart price could still change after that shipping price has been selected.

 

Hope you have a great day,

Jon551 | API Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 9 (9)

Don
Shopify Staff
2750 198 384

Hi there @manujames!

 

I just wanted to let you know I have moved your query here to our dedicated API forums.

 

As we're unable to provide this kind of support ourselves directly, this is the best place for this kind of question

 

These threads are monitored and responded to by our own developers and Partners, so there's a good chance you'll get some quality info here.

 

All the best

Don | Social Care @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

jon551
Shopify Staff
28 7 5

This is an accepted solution.

Hi Manujames,

 

Thanks for your post. The [CarrierService API] does not currently have a way to provide information about cart level discounts in the information sent to the callback url.

 

It's important to keep in mind that buyers can still add or remove discount codes on the payment step of checkout after the CarrierService API has acquired a rate on the shipping step so the total cart price could still change after that shipping price has been selected.

 

Hope you have a great day,

Jon551 | API Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

manujames
Shopify Partner
2 0 0

Hello Jon,

Thank you for the reply. I understood the scenario with discount codes being applied after the CarrierService API call.

However is it possible to provide discounted price in case of automatic discount in product level and order level?

manujames_0-1662096622877.pngmanujames_1-1662096675256.png

 

jon551
Shopify Staff
28 7 5

Hi Manujames,

 

Thanks for your reply. Currently the information the CarrierService API sends to the callback url has a 'price' field for each line item, and that 'price' field shows the regular price (with no discounts at all) of a single instance of that line item without a decimal.

 

It wasn't mentioned in this thread but the 'grams' field also only shows the weight of a single instance of the line item.

 

So for example if the item's regular price is $1.00, each weighing 50 grams and the order contains 5 of them, the related data for that line item sent to the callback url would be like: "price"=>100, "quantity"=>5, "grams"=>50

 

Hope you have a great day,

Jon551 | API Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Tonegolf71
Shopify Partner
11 0 5

Hi, we are sufferring with this issue too. How would you propose a store could (consistently) offer free shipping when the order total is over a certain amount? At the moment, if a discount applies that takes an order back below a threshold, the customer still (incorrectly) would get free shipping.

Cfvilla
Shopify Partner
3 0 1

Sadly there is no solution to this.

I've faced this issue when I started developing Shopify Apps two and a half years ago, and at that time it was a known issue for years (Thread link for additional context: Discount info missing in shipping calculate webhook - Shopify Community)
I came here today to check if there was any updates regarding this,  but things seems to be the same.

Tonegolf71
Shopify Partner
11 0 5

Once it is fully released, I'm hoping to use https://www.shopify.com/uk/enterprise/shopify-functions for our free shipping use case.

turanturan
Shopify Partner
1 0 0

Adding or removing discount code in checkout's payment step still sends the information to the callback url and shipping rate in checkout is updated. It's just totally useless as the discount doesn't show up in the payload. I just can't understand the reasoning behind this. It would be very important to know what the customer is actually paying for the product when calculating the rate for shipping. 

MrPunkin
Shopify Partner
90 0 50

We found a solution that worked for us since we are the developer of both our own CarrierService app and our store's theme. We noticed that `properties: {}` was being passed to our quote endpoint which gave us the idea to set private line item properties via the Ajax Cart API on the cart page for items adjusted via automatic discounts.

 

Any item in the cart that has a `discounted_price` lower than `price` gets a `_discounted_price` line item property set. This gets passed through to the quote and used in place of the price, if it exists on that item, otherwise it just falls back to the regular item price.

 

The only real downsides are:

  • relying on the JS call to cart/change.js for this to work.
  • The visual display of the property showing up on orders in the admin (see image attached below).
  • The `discounted_price` doesn't always round exactly the same from the cart calculated value to the end result in checkout / admin.

 

// Example call to cart/change.js from cart page
jQuery.post(window.Shopify.routes.root + 'cart/change.js', {
  line: item.index,
  quantity: item.quantity,
  properties: {
    '_discounted_price': item.discounted_price
  }
});
## Example calculation in our Ruby CarrierService quote method

cart_value = items.map{ |item|  (item.dig(:properties, :_discounted_price) || item.price).to_i * (item[:quantity] || 0).to_i }.sum

 Screenshot 2022-11-22 at 7.03.17 PM.png