In this episode, we dive into how to calculate the cart subtotals and the grand total (which includes shipping) in your shopping cart. We start by looking at the subtotal, which is pretty straightforward since we've already been outputting it from our cart object.
Next, we focus on how to get the total, accounting for dynamic shipping costs. To make things flexible, we create a computed property that adds together the cart's subtotal and the selected shipping price, so whenever the shipping option changes, the total automatically updates too.
There's also a quick discussion about formatting – we look at the different ways you could display your total as a money value, either formatting it right in the component or just handling it in the template. For now, we keep it simple and leave formatting in the template, so the component can focus on just providing the correct numbers.
By the end of the episode, you'll have a subtotal, dynamic shipping, and a live-updating total, with clear guidance on how to best format and use these amounts in your app.