Okay.
Hopefully you gave that a go and you were able to succeed in getting the totals displayed on here.
I'll just go back to the code and I'll just demonstrate how we can set these different values.
And first of all, of course we're going to need the basket from our store.
And the way that we do that using RTK query is we use our use fetch basket query, even though technically
we probably won't go out to our API for this specific request because that's already going to be retrieved
based on our nav bar.
So we'll specify const data and basket inside here.
And we'll make use of the use fetch basket query.
And then we can use that to work out what the subtotal is.
And we can check the baskets items.
And we don't know if we've got a basket.
So that optional chaining is fine there.
And then we can use reduce.
And we've used this before.
And the sum is going to be the total or the subtotal.
And that's going to be a type of number.
So I'll put the type in there.
And then we're going to loop over our item which is going to be of type item.
And then we can use the arrow and we can just work out in the callback function what the subtotal is
based on each item we have in our basket multiplied by the item quantity.
So we'll use the sum the value that we're working with.
The current value of the sum plus the item quantity multiplied by the item price.
And we're going to give it a starting value of zero.
And if we don't have a basket then we're going to set the initial value to zero for the sum.
And that's how we use that function to work out this.
And then for a delivery fee, then it's just a case of checking the subtotal to see if this is over
10,000, because it's coming back as a long.
If it is then it's going to be zero.
Otherwise it's going to be 500 which represents $5.
And if we go and take a look and see how that is looking, then I can see that my current subtotal is
110999.
No delivery fee.
The discount will just ignore for some time, and then we've got our total.
And if I reduce, let's say the hats.
Then we should see this updating in our subtotal as well by the amount is being reduced by.
And if I get this to below $100, which means I'm going to need to be left with a single hat.
And I keep removing the other items inside here.
Then what we should have is we've got the.
Subtotal was 80 here.
And the delivery fee of $5 which makes the total $85.
So that's what we.
Were looking for there.
And if I add something back then the delivery fees goes away.
And our total.
Is correct.
So that's what we were aiming for there.
Hopefully you managed to achieve that.
And what we're going to take a look at next.
If we go back to our product and take a look.
At the product details, then we've also got the ability to add something to our basket in here, slightly
more complex this one because we can specify a quantity and we might even already have this item in
our basket.
Or we're going to add a new item to our basket.
So there's a few things to think about when it comes to our product details page.
And we'll take a look at that next.