Custom shipping calculations

shipping
custom-cart-items
javascript

#1

I’m currently trying to implement custom shipping based on the total amount in the cart as well as the input country.

As far as I understand this is possible by adding a custom item to the cart.

Since I need to calculate and/or update the costs, I am wondering if there is an easy way to update the custom item’s unit price and description via the Javascript SDK? So far I’m only able to update the quantity of the custom item (which I don’t really need to do).


#2

Hi @studioscholz

I’ve just been doing a very similar thing! At the moment however it’s only possible to update a cart items quantity through the SDK + the API.

To work around this whenever you want to update the price of a custom cart item, you should remove the previous cart item, and add a new one. The JS SDK uses promises, so chaining these together should be pretty straightforward:

moltin.Cart().RemoveItem(cartItemID).then(data => 
    moltin.Cart().AddCustomItem(cartItemData)
)

Hope this helps.


#3

Yep, that works. Thanks!


#4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.