1 00:00:00,360 --> 00:00:05,640 So here I'm going to use the other two of the script and then I'm going to say a product was already 2 00:00:05,640 --> 00:00:06,090 added. 3 00:00:06,240 --> 00:00:12,840 Product was already added because at this point the product was already added to CART. 4 00:00:12,840 --> 00:00:16,620 So we cannot add the product again to the car because it is in the cart. 5 00:00:17,220 --> 00:00:18,120 So this is the first thing. 6 00:00:18,150 --> 00:00:22,740 The second thing is that I'm going to take the user to the homepage, so I'm going to say Echo. 7 00:00:22,740 --> 00:00:24,480 And then again, I'm going to use JavaScript. 8 00:00:24,480 --> 00:00:26,970 I'm going to say your script, script. 9 00:00:26,970 --> 00:00:30,750 And then inside that script, what I'm going to do, I'm going to say Here script. 10 00:00:31,080 --> 00:00:40,980 And then inside the script I'm going to say here, window dot location, window, dot location and then 11 00:00:40,980 --> 00:00:42,570 interest window again. 12 00:00:42,570 --> 00:00:44,940 Make sure that the script, the spelling is correct. 13 00:00:44,940 --> 00:00:47,490 Here I have a problem, I should say window. 14 00:00:47,490 --> 00:00:55,660 And then that location is equal to index is equal to double cross and then index that Peachtree because 15 00:00:55,660 --> 00:01:00,690 of the index that HP is the home page and of course, don't forget the semicolon at the end. 16 00:01:01,080 --> 00:01:03,630 So here again, let me explain this one more time. 17 00:01:03,930 --> 00:01:04,230 Here. 18 00:01:04,230 --> 00:01:09,360 If the car if the product is not a record, if this product, a particular product is not a record, 19 00:01:09,750 --> 00:01:11,460 then we add that product in the cart. 20 00:01:11,790 --> 00:01:18,300 Else we tell the user that this product was already added to the cart and we take them to the homepage. 21 00:01:18,990 --> 00:01:21,000 So I'm going to click on file and then save all. 22 00:01:21,900 --> 00:01:25,680 And now we are done with this part which are going to add the product again. 23 00:01:25,680 --> 00:01:27,090 This is going to add the product to the cart. 24 00:01:27,090 --> 00:01:31,820 If it doesn't exist, if it hasn't been added to the cart, it's going to add it here. 25 00:01:31,830 --> 00:01:35,940 If, if, if it's the first product, it's going to initiate the session. 26 00:01:36,450 --> 00:01:41,910 If it's not the first product, then it's going to check first whether the product was already added 27 00:01:41,910 --> 00:01:42,200 or not. 28 00:01:42,210 --> 00:01:45,690 If it was added, then we cannot add that product again. 29 00:01:45,990 --> 00:01:51,990 If it has been already added, if it hasn't been already added, then we add that product to cart. 30 00:01:52,710 --> 00:01:53,460 So that's it. 31 00:01:53,610 --> 00:01:56,040 Very, very simple and straightforward. 32 00:01:57,180 --> 00:02:07,250 The next thing that we need to do is that we need to display the product here in the in here, in the 33 00:02:07,260 --> 00:02:08,280 Roomba, in the cart. 34 00:02:09,400 --> 00:02:11,020 In this card we need to display. 35 00:02:12,260 --> 00:02:14,750 The let me show you that. 36 00:02:15,200 --> 00:02:22,250 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. 37 00:02:22,280 --> 00:02:29,060 But here we need to remove these products products because these products have been added historically. 38 00:02:29,180 --> 00:02:31,820 So we need to remove them from the cart, from this cart. 39 00:02:32,420 --> 00:02:35,760 What we want to do is that we want to to leave. 40 00:02:35,780 --> 00:02:42,560 We want to remove two products and leave, only one to use to be used in order to loop over it and display 41 00:02:42,560 --> 00:02:44,570 all products that are in the cart. 42 00:02:45,260 --> 00:02:47,450 So let me here remove this. 43 00:02:47,450 --> 00:02:47,990 So this. 44 00:02:49,110 --> 00:02:49,680 The R. 45 00:02:50,580 --> 00:02:54,480 This represents the last product I'm going to remove this tr. 46 00:02:55,900 --> 00:02:58,000 And they're going to remove also this r. 47 00:03:00,020 --> 00:03:07,160 This represents the second product and I'm going to leave only one PR so we should have now one D.R. 48 00:03:07,700 --> 00:03:11,920 Let me first save and make sure that I didn't break my good leaving here. 49 00:03:11,930 --> 00:03:12,500 Refresh. 50 00:03:13,600 --> 00:03:13,960 And. 51 00:03:16,260 --> 00:03:18,180 And let me go to the one more time. 52 00:03:19,290 --> 00:03:24,600 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 53 00:03:24,600 --> 00:03:27,120 product was already added to CART. 54 00:03:27,120 --> 00:03:27,570 So. 55 00:03:30,130 --> 00:03:30,700 Let me. 56 00:03:32,450 --> 00:03:35,810 Let me let me first disable this. 57 00:03:35,960 --> 00:03:38,030 I think we shouldn't add this at all. 58 00:03:38,570 --> 00:03:41,060 Let me disable this, because we need to go to record. 59 00:03:41,060 --> 00:03:42,800 So I'm going to I'm going to call this out. 60 00:03:43,790 --> 00:03:45,050 I'm going to call this out. 61 00:03:45,980 --> 00:03:47,600 And let me go to. 62 00:03:48,900 --> 00:03:49,740 Let me click here. 63 00:03:50,850 --> 00:03:51,570 By now. 64 00:03:52,350 --> 00:03:56,730 And then I'm going to click on Add to Cart and here it's going to say product was added to CART, but 65 00:03:56,730 --> 00:03:58,460 it's going to leave me in the cart. 66 00:03:58,470 --> 00:04:03,900 Actually, we don't need this go to remove this because we need to stay in the cart. 67 00:04:04,960 --> 00:04:06,400 So I'm going to I'm not going to take it. 68 00:04:06,400 --> 00:04:07,270 They use it to the homepage. 69 00:04:07,900 --> 00:04:10,280 So now we have only one product in the cards. 70 00:04:10,300 --> 00:04:14,940 Now, this product has been added statically and we don't want that. 71 00:04:14,980 --> 00:04:17,200 Instead, we want to add the product dynamically. 72 00:04:18,010 --> 00:04:21,920 So to do this, I'm going to go again to the card. 73 00:04:22,480 --> 00:04:24,220 Let me let me close this down. 74 00:04:25,470 --> 00:04:31,620 And here we need to use the recession in order to display the products that we have in the garden. 75 00:04:32,160 --> 00:04:33,600 I remember that recession. 76 00:04:34,710 --> 00:04:39,710 Recession contains because recession is a loop position. 77 00:04:39,720 --> 00:04:45,600 Again, the structure is that position is a loop with with the with era. 78 00:04:45,630 --> 00:04:47,020 So we need to loop over it. 79 00:04:47,040 --> 00:04:47,940 So I'm going to say here. 80 00:04:49,010 --> 00:04:49,970 You're above this. 81 00:04:50,340 --> 00:04:52,060 TR We need to create a look. 82 00:04:52,070 --> 00:04:52,340 Beer. 83 00:04:54,120 --> 00:05:00,000 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 84 00:05:00,960 --> 00:05:02,580 and then I'm going to use the session. 85 00:05:03,690 --> 00:05:04,260 Session. 86 00:05:05,980 --> 00:05:06,430 Garth. 87 00:05:08,740 --> 00:05:10,500 Session cards. 88 00:05:11,110 --> 00:05:13,960 And then as he. 89 00:05:15,660 --> 00:05:16,290 Value. 90 00:05:18,010 --> 00:05:18,820 Key value. 91 00:05:19,690 --> 00:05:23,870 So the key the key is the product ID, the value is there. 92 00:05:23,870 --> 00:05:24,120 Right. 93 00:05:24,790 --> 00:05:29,980 And then I'm going to add here, Caleb Bracket, I'm going to open the clearly bracket and then below 94 00:05:29,980 --> 00:05:31,870 that I'm going to close the clearly brackets. 95 00:05:31,880 --> 00:05:35,410 I'm going to say B2B and then I'm going to close the bracket. 96 00:05:36,650 --> 00:05:37,340 And then. 97 00:05:41,630 --> 00:05:46,100 And then I'm going to here I'm going to be using the value. 98 00:05:46,430 --> 00:05:47,440 So the value is there. 99 00:05:47,660 --> 00:05:53,600 Remember the array that we added to the card, which is this array in this case and this array in this 100 00:05:53,600 --> 00:05:53,810 case. 101 00:05:54,200 --> 00:05:56,060 So this array has these keys. 102 00:05:56,060 --> 00:05:59,690 It has the product ID, product name, price, image, quantity. 103 00:06:00,230 --> 00:06:05,180 So we need to display the product ID name, price and quantity. 104 00:06:06,370 --> 00:06:08,440 So what I'm going to do is that you're in this loop. 105 00:06:09,880 --> 00:06:11,350 Instead of saying here, why choose? 106 00:06:11,350 --> 00:06:12,640 I'm going to remove this, why choose? 107 00:06:13,570 --> 00:06:17,530 And I'm going to remove this hardcoded text and I'm going to use speech. 108 00:06:17,530 --> 00:06:21,610 Me So I'm going to say here BHP and then I'm going to say Echo. 109 00:06:22,120 --> 00:06:29,260 And then what we want to echo is that we want equity value and we want to echo what we want equity product, 110 00:06:30,010 --> 00:06:36,010 underscore name and then semicolon because the product, the key for product name is product name. 111 00:06:40,490 --> 00:06:42,470 And then we have the. 112 00:06:44,710 --> 00:06:56,380 We have here the price we need to say here, BHP and then echo and we want to echo the value of the 113 00:06:56,380 --> 00:06:58,300 product price. 114 00:07:01,970 --> 00:07:06,770 And then semicolon and I'm going to copy this code because it's going to be the same. 115 00:07:08,090 --> 00:07:13,430 And then I'm going to sit here instead of saying, here, let me check this. 116 00:07:13,460 --> 00:07:14,240 This is the price. 117 00:07:14,240 --> 00:07:20,660 And here also we need to display the price and this is the total price. 118 00:07:20,660 --> 00:07:21,890 So we need to work on this later. 119 00:07:22,670 --> 00:07:25,340 But what else we want to work on is the quantity. 120 00:07:25,760 --> 00:07:26,920 So the quantity is here. 121 00:07:26,930 --> 00:07:35,690 So the quantity, when you need to say the quantity, your value, I'm going to remove this value and 122 00:07:35,690 --> 00:07:36,950 then I'm going to pay this code. 123 00:07:36,950 --> 00:07:39,350 And then I'm going to say product quantity. 124 00:07:40,680 --> 00:07:42,480 Crime data. 125 00:07:44,090 --> 00:07:52,610 For the image remember the image your assets image images feature that I'm going to remove this featured 126 00:07:52,610 --> 00:07:59,360 one that jpeg and then I'm going to place this good echo value a product image. 127 00:08:01,760 --> 00:08:02,350 Let me save. 128 00:08:02,450 --> 00:08:04,160 Leave me here, then over to the browser and test. 129 00:08:04,670 --> 00:08:05,540 So let me refresh. 130 00:08:05,540 --> 00:08:08,600 And if I refresh, it's going to tell me product was already added to CART. 131 00:08:09,200 --> 00:08:09,990 And guess what? 132 00:08:10,010 --> 00:08:11,510 It's going to display the product. 133 00:08:11,930 --> 00:08:15,530 But this time, this product is not the. 134 00:08:16,590 --> 00:08:21,450 It's not the hardcoded product, it's the dynamic product. 135 00:08:21,870 --> 00:08:24,480 And here I have a problem actually displaying the name of the product. 136 00:08:25,230 --> 00:08:26,550 So here I should say. 137 00:08:27,680 --> 00:08:28,700 Product name. 138 00:08:29,600 --> 00:08:31,670 So I have here an issue. 139 00:08:31,700 --> 00:08:35,990 I have an issue with product name of your name. 140 00:08:35,990 --> 00:08:37,430 So I have a problem here. 141 00:08:38,810 --> 00:08:43,580 The in the single product, let me make sure that they passed here. 142 00:08:43,910 --> 00:08:45,260 Here I have, I think a problem. 143 00:08:45,830 --> 00:08:48,980 Product name, product name, product price, product price. 144 00:08:49,520 --> 00:08:50,450 Here I have a problem. 145 00:08:50,450 --> 00:08:54,020 So as you can see here, name should be product underscore price. 146 00:08:55,250 --> 00:08:56,150 Product price. 147 00:08:56,840 --> 00:08:58,610 So this should be product price. 148 00:08:59,890 --> 00:09:03,940 This is why I'm getting your price instead of any. 149 00:09:04,630 --> 00:09:07,270 So in order to fix this, I'm going to close down my. 150 00:09:08,320 --> 00:09:11,440 I'm going to close down this gap, and then I'm going to open it again. 151 00:09:20,860 --> 00:09:24,490 So as you can see here, it's going to display the product name and we have no problem. 152 00:09:25,060 --> 00:09:28,490 Me test with another product to make sure that this works. 153 00:09:28,510 --> 00:09:32,590 I'm going to go back and then I'm going to go back again and let's add another product. 154 00:09:33,040 --> 00:09:34,420 For example, I'm going to add this product. 155 00:09:34,450 --> 00:09:37,960 I'm going to click on Buy now and then I'm going to click on Add to Cart. 156 00:09:38,740 --> 00:09:43,930 So if I click on Add to Cart, as you can see, it has been added to Cart and now it worked successfully 157 00:09:43,930 --> 00:09:46,380 and we have no problems with this. 158 00:09:46,390 --> 00:09:48,460 So the cart now works perfectly.