Shopify / js-buy-sdk

The JS Buy SDK is a lightweight library that allows you to build ecommerce into any website. It is based on Shopify's API and provides the ability to retrieve products and collections from your shop, add products to a cart, and checkout.
https://shopify.github.io/js-buy-sdk
MIT License
991 stars 262 forks source link

Cannot update line items created by bogo discount #780

Open Greg-Archer-at-Funko opened 4 years ago

Greg-Archer-at-Funko commented 4 years ago

Line items which are created by Automatic bogo discounts cannot be removed / updated.

Note: I am only describing my specific case, but the bug may apply to wider scenarios.

To Reproduce

Create an automatic discount.
Type: 'Buy X get Y' Customer buys: Minimum qty of items: 1 Customer gets: 1 Free

Add qty two of one item which is eligible to trigger discount, and eligible for discount offer.

Inspect checkout and note that the item is divided into two line items.

Attempt to remove / update second line item with JS Buy checkout methods.

ex:

 client.checkout.removeLineItems( ... )
 client.checkout.updateLineItems( ... )  // ex: update qty

example response:

{
  "checkoutLineItemsRemove": {
    "userErrors": [
      {
        "field": null,
        "message": "Line item with id 336128088147311 not found"
      }
    ],
    "checkoutUserErrors": [
      {
        "field": null,
        "message": "Line item with id 336128088147311 not found",
        "code": "LINE_ITEM_NOT_FOUND"
      }
    ],
    "checkout": null
  }
}

Expected behavior The line item should be removed / updated

Environment (please complete the following information):

vixdug commented 4 years ago

Hi @Greg-Archer-at-Funko

Can you confirm when you are doing the checkout.removeLineItems you are utilizing the Storefront API ID vs. a numerical ID? When I test this I'm getting a different result. The item is split as you have explained but removing one of the Line Items seems to be removing both when the BOGO is active.

nboliver commented 3 years ago

@Greg-Archer-at-Funko I get the same result as @vixdug. I found this thread looking for a way to tell if the second line item is the bogo item. If anyone has ideas about that, please share!