Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input for cart's TotalAmount does not account for discounts in product discount function #571

Closed
kylebuildsstuff opened this issue Oct 24, 2024 · 1 comment

Comments

@kylebuildsstuff
Copy link

Which template or example

  • Product discount function, Typescript
  • API version 2024/04

Describe the bug

When requesting the cart's total amount in the product function's Input object the value returned does not account for discounts. This creates issues when applying product discounts based on the total amount of the cart.

Steps to reproduce

  1. Create order discount code for 30% off order
  2. Create product discount function requesting cart total amount:
query RunInput {
  cart {
    lines {
      id
      quantity
      cost {
        totalAmount {
          amount
        }
      }
    }

    cost {
      subtotalAmount {
        amount
        currencyCode
      }

      totalAmount {
        amount
        currencyCode
      }
    }
  1. Run product discount and apply discount code
  2. Observe function logs

Expected behavior

The total amount of the cart returned by the product function's Input object should account for changes in amount from discounts and discount codes as well

Environment

  • Mac Sonoma 14.1.1 (23B2082)
  • "@shopify/cli": "^3.68.1",

Additional context

An example of the cart:

Image

Input (STDIN):

{
  "cart": {
    "lines": [
      {
        "id": "gid://shopify/CartLine/0",
        "quantity": 1,
        "attribute": null,
        "userAttribute": null,
        "merchandise": {
          "id": "gid://shopify/ProductVariant/47328231325999",
          "weight": 10,
          "weightUnit": "POUNDS",
          "metafield": {
            "value": "{\"applyProductDiscount\":false}"
          }
        },
        "cost": {
          "totalAmount": {
            "amount": "699.95"
          }
        }
      },
      {
        "id": "gid://shopify/CartLine/1",
        "quantity": 1,
        "attribute": null,
        "userAttribute": null,
        "merchandise": {
          "id": "gid://shopify/ProductVariant/47328231751983",
          "weight": 0,
          "weightUnit": "KILOGRAMS",
          "metafield": {
            "value": "..."
          }
        },
        "cost": {
          "totalAmount": {
            "amount": "10.0"
          }
        }
      }
    ],
    "cost": {
      "subtotalAmount": {
        "amount": "709.95",
        "currencyCode": "CAD"
      },
      "totalAmount": {
        "amount": "709.95",
        "currencyCode": "CAD"
      }
    },

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant