Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Modifying Total Cart Cost

Modifying Total Cart Cost

cherriecoder
Shopify Partner
14 0 0

I am using the checkout extensibility function and am trying to update the total tax amount based on the customer name and shipping address (this is for tax exempt purposes) but I am running into some trouble and am not sure what's wrong. I am getting an error message 

[ { "path": [ "errors" ], "explanation": "Expected value to not be null" }, { "path": [ "updatedTaxAmount" ], "explanation": "Field is not defined on FunctionRunResult" } ]

 

 

Here is how I set up my file (I am trying to modify the cart cost price no matter the condition for now just to see if it will work)

import type {CartCost, FunctionError, FunctionRunResult, RunInput,} from "../generated/api";
import {CurrencyCode} from "../generated/api";

export function run(input: RunInput): FunctionRunResult {
const currentBuyerAddress:string = input.cart.deliveryGroups[0]?.deliveryAddress?.address1 ?? '';
let errors: FunctionError[] = input.cart.lines
.filter(({ quantity }) => quantity > 1)
.map(() => ({
localizedMessage: "Not possible to order more than one of each",
target: "cart",
}));

const updatedTaxAmount: CartCost = {
subtotalAmount: {
amount: "749.00",
currencyCode: CurrencyCode.Usd
},
totalAmount:{
amount: "749.00",
currencyCode: CurrencyCode.Usd
},
totalTaxAmount: {
amount: "0.00",
currencyCode: CurrencyCode.Usd
}
};

return {
errors,
updatedTaxAmount
}
};

and here is what i added in my schema 

type FunctionRunResult {
errors: [FunctionError!]!
updatedTaxAmount: CartCostInput!
}


"""
The result of a cart validation function.
"""
input FunctionRunResult {
"""
Errors.
"""
errors: [FunctionError!]!

"""
Updated Tax Amount.
"""
updatedTaxAmount: CartCostInput!
}

input CartCostInput {
subtotalAmount: MoneyV2Input!
totalAmount: MoneyV2Input!
totalTaxAmount: MoneyV2Input
}

input MoneyV2Input {
amount: String!
currencyCode: String!
}

 

Replies 0 (0)