Shopify / function-examples

MIT License
188 stars 54 forks source link

Multiple Merge Operations Result in Cart Instability #489

Closed nelson-maze closed 6 months ago

nelson-maze commented 6 months ago

Which template or example

CartTransform - Merge Operation

Describe the bug

Line Item issues begin to occur with any multiple of a CartTransform Merge "bundle" being added to the cart (either by incrementing via form submission on the cart page or via cart AJAX API). Adding any other line items and bundles only exacerbates the issue.

Partner app dashboard logs indicate that function invocations are occurring where the cart line item inputs are being modified outside of the function's execution, along with potentially extra function invocations being made along the way (accelerating the duplication issues).

Steps to reproduce

Assumptions

Steps

  1. Add 1 of each of the component products to the cart to manually create the bundle in-cart.

    • (2/3 bundle products added to cart) image

    • (3/3 bundle products added to cart) image

    • Note that this first invocation/interaction properly results in a single bundle being rendered in cart. This is also evident in the partner logs. (3 products input results in 1 Merge Operation with the 3 required component line items in the correct quantities). FirstBundleInput.json: FirstBundleInput.json FirstBundleOutput.json: FirstBundleOutput.json

  2. From the cart page, increment the bundle to 2 via the "+" button.

    • The page will update and result in:
      • Another line item being added with a price of $0.00 and quantity of 2
      • The first bundle's line item being updated to a quantity of 2 image
      • Note that this is not the theme rendering things incorrectly - the returned response from the Cart AJAX API clearly returns an "empty" bundle line item at $0.00: CartResponse_2_Bundles.json
      • This is also not the result of incorrect Function output, as the logs correctly display 2 merge operations, each for a group of 3 line items: SecondBundleInput.json: SecondBundleInput.json SecondBundleOutput.json: SecondBundleOutput.json
      • Note that the "empty" line item is not found anywhere in the Function input/output logs.
  3. Proceed to checkout via the checkout button on the cart page with the current cart of 2 bundles and 2 "empty" bundles.

    • These function invocations with modified inputs result in the cart now being completely different from even the original "2" line items (Cart AJAX API line items JSON found here CartResponse_FirstDuplicationResponse.json): image

      • The expected outputs of the function are still technically correct - but the input varying is what is resulting in this behavior between invocations, not the function execution itself.
      • The only user interaction here between function invocations was the visit to checkout.
  4. Navigate back to the cart page, and attempt to "correct" the cart by deleting a line item (any of them)

    • This only results in a continuation of the duplication issues, which after 2 attempts finally results in such a large quantity of line items that the runtime instruction count limit is exceeded, finally resulting in all bundles being broken up, as shown in the cart. image

    • The Function input/output logs of this are below: DeleteAttemptInput: DeleteAttemptInput.json DeleteAttemptOutput: DeleteAttemptOutput.json

Expected behavior

Environment

Additional context

This is occurring in multiple Shopify Plus environments.

nickwesselman commented 6 months ago

Hi @nelson-maze! Please report bugs with Function APIs on Community. Issues on these OSS repos should be directly related to the code within.

nelson-maze commented 6 months ago

Hi Nick - thanks, appreciate the corrected location for this. Issue is opened there, linking here for posterity: https://community.shopify.com/c/shopify-functions/carttransform-merge-operations-seem-unstable-with-quantities/td-p/2544569

On Tue, Apr 23, 2024 at 11:55 AM Nick Wesselman @.***> wrote:

Hi @nelson-maze https://github.com/nelson-maze! Please report bugs with Function APIs on Community https://community.shopify.com/c/shopify-functions/bd-p/functions. Issues on these OSS repos should be directly related to the code within.

— Reply to this email directly, view it on GitHub https://github.com/Shopify/function-examples/issues/489#issuecomment-2073199343, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY6ANPJT7KC2QG5ES5RJ5CLY62VDNAVCNFSM6AAAAABGVPGPACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZTGE4TSMZUGM . You are receiving this because you were mentioned.Message ID: @.***>