Welcome back.
Now, what we need to do is that we need to work on this edit button.
So if a user decides to increase the quantity of a product, we need to edit the quantity and the subtotal.
So if the user clicks here on edit and chooses, for example, for quantity, for items of the same
product, we need to increase the quantity as well as the subtotal.
How can we do this?
To do this, we need to activate this button.
So remember here in the cart, we have this edit button.
We need to create a form here where you could say form and then this form we're going to give it method
and action.
So the method is going to be fast and the action is going to be cart, dot, HP.
And then I'm going to move I'm going to remove this attack.
And then I'm going to create here two inputs, one input, and I'm going to give it a class called edit
button, edit button and values.
So the value.
Value is at it.
And also we need name.
So the name is added quantity.
Added underscore quantity.
And we need another input, which is the product, the input.
And then name first type.
The type is hidden and the name is product I.D..
And the value is between.
Echo.
Product value.
Product.
Product I.D. semicolon.
And don't forget to close this angular bracket.
And here the second input must have a type, and the type is submit.
Let me push these to.
And again, let me explain this one more time.
This form is inside this loop so we can use the value, the product ID value, and the second input
and the first input is hidden, but it's going to hold the product ID, the second input is going to
submit the form and it will allow us to get the product ID and edit the quantity.
So we also need the right quantity itself.
So we need to create another.
We need to create another input for the quantity itself.
Remember, the quantity is is this.
So we need you to yet another input.
I'm going to say your book or actually we have the way the input we need to copy it and then we need
to move it over to the form so it's going to be here.
So this is the quantity Laney save and.
Let's this let's make sure that the female code is not broken.
So as you can see, it's fine, but we need to do fix the edit.
So we need to remove the again.
We need to return over to CSIS.
And we need to edit the.
We need to open the style.
Let's use this.
And then for the edit button, we need to hear, say, background color white.
And we need to remove the borders or none.
And the width is 100%.
Lady save on.
Let me make sure that they resign is fine.
So let me go back to the page.
So in the garbage we have, we now we have actually a problem.
So let me remove this weight.
I don't think that the with is needed here.
So again, I need to go to the cart one more time.
They should fix it.
So it has been fixed.
Now we need to work on the logic.
So here we need to create in every car that BHP.
What we want to do is that we need to use the these inputs and use the past
value of BHP.
So at the top we need to add else.
If with this else, if we need to push this good, then we need to create another elseif.
ElseIf.
And then don't forget to close the curly bracket and open it here and here.
I'm going to say elseif if it's set.
Lost.
Lost and then a great quantity.
It it quantity.
Why?
Why it quantity?
Why do they say it is quantity?
Because.
Here.
The forum has it.
It wanted to submit the button.
So the submit button has any called it is quantity.
So we need to use this to submit the form.
And here we need to work on their logic.
So here's what we need to do, is that we need to get the current quantity and it is that quantity.
So how can we get the current quantity?
To get the current quantity we need to say here we need first to get the quantity from before.
So I'm going to say.
Your product.
Product.
Product underscore quantity is equal to cost.
Boss.
And then product quantity.
Remember the form has product this for the product quantity it doesn't have a name.
So we need to give it a name and the name is going to be equal to product quantity.
So we need the product quantity and the product me from this form.
So I'm going to say your product quantity is equal to past product underscore quantity.
And then we need the product ID.
So I'm going to get another variable called product ID and it's going to be equal to boss.
Right.
Okay.
First and then.
Product.
I'd.
Now we need to access the decision and update the product quantity.
So to access the session, we can say session, event card and then we need to get the the product that
the array of that specific product.
So we need to say product.
So this is going to return an array here.
I'm going to say product.
Product underscore at right.
So the product array is equal to is equal to the session card product.
Now from this product array, we can access the quantity, the current quantity, the old quantity.
So can I say product underscore quantity.
Quantity.
This now is the old quantity.
This is the old underscore quantity.
And the new quantity is this.
This is the new quantity.
So instead, we need to replace we need to remove this old quantity and add the new quantity.
How can we do this?
To do this, we need to say we need 3 to 3.
We need the we don't need this, this, this valuable like it is valuable just to explain how it works.
All we need to do now is to say, right, the quantity is equal to the new product quantity, which
is this product quantity.
So this is the old the old quantity.
I'm going to override the value with a new quantity.
Finally, we need to push or add this array again to the to the session.
So we need to say session.
And then Garth.
And then.
Product ID.
Is equal to the rate.
So we need.
We need we need to.
To return the product array back to the to the to the decision.
So let me explain this code one more time here.
I'm going to add comments here.
First get we get ID and quantity from before.
And then the second step is to get the product array from the station.
We extract that array, we extract out the array from the session because there might be many products.
The third step is to update, update product quantity.
The last step is to put back to a return or or return.
That's a return array back to its place.
To its place inside the session place.
Let me save and let's test this.
Good.
So we're going to here refresh and then I'm going to try to increase it.
I'm going to try to increase this value to, let's say three and then I'm going to click on edit.
So as you can see, if I click on edit, now we have three.
If I increase this to seven and if you click on edit, if we're going to say edit, it's going to say
seven here.
So it worked successfully, and now this product will be usable by seven items.
If you want to make sure that it works, you can go back to the homepage.
For example, you can go to the homepage.
And then you can try to go back to let me go back to the cartridge.
So if they try to go to the page one more time, it's going to it's going to remain here seven because
now the user has set the number to save it.
The next thing that we need to work on is the subtotal.
So we need to work on this later.