Welcome back.
Now, what we need to do is that we need to work on the statement where if you there has already added
something to the card.
So if you use our has ADD, it has already added something to the cart.
We need to to check whether the new product is one of the products that the user has already added to
the cart or not.
To do this, we need to create a new variable called product.
Products are products under score array.
Ideas which is going to return and an array with all products that are with or with all product ideas
that have been added to the to the cart.
And that can be done using the array column function.
If I see a recall and if I pass the session to it session cart.
Efficient car.
And then if I pass the column that I'm interested in to the column is the product A-D.
I'm going to say product maybe.
This is going to return an array with all products, with all products, products, products, ads.
So for example, if I added product, product that has an idea of two and three and four and ten and
15.
Then this array is going to return is going to return these items.
And then we need to use this statement to check whether the product has already been added or not.
So I'm going to say if if that product is not in the array, if in array.
If an array.
And then if in a array.
If.
If it's not in the array.
The product.
It.
Right.
If.
Comma and then.
Product, products and rides.
Let me explain this.
I'm going to have your Kelly brackets.
So this is going to check this statement is going to check if a product has already been added or not
added to cart or not.
How by by comparing this function in array is going to compare is going to try to find if this product
it is is one of the product array it is one of the elements of the product's array IDs.
So if that ID exists within exists in this are in this products array IDs, then we need to tell the
user here to say here in this case product has already been at it's been at l a here.
If not, then we need to add it to a card.
So here, here in this, if we need to add it to the card and to add that to the card, we need to create
another.
We need to get an array like this.
We need to we need to create a code like this and add that to the to the to the session to the session
card.
So I'm going to copy this card.
And mean.
I've got a business card here.
I'm going to paste this code here, but I'm going to fix a few things.
Let me push this and then I'm going to fix a few things.
First, we need to say product ID is equal to the ID.
That's fine.
And then we need to pass these here in this array, this also fine.
And finally, we need to have this array.
So there isn't nothing.
Nothing is going to be different.
But instead of creating this long code, we can, for the sake of making everything simple, we can
push.
We can insert the past, the past parameters immediately.
So we can say your product, product, underscore ID immediately without creating these parameters.
So without using these parameters, because it's just going to take more code.
If you don't want to do this, you can use the POS request immediately like this.
This is just going to reduce the number of number of lines we have in our.
So as you can see here, I removed these lines and now our code is much smaller.
Much shorter now for for in case the user has already added this product to cart, we need to tell them.
We need to say, for example, echo.
Echo.
Script.