Order created webhook - how to identify items belonging to a "buy X get Y" offer?

Order created webhook - how to identify items belonging to a "buy X get Y" offer?

rohithrajagopal
Visitor
1 0 0

I'm subscribed to the Order Created event in the webhook and am trying to identify all line items in an order which qualify under the b2g1 (buy 2 get 1) discount that's configured. The JSON response doesn't seem to have a way of doing this. If there are 3 items in the order which all fall under the b2g1 discount, only the cheapest line item seems to have the discount_allocation field populated, the other 2 b2g1 items which are also part of the b2g1 discount bundle don't seem to have any fields which indicate that they are part of the discount bundle.

Here's a sample json (with some fields removed for privacy)

{
"id": 1,
"admin_graphql_api_id": "gid://shopify/Order/1",
"buyer_accepts_marketing": true,
"cancel_reason": null,
"cancelled_at": null,
"client_details": {
},
"closed_at": null,
"company": null,
"confirmed": true,
"currency": "INR",
"current_subtotal_price": "5882.00",
"current_subtotal_price_set": {
"shop_money": {
"amount": "5882.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "5882.00",
"currency_code": "INR"
}
},
"current_total_discounts": "2392.00",
"current_total_discounts_set": {
"shop_money": {
"amount": "2392.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "2392.00",
"currency_code": "INR"
}
},
"current_total_duties_set": null,
"current_total_price": "5882.00",
"current_total_price_set": {
"shop_money": {
"amount": "5882.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "5882.00",
"currency_code": "INR"
}
},
"current_total_tax": "280.10",
"current_total_tax_set": {
"shop_money": {
"amount": "280.10",
"currency_code": "INR"
},
"presentment_money": {
"amount": "280.10",
"currency_code": "INR"
}
},
"discount_codes": [],
"estimated_taxes": false,
"financial_status": "pending",
"fulfillment_status": null,
"original_total_duties_set": null,
"payment_gateway_names": [
],
"phone": null,
"presentment_currency": "INR",
"subtotal_price": "5882.00",
"subtotal_price_set": {
"shop_money": {
"amount": "5882.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "5882.00",
"currency_code": "INR"
}
},
"tags": "",
"tax_lines": [
{
...
},
"channel_liable": false
}
],
"taxes_included": true,
"test": false,
"total_discounts": "2392.00",
"total_discounts_set": {
"shop_money": {
"amount": "2392.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "2392.00",
"currency_code": "INR"
}
},
"total_line_items_price": "8274.00",
"total_line_items_price_set": {
"shop_money": {
"amount": "8274.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "8274.00",
"currency_code": "INR"
}
},
"total_outstanding": "5882.00",
"total_price": "5882.00",
"total_price_set": {
"shop_money": {
"amount": "5882.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "5882.00",
"currency_code": "INR"
}
},
"total_shipping_price_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "INR"
}
},
"total_tax": "280.10",
"total_tax_set": {
"shop_money": {
"amount": "280.10",
"currency_code": "INR"
},
"presentment_money": {
"amount": "280.10",
"currency_code": "INR"
}
},
"total_tip_received": "0.00",
"total_weight": 1500,
"user_id": null,
"billing_address": {
...
},
"customer": { ...
}
},
"discount_applications": [
{
"target_type": "line_item",
"type": "automatic",
"value": "100.0",
"value_type": "percentage",
"allocation_method": "each",
"target_selection": "entitled",
"title": "Buy 2 get 1 "
}
],
"fulfillments": [],
"line_items": [
{
"id": 12,
"fulfillable_quantity": 1,
"fulfillment_service": "manual",
"fulfillment_status": null,
"gift_card": false,
"grams": 500,
"name": "Onion Pink Zariwork Banarasi Unstitched Salwar Suit - One Size",
"price": "3490.00",
"price_set": {
"shop_money": {
"amount": "3490.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "3490.00",
"currency_code": "INR"
}
},
"product_exists": true,
"product_id": 68,
"properties": [],
"quantity": 1,
"requires_shipping": true,
"sku": "SSUS0022159_ONION_PINK",
"taxable": true,
"title": "Onion Pink Zariwork Banarasi Unstitched Salwar Suit",
"total_discount": "0.00",
"total_discount_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "INR"
}
},
"variant_id": 403,
"variant_inventory_management": "shopify",
"variant_title": "One Size",
"vendor": ...,
"tax_lines": [
{
"channel_liable": false,
"price": "166.20",
"price_set": {
"shop_money": {
"amount": "166.20",
"currency_code": "INR"
},
"presentment_money": {
"amount": "166.20",
"currency_code": "INR"
}
},
"rate": 0.05,
"title": "CGST"
}
],
"duties": [],
"discount_allocations": []
},
{
"id": 1275,
"admin_graphql_api_id": "gid://shopify/LineItem/1275",
"fulfillable_quantity": 1,
"fulfillment_service": "manual",
"fulfillment_status": null,
"gift_card": false,
"grams": 500,
"name": "Black Threadwork Chanderi Unstitched Salwar Suit - One Size",
"price": "2392.00",
"price_set": {
"shop_money": {
"amount": "2392.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "2392.00",
"currency_code": "INR"
}
},
"product_exists": true,
"product_id": 66,
"properties": [],
"quantity": 1,
"requires_shipping": true,
"sku": "SSUS0019609_BLACK",
"taxable": true,
"title": "Black Threadwork Chanderi Unstitched Salwar Suit",
"total_discount": "2392.00",
"total_discount_set": {
"shop_money": {
"amount": "2392.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "2392.00",
"currency_code": "INR"
}
},
"variant_id": 39,
"variant_inventory_management": "shopify",
"variant_title": "One Size",
"vendor": ...,
"tax_lines": [
{
"channel_liable": false,
"price": "0.00",
"price_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "INR"
}
},
"rate": 0.05,
"title": "CGST"
}
],
"duties": [],
"discount_allocations": [
{
"amount": "2392.00",
"amount_set": {
"shop_money": {
"amount": "2392.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "2392.00",
"currency_code": "INR"
}
},
"discount_application_index": 0
}
]
},
{
"id": 12,
"admin_graphql_api_id": "gid://shopify/LineItem/12",
"fulfillable_quantity": 1,
"fulfillment_service": "manual",
"fulfillment_status": null,
"gift_card": false,
"grams": 500,
"name": "Mustard Zariwork Banarasi Unstitched Salwar Suit - One Size",
"price": "2392.00",
"price_set": {
"shop_money": {
"amount": "2392.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "2392.00",
"currency_code": "INR"
}
},
"product_exists": true,
"product_id": 669,
"properties": [],
"quantity": 1,
"requires_shipping": true,
"sku": "SSUS0017178_MUSTARD",
"taxable": true,
"title": "Mustard Zariwork Banarasi Unstitched Salwar Suit",
"total_discount": "0.00",
"total_discount_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "INR"
}
},
"variant_id": 393,
"variant_inventory_management": "shopify",
"variant_title": "One Size",
"vendor": "Koskii",
"tax_lines": [
{
"channel_liable": false,
"price": "113.90",
"price_set": {
"shop_money": {
"amount": "113.90",
"currency_code": "INR"
},
"presentment_money": {
"amount": "113.90",
"currency_code": "INR"
}
},
"rate": 0.05,
"title": "CGST"
}
],
"duties": [],
"discount_allocations": []
}
],
"payment_terms": null,
"refunds": [],
"shipping_address": {
... },
"shipping_lines": [
{
"id": 419,
"carrier_identifier": null,
"code": "Free Shipping",
"delivery_category": null,
"discounted_price": "0.00",
"discounted_price_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "INR"
}
},
"phone": null,
"price": "0.00",
"price_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "INR"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "INR"
}
},
"requested_fulfillment_service_id": null,
"source": "shopify",
"title": "Free Shipping",
"tax_lines": [],
"discount_allocations": []
}
]
}

 

Replies 0 (0)