Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

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["_fenixData"] = {"oVal"=>total.cents.to_s()}

  line_item.change_properties(properties,message:"order value")

end

Output.cart = Input.cart

Steps to apply the script in Shopify

  1. Go to Shopify Dashboard

  2. Next go to Apps → Script Editor

  3. Create Blank Line Item Script

  4. Paste the above code snippet in the script created in Step #3

  5. Save and Publish

  • No labels