So here I'm going to use the other two of the script and then I'm going to say a product was already
added.
Product was already added because at this point the product was already added to CART.
So we cannot add the product again to the car because it is in the cart.
So this is the first thing.
The second thing is that I'm going to take the user to the homepage, so I'm going to say Echo.
And then again, I'm going to use JavaScript.
I'm going to say your script, script.
And then inside that script, what I'm going to do, I'm going to say Here script.
And then inside the script I'm going to say here, window dot location, window, dot location and then
interest window again.
Make sure that the script, the spelling is correct.
Here I have a problem, I should say window.
And then that location is equal to index is equal to double cross and then index that Peachtree because
of the index that HP is the home page and of course, don't forget the semicolon at the end.
So here again, let me explain this one more time.
Here.
If the car if the product is not a record, if this product, a particular product is not a record,
then we add that product in the cart.
Else we tell the user that this product was already added to the cart and we take them to the homepage.
So I'm going to click on file and then save all.
And now we are done with this part which are going to add the product again.
This is going to add the product to the cart.
If it doesn't exist, if it hasn't been added to the cart, it's going to add it here.
If, if, if it's the first product, it's going to initiate the session.
If it's not the first product, then it's going to check first whether the product was already added
or not.
If it was added, then we cannot add that product again.
If it has been already added, if it hasn't been already added, then we add that product to cart.
So that's it.
Very, very simple and straightforward.
The next thing that we need to do is that we need to display the product here in the in here, in the
Roomba, in the cart.
In this card we need to display.
The let me show you that.
So if I go to if I click on buy now and if I click on Add to Cart, this is going to add it to the cart.
But here we need to remove these products products because these products have been added historically.
So we need to remove them from the cart, from this cart.
What we want to do is that we want to to leave.
We want to remove two products and leave, only one to use to be used in order to loop over it and display
all products that are in the cart.
So let me here remove this.
So this.
The R.
This represents the last product I'm going to remove this tr.
And they're going to remove also this r.
This represents the second product and I'm going to leave only one PR so we should have now one D.R.
Let me first save and make sure that I didn't break my good leaving here.
Refresh.
And.
And let me go to the one more time.
I'm going to click on Buy now and if you click on Add to Cart, as you can see, it's going to say your
product was already added to CART.
So.
Let me.
Let me let me first disable this.
I think we shouldn't add this at all.
Let me disable this, because we need to go to record.
So I'm going to I'm going to call this out.
I'm going to call this out.
And let me go to.
Let me click here.
By now.
And then I'm going to click on Add to Cart and here it's going to say product was added to CART, but
it's going to leave me in the cart.
Actually, we don't need this go to remove this because we need to stay in the cart.
So I'm going to I'm not going to take it.
They use it to the homepage.
So now we have only one product in the cards.
Now, this product has been added statically and we don't want that.
Instead, we want to add the product dynamically.
So to do this, I'm going to go again to the card.
Let me let me close this down.
And here we need to use the recession in order to display the products that we have in the garden.
I remember that recession.
Recession contains because recession is a loop position.
Again, the structure is that position is a loop with with the with era.
So we need to loop over it.
So I'm going to say here.
You're above this.
TR We need to create a look.
Beer.
So here what I'm going to do is that I'm going to use speech B and then I'm going to say here for each
and then I'm going to use the session.
Session.
Garth.
Session cards.
And then as he.
Value.
Key value.
So the key the key is the product ID, the value is there.
Right.
And then I'm going to add here, Caleb Bracket, I'm going to open the clearly bracket and then below
that I'm going to close the clearly brackets.
I'm going to say B2B and then I'm going to close the bracket.
And then.
And then I'm going to here I'm going to be using the value.
So the value is there.
Remember the array that we added to the card, which is this array in this case and this array in this
case.
So this array has these keys.
It has the product ID, product name, price, image, quantity.
So we need to display the product ID name, price and quantity.
So what I'm going to do is that you're in this loop.
Instead of saying here, why choose?
I'm going to remove this, why choose?
And I'm going to remove this hardcoded text and I'm going to use speech.
Me So I'm going to say here BHP and then I'm going to say Echo.
And then what we want to echo is that we want equity value and we want to echo what we want equity product,
underscore name and then semicolon because the product, the key for product name is product name.
And then we have the.
We have here the price we need to say here, BHP and then echo and we want to echo the value of the
product price.
And then semicolon and I'm going to copy this code because it's going to be the same.
And then I'm going to sit here instead of saying, here, let me check this.
This is the price.
And here also we need to display the price and this is the total price.
So we need to work on this later.
But what else we want to work on is the quantity.
So the quantity is here.
So the quantity, when you need to say the quantity, your value, I'm going to remove this value and
then I'm going to pay this code.
And then I'm going to say product quantity.
Crime data.
For the image remember the image your assets image images feature that I'm going to remove this featured
one that jpeg and then I'm going to place this good echo value a product image.
Let me save.
Leave me here, then over to the browser and test.
So let me refresh.
And if I refresh, it's going to tell me product was already added to CART.
And guess what?
It's going to display the product.
But this time, this product is not the.
It's not the hardcoded product, it's the dynamic product.
And here I have a problem actually displaying the name of the product.
So here I should say.
Product name.
So I have here an issue.
I have an issue with product name of your name.
So I have a problem here.
The in the single product, let me make sure that they passed here.
Here I have, I think a problem.
Product name, product name, product price, product price.
Here I have a problem.
So as you can see here, name should be product underscore price.
Product price.
So this should be product price.
This is why I'm getting your price instead of any.
So in order to fix this, I'm going to close down my.
I'm going to close down this gap, and then I'm going to open it again.
So as you can see here, it's going to display the product name and we have no problem.
Me test with another product to make sure that this works.
I'm going to go back and then I'm going to go back again and let's add another product.
For example, I'm going to add this product.
I'm going to click on Buy now and then I'm going to click on Add to Cart.
So if I click on Add to Cart, as you can see, it has been added to Cart and now it worked successfully
and we have no problems with this.
So the cart now works perfectly.