1 00:00:00,570 --> 00:00:01,230 Welcome back. 2 00:00:01,590 --> 00:00:07,890 Now, what we need to do is that we need to calculate the total quantity of the cart and also the product 3 00:00:07,890 --> 00:00:09,180 quantity, the subtotal. 4 00:00:09,480 --> 00:00:11,100 So let's start with the subtotal. 5 00:00:11,100 --> 00:00:15,030 So in order to calculate the subtotal, we need to get the here. 6 00:00:15,570 --> 00:00:21,060 We need to get the product quantity and multiply it by the price. 7 00:00:21,060 --> 00:00:28,200 So here in this product price, we can here we have this price here and also it's being displayed here. 8 00:00:28,650 --> 00:00:36,810 So this is the single price and this is the the total subtotal, the total of a single day total of 9 00:00:36,810 --> 00:00:43,350 a one product multiplied by the number up by multiplying by the quantity. 10 00:00:44,130 --> 00:00:52,620 So here service playing 155 we need to say B2B and then we need, we need to multiply the weight to 11 00:00:52,620 --> 00:00:57,570 say echo and then we need to multiply the value product. 12 00:00:59,310 --> 00:01:00,720 Product quantity. 13 00:01:03,880 --> 00:01:08,500 By times the value. 14 00:01:11,500 --> 00:01:13,030 Product price. 15 00:01:15,060 --> 00:01:18,030 Product underscore price and then semicolon. 16 00:01:18,030 --> 00:01:19,050 No, forget the semicolon. 17 00:01:19,380 --> 00:01:21,540 Now, let me see and let me refresh and show you that. 18 00:01:21,540 --> 00:01:29,580 Now, this is going to be nine times 155 because a single a single product would cost to 155. 19 00:01:29,580 --> 00:01:32,670 A single pair of shoes would cost 155. 20 00:01:33,120 --> 00:01:41,910 But if you want to buy nine of these shoes, we need to I need to pay 155 multiplied by nine. 21 00:01:41,910 --> 00:01:46,200 So let me refresh let me go to the cart one more time. 22 00:01:47,040 --> 00:01:53,490 So if I go to the cart, I should say I should here to get 1395. 23 00:01:53,940 --> 00:01:56,400 So if you make the calculation, you will find that this is correct. 24 00:01:56,850 --> 00:02:04,800 Let me prove it to you so many years say to let me say here to if I say to and edit here the cost to 25 00:02:04,930 --> 00:02:10,740 the total cost out of a two shoes is 310. 26 00:02:10,740 --> 00:02:15,950 And that's correct because 155 plus 155 is equal to 310. 27 00:02:15,960 --> 00:02:16,740 So this is correct. 28 00:02:17,250 --> 00:02:20,820 Now let's work on the total product. 29 00:02:20,820 --> 00:02:29,040 So if I have many products, for example, if I have, let me go back and let me add let me go back 30 00:02:29,040 --> 00:02:29,760 to the homepage. 31 00:02:30,420 --> 00:02:35,100 Allow me add this product so this product would cost also, let me let me see look at that product because 32 00:02:35,100 --> 00:02:36,090 I want another price. 33 00:02:36,090 --> 00:02:38,910 So this one this one would cost 250. 34 00:02:39,300 --> 00:02:45,780 So if I click on buy now and add this product to cart, we have here 310 and here 250. 35 00:02:46,080 --> 00:02:47,370 But the total is static. 36 00:02:47,370 --> 00:02:48,630 So we need to work on that total. 37 00:02:49,050 --> 00:02:52,620 To work on the total we need to say we need to create a code a year. 38 00:02:54,220 --> 00:02:55,930 That's going to calculate the total. 39 00:02:56,320 --> 00:02:59,110 So I'm going to create here a function I'm going to here. 40 00:03:00,700 --> 00:03:01,150 Here. 41 00:03:02,410 --> 00:03:03,400 I'm going to give you the function. 42 00:03:03,400 --> 00:03:10,030 I'm going to say function and then I'm going to say calculate total. 43 00:03:10,950 --> 00:03:11,450 Can't. 44 00:03:15,820 --> 00:03:21,610 And then I'm going out in order to get the total, we need to say we need to look over to the station. 45 00:03:22,060 --> 00:03:25,150 So I'm going to say for each session. 46 00:03:26,420 --> 00:03:31,190 Session cart and then we to get each single product. 47 00:03:31,190 --> 00:03:33,280 So we need to say what we need to say for each thing. 48 00:03:33,680 --> 00:03:34,490 Session, cart. 49 00:03:35,610 --> 00:03:37,500 As key. 50 00:03:38,980 --> 00:03:39,790 Value. 51 00:03:41,430 --> 00:03:41,850 Key. 52 00:03:43,930 --> 00:03:47,890 Value and then we need to get each single product. 53 00:03:49,450 --> 00:03:55,630 So each single product in order to get each single product, we need to say session and then. 54 00:03:58,150 --> 00:03:58,900 And then. 55 00:04:00,800 --> 00:04:02,000 And then key. 56 00:04:03,710 --> 00:04:04,100 Key. 57 00:04:05,600 --> 00:04:09,590 This is going to return the array of each single product so we can say here product. 58 00:04:10,070 --> 00:04:17,660 So for each single product, what we want to get is that we want to get we need to say we need to get 59 00:04:17,660 --> 00:04:21,560 the the price as well as the quantity. 60 00:04:23,380 --> 00:04:28,270 So this is going to return an array and each time it's going to return a different product. 61 00:04:28,690 --> 00:04:36,700 So for each different product, for each different for each different product, we need to get the product. 62 00:04:38,970 --> 00:04:40,710 Price and quantity. 63 00:04:40,710 --> 00:04:42,000 So I'm going to get the price. 64 00:04:43,410 --> 00:04:44,220 I'm going to get here. 65 00:04:44,220 --> 00:04:44,730 Price. 66 00:04:47,000 --> 00:04:47,900 And quantity. 67 00:04:50,620 --> 00:04:51,730 Quantity. 68 00:04:52,540 --> 00:05:02,200 So the quantity is going to be equal to your product, product, product, quantity, quantity. 69 00:05:04,100 --> 00:05:06,470 And then we need to multiply the price by the quantity. 70 00:05:06,470 --> 00:05:15,620 So we need to say total is equal to price, price multiplied by the quantity. 71 00:05:20,290 --> 00:05:24,040 However, this is going to return only one total of one product. 72 00:05:24,490 --> 00:05:30,340 Therefore, we need to create a variable called total and it's going to be initially zero. 73 00:05:30,820 --> 00:05:41,070 And then we need to say total is equal to total, total plus price multiplied by the quantity. 74 00:05:41,080 --> 00:05:50,410 So what this what this is going to do is that each time it is going to increase the each time it's going 75 00:05:50,410 --> 00:05:54,700 to increase the it's going to add the old total to the new total. 76 00:05:55,540 --> 00:05:57,100 So it's going to give the all total. 77 00:05:57,100 --> 00:06:02,020 And each time we have a product, we are going to get the price multiplied by the quantity and adding 78 00:06:02,020 --> 00:06:02,620 to the total. 79 00:06:03,190 --> 00:06:08,170 And here, by the way, I should say total and finally we can here say return. 80 00:06:08,350 --> 00:06:10,450 Finally return. 81 00:06:11,200 --> 00:06:11,880 Return what? 82 00:06:11,890 --> 00:06:12,850 To return the total. 83 00:06:15,060 --> 00:06:17,370 Or better. 84 00:06:17,580 --> 00:06:20,220 Instead of returning, we need to store this in indecision. 85 00:06:20,220 --> 00:06:22,560 So I'm going to get here in decision. 86 00:06:22,560 --> 00:06:26,730 I'm going to create a new key called Doctor. 87 00:06:27,480 --> 00:06:27,840 Doctor. 88 00:06:27,840 --> 00:06:34,110 I'm going to say Doctor Total now is going to be equal to doctor. 89 00:06:36,180 --> 00:06:36,660 That's it. 90 00:06:37,200 --> 00:06:38,810 Now we need to call this function so we. 91 00:06:38,810 --> 00:06:39,930 When should we call this function? 92 00:06:40,320 --> 00:06:43,380 We should call this function each time we add a product to the cart. 93 00:06:43,710 --> 00:06:46,380 So we need to call the address inside. 94 00:06:46,770 --> 00:06:47,970 Inside, add to cart. 95 00:06:47,980 --> 00:06:49,260 So inside this add to cart. 96 00:06:50,610 --> 00:06:54,240 Inside this add to cart here. 97 00:06:55,490 --> 00:07:03,980 Hearing to say update or calculate total. 98 00:07:07,160 --> 00:07:09,230 So here I'm going to say calculate total. 99 00:07:11,240 --> 00:07:12,350 Calculate total carte. 100 00:07:14,280 --> 00:07:17,220 Finally, we need to display the total here in the bottom. 101 00:07:20,580 --> 00:07:22,500 In the bottom, we need to say. 102 00:07:24,520 --> 00:07:26,050 We need to say here. 103 00:07:27,550 --> 00:07:30,530 You remember this first part? 104 00:07:30,700 --> 00:07:31,870 This table in this table. 105 00:07:31,880 --> 00:07:38,350 So in this table, we don't need actually this subtotal because we don't have I didn't add any other 106 00:07:38,350 --> 00:07:38,860 costs. 107 00:07:38,860 --> 00:07:40,450 So I am going to remove this subtotal. 108 00:07:40,450 --> 00:07:42,580 Subtotal, we just need the total. 109 00:07:42,580 --> 00:07:47,110 So the total, instead of saying, I want 55, I'm going to remove it and then I'm going to say BHP 110 00:07:47,800 --> 00:07:49,090 and then I'm going to use this session. 111 00:07:49,330 --> 00:07:50,230 I'm going to say Session. 112 00:07:52,100 --> 00:07:52,640 Total. 113 00:07:54,910 --> 00:07:56,720 And of course, we need to say echo. 114 00:07:58,280 --> 00:07:58,820 Echo. 115 00:07:59,480 --> 00:08:00,710 Total session. 116 00:08:00,710 --> 00:08:01,040 Total. 117 00:08:01,550 --> 00:08:03,200 Let me now save and let me refresh. 118 00:08:05,300 --> 00:08:09,470 So here, as you can see, what I'm going to get is that I'm going to get 560. 119 00:08:09,740 --> 00:08:11,930 So let's make it a calculation together. 120 00:08:12,350 --> 00:08:18,050 Is 310 plus 200, 250 is equal to 560. 121 00:08:18,110 --> 00:08:19,160 Well, that's correct. 122 00:08:19,610 --> 00:08:20,750 Let me prove it to you. 123 00:08:21,340 --> 00:08:27,020 Link will prove that this is correct, that the total DOT three total has been calculated correctly 124 00:08:27,350 --> 00:08:31,280 leaving here the number of products and limit click on edit. 125 00:08:32,540 --> 00:08:37,820 And if you click on edit now the total is still here. 126 00:08:37,880 --> 00:08:41,690 The reason why it's still 560 is because actually I need to call. 127 00:08:42,560 --> 00:08:44,510 I need to call the calculate. 128 00:08:44,870 --> 00:08:45,470 Also here. 129 00:08:45,470 --> 00:08:46,610 I need to call it here. 130 00:08:47,610 --> 00:08:52,580 In the in case we update, in case we update or in case we remove. 131 00:08:52,590 --> 00:09:00,780 So here in case we remove something foreign because we need to calculate return to calculate total. 132 00:09:03,310 --> 00:09:14,800 And also in case in case we update in case we update the quantity we need here to calculate total calculated. 133 00:09:19,440 --> 00:09:20,640 Let me try one more time. 134 00:09:20,670 --> 00:09:21,960 So now if I refresh. 135 00:09:25,450 --> 00:09:30,490 Now the total as you can see, the total is 810 linear decrease. 136 00:09:30,490 --> 00:09:32,680 This one more time I'm going to say one and edit. 137 00:09:34,100 --> 00:09:40,340 And now they total again back to a 560 limit increase this to two and then update. 138 00:09:41,360 --> 00:09:44,090 And as you can see, the total now is 810. 139 00:09:44,630 --> 00:09:52,560 If I increase this to three and update, as you can see now, the total is four 965. 140 00:09:52,580 --> 00:09:58,490 So now the total worked successfully and now we have the total total amount. 141 00:09:58,490 --> 00:10:02,660 So this is the single price of this is the subtotal and this is the total.