Development discussions around Shopify APIs
Hi,
I am read all document and forum post regarding creating order with live item level discount, but none of them are working for me.
Here is my JSON payload.
{ "order":{ "discount_codes":[ { "code":"RAKESHTE2ST", "amount":"45" } ], "email":"foo@example.com", "line_items":[ { "variant_id":21516219908176, "quantity":1, "discount_allocations": [ { "amount": "45", "discount_application_index": 0 } ] }, { "variant_id":21516220006480, "quantity":1 } ] } }
Discount code is configured to give 30% on one of variant that I mentioned in line items.
Expected result is having discount on that 21516219908176 ( variant ID ) not on other. But its being applied prorated on both line items.
Can any one help me please ?
Thanks,
Rakesh
Solved! Go to the solution
This is an accepted solution.
Hey Rakesh,
The current implementation of discounts with the Order API only allows discount codes to be applied to the whole order, not at a line item level.
The discount_allocations array is also read only, so it will be ignored when you include it in your calls. When using your example call you provided, it could be altered like this so that discount_allocations is no longer present :
{ "order":{ "discount_codes":[ { "code":"RAKESHTE2ST", "amount":"45" } ], "email":"foo@example.com", "line_items":[ { "variant_id":21516219908176, "quantity":1, }, { "variant_id":21516220006480, "quantity":1 } ] } }
That would apply a flat discount of $45 to the entire order.
The DraftOrder API does support discounts at a line item level though, so you may want to experiment with creating draft orders instead and then converting them into completed orders afterwards.
Josh | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
This is an accepted solution.
Hey Rakesh,
The current implementation of discounts with the Order API only allows discount codes to be applied to the whole order, not at a line item level.
The discount_allocations array is also read only, so it will be ignored when you include it in your calls. When using your example call you provided, it could be altered like this so that discount_allocations is no longer present :
{ "order":{ "discount_codes":[ { "code":"RAKESHTE2ST", "amount":"45" } ], "email":"foo@example.com", "line_items":[ { "variant_id":21516219908176, "quantity":1, }, { "variant_id":21516220006480, "quantity":1 } ] } }
That would apply a flat discount of $45 to the entire order.
The DraftOrder API does support discounts at a line item level though, so you may want to experiment with creating draft orders instead and then converting them into completed orders afterwards.
Josh | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023Summary of EventsBeginning in January of 2023, some merchants reported seeing a large amo...
By Trevor May 15, 2023With 2-Factor Authentication being required to use Shopify Payments, we’re here to help yo...
By Imogen Apr 26, 2023