Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

...

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.

...

Type of script: Line Item

Code Block
##

## 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
 =
  case cart.discount_code
    when

    when CartDiscount::Percentage
      if

      if cart.subtotal_price >= cart.discount_code.minimum_order_amount
       

        cart_subtotal_without_gc = cart.line_items.reduce(Money.zero) do |total, item|
          total +

          total + (item.variant.product.gift_card? ? Money.zero : item.line_price)

        end

       

        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

       

      else
        cart.subtotal_price

      end

    when

      end
    when CartDiscount::FixedAmount
      if

      if cart.subtotal_price >= cart.discount_code.minimum_order_amount
       

        [cart.subtotal_price - cart.discount_code.amount, Money.zero].max

      else

       

      else
        cart.subtotal_price

      end

    else

     

      end
    else
      cart.subtotal_price

  end

##

## Add the discount information for each line item in the cart

##


  end


##
## Add the discount information for each line item in the cart
##
Input.cart.line_items.each do |line_item|
  properties =

  properties = line_item.properties_was
  if properties

  if properties ==
nil

    properties = Hash.new

  end

  properties["_fenixData"] = {"oVal"=>total
 nil
    properties = Hash.new
  end
  properties["_fenix_order_value"] = total.cents.to_s()
}  line

  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