Shipping discount applied via Script Editor not present in Checkout data

Tourist
6 0 1

 

Hi!

 

I have the following Shipping Script published on my store with Script Editor:

 

FREE_SHIPPING_CODES = %w(... some codes ...)

Input.shipping_rates.each do |shipping_rate| if Input.cart.discount_code and FREE_SHIPPING_CODES.include?(Input.cart.discount_code.code) shipping_rate.apply_discount(shipping_rate.price, message: "Free shipping!") end
end

 

The intent is to waive shipping fees for some specific discount codes (e.g. a code we give out to our employees).

This is meant to enable us to waive shipping fees while, for instance, applying a 25% discount on the order total.

 

I have noticed some glitches with this method:

  1. If I apply this code on the payment methods step of the checkout, the shipping rate is not updated to "Free"
  2. If I go back to the shipping methods step, then shipping is immediately updated to "Free"

Those are not a show stopper for me but that doesn't look like an expected behaviour. Should my script update the cart's shipping as well? Is that even possible from a shipping script?

 

The real problem I've got though, is this:

  • When the discount code is applied and free shipping is correctly taken into account, using the REST API to get my Checkout object will return JSON data with no trace of that shipping discount at all:
{
	"checkout": {
		"clone_url": "https://myshop.myshopify.com/29147422/checkouts/2ff2725af6625d516b52ebeafa5abc9a/clone",
		"completed_at": null,
		"created_at": "2019-03-19T22:38:14+01:00",
		"currency": "EUR",
		"presentment_currency": "EUR",
		"customer_id": 1109682749489,
		"customer_locale": "fr",
		"device_id": null,
		"discount_code": "OL_TEST_4",
		"email": "---",
		"legal_notice_url": null,
		"location_id": null,
		"name": "#8258806939697",
		"note": "",
		"note_attributes": {},
		"order_id": null,
		"order_status_url": null,
		"order": null,
		"payment_due": "82.50",
		"payment_url": "https://elb.deposit.shopifycs.com/sessions",
		"payments": [],
		"phone": null,
		"shopify_payments_account_id": null,
		"privacy_policy_url": "https://myshop.myshopify.com/29147422/policies/2175729713.html",
		"refund_policy_url": "https://myshop.myshopify.com/29147422/policies/2175696945.html",
		"requires_shipping": true,
		"reservation_time_left": 0,
		"reservation_time": null,
		"source_identifier": null,
		"source_name": "checkout_next",
		"source_url": null,
		"subtotal_price": "82.50",
		"shipping_policy_url": null,
		"tax_exempt": false,
		"taxes_included": true,
		"terms_of_sale_url": null,
		"terms_of_service_url": "https://myshop.myshopify.com/29147422/policies/2175762481.html",
		"token": "---",
		"total_price": "82.50",
		"total_tax": "0.00",
		"total_tip_received": "0.00",
		"total_line_items_price": "198.00",
		"updated_at": "2019-03-19T22:41:07+01:00",
		"user_id": null,
		"web_url": "https://myshop.myshopify.com/29147422/checkouts/2ff2725af6625d516b52ebeafa5abc9a?key=e00299342059c8b2f8061d3ca4ac5cf5",
		"line_items": [{
			"id": "b521c7dc84f870438e441da86ad91f5a",
			"key": "---",
			"product_id": 1387688558641,
			"variant_id": 12451477127217,
			"sku": "",
			"vendor": "MyShop stock",
			"title": "Denim Shirt",
			"variant_title": "Washed / L",
			"taxable": true,
			"requires_shipping": true,
			"gift_card": false,
			"price": "99.00",
			"compare_at_price": "99.00",
			"line_price": "99.00",
			"properties": {
				"_order_type": "stock",
				"_shipment": "shipment_stock"
			},
			"quantity": 1,
			"grams": 300,
			"fulfillment_service": "manual",
			"applied_discounts": []
		}, {
			"id": "4d620bf9ac85b06d5c8a073e4eafc04e",
			"key": "---",
			"product_id": 1387688558641,
			"variant_id": 12451477127217,
			"sku": "",
			"vendor": "MyShop stock",
			"title": "Denim shirt",
			"variant_title": "Washed / L",
			"taxable": true,
			"requires_shipping": true,
			"gift_card": false,
			"price": "99.00",
			"compare_at_price": "99.00",
			"line_price": "99.00",
			"properties": {
				"_order_type": "stock",
				"_shipment": "shipment_stock"
			},
			"quantity": 1,
			"grams": 300,
			"fulfillment_service": "manual",
			"applied_discounts": []
		}],
		"gift_cards": [],
		"tax_lines": [],
		"tax_manipulations": [],
		"shipping_line": {
			"handle": "shopify-International%20Shipping-20.00",
			"price": "20.00",
			"title": "International Shipping"
		},
		"shipping_rate": {
			"id": "shopify-International%20Shipping-20.00",
			"price": "20.00",
			"title": "International Shipping"
		},
		"shipping_address": {
			...
		},
		"credit_card": null,
		"billing_address": null,
		"applied_discount": {
			"amount": "82.50",
			"title": "OL_TEST_4",
			"description": null,
			"value": "100.00",
			"value_type": "percentage",
			"non_applicable_reason": null,
			"applicable": true
		}
	}
}

Once I pay and my Checkout is transitioned to an Order, getting the Order JSON data properly shows the applied discount at various places (shipping_line, discount_allocations, ...).

 

So I have several questions because of this:

  1. Why is the Checkout data incomplete?
  2. How does Shopify finds back the shipping discount to be applied on the Checkout page? And when processing the order?
  3. Is there a better way for me to achieve the same result?
  4. If not, is there any way for me to get back the shipping discount from the Checkout or an associated object?

Thanks for your help!

 

1 Like
New Member
3 0 0

Hey @olance,

 

Were you able to get any further with this issue? Just encountered the same issue.

0 Likes
Tourist
6 0 1
Hey!

No I don't think there's anything to be done unfortunately.
My understanding, which has been more or less confirmed by Shopify support,
is that the "Admin" API is not on par with all the features Shopify have
implemented in their own backoffice...

So, especially around discounts, there are many behaviours you can't
reproduce using the API, and I guess having this "double discount" applied
is one of them.
0 Likes