Orderのline_itemsのtotal_discountに値を持たせる方法を教えてください

Shopifyの注文データを別のツールに渡しています。

商品ごとの割引価格を取得したいのですが、

受け取る側のツールにはorder > order_line(line_itemsと同じと思われる)> total_discountとtotal_discount_setしかありません。

ドキュメントには以下のように記載があります。

  • total_discount: The total amount of the discount allocated to the line item in the shop currency. This field must be explicitly set using draft orders, Shopify scripts, or the API. Instead of using this field, Shopify recommends using discount_allocations, which provides the same information.
  • total_discount_set: The total amount allocated to the line item in the presentment currency. Instead of using this field, Shopify recommends using discount_allocations, which provides the same information.

https://shopify.dev/docs/api/admin-rest/2024-10/resources/order

ドキュメントの内容から、何もしない場合、これらの値は使用できないという認識をしています。

このtotal_discountやtotal_discount_setに値を持たせる方法があれば教えてください。

*discount_allocationsの使用を勧められていますが、データを受け取る側のツールが、discount_allocationsを受け取れません…

Shopify Flowの「orderEditAddLineItemDiscount」のミューテーションを使用し、既存の「discount_allocations」を取得して、新しくディスカウントを追加すると、total_discountの値は期待通りになったのですが、元のdiscount_allocationsの値にも追加されてしまいうまくいきませんでした。(orderEditAddLineItemDiscount というミューテーションなので、追加されるだけなのは当たり前なのですが… しかもorderEditDeleteLineItemDiscountがFlowの中にはありませんでした…)

Flowやその他のやり方で何か手段をご存知の方がいらっしゃいましたら教えてください。

@monchan

Shopifyの注文データを別のツールに渡しています。

「別のツール」にはどのようにデータを渡すのでしょうか?

もし、API経由でデータを渡すのでしたら、

Shopify Flowで、Run Code アクションを利用して「別のツールのAPIに渡す用のデータ」を作成し、APIコールしてしまうのが簡単かと思います。

CSVで渡す場合も、

同様に、Shopify Flowで、Run Code アクションを利用して「別のツールに渡す用のCSVデータ」を作成してスプレッドシートに流し込み、後はスプレッドシート側でGASでデータを整える、というのが簡単かと思います。

(GASは原因が分かりにくいエラーが発生しがちなのでおすすめではないのですが。)

ご参考まで。

(キュー田辺)