FROM CACHE - jp_header

REST Admin Order APIにおけるLine Itemsの割引について

rmrm
訪問者
1 0 0

英語圏でのコミュニティにて似たような質問がございますが、回答が提示されず議論が止まっておりますのでこちらで質問をさせていただきます。

https://community.shopify.com/c/shopify-apis-and-sdks/orders-api-adding-line-item-discounts/m-p/4602...

 

Admin Order APIにて特定の商品に対してのみ割引率が適用されるクーポンでの注文を反映をさせたいのですが、

Order APIのドキュメントに載っております discount_codes で反映をさせると、全体に対して割引が適用されます。

 

order > line_items > discount_allocations > discount_application_index に関しても調べまして

order > discount_applications はread-only ある且つ、discount_codes にて指定した上で discount_application_index を指定するのかと思ったのですが、それでも全体に適用されてしまいます。

 

 

上記仕様からOrder APIにて特定の商品に対して割引を適用させる注文を作成するにはどのように実現すればよいかご教示いただくことは可能でしょうか。

(discount_codesのtypeにfixed_amountをamountに割引額を入れれば似たようなorderは作れると思いますが少しモヤモヤするためこちらで質問をさせていただきました。)

 

以下にこちらで試してみた擬似的なコード掲載させていただきます。

 

・Order APIにてPOST

ex ) 1,250円の商品A * 1つ、1,250円の商品B * 2つ購入し、商品Aに対してのみ割引率20%を適用したい場合

 

サンプルとして実在しないクーポンを適用しておりますが、実在するクーポンをdiscount_codeにて指定しても同様の現象が起きます。

{
    "order":{
        "discount_codes" : [
            {
                "code": "SAMPLE_COUPON_01",
                "amount": "20.0",
                "type": "percentage"
            }
        ],
        "line_items":[
            {
                "quantity":1,
                "variant_id":11111111111111,
                "discount_allocations":[
                    {
                        "amount":"250.0",
                        "discountApplicationIndex": 0
                    }
                ]
            },
            {
                "quantity":2,
                "variant_id":22222222222222,
                "discount_allocations": []
            }
        ]
    }
}

 

・Response (抜粋)

割引が全体に適用されてしまっています。

{
    "order": {
        "currency": "JPY",
        "current_subtotal_price": "3000",
        "current_total_discounts": "750",
        "current_total_price": "3000",
        "discount_codes": [
            {
                "code": "SAMPLE_COUPON_01",
                "amount": "750",
                "type": "percentage"
            }
        ],
        "subtotal_price": "3000",
        "total_discounts": "750",
        "total_line_items_price": "3750",
        "total_price": "3750",
        "discount_applications": [
            {
                "target_type": "line_item",
                "type": "manual",
                "value": "20.0",
                "value_type": "percentage",
                "allocation_method": "across",
                "target_selection": "all",
                "title": "SAMPLE_COUPON_01",
                "description": "SAMPLE_COUPON_01"
            }
        ],
        "line_items": [
            {
                "price": "1250",
                "quantity": 1,
                "total_discount": "0",
                "discount_allocations": [
                    {
                        "amount": "250",
                        "amount_set": {
                            "shop_money": {
                                "amount": "250",
                                "currency_code": "JPY"
                            },
                            "presentment_money": {
                                "amount": "250",
                                "currency_code": "JPY"
                            }
                        },
                        "discount_application_index": 0
                    }
                ]
            },
            {
                "price": "1250",
                "quantity": 2,
                "total_discount": "0",
                "discount_allocations": [
                    {
                        "amount": "500",
                        "amount_set": {
                            "shop_money": {
                                "amount": "500",
                                "currency_code": "JPY"
                            },
                            "presentment_money": {
                                "amount": "500",
                                "currency_code": "JPY"
                            }
                        },
                        "discount_application_index": 0
                    }
                ]
            }
        ],
    }
}

 

以上です。

私の認識がそもそも間違えている場合ご指摘いただけますと幸いです。

何卒よろしくお願い申し上げます。

 

 

0件の返信0