WEBVTT

00:00.020 --> 00:00.290
Okay.

00:00.320 --> 00:06.080
Hopefully you gave that a go and you were able to succeed in getting the totals displayed on here.

00:06.080 --> 00:12.470
I'll just go back to the code and I'll just demonstrate how we can set these different values.

00:12.470 --> 00:16.010
And first of all, of course we're going to need the basket from our store.

00:16.010 --> 00:24.680
And the way that we do that using RTK query is we use our use fetch basket query, even though technically

00:24.680 --> 00:30.800
we probably won't go out to our API for this specific request because that's already going to be retrieved

00:30.800 --> 00:32.510
based on our nav bar.

00:32.570 --> 00:37.400
So we'll specify const data and basket inside here.

00:37.400 --> 00:41.150
And we'll make use of the use fetch basket query.

00:41.150 --> 00:45.410
And then we can use that to work out what the subtotal is.

00:45.410 --> 00:49.250
And we can check the baskets items.

00:49.250 --> 00:50.990
And we don't know if we've got a basket.

00:50.990 --> 00:53.150
So that optional chaining is fine there.

00:53.150 --> 00:55.190
And then we can use reduce.

00:55.190 --> 00:56.810
And we've used this before.

00:56.810 --> 01:00.740
And the sum is going to be the total or the subtotal.

01:00.740 --> 01:02.180
And that's going to be a type of number.

01:02.180 --> 01:03.470
So I'll put the type in there.

01:03.470 --> 01:08.810
And then we're going to loop over our item which is going to be of type item.

01:10.260 --> 01:17.700
And then we can use the arrow and we can just work out in the callback function what the subtotal is

01:17.700 --> 01:24.150
based on each item we have in our basket multiplied by the item quantity.

01:24.180 --> 01:27.090
So we'll use the sum the value that we're working with.

01:27.120 --> 01:38.070
The current value of the sum plus the item quantity multiplied by the item price.

01:38.070 --> 01:40.800
And we're going to give it a starting value of zero.

01:40.800 --> 01:47.010
And if we don't have a basket then we're going to set the initial value to zero for the sum.

01:47.010 --> 01:50.400
And that's how we use that function to work out this.

01:50.400 --> 01:57.000
And then for a delivery fee, then it's just a case of checking the subtotal to see if this is over

01:57.000 --> 01:59.790
10,000, because it's coming back as a long.

01:59.790 --> 02:01.800
If it is then it's going to be zero.

02:01.830 --> 02:06.240
Otherwise it's going to be 500 which represents $5.

02:06.240 --> 02:12.270
And if we go and take a look and see how that is looking, then I can see that my current subtotal is

02:12.270 --> 02:14.640
110999.

02:14.730 --> 02:15.930
No delivery fee.

02:15.960 --> 02:20.600
The discount will just ignore for some time, and then we've got our total.

02:20.600 --> 02:24.680
And if I reduce, let's say the hats.

02:24.830 --> 02:30.860
Then we should see this updating in our subtotal as well by the amount is being reduced by.

02:30.890 --> 02:36.710
And if I get this to below $100, which means I'm going to need to be left with a single hat.

02:36.920 --> 02:40.550
And I keep removing the other items inside here.

02:40.670 --> 02:42.920
Then what we should have is we've got the.

02:42.950 --> 02:44.600
Subtotal was 80 here.

02:44.600 --> 02:49.490
And the delivery fee of $5 which makes the total $85.

02:49.490 --> 02:50.030
So that's what we.

02:50.060 --> 02:50.960
Were looking for there.

02:50.960 --> 02:54.050
And if I add something back then the delivery fees goes away.

02:54.050 --> 02:55.550
And our total.

02:55.580 --> 02:56.840
Is correct.

02:56.840 --> 02:58.430
So that's what we were aiming for there.

02:58.430 --> 03:00.110
Hopefully you managed to achieve that.

03:00.110 --> 03:01.760
And what we're going to take a look at next.

03:01.760 --> 03:03.620
If we go back to our product and take a look.

03:03.650 --> 03:11.360
At the product details, then we've also got the ability to add something to our basket in here, slightly

03:11.360 --> 03:17.570
more complex this one because we can specify a quantity and we might even already have this item in

03:17.570 --> 03:18.170
our basket.

03:18.170 --> 03:20.600
Or we're going to add a new item to our basket.

03:20.600 --> 03:24.560
So there's a few things to think about when it comes to our product details page.

03:24.560 --> 03:27.140
And we'll take a look at that next.
