Shopify Discount issue on Checkout
As part of the onboarding process for Shopify Customers, the onboarding team needs to share the below Shopify limitation to the retailer and suggest the solution before they go live.
Shopify Limitation
On the checkout page, if the customer applies a discount coupon, Shopify can't send the discounted cart's subtotal to a third party shipping rate provider like Fenix. Shopify applies the discount successfully on the frontend. However, when Shopify calls Fenix to get the rates after the discount is applied, it doesn't send any information about the discount and Fenix thinks that no discount is applied on the cart.
Implication
If Fenix doesn’t receive the discounted cart value, it will not be able to apply the tier based shipping options we set up for them. For example, please follow the below example.
Â
The Economy Free Shipping threshold is $99. So, if the customer cart's subtotal is $100 (Free shipping eligible) and then he applies a discount which brings his cart total to below $99 (not eligible to Free shipping now), then Fenix would still think the cart value is above $100 as it doesn't receive the discounted cart value and would still offer Free Shipping.
Â
Solution
Note: Only applicable to Shopify Plus customers
Since it is a Shopify limitation, we use a Line Item script which calculates the discounted cart value and adds that information to the line item properties. Once Fenix gets the checkout request, it simply reads this information and uses it to apply the free shipping rules.
We have added this line item script in the test store with the name: Line Item script to send discount information to Fenix
Below is how you can see the added information (_fenixData) in the order details page.
Â
Script that we can apply for any Shopify Plus customer to resolve the issue
Script Language: Ruby
Type of script: Line Item
##
## This script is used to send the discounted cart information to Fenix as Shopify doesn't
## include the discount information while sending the request to Fenix on the checkout page.
##
cart = Input.cart
##
## Calculate the discount information based on its type.
##
total =
case cart.discount_code
when CartDiscount::Percentage
if cart.subtotal_price >= cart.discount_code.minimum_order_amount
cart_subtotal_without_gc = cart.line_items.reduce(Money.zero) do |total, item|
total + (item.variant.product.gift_card? ? Money.zero : item.line_price)
end
gift_card_amount = cart.subtotal_price - cart_subtotal_without_gc
cart_subtotal_without_gc * ((Decimal.new(100) - cart.discount_code.percentage) / 100) + gift_card_amount
else
cart.subtotal_price
end
when CartDiscount::FixedAmount
if cart.subtotal_price >= cart.discount_code.minimum_order_amount
[cart.subtotal_price - cart.discount_code.amount, Money.zero].max
else
cart.subtotal_price
end
else
cart.subtotal_price
end
##
## Add the discount information for each line item in the cart
##
Input.cart.line_items.each do |line_item|
properties = line_item.properties_was
if properties == nil
properties = Hash.new
end
properties["_fenix_order_value"] = total.cents.to_s()
line_item.change_properties(properties,message:"order value")
end
Output.cart = Input.cart |
Â
Steps to apply the script in Shopify
Go to Shopify Dashboard
Next go to Apps → Script Editor
Create Blank Line Item Script
Paste the above code snippet in the script created in Step #3
Save and Publish