Solved

BUG: Product Discount Function - Extra lines being removed from Cart when using Storefront API

originmaster
Shopify Partner
42 2 19

Background:

We use a product discount function for things like volume discounts - for example:

 

Buy 2 and get 10% off

We've set it up in this case to work in multiples of 2. So if a customer adds 3 of that item to cart, 2 will be discounted and 1 will be the original price and will be split into it's own line item.

 

Issue:

When the non-discounted item is removed from cart using the storefront API the discounted items are also removed, even though they have a different line ID (line ID is used to remove a cart line via the api).

 

Some more detail:

Cart lines before attempting to removing the first one

 

[
// Non-discounted line
{
    "id": "gid://shopify/CartLine/ddd73847-ee2f-4a6d-a9ab-e8dce2832627?cart=Z2NwLXVzLWNlbnRyYWwxOjAxSE00WDI1M0JRMUNaNlBIMk03VDBaRDRZ",
    "quantity": 1,
   ...
},
// Discounted lines - different line ID but share the same variant ID
{
    "id": "gid://shopify/CartLine/1db25861-a954-4a0f-8aa6-3ee711eba960?cart=Z2NwLXVzLWNlbnRyYWwxOjAxSE00WDI1M0JRMUNaNlBIMk03VDBaRDRZ",
    "quantity": 2,
   ...
}
]

 

 

Payload of removeCartLines mutation, clearly showing the lineID to be removed in the variables object

 

{
    "query": "\n  mutation removeCartLines($cartId: ID!, $lineIds: [ID!]!) {\n    cartLinesRemove(cartId: $cartId, lineIds: $lineIds) {\n      userErrors {\n        code\n        field\n        message\n      }\n      cart {\n        ...cartFields\n      }\n    }\n  }\n  \n  fragment cartFields on Cart {\n    id\n    checkoutUrl\n    cost {\n      subtotal: subtotalAmount {\n        amount\n      }\n      total: totalAmount {\n        amount\n      }\n    }\n    discounts: discountAllocations {\n      discountedAmount {\n        amount\n      }\n    }\n    note\n    totalQuantity\n    lines(first: 200) {\n      edges {\n        node {\n          id\n          attributes {\n            key\n            value\n          }\n          cost {\n            price: amountPerQuantity {\n              amount\n            }\n            compareAt: compareAtAmountPerQuantity {\n              amount\n            }\n            subtotal: subtotalAmount {\n              amount\n            }\n            total: totalAmount {\n              amount\n            }\n          }\n          discounts: discountAllocations {\n            discountedAmount {\n              amount\n            }\n            ... on CartAutomaticDiscountAllocation {\n              title\n            }\n            ... on CartCodeDiscountAllocation {\n              code\n            }\n            ... on CartCustomDiscountAllocation {\n              title\n            }\n          }\n          merchandise {\n            ... on ProductVariant {\n              ...variantFields\n            }\n          }\n          quantity\n        }\n      }\n    }\n  }\n  \n  fragment variantFields on ProductVariant {\n    availableForSale\n    id\n    compareAt: compareAtPriceV2 {\n      amount\n    }\n    image {\n      altText\n      originalSrc\n      transformedSrc(maxHeight: 96, maxWidth: 96, crop: CENTER)\n    }\n    product {\n      handle\n      id\n      images(first: 1) {\n        edges {\n          node {\n            originalSrc\n            altText\n          }\n        }\n      }\n      ageRestricted: metafield(key: \"age_verification_required\", namespace: \"global\") {\n        value\n      }\n      productType\n      tags\n      title\n      vendor\n    }\n    price: priceV2 {\n      amount\n    }\n    quantityAvailable\n    selectedOptions {\n      name\n      value\n    }\n    sku\n    title\n  }\n\n\n",
    "variables": {
        "cartId": "gid://shopify/Cart/Z2NwLXVzLWNlbnRyYWwxOjAxSE00WDI1M0JRMUNaNlBIMk03VDBaRDRZ",
        "lineIds": [
            "gid://shopify/CartLine/ddd73847-ee2f-4a6d-a9ab-e8dce2832627?cart=Z2NwLXVzLWNlbnRyYWwxOjAxSE00WDI1M0JRMUNaNlBIMk03VDBaRDRZ"
        ]
    }
}

 

 

Result is both lines being removed that share the same variant ID.

Accepted Solution (1)
SBD_
Shopify Staff
1829 270 412

This is an accepted solution.

This has now been resolved 🙂

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 5 (5)

SBD_
Shopify Staff
1829 270 412

Hey @originmaster 

 

Checking with the Discount folks and will report back.

Scott | Developer Advocate @ Shopify 

SBD_
Shopify Staff
1829 270 412

Redirected to the Checkout team - keep you posted.

Scott | Developer Advocate @ Shopify 

SBD_
Shopify Staff
1829 270 412

Hey @originmaster 

 

Thanks for reporting this. Function's team has confirmed it's a bug related to a new feature rolling out and are working on resolving. In the mean time, your store has been temporarily opted out of the new feature so you shouldn't see this issue any more - please confirm 🙂

Scott | Developer Advocate @ Shopify 

SBD_
Shopify Staff
1829 270 412

This is an accepted solution.

This has now been resolved 🙂

Scott | Developer Advocate @ Shopify 

originmaster
Shopify Partner
42 2 19

@SBD_ Thanks for looking into it for me!