1 00:00:00,990 --> 00:00:01,590 Welcome back. 2 00:00:01,980 --> 00:00:06,330 Now, what we need to do is that we need to get the data from the form and use it in records. 3 00:00:06,690 --> 00:00:10,380 But before I do so, I need also to pass another input. 4 00:00:10,380 --> 00:00:12,480 I need to pass the ID, the product ID. 5 00:00:12,960 --> 00:00:16,320 So I'm going to get another input here and I'm going to say type hidden. 6 00:00:16,980 --> 00:00:19,800 And the name and the name is product ID. 7 00:00:21,210 --> 00:00:23,040 Product ID. 8 00:00:25,130 --> 00:00:32,420 And I'm going to need value and the value is as usual, BHP and then echo and then. 9 00:00:33,700 --> 00:00:34,150 Raw. 10 00:00:37,390 --> 00:00:37,990 And then. 11 00:00:41,400 --> 00:00:42,810 Semicolon and the product. 12 00:00:43,110 --> 00:00:43,850 Product item. 13 00:00:44,550 --> 00:00:45,420 Product I. 14 00:00:47,470 --> 00:00:47,950 That's it. 15 00:00:49,030 --> 00:00:52,390 And you forget to close this stack, and we are good to go. 16 00:00:52,720 --> 00:00:56,860 Now, in the car, the most important part is here. 17 00:00:57,190 --> 00:00:57,580 Here. 18 00:00:57,580 --> 00:00:59,200 Before we display the cart. 19 00:00:59,650 --> 00:01:04,420 Before we display the cart, the first thing that we need to do is that we need to get the data from 20 00:01:04,420 --> 00:01:05,140 this single page. 21 00:01:05,140 --> 00:01:09,340 Because when you click when you click on Add to Cart. 22 00:01:10,870 --> 00:01:18,190 We will take the user to the car, but we need first to display the data here, to display the products 23 00:01:18,190 --> 00:01:22,320 that the user or the product that the user added to the card. 24 00:01:22,750 --> 00:01:26,940 We need to get to get it from the from the single product that B2B. 25 00:01:27,490 --> 00:01:30,850 So here, before we do anything, we need to use the session to do this. 26 00:01:31,480 --> 00:01:33,790 So I'm going to start by saying here. 27 00:01:34,150 --> 00:01:36,970 Session, session, start. 28 00:01:38,570 --> 00:01:44,450 Session start and then we need to check whether the the boss parameter is empty or not. 29 00:01:45,080 --> 00:01:52,220 So we do use the set function and this is set function is going to check whether the whether the user 30 00:01:52,220 --> 00:01:54,560 came to this page using the form or not. 31 00:01:55,700 --> 00:01:58,070 So I'm going to say add underscore to cart. 32 00:02:02,060 --> 00:02:03,080 And then else. 33 00:02:03,650 --> 00:02:11,540 So this basically this is said post after card is going to check whether the user clicked on add to 34 00:02:11,540 --> 00:02:13,060 cart button or not. 35 00:02:13,080 --> 00:02:19,400 If if user clicked on add to cart, then we need to move on and continue with the cart. 36 00:02:19,410 --> 00:02:26,180 Else it means that the user tried to get to the cart page from some somewhere else. 37 00:02:26,180 --> 00:02:32,540 And we don't at this point we need to probably take the user to the do the previous page or do something 38 00:02:32,540 --> 00:02:32,780 else. 39 00:02:33,380 --> 00:02:42,350 So in this case, we need to do something else, maybe take the user to another page or or maybe we 40 00:02:42,350 --> 00:02:46,610 can take the user to the to the all page or the index. 41 00:02:46,610 --> 00:02:47,720 We can see a location. 42 00:02:51,040 --> 00:02:52,270 Index, not BHP. 43 00:02:53,430 --> 00:02:53,650 Okay. 44 00:02:54,010 --> 00:03:01,060 So here after we made sure that the user came to the Spanish by clicking on this button, by clicking 45 00:03:01,060 --> 00:03:05,440 on the on this button, we need now to check the session. 46 00:03:05,830 --> 00:03:11,650 So I'm going to say if, if session if, if is set. 47 00:03:12,490 --> 00:03:13,300 If a set. 48 00:03:14,310 --> 00:03:14,910 Session. 49 00:03:16,750 --> 00:03:17,380 Session. 50 00:03:17,750 --> 00:03:18,040 Mm hmm. 51 00:03:18,700 --> 00:03:21,550 And then I'm going to give you a session called Shopping. 52 00:03:22,600 --> 00:03:23,050 Can't. 53 00:03:24,760 --> 00:03:28,150 Or let's say, just for the sake of simplicity, I'm going to say cars. 54 00:03:29,230 --> 00:03:37,930 Efficient cars is if we have a card, if if the user has already added something to the card before, 55 00:03:38,590 --> 00:03:41,290 then we need just to add more to this card. 56 00:03:41,290 --> 00:03:41,800 Else. 57 00:03:42,730 --> 00:03:49,330 Else it means that the user it means that this is the first product that the user is attempting to add 58 00:03:49,330 --> 00:03:49,720 to the card. 59 00:03:49,730 --> 00:03:54,400 So here I'm going to say if this is the first product. 60 00:03:58,070 --> 00:03:59,900 And here if. 61 00:04:01,920 --> 00:04:05,850 If this if user has already. 62 00:04:07,480 --> 00:04:07,980 Added. 63 00:04:09,880 --> 00:04:12,280 A product to cart. 64 00:04:13,600 --> 00:04:15,280 So if if user has already. 65 00:04:16,360 --> 00:04:19,990 If user has already added something to cart, it means that the cart is not empty. 66 00:04:20,620 --> 00:04:25,060 If this is the first product, then we need to add it to CART as the first product. 67 00:04:25,570 --> 00:04:29,530 So here the first product record is going to be like this first. 68 00:04:30,490 --> 00:04:36,580 We need to create the session from from scratch because this is the this is the first product. 69 00:04:38,980 --> 00:04:46,900 So we need to say we need to get the the data from the from the POS request. 70 00:04:47,380 --> 00:04:55,570 So to get the data from the past request, we can say based then remember the parameters that we passed 71 00:04:55,570 --> 00:04:58,200 are for the image, name and price. 72 00:04:58,210 --> 00:05:02,350 So we need to say here project. 73 00:05:05,000 --> 00:05:05,840 Underscore it. 74 00:05:07,610 --> 00:05:15,110 And it's going to be equal to your product I.D. So product I.D. is going to be equal to this. 75 00:05:15,680 --> 00:05:19,130 And then we need to repeat the same thing for other parameters. 76 00:05:19,610 --> 00:05:21,830 So I'm going to copy this and paste it three times. 77 00:05:23,850 --> 00:05:26,450 Here and here and here. 78 00:05:26,460 --> 00:05:27,530 So we need it. 79 00:05:28,230 --> 00:05:29,130 We need product. 80 00:05:29,250 --> 00:05:29,760 I need. 81 00:05:30,510 --> 00:05:31,440 We need product. 82 00:05:32,760 --> 00:05:33,300 Price. 83 00:05:33,840 --> 00:05:34,920 We need product. 84 00:05:35,490 --> 00:05:37,910 Image and we need product. 85 00:05:37,920 --> 00:05:38,850 I think quantity. 86 00:05:39,870 --> 00:05:40,410 Product. 87 00:05:41,040 --> 00:05:41,640 Name. 88 00:05:41,670 --> 00:05:42,300 Quantity. 89 00:05:49,250 --> 00:05:49,800 One. 90 00:05:50,710 --> 00:05:52,270 And then I'm going to store these in variable. 91 00:05:52,270 --> 00:05:55,120 So I'm going to use the variable called product. 92 00:05:56,390 --> 00:06:00,590 The name is equal to this and then product. 93 00:06:03,860 --> 00:06:06,410 Price is equal to this. 94 00:06:07,070 --> 00:06:07,640 And then. 95 00:06:08,790 --> 00:06:09,480 Right act. 96 00:06:11,090 --> 00:06:12,770 Image is equal to this. 97 00:06:13,430 --> 00:06:14,180 And lastly. 98 00:06:15,620 --> 00:06:16,160 Project. 99 00:06:17,480 --> 00:06:18,110 Quantity. 100 00:06:19,850 --> 00:06:20,660 Is equal to this. 101 00:06:21,710 --> 00:06:25,420 Now we need to add these parameters in in a single area. 102 00:06:25,430 --> 00:06:29,540 So I'm going to do it here and a equal product array. 103 00:06:30,520 --> 00:06:35,320 And then I'm going to say it's going to be equal to Iran with these guys. 104 00:06:36,340 --> 00:06:37,930 So we need to say product. 105 00:06:40,250 --> 00:06:46,610 Let me add this in a new line first semicolon and then in a new line so that you see the structure. 106 00:06:46,620 --> 00:06:48,890 I want you to recognize the structure. 107 00:06:48,890 --> 00:06:54,800 I'm going to say product I.D. is going to be equal to the product. 108 00:06:56,090 --> 00:06:56,630 And then. 109 00:06:58,050 --> 00:07:01,650 Comma and then the product's name. 110 00:07:03,150 --> 00:07:05,220 Product name. 111 00:07:07,130 --> 00:07:09,830 Is equal to or nickname. 112 00:07:11,360 --> 00:07:14,960 I think comma and then product. 113 00:07:16,600 --> 00:07:20,020 Price is equal to the price. 114 00:07:23,100 --> 00:07:24,150 And then project. 115 00:07:25,860 --> 00:07:26,550 Image. 116 00:07:29,370 --> 00:07:30,540 Is equal to the image. 117 00:07:36,050 --> 00:07:43,500 And then product quantity right at 180 118 00:07:45,450 --> 00:07:47,340 is equal to the product quantity. 119 00:07:49,440 --> 00:07:53,760 So we have all all of these finally, we need to add this area to this issue. 120 00:07:54,060 --> 00:08:01,470 So what I did is that is that I took the data from the single page, which then here from the past request, 121 00:08:01,800 --> 00:08:07,260 and then added them to two separate and individual parameters. 122 00:08:07,260 --> 00:08:10,500 And then I collected them using this array. 123 00:08:10,800 --> 00:08:13,170 And then I'm going to add this array now to the session. 124 00:08:13,560 --> 00:08:14,880 So I'm going to give you the session here. 125 00:08:16,080 --> 00:08:20,940 I'm going to say a session with a key called Card. 126 00:08:22,610 --> 00:08:22,970 Guard. 127 00:08:24,300 --> 00:08:37,170 And the the in order to recognize this this product, we need to give this array a unique I.D. And to 128 00:08:37,170 --> 00:08:40,830 give this this array a unique I.D., we can use the product. 129 00:08:41,100 --> 00:08:48,210 So I'm going to say here right at Andy Roddick, it is going to be equal to the product. 130 00:08:48,210 --> 00:08:48,570 All right. 131 00:08:49,230 --> 00:08:50,100 So let me explain this. 132 00:08:50,110 --> 00:08:52,020 I know that this is confusing right now. 133 00:08:52,740 --> 00:08:58,620 Now, what I did here is that I created a session and that session isn't all right. 134 00:08:58,620 --> 00:09:00,420 So this session let me show you the structure. 135 00:09:00,420 --> 00:09:04,110 So the structure is going to be this session can can store anything. 136 00:09:04,110 --> 00:09:08,700 So it's going to in this case, this session is going to store a store, an array. 137 00:09:09,240 --> 00:09:15,980 And in this array in this array, we have another area, which is this product area, but this product 138 00:09:16,000 --> 00:09:19,680 array, in order to recognize this product, everything we need to give it a unique ID. 139 00:09:20,280 --> 00:09:22,620 So the ID is going to be the product ID. 140 00:09:23,190 --> 00:09:28,980 So, for example, if the product I.D. is true, then I'm going to store to with the product ID. 141 00:09:29,430 --> 00:09:35,430 So this is the product, maybe this is going to represent the product ID and the key is going to represent 142 00:09:35,430 --> 00:09:41,580 the product ID is going to be the product in order to recognize this product. 143 00:09:42,390 --> 00:09:45,450 This in order to recognize this product array. 144 00:09:46,620 --> 00:09:52,680 Because if we add more products, we need to also give them unique ID. 145 00:09:52,800 --> 00:09:57,480 So for example, if I add product three, I'm going to say three is equal to another, right? 146 00:09:57,900 --> 00:10:03,120 And then if I add another product to the record, I'm going to say, for example, five two is equal 147 00:10:03,120 --> 00:10:04,110 to another array. 148 00:10:04,530 --> 00:10:11,610 So each array that I'm going to add to the cart must have a unique I.D. And this is the structure of 149 00:10:11,610 --> 00:10:13,490 the array of recession, right? 150 00:10:13,920 --> 00:10:16,260 So the session array is a big array. 151 00:10:16,260 --> 00:10:23,400 And inside it we will have given you pairs where the key is the product ID and the value is the array 152 00:10:23,400 --> 00:10:27,120 itself is this array that contains the information about that specific product. 153 00:10:27,660 --> 00:10:35,310 That way I will be able to recognize and distinguish between products that have been added to the cart.