Can somebody explain me how to precisely fill discount_code/ discount_applications/discount_allocations parameters in the Orders API ? And whether they are taken into account yes or no ?
I have read the changes to discount_codes post where it says that it allocates to line items, which it is doing, but NOT according to the rules of the discount code, as it seems.
It all works fine for shipping discount (free shipping) and order level product discounts (25% of entire order or 10 EUR off entire order). It spreads the total amount across all line items. So far so good.
But if I enter more complicated discounts ( with entitlements, eg. 3 items in an order and only 25% off on 2 out of the 3 ),
it spreads the total discounts (the total amount is correct) to ALL 3 items.
I have all the information available from my own application (where the discounts are correctly calculated, both total and for each line item (based on the logic of the parameters in the discount code, because I retrieve the discount code and use those parameters for calculation, but no matter what I enter, it keeps spreading it over all the line items, which is not correct.
The example:
2 pc item 1. price = 22.50. total value = 45. The product is entitled so 25% discount applies
Total value = 33.75. Discount = 11.25
1 pc item 2 price = 22.50 total value = 22.50. No entitled discount
Total value = 56.25. Total discount = 11.25
The discount code = TESTPERCENTENTITLED. (percentage based on entitled products, the first product is entitled, the second not.
I want to enter the discount code (and not calculated manually, because the discount code usage should be recorded.
I seems that I AM FORCED to enter the discount code object with the total amount = 11.25 and type: ‘fixed amount’, otherwise things go seriously wrong and the total discount is not calculated correctly (even though I also supply it in the total_discounts field
If I provide a discount_applications objects with fields, corresponding to the parameters of the discount_code. Shopify ignores it. It keeps giving back following object in the order.
RESULT
“discount_applications”: [
{
“type”: “discount_code”,
“value”: “11.25”,
“value_type”: “fixed_amount”,
“allocation_method”: “across”,
“target_selection”: “all”,
“target_type”: “line_item”,
“code”: “TESTPERCENTENTITLED”
}
],
It seems that Shopify well records the objects but does not calculate the discount according to the parameters in the discount code. And it also ignores whether I supply a discount allocations object in the api or not. (in the example below, I supplied it manually
WHAT I SUPPLY IN THE API
line_items: [
{
price: 22.5,
quantity: 2,
variant_id: 28372796768328,
discount_allocations: [{ amount: 11.25 }],
tax_lines: [{ title: ‘VAT’, price: 5.86, rate: 0.21 }]
},
{
price: 22.5,
quantity: 1,
variant_id: 28372796801096,
discount_allocations: ,
tax_lines: [{ title: ‘VAT’, price: 3.91, rate: 0.21 }]
}
],
discount_codes: [{
code: ‘TESTPERCENTENTITLED’,
amount: 11.25,
}],
subtotal_price: 56.25,
total_price: 56.25,
total_line_items_price: 67.5,
total_discounts: 11.25,
total_tax: 9.77,
WHAT IT GET BACK IN LINE ITEMS IS THE FOLLOWING
As you can see the discount_allocations are different, as it spreads the total mount across all line items, instead of the ‘each’ allocation method and ‘entitled’ target_selection’ which are the parameters in the discount_code.
“line_items”: [
{
“id”: 2374214713416,
“variant_id”: 28372796768328,
“title”: “PRODUCT2”,
“quantity”: 2,
“sku”: “5420079553934”,
“variant_title”: “1”,
“vendor”: “TEST”,
“fulfillment_service”: “manual”,
“product_id”: 3583951077448,
“requires_shipping”: true,
“taxable”: true,
“gift_card”: false,
“name”: “PRODUCT 1”,
“variant_inventory_management”: “shopify”,
“properties”: ,
“product_exists”: true,
“fulfillable_quantity”: 2,
“grams”: 150,
“price”: “22.50”,
“total_discount”: “0.00”,
“fulfillment_status”: null,
“price_set”: {
“shop_money”: {
“amount”: “22.50”,
“currency_code”: “EUR”
},
“presentment_money”: {
“amount”: “22.50”,
“currency_code”: “EUR”
}
},
“total_discount_set”: {
“shop_money”: {
“amount”: “0.00”,
“currency_code”: “EUR”
},
“presentment_money”: {
“amount”: “0.00”,
“currency_code”: “EUR”
}
},
“discount_allocations”: [
{
“amount”: “7.51”,
“discount_application_index”: 0,
“amount_set”: {
“shop_money”: {
“amount”: “7.51”,
“currency_code”: “EUR”
},
“presentment_money”: {
“amount”: “7.51”,
“currency_code”: “EUR”
}
}
}
],
“admin_graphql_api_id”: “gid://shopify/LineItem/2374214713416”,
“tax_lines”: [
{
“title”: “VAT”,
“price”: “5.86”,
“rate”: 0.21,
“price_set”: {
“shop_money”: {
“amount”: “5.86”,
“currency_code”: “EUR”
},
“presentment_money”: {
“amount”: “5.86”,
“currency_code”: “EUR”
}
}
}
]
},
{
“id”: 2374214746184,
“variant_id”: 28372796801096,
“title”: “PRODUCT2”,
“quantity”: 1,
“sku”: “5420079553958”,
“variant_title”: “Grey”,
“vendor”: “TEST”,
“fulfillment_service”: “manual”,
“product_id”: 3583951077448,
“requires_shipping”: true,
“taxable”: true,
“gift_card”: false,
“name”: “PRODUCT 2”,
“variant_inventory_management”: “shopify”,
“properties”: ,
“product_exists”: true,
“fulfillable_quantity”: 1,
“grams”: 150,
“price”: “22.50”,
“total_discount”: “0.00”,
“fulfillment_status”: null,
“price_set”: {
“shop_money”: {
“amount”: “22.50”,
“currency_code”: “EUR”
},
“presentment_money”: {
“amount”: “22.50”,
“currency_code”: “EUR”
}
},
“total_discount_set”: {
“shop_money”: {
“amount”: “0.00”,
“currency_code”: “EUR”
},
“presentment_money”: {
“amount”: “0.00”,
“currency_code”: “EUR”
}
},
“discount_allocations”: [
{
“amount”: “3.74”,
“discount_application_index”: 0,
“amount_set”: {
“shop_money”: {
“amount”: “3.74”,
“currency_code”: “EUR”
},
“presentment_money”: {
“amount”: “3.74”,
“currency_code”: “EUR”
}
}
}
],
“admin_graphql_api_id”: “gid://shopify/LineItem/2374214746184”,
“tax_lines”: [
{
“title”: “VAT”,
“price”: “3.91”,
“rate”: 0.21,
“price_set”: {
“shop_money”: {
“amount”: “3.91”,
“currency_code”: “EUR”
},
“presentment_money”: {
“amount”: “3.91”,
“currency_code”: “EUR”
}
}
}
]
}
],
IF I SUPPLY the discount applications object according to the discount code, Shopify ignores it.
And if start tampering a bit with the parameters, I can make it work, but the it says type ‘manual’ and most importantly it becomes a CUSTOM DISCOUNT, and no longer counts for the usage of the discount code
example
discount_applications: [
{
type: ‘discount_code’,
value: “25.0”,
value_type: ‘percentage’,
allocation_method: ‘each’,
target_selection: ‘entitled’,
target_type: ‘line_item’,
code: “TESTPERCENTENTITLED”
}
],