Solved

How to understand discount_applications and discount_codes in Order object?

lewen
Tourist
5 0 1
"discount_applications": {
    "discount_applications": [
      {
        "type": "manual",
        "title": "custom discount",
        "value": "2.0",
        "value_type": "fixed_amount",
        "description": "customer deserved it",
        "target_type": "line_item",
        "target_selection": "explicit",
        "allocation_method": "across"
      },
      {
        "type": "script",
        "value": "5.0",
        "value_type": "fixed_amount",
        "description": "my scripted discount",
        "target_type": "shipping_line",
        "target_selection": "explicit",
        "allocation_method": "across"
      },
      {
        "code": "SUMMERSALE",
        "type": "discount_code",
        "value": "10.0",
        "value_type": "fixed_amount",
        "target_type": "line_item",
        "target_selection": "all",
        "allocation_method": "across"
      }
    ]
  },
  "discount_codes": [
    {
      "code": "SPRING30",
      "type": "fixed_amount",
      "amount": "30.00"
    }
  ],

This code is part of an order object in link https://shopify.dev/api/admin-rest/2021-10/resources/order#resource_object 

I have some questions about this:

1. Can I have more than one discount_application on one order? The filed discount_applications is an array.

2. There are 3 types, manual and script and discount_code. How do I generate these discounts? When a customer input a code in checkout page, which discount will generate?

3. What is the difference between discount_applications and discount_codes?

Accepted Solution (1)
Shipwire_Dev
Shopify Partner
5 1 1

This is an accepted solution.

One update in my first answer:

There can be 4 types within the discount_application type:

  • type: The discount application type. Valid values:
    • automatic: The discount was applied automatically, such as by a Buy X Get Y automatic discount.
    • discount_code: The discount was applied by a discount code.
    • manual: The discount was manually applied by the merchant (for example, by using an app or creating a draft order).
    • script: The discount was applied by a Shopify Script.

 

And now to answer your follow up questions:

Your mean is there could be 3 discount_application in one order at most. But the types must be different just like as below, right?

=> There could be 4 tyes but Yes, you shouldn't see the same type again in the discount_application field 

 

If there is a discount_code type in discount_application, and there must be a “discount_codes” object in the order?

=> Yes

View solution in original post

Replies 4 (4)

Shipwire_Dev
Shopify Partner
5 1 1

Hello Lewen,

Please find the answers (based on my understanding and experience) as below:

1. Can I have more than one discount_application on one order? The filed discount_applications is an array.

=> You can have more than one type (manual, discount_code, and script) in the discount_application field but discount_application will be present only once on the order level 

 

2. There are 3 types, manual and script, and discount_code. How do I generate these discounts? When a customer input a code on the checkout page, which discount will generate?

=> discount_code - when a customer applies a discount while placing an order, the other 2 can be generated via creating a draft order from Shopify admin and admin scripts in Shopify plus store

 

3. What is the difference between discount_applications and discount_codes?

=> Discount application tells you which discounts are applied on that orders and discount code will give you info on which discount codes are applied on that order

lewen
Tourist
5 0 1

1. Can I have more than one discount_application on one order? The filed discount_applications is an array.

=> You can have more than one type (manual, discount_code, and script) in the discount_application field but discount_application will be present only once on the order level

=> Your mean is there could be 3 discount_application in one order at most. But the types must be different just like as below, right?

"discount_applications": {
    "discount_applications": [
      {
        "type": "manual",
        "title": "custom discount",
        "value": "2.0",
        "value_type": "fixed_amount",
        "description": "customer deserved it",
        "target_type": "line_item",
        "target_selection": "explicit",
        "allocation_method": "across"
      },
      {
        "type": "script",
        "value": "5.0",
        "value_type": "fixed_amount",
        "description": "my scripted discount",
        "target_type": "shipping_line",
        "target_selection": "explicit",
        "allocation_method": "across"
      },
      {
        "code": "SUMMERSALE",
        "type": "discount_code",
        "value": "10.0",
        "value_type": "fixed_amount",
        "target_type": "line_item",
        "target_selection": "all",
        "allocation_method": "across"
      }
    ]
  },

3. What is the difference between discount_applications and discount_codes?

=> Discount application tells you which discounts are applied on that orders and discount code will give you info on which discount codes are applied on that order

=> If there is a discount_code type in discount_application, and there must be a “discount_codes” object in the order?

Shipwire_Dev
Shopify Partner
5 1 1

This is an accepted solution.

One update in my first answer:

There can be 4 types within the discount_application type:

  • type: The discount application type. Valid values:
    • automatic: The discount was applied automatically, such as by a Buy X Get Y automatic discount.
    • discount_code: The discount was applied by a discount code.
    • manual: The discount was manually applied by the merchant (for example, by using an app or creating a draft order).
    • script: The discount was applied by a Shopify Script.

 

And now to answer your follow up questions:

Your mean is there could be 3 discount_application in one order at most. But the types must be different just like as below, right?

=> There could be 4 tyes but Yes, you shouldn't see the same type again in the discount_application field 

 

If there is a discount_code type in discount_application, and there must be a “discount_codes” object in the order?

=> Yes

lewen
Tourist
5 0 1

Thank you.