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

Cart Transform function calculates line.cost.totalAmount.amount differently for custom line items #560

Open
kylebuildsstuff opened this issue Sep 24, 2024 · 0 comments

Comments

@kylebuildsstuff
Copy link

Packages

"@shopify/app": "^3.58.2",
"@shopify/cli": "3.66.1",
"@shopify/shopify_function": "0.0.3",

Describe the bug

When using the Cart Transform function to update the price of a line item it returns line.cost.totalAmount.amount as the price of the line item multiplied by the quantity for normal products but for custom line items it returns the value as just the price of one line item, disregarding the quantity.

While it may seem simple to just change the calculation to account for quantity too, this would fix one problem and create another, as normal products don't require you to account for quantity when using totalAmount.amount but custom line items do.

Steps to reproduce

  1. Create cart transform function to update line item.

Example code:

// run.ts

// 10%
let priceChangeValue = 10

const cartTotalAmount = cart?.lines?.reduce?.((total, line) => {
          return total + (Number(line?.cost?.totalAmount?.amount) || 0);
        }, 0);
        const newPrice = cartTotalAmount * (Number(priceChangeValue) / 100);

return {
          update: {
            cartLineId: lineId,
            price: {
              adjustment: {
                fixedPricePerUnit: {
                  amount: newPrice,
                },
              },
            },
          },
        };
// run.graphql
query RunInput {
  cart {
    lines {
      id
      quantity
      cost {
        totalAmount {
          amount
          currencyCode
        }
      }

      merchandise {
        ... on ProductVariant {
          id
        }
      }
    }
  }

  presentmentCurrencyRate
...
  1. Create draft order with the item in question along with a custom line item
  2. Adjust the quantity of the custom line item
  3. Create Add normal product to order/draft order
  4. Adjust quantity of normal product

Expected behavior

line.cost.totalAmount.amount should return the total amount of the line with the quantity already accounted for for custom line items, or if it's already working as intended then line.cost.totalAmount.amount should return the total amount of the line without the quantity account for for normal products.

Additional context

Video demo of issue:

https://youtu.be/5ejoPdP_akw

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