My client has a subset of webstore items which hav...
# suitecommerce
a
My client has a subset of webstore items which have specific shipping costs associated with them. My current approach was to add a new line item via code when any of these items are selected and add the shipping as a service item line. This worked up to the point where I've added my service line to the cart using cart.addLine - but it won't let me set the amount - its defaulting to the $0 amount on the item record. (I am setting amount in my
cart.addLine
but it seems to be just ignoring that.) so 2 questions - 1. is there just a simpler way to do this and I shouldn't be doing this via SC extension code at all? šŸ™‚ 2. how can fix my existing code to set the price on the newly added line?
Copy code
if(amount){
    cart.addLine({
        line: {
            quantity: 1,
            amount: amount,
            item: {
                internalid: 3420
            }
        }
    });
}
p
you'll either have to use Scriptable cart or have different items per rate
a
thanks, isn't Scriptable Cart generally a bad idea? or is that out dated thinking these days? šŸ™‚
p
there is no other way to add variable amount items unfortunately.
out of curiosity, was that api call you are doing in frontend or backend?
a
frontend
p
So you are trusting the frontend to set the amount to be paid for shipping. That wouldn't be secure.
a
Fair point, I still need it to display to the customer before they confirm the order so they know what they're buying...
if i do this using scriptable cart will it do both?
p
What i normally do is: • Orchestate the addition/substraction of complementary / add on items from server side • Send the amount as a transaction column field (that is set via server side, not via frontend) - this transaction column field is read by scriptable cart and set as rate. • Add additional integrity checks on the order to ensure addons are also added and removed together as a pair and amounts are correct.
a
yeah that makes total sense, thank you.