Welcome back.
Now, what we need to do is that we need to calculate the total quantity of the cart and also the product
quantity, the subtotal.
So let's start with the subtotal.
So in order to calculate the subtotal, we need to get the here.
We need to get the product quantity and multiply it by the price.
So here in this product price, we can here we have this price here and also it's being displayed here.
So this is the single price and this is the the total subtotal, the total of a single day total of
a one product multiplied by the number up by multiplying by the quantity.
So here service playing 155 we need to say B2B and then we need, we need to multiply the weight to
say echo and then we need to multiply the value product.
Product quantity.
By times the value.
Product price.
Product underscore price and then semicolon.
No, forget the semicolon.
Now, let me see and let me refresh and show you that.
Now, this is going to be nine times 155 because a single a single product would cost to 155.
A single pair of shoes would cost 155.
But if you want to buy nine of these shoes, we need to I need to pay 155 multiplied by nine.
So let me refresh let me go to the cart one more time.
So if I go to the cart, I should say I should here to get 1395.
So if you make the calculation, you will find that this is correct.
Let me prove it to you so many years say to let me say here to if I say to and edit here the cost to
the total cost out of a two shoes is 310.
And that's correct because 155 plus 155 is equal to 310.
So this is correct.
Now let's work on the total product.
So if I have many products, for example, if I have, let me go back and let me add let me go back
to the homepage.
Allow me add this product so this product would cost also, let me let me see look at that product because
I want another price.
So this one this one would cost 250.
So if I click on buy now and add this product to cart, we have here 310 and here 250.
But the total is static.
So we need to work on that total.
To work on the total we need to say we need to create a code a year.
That's going to calculate the total.
So I'm going to create here a function I'm going to here.
Here.
I'm going to give you the function.
I'm going to say function and then I'm going to say calculate total.
Can't.
And then I'm going out in order to get the total, we need to say we need to look over to the station.
So I'm going to say for each session.
Session cart and then we to get each single product.
So we need to say what we need to say for each thing.
Session, cart.
As key.
Value.
Key.
Value and then we need to get each single product.
So each single product in order to get each single product, we need to say session and then.
And then.
And then key.
Key.
This is going to return the array of each single product so we can say here product.
So for each single product, what we want to get is that we want to get we need to say we need to get
the the price as well as the quantity.
So this is going to return an array and each time it's going to return a different product.
So for each different product, for each different for each different product, we need to get the product.
Price and quantity.
So I'm going to get the price.
I'm going to get here.
Price.
And quantity.
Quantity.
So the quantity is going to be equal to your product, product, product, quantity, quantity.
And then we need to multiply the price by the quantity.
So we need to say total is equal to price, price multiplied by the quantity.
However, this is going to return only one total of one product.
Therefore, we need to create a variable called total and it's going to be initially zero.
And then we need to say total is equal to total, total plus price multiplied by the quantity.
So what this what this is going to do is that each time it is going to increase the each time it's going
to increase the it's going to add the old total to the new total.
So it's going to give the all total.
And each time we have a product, we are going to get the price multiplied by the quantity and adding
to the total.
And here, by the way, I should say total and finally we can here say return.
Finally return.
Return what?
To return the total.
Or better.
Instead of returning, we need to store this in indecision.
So I'm going to get here in decision.
I'm going to create a new key called Doctor.
Doctor.
I'm going to say Doctor Total now is going to be equal to doctor.
That's it.
Now we need to call this function so we.
When should we call this function?
We should call this function each time we add a product to the cart.
So we need to call the address inside.
Inside, add to cart.
So inside this add to cart.
Inside this add to cart here.
Hearing to say update or calculate total.
So here I'm going to say calculate total.
Calculate total carte.
Finally, we need to display the total here in the bottom.
In the bottom, we need to say.
We need to say here.
You remember this first part?
This table in this table.
So in this table, we don't need actually this subtotal because we don't have I didn't add any other
costs.
So I am going to remove this subtotal.
Subtotal, we just need the total.
So the total, instead of saying, I want 55, I'm going to remove it and then I'm going to say BHP
and then I'm going to use this session.
I'm going to say Session.
Total.
And of course, we need to say echo.
Echo.
Total session.
Total.
Let me now save and let me refresh.
So here, as you can see, what I'm going to get is that I'm going to get 560.
So let's make it a calculation together.
Is 310 plus 200, 250 is equal to 560.
Well, that's correct.
Let me prove it to you.
Link will prove that this is correct, that the total DOT three total has been calculated correctly
leaving here the number of products and limit click on edit.
And if you click on edit now the total is still here.
The reason why it's still 560 is because actually I need to call.
I need to call the calculate.
Also here.
I need to call it here.
In the in case we update, in case we update or in case we remove.
So here in case we remove something foreign because we need to calculate return to calculate total.
And also in case in case we update in case we update the quantity we need here to calculate total calculated.
Let me try one more time.
So now if I refresh.
Now the total as you can see, the total is 810 linear decrease.
This one more time I'm going to say one and edit.
And now they total again back to a 560 limit increase this to two and then update.
And as you can see, the total now is 810.
If I increase this to three and update, as you can see now, the total is four 965.
So now the total worked successfully and now we have the total total amount.
So this is the single price of this is the subtotal and this is the total.