Can not set discount base on cart line item index instead of the product Variant

Can not set discount base on cart line item index instead of the product Variant

BaoMai_LA
Shopify Partner
3 0 1

For now Shopify only have 2 options for discount

 

https://shopify.dev/docs/api/functions/reference/order-discounts/graphql/common-objects/target

 

Do we have any way to set discount on cart item index, instead of the productVairant 

In my case, there are 2 items in cart with the same variant. But they have different properties for Private Sale

Input:

{
  "cart": {
    "lines": [
      {
        "id": "gid://shopify/CartLine/0",
        "quantity": 2,
        "cost": {
          "amountPerQuantity": {
            "amount": "785.95"
          }
        },
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid://shopify/ProductVariant/47641613599039",
          "product": {
            "id": "gid://shopify/Product/9118075814207"
          }
        }
      },
      {
        "id": "gid://shopify/CartLine/1",
        "quantity": 1,
        "cost": {
          "amountPerQuantity": {
            "amount": "785.95"
          }
        },
        "TeamStore_Private": {
          "value": "$765.95"
        },
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid://shopify/ProductVariant/47641613599039",
          "product": {
            "id": "gid://shopify/Product/9118075814207"
          }
        }
      }
    ],
    "buyerIdentity": null
  }
}

Output:

{
  "discounts": [
    {
      "targets": [
        {
          "productVariant": {
            "id": "gid://shopify/ProductVariant/47641613599039",
            "quantity": 1
          }
        }
      ],
      "value": {
        "fixedAmount": {
          "amount": 20
        }
      },
      "message": "Team Store"
    }
  ],
  "discountApplicationStrategy": "ALL"
}

The discount should be affect for the first item has Private Sale instead the second one.

 

Capture.PNG

 

 

Reply 1 (1)

tobebuilds
Shopify Partner
501 35 132

You can't target a specific line item with Functions discounts right now.

 

There's a popular GitHub discussion thread where devs are requesting this functionality: https://github.com/Shopify/function-examples/discussions/199

Founder, Regios Discounts app (4.8 stars, 77 reviews, Built for Shopify)
- Custom discounts made simple
- "Just about any discount you'll ever need"
- Built by an ex-Google software engineer