Description
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
- 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
...
- Create draft order with the item in question along with a custom line item
- Adjust the quantity of the custom line item
- Create Add normal product to order/draft order
- 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: