YouTube2Text

Build Multi Vendor E-Commerce Marketplace with Laravel & React — Transcript

by The Codeholic · 97,657 words · 14,541 segments · language en · Watch on YouTube

Full transcript

  1. 0:00in this video I will teach you how to
  2. 0:02create multivendor e-commerce
  3. 0:04marketplace with laravel and react from
  4. 0:08absolutely scratch the video has time
  5. 0:10codes so if you want to jump to a
  6. 0:12specific section you can do this also I
  7. 0:14have been working on this project for
  8. 0:15about two months and I did my best to
  9. 0:18create a single YouTube video that would
  10. 0:20cover the most complicated e-commerce
  11. 0:23features such as shopping cart
  12. 0:25functionality adding items into the cart
  13. 0:27managing items into the card and also
  14. 0:30adding items for the guest users
  15. 0:32creating product variations vendor users
  16. 0:35will be able to Define different sizes
  17. 0:38colors and they will also be able to
  18. 0:40attach different images to different
  19. 0:42variation options Implement checkout
  20. 0:44functionality using stripe Implement
  21. 0:47multivendor functionality use stripe
  22. 0:50connect to connect vendors into our
  23. 0:53Marketplace account and Implement
  24. 0:56payouts to vendors once in a while we're
  25. 0:58going to also Implement pay a
  26. 1:00distribution between stripe the platform
  27. 1:03and the vendor and there are way more
  28. 1:06than
  29. 1:08[Music]
  30. 1:12this hello everyone my name is Zur and
  31. 1:15I'm the code holic I have 12 plus years
  32. 1:18of experience working as professional
  33. 1:20software developer I have created and
  34. 1:22delivered dozens of projects to my
  35. 1:24clients even now I work full-time I am
  36. 1:27dead of three girls and I love teaching
  37. 1:29so I still somehow manage to find the
  38. 1:32time to create such massive tutorials so
  39. 1:34if you find this tutorial helpful please
  40. 1:36hit the like button and also subscribe
  41. 1:39to the channel because that really means
  42. 1:41a lot to me I started working on PHP in
  43. 1:432013 since 2015 I have been using PHP
  44. 1:47storm as my primary IDE today I'm super
  45. 1:51proud to announce that this massive
  46. 1:53video is sponsored by jet brains and PHP
  47. 1:56storm if you're a developer writing a
  48. 1:58code you probably know what is jet brace
  49. 2:00jet brace creates all kind of IDs and
  50. 2:03tools for different types of programming
  51. 2:05languages such as python Java CP
  52. 2:08JavaScript and so on for PHP they have
  53. 2:10PHP storm which I personally think that
  54. 2:12is the best PHP ID out there PHP storm
  55. 2:15is all-in-one tool it's ready to be used
  56. 2:19as soon as you install it no need to
  57. 2:21waste your time or install some plugins
  58. 2:23or extensions it supports all PHP
  59. 2:26Frameworks laravel WordPress it has
  60. 2:28built-in database client which supports
  61. 2:30almost all the databases and it works
  62. 2:33perfectly for the front end framework
  63. 2:35such as Vu react or tan CSS the autoc
  64. 2:38completion is super smart and very often
  65. 2:40it suggests the options which I'm
  66. 2:42actually looking for recently they added
  67. 2:45full line autoc completion with the help
  68. 2:47of local AI PHP storm downloads local AI
  69. 2:51model and it analyzes your project code
  70. 2:54and gives you Smart Suggestions based on
  71. 2:56the code context and all that happens
  72. 2:59without your project code leaving your
  73. 3:01computer the navigation is super smooth
  74. 3:04you can jump around between classes
  75. 3:06methods properties you can move your
  76. 3:09classes from one folder into another or
  77. 3:11rename the name space or change the
  78. 3:13class name everything is smooth and
  79. 3:16whenever you do such things PHP storm
  80. 3:18doeses refactoring for you you're going
  81. 3:20to see this in the video as well when I
  82. 3:22moved 10 or 12 react files from one
  83. 3:25folder into another and I have not even
  84. 3:28updated any Imports in the project
  85. 3:30everything was done automatically by PHP
  86. 3:32stor yes that works on react files as
  87. 3:34well it also has full git integration
  88. 3:37from inside the ID you can create
  89. 3:40comment messages you can exclude certain
  90. 3:42files or even exclude certain changes
  91. 3:45from the files in the comet message so
  92. 3:48that you can create separate Comet
  93. 3:49messages for those files or those
  94. 3:51changes it's local history actually
  95. 3:54saved my life in many cases when I lost
  96. 3:57something which I didn't have commented
  97. 3:59using git and I was able to recover
  98. 4:01these only because of the PHP Storm's
  99. 4:03local history I also use its scratch
  100. 4:06files features a lot and you're going to
  101. 4:07see this also in the project when I open
  102. 4:09the scratch file for some brainstorming
  103. 4:12for explaining things for some notes it
  104. 4:14works like a charm even if you close
  105. 4:16that scratch file it still is associated
  106. 4:19to the project and you can always reopen
  107. 4:21this whenever you need that after all if
  108. 4:23you still want to customize PHP stor
  109. 4:26this is also possible you can install
  110. 4:28plugins for themes or for different
  111. 4:30functionalities Lal idea is a plug-in
  112. 4:33for Lal developers it adds features like
  113. 4:36grow and model AO completion code
  114. 4:39generation and migration support and all
  115. 4:42that is also compatible with different
  116. 4:44lateral packages such as filament Live
  117. 4:47Wire inertia and a lot more I use this
  118. 4:50package for this specific project also
  119. 4:53and you're going to see how helpful it
  120. 4:54is in cases when I want to autocomplete
  121. 4:57Road names for example in the react
  122. 4:59files and that happens like a charm of
  123. 5:02course that's just one example but
  124. 5:03you're going to see other examples in
  125. 5:04the project as well PHP storm was kind
  126. 5:07enough to provide coupon code for my
  127. 5:08subscribers if you aren subscribed
  128. 5:10please hit the Subscribe button right
  129. 5:11now go to the website jb. g/ thee codol
  130. 5:15or click to the link in the video
  131. 5:17description in the following form you're
  132. 5:18going to enter the coupon code the codic
  133. 5:20your details and you will receive three
  134. 5:22months PHP storm license on your email
  135. 5:25for free that will help you to get
  136. 5:26started with PHP storm and if you like
  137. 5:28it of course you can extend it and thank
  138. 5:31you jet brains and PHP storm for
  139. 5:33sponsoring this video now to get back to
  140. 5:35our project if you are really into this
  141. 5:38project but you're a beginner and you
  142. 5:39don't have any experience on LEL and
  143. 5:42react I highly recommend to get some
  144. 5:44beginners courses for LL and react for
  145. 5:47LL I have amazing course LL for
  146. 5:50beginners it is 24 hours course it has
  147. 5:53first couple of modules actually for
  148. 5:54free you can find this course on my
  149. 5:56website the cod.com and I really
  150. 5:58encourage you just to have a look at the
  151. 6:00first three modules watch it and you
  152. 6:03will understand what I mean and also
  153. 6:05have a look at the uh course curriculum
  154. 6:08you're going to find out all the modules
  155. 6:10that you're going to teach in this
  156. 6:11course even though this course is
  157. 6:13created for beginners actually there are
  158. 6:16some modules which are appropriate for
  159. 6:18intermediate developers as well you're
  160. 6:20going to learn authentication and
  161. 6:22authorization uh what are Gates and
  162. 6:24policies how to write tests and how to
  163. 6:26deploy your projects on production
  164. 6:28environment on custom domain on VPS
  165. 6:30server check the course on my website
  166. 6:32the cool.com and you can find out
  167. 6:35everything by yourself if you're new to
  168. 6:36react I recommend to grab some react for
  169. 6:39beginners course now let's have a look
  170. 6:41at the full demo of this project on the
  171. 6:44homepage we see all the published
  172. 6:46products from our vendors at the moment
  173. 6:48we have only three products each product
  174. 6:51has the information by whom this
  175. 6:53specific product is created and in which
  176. 6:56department it exists by clicking these
  177. 6:59links it is going to open separate
  178. 7:01profile page for this vendor or if we
  179. 7:04click on the department it's going to
  180. 7:05open separate departments page we also
  181. 7:09have ability to search items by keyword
  182. 7:12generally on the homepage or inside
  183. 7:14specific Department by clicking on one
  184. 7:17of the department it is going to filter
  185. 7:19out and leave only products inside this
  186. 7:22department we can add items into the
  187. 7:24card from the homepage just clicking
  188. 7:27these buttons or we can go inside the
  189. 7:29the product Details page have a look at
  190. 7:31the full version of the product and then
  191. 7:33add that into the cart as we see right
  192. 7:36now this product has multiple images it
  193. 7:39has multiple variations each variation
  194. 7:42option has its own images and we see
  195. 7:44right here different variations like
  196. 7:46size style color and so on when we add
  197. 7:51different variation inside the cart
  198. 7:53we're going to see this as a different
  199. 7:55item in the card details so we see black
  200. 7:59headset and we see this green headset
  201. 8:01and right here we also see what
  202. 8:03variation options we used to add that
  203. 8:07item into the cart so from here we have
  204. 8:09ability to change the quantity of the
  205. 8:10item delete that from the cart or save
  206. 8:13for later we also have ability to pay
  207. 8:16only for this vendor however clicking
  208. 8:19proceed to check out will perform the
  209. 8:21checkout for all the cart items what we
  210. 8:24have let's check another product this
  211. 8:26also has variations and I defined
  212. 8:28different quantity and different size
  213. 8:31for each variation options let's say the
  214. 8:34green one is kind of limited it's uh has
  215. 8:38only three item left and its price is a
  216. 8:40little bit higher relative to other one
  217. 8:43so we also have possibility to Define
  218. 8:45such things and I cannot add more than
  219. 8:48three items into the cart okay let's add
  220. 8:51this one as well now let's check out our
  221. 8:53cart items and right here we have two
  222. 8:56vendors vendor store and the second
  223. 8:58which is Zoomer I'm going to click on
  224. 9:01this proceed to check out which asks me
  225. 9:03to authenticate first I have
  226. 9:05authenticated and I'm going to proceed
  227. 9:07to check out on the Strip page I also
  228. 9:09get the overview of the items what I am
  229. 9:12about to check out right now I'm running
  230. 9:14this demo on my local installation and
  231. 9:16images are not visible because of this
  232. 9:19but as soon as you deploy the project
  233. 9:21somewhere on VPS for example then you
  234. 9:23are going to see the images right here
  235. 9:25as well and we see also additional
  236. 9:27information which type what type of
  237. 9:29variations we are trying to check out
  238. 9:32right now so let me fill the information
  239. 9:35after filling out the user information
  240. 9:37the payment was made we are redirected
  241. 9:39back in our website we we see this nice
  242. 9:41success message payment was completed
  243. 9:43and we see two orders right here one is
  244. 9:46for the vendor store with the order
  245. 9:48number items and total and second is for
  246. 9:51the Zoomer uh vendor there will be three
  247. 9:54emails sent totally because of this
  248. 9:56order so we're going to see emails to
  249. 9:58each vent one email to each vendor and
  250. 10:01we're going to see one email to the user
  251. 10:04as well let's check the user email first
  252. 10:06you we customized this email completely
  253. 10:09we used our own logo our own design
  254. 10:11payment was completed successfully we
  255. 10:14see the details of the uh seller one
  256. 10:17order items total we see also the items
  257. 10:20for the seller one and here we see this
  258. 10:21view order details button and we have
  259. 10:23the seller 2 information right here as
  260. 10:26well with some additional information
  261. 10:28you can put right here whatever you want
  262. 10:30now let's see other orders this order is
  263. 10:33uh sent to vendor one we see vendor
  264. 10:36details here what was the um order total
  265. 10:40what was the payment processing fee what
  266. 10:42was that was basically stripe fee the
  267. 10:45platform fee which is by default 10% um
  268. 10:49deducting this payment processing fee
  269. 10:52and what was the vendors earning out of
  270. 10:55the following sale so we have the
  271. 10:57breakdown of the cast
  272. 10:59and we have additional information here
  273. 11:01and now we can check the second order
  274. 11:03email for the vendor too again same type
  275. 11:06of information order total payment
  276. 11:08processing fee platform fee and our
  277. 11:11earnings as a vendor and we see also the
  278. 11:13details of each product now if I log out
  279. 11:16from the website and authenticate as
  280. 11:19vendor user I'm going to see my products
  281. 11:21and my orders and in my order section I
  282. 11:24see this latest order with order number
  283. 11:2620 total price and my total which I
  284. 11:30earned out of the following order I'm
  285. 11:32going to sign out from here and I'm
  286. 11:35going to log in with admin user now so
  287. 11:37we have three roles admin vendor and
  288. 11:40regular user and all of them has their
  289. 11:42own access to data so for the admin user
  290. 11:46we have departments and vendors admin
  291. 11:48users will be able to define the
  292. 11:50Departments they want to be displayed on
  293. 11:53the website so if I click on electronics
  294. 11:55we're going to see the electronics
  295. 11:57department information with a name slack
  296. 12:00and right here we see all the categories
  297. 12:02that belongs to electronics department
  298. 12:05in the vendor section admin users will
  299. 12:07see all the vendors with their status
  300. 12:09and the store name and if we want to
  301. 12:12block certain vendors from the website
  302. 12:15uh let me actually block this one so I'm
  303. 12:17going to change this approved status
  304. 12:19into rejected or even pending which
  305. 12:21means that it is not actually approved
  306. 12:24and right now if we try to access the
  307. 12:26website we are not going to see uh
  308. 12:29products from this vendor so two
  309. 12:31products we are actually hidden on the
  310. 12:32website because the vendor status was
  311. 12:35changed uh from approved if we set this
  312. 12:37back into approved by the Admin user
  313. 12:40then the products for that vendor will
  314. 12:42be also displayed on the website now
  315. 12:45let's say I'm a new vendor user and I
  316. 12:48want to become a member of this
  317. 12:50Marketplace and start selling the year
  318. 12:52what should I do so first let me log out
  319. 12:55and create new account I'm going to use
  320. 12:57actually my name right here as soon as I
  321. 12:59create the account I'm authenticated but
  322. 13:02I need to verify my email address so I
  323. 13:05receiv received a new email right here
  324. 13:06ver for your email address I'm going to
  325. 13:08click on this and verify my email
  326. 13:10address right now I am just buyer and I
  327. 13:13can purchase the items add them uh into
  328. 13:16the cart and check out them but if I
  329. 13:18want to become a vendor I'm going to go
  330. 13:20into profile section and right here I
  331. 13:22have this become a vendor button I'm
  332. 13:25going to click on this I'm going to
  333. 13:26confirm this and now I'm immediately ly
  334. 13:29a vendor user and my status by default
  335. 13:32is approved so we have this Auto
  336. 13:34approval process for vendors which you
  337. 13:36can obviously customize and change it
  338. 13:38and uh create new vendors with a pending
  339. 13:41status and then admin users can approve
  340. 13:43them so because I'm approved I can just
  341. 13:46um adjust my store name store details I
  342. 13:48can update them or this is the
  343. 13:51interesting thing so I can connect to
  344. 13:53stripe without connecting to stripe I
  345. 13:56can actually still access my portal uh
  346. 13:59create the products and display those
  347. 14:02products onto the website and even other
  348. 14:04users can actually purchase my products
  349. 14:07but without connection to stripe I will
  350. 14:09not be able to earn the money now the
  351. 14:12platform will not transfer the money to
  352. 14:15my stripe account so this is something
  353. 14:18uh we are going to do definitely so I'm
  354. 14:19going to click on this connect to Stripe
  355. 14:21Right now this starts stripe onboarding
  356. 14:25process so this is hosted on the stripe
  357. 14:27you can see the domain connect .
  358. 14:29stripe.com and as a vendor I have to
  359. 14:32provide all the necessary details that
  360. 14:34stripe requires from me to be able to
  361. 14:37connect to Marketplace which I'm going
  362. 14:39to do right now this is the final stage
  363. 14:42where I review and submit all my
  364. 14:44information after which I will be
  365. 14:46redirected back into my website so if I
  366. 14:49go into my profile right now I'm going
  367. 14:51to see that you are successfully
  368. 14:53connected to stripe and now whenever I
  369. 14:56sell something I will be able to paid
  370. 14:58out out now I'm going to access my admin
  371. 15:01area from which I can create new
  372. 15:04products I'm going to click on the
  373. 15:05product section new product okay that is
  374. 15:09Main's t-shirt we're going to choose the
  375. 15:12department we're going to choose the
  376. 15:14category I'm going to provide some test
  377. 15:16description here provide price quantity
  378. 15:19which if I leave empty means unlimited
  379. 15:21quantity but let's give it five status
  380. 15:24is going to be published and here I can
  381. 15:26also provide SEO related information
  382. 15:28such as metatype title or description I
  383. 15:30click on Create and now we can upload
  384. 15:33images on that product or we can go
  385. 15:36inside variation types and Define
  386. 15:38different variations now this is
  387. 15:41interesting part I'm going to Define two
  388. 15:43variations for this product we're going
  389. 15:45to have image variation I'm going to
  390. 15:48choose image type right here and we're
  391. 15:51going to give it color so let me
  392. 15:53actually upload images first let's go
  393. 15:56into my folder I have this t-shirt and
  394. 15:59I'm going to choose black one right now
  395. 16:02upload all of them let's give it also
  396. 16:04name black I'm going to collapse this
  397. 16:07and I'm going to no new Option inside
  398. 16:09image let's upload other images let's
  399. 16:12give it text white I'm going to collapse
  400. 16:15this two more
  401. 16:17options this is going to be
  402. 16:20red collapse this and one more
  403. 16:24option this is going to be blue now I'm
  404. 16:28going to add second second variation
  405. 16:29type which is going to be size I'm going
  406. 16:31to choose the type to be radio give it
  407. 16:34size and let's define as many sizes as
  408. 16:37you want I'm going to Define small new
  409. 16:40Option this is going to be medium
  410. 16:43another option this is going to be large
  411. 16:46we don't need to upload any images for
  412. 16:48size so we can collapse this and we can
  413. 16:51make an overview right here we can
  414. 16:53reorder the images as well so I'm going
  415. 16:55to open this I want this one to be the
  416. 16:57first one second
  417. 16:59okay fine now I'm going to click on Save
  418. 17:01changes and we added two variation types
  419. 17:03right now the product is published and
  420. 17:06now I'm going to add also variations
  421. 17:09variation options so we just addit types
  422. 17:12but right now we have the combination of
  423. 17:14these variation types we have black
  424. 17:15small we have white small we have red
  425. 17:18small we have blue small and so on you
  426. 17:21get the idea right so and for each this
  427. 17:23combination we can adjust quantity and
  428. 17:26the price let's say that the r one is
  429. 17:30kind of limited so we have it only one
  430. 17:34and its price is actually 25 now we're
  431. 17:37going to scroll down below and I'm going
  432. 17:38to click on Save changes the product is
  433. 17:41published and if we go on the homepage
  434. 17:44right now we're going to see one more
  435. 17:46product right here black is the default
  436. 17:48one and we see four colors clicking on
  437. 17:51this updates the UI and we see red small
  438. 17:55is only one left and red small also has
  439. 17:58different price now I'm going to log out
  440. 18:01and log in as a regular user again add
  441. 18:04Zora's product into the cart and I'm
  442. 18:06going to perform the checkout after
  443. 18:08check out we see the success Mage and
  444. 18:10now if I log out and log in back with
  445. 18:13zoraa user we're going to see a single
  446. 18:15order for this user with the total price
  447. 18:17my subtotal and the order number as well
  448. 18:19now I'm going to perform payout to
  449. 18:22venders if I check right now my stripe
  450. 18:25account we're going to see that I have
  451. 18:27three connected accounts this is one
  452. 18:30this one is not connected the onboarding
  453. 18:32was not finished I did this on purpose
  454. 18:34and payout will not happen to this
  455. 18:36vendor but for these three payout should
  456. 18:39happen if there are some orders and the
  457. 18:41last one which we connected today is my
  458. 18:44account Zora's account actually and
  459. 18:46zoraa should receive something on his
  460. 18:49balance to perform the payout to vendors
  461. 18:51we have the following custom Artisan
  462. 18:53commment written PHP Artisan payout
  463. 18:55vendors and this is also added inside up
  464. 18:58service provider with this schedule so
  465. 19:01if you have schuer configured correctly
  466. 19:05this command will be executed once in a
  467. 19:08month on the first of the month
  468. 19:09overnight and it is going to perform the
  469. 19:12payout to vendors right now I'm going to
  470. 19:14execute this by hand and we're going to
  471. 19:17see the output as well so here we see
  472. 19:19nothing to process and that happens
  473. 19:21because there should be at least 30 days
  474. 19:26past since the order was made but
  475. 19:29because I simply made the order right
  476. 19:30now the payout didn't work so I opened
  477. 19:34orders table and I changed orders
  478. 19:36created date from 26th of uh November
  479. 19:39into 26th of September and I'm going to
  480. 19:42actually save this right now and we're
  481. 19:44going to reexecute payout vendors now it
  482. 19:47is processing payouts and it is sending
  483. 19:50these to the following users for vendor
  484. 19:52user for user 3 and for Zur as well and
  485. 19:55to if we check right now inside stripe
  486. 19:58connection accounts we are going to see
  487. 20:00my user zoraa has balance
  488. 20:041283 the entire project is built with L
  489. 20:06and react but because of the server side
  490. 20:09rendering we have full SEO capabilities
  491. 20:12as well for example if we go the product
  492. 20:14on the product Details page um check
  493. 20:17specific variations of the products
  494. 20:19we're going to also see that this
  495. 20:21updates the URL and in the URLs we see
  496. 20:23different options what we have just
  497. 20:25chosen by choosing uh different options
  498. 20:28right here the URL is also updated and
  499. 20:31right now we have this pink headset
  500. 20:34selected and now if we check page source
  501. 20:38and scroll down below we're going to see
  502. 20:39right here these meta tags as well so we
  503. 20:41have meta title meta description uh we
  504. 20:44have this OG title description OG image
  505. 20:47as well we have the canonical URL of the
  506. 20:50product and all that happens with the
  507. 20:52help of inertia JS uh serice side
  508. 20:56rendering so if we copy this OG G image
  509. 20:59URL and open this we're going to see
  510. 21:00that this is actually a pink headset so
  511. 21:03this is fully rendered on the server
  512. 21:05side so you can copy the URLs share it
  513. 21:08on social media or even Google will
  514. 21:11start indexing your products nicely if
  515. 21:13you want to know how to deploy your LL
  516. 21:15react with serice side rendering on VPS
  517. 21:18on custom domain I do have a separate
  518. 21:20video on this as well I hope you like
  519. 21:22the project and you are as much excited
  520. 21:24as I was when I started working on this
  521. 21:26project I plan to improve this project
  522. 21:28there will be much more features added
  523. 21:30step by step and if you're interested to
  524. 21:32know more about this when the new
  525. 21:34feature is added or generally to get
  526. 21:37some updates about the project just
  527. 21:39check the video description this project
  528. 21:41is not the type of project you're going
  529. 21:43to watch on mobile or you can watch it
  530. 21:45and you're going to learn everything
  531. 21:47there is a lot more to do this so the
  532. 21:50project duration is 12 hours but
  533. 21:52actually you might need two three or
  534. 21:54even five times more than 12 hours to
  535. 21:58follow follow along and implement the
  536. 22:00same functionality what is done in the
  537. 22:01video please be patient just start
  538. 22:04building follow along if you are stuck
  539. 22:07you can rewind check the same section
  540. 22:09second times I'm sure you can do it and
  541. 22:12you can learn a lot out of this project
  542. 22:15and whenever you feel something about
  543. 22:18this project positive or negative please
  544. 22:21leave a comment down below under the
  545. 22:23video and we can discuss few things uh
  546. 22:25in the comment section as well I will be
  547. 22:27happy to help as as many of you as I can
  548. 22:31now let's start building this awesome
  549. 22:33project now let's create new LEL project
  550. 22:36there are a couple of ways to create new
  551. 22:38project one of them is to open Lal herd
  552. 22:41and open sites right here and then click
  553. 22:45add button here and follow this wizard
  554. 22:48from the user interface the second way
  555. 22:50is to create using terminal which is
  556. 22:52exactly what I'm going to do I'm going
  557. 22:54to close Lal her and I'm going to open
  558. 22:57gitbash Which is my pref choice of
  559. 22:59terminal on Windows you can use any
  560. 23:01terminal you prefer just make sure you
  561. 23:04have composer PHP node commands globally
  562. 23:07available and make sure you also have a
  563. 23:10Lal installer installed globally using
  564. 23:13composer for this you're going to
  565. 23:14execute composer Global require
  566. 23:19ll/ installer you hit the enter it is
  567. 23:22going to install a ll installer and
  568. 23:25you're going to have a ll commment
  569. 23:26globally available after which we we are
  570. 23:29going to execute Lal new and the local
  571. 23:33folder name inside which we are going to
  572. 23:36create the project but first i'm going
  573. 23:38to navigate into her folder because this
  574. 23:41is the folder inside which I want to
  575. 23:42create my project this is where I have
  576. 23:45all my projects using LEL herd right
  577. 23:47here okay so let's clear this up and now
  578. 23:51I'm going to execute LL new Lal
  579. 23:56react e-commerce with the enter now we
  580. 23:59have to choose St I'm going to choose
  581. 24:02Breeze I'm going to choose react here
  582. 24:04I'm going to choose dark
  583. 24:06mode I'm going to choose server side
  584. 24:10rendering and typescript we hit the
  585. 24:12enter I'm going to choose the default
  586. 24:14one which is past and now it's is going
  587. 24:16to take few seconds or minutes to
  588. 24:18download and set the project for us now
  589. 24:21it asks us which database we want to use
  590. 24:24I'm going to choose the default one
  591. 24:25which is sqlite so hit the enter and the
  592. 24:28default one is also to run migrations so
  593. 24:30I'm going to hit the enter and the
  594. 24:31migrations we are executed after which
  595. 24:35it is going to install Lal Bree with
  596. 24:38inertia and it's going to finish the
  597. 24:41project setup it is going to execute uh
  598. 24:43also mpm run build and npm run install
  599. 24:46it is going to also install a LEL pest
  600. 24:49in our project okay the project setup
  601. 24:52was completed it executed mpm run build
  602. 24:56right here with a typescript build for
  603. 24:59uh serice side rendering as well and
  604. 25:01finally we need to navigate into the
  605. 25:03following folder and we can already
  606. 25:04access the project on the following URL
  607. 25:07so I'm going to open this right now in
  608. 25:10my browser and this domain was assigned
  609. 25:14using Lal herd so we can access this if
  610. 25:16you don't use Lal herd use um zamp or
  611. 25:20something else you can always start the
  612. 25:22project using composer run de which is
  613. 25:25relatively new command so because
  614. 25:28because we have these started using
  615. 25:30laral herd we don't need to execute a
  616. 25:32PHP Artisan serve the only thing we need
  617. 25:34to execute is mpm run Dev for
  618. 25:38development okay I'm going to explain
  619. 25:40this in more detailed way but first
  620. 25:42let's open the project using PHP store
  621. 25:46I'm going to open explorer. EXA the
  622. 25:49current
  623. 25:50folder and here we have all the projects
  624. 25:54and Lal react Ecommerce is our project
  625. 25:57so I'm going to open this using PHP stor
  626. 26:01okay so this is Project already opened U
  627. 26:05because of lot of well um because of the
  628. 26:08windows def Ender so we have to exclude
  629. 26:10some of the folders from the def Ender
  630. 26:13to increase the
  631. 26:14performance of the project so we have to
  632. 26:17exclude this here we have to agree on
  633. 26:21that and then I'm going to open PHP
  634. 26:24storms buil-in
  635. 26:26terminal and if you don't use Lal her
  636. 26:30you can start the project by executing
  637. 26:33composer run Dev which runs couple of
  638. 26:37commments this is relatively new
  639. 26:40composer command in Lal projects and it
  640. 26:43is going to execute mpm run Dev as well
  641. 26:46so here we have the V server it is going
  642. 26:49to start the Artisan server as well on
  643. 26:51Port 8,000 let's click on this and we're
  644. 26:54going to see Lal application up and
  645. 26:56running on Port 8,000 as well as well so
  646. 26:59if you're running this using this
  647. 27:01composer randev or PHP Artisan serve you
  648. 27:04might need to change the application URL
  649. 27:08in file so we should probably change
  650. 27:11this into local hostport 8000 like this
  651. 27:14but I'm going to actually use this on
  652. 27:17Lal herd installation on the following
  653. 27:20domain so I'm going to close this and
  654. 27:22because I'm going to use that I'm going
  655. 27:24to leave this URL in the file just like
  656. 27:27this
  657. 27:29and I also don't need to execute
  658. 27:31composer run Dev which runs all these
  659. 27:33commments it actually runs um Q command
  660. 27:37uh V server it is going to run also pale
  661. 27:40command but in my installation it
  662. 27:42requires the following extension which
  663. 27:44is not a big deal I don't um actually
  664. 27:47need to use this pale in in this case um
  665. 27:51but yeah so I'm going to just stop this
  666. 27:55and I'm going to execute mpm run Dev so
  667. 27:58I primarily need two servers Artisan
  668. 28:01server U PHP server and the V server
  669. 28:05okay so PHP server is right here using
  670. 28:09herd and engine X and I just need mpm
  671. 28:11run and just like this I have my
  672. 28:13application up and running and I'm going
  673. 28:15to leave this mpm run Dev always running
  674. 28:18I'm going to open second terminal from
  675. 28:20which I'm going to execute PHP artisan
  676. 28:23and as you see the PHP storms new
  677. 28:25terminal actually autocompletes a few
  678. 28:28things for us we can see the folders and
  679. 28:31commments and many other things PHP
  680. 28:34Artisan um
  681. 28:37Storage storage colum link we hit the
  682. 28:41enter the storage link was created now
  683. 28:45let's explore typescript related project
  684. 28:48folder and file structure I think this
  685. 28:50is really interesting so we're going to
  686. 28:52go into resources JS and this is the
  687. 28:55place where all the react applications
  688. 28:58react files are located and here we have
  689. 29:01this main app. T6 which is the main
  690. 29:04application it creates the inertia
  691. 29:06application and inside setup it has two
  692. 29:09versions if the server side rendering is
  693. 29:11enabled it uses this hydrate route
  694. 29:14otherwise it uses this create route and
  695. 29:16finally everything is rendered inside
  696. 29:18this app uh component okay let's open
  697. 29:22this um this bootstrap TS is very simple
  698. 29:25nothing complicated let's open this
  699. 29:27server side range rendering right here
  700. 29:29and here we see this function create
  701. 29:32server which has the following render
  702. 29:34common so everything is rendered so that
  703. 29:36file is basically responsible to render
  704. 29:40the application with serers side
  705. 29:41rendering when we actually have the
  706. 29:44server side rendering server up and
  707. 29:46running and here we have this resolve
  708. 29:49page component as well to and this is
  709. 29:52the location where all the pages is
  710. 29:54going to reside so that's the main file
  711. 29:57for server side rendering basically okay
  712. 30:00and it use this uh Ziggy roads right
  713. 30:03here for resolving roads as well okay
  714. 30:06now let's go into types that's really
  715. 30:09interesting so inside This Global we
  716. 30:11have this window and root which is
  717. 30:14actually Ziggy Ro imported from this
  718. 30:17Ziggy JS Ziggy basically is a package
  719. 30:20which registers all the Lal Roots into
  720. 30:24react um into JavaScript so that we can
  721. 30:27use these Roots by root name into react
  722. 30:30application and we also have the
  723. 30:32following U Declaration of module for
  724. 30:35inera JS core we we overwrite this page
  725. 30:38props which actually extends two things
  726. 30:41it extends inura page props now which is
  727. 30:45coming from inertia core page props and
  728. 30:47it also extends the application page
  729. 30:49props um right here so and the
  730. 30:52application page props uh leaves in its
  731. 30:55own file index. d. TS this is it and
  732. 31:01right here we have two main types the
  733. 31:03user interface uh which has the
  734. 31:05following fields and the page props
  735. 31:07which um is kind of uh has
  736. 31:10this abstract type of definition so that
  737. 31:14we can extend these page props and
  738. 31:16additional types right there and the
  739. 31:19page props uh actually has is has
  740. 31:22additional things added to it as well
  741. 31:25which is out and zigy and if we open
  742. 31:28other Pages like uh welcome for example
  743. 31:32we can see that right here we are
  744. 31:33accepting the following props and using
  745. 31:37typescript we Define that the following
  746. 31:39object basically will have the type of
  747. 31:42page Props Plus edit Lal version field
  748. 31:46which is string and PHP version which is
  749. 31:49string so we are actually taking out
  750. 31:51three properties from this object from
  751. 31:53the props out Lal version and PHP
  752. 31:56version out is defined inside this page
  753. 31:59props we can see it right here but this
  754. 32:02lateral version and PHP version is
  755. 32:04declared right here so if we remove The
  756. 32:06Following part basically then um the PHP
  757. 32:12storm will start complaining about it
  758. 32:15and we will not be able to execute mpm
  759. 32:18run build to build our project because
  760. 32:21typescript simply doesn't know where
  761. 32:23this lateral version and PHP version is
  762. 32:26coming from so we can test this we can
  763. 32:28open Terminal we can open new terminal
  764. 32:31or we can simply close this terminal
  765. 32:33inside which we have mpm run Dev running
  766. 32:36and we can execute mpm run build and
  767. 32:40we're going to see the error and every
  768. 32:42time when you execute mpm run build if
  769. 32:45you have that error you should know that
  770. 32:47this is the reason okay so this not
  771. 32:51specifically related to this welcome T6
  772. 32:53but something is not okay with the
  773. 32:55typescript and this is exactly right
  774. 32:57here so I'm going to undo
  775. 32:59this the following thing and we can
  776. 33:02execute mpm run build again and
  777. 33:04everything should be
  778. 33:07good yeah if it started building it
  779. 33:09means everything is good now it's
  780. 33:11building for SSR and finally it was done
  781. 33:13mpm run
  782. 33:15Dev okay so we can check other files
  783. 33:19like um inside dashboard this is pretty
  784. 33:21simple it doesn't even accept props we
  785. 33:23can check the profile area profile edit
  786. 33:26we are accepting this must verify email
  787. 33:29here and Status so these are again added
  788. 33:33into the default page props and so on so
  789. 33:35we're going to of course create new
  790. 33:37types uh new prop declarations similar
  791. 33:40to the following one and everything will
  792. 33:43get more clear just um I generally
  793. 33:46recommend when you start new project and
  794. 33:48use some starter kit whether that's the
  795. 33:51first party starter kit like larel
  796. 33:53breeze or some third party I recommend
  797. 33:56to browse into the project and
  798. 33:59understand its structure how it is
  799. 34:01structured how certain things are used
  800. 34:03because that's the standard for that
  801. 34:06project and sometimes young developers
  802. 34:08simply delete everything uh what they
  803. 34:11don't need and start from scratch after
  804. 34:14the starter kit so that's not actually
  805. 34:16like really good idea so I I can
  806. 34:18obviously delete pages and create new
  807. 34:21pages and whatever I need but you should
  808. 34:23simply consider how this the developers
  809. 34:27of this first party or third party
  810. 34:29starter kit created things so that you
  811. 34:31can replicate uh in the same way so one
  812. 34:36thing I want to change is that we see
  813. 34:38that the indentation is set into four
  814. 34:40spaces 1 2 3 4 and this is what I want
  815. 34:43to change and for this I'm going to open
  816. 34:45editor config find this indent size two
  817. 34:49for yml files and I'm going to add Ts
  818. 34:52for TS and TSX files we want to set the
  819. 34:56indentation to be two as well
  820. 34:58additionally we can add JS and jsx as
  821. 35:01well even though we don't have those JS
  822. 35:03and jsx files and after this if we open
  823. 35:07edit or dashboard or any other file
  824. 35:10where the indentation is set into four
  825. 35:12spaces and we try to reformat the code
  826. 35:15using um the shortcut on my keyboard or
  827. 35:18using right click and
  828. 35:22refactor where is the
  829. 35:25reformat I almost always use the
  830. 35:30um yeah anyway so I'm going to still
  831. 35:32stick with my shortcut control alt and L
  832. 35:35this going to reformat the code into two
  833. 35:37spaces okay and this is generally how I
  834. 35:39prefer I don't want the text go uh go to
  835. 35:42the right too much and that's it so one
  836. 35:46thing I want to change is that inside
  837. 35:48components we have a bunch of components
  838. 35:50and I'm going to Define two main folders
  839. 35:52inside components one is going to be for
  840. 35:56core components and and second is going
  841. 35:58to be for up related components
  842. 36:01generally I differentiate these two
  843. 36:04folders in the following way everything
  844. 36:06that is specific to this project like
  845. 36:09the application logo for example uh
  846. 36:12before I move this I will explain
  847. 36:14everything that is specific to this
  848. 36:16project like the application logo for
  849. 36:17example I'm going to move this into app
  850. 36:20component anything that can be used into
  851. 36:24another project as well uh it's it is a
  852. 36:27core component and from Project to
  853. 36:30project if I create this core folder
  854. 36:33which contains all the reusable core
  855. 36:35components I can easily copy and paste
  856. 36:37from this project into another project
  857. 36:39this core folder and um just like this I
  858. 36:43will have every reusable components into
  859. 36:45a single folder so like checkbox for
  860. 36:48example danger button drop-down all
  861. 36:50these are core components and I'm going
  862. 36:52to move them
  863. 36:55however there's one thing I want to to
  864. 36:57show and why I Love Actually PHP storm
  865. 37:01so if we open for example
  866. 37:03login. TSX file so here we have those
  867. 37:08components let's see in the import area
  868. 37:10we see this checkbox input error input
  869. 37:12label primary button everything is
  870. 37:14coming from the components folder now if
  871. 37:17we take those components like now let's
  872. 37:20take only one primary button in this
  873. 37:22case and primary button is a core
  874. 37:24component which can be used into another
  875. 37:25project as well so I'm going to move
  876. 37:27this into core click on refractor and as
  877. 37:31you see the import of this primary
  878. 37:34button was also updated and we can try
  879. 37:36to find out all the other places where
  880. 37:39that was changed we can find like import
  881. 37:42primary button into the entire project
  882. 37:45and we see that it is used inside eight
  883. 37:47places and all of them we are updated
  884. 37:50because we moved this primary button
  885. 37:53using PHP Storm from one folder into
  886. 37:55another this this is awesome this is why
  887. 37:58I love using PHP storm and generally jet
  888. 38:00Brand Products so I'm going to move now
  889. 38:02this text input secondary button uh
  890. 38:06maybe the responsive nav link and nav
  891. 38:08link and modal almost all of
  892. 38:11them into the
  893. 38:15core refactor and now we're going to see
  894. 38:18that all of them we are updated okay now
  895. 38:20all of them is coming from core and
  896. 38:22let's move this application logo into up
  897. 38:25we're going to create more components
  898. 38:26inside the app folder now the coolest
  899. 38:29part is that we did all these moving
  900. 38:31from one folder into another but our
  901. 38:33application is not broken because
  902. 38:36everything was refactored we're going to
  903. 38:37see the login page we're going to see
  904. 38:40register page everything is there
  905. 38:42everything is up and
  906. 38:46running now I'm going to initialize git
  907. 38:49repository and I'm going to comment
  908. 38:50everything what I have created so far
  909. 38:53and this is pretty much initial comment
  910. 38:55so let's execute actually when working
  911. 38:58with Git I prefer to use gitbash so I'm
  912. 39:01going to open gitbash Terminal and I'm
  913. 39:03going to execute git in it so it
  914. 39:06initialized the repository right now and
  915. 39:09additional project icon was added under
  916. 39:12the project additional Navigation icon
  917. 39:15was added this is for Comet if we click
  918. 39:17on this we're going to see that there
  919. 39:20are2 files at the moment all of them are
  920. 39:23unv verion files uh we don't need to
  921. 39:26browse them because this is the initial
  922. 39:28Comet but we can group them by directory
  923. 39:31which is awesome and we can browse them
  924. 39:34uh by directory so in this case I
  925. 39:37actually don't need to browse anything
  926. 39:39so this is the initial comment I can
  927. 39:41just take all of them and just give it
  928. 39:43message initial
  929. 39:47comment we're going
  930. 39:51to do we need to yeah it has something
  931. 39:55like to analyze all the files and if we
  932. 39:58have this analyzing all the files active
  933. 40:00it going to take some time to analyze
  934. 40:02all the typescript files for us what we
  935. 40:05are about to comit and if we have some
  936. 40:08warnings it's going to give us those
  937. 40:09warnings maybe it's right here no this
  938. 40:12is not it okay let's hit on Comet and
  939. 40:15have a
  940. 40:15look okay the comet was completed it
  941. 40:18didn't analyze which is exactly what I
  942. 40:20wanted in this specific case because uh
  943. 40:23this is the initial project I don't need
  944. 40:25the analyze from git when I'm initially
  945. 40:28commenting the whole the whole 100 files
  946. 40:33okay so far so
  947. 40:35good now we're going to install da UI
  948. 40:38which is one of the most popular
  949. 40:40component library for tyan CSS we can
  950. 40:42check the entire documentation right
  951. 40:44here what components it supports and
  952. 40:47everything and I'm going to use this
  953. 40:49documentation quite often to copy
  954. 40:51certain things like the button designs
  955. 40:54for example we're going to copy these
  956. 40:55CSS classes into um into our project but
  957. 40:59first we're going to obviously install
  958. 41:01the project and for this let's open PHP
  959. 41:04stor I'm going to open Terminal this is
  960. 41:06g p terminal I can execute mpm install
  961. 41:08commands here as well or I can create
  962. 41:11separate terminal for this actually I'd
  963. 41:13love to organize these terminals so this
  964. 41:16is vit I'm going to call this this is
  965. 41:18vit server and we can call this um
  966. 41:22Artisan for example some artisan
  967. 41:24commments and we have gitbash so in this
  968. 41:26case I'm going to open partisan command
  969. 41:28and I'm going to execute um npm install
  970. 41:31and we see the terminal out completes
  971. 41:34for us mpm install
  972. 41:37Daisy Daisy UI and it fetched this from
  973. 41:40the npmjs as well so daui we're going to
  974. 41:44hit the enter it is going to install
  975. 41:46Daisy UI which was already done next
  976. 41:49we're going to open um tan config JS and
  977. 41:54right here we're going to use this Daisy
  978. 41:56UI so the pro project is already using
  979. 41:59forms which is something I want to
  980. 42:01remove so I'm going to remove this from
  981. 42:03here and I'm going to remove this from
  982. 42:05Imports and I'm going to also delete
  983. 42:08this package so let's bring up the
  984. 42:10terminal mpm uninstall and paste this
  985. 42:14tile on CSS SL forms we're going to hit
  986. 42:16the enter it is going to be uninstalled
  987. 42:19now let's
  988. 42:22require Daisy UI okay so far so good so
  989. 42:26we save this and now our application is
  990. 42:29actually using da UI we can click onite
  991. 42:32and we see that two them themes added
  992. 42:34into the project now let's check our
  993. 42:37project in the browser we're going to
  994. 42:39click on login and we see some Styles
  995. 42:42related to forms are actually broken so
  996. 42:45this is still tyon CSS some of the
  997. 42:47common things are there but the forms
  998. 42:50got broken and this is something we are
  999. 42:52going to fix now let's search for input
  1000. 42:55error uh not there text input and we're
  1001. 43:00going to find the following input with
  1002. 43:02border let's go into HTML or jsx doesn't
  1003. 43:05matter in this case and there are two
  1004. 43:07main classes input and input bordered
  1005. 43:10this is what we are going to add into
  1006. 43:12the inputs so this is the login form now
  1007. 43:16let's open login. T6 and we don't need
  1008. 43:20this T in config JS so I'm going to
  1009. 43:21close this and let's find now input here
  1010. 43:25we have this input label and text input
  1011. 43:28let's click on this text input now which
  1012. 43:30is a core component so this now leaves
  1013. 43:33inside this core component okay core
  1014. 43:35folder and let's scroll down below and
  1015. 43:37we have a bunch of talin Cs classes
  1016. 43:39which I'm going to remove and only leave
  1017. 43:41input and input bordered now I'm going
  1018. 43:44to save this and if we check in the
  1019. 43:46browser we see that the inputs are now
  1020. 43:48fixed this is awesome uh additionally we
  1021. 43:51can put those the class names into a
  1022. 43:53single line because we don't have that
  1023. 43:56many classes and I'm going to also every
  1024. 43:58time I open this new file I'm going to
  1025. 44:01format the code so that everything is
  1026. 44:03indented into two spaces
  1027. 44:05nicely okay next is to
  1028. 44:08open this um label where's the label
  1029. 44:12input label okay and we can check also
  1030. 44:15ji docks how the label is added right
  1031. 44:18here we can see that everything is
  1032. 44:21inside form control class which is
  1033. 44:22something we can do or cannot do we can
  1034. 44:25avoid that but the main thing is that
  1035. 44:27we're going to use this label class okay
  1036. 44:29and inside label class we're going to
  1037. 44:31have this span with label text okay this
  1038. 44:34is what I'm going to do now so this is
  1039. 44:36label we're going to give it a label
  1040. 44:39class and again we can put this on a
  1041. 44:42single line like this format on two
  1042. 44:46spaces and then we're going to use span
  1043. 44:51here and we're going to add to the span
  1044. 44:54class name label Tex
  1045. 44:57text okay now it is using the labels in
  1046. 45:02the same style that is inside right here
  1047. 45:06inside the daisy UI and the next thing
  1048. 45:08is to change the checkbox so we can find
  1049. 45:11the
  1050. 45:13checkbox and I'm going to go with a
  1051. 45:15primary color checkbox and the main
  1052. 45:18thing is that we're going to add those
  1053. 45:19two classes checkbox checkbox primary to
  1054. 45:22the input so again inside the core
  1055. 45:25component we're going to open checkbox
  1056. 45:28and instead of those classes we are
  1057. 45:30going to Simply a checkbox checkbox
  1058. 45:32primary put everything classes on a
  1059. 45:35single line format the code additionally
  1060. 45:38we can move these props into its own
  1061. 45:40line so that it is not too right so we
  1062. 45:45format the code and now this is this
  1063. 45:47looks like this we can do something
  1064. 45:48similar for
  1065. 45:51labels and for inputs no this is nicely
  1066. 45:55formatted already and let's check now
  1067. 45:59checkbox this is it this is awesome and
  1068. 46:02we have this primary button as well so
  1069. 46:04let's
  1070. 46:05open let's open secondary Button as well
  1071. 46:08and primary button we're going to adjust
  1072. 46:10both of
  1073. 46:11them so this is the primary button we're
  1074. 46:14going to remove all these classes and
  1075. 46:16we're going to give it BTN BTN primary
  1076. 46:20and additionally if the button is
  1077. 46:22disabled we add the opacity 25 which
  1078. 46:25comes with a breeze I'm going to remove
  1079. 46:27this because if it's disabled Daisy UI
  1080. 46:29will apply correct styles to this so I'm
  1081. 46:33going to format this class the
  1082. 46:36component nicely let's open secondary
  1083. 46:38input as well uh and I'm going to remove
  1084. 46:43all these classes but instead of a
  1085. 46:46secondary BTN BTN secondary I'm going to
  1086. 46:49give it a
  1087. 46:51different
  1088. 46:52um just BTN class okay and I will
  1089. 46:56explain why a little bit later because
  1090. 46:58BTN secondary um is not the color I
  1091. 47:01actually want for my secondary button so
  1092. 47:04we can remove this disabled classes
  1093. 47:06again we can put this on a single line
  1094. 47:09format the code uh move this down again
  1095. 47:12format the code and now this is awesome
  1096. 47:15okay so this is the primary button these
  1097. 47:17are inputs so far so good let's click on
  1098. 47:22register
  1099. 47:23and this form also looks
  1100. 47:29nice let's check the login page again
  1101. 47:32and find this link which
  1102. 47:37is right here forgot your password and
  1103. 47:41we can find also links from the
  1104. 47:45documentation okay here we go so this is
  1105. 47:47a simple link and we just need to add a
  1106. 47:50link class instead of all these things
  1107. 47:52so
  1108. 47:54let's change everything and just add
  1109. 47:58link class to it and we're going to do
  1110. 48:00something similar into register so let's
  1111. 48:04search for link and remove all these
  1112. 48:07classes and add link class to it now
  1113. 48:12this link which is Daisy UI link if we
  1114. 48:16go into actually if we click on this
  1115. 48:18already registered now this is also link
  1116. 48:21which is Dai link not the um not the one
  1117. 48:25which comes with um Breeze installation
  1118. 48:28additionally I want to also open
  1119. 48:32authenticated layout and uh this is why
  1120. 48:36I want to change this and first let's
  1121. 48:39search this authenticated layout where
  1122. 48:42it is used I think it is used in the
  1123. 48:44dashboard so let's open pages dashboard
  1124. 48:47TSX we see that the authenticated layout
  1125. 48:50is used actually right here but the
  1126. 48:52thing is that so it is imported from
  1127. 48:55this authenticated layout
  1128. 48:57uh and the import is also called
  1129. 48:59authenticated layout but inside we have
  1130. 49:02this named as authenticated and whenever
  1131. 49:04we try to use
  1132. 49:07authenticated um or authenticated layout
  1133. 49:10if we don't have that import so if we
  1134. 49:12created new file and I want to import
  1135. 49:16authenticated layout it is not able to
  1136. 49:18see authenticated layout it is it says
  1137. 49:21authenticated because this is the name
  1138. 49:23of the function inside this file and
  1139. 49:26this is why I want to change it okay
  1140. 49:29let's return this back and open this
  1141. 49:32file and I'm going to change this into
  1142. 49:34authenticated layout and now whenever I
  1143. 49:36need to use this it's uh the
  1144. 49:38autocomplete will give me this find with
  1145. 49:41the following
  1146. 49:43name now let's sign up on the
  1147. 49:46website let's click on uh actually I
  1148. 49:49think we have to change this no
  1149. 49:51everything's good here okay so we're
  1150. 49:54going to go into register page and I'm
  1151. 49:57going to try to create new account
  1152. 50:00actually when we navigate between Pages
  1153. 50:02as you probably noticed so it is a
  1154. 50:04little bit slow and this is because we
  1155. 50:07are using serers side rendering approach
  1156. 50:10but we don't have the SSR server started
  1157. 50:15running okay and sometimes that works
  1158. 50:18slightly slow but when we actually build
  1159. 50:21this and when we set up the project and
  1160. 50:24when we have the server side rendering
  1161. 50:26server also up and running it is not
  1162. 50:28going to be um that
  1163. 50:30slow it is going to be actually super
  1164. 50:33fast so I'm going to now try to create
  1165. 50:35new account we hit the enter the account
  1166. 50:37was created now let's go into profile
  1167. 50:41and we are using primary buttons right
  1168. 50:43here however this delete account is
  1169. 50:45actually a danger button which is not
  1170. 50:48something what we change so we're going
  1171. 50:50to open this danger button and I'm going
  1172. 50:52to remove these
  1173. 50:54classes and we're going to give it PTM
  1174. 50:56BTN error uh we're going to remove this
  1175. 51:00disabled oppacity class and let's put
  1176. 51:04this on a line format
  1177. 51:07this like this and this is cool now this
  1178. 51:10is the default danger button in daui
  1179. 51:14whenever we click on this now this opens
  1180. 51:16the danger button here and the secondary
  1181. 51:19button right here and this is why I gave
  1182. 51:23the BTN
  1183. 51:25class just BN class into the secondary
  1184. 51:28button so if I give it BTN secondary now
  1185. 51:32these colors are not nice to each other
  1186. 51:35in my opinion so I just leave it as
  1187. 51:39BTN okay I think we just moved into da
  1188. 51:45UI quite successfully now we can move on
  1189. 51:48to the next part which is actually to
  1190. 51:50define the navbar layout of our project
  1191. 51:54so we can search inside Daisy Y navbar
  1192. 51:58and we can find bunch of Navar examples
  1193. 52:01and they look pretty awesome so the
  1194. 52:02basic one and more complex one with some
  1195. 52:05links and dropdowns and we can see the
  1196. 52:08search as well the Avatar with it own
  1197. 52:11drop down this is cool and we even have
  1198. 52:13an example with a cart so this is
  1199. 52:15exactly what I want to use so I'm going
  1200. 52:17to just go into GSX and copy these but
  1201. 52:21before I copy that part I'm going to
  1202. 52:24comment the changes I made previously
  1203. 52:26and generally when building in real
  1204. 52:28project I always recommend to review the
  1205. 52:31changes you made because it is very very
  1206. 52:34common especially for beginner
  1207. 52:36developers so that you make an
  1208. 52:39intentional change into the project or
  1209. 52:41maybe intentional uh but this this this
  1210. 52:45is something you didn't actually want to
  1211. 52:47make uh when when you finally make the
  1212. 52:51review you understand okay yeah I should
  1213. 52:53probably not make this okay so in our
  1214. 52:56case we sh like we should probably make
  1215. 52:59a review but I'm not going to do this
  1216. 53:01right now obviously I'm not going to
  1217. 53:02take your time making these reviews but
  1218. 53:04generally just click double click on
  1219. 53:06this and see every change what you made
  1220. 53:08when you are building a real project
  1221. 53:10especially if you're are fixing
  1222. 53:12something on production you just pull
  1223. 53:13the code the production code make some
  1224. 53:15change there and your comment push for
  1225. 53:18the server just make the review because
  1226. 53:20that saved my life personally many many
  1227. 53:23times in the past when working on the
  1228. 53:25project some times like mistakenly uh
  1229. 53:28the developer modified the G ignore code
  1230. 53:31or I modified the G ignore code I hit an
  1231. 53:33incorrect character on my keyboard and I
  1232. 53:36didn't notice that I modified the G
  1233. 53:38ignore and the entire node modules
  1234. 53:40folder or the vendor folder was about to
  1235. 53:42be commented so just make the review and
  1236. 53:45you you have also these arrows right
  1237. 53:47here to navigate into all reviews even
  1238. 53:51across many files and yeah if something
  1239. 53:56uh doesn't feel right you can always
  1240. 53:58undo the change by clicking right here
  1241. 54:00here now in our case everything is good
  1242. 54:03we want that changes and that's perfect
  1243. 54:05one additional thing I really love in uh
  1244. 54:08using page patform is that so we can
  1245. 54:11actually include partial comment so I
  1246. 54:13want to for example comment everything
  1247. 54:17except inside the checkbox that specific
  1248. 54:21change and this change and I want to
  1249. 54:22include that specific changes into
  1250. 54:24another file into sorry to another
  1251. 54:26comment message this is what I also have
  1252. 54:29done um many times so your comment
  1253. 54:32messages should be Atomic one comment
  1254. 54:35message should be basically for one
  1255. 54:38thing what you did and sometimes we are
  1256. 54:40developers we're working we don't
  1257. 54:42remember always to open the comet and um
  1258. 54:45create the comment message so that's why
  1259. 54:47I very often have many changes in the
  1260. 54:49project but I just open this and just
  1261. 54:53include the files and changes only what
  1262. 54:56I want in the first comet then what I
  1263. 54:58want in the second Comet and so on and
  1264. 55:02here we removed uh the talent SES forms
  1265. 55:05and installed
  1266. 55:07Dy inside these dependencies and which
  1267. 55:11is
  1268. 55:12actually uh I think the day UI should be
  1269. 55:15inside um Dev dependencies yeah but
  1270. 55:20anyway we can leave this so we are going
  1271. 55:22to give this comment message install and
  1272. 55:25activate at uh Daisy
  1273. 55:29UI control and enter everything was
  1274. 55:32committed and now we can focus on the
  1275. 55:34Navar so let's now open authenticated
  1276. 55:39layout right
  1277. 55:41here and we have this nav which is
  1278. 55:45actually nav bar right here just above
  1279. 55:48the header and the header is the
  1280. 55:50following area this is the header and
  1281. 55:52this is the nav bar obviously so we're
  1282. 55:54going to take out this nav and let's
  1283. 55:56create Now new component which is
  1284. 55:58specific to our project so I'm going to
  1285. 56:01put this inside app folder new
  1286. 56:04typescript file js6 file navbar we're
  1287. 56:08going to hit the enter click on add to
  1288. 56:11add this file into git
  1289. 56:14project and here I'm going to use no
  1290. 56:16shortcut to generate the skeleton of my
  1291. 56:18component R SF we're going to hit the
  1292. 56:22tab and the component was created and
  1293. 56:25now let's put the this nav right
  1294. 56:28here actually uh this is what I'm going
  1295. 56:32to
  1296. 56:33do so actually I'm going to put this nav
  1297. 56:37into a new scratch file so Control Alt
  1298. 56:41shift and insert to create new scratch
  1299. 56:44file I'm going to choose HTML scratch
  1300. 56:47file and paste everything here and if we
  1301. 56:51expand this we're going to see this
  1302. 56:52entire nav bar would we copied so far
  1303. 56:54but what I want is is to take this new
  1304. 56:58navbar component so I'm going to copy
  1305. 57:00this paste everything here uh I can
  1306. 57:04remove all these Imports I don't need
  1307. 57:06them at the
  1308. 57:07moment these are props and at the moment
  1309. 57:10I don't want to also accept any props
  1310. 57:12and if we have a look in the browser uh
  1311. 57:14we are not going to see anything because
  1312. 57:16we don't use this newly created navbar
  1313. 57:19so if we go in the authenticated
  1314. 57:23layout uh yeah the the nav bar was
  1315. 57:25actually lost but let's use now
  1316. 57:31navbar save that and now we see this
  1317. 57:34Daisy UI Navar including the drop downs
  1318. 57:37and everything okay now if we go in the
  1319. 57:40nav bar I'm going to change this Daisy
  1320. 57:41UI into Lara store we're going to change
  1321. 57:46this into iner link and specify hre to
  1322. 57:50be just slash and we're going to import
  1323. 57:52that in your link that is awesome now
  1324. 57:56let's scroll down below and find the
  1325. 58:00profile section here we see the profile
  1326. 58:02we're going to change this into inertial
  1327. 58:04link again inside h r we're going to
  1328. 58:07provide a
  1329. 58:08root and this is going to be profile.
  1330. 58:12edit and the autoc completion right here
  1331. 58:14happens using Lal idea plugin okay
  1332. 58:18without the Lal Ida plugin you are not
  1333. 58:21going to get that type of Auto
  1334. 58:23completion for roads in your um
  1335. 58:26T6 files so we're going to use this
  1336. 58:29route edit we're going to remove this
  1337. 58:31new we don't need settings and we're
  1338. 58:33going to change this
  1339. 58:35into uh into the following way and this
  1340. 58:37is going to be link again inside HRI
  1341. 58:40we're going to provide root uh log
  1342. 58:44out and we're going to provide method to
  1343. 58:48be method to be post and we're going to
  1344. 58:53also H give as button so the following
  1345. 58:58link should be
  1346. 59:01button okay so again we form the code
  1347. 59:04save everything now we see the profile
  1348. 59:06page clicking on which activates the
  1349. 59:09profile that's awesome and if I click on
  1350. 59:11log out that actually performs the log
  1351. 59:13out now let's use my credentials to log
  1352. 59:17in back I'm going to leave this drop
  1353. 59:19down at the moment because this is dummy
  1354. 59:21and when we Implement cart we're going
  1355. 59:22to modify this as well but if we check
  1356. 59:25this Nar component examples we have a
  1357. 59:28bunch of other examples we have
  1358. 59:29additional icons we can put we have this
  1359. 59:31drop- down menu items we can put right
  1360. 59:35here and we have the different
  1361. 59:37variations as well so just feel free to
  1362. 59:40configure the nabar as you want you may
  1363. 59:42be want to put this search field inside
  1364. 59:45the now bar so just have a look
  1365. 59:47understand how you can grab the search
  1366. 59:49and put this inside the project so in my
  1367. 59:52case what I want to do is change the uh
  1368. 59:57welcome page as well so I don't want
  1369. 59:58this welcome page I want a nice Navar
  1370. 1:00:01the same type of Navar and maybe a hero
  1371. 1:00:04section as well so now let's do
  1372. 1:00:07additional
  1373. 1:00:09work if we open roads file web.php we're
  1374. 1:00:13going to see that we are rendering this
  1375. 1:00:14welcome page on this slash
  1376. 1:00:18okay so this is something I want to
  1377. 1:00:23change first let me open this welcome
  1378. 1:00:26and scroll down below it has a lot of
  1379. 1:00:28HTML because it has SVG content right
  1380. 1:00:31there and this is something let's clear
  1381. 1:00:35it up
  1382. 1:00:37completely okay remove this save we can
  1383. 1:00:40remove this image as
  1384. 1:00:42well save that and this is now our
  1385. 1:00:45welcome page and I want the welcome page
  1386. 1:00:47to use authenticated layout as well so
  1387. 1:00:50and just like this uh it autocompletes
  1388. 1:00:53this authenticated layout correctly so
  1389. 1:00:56without the change I made right here it
  1390. 1:01:00would not autocomplete this
  1391. 1:01:02authenticated layout it would outut
  1392. 1:01:04complete this as
  1393. 1:01:06authenticated okay nice so we have this
  1394. 1:01:08authenticated layout we can check this
  1395. 1:01:10in the browser already we see this is so
  1396. 1:01:13far so good and this is the homepage
  1397. 1:01:16which we will Implement in the future to
  1398. 1:01:20just display the products and everything
  1399. 1:01:22but for now let's put a dummy hero
  1400. 1:01:25section
  1401. 1:01:27there this is the hero section I'm going
  1402. 1:01:29to copy this I'm going
  1403. 1:01:34to we have this PG gray we probably
  1404. 1:01:37don't need this PG gray or maybe we need
  1405. 1:01:40a div a wrapper for everything but we
  1406. 1:01:44probably don't need
  1407. 1:01:45this or maybe even we don't need this de
  1408. 1:01:48so I'm going to just delete if I need I
  1409. 1:01:50will add this back so here is my um hero
  1410. 1:01:53section which has minimum height of
  1411. 1:01:56screen which is something I want to
  1412. 1:01:57change and let's give it eight of like
  1413. 1:02:00300
  1414. 1:02:02pixel uh and let's give it also BG gray
  1415. 1:02:07200 we save this and have a look okay
  1416. 1:02:11this looks not bad so this is our
  1417. 1:02:14homepage and whenever I am not
  1418. 1:02:18authenticated if we go on
  1419. 1:02:22homepage now I still see this user drop
  1420. 1:02:24down which is something I want to to
  1421. 1:02:26change obviously right now I am not
  1422. 1:02:27authenticated so I cannot actually
  1423. 1:02:29access the profile page right so let's
  1424. 1:02:32go into navbar
  1425. 1:02:35and so we need the user information
  1426. 1:02:37right here so for this we're going to
  1427. 1:02:39access props
  1428. 1:02:41const uh actually props equals use page
  1429. 1:02:46use
  1430. 1:02:48page. props so now I want to destructure
  1431. 1:02:52those props and take out out from it
  1432. 1:02:55because the props if we just uh hit on
  1433. 1:02:59control or Mouse over we're going to see
  1434. 1:03:01that uh it is actually instance of page
  1435. 1:03:04props and if we click control and click
  1436. 1:03:07on this we can actually open that this
  1437. 1:03:11this is coming from this types do um DTS
  1438. 1:03:15from the core but it is using this page
  1439. 1:03:18props but we redefine the page props and
  1440. 1:03:21now uh typescript knows that our page
  1441. 1:03:25props has out inside there okay if we
  1442. 1:03:29check again inside types Global this is
  1443. 1:03:32the page props which we redefined and
  1444. 1:03:34now the page props which is inertia JS
  1445. 1:03:37core page props it extends the inertia
  1446. 1:03:40page props as well as our page props and
  1447. 1:03:43our page props has this out inside there
  1448. 1:03:46so right here we can access this out and
  1449. 1:03:49we can take the user information from
  1450. 1:03:51this we can even destructure this out
  1451. 1:03:53and get the user in the following way
  1452. 1:03:57out now we're going to use that user
  1453. 1:04:00variable down below when we have this
  1454. 1:04:03drop down for the user so this is the
  1455. 1:04:05drop- down for the user so let's take
  1456. 1:04:08this out if the user exists then we
  1457. 1:04:11render the drop down if the user does
  1458. 1:04:14not
  1459. 1:04:15exist then we are going to render two
  1460. 1:04:18buttons one for login second for sign up
  1461. 1:04:21so let's use fragment
  1462. 1:04:23here and inside the fragment we're going
  1463. 1:04:25to we're going to put two uh
  1464. 1:04:28links so this is going to be for login
  1465. 1:04:33rout oops uh not log out but
  1466. 1:04:39login and let's give it also classes
  1467. 1:04:42this is going to be BTN class and
  1468. 1:04:46duplicate this and the second class uh
  1469. 1:04:49second button we have BTN
  1470. 1:04:52primary BTN primary and we can give it
  1471. 1:04:54also text
  1472. 1:04:56um register or sign
  1473. 1:05:00up
  1474. 1:05:01register so now we format this we can
  1475. 1:05:04move this text down and have a look so
  1476. 1:05:09we see this login register however we
  1477. 1:05:11need some
  1478. 1:05:14space between these links we can do the
  1479. 1:05:17following so we can create div and give
  1480. 1:05:19it a display flex and GAP so that we
  1481. 1:05:23create space between login and register
  1482. 1:05:25or I think we need space between all
  1483. 1:05:27these three uh elements so this has a
  1484. 1:05:31flex none and let's give it g four we
  1485. 1:05:35save that and now we have this space
  1486. 1:05:37between the sections login
  1487. 1:05:41register this is dummy we can leave this
  1488. 1:05:44at the moment so I think this looks good
  1489. 1:05:46one last thing I want to do is to
  1490. 1:05:49include the Navar as well for the login
  1491. 1:05:52and register pages so let's open open
  1492. 1:05:56login TSX it uses guest layout at the
  1493. 1:05:59top instead of authenticated layout and
  1494. 1:06:02this is what we are going to change
  1495. 1:06:04authenticated
  1496. 1:06:05layout and we can see now login page
  1497. 1:06:08gets really ugly no problem we're going
  1498. 1:06:10to fix that let's open
  1499. 1:06:14register and change this into
  1500. 1:06:16authenticated layout
  1501. 1:06:19again this looks ugly as well now let's
  1502. 1:06:22open login
  1503. 1:06:23TX uh actually let's
  1504. 1:06:27check uh guest
  1505. 1:06:30layout and here we are using the Lo um
  1506. 1:06:35logo which is actually lost and we we
  1507. 1:06:38are okay with that we don't want this
  1508. 1:06:39logo but we have this um card type CSS
  1509. 1:06:44classes into the GU layout now we're
  1510. 1:06:46going to put this inside login so I'm
  1511. 1:06:48going to wrap
  1512. 1:06:50everything into card let's give it B G
  1513. 1:06:56white and give it also Shadow
  1514. 1:07:01probably and then we have card body not
  1515. 1:07:05card body but card
  1516. 1:07:07body and paste
  1517. 1:07:10everything and we're going to give some
  1518. 1:07:13classes like Max width
  1519. 1:07:16of um 4 20 pixel something like this and
  1520. 1:07:21margin X Auto as well so we're going to
  1521. 1:07:25SA save this and now we see the button
  1522. 1:07:27in the center additionally we can wrap
  1523. 1:07:30it into another div and give this
  1524. 1:07:34div
  1525. 1:07:35pading uh pading four let's give it
  1526. 1:07:38pading
  1527. 1:07:39four now this is the login page or maybe
  1528. 1:07:42four is small we give it piling eight
  1529. 1:07:45now this is awesome register is still
  1530. 1:07:47ugly we're going to open register
  1531. 1:07:50T6 and we're going to wrap it let me
  1532. 1:07:53actually copy
  1533. 1:07:56uh the following three Dives past here
  1534. 1:08:00and now we're going to create ending of
  1535. 1:08:02each div closing text now we format the
  1536. 1:08:07code
  1537. 1:08:09and that's nice and just like this we
  1538. 1:08:11have now login and register Pages which
  1539. 1:08:16um has this header as
  1540. 1:08:20well
  1541. 1:08:22awesome now again we can open the
  1542. 1:08:25kitbash and I'm going to give it corre
  1543. 1:08:27correct message create and use new
  1544. 1:08:32navbar using
  1545. 1:08:34Daisy UI I might not include all the
  1546. 1:08:39comment messages in the video so if you
  1547. 1:08:41find something um while watching this in
  1548. 1:08:44the next sections that I didn't mention
  1549. 1:08:47the comment in the video just to know
  1550. 1:08:49about this so right now we see all the
  1551. 1:08:51new files are the new files are green
  1552. 1:08:54modified files are blue we can see the
  1553. 1:08:56changes right here as well as soon as I
  1554. 1:08:58comment this those changes are actually
  1555. 1:09:01gone and you might notice that I have
  1556. 1:09:03the changes and then the next section
  1557. 1:09:05starts without changes and that's
  1558. 1:09:07because I simply did not include the
  1559. 1:09:09comment message in the video itself now
  1560. 1:09:13I want to start working on roles and
  1561. 1:09:15permissions and for this I'm going to
  1562. 1:09:17use Spa Lal permission package and we're
  1563. 1:09:21going to also browse the documentation
  1564. 1:09:23in certain things to understand um to
  1565. 1:09:26give you information where you can find
  1566. 1:09:28these or that things the permission
  1567. 1:09:30package actually supports roles and
  1568. 1:09:32permissions and users are supposed to be
  1569. 1:09:35assigned roles but also you can assign
  1570. 1:09:37permissions to users and the roles
  1571. 1:09:40should have permissions okay now let's
  1572. 1:09:43install this package and I'm going to
  1573. 1:09:44also uh step by step U give you the
  1574. 1:09:46information so first we have to execute
  1575. 1:09:49the following composer comment let's
  1576. 1:09:50bring up the terminal inside Artisan
  1577. 1:09:52terminal and I'm going to execute
  1578. 1:09:54composer requires but LEL permission uh
  1579. 1:09:57this is something we don't need um this
  1580. 1:09:59is also
  1581. 1:10:00optional no this is not optional we
  1582. 1:10:03should publish the migration uh as well
  1583. 1:10:05as the config file so I'm going to copy
  1584. 1:10:08this and I'm going to paste this here
  1585. 1:10:10we're going to hit the enter and we see
  1586. 1:10:14that the permission file was
  1587. 1:10:20copied actually this was done and then
  1588. 1:10:24this was done
  1589. 1:10:25so two files we say done two times so
  1590. 1:10:28two files we are copied one for config
  1591. 1:10:30second for migration and we will
  1592. 1:10:33obviously need to execute migrate but
  1593. 1:10:35let's have a look before running
  1594. 1:10:37migrations this is not something for us
  1595. 1:10:42so we're going to skip that
  1596. 1:10:45section yeah we probably need to clear
  1597. 1:10:47the config cache let's execute
  1598. 1:10:51this and we execute PHP Artisan config
  1599. 1:10:54clear as
  1600. 1:10:56well in next we can execute PHP Artis
  1601. 1:10:59and my crate it created roles and
  1602. 1:11:02permissions and now it's time to check
  1603. 1:11:05the database and for this I'm going to
  1604. 1:11:07use phb storms built-in database tool
  1605. 1:11:10here we have this databas site file we
  1606. 1:11:12are using sqlite we're going to double
  1607. 1:11:14click on
  1608. 1:11:16this and this brings up the data sources
  1609. 1:11:19in driver's window and I'm going to
  1610. 1:11:21click on okay and on the right side now
  1611. 1:11:24we have
  1612. 1:11:25the database we can have multiple
  1613. 1:11:28databases in a project that's possible
  1614. 1:11:30uh in PHP sh and this supports actually
  1615. 1:11:33a lot of many common databases um a lot
  1616. 1:11:36of so we can expand this and we're going
  1617. 1:11:39to see the tables here and so the tables
  1618. 1:11:44that was created because of these Lal
  1619. 1:11:47spotty uh permissions package is model
  1620. 1:11:50has permissions model has roles roles
  1621. 1:11:55permissions and Ro has permissions and
  1622. 1:11:58we can also check this inside migrations
  1623. 1:12:01open the permissions and we
  1624. 1:12:03see we see create table for permissions
  1625. 1:12:07create table for roles create table for
  1626. 1:12:10model has
  1627. 1:12:11permissions um model has
  1628. 1:12:13roles and R has permissions and that's
  1629. 1:12:17it so the tables we are created and now
  1630. 1:12:22we're going to Define roles and
  1631. 1:12:24permissions in the database or only
  1632. 1:12:26rules depending on our use case so one
  1633. 1:12:28thing what we need to do for sure is
  1634. 1:12:30that we're going to update the user and
  1635. 1:12:32include the following trait inside the
  1636. 1:12:35user mode so let's open user.php
  1637. 1:12:40and has roles trait we need to include
  1638. 1:12:46that next I think there is not much we
  1639. 1:12:49need to actually do uh and now I'm going
  1640. 1:12:53to create anms for roles and
  1641. 1:12:57permissions U I'm going to execute
  1642. 1:12:59Artisan command to create new class but
  1643. 1:13:01actually I'm going to show also this
  1644. 1:13:03double control so in PHP storm I use
  1645. 1:13:06this quite often I just started using it
  1646. 1:13:09recently so double control click on
  1647. 1:13:11control two times it's going to open
  1648. 1:13:13this run anything and right here we can
  1649. 1:13:16execute Artis and commments as well like
  1650. 1:13:18PHP artisan make class and we're going
  1651. 1:13:23to call this um
  1652. 1:13:25rolls rolls enam for example and we're
  1653. 1:13:29going to hit the enter the class was
  1654. 1:13:32created again double control PHP artisan
  1655. 1:13:36make class and the second we're going to
  1656. 1:13:38create is
  1657. 1:13:40permissions enam we're going to hit the
  1658. 1:13:43enter that was also created now I'm
  1659. 1:13:45going to hit double shift let's open
  1660. 1:13:47rolls enam double shift again
  1661. 1:13:51and
  1662. 1:13:53permissions enm
  1663. 1:13:55both of them are actually open they are
  1664. 1:13:57classes because we executed a make class
  1665. 1:13:59I think we can execute make enm as well
  1666. 1:14:03can we make in um permissions in um two
  1667. 1:14:09for example yeah that also works why I
  1668. 1:14:11executed make class I don't know okay we
  1669. 1:14:14open this app folder and those uh
  1670. 1:14:17classes actually let's remove this make
  1671. 1:14:19nm2 and we're going to change them from
  1672. 1:14:22class into NM here
  1673. 1:14:25and enm here and we obviously don't need
  1674. 1:14:28this Constructor because these are
  1675. 1:14:32enms okay now let's define the type of
  1676. 1:14:36this enm permissions enm actually I'm
  1677. 1:14:38thinking that I I just want to give you
  1678. 1:14:41the information how you can set up the
  1679. 1:14:43permissions and roles and connect them
  1680. 1:14:44to each other but in our case I think
  1681. 1:14:47that we are not going to use permissions
  1682. 1:14:49we are only going to use roles and we're
  1683. 1:14:52going to have three main roles in our
  1684. 1:14:54project
  1685. 1:14:55and let's define them um and this is
  1686. 1:14:58cool part so this is now PHP
  1687. 1:15:01storms full line autoc completion which
  1688. 1:15:04is quite intelligent and we're going to
  1689. 1:15:06see this in action uh right now and in
  1690. 1:15:09in the next sections as well case
  1691. 1:15:13administrator case user and we need
  1692. 1:15:16another case which is going to be
  1693. 1:15:20vendor okay now uh I want to change this
  1694. 1:15:24into admin
  1695. 1:15:26case
  1696. 1:15:28admin okay
  1697. 1:15:30cool as for the permissions we can
  1698. 1:15:33create um small permissions for each row
  1699. 1:15:37for example uh the regular user can
  1700. 1:15:41browse the products can add the product
  1701. 1:15:43into the cart can buy the products and
  1702. 1:15:47can uh login can register and so on so
  1703. 1:15:53you should Define for your specific
  1704. 1:15:55project what type of uh these
  1705. 1:15:59permissions you need like byproducts
  1706. 1:16:01browse products um Edge into the cart
  1707. 1:16:04and so on okay so in our case I'm going
  1708. 1:16:08to just use
  1709. 1:16:09rols uh
  1710. 1:16:11and I'm not going to Define any kind of
  1711. 1:16:14specific permissions but I I will show
  1712. 1:16:16you how you can use these permissions as
  1713. 1:16:19well
  1714. 1:16:20okay so then uh the admin user can
  1715. 1:16:24actually do everything it can do what
  1716. 1:16:27the vendor user is doing so we're going
  1717. 1:16:28to have we in your project you're going
  1718. 1:16:31to define those permissions like manage
  1719. 1:16:34um manage vendor vendors for example
  1720. 1:16:38which is only relevant for the
  1721. 1:16:40permissions actually let's let's do the
  1722. 1:16:43following so I'm going to Define uh
  1723. 1:16:45three permissions one corresponds to
  1724. 1:16:48each uh role
  1725. 1:16:51okay and these permissions will be
  1726. 1:16:56um okay
  1727. 1:16:58case I'm thinking right now so approve
  1728. 1:17:05vendors let's say as an example is uh
  1729. 1:17:09buy products which is common for uh user
  1730. 1:17:14and another one sell products which is
  1731. 1:17:17for vendor okay so three roles three
  1732. 1:17:20permissions as I mentioned in more
  1733. 1:17:23complex applications you probably need
  1734. 1:17:25more permissions and you can associate
  1735. 1:17:27more permissions to the roles now we
  1736. 1:17:31have roles we have permissions and I
  1737. 1:17:33want to open the database
  1738. 1:17:36Cedar and I want to um seed some the
  1739. 1:17:41these roles and permissions into the
  1740. 1:17:44database okay or we can actually
  1741. 1:17:48even um create a separate Cedar class
  1742. 1:17:52for this this is also possible we can
  1743. 1:17:53execute uh PHP artisan make Cedar now
  1744. 1:17:57rolls Cedar roll Cedar and then we can
  1745. 1:17:59use that roll Cedar in our project so in
  1746. 1:18:02my case I'm going to put this right here
  1747. 1:18:05um we might also need to
  1748. 1:18:10create uh users and roles as well okay
  1749. 1:18:14let's create now two see there PHP
  1750. 1:18:16artisan
  1751. 1:18:18make Cedar uh one is going to be roll
  1752. 1:18:23Cedar
  1753. 1:18:25and second is going to be user
  1754. 1:18:29Ceder user
  1755. 1:18:32Cedar okay so both seeders we are
  1756. 1:18:37created now right here we don't need
  1757. 1:18:40anything so and I'm going to call uh the
  1758. 1:18:43method call here we're going to pass an
  1759. 1:18:46array first we're going to execute R
  1760. 1:18:49Ceder and then we're going to execute
  1761. 1:18:51user Ceder and as you see the out
  1762. 1:18:53completion helps a lot so inside R here
  1763. 1:18:57we need to define those roles and we
  1764. 1:19:00need to associate permissions to these
  1765. 1:19:03roles now let's use this user Ro equals
  1766. 1:19:09Ro reate and we're going to provide here
  1767. 1:19:13name of the role to
  1768. 1:19:16be uh roles enam
  1769. 1:19:20user value okay we are going to import
  1770. 1:19:25that roll from spoty permission models
  1771. 1:19:28roll okay now let's duplicate these two
  1772. 1:19:30more times next one is going to be
  1773. 1:19:33vendor Ro here we're going to use
  1774. 1:19:37vendor and the last one is going to be
  1775. 1:19:41admin rooll and here we are going to use
  1776. 1:19:45admin now we have all these three roles
  1777. 1:19:47now let's define three permissions as
  1778. 1:19:49well uh one is let's check the
  1779. 1:19:52permissions andm one is approv vendors
  1780. 1:19:55approve
  1781. 1:19:58vendors is going to be
  1782. 1:20:02permission spoty permission models okay
  1783. 1:20:05permission create and inside the name
  1784. 1:20:08we're going to
  1785. 1:20:09use
  1786. 1:20:11permissions enam aove
  1787. 1:20:14vendors not name but
  1788. 1:20:18value okay we're going to dup oh let's
  1789. 1:20:20move this down so that everything is
  1790. 1:20:22visible nicely visible okay let's
  1791. 1:20:24duplicate these two times and this is
  1792. 1:20:27going to be sell products sell
  1793. 1:20:33products right here we're going to use
  1794. 1:20:35sell products and the last one is going
  1795. 1:20:38to be buy
  1796. 1:20:41products buy products and here we need
  1797. 1:20:46buy products as well now we have three
  1798. 1:20:48roles three permissions and we're going
  1799. 1:20:50to synchronize no permissions to those
  1800. 1:20:53roles okay so on the user role we're
  1801. 1:20:56going to call sync permissions and we're
  1802. 1:21:00going to provide array of permissions
  1803. 1:21:02right here so if you defined multiple
  1804. 1:21:05permissions for each role if you have
  1805. 1:21:08multiple permissions here and Define
  1806. 1:21:10multiple permissions for each role
  1807. 1:21:12you're going to synchronize all of them
  1808. 1:21:13into the user Ro at the moment we have
  1809. 1:21:15only one permission for user role and
  1810. 1:21:18that's byproduct so we're going to
  1811. 1:21:20provide byproducts here and we can put
  1812. 1:21:22this probably on single line
  1813. 1:21:25now we need to do something similar for
  1814. 1:21:28vendor roll sync permissions and we're
  1815. 1:21:32going to provide sell products as well
  1816. 1:21:34as buy products so vendor users can
  1817. 1:21:36actually buy products not their own
  1818. 1:21:39products but somebody else's
  1819. 1:21:41products and admin role can sell
  1820. 1:21:44products buy products and also approve
  1821. 1:21:50vendors okay let's make sure that this
  1822. 1:21:53is visible
  1823. 1:21:56now we have three roles we have three
  1824. 1:21:58permissions and we Associated
  1825. 1:22:00permissions to these roles and again if
  1826. 1:22:02you have multiple permissions um 20 30
  1827. 1:22:06whatever permissions you need to
  1828. 1:22:07associate them to the roles and the main
  1829. 1:22:10thing is that now user needs to have
  1830. 1:22:13roles and for this let's
  1831. 1:22:16open user Ceder and we're going to
  1832. 1:22:19create now three users here
  1833. 1:22:24let's use
  1834. 1:22:26user uh
  1835. 1:22:28user Factory create and we're going to
  1836. 1:22:32provide name to be
  1837. 1:22:37user email to be user at
  1838. 1:22:41example example.com
  1839. 1:22:45and the password can be the default one
  1840. 1:22:47which is inside the user Factory let's
  1841. 1:22:49open user Factory as well and have a
  1842. 1:22:52look so the default password is going to
  1843. 1:22:54be just password and we can leave this
  1844. 1:22:57and we created that user let's import
  1845. 1:22:59this user model app models user and
  1846. 1:23:02finally when the user is created we're
  1847. 1:23:04going to assign role to it and the role
  1848. 1:23:07is going to be user role but we're going
  1849. 1:23:09to use rolls
  1850. 1:23:12enam rolls
  1851. 1:23:15enam
  1852. 1:23:17um user value okay and let's now
  1853. 1:23:22duplicate these two more times and this
  1854. 1:23:24is going to be
  1855. 1:23:28vendor uh let's keep it first name and
  1856. 1:23:30last name like vendor whatever vendor
  1857. 1:23:34vendor okay let it be just vendor so
  1858. 1:23:37vendor example.com and that should have
  1859. 1:23:40vendor roll let's create one empty line
  1860. 1:23:44and the last one is going to be
  1861. 1:23:47admin admin example.com and the role
  1862. 1:23:50assigned to it is going to be admin
  1863. 1:23:52rooll okay one one additional thing I
  1864. 1:23:55want to show to you is that we created
  1865. 1:23:57those enms inside app folder directly
  1866. 1:24:01but I actually want to move them into
  1867. 1:24:03the enm folder and this is something I
  1868. 1:24:05did on
  1869. 1:24:06purpose so I'm going to create now enm
  1870. 1:24:10folder or
  1871. 1:24:11enams and now pay attention so we are
  1872. 1:24:14using these um enams already in couple
  1873. 1:24:16of places so for example here in the
  1874. 1:24:20user um user Cedar we are using
  1875. 1:24:26rolls Anam where is the import here we
  1876. 1:24:29see this rolls Anam and we also have the
  1877. 1:24:33permissions enam right here now I'm
  1878. 1:24:36going to move those enms into anms
  1879. 1:24:39folder and click on refactor and the
  1880. 1:24:42refactoring will basically change the
  1881. 1:24:45usage of that as well now we see that
  1882. 1:24:47rolls enam now is coming from anam's
  1883. 1:24:50folder and permissions enm is also
  1884. 1:24:52coming from anam's folder in in stead
  1885. 1:24:55of instead of the app folder
  1886. 1:24:59directly and this is pretty cool now we
  1887. 1:25:02Define the um M the the cedar classes
  1888. 1:25:06and I think we can execute PHP Artisan
  1889. 1:25:08migrate again I'm going to double click
  1890. 1:25:11on control PHP Artisan migrate you can
  1891. 1:25:16open the terminal if you don't follow
  1892. 1:25:18with PHP store hit the
  1893. 1:25:20enter nothing to migrate that's correct
  1894. 1:25:23we're going to execute actually PHP AR
  1895. 1:25:25migrate
  1896. 1:25:27fresh- D seed we're going to hit the
  1897. 1:25:31enter okay everything was completed and
  1898. 1:25:34now let's check so inside users we see
  1899. 1:25:38three users inside roles we see three
  1900. 1:25:41roles inside permissions we see three
  1901. 1:25:43permissions and we also have Ro has
  1902. 1:25:46permissions and we have these defined
  1903. 1:25:48here okay so totally there are six
  1904. 1:25:52records and that's because if we check
  1905. 1:25:54roles right now admin user has three
  1906. 1:25:57roles vendor has two roles and user has
  1907. 1:26:00one Ro totally six records and we also
  1908. 1:26:03have model has roles which is the
  1909. 1:26:06polymorphic table Ro ID the model type
  1910. 1:26:09and the model ID each user has one role
  1911. 1:26:12Associated to
  1912. 1:26:14it inside model has permissions we don't
  1913. 1:26:17have anything because we did not
  1914. 1:26:19explicitly associate user any
  1915. 1:26:22permissions user has roles r has has
  1916. 1:26:25permissions and the user has permissions
  1917. 1:26:27as well and just like this we Define
  1918. 1:26:30roles permissions uh created the correct
  1919. 1:26:32Cedar class and we probably need to
  1920. 1:26:35create comment message
  1921. 1:26:37here install
  1922. 1:26:40spy permissions package and Define roles
  1923. 1:26:45and
  1924. 1:26:48permissions uh again if you're doing
  1925. 1:26:50something on production you should
  1926. 1:26:51probably make a review uh something
  1927. 1:26:55which if you working on an application
  1928. 1:26:58um real application uh for a production
  1929. 1:27:01cool let's close now everything now I'm
  1930. 1:27:04going to install filament PHP and have
  1931. 1:27:07this admin panel admin area for admin
  1932. 1:27:11users as well as for the vendor users
  1933. 1:27:14now I'm going to open filament docs and
  1934. 1:27:17I think I'm going to use the this quite
  1935. 1:27:19a
  1936. 1:27:22lot click on get
  1937. 1:27:25started here and the installation
  1938. 1:27:28instructions the following however I'm
  1939. 1:27:30not going to uh require this specific
  1940. 1:27:32version I'm just going to require
  1941. 1:27:34filament filament just like this because
  1942. 1:27:37I had some issues previously when
  1943. 1:27:39requiring that
  1944. 1:27:413 um two version okay so let's execute
  1945. 1:27:45composer require filament filament after
  1946. 1:27:48which we're going to create install
  1947. 1:27:51panels so let me copy the following
  1948. 1:27:53commment the installation was done now
  1949. 1:27:55we're going to um execute filament
  1950. 1:27:58install D- panels and here we have to
  1951. 1:28:01provide the ID for the panel and we can
  1952. 1:28:04leave this the default one which is
  1953. 1:28:05admin I'm going to hit the
  1954. 1:28:07enter and right now I'm just going type
  1955. 1:28:11no okay so the provider was created if
  1956. 1:28:15we check
  1957. 1:28:16up providers filament we see this admin
  1958. 1:28:20panel provider and now we should be able
  1959. 1:28:23to
  1960. 1:28:24access the URL so on admin URL we see
  1961. 1:28:29this filament admin page however we
  1962. 1:28:31haven't created the filament user we're
  1963. 1:28:33going to execute the following command
  1964. 1:28:35let's bring up the terminal paste hit
  1965. 1:28:38the enter and we have to provide the
  1966. 1:28:39name so we actually already have admin
  1967. 1:28:42user right so do we need to create new
  1968. 1:28:44user I think no so I'm just going to
  1969. 1:28:47cancel this and try to authenticate with
  1970. 1:28:51admin at example.com click on sign in
  1971. 1:28:55and I was able to log in so I don't need
  1972. 1:28:57to execute the following um command and
  1973. 1:29:00right now the thing is that I am able to
  1974. 1:29:04access to this panel with every user
  1975. 1:29:07even the user role is able to access
  1976. 1:29:10this because we don't have that type of
  1977. 1:29:13restriction but obviously user role
  1978. 1:29:16users should not be able to access to
  1979. 1:29:19this panel for this we need to use the
  1980. 1:29:22correct middle We R all middle we from
  1981. 1:29:25the spa permission package so if we
  1982. 1:29:28check the documentation again we're
  1983. 1:29:30going to find this middle wear section
  1984. 1:29:33and if we scroll down below we see U how
  1985. 1:29:36we can add these middle we or what
  1986. 1:29:38middle we there exist so K is basically
  1987. 1:29:42for permissions however we want middle
  1988. 1:29:45wear which refers to roles so if we
  1989. 1:29:47scroll down below uh yeah this is also
  1990. 1:29:50the case where we can Define the uh
  1991. 1:29:53middle we alas is and this is what I'm
  1992. 1:29:55going to do so I'm just going to copy
  1993. 1:29:58this and go into my
  1994. 1:30:03bootstrap up PHP and this is where uh
  1995. 1:30:08inside with middle we I'm going to paste
  1996. 1:30:11this code so I defined the following
  1997. 1:30:13aliases for the roll middle wear
  1998. 1:30:16permission middle wear and roll or
  1999. 1:30:18permission middle middle wear and now if
  2000. 1:30:21we check how we can use this roll middle
  2001. 1:30:23wear is the following so role manager
  2002. 1:30:27and if we want we can specify the guard
  2003. 1:30:31here as well or we can also provide
  2004. 1:30:34multiple roles with pipe so in this case
  2005. 1:30:38this means that uh the following group
  2006. 1:30:41applies to the role for manager or for
  2007. 1:30:45writer now let's open just created admin
  2008. 1:30:50panel provider and if we scroll down
  2009. 1:30:52below here we have this middle wheel
  2010. 1:30:54so also accessing to
  2011. 1:30:59um accessing to admin panel
  2012. 1:31:03provider yeah it it is only for
  2013. 1:31:06authenticated users right so we don't
  2014. 1:31:08need to do any additional out
  2015. 1:31:11here we only need to use roll middle
  2016. 1:31:15wear so for this I'm going to use Sprint
  2017. 1:31:18Sprint function and I'm going to use
  2018. 1:31:21roll colum and then we need uh two roles
  2019. 1:31:26actually one for admin second for vendor
  2020. 1:31:30so let me use this percent s then pipe
  2021. 1:31:34and another percent s and we have to
  2022. 1:31:38provide those two roles here roll uh
  2023. 1:31:43roles in
  2024. 1:31:45um
  2025. 1:31:47admin value and duplicate this and rolls
  2026. 1:31:52enam vendor value value so only admin
  2027. 1:31:56and vendor users will be able to access
  2028. 1:31:58to this admin panel provider and if we
  2029. 1:32:01right
  2030. 1:32:09now yeah we need out as
  2031. 1:32:12well we access the
  2032. 1:32:14homepage user is not authenticated click
  2033. 1:32:17on admin user is not logged
  2034. 1:32:21in let's provide out that is is also
  2035. 1:32:24necessary probably
  2036. 1:32:27here okay it requires authentication and
  2037. 1:32:31I added this out because I don't want to
  2038. 1:32:33access this adamine basically without
  2039. 1:32:37authentication so I'm going to use the
  2040. 1:32:39following login form this login form but
  2041. 1:32:42whenever the login is done in our case
  2042. 1:32:46let's try to log in with the user then
  2043. 1:32:49the user uh will not be able to actually
  2044. 1:32:51access to the admin now user is
  2045. 1:32:55authenticated but user is not able to
  2046. 1:32:59access admin that's correct however if
  2047. 1:33:03admin user will sign up admin at
  2048. 1:33:06example.com click on
  2049. 1:33:09login then access on admin this is
  2050. 1:33:13possible and also
  2051. 1:33:16if also if a
  2052. 1:33:19vendor vendor user will log in
  2053. 1:33:28uh what
  2054. 1:33:30happened password the enter okay and now
  2055. 1:33:33try to access to admin vendor user is
  2056. 1:33:36also able to access the admin area okay
  2057. 1:33:39only user is not able and based on who
  2058. 1:33:43who is authenticated right now I'm going
  2059. 1:33:45to also implement the way to redirect
  2060. 1:33:48user into the correct um correct Road so
  2061. 1:33:54for this let's
  2062. 1:33:56open
  2063. 1:33:58authenticated session controller which
  2064. 1:34:01is the controller inside which we
  2065. 1:34:04Implement user
  2066. 1:34:07login okay after the authenticate
  2067. 1:34:10happens and the session regenerate
  2068. 1:34:12happens let's grab user from out user
  2069. 1:34:16and we can also add this annotation that
  2070. 1:34:18the user is an instance of user model so
  2071. 1:34:21that uh PHP storm giv gives us the cool
  2072. 1:34:25a completion so if user um and I'm going
  2073. 1:34:29to use now has any role and I want to
  2074. 1:34:33provide two roles here if user has any
  2075. 1:34:36role and let's now use roles
  2076. 1:34:39inam
  2077. 1:34:42admin uh actually I think we don't need
  2078. 1:34:45to provide the value so if user has any
  2079. 1:34:49role admin
  2080. 1:34:51and roles and um
  2081. 1:34:56rolls and um
  2082. 1:34:58vendor then we need to redirect user
  2083. 1:35:01into the filament admin Pages dashboard
  2084. 1:35:06okay so we need to know what is the root
  2085. 1:35:09name for um for filament or we can use
  2086. 1:35:14the uh root URL as well so let me tell
  2087. 1:35:18you what I mean so first I'm going to
  2088. 1:35:19use
  2089. 1:35:20inertia location because I want to
  2090. 1:35:23redirect outside of the inertia um page
  2091. 1:35:29okay and then inside the location I can
  2092. 1:35:31provide just admin like this and it's
  2093. 1:35:34going to work okay let let me leave this
  2094. 1:35:36right now and I'm going to come back to
  2095. 1:35:38this and if the user else if the user
  2096. 1:35:43has
  2097. 1:35:44role regular user role then we need to
  2098. 1:35:49do something else okay uh let me Define
  2099. 1:35:53right now now Ro equals
  2100. 1:35:56slash and if the regular user is trying
  2101. 1:36:00to authenticate then I'm going to change
  2102. 1:36:02the root to be let me use
  2103. 1:36:07root root dashboard and I'm going to
  2104. 1:36:12provide uh also
  2105. 1:36:14absolute true
  2106. 1:36:17here and finally we are going to change
  2107. 1:36:22the following part
  2108. 1:36:25uh actually I need absolute false
  2109. 1:36:27because default one is absolute true and
  2110. 1:36:29then I'm going to provide this route
  2111. 1:36:32here so if the authenticated user is
  2112. 1:36:35either admin or vendor we're going to
  2113. 1:36:37redirect into admin location um if the
  2114. 1:36:40user is then regular user we can use
  2115. 1:36:43just else as well in this case so then
  2116. 1:36:46we're going to redirect into dashboard
  2117. 1:36:49okay so if I save this right now and
  2118. 1:36:52click on log out
  2119. 1:36:55then let me try to authenticate as
  2120. 1:37:00admin okay return value must be typed
  2121. 1:37:03okay so I need to change
  2122. 1:37:06this
  2123. 1:37:07uh re redirect response this is not
  2124. 1:37:11redirect response anymore it is
  2125. 1:37:18actually so we are going to use both
  2126. 1:37:25okay let's see if that
  2127. 1:37:32works uh is the user authenticated
  2128. 1:37:36now yeah the user is authenticated let's
  2129. 1:37:38log out click on
  2130. 1:37:41login uh I'm going to use
  2131. 1:37:45admin okay so now I'm redirected into
  2132. 1:37:48the admin page which is exactly what I
  2133. 1:37:50wanted and we can try other two roles as
  2134. 1:37:53well well vendor click on enter redirect
  2135. 1:37:57it into admin and log
  2136. 1:38:01out and
  2137. 1:38:04user enter redirected into something uh
  2138. 1:38:09user doesn't have the right roles so it
  2139. 1:38:12is probably because it still tries to
  2140. 1:38:15access to admin page but this is what
  2141. 1:38:18I'm going to
  2142. 1:38:19do I'm going to log out
  2143. 1:38:25and click on login
  2144. 1:38:28user now we are redirected into
  2145. 1:38:30dashboard which works correctly however
  2146. 1:38:33we don't even want this dashboard page
  2147. 1:38:36so we're going to open web.php and we're
  2148. 1:38:39going to change this uh here so we don't
  2149. 1:38:41need dashboard uh or we can define
  2150. 1:38:45something like this that the dashboard
  2151. 1:38:47is the
  2152. 1:38:49homepage uh I'm going to remove this
  2153. 1:38:52dashboard completely okay so I don't
  2154. 1:38:54need this dashboard uh however the
  2155. 1:38:57dashboard rot name might be used in
  2156. 1:38:59couple of other places so I'm going to
  2157. 1:39:01search for root dashboard that is used
  2158. 1:39:06here um couple of other places so open
  2159. 1:39:11in find
  2160. 1:39:13window let's define um either we have to
  2161. 1:39:16change all the places where the
  2162. 1:39:17dashboard uh Roots name is used and to
  2163. 1:39:21be more specific we're going to search
  2164. 1:39:22for lowercase and words so those are the
  2165. 1:39:25roots names and they are used inside the
  2166. 1:39:27verify email controller and many other
  2167. 1:39:30places so the dashboard is basically the
  2168. 1:39:32homepage right for authenticated users
  2169. 1:39:34only so what I'm going to do right now
  2170. 1:39:36is assign dashboard rout to the
  2171. 1:39:42homepage dashboard just like this and
  2172. 1:39:46now if we go
  2173. 1:39:49back access to login and if I log out
  2174. 1:39:54then if I try to log in as a regular
  2175. 1:39:56user the user will be redirected back to
  2176. 1:39:59the
  2177. 1:40:01homepage now instead of having this
  2178. 1:40:03hardcoded admin route right here this is
  2179. 1:40:06something we can also change and let me
  2180. 1:40:08bring up the terminal and we're going to
  2181. 1:40:11execute PHP Artisan root list and this
  2182. 1:40:15way we're going to see all the Define
  2183. 1:40:17roots and I want to find this admin root
  2184. 1:40:22filament
  2185. 1:40:23admin as you see and it has the
  2186. 1:40:25following root name associated to it
  2187. 1:40:28filament admin Pages dashboard so we can
  2188. 1:40:30copy the following root name and instead
  2189. 1:40:33of hardcoding admin URL here we can use
  2190. 1:40:36root and provide the root name filament
  2191. 1:40:39admin uh Pages dashboard now if we save
  2192. 1:40:43this log
  2193. 1:40:45out try to log in with admin user we
  2194. 1:40:49will be redirected back into the
  2195. 1:40:51dashboard and one last thing just make
  2196. 1:40:54sure everything works correctly I'm
  2197. 1:40:56going to try
  2198. 1:40:58to log in as user and user is is not
  2199. 1:41:02able to access the uh admin this is what
  2200. 1:41:05I wanted to test no this is not for the
  2201. 1:41:09users one last thing I want to do inside
  2202. 1:41:13this admin panel provider is that to
  2203. 1:41:15comment out this out middle we so the
  2204. 1:41:19authenticate uh is the filament
  2205. 1:41:21authenticate which uh basically redirect
  2206. 1:41:23user into the filament login page and if
  2207. 1:41:26you want to have the filament login page
  2208. 1:41:28uh that's also fine and that's also
  2209. 1:41:31possible but in our case I just don't
  2210. 1:41:34want this filament login page let's move
  2211. 1:41:36the semicolon down I'm going to comment
  2212. 1:41:38out this part completely I'm using
  2213. 1:41:40regular out and I'm using regular login
  2214. 1:41:44page even for the filament uh interface
  2215. 1:41:48so the admin and vendors will use this
  2216. 1:41:51login page to access to filament admin
  2217. 1:41:54panel and then based on the roles and
  2218. 1:41:57permissions um not permissions maybe but
  2219. 1:42:00roles we're going to differentiate what
  2220. 1:42:02admin users is going to see and what
  2221. 1:42:04vendor users is going to see or access
  2222. 1:42:07right
  2223. 1:42:08here and now I'm going to make a quick
  2224. 1:42:11comment message I have a look in the
  2225. 1:42:12composer Json filament was installed uh
  2226. 1:42:16do we have anything else here the
  2227. 1:42:18command was added filament upgrade
  2228. 1:42:20command was added into post aoad dump
  2229. 1:42:23that's fine you can make the review
  2230. 1:42:25entire review of this we have new files
  2231. 1:42:27admin panel provider as well as some CSS
  2232. 1:42:30and JavaScript files which is necessary
  2233. 1:42:32for filament and I'm going to include
  2234. 1:42:34all of them right now call this install
  2235. 1:42:39uh filament and create admin
  2236. 1:42:44panel now I'm going to start working on
  2237. 1:42:47displaying departments for admin users
  2238. 1:42:50and managing those departments so the
  2239. 1:42:52idea is that admin users the website
  2240. 1:42:54administrators will Define departments
  2241. 1:42:57and
  2242. 1:42:57categories and those are the Departments
  2243. 1:43:00and categories which is available for
  2244. 1:43:03sales on the website and vendor users
  2245. 1:43:06will use those departments and
  2246. 1:43:09categories to create products from their
  2247. 1:43:12end and just publish them on the website
  2248. 1:43:14so if the department is not defined if
  2249. 1:43:17admin users are not selling special type
  2250. 1:43:20of uh products under the Department then
  2251. 1:43:23the admin users will not be able to
  2252. 1:43:26define the department so uh the the
  2253. 1:43:28vendor users will only be able to sell
  2254. 1:43:31those products which departments are
  2255. 1:43:33already defined by admin users the first
  2256. 1:43:36thing we're going to do is to define the
  2257. 1:43:38department model in
  2258. 1:43:40migration so I'm going to execute PHP
  2259. 1:43:43artisan make model Department DM for
  2260. 1:43:48migration as well the model and the
  2261. 1:43:51migration was created now let's open
  2262. 1:43:53create departments table and we're going
  2263. 1:43:56to define a few Fields uh we need name
  2264. 1:44:00uh we
  2265. 1:44:01need um string slug which actually must
  2266. 1:44:07be unique we
  2267. 1:44:10need uh we need string uh meta title
  2268. 1:44:15which can be null we need meta
  2269. 1:44:17description which can also be null and
  2270. 1:44:20we need table
  2271. 1:44:23Boolean active which by default should
  2272. 1:44:26be
  2273. 1:44:27true okay so we Define those fields and
  2274. 1:44:31now we're going to generate a filament
  2275. 1:44:34resource but before I do this I'm going
  2276. 1:44:37to open providers filament admin panel
  2277. 1:44:40provider and I'm going to unguard all
  2278. 1:44:42the models uh right here so I'm going to
  2279. 1:44:46add here boot
  2280. 1:44:49method
  2281. 1:44:51boot that should should be
  2282. 1:44:55boot okay and I'm going to execute model
  2283. 1:44:59illuminate database eloquent uard so the
  2284. 1:45:03models what I'm going to use in the
  2285. 1:45:06filament uh will be unguarded which
  2286. 1:45:08basically means that uh the if we open
  2287. 1:45:11Department PHP so we don't have anything
  2288. 1:45:15defined in the fiable and generally when
  2289. 1:45:18we load some data into model uh these
  2290. 1:45:22fields
  2291. 1:45:23um should be defined in the failable but
  2292. 1:45:27the
  2293. 1:45:28Ard disables that check basically and it
  2294. 1:45:32is because we are going to only use that
  2295. 1:45:34on the filament side arding model is
  2296. 1:45:37actually a common thing and we can check
  2297. 1:45:39the documentation as well about this uh
  2298. 1:45:42this is mentioned also in the
  2299. 1:45:43documentation um it's not something like
  2300. 1:45:46I came up
  2301. 1:45:49with uh okay now what I'm going to do is
  2302. 1:45:52to generate new
  2303. 1:45:56resource uh okay let's check the getting
  2304. 1:45:58started section uh this is the demo
  2305. 1:46:01project create models everything here's
  2306. 1:46:04the arding example in our um filament
  2307. 1:46:07demo and what we want is to generate now
  2308. 1:46:10department resource so we have the model
  2309. 1:46:13ready we have the table ready we
  2310. 1:46:14probably need to execute migrations PHP
  2311. 1:46:17Artis on
  2312. 1:46:19Migrate okay Department stable was
  2313. 1:46:22created let's clear this up and now
  2314. 1:46:24let's execute actually I think we can
  2315. 1:46:27always use this double Control Paste
  2316. 1:46:29this here PHP artisan make filament
  2317. 1:46:32resource and we're going to call this
  2318. 1:46:36department hit the enter okay Department
  2319. 1:46:39resource was created and now if we check
  2320. 1:46:42the browser we're going to see
  2321. 1:46:44departments right here if we click on
  2322. 1:46:46this we don't see anything if we click
  2323. 1:46:48this new Department we also don't see
  2324. 1:46:51anything and this is something
  2325. 1:46:53we have to take care of and Define
  2326. 1:46:55Fields now let's
  2327. 1:46:58open just created Department resource
  2328. 1:47:02and we're going to find this form area
  2329. 1:47:04and we're going to define a couple of
  2330. 1:47:06fields I'm going to use text input make
  2331. 1:47:09for name uh and I'm going
  2332. 1:47:12to uh it should be
  2333. 1:47:14required and I also uh want to have Slug
  2334. 1:47:18and whenever name is changed I want to
  2335. 1:47:20generate slug from the name so let's
  2336. 1:47:24define slug as well we need comma here
  2337. 1:47:28that should be Slug and we also need to
  2338. 1:47:32Define
  2339. 1:47:36checkbox we need comma here checkbox
  2340. 1:47:40filament forms component checkbox and
  2341. 1:47:43should be active
  2342. 1:47:45checkbox uh
  2343. 1:47:47and let's check the Imports
  2344. 1:47:53yeah text input was imported but why
  2345. 1:47:55wasn't checkbox wasn't imported let's
  2346. 1:47:58import the checkbox as
  2347. 1:48:01well okay now we're going to listen to
  2348. 1:48:05uh we're going to make this live and
  2349. 1:48:07we're going to listen on blur of the
  2350. 1:48:10name and whenever on blur happens now
  2351. 1:48:14I'm going to add a call back after State
  2352. 1:48:19updated okay and whenever state is
  2353. 1:48:22updated
  2354. 1:48:24it returns this state so this is what we
  2355. 1:48:26are going to
  2356. 1:48:33change let's provide regular function
  2357. 1:48:37here uh why do we have so many
  2358. 1:48:40RS probably we have some yeah we don't
  2359. 1:48:43need
  2360. 1:48:44this okay so whenever state is updated
  2361. 1:48:48we're going to update this slag so here
  2362. 1:48:51um the a completion didn't
  2363. 1:48:53quite work perfectly so we have string
  2364. 1:48:56operation what happens whether that was
  2365. 1:48:59um create or update and we have also
  2366. 1:49:03State here and we have cable which is
  2367. 1:49:08set and we are going to call set we are
  2368. 1:49:12going to provide the attribute name Slug
  2369. 1:49:16and we're going to generate the state is
  2370. 1:49:18going to be the actual name and I'm
  2371. 1:49:20going to use St Str
  2372. 1:49:23um support generate slug from State
  2373. 1:49:28let's format the code okay name slugs
  2374. 1:49:31required that's active okay now let's
  2375. 1:49:34have a look refresh the page and we see
  2376. 1:49:36name Slug and active and I'm going to
  2377. 1:49:38call this um Electronics as an example
  2378. 1:49:42and whenever I click on outside that is
  2379. 1:49:45updated we have double e here which is
  2380. 1:49:48not necessary that gets updated I'm
  2381. 1:49:50going to click on active click on create
  2382. 1:49:53and that was actually created and we can
  2383. 1:49:55click on departments and we're going to
  2384. 1:49:57see one record right here but now we
  2385. 1:50:00need to display that information so
  2386. 1:50:03scroll down below in the columns area
  2387. 1:50:07we're going to use text column for name
  2388. 1:50:10we can make this sortable and we can
  2389. 1:50:13make this searchable as well and we can
  2390. 1:50:17also provide right here default sort to
  2391. 1:50:21be by create ated at in descending
  2392. 1:50:26order then we have filters uh inside
  2393. 1:50:29actions we have edit and we probably
  2394. 1:50:32need to add delete action as well and
  2395. 1:50:37inside bulk actions we're going to have
  2396. 1:50:39this um delete action only so if I save
  2397. 1:50:42this right now refresh the page we're
  2398. 1:50:44going to see name right here which is
  2399. 1:50:45sortable searchable and clicking edit
  2400. 1:50:48opens this clicking delete bring UPS
  2401. 1:50:51brings up the confirmation click on
  2402. 1:50:53confirm and the record was
  2403. 1:50:55deleted that's
  2404. 1:50:57awesome now let's add two things right
  2405. 1:51:00here first is that whenever we create
  2406. 1:51:03new
  2407. 1:51:04Department uh we stay on the edit page
  2408. 1:51:07and we want to be redirected into the
  2409. 1:51:09index page so for this let's open the
  2410. 1:51:14department so inside up filament
  2411. 1:51:18resources department resource click on
  2412. 1:51:22this create department and right here
  2413. 1:51:24we're going to add a get redirect URL
  2414. 1:51:29and we are going to redirect user into
  2415. 1:51:33the index road so
  2416. 1:51:36this get
  2417. 1:51:39resource oops get
  2418. 1:51:42resource and then on that we're going to
  2419. 1:51:45call uh get URL for index okay this get
  2420. 1:51:50resource Returns the following class and
  2421. 1:51:53that has the pages right here and we
  2422. 1:51:56need index page and we're going to do
  2423. 1:51:59something similar on Department
  2424. 1:52:02edit edit Department scroll down below
  2425. 1:52:07oops and get redirect URL now if we
  2426. 1:52:11update the record we will be redirected
  2427. 1:52:13into index or if we create new record we
  2428. 1:52:17will be redirected into the index second
  2429. 1:52:21thing is that if we log out right now
  2430. 1:52:24and try
  2431. 1:52:26to log in as
  2432. 1:52:30vendor we access the admin and we are
  2433. 1:52:33able to see the Departments but vendor
  2434. 1:52:34users should not be able to see the
  2435. 1:52:38Departments right so this is something
  2436. 1:52:41we need to uh fix in the department
  2437. 1:52:45resource down below we're going to add
  2438. 1:52:46new function public static function uh
  2439. 1:52:51can view
  2440. 1:52:53any where we're going to overwrite that
  2441. 1:52:55function and we're going to return true
  2442. 1:52:57or false whether the current user has
  2443. 1:52:59access to see list of departments or
  2444. 1:53:04not and so in this case I'm going to
  2445. 1:53:07access user using filament
  2446. 1:53:12user uh actually filament
  2447. 1:53:15Al user and then I'm going to check if
  2448. 1:53:19user
  2449. 1:53:20exists and if
  2450. 1:53:23user has
  2451. 1:53:25rooll
  2452. 1:53:27admin roles
  2453. 1:53:30enam admin only in this case we are
  2454. 1:53:34going to um give the permission to view
  2455. 1:53:38the listing now if I refresh the page it
  2456. 1:53:41is forbidden if I simply access admin
  2457. 1:53:44page now the user is not able the vendor
  2458. 1:53:47user is not even able to see departments
  2459. 1:53:50in the menu item which is exactly what
  2460. 1:53:52we wanted if you log out right now and
  2461. 1:53:55log in as admin user admin user now sees
  2462. 1:53:59these
  2463. 1:54:00departments okay this is awesome now if
  2464. 1:54:02we click on this this is the edit page
  2465. 1:54:05uh and we also want to manage categories
  2466. 1:54:08for the department so the department
  2467. 1:54:10might have multiple categories and we
  2468. 1:54:12want to manage that as
  2469. 1:54:15well now let's create category model and
  2470. 1:54:18Define the migration as well and we're
  2471. 1:54:20going to set up the relation between
  2472. 1:54:21departments and categories for this I'm
  2473. 1:54:24going to execute PHP artisan make a
  2474. 1:54:28category provide the migration as
  2475. 1:54:33well uh I'm sorry I did something stupid
  2476. 1:54:36PHP artisan make model category in the
  2477. 1:54:41migration as well now let's open create
  2478. 1:54:44categories
  2479. 1:54:46table and we're going to Define category
  2480. 1:54:50name we're going to Define
  2481. 1:54:52um boring ID on we need parent ID
  2482. 1:54:57actually so that should be knowable and
  2483. 1:54:59constrainted on categories uh but we
  2484. 1:55:02also need
  2485. 1:55:03table uh foring ID that should be on
  2486. 1:55:09Department ID okay and we can um we need
  2487. 1:55:14that to be constrained and we probably
  2488. 1:55:17need to also add index to
  2489. 1:55:21that uh as as well as the parent
  2490. 1:55:25ID maybe we need to move this
  2491. 1:55:32down so we have name we have the
  2492. 1:55:35department name we have the parent
  2493. 1:55:37category name and we can add additional
  2494. 1:55:40field which is going to be uh Boolean
  2495. 1:55:46active Okay by default we can assign it
  2496. 1:55:49to true so now we have that categories
  2497. 1:55:52table defined as well I'm thinking if I
  2498. 1:55:55missed anything I think I don't
  2499. 1:55:57optionally we can add order attribute as
  2500. 1:55:59well to implement ordering which
  2501. 1:56:01category should be the first which one
  2502. 1:56:02should be the second but I'm going to
  2503. 1:56:04skip that part so now we have this uh
  2504. 1:56:06migration ready let's execute PHP
  2505. 1:56:09Artisan migrate hit the enter migrations
  2506. 1:56:13we applied awesome and now we're going
  2507. 1:56:16to Define relation between Department
  2508. 1:56:19into category so we can create separate
  2509. 1:56:21resource category resource s but this is
  2510. 1:56:23what I'm going to do I'm just going to
  2511. 1:56:24show the category management right here
  2512. 1:56:29on the department page for
  2513. 1:56:33this uh there is something related to
  2514. 1:56:36relation so
  2515. 1:56:39relation uh relation manager introducing
  2516. 1:56:42relation managers I think this is what
  2517. 1:56:45we want exactly okay now I'm going to
  2518. 1:56:47copy the following commment and let's
  2519. 1:56:49execute this and um I will explain this
  2520. 1:56:52so we're going to execute PHP Artis and
  2521. 1:56:54make filament relation manager and we're
  2522. 1:56:57going to provide the parent resource
  2523. 1:56:59which is Department resource okay so
  2524. 1:57:03we're going to define the relation from
  2525. 1:57:06Department resource uh we're going to
  2526. 1:57:09define the field uh the relation field
  2527. 1:57:12which is going to be categories okay and
  2528. 1:57:14we're going to also use the name field
  2529. 1:57:17which will be used in the relation um
  2530. 1:57:20that field is the category field
  2531. 1:57:22name um let's hit the
  2532. 1:57:28enter um let's have a look filament
  2533. 1:57:31relation manager okay make sure to
  2534. 1:57:33register the relation in get relations
  2535. 1:57:37so we have to register that relation but
  2536. 1:57:40we have to also open Department PHP and
  2537. 1:57:43Define has many has many
  2538. 1:57:47categories which goes to category model
  2539. 1:57:52now let's open
  2540. 1:57:54Department
  2541. 1:57:56resource and we are going to find the
  2542. 1:58:01method get relations and right here
  2543. 1:58:04we're going to use categories relation
  2544. 1:58:06manager uh class okay so I save
  2545. 1:58:11this and refresh the page and down below
  2546. 1:58:14we see categories and I click this new
  2547. 1:58:17category which brings up this form and
  2548. 1:58:20this is something we are going to work
  2549. 1:58:23right now and add more um Fields here
  2550. 1:58:27let's open these categories relations
  2551. 1:58:30manager and here we have the form we
  2552. 1:58:33also need a prent ID which is going to
  2553. 1:58:36be select select p in ID uh it is not
  2554. 1:58:40actually required but we have to Define
  2555. 1:58:42what options that should have so I'm
  2556. 1:58:44going to provide options here which
  2557. 1:58:47accepts
  2558. 1:58:49function okay and from here we're going
  2559. 1:58:52to return the array what will be the
  2560. 1:58:56options for that select so we are going
  2561. 1:58:59to do Q from
  2562. 1:59:01category uh we're going to filter and
  2563. 1:59:04take out only those categories which
  2564. 1:59:07belong to this specific department and
  2565. 1:59:11this specific Department basically is
  2566. 1:59:14right here um we can access the record
  2567. 1:59:18in the following way this get owner
  2568. 1:59:22record and this is going the owner in
  2569. 1:59:24this case is the department so we can
  2570. 1:59:25call this
  2571. 1:59:28department all right and then right here
  2572. 1:59:31inside this function we're going to pass
  2573. 1:59:34use department and we're going to find
  2574. 1:59:37those
  2575. 1:59:40categories uh let's provide um
  2576. 1:59:44where where um column name
  2577. 1:59:50Department Department ID equals the
  2578. 1:59:53given
  2579. 1:59:55Department ID all right then I'm going
  2580. 1:59:58to call plaque on this I want
  2581. 2:00:01associative array column name is going
  2582. 2:00:03to be the name the key is going to be
  2583. 2:00:05the ID and finally I'm going to call two
  2584. 2:00:08array on
  2585. 2:00:10this um I think that's good so we have
  2586. 2:00:13the department we're giving the
  2587. 2:00:15department we're filtering categories
  2588. 2:00:18okay so let's give it a label to this
  2589. 2:00:22parent ID the label is going to be pent
  2590. 2:00:26category let's give it
  2591. 2:00:28also reload it is going to be preloaded
  2592. 2:00:32uh without clicking on on this and I'm
  2593. 2:00:35going to make this also
  2594. 2:00:38searchable basically we are preloading
  2595. 2:00:40all the Departments uh sorry all the
  2596. 2:00:44categories uh without this preload and
  2597. 2:00:47searchable it is going to search by the
  2598. 2:00:49given uh keyword what we're going to put
  2599. 2:00:52there okay and we also need checkbox so
  2600. 2:00:55we can use checkbox make active Okay
  2601. 2:01:01cool uh let's focus on the table as well
  2602. 2:01:04here we have the columns we have name at
  2603. 2:01:07the moment and we're going to make
  2604. 2:01:09that name
  2605. 2:01:12sortable and searchable and we're going
  2606. 2:01:15to use additional text column as well
  2607. 2:01:19which is going to be parent name but in
  2608. 2:01:21this case I'm going to access this
  2609. 2:01:23through relation parent. name and let's
  2610. 2:01:27make this
  2611. 2:01:28sortable and searchable as well and
  2612. 2:01:32finally we need um icon column here
  2613. 2:01:36which is going to be
  2614. 2:01:39active however the parent relation does
  2615. 2:01:42not exist at the moment so we're going
  2616. 2:01:44to open category model and we're going
  2617. 2:01:48to Define right here heent relation
  2618. 2:01:51belongs to
  2619. 2:01:52pent and this is going to be category by
  2620. 2:01:56pent
  2621. 2:01:58ID okay and we can also Define um as
  2622. 2:02:02many children but we don't need this at
  2623. 2:02:04the moment so I'm going to skip that
  2624. 2:02:06part now I save this refresh the
  2625. 2:02:10page now let's have a look new
  2626. 2:02:14category name headsets for example the
  2627. 2:02:18parent category nothing click on AC
  2628. 2:02:22create that was created now let's see
  2629. 2:02:27Sony
  2630. 2:02:29headsets parent is headsets active
  2631. 2:02:33create uh active is not displayed for
  2632. 2:02:37some
  2633. 2:02:38reason I column I think we have this
  2634. 2:02:42Boolean as well so this is a Boolean and
  2635. 2:02:45in which case it should display this
  2636. 2:02:47properly okay cool so if I edit this it
  2637. 2:02:51brings up this model deactivate click on
  2638. 2:02:54Save we see that the active Flags like
  2639. 2:02:56this so that's pretty cool so now we can
  2640. 2:02:59search for
  2641. 2:03:01Sony and it filters out those categories
  2642. 2:03:05so just like this now we have crowd for
  2643. 2:03:07departments you can create any
  2644. 2:03:08department so let's define uh
  2645. 2:03:12electronics uh and let's make it active
  2646. 2:03:15click on create that was created and uh
  2647. 2:03:19inside the electronics you can Define
  2648. 2:03:21categories as
  2649. 2:03:23well let me actually Define some C data
  2650. 2:03:27for departments and for categories so
  2651. 2:03:30I'm going to execute PHP artisan make
  2652. 2:03:35Cedar uh this is going to be Department
  2653. 2:03:39Cedar we hit the
  2654. 2:03:41enter and PHP Artisan makes Cedar the
  2655. 2:03:45next one is going to be category Cedar
  2656. 2:03:49we hit the enter okay let's open
  2657. 2:03:52database Cedar and let's add Department
  2658. 2:03:57Cedar here and category Ceder here now
  2659. 2:04:01let's open Department Ceder and I'm
  2660. 2:04:05going to actually
  2661. 2:04:07use uh copy some data from Department
  2662. 2:04:10CED what I have prepared and you can
  2663. 2:04:14grab it from the
  2664. 2:04:16uh video description or you can type it
  2665. 2:04:19or you can uh get it from the source
  2666. 2:04:22code of the project so this is just
  2667. 2:04:25associative array containing six uh
  2668. 2:04:27departments I think it's six so we have
  2669. 2:04:29this name electronics its corresponding
  2670. 2:04:32slack active true and created that and
  2671. 2:04:35update that is now okay so we have this
  2672. 2:04:37departments we have fashion again active
  2673. 2:04:40we have home gardening tools and we can
  2674. 2:04:42import this Str
  2675. 2:04:45Str oops let's import this eliminate
  2676. 2:04:49support St Str uh we generate slug
  2677. 2:04:53basically out of the following name so
  2678. 2:04:56here again we generate um slug out of
  2679. 2:04:59this text and here again we generate
  2680. 2:05:01Slag out of this text and these are all
  2681. 2:05:03the Departments we have and what we need
  2682. 2:05:05to do right now is to
  2683. 2:05:09use DB DB
  2684. 2:05:13table departments insert and let's
  2685. 2:05:17import this illuminate support facades
  2686. 2:05:19DB as well and we're going to do
  2687. 2:05:22something similar into category as well
  2688. 2:05:25so let me copy some category data as
  2689. 2:05:31well
  2690. 2:05:33category
  2691. 2:05:36Cedar and I'm going to paste this let's
  2692. 2:05:38have a look so we have name of the
  2693. 2:05:43category to be electronics and it is uh
  2694. 2:05:46referring to Department ID one assuming
  2695. 2:05:49that the department ID is for electron
  2696. 2:05:52parent ID is null and active is true
  2697. 2:05:55create that updated that next we have
  2698. 2:05:57fashion it's for Department to uh and uh
  2699. 2:06:02and so on basically so we have parent ID
  2700. 2:06:04n here as well but um this is again for
  2701. 2:06:08Department one which is electronics now
  2702. 2:06:10we have computers a second category
  2703. 2:06:12inside electronics and it has PRN ID in
  2704. 2:06:16this case it is a child of electronics
  2705. 2:06:18category and we have smartphones which
  2706. 2:06:20is also
  2707. 2:06:22um here into is electronics so child of
  2708. 2:06:25electronics and we see right here
  2709. 2:06:27laptops and so on so we have desktops
  2710. 2:06:30all of them belong to Department one but
  2711. 2:06:32in this case the parent is uh computers
  2712. 2:06:37right and we have smartphones as well
  2713. 2:06:39pent is
  2714. 2:06:40smartphones um and so on where's
  2715. 2:06:45the we have smartphones as you see if
  2716. 2:06:48you scroll down below then we have
  2717. 2:06:50Android which has PR inti the
  2718. 2:06:52smartphones in the iPhone as well so
  2719. 2:06:55finally let's use
  2720. 2:06:57DB uh table categories insert and just
  2721. 2:07:01like this we're going to have the whole
  2722. 2:07:03data however I'm going to execute PHP
  2723. 2:07:06artisan
  2724. 2:07:07make um not make but
  2725. 2:07:11migrate Fresh So that everything is
  2726. 2:07:13dropped and recreated with D- C data so
  2727. 2:07:17the data what we created right here is
  2728. 2:07:20going to be dropped and new data will be
  2729. 2:07:22created and we will have categories and
  2730. 2:07:24departments for your e-commerce website
  2731. 2:07:27you might need to put more departments
  2732. 2:07:29and more categories in your Cedar uh
  2733. 2:07:33classes but that's up to you so in my
  2734. 2:07:36case let's execute phps and make um PHP
  2735. 2:07:39and migrate Fresh D
  2736. 2:07:43seed okay all the seeders we are
  2737. 2:07:45executed now we will be logged
  2738. 2:07:49out now if we are authenticate with
  2739. 2:07:53admin click on departments we see
  2740. 2:07:57Electronics Fashion Home garden tools
  2741. 2:07:59book and audible okay so far so good
  2742. 2:08:02click on electronics and we see the
  2743. 2:08:04following categories belong to
  2744. 2:08:06electronics department so this one is
  2745. 2:08:08the prent category and now this one the
  2746. 2:08:11other ones uh simply belong to this so
  2747. 2:08:14now we have at least some simple data to
  2748. 2:08:16work with and to create some products
  2749. 2:08:18out of this data clicking on this triers
  2750. 2:08:21editing and we can change the paring
  2751. 2:08:23category we can do anything we want
  2752. 2:08:25clicking on this will um trigger the
  2753. 2:08:27delete and I don't want to delete
  2754. 2:08:29anything at the moment and let's search
  2755. 2:08:32for something uh let's search for
  2756. 2:08:34Android and search also works perfectly
  2757. 2:08:37and even
  2758. 2:08:39sorting and Parn sorting all these
  2759. 2:08:42things are working as they should work
  2760. 2:08:45now let's start working on product crud
  2761. 2:08:48which is going to be added for the
  2762. 2:08:51vendor users not for the admin user so
  2763. 2:08:54actually I think we can sign out and we
  2764. 2:08:58can log in as vendor
  2765. 2:09:01user vendor example.com
  2766. 2:09:05okay here we go now let me
  2767. 2:09:11execute PHP
  2768. 2:09:14artisan make
  2769. 2:09:18model product with migration and I think
  2770. 2:09:22we will need controller as well on the
  2771. 2:09:24front end side and that controller
  2772. 2:09:26should be uh should have um listing of
  2773. 2:09:29the products um should it be resource No
  2774. 2:09:33it should not be resource controllers
  2775. 2:09:34we're going to only have listing of the
  2776. 2:09:36products nothing else but we need
  2777. 2:09:38controller so I think we are good I'm
  2778. 2:09:41going to hit the
  2779. 2:09:43enter okay so the model the migration
  2780. 2:09:47and the controller was generated I'm
  2781. 2:09:49going to also generate enam PHP artisan
  2782. 2:09:54make enam let's call this product status
  2783. 2:09:59Anam and I'm going to put this inside
  2784. 2:10:02anam's
  2785. 2:10:04folder so I'm going to specify name
  2786. 2:10:06space as well we are going to hit the
  2787. 2:10:09enter and finally we are going to
  2788. 2:10:12execute PHP artisan
  2789. 2:10:15make um
  2790. 2:10:17filament resource and we're going to
  2791. 2:10:20provide
  2792. 2:10:22product here okay I'm going to hit the
  2793. 2:10:24enter the product resource was
  2794. 2:10:28generated now let's open migration file
  2795. 2:10:32create products table and Define couple
  2796. 2:10:35of fields so first we need to define the
  2797. 2:10:38title with the length of 2,000 I'm going
  2798. 2:10:41to Define slug as well and then I'm
  2799. 2:10:44going to Define long text description we
  2800. 2:10:47need foring ID to Department to
  2801. 2:10:50Department table and to call the column
  2802. 2:10:51foring idid I'm going to Define index on
  2803. 2:10:54that as well and it must be constrained
  2804. 2:10:56on departments in the same way we're
  2805. 2:10:58going to Define category ID with index
  2806. 2:11:01and with constraint next I'm going to
  2807. 2:11:04Define price field with total 20 and
  2808. 2:11:06places four I'm going to Define string
  2809. 2:11:10which is going to be status and I'm
  2810. 2:11:13going to Define also quantity here and
  2811. 2:11:16uh I'm going to Define created by and
  2812. 2:11:19updated by which be the user who created
  2813. 2:11:23or modified this specific product in
  2814. 2:11:26most cases or in all cases in
  2815. 2:11:28specific in our specific project created
  2816. 2:11:31by and updated by is going to be the
  2817. 2:11:33same so this is going to be the vendor
  2818. 2:11:35but if you want to improve this in the
  2819. 2:11:37future and add also ability that vendor
  2820. 2:11:39users give possibility to add other
  2821. 2:11:43users to manage their stock then created
  2822. 2:11:47by and updated by might be actually
  2823. 2:11:50different okay so we also need to add
  2824. 2:11:54deleted at which is going to be nullable
  2825. 2:11:57Tim stamp and we are going to add I
  2826. 2:12:00think yeah that's it so we're going to
  2827. 2:12:02import now user model because we are
  2828. 2:12:05using that user model and we are done on
  2829. 2:12:07the migration side now let's open
  2830. 2:12:10product status ANM and right here I'm
  2831. 2:12:14going to give it the type of string and
  2832. 2:12:16Define two cases draft and published and
  2833. 2:12:20then I'm going to Define two function
  2834. 2:12:21functions one for labels second for
  2835. 2:12:23colors inside labels we're going to
  2836. 2:12:25return an associative array we are draft
  2837. 2:12:28key corresponds to draft and published
  2838. 2:12:31corresponds to published and the same
  2839. 2:12:33way we are going to Define
  2840. 2:12:36colors where uh gray color corresponds
  2841. 2:12:39to draft value and success uh color
  2842. 2:12:42corresponds to published value so here
  2843. 2:12:44we are using this underscore underscore
  2844. 2:12:46function which is for internalization
  2845. 2:12:49for translating these texts so we are
  2846. 2:12:52not actually building our project uh
  2847. 2:12:55translatable and I'm not going to
  2848. 2:12:57implement anything related to
  2849. 2:12:59translations but having these underscore
  2850. 2:13:02uncore functions right here doesn't Hur
  2851. 2:13:05it so if in the future you decide that
  2852. 2:13:08you want to implement translations you
  2853. 2:13:09know that you don't have to find all the
  2854. 2:13:11places where we have written strings and
  2855. 2:13:16we can just use this underscore uncore
  2856. 2:13:18parenthesis I know probably I am not
  2857. 2:13:20using this underscore
  2858. 2:13:22underscore function in every place where
  2859. 2:13:25I should be using but that's only
  2860. 2:13:27because I am not actually implementing
  2861. 2:13:29translations but in the places where it
  2862. 2:13:31is already used you don't need to touch
  2863. 2:13:33it and you can just directly activate
  2864. 2:13:35translations if you want that in the
  2865. 2:13:37future okay so we Define the status and
  2866. 2:13:41next is to
  2867. 2:13:43open a product
  2868. 2:13:46model and right here I want to Define um
  2869. 2:13:50two Rel ation uh both of them will be
  2870. 2:13:52belongs to so belongs to category so
  2871. 2:13:55product belongs to category we're going
  2872. 2:13:57to use category class here and second or
  2873. 2:14:00maybe first we should have Department in
  2874. 2:14:03then category because department is kind
  2875. 2:14:05of apperent of the category as well now
  2876. 2:14:08belongs to so this is just my personal
  2877. 2:14:10preference of course you can have
  2878. 2:14:12category first and Department second um
  2879. 2:14:16department and here we need Department
  2880. 2:14:20class okay cool and finally we're going
  2881. 2:14:23to open product
  2882. 2:14:25resource and right here in the um
  2883. 2:14:28columns and in the uh form section we
  2884. 2:14:31are going to Define some of the fields
  2885. 2:14:34let's start with
  2886. 2:14:35the with the forms and first we're going
  2887. 2:14:38to um Define a title text input uh for
  2888. 2:14:42title we're going to listen to its
  2889. 2:14:45change on blur basically we uh first it
  2890. 2:14:49needs to be required but we're going to
  2891. 2:14:51listen to on blar and whenever the state
  2892. 2:14:53is changed we are going to update slug
  2893. 2:14:57as well so we will import this St class
  2894. 2:15:00in a moment so text input similar to
  2895. 2:15:03what we did for the Departments we have
  2896. 2:15:05text input whenever it changes we update
  2897. 2:15:07the slack next we're going to define the
  2898. 2:15:09slack which needs to be required we're
  2899. 2:15:11going to Define Department ID and we are
  2900. 2:15:13going to associate that field into
  2901. 2:15:16Department relation with the and we're
  2902. 2:15:19going to use this name field to display
  2903. 2:15:23departments in this drop-down okay we're
  2904. 2:15:26going to give it also label Department
  2905. 2:15:28which is going to be translatable we're
  2906. 2:15:29going to give it a preload so all the
  2907. 2:15:31Departments will be preloaded it is
  2908. 2:15:33going to be searchable and it's going to
  2909. 2:15:35be required okay it's going to be also
  2910. 2:15:38reactive to make um to um adapt some
  2911. 2:15:42changes on um on that and whenever the
  2912. 2:15:45department is changed this is why we
  2913. 2:15:46need reactive whenever the department is
  2914. 2:15:49changed we are going to
  2915. 2:15:51set the category ID to be null whenever
  2916. 2:15:54we choose something if the category is
  2917. 2:15:55already set we're going to reset the
  2918. 2:15:57category
  2919. 2:15:59okay uh now let's define the category
  2920. 2:16:03field the category field has a
  2921. 2:16:05relationship uh similar to how
  2922. 2:16:07department has relationship but it has
  2923. 2:16:09slightly more complex relationship so um
  2924. 2:16:12the name of the relation is category and
  2925. 2:16:15the title attribute is name however we
  2926. 2:16:17need to modify the query as well so we
  2927. 2:16:20only want to those categories which are
  2928. 2:16:22for the selected
  2929. 2:16:24department for this we are going to get
  2930. 2:16:27the Department first using this uh
  2931. 2:16:30callable get okay so we get the
  2932. 2:16:33Department then we check if the
  2933. 2:16:35department exists we are going to write
  2934. 2:16:38the following we we Department ID is the
  2935. 2:16:40selected Department ID and that
  2936. 2:16:43basically filters categories based on
  2937. 2:16:45the department all right so next we need
  2938. 2:16:48to associate label to it category we're
  2939. 2:16:51going to preload all the categories
  2940. 2:16:53we're going to make it searchable and
  2941. 2:16:54required as well and after this
  2942. 2:16:58basically which
  2943. 2:17:00is um the following
  2944. 2:17:05greed okay so after this grid down
  2945. 2:17:11below we are going to Define reach
  2946. 2:17:13editor okay so which needs to be for the
  2947. 2:17:17description field which needs to be
  2948. 2:17:18required it's it's it's going to have
  2949. 2:17:21column spun for two it's going to be
  2950. 2:17:22stretch on two columns and we're going
  2951. 2:17:25to customize the toolbar buttons as well
  2952. 2:17:27so we're going to have the following
  2953. 2:17:28buttons block quote bold buet bullet
  2954. 2:17:32list H2 H3 italic link order list redo
  2955. 2:17:35strike underline undo and table okay and
  2956. 2:17:39then we're going to Define price which
  2957. 2:17:41is going to be numeric Fielder required
  2958. 2:17:43quantity which is going to be integer
  2959. 2:17:46status which is going to have the um
  2960. 2:17:49options from the product status enm
  2961. 2:17:52we're going to import all these
  2962. 2:18:20input and then we're going to inut this
  2963. 2:18:23product status in um as well okay so I
  2964. 2:18:27think we don't have anything that is not
  2965. 2:18:30imported okay now we're going to save
  2966. 2:18:33this and let's refresh it and as you see
  2967. 2:18:37right here we have the products if we
  2968. 2:18:39click on the
  2969. 2:18:41products uh okay the products table is
  2970. 2:18:43not created so we're going to execute
  2971. 2:18:47migration PHP Artisan migrate hit the
  2972. 2:18:49enter that was executed good refresh the
  2973. 2:18:53page and now we see the products empty
  2974. 2:18:56table and if we click on this um a
  2975. 2:18:59product now this gives us the following
  2976. 2:19:02form we have title slug Department
  2977. 2:19:05category we have some description price
  2978. 2:19:07quantity and
  2979. 2:19:09status now let's try to create our first
  2980. 2:19:13product first product the slack should
  2981. 2:19:16be generated we're going to choose the
  2982. 2:19:19department to be Electronics
  2983. 2:19:21uh we see all the elect Electronics um
  2984. 2:19:24categories I'm going to choose computers
  2985. 2:19:27some test
  2986. 2:19:28description let's give it some price I'm
  2987. 2:19:32going to leave the quantity empty and
  2988. 2:19:34click on
  2989. 2:19:36Create and we have the following problem
  2990. 2:19:38so the created by is actually required
  2991. 2:19:41field in the database but we didn't
  2992. 2:19:43provide anything so to fix this we are
  2993. 2:19:46going to open
  2994. 2:19:50filament resources product resource
  2995. 2:19:53create product and right here we need to
  2996. 2:19:56override method mutate form data before
  2997. 2:20:01create and we have the data here and
  2998. 2:20:04inside the data we are going to put
  2999. 2:20:07updated by
  3000. 2:20:09equals um out ID and created by equals
  3001. 2:20:14Al
  3002. 2:20:16ID and finally we are going to return
  3003. 2:20:20that data from here and if we try now
  3004. 2:20:25retry to create new
  3005. 2:20:28product created so we see that the
  3006. 2:20:30product was created we see right now
  3007. 2:20:32product edit page and we can check this
  3008. 2:20:35in the database as well refresh the
  3009. 2:20:37database we see products click on this
  3010. 2:20:40and we see this single product that was
  3011. 2:20:42already created in the database okay so
  3012. 2:20:46if we want to restrict access to the
  3013. 2:20:49products page only for uh vendor users
  3014. 2:20:53now we can add right here can view any
  3015. 2:20:57similar to how we have for Department
  3016. 2:21:01resource can view any but the thing is
  3017. 2:21:05that product resources is used only
  3018. 2:21:07inside filament admin inside filament
  3019. 2:21:10admin only two role users can access
  3020. 2:21:12admin user and vendor user if we add
  3021. 2:21:15right here can view any for vendor Ro it
  3022. 2:21:19means that the admin user is not able to
  3023. 2:21:22view products which kind of makes sense
  3024. 2:21:25so it really depends how you want do you
  3025. 2:21:27want admin users to create new products
  3026. 2:21:29or not if you want to create admin users
  3027. 2:21:33new products then you should not put
  3028. 2:21:36this but I'm going to actually put this
  3029. 2:21:38so admin users will do the admin side
  3030. 2:21:41and um vendor users will do vendor
  3031. 2:21:44related things so I'm going to put a
  3032. 2:21:46vendor here which means that admin users
  3033. 2:21:48will not be able to see this products
  3034. 2:21:50menu item okay so that's fine um next we
  3035. 2:21:56are going to see the product listing and
  3036. 2:21:58we're going to display some of the
  3037. 2:22:00information from the products
  3038. 2:22:03table now in the table function in the
  3039. 2:22:07columns area let's define some of the
  3040. 2:22:09columns like we need Title and we're
  3041. 2:22:12going to make this title sortable but
  3042. 2:22:14we're going to take only first 10 words
  3043. 2:22:16from the title we don't want the entire
  3044. 2:22:18title let's make this searchable in and
  3045. 2:22:21um yeah that's it the second field is
  3046. 2:22:23going to be status uh we're going to
  3047. 2:22:26activate uh page we're going to make
  3048. 2:22:28this status column as bable so call it
  3049. 2:22:32so and the following colors will be used
  3050. 2:22:34to display bed padges um then we're
  3051. 2:22:39going to display Department name and
  3052. 2:22:42category name as well and we're going to
  3053. 2:22:44display created that um as a daytime
  3054. 2:22:47format so if I save this right now
  3055. 2:22:51and refresh it this is how it looks like
  3056. 2:22:55okay so I think the next step will be to
  3057. 2:22:59start working on images for the products
  3058. 2:23:02and variations so we have this create of
  3059. 2:23:06the product typical crud is actually
  3060. 2:23:09done uh let's turn this into
  3061. 2:23:13published go into products and we see
  3062. 2:23:17publish right
  3063. 2:23:18here okay good
  3064. 2:23:21uh I think we can also add some of the
  3065. 2:23:23filters to this
  3066. 2:23:26so here I'm going to use select filter
  3067. 2:23:30for status and we're going to provide
  3068. 2:23:33options that will be product status andm
  3069. 2:23:37labels second is going to be select
  3070. 2:23:39filer for Department ID and I'm going to
  3071. 2:23:42Define relationship with Department name
  3072. 2:23:46so if I save this and refresh it right
  3073. 2:23:48here we see this filtering section and I
  3074. 2:23:50can filter draft items it chose empty or
  3075. 2:23:55published items it chose this one or all
  3076. 2:23:58it chose all of them and we can also
  3077. 2:24:00filter them by Department like I want to
  3078. 2:24:02find books and audible or Electronics
  3079. 2:24:05which finds something fashion and so so
  3080. 2:24:08we have this nice filtering section as
  3081. 2:24:10well for images and uploading images on
  3082. 2:24:13the product we are going to use another
  3083. 2:24:16spatius package or spatius another
  3084. 2:24:19package um and this is media library or
  3085. 2:24:24can search this spati
  3086. 2:24:27m media library and I want the filament
  3087. 2:24:32version of it because we are actually
  3088. 2:24:34using filament and I want to use this
  3089. 2:24:36inside
  3090. 2:24:37filament okay so the idea of this
  3091. 2:24:40filament this partty media library is
  3092. 2:24:43that it creates polymorphic tables in
  3093. 2:24:48the database and you can implement image
  3094. 2:24:51or basically media upload on any table
  3095. 2:24:54on any um any records okay and this is
  3096. 2:24:59how simple is that so let's go ahead and
  3097. 2:25:02install this P media library plug-in so
  3098. 2:25:05I'm going to copy
  3099. 2:25:07this let's bring up the terminal and I'm
  3100. 2:25:10going to
  3101. 2:25:13hit actually uh let me comment
  3102. 2:25:17everything while this is being installed
  3103. 2:25:21in composer Json we have the spum media
  3104. 2:25:23library so this is the case when I don't
  3105. 2:25:24want this to be included because I'm
  3106. 2:25:27actually committing the previous changes
  3107. 2:25:28I made so
  3108. 2:25:33Implement
  3109. 2:25:35Implement product
  3110. 2:25:39Rod okay let's click on
  3111. 2:25:43comit now we have two
  3112. 2:25:45changes let's close everything that was
  3113. 2:25:49installed
  3114. 2:25:51next uh we have to
  3115. 2:25:55publish migration
  3116. 2:26:01files okay so it's publish this
  3117. 2:26:05migration file and we can have a look
  3118. 2:26:07inside this create media
  3119. 2:26:10table create media table and look at
  3120. 2:26:14this so it has this morphs type of
  3121. 2:26:17column on model so it has the uid it has
  3122. 2:26:21the collection name um and basically
  3123. 2:26:24let's go ahead and implement the file
  3124. 2:26:27upload and then when there is a record
  3125. 2:26:29already inserted in the table then it
  3126. 2:26:32will make um much more
  3127. 2:26:35sense so that's pretty powerful Library
  3128. 2:26:38actually so now we're going to execute
  3129. 2:26:39PHP Artisan
  3130. 2:26:44migrate okay the tables we are created
  3131. 2:26:47we can see that media table right here
  3132. 2:26:52awesome okay um we can close this and
  3133. 2:26:55now I'm going to
  3134. 2:26:56open product resource and I'm going to
  3135. 2:27:00create subnavigation um inside that
  3136. 2:27:04resource so maybe here after Pages I'm
  3137. 2:27:08going to add um get record sub
  3138. 2:27:12navigation I'm going to overwrite that
  3139. 2:27:14method
  3140. 2:27:18basically and on that page page we have
  3141. 2:27:21the page here on that page I'm going to
  3142. 2:27:24generate navigation items okay and I'm
  3143. 2:27:27going to have a few items one is going
  3144. 2:27:29to be edit
  3145. 2:27:31product uh edit
  3146. 2:27:35product class this is going to be one
  3147. 2:27:38and we are going to import that edit
  3148. 2:27:41product which is filament edit page we
  3149. 2:27:44can go ahead this edit product and this
  3150. 2:27:48extends edit record
  3151. 2:27:51okay so this is one now if we save this
  3152. 2:27:54and have a look in the
  3153. 2:27:56browser uh and if we click on the
  3154. 2:28:01product okay argument
  3155. 2:28:07one oh sorry I should directly return
  3156. 2:28:10this generate um navigation
  3157. 2:28:14items refresh the page okay now we see
  3158. 2:28:18that the uh sub sub navigation is right
  3159. 2:28:21here on the left so we're going to add
  3160. 2:28:24um more subnavigation
  3161. 2:28:28items first let's scroll up and I'm
  3162. 2:28:31going to change the subnavigation
  3163. 2:28:34position subnavigation position is going
  3164. 2:28:37to be sub navigation position end so we
  3165. 2:28:42want that on the right side rather than
  3166. 2:28:46on the left side
  3167. 2:28:50now similar to edit product I want to
  3168. 2:28:54create another page which extends edit
  3169. 2:28:58record and this is going to be for
  3170. 2:29:02images so let me duplicate this edit
  3171. 2:29:06product and I'm going to call this
  3172. 2:29:09product
  3173. 2:29:12images okay now here we can
  3174. 2:29:16Define
  3175. 2:29:18form and we are going to return um some
  3176. 2:29:23of the fields let's open this product
  3177. 2:29:33resource okay in here I want to use now
  3178. 2:29:36this spatty media library
  3179. 2:29:39to return and render these fields and
  3180. 2:29:42the field is called this the the class
  3181. 2:29:45name is spati Media
  3182. 2:29:48Library by file upload okay let's take
  3183. 2:29:55this and put this right here we are
  3184. 2:29:59going to import that however
  3185. 2:30:03that should be on images we don't have
  3186. 2:30:08Avatar I'm going to change this into
  3187. 2:30:10images and then we're going to add a
  3188. 2:30:13couple of methods like this is going to
  3189. 2:30:16be image uh multiple
  3190. 2:30:20we're going to uh give it also openable
  3191. 2:30:23so that each image can be opened we're
  3192. 2:30:25going to give it panel layout to be
  3193. 2:30:30grid let's give it uh the images should
  3194. 2:30:33be saved inside the collection called
  3195. 2:30:36images that collection is a column name
  3196. 2:30:38in this media table we're going to add
  3197. 2:30:41Also
  3198. 2:30:44reorderable let's give it also upend
  3199. 2:30:46files because every new file is added uh
  3200. 2:30:49as a first first file so we want new
  3201. 2:30:51files to be at the bottom and we're
  3202. 2:30:54going to give it preserve preserve file
  3203. 2:30:57names and also let's give it column span
  3204. 2:31:01to be
  3205. 2:31:02to now we're going to open this product
  3206. 2:31:06resource and scroll down below find
  3207. 2:31:11this get pages and we are going to add
  3208. 2:31:15right here
  3209. 2:31:18images from Pages we're going to access
  3210. 2:31:22product
  3211. 2:31:24images and let's define the road this is
  3212. 2:31:27going to be record images and in
  3213. 2:31:29subnavigation we're going to also Define
  3214. 2:31:33product images now if we save
  3215. 2:31:36that and have a look now we see this
  3216. 2:31:40product images obviously we can change
  3217. 2:31:41this um image icon but when we click on
  3218. 2:31:46this let's have a look
  3219. 2:31:51yeah okay the model should um should
  3220. 2:31:55Implement should extend should use sorry
  3221. 2:31:58should use this has media trait and
  3222. 2:32:00let's check the documentation for this
  3223. 2:32:03okay so this is how we
  3224. 2:32:07can this is something specific
  3225. 2:32:10to filament what we are interested
  3226. 2:32:14in spoty Media Library without filament
  3227. 2:32:21let's check
  3228. 2:32:24this click on base installation so we're
  3229. 2:32:28going to require that we published that
  3230. 2:32:29we execute
  3231. 2:32:31migrations um the publishing the config
  3232. 2:32:33find is optional scroll down
  3233. 2:32:40below this is also optional yeah then we
  3234. 2:32:44need to set up the queue which we will
  3235. 2:32:46do for the image manipulation such as
  3236. 2:32:49the conversion
  3237. 2:32:50or generating different um variations of
  3238. 2:32:54the image small thumbnail and so
  3239. 2:32:57on uh but what I'm interested
  3240. 2:33:01is preparing your modu basic usage okay
  3241. 2:33:05so we are going to implement an
  3242. 2:33:07interface as media and usually trade
  3243. 2:33:09interacts with media so let's open
  3244. 2:33:13product.php product.php
  3245. 2:33:19P why it finds that okay and this
  3246. 2:33:24implements has
  3247. 2:33:26media and it uses interacts with media
  3248. 2:33:32okay now if we refresh the page we see
  3249. 2:33:36the drag and drop section for images I'm
  3250. 2:33:39going to click on this browse and I'm
  3251. 2:33:41going to choose three images click on
  3252. 2:33:43open the images have been dropped here
  3253. 2:33:47they were uploaded
  3254. 2:33:50and click on Save changes that was saved
  3255. 2:33:53but let's have a look what else do we
  3256. 2:33:55need so here we have this register media
  3257. 2:33:57conversions so this is for to generate
  3258. 2:34:00different conversions for the
  3259. 2:34:03media how to associate the
  3260. 2:34:06files how how we can
  3261. 2:34:09access um how we can add new files how
  3262. 2:34:13we can access these new files okay this
  3263. 2:34:16is what I'm going to do I'm going to
  3264. 2:34:17open the media and have a look so we
  3265. 2:34:19have three
  3266. 2:34:20images here model ID this is the
  3267. 2:34:25collection this is the file name this is
  3268. 2:34:28the collection name we have the mime
  3269. 2:34:31type we have the disk and we have the uh
  3270. 2:34:35conversions disk and we're going to find
  3271. 2:34:37those images
  3272. 2:34:39into storage up public and we see one
  3273. 2:34:44two and
  3274. 2:34:47three this is good
  3275. 2:34:52now let's open this product model again
  3276. 2:34:54and we are going to register media
  3277. 2:34:57conversions for uh different resolutions
  3278. 2:35:00so
  3279. 2:35:02register
  3280. 2:35:04media uh
  3281. 2:35:06conversions okay and we accept right
  3282. 2:35:09here
  3283. 2:35:10media which we don't need I think so on
  3284. 2:35:14this a media conversion uh we're going
  3285. 2:35:17to give it name this conversion is
  3286. 2:35:19thumbnail and let's give it width and
  3287. 2:35:21the width is going to be 100 for
  3288. 2:35:24thumbnail okay this is one conversion we
  3289. 2:35:27registered second is going to be
  3290. 2:35:31small let's give it width of
  3291. 2:35:3548 for different screen resolutions and
  3292. 2:35:39then we are going to have
  3293. 2:35:43large which is going to
  3294. 2:35:46be 1,200 okay and and we're going to
  3295. 2:35:50also have original which will be the
  3296. 2:35:52very large uh and we have now four
  3297. 2:35:56resolutions for each image and we have
  3298. 2:35:59to also start Q otherwise these images
  3299. 2:36:02will not be processed because these
  3300. 2:36:03images are actually processed inside the
  3301. 2:36:05Q but before I activate the Q we're
  3302. 2:36:09going to see the result without Q as
  3303. 2:36:13well now let's
  3304. 2:36:17delete those files
  3305. 2:36:20and click save now let's choose them
  3306. 2:36:26again uh in the database we can see that
  3307. 2:36:29there are no data because we deleted
  3308. 2:36:31that and click on Save changes that was
  3309. 2:36:34saved on the file system we see four
  3310. 2:36:37five and six as you see and right here
  3311. 2:36:41we see these three items okay and if we
  3312. 2:36:45expand this four five and six we only
  3313. 2:36:47see one image for each okay now let's
  3314. 2:36:50start
  3315. 2:36:52Q I'm going to bring up the
  3316. 2:36:55terminal so this is white this is
  3317. 2:36:57Artisan inside
  3318. 2:37:00Artisan let's call this
  3319. 2:37:03Q PHP
  3320. 2:37:06Artisan Q
  3321. 2:37:10listen okay now it started
  3322. 2:37:13processing perform conversion jobs it is
  3323. 2:37:17doing this processing it has completed
  3324. 2:37:21that and if we have a
  3325. 2:37:23look right here look at this so we have
  3326. 2:37:27these generated conversions right now we
  3327. 2:37:30have thumbnail small and large
  3328. 2:37:33conversions generated and if we check
  3329. 2:37:35file system storage up public for we see
  3330. 2:37:40the original one as well as the
  3331. 2:37:42conversions three different resolution
  3332. 2:37:44this is large this is small this is
  3333. 2:37:47thumbnail okay so we have different um
  3334. 2:37:50conversions already registered now what
  3335. 2:37:53I want to change is this path so here we
  3336. 2:37:57have the ID and we want to customize
  3337. 2:38:00this for
  3338. 2:38:02this uh I want to publish config
  3339. 2:38:06file let's come right here go
  3340. 2:38:10back go
  3341. 2:38:14back okay this is the part I want to
  3342. 2:38:17copy Media Library config this is what I
  3343. 2:38:20want to publish so this is Q which is
  3344. 2:38:23running I'm going to open another
  3345. 2:38:24terminal where I can put this right here
  3346. 2:38:26hit the enter the config file media Li
  3347. 2:38:30media library config file was published
  3348. 2:38:33now let's open this and find path uh
  3349. 2:38:40generator this one path generator which
  3350. 2:38:43uses um from this py media library
  3351. 2:38:47default path generator okay so what I
  3352. 2:38:51want to do is to create new class maybe
  3353. 2:38:56inside um app Services let's
  3354. 2:39:00define new
  3355. 2:39:02folder services and then inside here I
  3356. 2:39:06want to create new class custom path
  3357. 2:39:11generator and I think this might be also
  3358. 2:39:13mentioned in the documentation somewhere
  3359. 2:39:15I previously found that um in the
  3360. 2:39:18documentation or there was a video maybe
  3361. 2:39:20about this this should implements path
  3362. 2:39:22generator from SP media library okay
  3363. 2:39:26cool and we have to implement these
  3364. 2:39:28methods okay three methods get path get
  3365. 2:39:33path uh for conversions and get path for
  3366. 2:39:36responsive media okay so
  3367. 2:39:40now let's
  3368. 2:39:42return we're going to take the media uh
  3369. 2:39:45media
  3370. 2:39:46ID which is going to be one two three
  3371. 2:39:50and sequential number and we're going to
  3372. 2:39:52concatenate this with the
  3373. 2:39:55config of applications key and we are
  3374. 2:40:01going to
  3375. 2:40:02create md5 out of
  3376. 2:40:06it and then we're going to add slash now
  3377. 2:40:10let's copy these path
  3378. 2:40:13generated and here we need convergence
  3379. 2:40:21and here we need
  3380. 2:40:24responsive
  3381. 2:40:27images cool and we're going to use this
  3382. 2:40:30C custom path generator right now in
  3383. 2:40:33this media library instead of this so
  3384. 2:40:37let's call this custom path
  3385. 2:40:41generator cool now let me delete these
  3386. 2:40:48files and
  3387. 2:40:51again click on Save they must be deleted
  3388. 2:40:55from the file
  3389. 2:40:59system they were deleted from here maybe
  3390. 2:41:02because we Chang this
  3391. 2:41:05um custom path
  3392. 2:41:08generator yeah they stayed here anyway
  3393. 2:41:10we can delete them manually they will
  3394. 2:41:12not stay in the future now we can upload
  3395. 2:41:16these three images again
  3396. 2:41:24Okay click on Save the que is there it
  3397. 2:41:28is working it is going to catch and
  3398. 2:41:34process and here we see now this random
  3399. 2:41:38uh
  3400. 2:41:39md5 names okay so and here we
  3401. 2:41:43have I think I missed slash
  3402. 2:41:50extra slash
  3403. 2:41:52here and
  3404. 2:41:56here okay again we can delete them by
  3405. 2:42:00hand we can delete these from the file
  3406. 2:42:14system it is being uploaded click on
  3407. 2:42:17Save
  3408. 2:42:19and here we see now the conversions are
  3409. 2:42:22not yet generated now we see
  3410. 2:42:25them okay awesome and now the thing is
  3411. 2:42:30that how we can access those images and
  3412. 2:42:34for example display in the product
  3413. 2:42:36listing right here we want the thumbnail
  3414. 2:42:39to be displayed here as
  3415. 2:42:41well let's open product resource and
  3416. 2:42:46find table section and right here we are
  3417. 2:42:49going to use
  3418. 2:42:51spaty uh media
  3419. 2:42:56library why does not
  3420. 2:42:59autocomplete
  3421. 2:43:07spoty okay uh let me check this in the
  3422. 2:43:11documentation it should be out to
  3423. 2:43:12complete it Sparty media
  3424. 2:43:17library um image column and just like
  3425. 2:43:22this we need
  3426. 2:43:24to get it and put this right here
  3427. 2:43:28however
  3428. 2:43:30the that should be for images we're
  3429. 2:43:32going to give it
  3430. 2:43:35also
  3431. 2:43:37collection for images put a comma here
  3432. 2:43:42let's import this P media library it was
  3433. 2:43:45imported Okay cool so we're going to
  3434. 2:43:47take only first so we're going to call
  3435. 2:43:49limit one and we also want uh
  3436. 2:43:53conversion uh thumbnail okay thumb now
  3437. 2:43:58we save
  3438. 2:43:59this and have a look here and we see
  3439. 2:44:03from many images we can give it also
  3440. 2:44:06label label to be
  3441. 2:44:10image so we see an image right here if
  3442. 2:44:13we click on this and click on product
  3443. 2:44:15images we can change the ordering like
  3444. 2:44:18we can move this black want of the first
  3445. 2:44:19one click on Save changes and that will
  3446. 2:44:22be updated in the database as well and
  3447. 2:44:25if we click on the product listing now
  3448. 2:44:27we see Blake right here okay uh in the
  3449. 2:44:31database we
  3450. 2:44:33see order column right here which
  3451. 2:44:36defines the ordering for
  3452. 2:44:39that okay so we have product editing we
  3453. 2:44:43have a product images and I want to
  3454. 2:44:45change this icon right now
  3455. 2:44:49and that icon is used in the product
  3456. 2:44:54images uh because this is for edit
  3457. 2:44:58record this one has the view and
  3458. 2:45:02Navigation icon as
  3459. 2:45:04well and this icon is actually coming
  3460. 2:45:08from it's a hero icon o pencil square
  3461. 2:45:13right so we have to override this
  3462. 2:45:16Navigation icon
  3463. 2:45:19Navigation icon equals to something
  3464. 2:45:22let's give it hero icon o collection and
  3465. 2:45:25have a
  3466. 2:45:29look SVG by name O collection from set
  3467. 2:45:32not found okay so this is the thing so
  3468. 2:45:35filament PHP is
  3469. 2:45:39using set of icons and I want to find
  3470. 2:45:44this right now
  3471. 2:45:49uh let's check this in the package lock
  3472. 2:45:54um it is using this blade UI kit and
  3473. 2:45:59blade hero
  3474. 2:46:00icons so if we check right now what is
  3475. 2:46:03blade UI kit it is using only hero icons
  3476. 2:46:06at the moment I think it is not using
  3477. 2:46:10blade UI kit so it is not using any
  3478. 2:46:13other things from this play UI kit right
  3479. 2:46:20it is using it is only using uh it is
  3480. 2:46:23using blade icons as
  3481. 2:46:28well blade
  3482. 2:46:30icons and blade hero icons so this is
  3483. 2:46:34one two one one blade
  3484. 2:46:39icons okay so if we check these blade UI
  3485. 2:46:42icons we are going to see that this is a
  3486. 2:46:46huge list of
  3487. 2:46:51I want to find those icons huge list of
  3488. 2:46:55icons okay and this is a hero icon
  3489. 2:46:58example we can search for icons we see
  3490. 2:47:02more than 100,000 icons and if we search
  3491. 2:47:06for uh blade icons or if we search for
  3492. 2:47:10hero
  3493. 2:47:11icons that's it now we can filter inside
  3494. 2:47:15the hero icon list if we search for
  3495. 2:47:17image
  3496. 2:47:19uh it is not there uh
  3497. 2:47:22picture or photo maybe now we find this
  3498. 2:47:27okay we can take this
  3499. 2:47:30one which is hero icon C photo and this
  3500. 2:47:35is coming from these blade hero icons so
  3501. 2:47:38if you don't have these blade hero icons
  3502. 2:47:40installed in the project this is not
  3503. 2:47:42going to work if you have it it is going
  3504. 2:47:44to work so we're going to copy this hero
  3505. 2:47:46icon C photo open this product
  3506. 2:47:50images and paste this here
  3507. 2:47:54save refresh it and now we see product
  3508. 2:47:57images icon right here I think we can
  3509. 2:48:00change this uh product listing as
  3510. 2:48:06well uh maybe we can use some
  3511. 2:48:08list or
  3512. 2:48:11product not sure let's take this one
  3513. 2:48:15here ion s Square list let's get this
  3514. 2:48:19and it is going to be inserted inside
  3515. 2:48:22product
  3516. 2:48:26resource
  3517. 2:48:29okay refresh the page now this was
  3518. 2:48:32updated this was
  3519. 2:48:34updated and to talk a little bit
  3520. 2:48:37of uh spy media library as well I'm
  3521. 2:48:40going to open the table and have a look
  3522. 2:48:42so we see that this is a polymorphic
  3523. 2:48:44table and we have the following column
  3524. 2:48:48for the mode type and mod ID we have
  3525. 2:48:50this uh U ID also Associated to each
  3526. 2:48:53image we have the collection name which
  3527. 2:48:55is something we gave when we tried to
  3528. 2:48:58upload images inside this product images
  3529. 2:49:01right here we give it collection of
  3530. 2:49:03images and we have the name which is are
  3531. 2:49:06the which are the original names we have
  3532. 2:49:08the file names as well M type disk where
  3533. 2:49:11those files are located and the media
  3534. 2:49:13library also supports multiple discs you
  3535. 2:49:15can upload them on S3 or any other dis
  3536. 2:49:18you want and we have the conversion dis
  3537. 2:49:21this is also possible you can have the
  3538. 2:49:23original images saved in one dis but the
  3539. 2:49:25conversions into another disk we have
  3540. 2:49:27the size we can have additional
  3541. 2:49:30manipulations like add Watermark to the
  3542. 2:49:34images and save them as additional
  3543. 2:49:36things and so on we can also generate um
  3544. 2:49:40responsive variants for those images and
  3545. 2:49:43this is also possible right here they
  3546. 2:49:45will be saved right here we have the
  3547. 2:49:46order column created and up dated it we
  3548. 2:49:49are not going to use every single um
  3549. 2:49:52feature of this media library but what
  3550. 2:49:54we are using is quite good enough we
  3551. 2:49:56have the que started we generate the
  3552. 2:49:58conversions and we're going to use
  3553. 2:49:59different images different conversions
  3554. 2:50:02for different um in different cases in
  3555. 2:50:05our project quick puse if you're
  3556. 2:50:07watching this follow with me and if
  3557. 2:50:10you're enjoying this please leave a like
  3558. 2:50:13And subscribe now I'm going to start
  3559. 2:50:15working on product variations and this
  3560. 2:50:18is one of the most exciting thing for me
  3561. 2:50:22personally okay and also it's a quite
  3562. 2:50:24challenging compared to what we did so
  3563. 2:50:26far now first I'm going to create three
  3564. 2:50:30models PHP artisan make model one of
  3565. 2:50:34them is going to be
  3566. 2:50:37variation type variation type model uh
  3567. 2:50:41and I'm not going to generate migration
  3568. 2:50:43for that so it's just model variation
  3569. 2:50:47type we hit the ENT enter next I'm going
  3570. 2:50:50to generate second model which is going
  3571. 2:50:52to be variation type option variation
  3572. 2:50:56type has options okay I'm just going to
  3573. 2:51:00generate model again and then I'm going
  3574. 2:51:03to generate uh product variation and I'm
  3575. 2:51:06going to generate
  3576. 2:51:08migration for it as well and I'm going
  3577. 2:51:10to put inside that single migration file
  3578. 2:51:15all three tables related to product
  3579. 2:51:18variation
  3580. 2:51:20right
  3581. 2:51:22here okay now let's define on table we
  3582. 2:51:26have foring ID on the product it has
  3583. 2:51:31constrained to
  3584. 2:51:34products and we can add also index to
  3585. 2:51:40it and we're going to make this also
  3586. 2:51:43nullable not nullable sorry um Cascade
  3587. 2:51:47on delete
  3588. 2:51:49okay whenever product is deleted its
  3589. 2:51:52variation types should be also deleted
  3590. 2:51:56next is to Define string which is going
  3591. 2:52:00to be the variation type name and I'm
  3592. 2:52:03going to also define variation um type
  3593. 2:52:09type so variation type might
  3594. 2:52:13be sorry so this is going to be
  3595. 2:52:17variation
  3596. 2:52:19types okay variation type might be color
  3597. 2:52:23size as an example uh and color will
  3598. 2:52:28have a type of image and we're going to
  3599. 2:52:31have different images for different
  3600. 2:52:35colors well we might not have but we we
  3601. 2:52:38are going to implement support it's up
  3602. 2:52:40to wonder if they upload different
  3603. 2:52:42images for different colors or not but
  3604. 2:52:43we actually is going to give them
  3605. 2:52:46possibility to upload different images
  3606. 2:52:48for different
  3607. 2:52:50colors if the variation type is for
  3608. 2:52:52example radio we're going to just have
  3609. 2:52:55um simply radio type of options and I
  3610. 2:52:59think the best example um is um
  3611. 2:53:03Amazon
  3612. 2:53:05amazon.com so if we can access this I
  3613. 2:53:08will show you exactly what I mean
  3614. 2:53:13tfj now if we choose any of the dress
  3615. 2:53:19so now we have a size which is in this
  3616. 2:53:22case select type of variation and we
  3617. 2:53:26have color color is different variation
  3618. 2:53:29and we see that we have different images
  3619. 2:53:32for different colors okay so in this
  3620. 2:53:35case the size is has type of Select
  3621. 2:53:38color has type of image so this is
  3622. 2:53:41something like this we're going to do
  3623. 2:53:43okay next let me actually copy this two
  3624. 2:53:50times okay and next is going to be
  3625. 2:53:53variation type options okay so this has
  3626. 2:53:59foreign key on variation type
  3627. 2:54:03ID uh we can give it index uh
  3628. 2:54:06constrainted
  3629. 2:54:07on variation types and Cascade on delete
  3630. 2:54:11also works here whenever uh variation
  3631. 2:54:14type is deleted the variation type
  3632. 2:54:16options should also be deleted deleted
  3633. 2:54:19and we're going to have just the name of
  3634. 2:54:21this variation type option and I'm going
  3635. 2:54:24to delete the type and we also don't
  3636. 2:54:26need time stamp here and here so if the
  3637. 2:54:29variation type is color then the name
  3638. 2:54:32right here will be black what about
  3639. 2:54:35images so we're going to do images using
  3640. 2:54:38spaty media library again and we have
  3641. 2:54:41this table ready it's a polymorphic
  3642. 2:54:43table and we're going to Simply
  3643. 2:54:45associate that to the option model we're
  3644. 2:54:48going to do
  3645. 2:54:49this and finally we have this um
  3646. 2:54:53product
  3647. 2:54:55variations and we're going to have let
  3648. 2:54:58me remove these
  3649. 2:55:00fields so we are going to have um foring
  3650. 2:55:05ID on
  3651. 2:55:07product okay this product we can give it
  3652. 2:55:11again index
  3653. 2:55:14and constraint on products
  3654. 2:55:18move this
  3655. 2:55:21down and we can give it also Cascade on
  3656. 2:55:24delete
  3657. 2:55:26okay however we are going to all add one
  3658. 2:55:30Json
  3659. 2:55:32field which is going to be uh
  3660. 2:55:36variation
  3661. 2:55:39variation uh
  3662. 2:55:41type option
  3663. 2:55:44IDs okay this is how I'm going to call
  3664. 2:55:46this and that actually should be
  3665. 2:55:50required so I'm just going to make it
  3666. 2:55:51nullable and I will explain what that
  3667. 2:55:54table will contain
  3668. 2:55:57additionally for each variation type so
  3669. 2:56:01okay let me try to explain it so now we
  3670. 2:56:03have defined let's say two variations we
  3671. 2:56:06we have defined two variation types so
  3672. 2:56:10um size and color okay and we have I'm
  3673. 2:56:15going to open text file we Define two
  3674. 2:56:18variation types size and color okay and
  3675. 2:56:23we defined options for each of them like
  3676. 2:56:25size is small we have medium and we have
  3677. 2:56:30large and we also defined three
  3678. 2:56:33different colors or let's say two
  3679. 2:56:35different colors for Simplicity okay red
  3680. 2:56:38and
  3681. 2:56:39white okay now we have six combinations
  3682. 2:56:43of these products right so we have small
  3683. 2:56:48small red we
  3684. 2:56:51have
  3685. 2:56:53small uh White we have medium red okay
  3686. 2:56:57you get the idea okay I'm just going to
  3687. 2:56:59um simply leave only medium and small
  3688. 2:57:02and then we're going to duplicate this
  3689. 2:57:04and here we need medium and for each
  3690. 2:57:08each variation is a different type of
  3691. 2:57:11product and we need quantity and maybe
  3692. 2:57:15price Associated to it like this will
  3693. 2:57:18have quantity of 10 and price 15 is an
  3694. 2:57:21example so this will have quantity of 10
  3695. 2:57:23but price is 13 um and so on so for
  3696. 2:57:29each um so right here in this product
  3697. 2:57:33variations
  3698. 2:57:35table let's say that this is the product
  3699. 2:57:38variations
  3700. 2:57:40table so here we're going to have
  3701. 2:57:43information in the following format
  3702. 2:57:45obviously we're going to have the ID
  3703. 2:57:47primary key then we're going to have the
  3704. 2:57:49product ID okay product
  3705. 2:57:52first okay uh product first then
  3706. 2:57:57quantity 10 price is going to be 15 and
  3707. 2:58:02then we're going to have the variation
  3708. 2:58:04types uh variation type options more
  3709. 2:58:07specifically so we have four options
  3710. 2:58:10defined two for uh the size variation
  3711. 2:58:13type two for color and each of them will
  3712. 2:58:16have their own ID right right uh here
  3713. 2:58:19we're going to have two three and four
  3714. 2:58:24okay and in this product variations
  3715. 2:58:27table this is the primary key we can
  3716. 2:58:29omit
  3717. 2:58:30this first product 10 quantity uh 15
  3718. 2:58:35price and for the following variations
  3719. 2:58:38and that variations will be small red so
  3720. 2:58:42here will be written one and
  3721. 2:58:45three and now product
  3722. 2:58:49One Price 10 uh sorry quantity 10 price
  3723. 2:58:54uh we can give it this is product ID
  3724. 2:58:58then we have quantity then we have price
  3725. 2:59:03then we have
  3726. 2:59:05variations
  3727. 2:59:09now this is
  3728. 2:59:13it this is
  3729. 2:59:16quantity this is price
  3730. 2:59:21and this is product
  3731. 2:59:24variations and here we're going to have
  3732. 2:59:27variation of one and four small and
  3733. 2:59:33white and just like this for each
  3734. 2:59:37product if we Define prices and
  3735. 2:59:40quantities for each variation we're
  3736. 2:59:42going to have in this case four records
  3737. 2:59:45in the product
  3738. 2:59:47variations I hope this makes sense
  3739. 2:59:49that's why we Define this variation type
  3740. 2:59:52option IDs to be Json and we need to
  3741. 2:59:55Define um integer quantity which can be
  3742. 3:00:02nullable I guess and we're going to
  3743. 3:00:08Define
  3744. 3:00:10um decimal price if it's null it means
  3745. 3:00:13that um we're going to pick up the
  3746. 3:00:15default quantity or it should not be
  3747. 3:00:17null in my op opinion so if we Define
  3748. 3:00:19the
  3749. 3:00:20variation yeah if we Define quantity
  3750. 3:00:22null it means it's probably unlimited
  3751. 3:00:25okay and that's
  3752. 3:00:27it so we're we're going to leave this
  3753. 3:00:30quantity nullable for the price we're
  3754. 3:00:32going to make it like 20 on four and I'm
  3755. 3:00:35going to make this nullable as
  3756. 3:00:39well if the price is not specified it
  3757. 3:00:44means that uh we're going to pick up the
  3758. 3:00:46default price which is saved in the
  3759. 3:00:48products table okay now we have these
  3760. 3:00:52tables ready now let's execute migration
  3761. 3:00:55PHP Artisan
  3762. 3:00:59migrate okay the migration has been
  3763. 3:01:01applied so three more tables should be
  3764. 3:01:04created in the database we can
  3765. 3:01:05synchronize this and have a look product
  3766. 3:01:09product variations we say variation
  3767. 3:01:12types and variation type
  3768. 3:01:15options now let's close the data and we
  3769. 3:01:18are going to add new page into the
  3770. 3:01:21product area right here and this is
  3771. 3:01:25going to be product variation
  3772. 3:01:28types let's go into up
  3773. 3:01:32filament product resource and I'm going
  3774. 3:01:35to copy these product
  3775. 3:01:39images that should be product
  3776. 3:01:43variation
  3777. 3:01:46types where we're going to click on add
  3778. 3:01:49to this it extends this edit record
  3779. 3:01:51which is fine uh product variation types
  3780. 3:01:55we're going to remove this schema we
  3781. 3:01:58don't need this let's go into product
  3782. 3:02:03resource open that scroll down below
  3783. 3:02:06find
  3784. 3:02:09the get
  3785. 3:02:11pages and I'm going to duplicate this
  3786. 3:02:13and this is going to be variation types
  3787. 3:02:19variation types and here let's call this
  3788. 3:02:23variation types as
  3789. 3:02:28well product variation types now I'm
  3790. 3:02:32going to save this and we're going to
  3791. 3:02:35edit right here as well product
  3792. 3:02:38variation types class now if I refresh
  3793. 3:02:41the page we're going to see this product
  3794. 3:02:43variation types here uh on that we're
  3795. 3:02:46going to change the image we're going to
  3796. 3:02:47do this later but right now we see this
  3797. 3:02:49empty
  3798. 3:02:51page I'm going to also Define another
  3799. 3:02:55enm this is going to be make enm inside
  3800. 3:03:00enum's folder
  3801. 3:03:03product variation oops we need Pascal
  3802. 3:03:07case product
  3803. 3:03:08variation types inum so product
  3804. 3:03:12variation types is going to be the enm
  3805. 3:03:15um
  3806. 3:03:18yeah I
  3807. 3:03:23think types
  3808. 3:03:26enum let's hit the
  3809. 3:03:28enter uh that was created let's open now
  3810. 3:03:32inside
  3811. 3:03:35enms
  3812. 3:03:40oops okay make in
  3813. 3:03:44um yeah that's my bed product status enm
  3814. 3:03:48I created this in a nested enms folder
  3815. 3:03:52here which is kind of a problem not a
  3816. 3:03:55problem but not an ideal as well so we
  3817. 3:03:58are using this in couple of places
  3818. 3:04:00obviously because we are using PHP storm
  3819. 3:04:02we can simply take this out from here
  3820. 3:04:04and it's going to do refactoring let's
  3821. 3:04:07move this out as well and we can delete
  3822. 3:04:10this enams
  3823. 3:04:11folder and now we're going to
  3824. 3:04:14Define couple of cases here I'm going to
  3825. 3:04:17Define
  3826. 3:04:18um basically three cases or two cases um
  3827. 3:04:23case we can have
  3828. 3:04:26select case select we're going to have
  3829. 3:04:30case radio and we're going to have case
  3830. 3:04:33uh
  3831. 3:04:35image and let me Define public static
  3832. 3:04:39function labels which should return
  3833. 3:04:43array and we are going to return self
  3834. 3:04:50select and let's use value here
  3835. 3:04:54duplicate this two more
  3836. 3:04:57times and here we're going to have radio
  3837. 3:05:00and here we are going to have
  3838. 3:05:03image
  3839. 3:05:05radio and image now let's open this
  3840. 3:05:10product variation types
  3841. 3:05:13page and find this form and we are going
  3842. 3:05:16to implement this okay
  3843. 3:05:19so this is how I am going to do it on
  3844. 3:05:23the following page I am going to use
  3845. 3:05:25filament repeater so we can have a look
  3846. 3:05:28in the filament repeater
  3847. 3:05:30documentation uh and if we have some
  3848. 3:05:32images that's going to be good we're
  3849. 3:05:34going to have
  3850. 3:05:38repeater we're going to have some
  3851. 3:05:40understanding this is it okay so this is
  3852. 3:05:42a repeater example and uh we can add
  3853. 3:05:46more blocks so the repeater can have um
  3854. 3:05:49add new Option or add new block button
  3855. 3:05:54right here we have this add to members
  3856. 3:05:56and in the following way we will be able
  3857. 3:05:58to add new variation types so our goal
  3858. 3:06:02is to add variation types and for each
  3859. 3:06:06type we are going to add variation type
  3860. 3:06:09options as well so we're going to have a
  3861. 3:06:11repeater we're going to use this
  3862. 3:06:13repeater so repeater make for variation
  3863. 3:06:16types and this variation types needs to
  3864. 3:06:19be defined on products product.php we
  3865. 3:06:23have Department category let's define as
  3866. 3:06:27many variation types and here we're
  3867. 3:06:31going to use variation type class okay
  3868. 3:06:36cool now we're going to Define
  3869. 3:06:39relationship uh this is because this is
  3870. 3:06:42a repeater we Define the relationship
  3871. 3:06:43we're going to make this collapsible the
  3872. 3:06:46default items is going to be one we're
  3873. 3:06:48going to add the action label add new
  3874. 3:06:50variation type and we're going to
  3875. 3:06:53display the content into two columns uh
  3876. 3:06:55we're going to stretch the entire
  3877. 3:06:57repeater into two
  3878. 3:06:58columns and we're going to define the
  3879. 3:07:00schema for the repeater itself okay so
  3880. 3:07:04we're going to have um inside these
  3881. 3:07:06variation types each variation type
  3882. 3:07:09pretty much is going to have name it
  3883. 3:07:11must be required it will have a type
  3884. 3:07:14which will be a drop- down and we are
  3885. 3:07:16going to use this product variation um
  3886. 3:07:19type enm uh did I call this correctly
  3887. 3:07:22product variation types enm I call this
  3888. 3:07:25product variation types enm I should
  3889. 3:07:28call this type
  3890. 3:07:30enm uh let's do the
  3891. 3:07:36refactoring okay so next we're going to
  3892. 3:07:39we're going to make this required um
  3893. 3:07:42then so we have name and type for each
  3894. 3:07:45variation type but we're going to Define
  3895. 3:07:48also options and this is going to be
  3896. 3:07:50nested repeater okay and we're going to
  3897. 3:07:53also
  3898. 3:07:54open uh variation type and we are going
  3899. 3:07:57to Define right here has many options so
  3900. 3:08:01each variation type has many product
  3901. 3:08:07variation uh or variation type
  3902. 3:08:11options like this and the foreign key
  3903. 3:08:15name is variation type it
  3904. 3:08:18PHP store helps okay next let's open
  3905. 3:08:24this page and continue so we have this
  3906. 3:08:26relationship on options we're going to
  3907. 3:08:28make this collapsible and we're going to
  3908. 3:08:30Define schema and we're going to also
  3909. 3:08:33give it column span two on the repeater
  3910. 3:08:36inside schema we're going to have name
  3911. 3:08:38each option will have name uh with
  3912. 3:08:40column span two and each option will
  3913. 3:08:45have might have images
  3914. 3:08:48so even
  3915. 3:08:50though uh we might Define option called
  3916. 3:08:53for size uh even size might have some
  3917. 3:08:59additional images so we are using Spa
  3918. 3:09:01media library right here for images we
  3919. 3:09:05are going to give it filter of image
  3920. 3:09:07multiple openable panel layout grid
  3921. 3:09:10collection is going to be images
  3922. 3:09:12reorderable up and files preserve file
  3923. 3:09:15names columns p and so on so just like
  3924. 3:09:19this we defined the uh schema for form
  3925. 3:09:23now let's import this text input we
  3926. 3:09:27import the repeater we import the select
  3927. 3:09:32and we're going to import this product
  3928. 3:09:33variation type let me think so we have
  3929. 3:09:38permissions product status and um rules
  3930. 3:09:42enam yeah so it's a kind of inconsistent
  3931. 3:09:45so sometimes we have the plural form
  3932. 3:09:48permissions andam and sometimes we have
  3933. 3:09:50in singular form I think singular makes
  3934. 3:09:55sense product variation type in I'm
  3935. 3:09:58going to leave this singular okay now
  3936. 3:10:01we're going to import this
  3937. 3:10:03and now the last thing is to
  3938. 3:10:07open product
  3939. 3:10:10variation type option because uh that
  3940. 3:10:15option is used right here here make
  3941. 3:10:18options with relationship and it each
  3942. 3:10:20option has this images so each option
  3943. 3:10:25should
  3944. 3:10:26Implement uh his
  3945. 3:10:28media and we're going to use interacts
  3946. 3:10:32with media here as well and we're going
  3947. 3:10:35to also
  3948. 3:10:37Define the uh variations the
  3949. 3:10:41conversions so I'm going to copy this
  3950. 3:10:45function and put them right
  3951. 3:10:50here now it's time to have a
  3952. 3:10:58look what's
  3953. 3:11:01this okay add variation
  3954. 3:11:07type Let me refresh
  3955. 3:11:11it
  3956. 3:11:16um okay okay if I simply remove this
  3957. 3:11:19schema this is repeater okay default
  3958. 3:11:22items is
  3959. 3:11:24one why don't we see this one
  3960. 3:11:29item anyway so now let's define the type
  3961. 3:11:33we're going to see
  3962. 3:11:36color has a type of image now let's
  3963. 3:11:40define options so the first option is
  3964. 3:11:45black and we're going to attach an image
  3965. 3:11:48to
  3966. 3:11:49it collapse that and another option
  3967. 3:11:54which is going to be
  3968. 3:11:58blue upload that and add another option
  3969. 3:12:03which is going to be
  3970. 3:12:06purple and choose
  3971. 3:12:08that so we
  3972. 3:12:10defined option color with three options
  3973. 3:12:14variation type color with three options
  3974. 3:12:17now I'm going to add new variation type
  3975. 3:12:19which is going to be size now this is
  3976. 3:12:23radio and we're going to
  3977. 3:12:25Define uh
  3978. 3:12:28small add another option this is going
  3979. 3:12:31to be
  3980. 3:12:33medium add another option this is going
  3981. 3:12:36to be large now I'm going to hit on Save
  3982. 3:12:39changes and we
  3983. 3:12:42see okay variation types has no column
  3984. 3:12:46named update it that's correct we are
  3985. 3:12:50going to open variation type and we are
  3986. 3:12:54going to disable time
  3987. 3:12:57stamps we're going to disable time
  3988. 3:12:59stamps on variation type options as
  3989. 3:13:04well uh time stamps equals
  3990. 3:13:08false okay now let's click on Save
  3991. 3:13:12again it looks like something was saved
  3992. 3:13:15and we're going to see what happened
  3993. 3:13:19here we see again blue image but let's
  3994. 3:13:23see in the database so we have variation
  3995. 3:13:26types okay two variation type was added
  3996. 3:13:29here which is awesome inside variation
  3997. 3:13:32type options we have totally six options
  3998. 3:13:36this is for the first variation type
  3999. 3:13:38this is for the second variation type
  4000. 3:13:40this is also good inside
  4001. 3:13:43media now there should be images for
  4002. 3:13:50for blue for the
  4003. 3:13:52second for first second and third there
  4004. 3:13:55should be
  4005. 3:13:56records okay look at this so for the
  4006. 3:13:59model variation type option for first
  4007. 3:14:02second and third they are our records
  4008. 3:14:06and we also have generated
  4009. 3:14:09conversions and this is pretty
  4010. 3:14:12cool so if we refresh the page we see
  4011. 3:14:16the data is also
  4012. 3:14:21prepopulated
  4013. 3:14:25color yeah this is this is cool I'm
  4014. 3:14:28going to remove this this is purple
  4015. 3:14:30let's attach
  4016. 3:14:35purple and click on Save changes that
  4017. 3:14:39was
  4018. 3:14:43saved refresh it and
  4019. 3:14:48and okay additional Improvement will be
  4020. 3:14:52whenever we don't choose right here
  4021. 3:14:54image um and we choose radio we probably
  4022. 3:14:58should not display the following images
  4023. 3:15:01component um and that's going to be an
  4024. 3:15:04improvement which we can add later um
  4025. 3:15:08but so far this
  4026. 3:15:10looks really good now let's adjust this
  4027. 3:15:13icon for the product variation types I'm
  4028. 3:15:17not sure what icon would apply to
  4029. 3:15:20this something that is many
  4030. 3:15:24like uh nothing something maybe related
  4031. 3:15:28to
  4032. 3:15:33list okay I don't know maybe we can
  4033. 3:15:35choose this one hero icon aim numbered
  4034. 3:15:40list let's open this variation types
  4035. 3:15:43scroll up we're going to change this
  4036. 3:15:48and we can also assign title to it it's
  4037. 3:15:51it's uh one of the greatest things I
  4038. 3:15:53love in PHP stor is that whenever the
  4039. 3:15:56class overwrites
  4040. 3:15:58um something um else and they we we try
  4041. 3:16:03to use a property from the parent class
  4042. 3:16:06it autocompletes this for me so I know
  4043. 3:16:08that there's something like title so I
  4044. 3:16:12have to I start typing it how to complet
  4045. 3:16:14this and now using this full I
  4046. 3:16:16completion it gives us the following
  4047. 3:16:20text variation
  4048. 3:16:22types now refresh the page we see
  4049. 3:16:25variation types right here what is
  4050. 3:16:30this oh this is I know what is this so
  4051. 3:16:34this is coming from here because this is
  4052. 3:16:36variation types it Associated label to
  4053. 3:16:39it but the entire page basically is for
  4054. 3:16:42variation type so maybe we simply need
  4055. 3:16:46to
  4056. 3:16:47remove the label if that works like
  4057. 3:16:51this okay cool variation types and here
  4058. 3:16:54we have the
  4059. 3:16:55list and here we have the
  4060. 3:16:58options if we go in the product images
  4061. 3:17:01this has the title edit product we're
  4062. 3:17:04going to change this product
  4063. 3:17:11images
  4064. 3:17:14title images
  4065. 3:17:17cool
  4066. 3:17:19refresh okay we see images right here I
  4067. 3:17:21think we need to remove
  4068. 3:17:23this so we are going to give it label
  4069. 3:17:28equals
  4070. 3:17:32false nice okay now we did one part of
  4071. 3:17:38the product
  4072. 3:17:41variations
  4073. 3:17:43that was The Following part so we Define
  4074. 3:17:47size and small and medium color red and
  4075. 3:17:49white and we even uploaded images but
  4076. 3:17:52now this is the part what is remaining
  4077. 3:17:55on the product we're going to define the
  4078. 3:17:58combination of the variation options
  4079. 3:18:00what we have small red small white
  4080. 3:18:04medium red medium white in their
  4081. 3:18:07Associated quantity
  4082. 3:18:09price
  4083. 3:18:10um and yeah that's it and if we have
  4084. 3:18:14three variations like we have size
  4085. 3:18:17color and something else like if we are
  4086. 3:18:20speaking about the keyboard the keyboard
  4087. 3:18:22might have color might have design
  4088. 3:18:25whether it is USB or uh or another
  4089. 3:18:29interface and also compatibility whether
  4090. 3:18:32it's for like Xbox or whatever okay so
  4091. 3:18:37we might have more than two combinations
  4092. 3:18:39in which case we're going to make it
  4093. 3:18:43like the result is going to be um even
  4094. 3:18:46um result will have even more
  4095. 3:18:49records okay but this is something we're
  4096. 3:18:52going to do uh and right now I'm going
  4097. 3:18:54to comment all the things what I made so
  4098. 3:18:57far I'm going to create one more page
  4099. 3:19:00right here which is going to be to
  4100. 3:19:03Define quantities and prices for the
  4101. 3:19:07combination of these variation types but
  4102. 3:19:11before that let me actually reduce this
  4103. 3:19:13navigation size right here I'm going to
  4104. 3:19:15open admin pan Chanel
  4105. 3:19:19provider sidebar width by default this
  4106. 3:19:23is 20 Ram I'm going to reduce this into
  4107. 3:19:2514 Ram refresh it okay much better now
  4108. 3:19:30let's define new
  4109. 3:19:33page let's open up filament product
  4110. 3:19:37resources and I'm going to copy this
  4111. 3:19:40product variation types and let's call
  4112. 3:19:43these product variations
  4113. 3:19:48copy and paste hit on ADD product
  4114. 3:19:51variations
  4115. 3:19:53okay
  4116. 3:19:55variations we're going to change the
  4117. 3:19:57hero icon the icon basically let's let's
  4118. 3:20:01choose this
  4119. 3:20:08one okay I'm going to remove everything
  4120. 3:20:11at the moment from form we're going to
  4121. 3:20:13have something custom right here
  4122. 3:20:18and let me open product resource scroll
  4123. 3:20:22down below find
  4124. 3:20:25that get Pages section duplicate these
  4125. 3:20:30variations and we're going to use
  4126. 3:20:32product variations
  4127. 3:20:37here okay and we're going to add this
  4128. 3:20:42product variations
  4129. 3:20:47here as
  4130. 3:20:49well okay so let me remove this page
  4131. 3:20:52import that
  4132. 3:20:55cool now let's refresh the page and we
  4133. 3:20:58have this variations here I'm going to
  4134. 3:21:00click on this and it displays this empty
  4135. 3:21:02page here I want to display the
  4136. 3:21:05combination of all available variation
  4137. 3:21:09types and let's see an example on the
  4138. 3:21:13database I'm going to open variation
  4139. 3:21:16type of options table and we see that we
  4140. 3:21:18have two variation types this is for
  4141. 3:21:21color this is for size and each of them
  4142. 3:21:24has three variation type options so
  4143. 3:21:28speaking about the combination of all of
  4144. 3:21:30them which is also called Cartesian
  4145. 3:21:32product so we have nine combinations of
  4146. 3:21:36this I'm going to open new text scratch
  4147. 3:21:39file let's move this on the right side
  4148. 3:21:42and have a look so we have I'm I'm just
  4149. 3:21:44going to use first two letters like
  4150. 3:21:47black so we have black purple we have
  4151. 3:21:52black sorry black small not purple black
  4152. 3:21:57small we have black medium we have black
  4153. 3:22:01large we have
  4154. 3:22:04blue uh it's also BL so let's just use B
  4155. 3:22:08so this is blue uh blue
  4156. 3:22:11small blue
  4157. 3:22:13medium blue large
  4158. 3:22:16all right and we also have purple small
  4159. 3:22:19purple medium purple large so totally as
  4160. 3:22:22you probably guessed we have nine
  4161. 3:22:25combinations so 3 * three and what we
  4162. 3:22:28want is to display all these
  4163. 3:22:31combinations and next to the next to
  4164. 3:22:34each combination we are going to also
  4165. 3:22:37add quantity and price input Fields so
  4166. 3:22:42how many items what is the quantity
  4167. 3:22:46of uh black variation type with small
  4168. 3:22:51size so let's say that the vendor has
  4169. 3:22:53black small 10 and the price is 15 it
  4170. 3:22:58has black medium nine and the price is
  4171. 3:23:0111 whatever so you have ability to
  4172. 3:23:04configure the quantity and price for
  4173. 3:23:06each variation type and so far this is
  4174. 3:23:10the most challenging part we have done
  4175. 3:23:13and just I want to follow with me and be
  4176. 3:23:16just be patient because you might not
  4177. 3:23:19immediately understand everything I will
  4178. 3:23:22explain it and I will probably re
  4179. 3:23:25explain it second times okay so this is
  4180. 3:23:28good uh we can just move this to the
  4181. 3:23:30right side whenever we want it um now
  4182. 3:23:34I'm going to go into product variations
  4183. 3:23:38okay and I want to override filament
  4184. 3:23:41method which is called mutate form data
  4185. 3:23:45before fill so we get the following data
  4186. 3:23:48and we want to do the mutation before it
  4187. 3:23:52is filled okay so now what we are going
  4188. 3:23:56to
  4189. 3:23:57do uh first we're going to return the
  4190. 3:23:59data right here but we're going to put
  4191. 3:24:01something inside the data so we are
  4192. 3:24:03going to get uh the variations all the
  4193. 3:24:06variations what we have so far and this
  4194. 3:24:09record in this case refers to the edit
  4195. 3:24:12record and this record is product so
  4196. 3:24:15product has relation into variations
  4197. 3:24:18which is called in our database uh
  4198. 3:24:20product variations just let's make sure
  4199. 3:24:24we have this relation defined in product
  4200. 3:24:27PHP we have variation types but we don't
  4201. 3:24:30have variations so let's define as many
  4202. 3:24:34variations and this is going to be
  4203. 3:24:37product variation and we're going to set
  4204. 3:24:40up with a column product ID the foring
  4205. 3:24:43key is the product ID okay now we have
  4206. 3:24:45the variations and from product This
  4207. 3:24:47Record refers to product from product we
  4208. 3:24:50can access to variations and we need an
  4209. 3:24:53array so we just need a plain array out
  4210. 3:24:55of these variations we don't want
  4211. 3:24:57collection we're going to work on the
  4212. 3:24:59plain array next now this is the
  4213. 3:25:02interesting part next we are going to
  4214. 3:25:04generate some data and put this inside
  4215. 3:25:07data
  4216. 3:25:08variations and for this we are going to
  4217. 3:25:10create new method merge Cartesian with
  4218. 3:25:15existing so this is how I am going to
  4219. 3:25:18call my method and this will accept two
  4220. 3:25:21arguments This Record variation types
  4221. 3:25:24and we know that the variation types are
  4222. 3:25:27just color and size nothing else
  4223. 3:25:32okay we are going to merge this with the
  4224. 3:25:35variation types the first argument is
  4225. 3:25:37the variation types we're going to pass
  4226. 3:25:39and the second argument is going to be
  4227. 3:25:41all the variations we already have in
  4228. 3:25:43the database for this product and this
  4229. 3:25:46is actually necessary the merging is
  4230. 3:25:49actually necessary for the following
  4231. 3:25:51case so far we saw that we have nine
  4232. 3:25:55combinations
  4233. 3:25:57totally and the um ninth one is actually
  4234. 3:26:01so purple small purple medium and purple
  4235. 3:26:07large okay now let's say that vendor
  4236. 3:26:12decided to add a new size which is going
  4237. 3:26:15to be extra large so that totally
  4238. 3:26:19changes the picture so if so far we have
  4239. 3:26:22nine variations if we add one more
  4240. 3:26:25variation right here so then we're going
  4241. 3:26:27to have 12 variations so if I add extra
  4242. 3:26:31large here and let's say that we
  4243. 3:26:33Associated some prices and quantities
  4244. 3:26:36for each variation and let's say for all
  4245. 3:26:38of them the quantity is 10 and the price
  4246. 3:26:40is 20 or
  4247. 3:26:42$19 okay so we added price in quantity
  4248. 3:26:47for each variation now so this is going
  4249. 3:26:50to be called existing data which will
  4250. 3:26:54be right here these record variations
  4251. 3:26:58and that data will be saved inside
  4252. 3:27:01product variations table where we have
  4253. 3:27:04the primary key we have the product ID
  4254. 3:27:06we have these variation type option IDs
  4255. 3:27:09in which case we will have the ID for
  4256. 3:27:12black ID for small so this um IDs let's
  4257. 3:27:18actually have a look again inside
  4258. 3:27:20options so the ID for Blake is one if I
  4259. 3:27:23interpret this in a different way if I
  4260. 3:27:27simply copy and paste here ID for
  4261. 3:27:30black is going to be one ID for small is
  4262. 3:27:34four so this is going to be the option
  4263. 3:27:37IDs inside product variations right here
  4264. 3:27:41variation type option IDs right so one
  4265. 3:27:45and four and here we're going to have
  4266. 3:27:47one and
  4267. 3:27:50five here we're going to have one and
  4268. 3:27:54six then here we're going to have what's
  4269. 3:27:57the ID for blue it is two what's the ID
  4270. 3:28:00for small it is four so here we're going
  4271. 3:28:02to have
  4272. 3:28:04oops two and four and so on I'm not
  4273. 3:28:08going to do this for all of them but
  4274. 3:28:10this is how the data will be saved
  4275. 3:28:12inside product variations okay and right
  4276. 3:28:15here in this product variations when we
  4277. 3:28:17get the existing variations this is
  4278. 3:28:19going to be the ex existing data into
  4279. 3:28:22the database table but if we added new
  4280. 3:28:26variation type let's say extra large
  4281. 3:28:28that changes the picture so right here
  4282. 3:28:31we're going to
  4283. 3:28:32have additional black extra large but it
  4284. 3:28:36doesn't have price and quantity here
  4285. 3:28:39we're going to have blue extra large
  4286. 3:28:42it's not going to have price and
  4287. 3:28:44quantity again and we're going to have
  4288. 3:28:45purple
  4289. 3:28:47extra large and it is not going to have
  4290. 3:28:49price and quantity however if it doesn't
  4291. 3:28:51have price and quantity I want to set
  4292. 3:28:54the default price and quantity that is
  4293. 3:28:58available inside the products table okay
  4294. 3:29:02and this is what this merge cartisian
  4295. 3:29:04with existing is going to do so I'm just
  4296. 3:29:06going to generate such type of data
  4297. 3:29:10without prices so in in this
  4298. 3:29:13case without this data so I will
  4299. 3:29:16generate the following
  4300. 3:29:19data but I know that in the database I
  4301. 3:29:23already have some data for the following
  4302. 3:29:25things for the first three for this and
  4303. 3:29:28for this as well so then I'm going to do
  4304. 3:29:31the
  4305. 3:29:32merging and right here I will get the
  4306. 3:29:35following result and I'm going to plus
  4307. 3:29:36right here here and here at the default
  4308. 3:29:39values okay I think right now we can
  4309. 3:29:42continue enough talking and we're going
  4310. 3:29:44to create that merge C Tian with
  4311. 3:29:47existing function so let's define this
  4312. 3:29:50function it is going to accept these two
  4313. 3:29:52arguments variation types and existing
  4314. 3:29:55data and now we are going to get the
  4315. 3:29:59default quantity which is going to be
  4316. 3:30:00the product quantity and we're going to
  4317. 3:30:03get the default price which is going to
  4318. 3:30:05be product price then we're going to
  4319. 3:30:08create one more function which is going
  4320. 3:30:10to be the cartisian
  4321. 3:30:11product that cartisian product is going
  4322. 3:30:14to take the variation typ types default
  4323. 3:30:17quantity and default price and this is
  4324. 3:30:20going to
  4325. 3:30:21generate such type of data imagine that
  4326. 3:30:24we don't have anything in this T table
  4327. 3:30:28and this is our case right now we don't
  4328. 3:30:30have anything in this table so what we
  4329. 3:30:32want is to generate such type of data
  4330. 3:30:35let's actually do the following so we
  4331. 3:30:38want to generate such type of
  4332. 3:30:41data
  4333. 3:30:43but we want it to generated with the
  4334. 3:30:47default quantity and default price and
  4335. 3:30:50the default quantity and default price
  4336. 3:30:51as I mentioned is going to be taken from
  4337. 3:30:53product so right here we're going to
  4338. 3:30:55have default quantity from the product
  4339. 3:30:57let's say 10 and the default price will
  4340. 3:30:59be 90 so this
  4341. 3:31:02is this is the format of the data but
  4342. 3:31:05instead of BL and S we're going to have
  4343. 3:31:08these IDs option IDs this is the format
  4344. 3:31:12we're going to
  4345. 3:31:13generate with this cartisian
  4346. 3:31:15product function okay and if we assume
  4347. 3:31:19that we already have such type of data
  4348. 3:31:21generated more
  4349. 3:31:23specifically I think I'm going to show
  4350. 3:31:26the Json structure of the data or I'm
  4351. 3:31:29going to show the Json example but uh
  4352. 3:31:31you can easily interpret this into an
  4353. 3:31:33associative array we can also create
  4354. 3:31:35associative array but I think Json is
  4355. 3:31:37easier to actually work with
  4356. 3:31:39so we're going to have array and we're
  4357. 3:31:43going to have um bunch of object
  4358. 3:31:46the variation types okay so let's take
  4359. 3:31:49the first one so this will have
  4360. 3:31:52variation type ID uh or variation type
  4361. 3:31:56one okay so and this will correspond to
  4362. 3:32:02some data so it is going to have like ID
  4363. 3:32:06of the option which is going to be
  4364. 3:32:09whatever is the option ID uh let's check
  4365. 3:32:13right here ID of the option let's start
  4366. 3:32:16with black so ID of the option is one
  4367. 3:32:19it's going to have the name of the
  4368. 3:32:21option which is going to be black and
  4369. 3:32:24we're going to also put the type
  4370. 3:32:27variation type this is going to be for
  4371. 3:32:30color so variation type one now here
  4372. 3:32:34we're going to have variation type two
  4373. 3:32:37and
  4374. 3:32:38variation um type no we're going we we
  4375. 3:32:41have only two variation types in the
  4376. 3:32:43specific case so we're going to have
  4377. 3:32:44variation type two
  4378. 3:32:46um here we're going to have
  4379. 3:32:49small uh which is size ID or and
  4380. 3:32:55additionally we're going to have here
  4381. 3:32:59quantity let's say 10 and price let's
  4382. 3:33:04say
  4383. 3:33:0519 so this is now one variation uh type
  4384. 3:33:10object and imagine that we have all the
  4385. 3:33:13other variation type so totally we're
  4386. 3:33:17going to have such type of object nine
  4387. 3:33:20in our case because we have the
  4388. 3:33:22combination gives us basical nine so
  4389. 3:33:24here we have this
  4390. 3:33:26six 7 8 and nine and imagine that we
  4391. 3:33:31just change right here the ID the
  4392. 3:33:35name and simply duplicate this part
  4393. 3:33:39like
  4394. 3:33:412
  4395. 3:33:433 4
  4396. 3:33:47five
  4397. 3:33:486
  4398. 3:33:507
  4399. 3:33:528 and
  4400. 3:33:54nine so if we check the text file again
  4401. 3:33:56so if we remove this extra large we
  4402. 3:33:58don't have it uh we have uh this nine
  4403. 3:34:02variations so far and we started with
  4404. 3:34:06this one one and
  4405. 3:34:08four and it is going to end with
  4406. 3:34:11whatever is the ID for purple and the ID
  4407. 3:34:14for large so three and six so imagine
  4408. 3:34:19that we fill that data with the correct
  4409. 3:34:21IDs right here and finally the last
  4410. 3:34:24record we will have variation type one
  4411. 3:34:28which is this variation type one will
  4412. 3:34:31have purple which is
  4413. 3:34:34three the name is purple its color and
  4414. 3:34:39variation type two is large so ID six
  4415. 3:34:45it is large and its type is size and
  4416. 3:34:50this is the
  4417. 3:34:51format uh that method right here the
  4418. 3:34:54cartisian product method should return
  4419. 3:34:58okay let's collapse the right side again
  4420. 3:35:01and let's continue right here so this is
  4421. 3:35:03going to return such type of array
  4422. 3:35:06associative array no it's not
  4423. 3:35:08associative it's a plain array of um sub
  4424. 3:35:11arrays where each sub array is already
  4425. 3:35:14associative array
  4426. 3:35:17cool now let's continue so we take that
  4427. 3:35:20cartisian product and we want to add we
  4428. 3:35:23want to merge this with existing um
  4429. 3:35:27existing data right here and finally
  4430. 3:35:29we're going to have the similar type of
  4431. 3:35:32output but instead of this default
  4432. 3:35:35quantity 10 and 19 which we provide rate
  4433. 3:35:39here default quantity and default price
  4434. 3:35:41which is taken from the product instead
  4435. 3:35:43of this 10 and 19 every time we are
  4436. 3:35:47going to override the data which already
  4437. 3:35:50exists in the database so in our
  4438. 3:35:52specific case there's no data in the
  4439. 3:35:54database but whenever there is some data
  4440. 3:35:57and we're implementing update then the
  4441. 3:36:00updated data will overwrite this this 10
  4442. 3:36:03and
  4443. 3:36:0519 okay continue we're going to start
  4444. 3:36:08iterating of this cartisian product as
  4445. 3:36:12product then we're going to start
  4446. 3:36:14extracting the option IDs from the
  4447. 3:36:18current uh product combination okay so
  4448. 3:36:21we're going to just convert that product
  4449. 3:36:24which looks like this into a collection
  4450. 3:36:28okay so this going to be converted into
  4451. 3:36:30collection next we are going to do
  4452. 3:36:34filtering on this so we get the value
  4453. 3:36:37and we get the key because this is a
  4454. 3:36:39associative array what I have selected
  4455. 3:36:41right now on the right side when we
  4456. 3:36:44convert this into collection and start
  4457. 3:36:45filtering we have value and key and then
  4458. 3:36:49during filtering we are going to only
  4459. 3:36:51take those keys which starts with
  4460. 3:36:55variation type so we have quantity and
  4461. 3:36:57price here as well but we want to take
  4462. 3:37:00this and this so we are filtering which
  4463. 3:37:02starts with variation type next I want
  4464. 3:37:06to call map so we filtered and left only
  4465. 3:37:09these
  4466. 3:37:10two then we call map on this and we just
  4467. 3:37:14take the ID and these are the option IDs
  4468. 3:37:18through this map this returns finally
  4469. 3:37:22collection of one and four in the in the
  4470. 3:37:26first for the first object for the
  4471. 3:37:28second object it's going to have one and
  4472. 3:37:30five um one and six and so on and for
  4473. 3:37:33the final one it is going to be um here
  4474. 3:37:36it should not be one it should be three
  4475. 3:37:39three and six okay so then we get the
  4476. 3:37:42values out of this because we simply
  4477. 3:37:45this this still is an associative array
  4478. 3:37:48but we simply want values and then we
  4479. 3:37:51call to array to convert this into a
  4480. 3:37:54plane array not a collection and finally
  4481. 3:37:56option idas is going to be a plain array
  4482. 3:37:59of one and
  4483. 3:38:01four okay
  4484. 3:38:05next uh we're going to find matching
  4485. 3:38:08array in existing data so the existing
  4486. 3:38:11data is the objects of the following
  4487. 3:38:15table
  4488. 3:38:16if I zoom out slightly or show the
  4489. 3:38:19actual column names so we have variation
  4490. 3:38:21type option IDs we have quantity price
  4491. 3:38:25and we have created at and updated at
  4492. 3:38:27but we don't care them at the moment so
  4493. 3:38:29what we care is the product ID variation
  4494. 3:38:32type option IDs which is going to be the
  4495. 3:38:36array of the same type what we just
  4496. 3:38:39generated and the option ID is is an
  4497. 3:38:41array of one and four okay so you
  4498. 3:38:45probably I need to open a PHP scratch
  4499. 3:38:47file as well and option
  4500. 3:38:50IDs option IDs will have a format of
  4501. 3:38:56combination of option IDs like one and
  4502. 3:38:58four um it's going to have three and six
  4503. 3:39:02and so on such type of vary and also in
  4504. 3:39:05this product variations table we're
  4505. 3:39:07going to have exactly same type of data
  4506. 3:39:10and now here what we want to do is to
  4507. 3:39:13filter the existing data data okay uh
  4508. 3:39:18with the option IDs and we want to find
  4509. 3:39:20if inside existing data there exists a
  4510. 3:39:24matching of these option IDs so for this
  4511. 3:39:29we uh in in the array filter we pass
  4512. 3:39:31this function we use the option IDs and
  4513. 3:39:34finally we're going to return if
  4514. 3:39:37existing option which is as I mentioned
  4515. 3:39:40record of the following table okay if
  4516. 3:39:43existing options variation type option
  4517. 3:39:46ID equals these option IDs what we just
  4518. 3:39:51generated so if inside existing options
  4519. 3:39:54that exist it means that the specific
  4520. 3:39:57option IDs we already have in the
  4521. 3:39:58database there exists record right here
  4522. 3:40:02in the following table so it has its own
  4523. 3:40:05quantity and price so in this case we're
  4524. 3:40:10going to do check if the matching is not
  4525. 3:40:12empty if the matching was found then
  4526. 3:40:15we're going to take the first element
  4527. 3:40:17from this matching okay through this
  4528. 3:40:20reset method we take this first element
  4529. 3:40:23and inside product which is something
  4530. 3:40:26what we iterate right here inside this
  4531. 3:40:29product we are going to add quantity
  4532. 3:40:31from existing entry and price also from
  4533. 3:40:35existing entry which existed in the
  4534. 3:40:38database table and just like this we
  4535. 3:40:42generated um the default dat with the
  4536. 3:40:45default quantity and
  4537. 3:40:48price but then let's say that for black
  4538. 3:40:52large we had different price in the
  4539. 3:40:54database which was let's say 24 so this
  4540. 3:40:57will override and it will be 24 if like
  4541. 3:41:00a purple small we had only five then
  4542. 3:41:03it's going to override and we will have
  4543. 3:41:05only five in the final um data however
  4544. 3:41:10if the matching wasn't found then the
  4545. 3:41:12product quantity and the product price
  4546. 3:41:14will be the default one so which we
  4547. 3:41:17provided right
  4548. 3:41:19here inside this cartisian with
  4549. 3:41:23existing Okay cool so finally we have
  4550. 3:41:26this product and finally we're going to
  4551. 3:41:27put this product inside merge merged
  4552. 3:41:30results and then we are going to return
  4553. 3:41:33this merged result from the following
  4554. 3:41:36function merge cartisian with existing
  4555. 3:41:39now we have this function to implement
  4556. 3:41:41cartisian product and this is going to
  4557. 3:41:43be interesting okay so let's define the
  4558. 3:41:45function cartisian product we're going
  4559. 3:41:47to accept variation types we're going to
  4560. 3:41:49accept default quantity and we're going
  4561. 3:41:52to accept default price now this is the
  4562. 3:41:55most challenging part um but be with me
  4563. 3:41:59um if you have any questions you can
  4564. 3:42:02leave the comments down below but I
  4565. 3:42:05think I'm like trying to explain
  4566. 3:42:07everything very clearly and slowly so
  4567. 3:42:10here we are going to generate this
  4568. 3:42:12cartisian product and we need three
  4569. 3:42:14nested Lopes so the result is going to
  4570. 3:42:18be the array final array inside which we
  4571. 3:42:22are going to put the entire data so now
  4572. 3:42:27we we know that the format of the data
  4573. 3:42:29should look like this right so um the
  4574. 3:42:32product variations is something we can
  4575. 3:42:35close we have this scratch PHP okay I
  4576. 3:42:37can close this as well but I'm going to
  4577. 3:42:39open now new Json scratch file and I'm
  4578. 3:42:43going to like St step by step granularly
  4579. 3:42:47uh like add content inside this scratch
  4580. 3:42:51Json file so that you can show how the
  4581. 3:42:53data is grown here so we have the
  4582. 3:42:56variation types default quantity and
  4583. 3:42:58default price and the result is
  4584. 3:43:00something like this so array with the
  4585. 3:43:04first element to be also associative
  4586. 3:43:06array like if if it's going to make
  4587. 3:43:10thing easier for you I think we can have
  4588. 3:43:13uh like this data or
  4589. 3:43:15result something
  4590. 3:43:18like this as well okay like it is here
  4591. 3:43:21and then we can put some data inside
  4592. 3:43:24okay next we start iterating over
  4593. 3:43:27variation types we get the index and the
  4594. 3:43:29variation type variation types simply is
  4595. 3:43:32a uh is an array of the variation types
  4596. 3:43:36from the database where do we provide
  4597. 3:43:39this yeah it's simply collection of
  4598. 3:43:42objects from the inside the database so
  4599. 3:43:45we start iterating over the variation
  4600. 3:43:46types and I create a new temporary array
  4601. 3:43:51and inside this we're going to put some
  4602. 3:43:53data then I start iterating over for
  4603. 3:43:56each variation type I start iterating
  4604. 3:43:58over its
  4605. 3:43:59options and then I do one more iteration
  4606. 3:44:04of the current results what we have so
  4607. 3:44:07far so we have three nested Loops right
  4608. 3:44:12now okay so at the moment the result is
  4609. 3:44:17an array which has only one element so
  4610. 3:44:19if we start this from scratch we have
  4611. 3:44:23two variation types one is color second
  4612. 3:44:26is size so the outer loop will be
  4613. 3:44:29iterated two
  4614. 3:44:30times each variation type has three
  4615. 3:44:33options so the nested Loop option will
  4616. 3:44:36be iterated three times for each
  4617. 3:44:39variation type and this is something
  4618. 3:44:41what we know for sure okay so here we
  4619. 3:44:46have two this is actually two this is
  4620. 3:44:49actually uh three so the following Loop
  4621. 3:44:54the following code basically will be
  4622. 3:44:56executed totally six times so this is
  4623. 3:44:59two each option each variation type has
  4624. 3:45:03um two three options so this code will
  4625. 3:45:06be executed six times but depending on
  4626. 3:45:11the result and we're going to
  4627. 3:45:13gradually um put some data inside
  4628. 3:45:16results so totally we're going to have
  4629. 3:45:18nine iterations and the result will be
  4630. 3:45:22um will have nine records exactly as we
  4631. 3:45:25planned so now this is what we're going
  4632. 3:45:28to do so we're going to take the
  4633. 3:45:29existing combination which is the which
  4634. 3:45:33is the following object which is empty
  4635. 3:45:35object at the moment so we take the
  4636. 3:45:37existing combination and we merge it
  4637. 3:45:39with something new and something new is
  4638. 3:45:42going to be the new variation type
  4639. 3:45:45in our case because this is the first
  4640. 3:45:48iteration variation type with ID one so
  4641. 3:45:52this is the key and its corresponding
  4642. 3:45:55content option ID option name and type
  4643. 3:45:58so
  4644. 3:46:00here so
  4645. 3:46:02this basically will become something
  4646. 3:46:05like this
  4647. 3:46:07variation type ID or it's not ID I think
  4648. 3:46:11variation type
  4649. 3:46:13one is the this ID
  4650. 3:46:18oops ID
  4651. 3:46:20one name is going to be
  4652. 3:46:23black and
  4653. 3:46:26type is going to be uh color so this is
  4654. 3:46:31what we did so far right here so we have
  4655. 3:46:33now new combination which is merged of
  4656. 3:46:36the existing combination which was empty
  4657. 3:46:38thing with this one and now we have this
  4658. 3:46:42new combination what I have selected
  4659. 3:46:44right now and we're going to put this
  4660. 3:46:46new combination inside final temp array
  4661. 3:46:49so let me
  4662. 3:46:51create um so this actually let's call
  4663. 3:46:55this I want to make this very clear so
  4664. 3:46:57let's call this final
  4665. 3:47:00result so so far we don't have anything
  4666. 3:47:04in the result in the result we still
  4667. 3:47:06have something like this okay inside
  4668. 3:47:09this result but we took this empty array
  4669. 3:47:12I'm going to create one more scratch
  4670. 3:47:13file but I'm going to put this down okay
  4671. 3:47:18so the result is still such type of empt
  4672. 3:47:20array what we defined so far right here
  4673. 3:47:23but what we did here was a new
  4674. 3:47:27combination so let me Define new
  4675. 3:47:32combination and the new combination now
  4676. 3:47:35looks like this so this is the new
  4677. 3:47:38combination and we took that new
  4678. 3:47:41combination and put this inside temp
  4679. 3:47:44let's define temp here as well which is
  4680. 3:47:46an array and we put this new combination
  4681. 3:47:49inside temp so finally temp looks like
  4682. 3:47:55this okay now what we did so the
  4683. 3:47:57iteration of result was finished because
  4684. 3:48:00it only contained one element so we
  4685. 3:48:02iterated basically we finished and we
  4686. 3:48:06moved into the outer loop and we're
  4687. 3:48:08going to move into the second option
  4688. 3:48:11second option for the color is blue
  4689. 3:48:15right so now we start that the same
  4690. 3:48:19thing and now let's see what happens so
  4691. 3:48:22now inside result we still have one
  4692. 3:48:25element and the result is still this
  4693. 3:48:28type of thing so the result is still
  4694. 3:48:31looking like this now we come here the
  4695. 3:48:34new combination was actually new
  4696. 3:48:37combination was reseted and we're going
  4697. 3:48:39to recreate new combination right here
  4698. 3:48:42it's an existing combination existing
  4699. 3:48:44combination is the first element of
  4700. 3:48:45result so this this is going to be
  4701. 3:48:48merged with the variation type and the
  4702. 3:48:51variation type is is still the first one
  4703. 3:48:55okay so this is going to be merged with
  4704. 3:48:58variation type one but it is going to be
  4705. 3:49:03for the second option second option so
  4706. 3:49:06we provide
  4707. 3:49:08ID which is going to be two we provide
  4708. 3:49:12name which is going to be blue blue
  4709. 3:49:15second option and we provide type which
  4710. 3:49:18is of course going to be color uppercase
  4711. 3:49:22see okay so now we created this new
  4712. 3:49:25combination and we're going to put this
  4713. 3:49:27new combination inside temp so I'm just
  4714. 3:49:30going to take
  4715. 3:49:32that new
  4716. 3:49:34combination and we're going to put this
  4717. 3:49:37inside temp now inside temp we have this
  4718. 3:49:40variation type one which is one black
  4719. 3:49:44color
  4720. 3:49:46we have the um variation type one again
  4721. 3:49:51two blue color and finally it's going to
  4722. 3:49:54go with the third option and again
  4723. 3:49:58result is still something like this so
  4724. 3:50:01we're going to have variation type uh
  4725. 3:50:04one again but with the third option
  4726. 3:50:06which is the purple color so finally
  4727. 3:50:09when this Loop finishes the work for all
  4728. 3:50:12three options for the first variation
  4729. 3:50:15type we are going to have data like this
  4730. 3:50:18in the temp variation type one
  4731. 3:50:22ID3
  4732. 3:50:24color purple and this is going to be the
  4733. 3:50:28color so now this Loop finished the work
  4734. 3:50:32inside temp we have that three elements
  4735. 3:50:35I can zoom out so that you can have a in
  4736. 3:50:37like overall look right here so we have
  4737. 3:50:40these three elements all of them are for
  4738. 3:50:42variation type
  4739. 3:50:43one here here and here and now let's
  4740. 3:50:46continue inside the code so after that
  4741. 3:50:49Loop is finished so we take that temp
  4742. 3:50:54and assign it into the result so now we
  4743. 3:50:58take the entire
  4744. 3:51:02temp
  4745. 3:51:03oops copy and assign that into the
  4746. 3:51:09result now this is something interesting
  4747. 3:51:12so after we change the result so then we
  4748. 3:51:17start iterating for the next variation
  4749. 3:51:20type which is variation type two now
  4750. 3:51:24let's see what happens here variation
  4751. 3:51:26type two is size size has three options
  4752. 3:51:30small medium and large and this Loop
  4753. 3:51:32will be iterated three times but now
  4754. 3:51:35inside results we have three options
  4755. 3:51:38already okay so we see those three
  4756. 3:51:41options in the result now we reset the
  4757. 3:51:46temp so down
  4758. 3:51:48below this
  4759. 3:51:50temp become an empty
  4760. 3:51:54array and the new combination even
  4761. 3:51:56doesn't exist but right here when we
  4762. 3:51:58start iterating over result and we take
  4763. 3:52:01each element from this result the
  4764. 3:52:04combination is this now we take an
  4765. 3:52:08existing combination and merge it with
  4766. 3:52:12the variation type now in in this case
  4767. 3:52:14the variation type ID is two so we take
  4768. 3:52:18that data I want to take this
  4769. 3:52:21data and we're going to merge this into
  4770. 3:52:24variation type two which is going to be
  4771. 3:52:27size so variation type two it is going
  4772. 3:52:30to have uh ID will be the corresponding
  4773. 3:52:36ID for small and I think small has ID
  4774. 3:52:40four we're going to have name
  4775. 3:52:45to be small and we're going to have type
  4776. 3:52:49to be not color but size so this is what
  4777. 3:52:53we did for the new combination and now
  4778. 3:52:55new combination is the following element
  4779. 3:52:59and we take it and assign it to Temp so
  4780. 3:53:02down below not assign but push it into
  4781. 3:53:05the temp now right here we're going to
  4782. 3:53:07push that data now we took this first
  4783. 3:53:12combination right here in this results
  4784. 3:53:14but we're going to move into the next
  4785. 3:53:15one because we are iterating over
  4786. 3:53:17results here we took the first one and
  4787. 3:53:20this one so we moved into the second one
  4788. 3:53:22we took this right here the existing
  4789. 3:53:26combination and merge it with another
  4790. 3:53:29variation uh another option so let's
  4791. 3:53:32move up let's create this new
  4792. 3:53:36combination we took this one and merge
  4793. 3:53:39it with variation type two in this case
  4794. 3:53:42we're going to have ID five
  4795. 3:53:45name is going to be medium size and type
  4796. 3:53:50is going to be size okay so we take this
  4797. 3:53:54new combination
  4798. 3:53:56now and push it into
  4799. 3:53:59temp right
  4800. 3:54:01here now we took the second com second
  4801. 3:54:05uh combination from the result but we
  4802. 3:54:07still have to do this take the third one
  4803. 3:54:09so we're going to take the third
  4804. 3:54:12one so inside this new combination we
  4805. 3:54:15are going to merge it with again
  4806. 3:54:18variation type uh two with the last
  4807. 3:54:22option which is going to be the large
  4808. 3:54:24option so ID is going to be six name is
  4809. 3:54:28going to be large and the type is going
  4810. 3:54:32to be size again we take
  4811. 3:54:37this uh we take the entire new
  4812. 3:54:41combination and we push put this inside
  4813. 3:54:46temp
  4814. 3:54:48okay now we addit the data inside the
  4815. 3:54:52temp right here so now this is what
  4816. 3:54:56happens uh
  4817. 3:55:00finally we assign that temp into the
  4818. 3:55:04result so whatever we have right now
  4819. 3:55:07inside
  4820. 3:55:09temp
  4821. 3:55:12uh so we have let's see so we have
  4822. 3:55:16this
  4823. 3:55:18one
  4824. 3:55:20two
  4825. 3:55:23three uh sorry I think I missed one
  4826. 3:55:27thing while explaining so actually this
  4827. 3:55:30code works but one thing was actually
  4828. 3:55:34missed while I was explaining so we took
  4829. 3:55:38the um we took the first one first uh
  4830. 3:55:42thing from the result first combination
  4831. 3:55:44from from the result this so it was
  4832. 3:55:47merged with the new
  4833. 3:55:49Option okay so we have um this is going
  4834. 3:55:53to be a one result so if we count how
  4835. 3:55:56many records we're going to have temp so
  4836. 3:55:58inside temp we're going to have nine
  4837. 3:55:59records but because I missed something
  4838. 3:56:02during explanation we totally have um
  4839. 3:56:05three records inside the temp which is
  4840. 3:56:07not what we expected but we're going to
  4841. 3:56:10have nine because uh for the second
  4842. 3:56:13variation type
  4843. 3:56:15uh this Loop right here iterates three
  4844. 3:56:18times okay and the result also contains
  4845. 3:56:22three elements so we totally do the nine
  4846. 3:56:26iteration so the new combination is
  4847. 3:56:28created nine times so and we push this
  4848. 3:56:31new combination inside temp so finally
  4849. 3:56:33we're going to have nine elements so if
  4850. 3:56:36I quickly re explain this part so the
  4851. 3:56:39temp becomes empty we start iterating
  4852. 3:56:42over options so then we take the first
  4853. 3:56:45element from the result it is going to
  4854. 3:56:47be merged with the first option of this
  4855. 3:56:50second variation type and it is going to
  4856. 3:56:54be inserted inside temp with the merged
  4857. 3:56:56one uh I'm not going to actually do this
  4858. 3:56:59um IDs and all the things but let's
  4859. 3:57:01imagine that um it contains all the data
  4860. 3:57:04and you don't need to imagine it is
  4861. 3:57:06going to actually contain the um correct
  4862. 3:57:08data so we take existing variation type
  4863. 3:57:12ID which is for one we merged it into
  4864. 3:57:16with the variation type ID which is for
  4865. 3:57:18two and with the uh option which is
  4866. 3:57:21going to be small so this merged with um
  4867. 3:57:28id4 with small let's call this just
  4868. 3:57:30small so black merged with small and
  4869. 3:57:33this is going to be inside here so then
  4870. 3:57:36for the second
  4871. 3:57:38combination
  4872. 3:57:39this is going to be merged with also
  4873. 3:57:43small because we are still talking about
  4874. 3:57:46the same option right here so this will
  4875. 3:57:48be merged with small as well and then
  4876. 3:57:51the third element from the result which
  4877. 3:57:54is combination will be merged with small
  4878. 3:57:56as well so we're going to have black
  4879. 3:57:59small blue small purple small and we're
  4880. 3:58:04going to have those three elements
  4881. 3:58:06inside temp Now we move into the second
  4882. 3:58:09option second option is medium so we're
  4883. 3:58:12going to have black medium blue medium
  4884. 3:58:17purple medium and each of them is pushed
  4885. 3:58:20inside temp so black
  4886. 3:58:23medium blue
  4887. 3:58:25medium and oops and purple medium and
  4888. 3:58:31finally we're going to move onto the
  4889. 3:58:32third option which is going to be
  4890. 3:58:36um large so it is going to be black
  4891. 3:58:39large Blue large and purple large so we
  4892. 3:58:44to this and totally there will be nine
  4893. 3:58:47data nine uh elements inside the data
  4894. 3:58:50and the result will have similar
  4895. 3:58:54structure but in format of array of
  4896. 3:58:57course this is Json without quantity and
  4897. 3:58:59price this is important so far so we're
  4898. 3:59:02going to have only variation type one
  4899. 3:59:04variation type
  4900. 3:59:06two now after this Loop actually
  4901. 3:59:10finished this variation types so then
  4902. 3:59:13we're going to do one more iteration
  4903. 3:59:15over the result and finally because we
  4904. 3:59:17are assigning this temp into the result
  4905. 3:59:20after we have this temp that temp will
  4906. 3:59:24be assigned into the result right here
  4907. 3:59:29and the result will have those nine
  4908. 3:59:32elements there now we start iterating
  4909. 3:59:35over these
  4910. 3:59:38results we're going to get each
  4911. 3:59:40combination from these results and as I
  4912. 3:59:44mentioned the format of each element
  4913. 3:59:48right here will be something like this
  4914. 3:59:51variation type one variation type two
  4915. 3:59:53without quantity and price so far
  4916. 3:59:55because we're going to add those
  4917. 3:59:56quantity and price so right here then
  4918. 3:59:58we're going to do check if count of
  4919. 4:00:00combination which is actually two is the
  4920. 4:00:03same as variation types count which is
  4921. 4:00:06also true so if we added all the
  4922. 4:00:08variation types that that means pretty
  4923. 4:00:10much this this if can be also removed
  4924. 4:00:13just I added this Force extra extra
  4925. 4:00:16check so in in all the cases the
  4926. 4:00:19combination the count of combination
  4927. 4:00:20will be the same as count of variation
  4928. 4:00:22types so if the counts match then inside
  4929. 4:00:25the combination we're going to add
  4930. 4:00:27quantity which is going to be the
  4931. 4:00:28default quantity and we're going to add
  4932. 4:00:30price which is going to be the default
  4933. 4:00:32price and finally we are going to return
  4934. 4:00:35this
  4935. 4:00:37result okay a lot of
  4936. 4:00:40talking but I wanted to make uh I wanted
  4937. 4:00:44to make this very very clear so after
  4938. 4:00:47this cartisian product now we have that
  4939. 4:00:49data in the following format having
  4940. 4:00:52price and quantity as well and now it is
  4941. 4:00:55time to render the data
  4942. 4:00:59inside inside form right
  4943. 4:01:02here now we're going to take the
  4944. 4:01:05variation types right here and we're
  4945. 4:01:07going to create the proper form fields
  4946. 4:01:10to render the data what we just created
  4947. 4:01:13okay so we're going to create Fields
  4948. 4:01:15array then we're going to start
  4949. 4:01:16iterating over types the variation types
  4950. 4:01:20which is going to be one um that's color
  4951. 4:01:24second this is size and right here
  4952. 4:01:27inside the fields we are going to uh
  4953. 4:01:31create that inputs so text input make
  4954. 4:01:34the variation type one so the I I
  4955. 4:01:38obviously starts with zero so we get the
  4956. 4:01:40variation type
  4957. 4:01:42one ID
  4958. 4:01:44and the variation type and that that ID
  4959. 4:01:48field actually is going to be hidden by
  4960. 4:01:50the way here it should not be ID it
  4961. 4:01:53should be um sorry it should not be I it
  4962. 4:01:56should be type ID I'm going to change
  4963. 4:01:59this so I'm going to change this just
  4964. 4:02:01let me finish this um code
  4965. 4:02:04inserting and I will I will come back to
  4966. 4:02:07this and change this okay so we're going
  4967. 4:02:09to put also ID but that ID inside Fields
  4968. 4:02:12is going to be hidden field
  4969. 4:02:14okay I want this whenever I process the
  4970. 4:02:16data so that ID to be also uh processed
  4971. 4:02:21so in the same way we are going to
  4972. 4:02:23display the variation type name here
  4973. 4:02:27variation type one. name which basically
  4974. 4:02:30means that variation type
  4975. 4:02:33one. name it is going to display this it
  4976. 4:02:36is not the actual variation type name
  4977. 4:02:39but from this sub array it is going to
  4978. 4:02:41display the option name so that that is
  4979. 4:02:44actually option name the the type name
  4980. 4:02:47itself is the type right here color but
  4981. 4:02:51that name right here the ID is the
  4982. 4:02:54option ID the name is the option
  4983. 4:02:58name so we create those
  4984. 4:03:01fields um and this is going to have the
  4985. 4:03:05label to be the variation type name and
  4986. 4:03:09the uh label is going to be black okay
  4987. 4:03:14so let's move on and inside the schema
  4988. 4:03:16we're going to use the repeater and
  4989. 4:03:20because when we prepare that data the
  4990. 4:03:22merge cartisian with existing data we
  4991. 4:03:24put that data inside variations so we're
  4992. 4:03:27going to make that repeater on these
  4993. 4:03:30variations what we just generated okay
  4994. 4:03:34and then each variation is the following
  4995. 4:03:37object like the following object right
  4996. 4:03:41so then on that variation we make this
  4997. 4:03:43variation collapsible um default items
  4998. 4:03:46one and inside schema um we're going to
  4999. 4:03:50Define some Fields but we're going to
  5000. 4:03:51also add two columns and column col
  5001. 4:03:54spine to be two and then we're going to
  5002. 4:03:56make some section inside section we are
  5003. 4:03:59going to put Fields so because this is
  5004. 4:04:03actually a repeater it is going to be
  5005. 4:04:05repeated as many times as many elements
  5006. 4:04:09there are inside
  5007. 4:04:10variations and inside variations just
  5008. 4:04:13like how we generated we know that in
  5009. 4:04:15our specific case we have nine items
  5010. 4:04:18inside variations what we just generated
  5011. 4:04:21so this repeater will repeat it nine
  5012. 4:04:24times and for each there will be these
  5013. 4:04:29fields and this will be uh the ID and
  5014. 4:04:33the name will be for each field the ID
  5015. 4:04:35will be hidden so we're going to make
  5016. 4:04:38this uh layout in three columns and
  5017. 4:04:42we're going to Now display so after we
  5018. 4:04:44display those options then we display
  5019. 4:04:48quantity and we display price so we have
  5020. 4:04:52those two additional input Fields now uh
  5021. 4:04:56I want to import that
  5022. 4:05:00section let's import this section which
  5023. 4:05:04is going to be filament forms component
  5024. 4:05:07section okay and I think we can have a
  5025. 4:05:10look right now in the browser so let's
  5026. 4:05:13refresh the page and just have a look
  5027. 4:05:16look at this so now we have color black
  5028. 4:05:20size small and is corresponding quantity
  5029. 4:05:22and price and quantity and price is the
  5030. 4:05:25default one taken from the product right
  5031. 4:05:27now blue small quantity price purple
  5032. 4:05:31small quantity price black
  5033. 4:05:35medium uh we have black small here as
  5034. 4:05:38well so black small blue small purple
  5035. 4:05:42small black medium blue medium purple
  5036. 4:05:45medium uh black large Blue large and
  5037. 4:05:49purple large and because we layout this
  5038. 4:05:51into three columns we see additional
  5039. 4:05:53space right here uh and yeah this is
  5040. 4:05:56exactly what we wanted so adding this
  5041. 4:05:59new variation doesn't actually do
  5042. 4:06:01anything because we don't have anything
  5043. 4:06:03else so we can even remove that uh
  5044. 4:06:07edible we we should not have that edible
  5045. 4:06:10and additional thing is that I'm going
  5046. 4:06:11to change this uh instead of using this
  5047. 4:06:14index plus one here we are going to
  5048. 4:06:17use
  5049. 4:06:19type type ID let me change this into
  5050. 4:06:24type ID as well so the i+ one um was
  5051. 4:06:29like by mistake I had I was using index
  5052. 4:06:33previously When I Was preparing for for
  5053. 4:06:35the project and then I switched into the
  5054. 4:06:37ID so in the database if the variation
  5055. 4:06:40types have different IDs instead of one
  5056. 4:06:44and two right here on production
  5057. 4:06:46obviously when there are a lot of data
  5058. 4:06:48we're going to have different ideas it's
  5059. 4:06:50going to be like 119
  5060. 4:06:53and 20 whatever so this is going to be
  5061. 4:06:56used right here
  5062. 4:06:58119 120 here instead of the one and two
  5063. 4:07:02just like what we had
  5064. 4:07:05before okay and I think this repeater uh
  5065. 4:07:08we
  5066. 4:07:09can uh we can disable eding by providing
  5067. 4:07:13edible false refresh it and we don't see
  5068. 4:07:17this add new
  5069. 4:07:19anymore now I think we can work on
  5070. 4:07:23saving the data so so far that was good
  5071. 4:07:26but we have to save that data and we
  5072. 4:07:28have the label here as well which we
  5073. 4:07:31can uh set into false as well the entire
  5074. 4:07:34page is for variations so we don't need
  5075. 4:07:37this title and we have expand all
  5076. 4:07:40collapse all just in case we need that
  5077. 4:07:43to work on saving the data we're going
  5078. 4:07:46to go into our product variation class
  5079. 4:07:51and we're going to override method
  5080. 4:07:52called mutate form data before save okay
  5081. 4:07:58this is the um filaments buil-in method
  5082. 4:08:01so we over readen over write that method
  5083. 4:08:05here so we get the data we have to
  5084. 4:08:07modify mutate that data and return that
  5085. 4:08:11modified data so we take the data return
  5086. 4:08:13it now let's work on modifying the data
  5087. 4:08:17so I want to initialize a new array and
  5088. 4:08:19that's going to change hold the format
  5089. 4:08:21data so the new format data so we have
  5090. 4:08:25now data coming from the form in the
  5091. 4:08:28following way just in a PHP array not
  5092. 4:08:32Json so we want to modify this and
  5093. 4:08:36convert that format into format which is
  5094. 4:08:41applicable for the database in the
  5095. 4:08:44database has the following format not
  5096. 4:08:47this table but product variations table
  5097. 4:08:51this
  5098. 4:08:52one so let me try to simulate one record
  5099. 4:08:57creation so this is one variation so
  5100. 4:09:01we're going to take the option ID one
  5101. 4:09:04we're going to take option ID 4 put this
  5102. 4:09:07right here
  5103. 4:09:09as as array one and four we're going to
  5104. 4:09:13provide the quantity to be 10 and we're
  5105. 4:09:17going to provide price to be 19 and
  5106. 4:09:20obviously we have to provide the product
  5107. 4:09:21ID for which we're doing this and
  5108. 4:09:24created it and updated it but I'm going
  5109. 4:09:25to leave this so now this is how we're
  5110. 4:09:29going to convert the data that data into
  5111. 4:09:32the following format so that that data
  5112. 4:09:34will be saved into the database okay I'm
  5113. 4:09:37going to delete this now and let's open
  5114. 4:09:40this product variations again and
  5115. 4:09:41continue
  5116. 4:09:44so then we start iterating over the data
  5117. 4:09:46variations which has the following
  5118. 4:09:48format we get option okay each option is
  5119. 4:09:53this this is each option so option has
  5120. 4:09:58quantity price and the variation types
  5121. 4:10:00so from that option we're going to take
  5122. 4:10:02the IDS this is what we are doing I'm
  5123. 4:10:05going to Define new array variation type
  5124. 4:10:07option IDs and then I'm going to start
  5125. 4:10:10iterating over the product Vari iation
  5126. 4:10:13types which is going to be color and
  5127. 4:10:16size in the corresponding objects then
  5128. 4:10:20inside this variation type option IDs
  5129. 4:10:23which has the purpose to save one and
  5130. 4:10:26four there so this is what we are doing
  5131. 4:10:29from the option which
  5132. 4:10:32is the following object from the option
  5133. 4:10:35we are taking variation type underscore
  5134. 4:10:39and the variation type ID so for the
  5135. 4:10:42corresponding variation type one or two
  5136. 4:10:44it is going to give us the following
  5137. 4:10:46object from the following object we're
  5138. 4:10:48going to take ID so this will return the
  5139. 4:10:52following number so we are pushing that
  5140. 4:10:55ID into the variation type IDs and we
  5141. 4:10:57are doing this for all the variation
  5142. 4:10:59types for the first one and for the
  5143. 4:11:03second one we take one and four push
  5144. 4:11:06into the variation type option IDs
  5145. 4:11:08awesome next we're going to take the
  5146. 4:11:10quantity from the option
  5147. 4:11:13and price from the option as well and
  5148. 4:11:16then we're going to create that um
  5149. 4:11:19formatted data so inside formatted data
  5150. 4:11:23we're going to push the following array
  5151. 4:11:25it is going to have these variation type
  5152. 4:11:27option IDs which is the column name
  5153. 4:11:29already database column name with a
  5154. 4:11:32variation type option ideas what we just
  5155. 4:11:34generated containing one and four we're
  5156. 4:11:37going to give it also quantity and we're
  5157. 4:11:40going to give it price and Final
  5158. 4:11:43inside data variations we are going to
  5159. 4:11:47put that formatted data and because
  5160. 4:11:51product model has this relation into
  5161. 4:11:54variations and we are mutating this
  5162. 4:11:57before saving so that data which has now
  5163. 4:12:01correct format variation type option IDs
  5164. 4:12:03quantity and price that data will be
  5165. 4:12:06saved into the
  5166. 4:12:08database this is so awesome to see the
  5167. 4:12:11result so we can provide that the black
  5168. 4:12:14are kind of expensive we can give it
  5169. 4:12:16price like 25 and also black are limited
  5170. 4:12:19we have only three options for black
  5171. 4:12:22let's search for black
  5172. 4:12:25325 another Black 3 quantity 25 so we
  5173. 4:12:30modified the variations as we wanted and
  5174. 4:12:33I'm going to click on
  5175. 4:12:35this save
  5176. 4:12:37changes uh maybe we should also disable
  5177. 4:12:41the delete so we want to Define
  5178. 4:12:43something for every variation type so I
  5179. 4:12:45will probably disable remove that delete
  5180. 4:12:47button so I'm going to click of sa click
  5181. 4:12:50on Save changes and let's see what
  5182. 4:12:51happens we have the error no such column
  5183. 4:12:57variations update products set
  5184. 4:12:59variations okay I think I know the
  5185. 4:13:01reason so we are going to go into
  5186. 4:13:04product and we are going to add right
  5187. 4:13:07here uh inside casts we are going to add
  5188. 4:13:12variations
  5189. 4:13:13to be
  5190. 4:13:15array now let's close the model and hit
  5191. 4:13:18on Save
  5192. 4:13:21again okay we still have the same error
  5193. 4:13:25yeah I know the reason so right here in
  5194. 4:13:30this product
  5195. 4:13:31variations uh we just prepared the data
  5196. 4:13:34and put the variations right here but
  5197. 4:13:37that variations um is not going to be
  5198. 4:13:40saved into the database because that is
  5199. 4:13:42actually an array so we have to
  5200. 4:13:43overwrite one more method which is going
  5201. 4:13:46to be handle record update so let me
  5202. 4:13:49overwrite this right now handle record
  5203. 4:13:52update so in which case we're going to
  5204. 4:13:55receive a record in data so this model
  5205. 4:13:58is actually product and data is the data
  5206. 4:14:02what was returned from this
  5207. 4:14:05mutate um Data before save so right here
  5208. 4:14:10instead of calling parent this is what
  5209. 4:14:12I'm going to do
  5210. 4:14:14so finally I'm going to return record so
  5211. 4:14:18return
  5212. 4:14:20record but before I return the record um
  5213. 4:14:24I want to take the
  5214. 4:14:27variations from data variations because
  5215. 4:14:31when there is some data inside when
  5216. 4:14:35there is some key inside the data now
  5217. 4:14:38filament tries to save that data into
  5218. 4:14:41the database so and and because of that
  5219. 4:14:43we have this error because we have
  5220. 4:14:45variations inside the data filament
  5221. 4:14:48tries to find the column variations in
  5222. 4:14:51the database to put that data but we're
  5223. 4:14:53going to take out those variations and
  5224. 4:14:55we're going to
  5225. 4:14:57unset unset data
  5226. 4:14:59variations now data doesn't have
  5227. 4:15:02variations and we're going to do the
  5228. 4:15:04following I'm going to call record
  5229. 4:15:06update so we are doing the actual update
  5230. 4:15:10of the data and instead of calling
  5231. 4:15:12record update we can also call the
  5232. 4:15:14parent and parent will do also the
  5233. 4:15:17update
  5234. 4:15:19because the data um now doesn't contain
  5235. 4:15:22variations there but let's leave it
  5236. 4:15:25right now like this and we can try the
  5237. 4:15:26second way as well record update data
  5238. 4:15:29then on the
  5239. 4:15:30record variations relation so we have
  5240. 4:15:33that variations relation I want to
  5241. 4:15:36delete all the variations what we have
  5242. 4:15:38in the database at the moment we don't
  5243. 4:15:41have
  5244. 4:15:43any re variations in the database so
  5245. 4:15:46we're going to delete that and then on
  5246. 4:15:49the
  5247. 4:15:50record
  5248. 4:15:52variations we are going
  5249. 4:15:54to create many variations with the
  5250. 4:15:58following array okay now let's save
  5251. 4:16:02it and let's click on Save
  5252. 4:16:06changes now we have another error
  5253. 4:16:08argument one values must be type of
  5254. 4:16:11array and string was
  5255. 4:16:14given
  5256. 4:16:17inside okay where is this coming from so
  5257. 4:16:21we have that
  5258. 4:16:23data create
  5259. 4:16:26many variations we call this
  5260. 4:16:34delete the error is actually coming from
  5261. 4:16:37the following line record variations
  5262. 4:16:39create manyu and let's have a look let's
  5263. 4:16:42debug it
  5264. 4:16:43and have a look what data we have inside
  5265. 4:16:46variations so after we update and after
  5266. 4:16:49after we call these variations delete or
  5267. 4:16:52maybe before delete we can print what
  5268. 4:16:55are inside
  5269. 4:16:57variations okay variation type option
  5270. 4:17:03IDs okay now that makes sense so
  5271. 4:17:07variation type option IDs is actually an
  5272. 4:17:10array okay and we try to put in the D
  5273. 4:17:12database the array but the product
  5274. 4:17:18variation needs to have cast field like
  5275. 4:17:23similar to what we added into product so
  5276. 4:17:26inside product actually I think we did
  5277. 4:17:28not need that variations but inside
  5278. 4:17:31product variation we have to add that
  5279. 4:17:33cast field and this is going to be
  5280. 4:17:36variation type option IDs to be Json
  5281. 4:17:40because this is actually an array
  5282. 4:17:44okay I think that should be
  5283. 4:17:46it we can remove
  5284. 4:17:50that click on Save changes and we see
  5285. 4:17:55right here saved now let's have a look
  5286. 4:17:58in product variations table in the
  5287. 4:18:01database look at this so we
  5288. 4:18:05have we have nine
  5289. 4:18:08records for the same product we have the
  5290. 4:18:11variation type option IDs here here 1 4
  5291. 4:18:132 4 3 4 1 5 all of them as we expect we
  5292. 4:18:17have quantities and for some of them it
  5293. 4:18:19was actually uh empty the default one
  5294. 4:18:22but for the black ones and the black
  5295. 4:18:24option has ID one so whenever we have
  5296. 4:18:28one
  5297. 4:18:29mentioned we gave different price and
  5298. 4:18:33limited quantity three and just like
  5299. 4:18:36this we have that working and this is so
  5300. 4:18:40awesome now if we hit on Save changes
  5301. 4:18:43again so this is going to delete the
  5302. 4:18:45records and recreate them which is not a
  5303. 4:18:49problem of course we can optimize this
  5304. 4:18:52and do some additional analysis um but
  5305. 4:18:55this is not also a problem uh we are not
  5306. 4:18:57going to use these IDs anywhere so every
  5307. 4:19:00time we make this update although I
  5308. 4:19:02don't expect this um updates very very
  5309. 4:19:06often but anyway it's not a problem so
  5310. 4:19:08we delete delete that recreate that um
  5311. 4:19:12generally um I would optimize that um if
  5312. 4:19:16I am about to put this
  5313. 4:19:19um like on
  5314. 4:19:22production so I would try to optimize
  5315. 4:19:24this but right now for this video Simply
  5316. 4:19:27I want to focus on the most important
  5317. 4:19:29stuff and leave the optimizations um for
  5318. 4:19:32the later stage if I have time for
  5319. 4:19:35this um okay what I want to try however
  5320. 4:19:38is that instead of calling This Record
  5321. 4:19:40update so maybe we can call this
  5322. 4:19:44parent um so record equals we can do the
  5323. 4:19:49following as well so we can do this
  5324. 4:19:51variation delete variation create menu
  5325. 4:19:55and then we can call parent handle
  5326. 4:19:59record update providing recording
  5327. 4:20:02data just like
  5328. 4:20:05this uh and the data I think doesn't
  5329. 4:20:09even contain anything else right so the
  5330. 4:20:13data doesn't actually do the product
  5331. 4:20:16update so yeah the data is actually
  5332. 4:20:19absolutely empty so we don't even need
  5333. 4:20:21to call appearent or we don't even need
  5334. 4:20:25to update the record we can simply
  5335. 4:20:28return the record so the the whole
  5336. 4:20:30purpose of this page is to update the
  5337. 4:20:32variations and this is something what we
  5338. 4:20:35are actually already
  5339. 4:20:37doing I generally don't like leave um
  5340. 4:20:42some question questions to some students
  5341. 4:20:44how they can do this or that thing so
  5342. 4:20:46probably you have a question how I can
  5343. 4:20:48do exactly this uh updating of the
  5344. 4:20:53variation product variation so that
  5345. 4:20:56every time I don't have to delete the
  5346. 4:20:58data and then recreate the data which
  5347. 4:21:00happens right now okay so if we refresh
  5348. 4:21:03it click on Save right now that does the
  5349. 4:21:06update refresh it and we're going to see
  5350. 4:21:08that the data is actually deleted and
  5351. 4:21:10recreated so I decided that after a
  5352. 4:21:13little bit of research Let's Do It um
  5353. 4:21:15it's not going to take too much time so
  5354. 4:21:18here we're we're going to provide
  5355. 4:21:19instead of create menu we're going to
  5356. 4:21:21provide upsert and we're going to
  5357. 4:21:23provide the data in the uh column based
  5358. 4:21:26on which we're going to do the detection
  5359. 4:21:28so The Logical one is going to be ID so
  5360. 4:21:31here we provide the ID and then we're
  5361. 4:21:34going to provide the columns which we
  5362. 4:21:36want to update from that variation sta
  5363. 4:21:40okay so this is going to be variation
  5364. 4:21:42type um option IDs we're going to have
  5365. 4:21:47quantity and price so we're going to
  5366. 4:21:50update the following data however these
  5367. 4:21:55variations do not contain IDs so
  5368. 4:21:59whenever we
  5369. 4:22:01are whenever we are generating the data
  5370. 4:22:05right here in this merge cartisian with
  5371. 4:22:07existing so the existing data right here
  5372. 4:22:12is variations taken from the database so
  5373. 4:22:16that variations contains ID so if we
  5374. 4:22:19follow that the existing data contains
  5375. 4:22:21ID so it's an array and each element
  5376. 4:22:24contains ID so here we have that
  5377. 4:22:27existing data we do the matching we take
  5378. 4:22:30the first existing entry if the matching
  5379. 4:22:33happened which means that if the
  5380. 4:22:35matching happens we are going to do
  5381. 4:22:37update okay not create so right here
  5382. 4:22:40inside product
  5383. 4:22:43ID we're going to provide existing entry
  5384. 4:22:47and then ID okay and after this when we
  5385. 4:22:51do this mutate form data before save so
  5386. 4:22:54now the data will contain that uh ID so
  5387. 4:22:59that ID is actually added next to the
  5388. 4:23:02quantity and price so if we have a look
  5389. 4:23:04in our Json structure we are going to
  5390. 4:23:07have ID eded right here and that ID is
  5391. 4:23:13going to be product variations primary
  5392. 4:23:16key like 20 so that 20 will be added
  5393. 4:23:19right here so we can change this into
  5394. 4:23:21one two three four five 6 7even 8 oops
  5395. 4:23:26what I
  5396. 4:23:28four five six 7 8 and nine awesome now
  5397. 4:23:34here we have one so if we go into
  5398. 4:23:38product
  5399. 4:23:39variations scroll down below
  5400. 4:23:43so right here we have the data we have
  5401. 4:23:45the options each option is the following
  5402. 4:23:47object and from that option we take
  5403. 4:23:50quantity price and right here we're
  5404. 4:23:52going to also take ID this is going to
  5405. 4:23:55be option ID now if I scroll down below
  5406. 4:24:00and dump variations we're going to see
  5407. 4:24:04that each variation has ID there click
  5408. 4:24:06on Save changes we see ID which is 20
  5409. 4:24:10white is 20 by the way
  5410. 4:24:13because I haven't saved that data let's
  5411. 4:24:16save it refresh it click on Save now we
  5412. 4:24:20see that the ID is one and right here we
  5413. 4:24:24do this upsert but this is not going to
  5414. 4:24:27work we're going to have an error
  5415. 4:24:28because variation type option IDs is
  5416. 4:24:31actually an array and this upsert
  5417. 4:24:33doesn't use eloquent models anymore and
  5418. 4:24:37we are directly inserting the data or
  5419. 4:24:39updating the data in the database and
  5420. 4:24:41it's going to give us an error because
  5421. 4:24:43that variation type option IDs is array
  5422. 4:24:46so let's try this click on Save we get
  5423. 4:24:49the uh get that error and this is what
  5424. 4:24:52we are going to do so
  5425. 4:24:57oops variations equals we can call um
  5426. 4:25:01array map for example or we can use a
  5427. 4:25:04collection method to do the collection I
  5428. 4:25:07actually love working with collections
  5429. 4:25:09so I'm going to use collect variations
  5430. 4:25:12and we're going to return the following
  5431. 4:25:17format with a semicolon so we need all
  5432. 4:25:20the columns pretty much so we need ID
  5433. 4:25:23variation ID we need variation type
  5434. 4:25:26option IDs which is going to be Json
  5435. 4:25:30encode okay so we do this Json encoding
  5436. 4:25:34then we're going to have quantity and
  5437. 4:25:36price so we just change this variation
  5438. 4:25:38type option IDs and then we provide the
  5439. 4:25:41variations here which should work click
  5440. 4:25:45on Save
  5441. 4:25:47changes upsert okay values must be type
  5442. 4:25:50of array collection given that's correct
  5443. 4:25:53the collect map Returns the collection
  5444. 4:25:55so finally we have to call to array on
  5445. 4:26:00this okay now we click on Save changes
  5446. 4:26:05it will saved and if we check right now
  5447. 4:26:09inside product variations table nothing
  5448. 4:26:12thing got changed and if we provide some
  5449. 4:26:16data like quantity 1500 price 1500 save
  5450. 4:26:23changes refresh it we see that the data
  5451. 4:26:26is actually changed but the IDS it is
  5452. 4:26:28not actually deleted and
  5453. 4:26:30recreated
  5454. 4:26:32um it is actually deleted but this line
  5455. 4:26:35can be completely removed it is not
  5456. 4:26:37necessary anymore you can test this one
  5457. 4:26:40final time
  5458. 4:26:42click on Save
  5459. 4:26:44changes
  5460. 4:26:47oops refresh it and we see the data
  5461. 4:26:50right here I have commented all the
  5462. 4:26:52changes what I had so far and now before
  5463. 4:26:56we move on the front and side on the
  5464. 4:26:58website part and start rendering
  5465. 4:27:00products let's make small changes right
  5466. 4:27:04here so this is product resource and at
  5467. 4:27:08the moment we are return uh we are
  5468. 4:27:10returning and rendering all the products
  5469. 4:27:13but we won't obviously restrict this in
  5470. 4:27:16return on the products which belong to
  5471. 4:27:20this vendor so for this we have to
  5472. 4:27:23override method get eloquent
  5473. 4:27:26cury and from here this called this per
  5474. 4:27:29and get eloquent cury and on that I am
  5475. 4:27:33going to add a we Clause to filter for
  5476. 4:27:36the currently authenticated vendor for
  5477. 4:27:39this I'm going to create for Simplicity
  5478. 4:27:41I'm going to create
  5479. 4:27:43scope we can open product.php
  5480. 4:27:47which is right
  5481. 4:27:50here and right here I'm going to add
  5482. 4:27:53public function
  5483. 4:27:55scope um
  5484. 4:27:58for vendor okay so return and this
  5485. 4:28:04actually scope for R vendor is going to
  5486. 4:28:07accept uh cery Builder so here we need
  5487. 4:28:10Builder build
  5488. 4:28:12Builder database quer
  5489. 4:28:15Builder Builder okay then on that or we
  5490. 4:28:19can call this Cy I
  5491. 4:28:21think on that Cy we can call
  5492. 4:28:27we uh created
  5493. 4:28:30by
  5494. 4:28:32equals currently
  5495. 4:28:34authenticated user
  5496. 4:28:36ID scope for vendor I'm going to add
  5497. 4:28:40additional Scopes right here which I'm
  5498. 4:28:42going to use on the front and side
  5499. 4:28:44public function scope published as an
  5500. 4:28:50example we accept
  5501. 4:28:52Builder return scope we
  5502. 4:28:56published uh not published but we have
  5503. 4:28:59status where status equals product
  5504. 4:29:03status
  5505. 4:29:05ANM published value or we can leave this
  5506. 4:29:10published as well
  5507. 4:29:12and both of them actually should return
  5508. 4:29:14an instance of Builder so we have for
  5509. 4:29:17vendor and
  5510. 4:29:19published and and and I think that's it
  5511. 4:29:23okay let's go into product resource and
  5512. 4:29:24right here I'm going to use for vendor
  5513. 4:29:27so I want products for vendor which
  5514. 4:29:29means for the currently authenticated
  5515. 4:29:32vendor and if we click on products right
  5516. 4:29:36now scope for
  5517. 4:29:39vendor the Q must be type of okay
  5518. 4:29:42database query Builder eloquent Builder
  5519. 4:29:45given um my bet so here instead of Q
  5520. 4:29:51Builder that accepts eloquent
  5521. 4:29:55Builder okay perfect so now if I want to
  5522. 4:30:01test this so we have one product which
  5523. 4:30:02has created by created by two which is
  5524. 4:30:08the currently authenticated user but I'm
  5525. 4:30:10going to change this into one and if I
  5526. 4:30:12refresh the page right now the current
  5527. 4:30:14vendor doesn't see any products because
  5528. 4:30:16that product does not belong to this
  5529. 4:30:18vendor without that CER get eloquent
  5530. 4:30:21query basically the current vendor is
  5531. 4:30:23able to see every product that is in the
  5532. 4:30:25database which is obviously something we
  5533. 4:30:28don't want we don't see any product now
  5534. 4:30:30we change the ID into
  5535. 4:30:32two and now we see the product right
  5536. 4:30:36here now let's open this in a new tab
  5537. 4:30:40and we're going to move on the front and
  5538. 4:30:42side and start rendering the
  5539. 4:30:45products let
  5540. 4:30:49me close everything and we need a new
  5541. 4:30:53controller pro probably we have actually
  5542. 4:30:57we have the product controller so let's
  5543. 4:30:59use it so right here we need index
  5544. 4:31:02method and we are going to select the uh
  5545. 4:31:06products and render them
  5546. 4:31:09so let's call this product
  5547. 4:31:12[Music]
  5548. 4:31:14products product we need we and we want
  5549. 4:31:18to select only published products so we
  5550. 4:31:21can actually let me call cury here and
  5551. 4:31:25then we need to call um published so we
  5552. 4:31:28added let's import the product so we
  5553. 4:31:31added that
  5554. 4:31:32scope published scope so we can select
  5555. 4:31:37published products right here and then
  5556. 4:31:41I'm going to call P inate on
  5557. 4:31:44this uh let it be 12 and then I am going
  5558. 4:31:48to return
  5559. 4:31:50inertia
  5560. 4:31:52render um let's use
  5561. 4:31:58home um and we're going to pass
  5562. 4:32:03products okay how however right here I'm
  5563. 4:32:07going to use uh resource so for this let
  5564. 4:32:11me create PHP artisan make
  5565. 4:32:15resource product
  5566. 4:32:18resource or because I want to use this
  5567. 4:32:21to display listing of the product I'm
  5568. 4:32:24going to use product list resource
  5569. 4:32:26because the data what we are going to
  5570. 4:32:29return into react what we're going to
  5571. 4:32:31pass into react will be different for
  5572. 4:32:34the listing and for the product Details
  5573. 4:32:36page so we're going to create that under
  5574. 4:32:39HTTP resources product list resource I'm
  5575. 4:32:43going to come back to this resource and
  5576. 4:32:44implement this
  5577. 4:32:47but let's check
  5578. 4:32:49the resources
  5579. 4:32:52JS uh pages and we have this welcome
  5580. 4:32:55which which I want to rename I'm going
  5581. 4:32:58to call this
  5582. 4:33:01home let's try to rename it in every
  5583. 4:33:05place okay uh let's open home and right
  5584. 4:33:11here uh we don't need this handle image
  5585. 4:33:13error I'm going to remove this but down
  5586. 4:33:15below I want to iterate over the
  5587. 4:33:18products we're going to accept products
  5588. 4:33:20right here we can remove this as well
  5589. 4:33:23this as well so we're going to accept
  5590. 4:33:24prop product iterate and for each
  5591. 4:33:27product I also want to create a new
  5592. 4:33:29component and I'm going to put this
  5593. 4:33:31inside up let's call
  5594. 4:33:35this product product item uh it should
  5595. 4:33:41not be just six it should be TS6 so
  5596. 4:33:43we're going to create typescript file
  5597. 4:33:47product
  5598. 4:33:51item okay maybe I was creating the same
  5599. 4:33:54one product item uh TSX file okay rsf
  5600. 4:34:01product item we're going to accept the
  5601. 4:34:02props we're going to handle um this
  5602. 4:34:06part okay cool and so we are going to
  5603. 4:34:11work on the resource we are going to
  5604. 4:34:13pass that data into home we're going to
  5605. 4:34:16accept the data here then iterate here
  5606. 4:34:19and render it nicely I'm going to change
  5607. 4:34:23this part and use product list resource
  5608. 4:34:26collection providing products right here
  5609. 4:34:29because we are returning collection that
  5610. 4:34:32is going to be an object and it's going
  5611. 4:34:34to have data and couple of pagination
  5612. 4:34:37related fields and we're going to get
  5613. 4:34:40those products on the homepage right
  5614. 4:34:43here however I'm going to Define new
  5615. 4:34:47data type on the homage for these
  5616. 4:34:51products for this I'm going to open
  5617. 4:34:53index.
  5618. 4:34:55D.S and right here let's define new type
  5619. 4:34:59for product which will have an ID title
  5620. 4:35:04slug price quantity image and user and
  5621. 4:35:08Department as well okay and I'm going to
  5622. 4:35:12also open this product list resource and
  5623. 4:35:14I'm going to return the same type of
  5624. 4:35:16data from here inside this two array so
  5625. 4:35:19we need ID title slug price quantity
  5626. 4:35:23image user which is the vendor user and
  5627. 4:35:28Department as well however if we check
  5628. 4:35:32product PHP do we have the relation to
  5629. 4:35:35Department yes we do have so this is
  5630. 4:35:39good now go into to home and we are
  5631. 4:35:43going to use now these products right
  5632. 4:35:45here and I think I also need to define a
  5633. 4:35:49pagination type so here I'm going to
  5634. 4:35:51Define this pagination props type of um
  5635. 4:35:55type pretty much and this is um abstract
  5636. 4:35:59definition and this gives us possibility
  5637. 4:36:02to use the generics T right here and the
  5638. 4:36:05data is array of T and in our case the
  5639. 4:36:09product is going to be pagination props
  5640. 4:36:14for product and we're going to import
  5641. 4:36:16pagination props in
  5642. 4:36:19product and now these products is going
  5643. 4:36:22to be an instance of pagination props
  5644. 4:36:25which will have data data will have will
  5645. 4:36:28be an array of products okay and that
  5646. 4:36:32pagination props will have additional
  5647. 4:36:34Fields like links and meta but uh we
  5648. 4:36:38don't need that at the moment and
  5649. 4:36:40whenever we need that
  5650. 4:36:42we can add this information um right
  5651. 4:36:45here okay cool now inside inside this
  5652. 4:36:48homepage we can start iterating over the
  5653. 4:36:50product so down below I'm going to
  5654. 4:36:52create one grid which will have some
  5655. 4:36:54responsive t one CSS classes as well and
  5656. 4:36:57pading and then I'm going to start
  5657. 4:37:00iterating our products data we're going
  5658. 4:37:03to get each product and I'm going to
  5659. 4:37:05call product item okay and I'm going to
  5660. 4:37:08provide two things right here I'm going
  5661. 4:37:10to provide the product itself and the
  5662. 4:37:13key as well for the product and
  5663. 4:37:15obviously at the top we're going to also
  5664. 4:37:17import this product item from the
  5665. 4:37:19components up product item now let's
  5666. 4:37:22open we're going to save this uh why do
  5667. 4:37:26we have error on the homepage yeah
  5668. 4:37:29because the product in key is not
  5669. 4:37:30defined on the product item let's open
  5670. 4:37:33Now product
  5671. 4:37:35item and right here we are going to
  5672. 4:37:38accept Now product as a prop which will
  5673. 4:37:41be an instance of the product what we
  5674. 4:37:43defined in the types right here so we're
  5675. 4:37:47going to import that product and let's
  5676. 4:37:49also import link we will need this
  5677. 4:37:51inside the template now we're going to
  5678. 4:37:54create card and that card is actually
  5679. 4:37:56Daisy UI card we give it background and
  5680. 4:38:00some Shadow as well then I'm going to
  5681. 4:38:03create a link and that link will be to
  5682. 4:38:07product Details page okay and we don't
  5683. 4:38:11have that product show yet defined do we
  5684. 4:38:14have uh I think we don't have that but
  5685. 4:38:17we're going to Define this we don't have
  5686. 4:38:19anything related to product defined yet
  5687. 4:38:22but we're going to Define it okay but
  5688. 4:38:24I'm going to use slug instead of the
  5689. 4:38:28URL uh when uh accessing the product
  5690. 4:38:32Details page okay so next we're going to
  5691. 4:38:35put an image we're going to use product
  5692. 4:38:37image we're going to use product title
  5693. 4:38:39inside alt and give it some some um
  5694. 4:38:42talin CSS classes like aspect square and
  5695. 4:38:45object cover we're going to display the
  5696. 4:38:48card body and inside we need the product
  5697. 4:38:51title and we are going to display the
  5698. 4:38:55information about the vendor as well
  5699. 4:38:58product usern
  5700. 4:38:59name um and let me show the product
  5701. 4:39:03Department name as well so this is the
  5702. 4:39:06product title which will be let's say
  5703. 4:39:09mouse Logitech mouse Whatever by then
  5704. 4:39:13we're going to have the vendor Name by
  5705. 4:39:15zoraa okay and that vendor name um in
  5706. 4:39:19the future will be a clickable link to
  5707. 4:39:21the vendor Details page vendor profile
  5708. 4:39:24page right now it moves into slash and
  5709. 4:39:28it is also into a department which might
  5710. 4:39:31be Mouse mous is as a department so that
  5711. 4:39:35the department will also be something
  5712. 4:39:37clickable in the future okay and then
  5713. 4:39:39we're going to do card action
  5714. 4:39:41at the bottom and uh inside card actions
  5715. 4:39:44we're going to display edit to card
  5716. 4:39:46button and we're going to display also
  5717. 4:39:49cart the product
  5718. 4:39:52price okay so if we go in the homepage
  5719. 4:39:55the error is gone product item is ready
  5720. 4:40:00resources ready controller is ready
  5721. 4:40:02let's update no roots so on the home
  5722. 4:40:05page instead of this welcome we're going
  5723. 4:40:08to use Now product
  5724. 4:40:12product
  5725. 4:40:13controller class this is going to be
  5726. 4:40:17index or we can call this home I think
  5727. 4:40:21let's replace this import the qualifier
  5728. 4:40:24with
  5729. 4:40:25import uh let's remove unused Imports
  5730. 4:40:28here and in the pr controller I'm going
  5731. 4:40:31to change this into
  5732. 4:40:38home okay now let's try to access to the
  5733. 4:40:42homepage and have a
  5734. 4:40:47look let's refresh it canot Rate
  5735. 4:40:50Property ID on null this is
  5736. 4:40:54coming where this is coming from why
  5737. 4:40:56doesn't highlight that
  5738. 4:41:02part user in
  5739. 4:41:08Department product least resource 20
  5740. 4:41:125 right
  5741. 4:41:15here
  5742. 4:41:18okay the
  5743. 4:41:21product okay has created by let's go
  5744. 4:41:24into product PHP and find
  5745. 4:41:28the user okay we don't have relation
  5746. 4:41:31defined to user and this is the thing um
  5747. 4:41:35let's define this as the first relation
  5748. 4:41:38right here user uh return return this
  5749. 4:41:42belongs to user but the field is created
  5750. 4:41:45by and let's give it return type as well
  5751. 4:41:49belongs to refresh
  5752. 4:41:54it okay we have an error that's probably
  5753. 4:41:57typescript error click on errors okay
  5754. 4:42:00product show is not defined which is
  5755. 4:42:02logical I expected that let's go into
  5756. 4:42:05product controller and Define empty
  5757. 4:42:07function at the moment
  5758. 4:42:10show we are going to accept product
  5759. 4:42:13right here and then we will do something
  5760. 4:42:16in the future but for now let's just
  5761. 4:42:21Define uh root get we're going to access
  5762. 4:42:26to a specific product product slash
  5763. 4:42:30we're going to all the variable product
  5764. 4:42:33we're going to access it by
  5765. 4:42:35Slug and here we're using product
  5766. 4:42:38controller show and the root name Will
  5767. 4:42:41will be product show as
  5768. 4:42:43well so this should be
  5769. 4:42:47enough let's see now this error is gone
  5770. 4:42:50this is something else and we see one
  5771. 4:42:53product is displayed right here it has
  5772. 4:42:56this product title image by vendor in
  5773. 4:43:01electronics department we see price
  5774. 4:43:03right here we need to format the price
  5775. 4:43:05we will come back to this but if we go
  5776. 4:43:08into product details and unpublish this
  5777. 4:43:12into
  5778. 4:43:13draft and refresh it we are not going to
  5779. 4:43:16see anything because we are only
  5780. 4:43:18selecting and displaying published
  5781. 4:43:19products which is actually pretty cool
  5782. 4:43:21it works as it should work now let's
  5783. 4:43:26create let's create another core
  5784. 4:43:29component in react components core and
  5785. 4:43:33I'm going to call this
  5786. 4:43:35component uh
  5787. 4:43:37currency
  5788. 4:43:40format
  5789. 4:43:42js6
  5790. 4:43:44okay now we have this currency format
  5791. 4:43:46and I'm going to accept right
  5792. 4:43:50here we're going to accept amount that
  5793. 4:43:54needs to be formatted we are going to
  5794. 4:43:57accept currency and we're going to
  5795. 4:44:00accept
  5796. 4:44:02local let's define the type as
  5797. 4:44:05well so currency um amount will be
  5798. 4:44:10number
  5799. 4:44:13um currency is actually going to
  5800. 4:44:16be uh string but I'm going to assign
  5801. 4:44:20default value to currency and this is
  5802. 4:44:22going to be USD so I'm going to make
  5803. 4:44:25this currency to be actually optional so
  5804. 4:44:28let me move this down and make this more
  5805. 4:44:35readable okay like
  5806. 4:44:38this and like this so we have now
  5807. 4:44:42currency optional string and we have
  5808. 4:44:45local which is going to be also optional
  5809. 4:44:48and
  5810. 4:44:49string and now inside this uh instead of
  5811. 4:44:53div maybe I can direct directly return
  5812. 4:44:58new Intel
  5813. 4:45:01inl number format and we're going to
  5814. 4:45:04provide local
  5815. 4:45:06here and we're going to provide Style to
  5816. 4:45:11be
  5817. 4:45:12currency and we're going to provide
  5818. 4:45:15currency to be the given currency and
  5819. 4:45:19we're going to call format on
  5820. 4:45:25amount okay with format the code nice
  5821. 4:45:28now let's go into product item and
  5822. 4:45:31instead of price we're going to
  5823. 4:45:34use currency format amount product.
  5824. 4:45:39price
  5825. 4:45:42we save it and now we see price is
  5826. 4:45:45formatted nicely I made comment all the
  5827. 4:45:49changes what we had so far and that was
  5828. 4:45:52actually product listing on the homepage
  5829. 4:45:55and now I'm going to start working on
  5830. 4:45:56product Details page let's open HTTP
  5831. 4:46:00controllers product controller and we're
  5832. 4:46:03going to implement this show method
  5833. 4:46:05right here we're going to
  5834. 4:46:07return inertia render
  5835. 4:46:12product slash show and right here we're
  5836. 4:46:16going to provide the product
  5837. 4:46:18details and for this I'm going to
  5838. 4:46:20actually create new resource so we have
  5839. 4:46:23product list resource which contains
  5840. 4:46:25only few information but product details
  5841. 4:46:29resource or product resource need to
  5842. 4:46:31contain much more information than this
  5843. 4:46:34so let me execute PHP artisan make
  5844. 4:46:39resource
  5845. 4:46:41uppercase P product resource we're going
  5846. 4:46:45to hit the enter product resource was
  5847. 4:46:48created now here we are using this
  5848. 4:46:50product resource providing the product
  5849. 4:46:53correctly and
  5850. 4:46:56optionally not optionally but I want to
  5851. 4:46:59also provide uh the options so this is
  5852. 4:47:03what I plan uh let me actually uh create
  5853. 4:47:06this show first and I will show you
  5854. 4:47:08exactly what I mean so first I need to
  5855. 4:47:11Simply render something on the page so
  5856. 4:47:14let's go into resources JS pages and I'm
  5857. 4:47:18going to create new folder here um let's
  5858. 4:47:21create new typescript file and this is
  5859. 4:47:24going to be inside product folder and
  5860. 4:47:26let's call this show so it created
  5861. 4:47:29product folder show inside there rsf and
  5862. 4:47:33this is called show okay cool let's
  5863. 4:47:36remove this props from here this import
  5864. 4:47:38of react is also not NE accessory and
  5865. 4:47:42let's just write test at the moment okay
  5866. 4:47:45so however we're going to accept right
  5867. 4:47:47here product this is kind of something
  5868. 4:47:50we know for sure and the
  5869. 4:47:53product has type of
  5870. 4:47:56product okay
  5871. 4:47:59cool and let's go into web.php and I I
  5872. 4:48:02think we have these root defined
  5873. 4:48:04properly so we should be good
  5874. 4:48:07let's click on this
  5875. 4:48:11and it doesn't actually show the page
  5876. 4:48:13let's have a
  5877. 4:48:16look product by
  5878. 4:48:22slug okay yeah I stopped the recording
  5879. 4:48:26yesterday continue today so I have this
  5880. 4:48:27mpm run Dev missing and let's also start
  5881. 4:48:31PHP Artisan you
  5882. 4:48:36listen Okay cool now let's see
  5883. 4:48:43let's open Dev tools just in case we
  5884. 4:48:45have some issues click on this okay this
  5885. 4:48:48opens the product Details page and we
  5886. 4:48:50see test right here um so this is now
  5887. 4:48:53what I want to show to you what I want
  5888. 4:48:55to implement so this page is going to
  5889. 4:48:59render the product Details page and we
  5890. 4:49:00will be able to choose different
  5891. 4:49:03variations of the products like we
  5892. 4:49:05defined in the
  5893. 4:49:07interface from the admin panel
  5894. 4:49:13click on this we have the variation
  5895. 4:49:16types we have color size and the user
  5896. 4:49:19will be able to choose different color
  5897. 4:49:21and different different size of item and
  5898. 4:49:23then add that into the product however I
  5899. 4:49:26want to also Implement one very cool
  5900. 4:49:29feature to preserve the URL when user
  5901. 4:49:32makes some changes for example if I
  5902. 4:49:34choose color black and size large I want
  5903. 4:49:38that information to be saved in the URL
  5904. 4:49:41so in the URL I plan to do something
  5905. 4:49:44like this inside options query parameter
  5906. 4:49:46which needs to be an array I'm going to
  5907. 4:49:49add the variation type option ID like
  5908. 4:49:53one uh option ID one we know that it
  5909. 4:49:57refers to
  5910. 4:49:59Black right so one refers to Black so
  5911. 4:50:03option ID one
  5912. 4:50:05and
  5913. 4:50:07options second option let's say large
  5914. 4:50:10six so we're going to exit six right
  5915. 4:50:13here so these Q parameters options one
  5916. 4:50:16and six will Define which variation type
  5917. 4:50:20needs to be selected on the page so that
  5918. 4:50:22whenever I copy the URL send it to my
  5919. 4:50:24wife telling that hey I really like this
  5920. 4:50:27black uh black large um T-shirt whatever
  5921. 4:50:31uh what do you think about it so it's
  5922. 4:50:33going to open the one what I selected in
  5923. 4:50:36the variation options not the first one
  5924. 4:50:37not the default one that's I think
  5925. 4:50:40really useful feature and this is what
  5926. 4:50:41I'm going to do as well so here I'm
  5927. 4:50:45going to pass
  5928. 4:50:48variation
  5929. 4:50:51VAR variation
  5930. 4:50:54options uh I have been traveling the
  5931. 4:50:56entire day today six or seven hours I'm
  5932. 4:50:59kind of tired then it's quite late right
  5933. 4:51:03now and I'm recording options Okay cool
  5934. 4:51:07so we're going to take th those options
  5935. 4:51:10and if the options doesn't exist we're
  5936. 4:51:11going to pass this um empty array uh why
  5937. 4:51:15do we get right here this
  5938. 4:51:18product new product okay this is
  5939. 4:51:20different product
  5940. 4:51:22resource no this is filament product
  5941. 4:51:24resource this is something we don't want
  5942. 4:51:27we
  5943. 4:51:28want HTTP resources product resource
  5944. 4:51:31Okay cool so now we get these options
  5945. 4:51:33and passing these into the view so the
  5946. 4:51:35variation options let's now go
  5947. 4:51:38into this show
  5948. 4:51:41T um TSX file and we're going to accept
  5949. 4:51:43those those variation options
  5950. 4:51:48which we can Define that variation
  5951. 4:51:50options is an array of numbers so now
  5952. 4:51:55right here we're going to print what is
  5953. 4:51:57product and what is
  5954. 4:52:00variation variation options let's have a
  5955. 4:52:04look product let's refresh
  5956. 4:52:09it okay so product actually has the data
  5957. 4:52:12so I think we can remove that
  5958. 4:52:14data
  5959. 4:52:17um inside WP we're going to set this to
  5960. 4:52:25false and we still have that data and
  5961. 4:52:28then we have this entire thing right
  5962. 4:52:31here which is the entire product thing
  5963. 4:52:32so we're going to work on the product
  5964. 4:52:34resource and we have these options here
  5965. 4:52:37as well so now I think we're going to
  5966. 4:52:39focus on this Source right here not this
  5967. 4:52:42one
  5968. 4:52:44but the product
  5969. 4:52:47resource product resource from HTTP
  5970. 4:52:53resources so like
  5971. 4:52:56this so we're going to work on this
  5972. 4:52:58product resource we're going to work on
  5973. 4:53:00this show TSX and this show TS6 is going
  5974. 4:53:03to also show a carousel of the images so
  5975. 4:53:07inside components core I want to create
  5976. 4:53:12a new TSX
  5977. 4:53:15file let's call this Carousel
  5978. 4:53:19TS6 and for the
  5979. 4:53:21carousel we are going to use the
  5980. 4:53:24carousel from the dais y so if we search
  5981. 4:53:28caral right here we're going to find the
  5982. 4:53:31correct example uh we are interested
  5983. 4:53:35inside this one or this one where do
  5984. 4:53:37have we need arrows as well so we have
  5985. 4:53:39this controls okay so I think we can use
  5986. 4:53:42this one which has the uh instead of the
  5987. 4:53:44numbers right here we're going to use
  5988. 4:53:46thumbnails so we render the thumbnails
  5989. 4:53:49and uh we display the image when
  5990. 4:53:51clicking on the thumbnail I think that's
  5991. 4:53:53that's going to be pretty cool okay now
  5992. 4:53:55let's focus on the actual
  5993. 4:53:58work I'm going to remove these props
  5994. 4:54:01right here remove this return and remove
  5995. 4:54:05this react now on the carousel first
  5996. 4:54:08let's import the image type which we are
  5997. 4:54:10going to Define in the index. D.S file
  5998. 4:54:15and here we're going to do a couple of
  5999. 4:54:17other things as well so let's just
  6000. 4:54:19Define image type and we're going to
  6001. 4:54:21give it a number we're going to give it
  6002. 4:54:24the different variations conversions of
  6003. 4:54:27the images so we're going to have
  6004. 4:54:29thumbnail we're going to have small
  6005. 4:54:31we're going to have medium and large
  6006. 4:54:34additionally on the product I am going
  6007. 4:54:37to add variation types which is going to
  6008. 4:54:41be array of variation types which we are
  6009. 4:54:45going to also Define here and I'm going
  6010. 4:54:48to also Define variations which is going
  6011. 4:54:50to be also array and each variation from
  6012. 4:54:54this array will have the following
  6013. 4:54:56format it is going to have ID number
  6014. 4:54:59variation type option IDs which will be
  6015. 4:55:02array of numbers we're going to have
  6016. 4:55:04quantity and price okay so now let's
  6017. 4:55:10let's define variation type right here
  6018. 4:55:15export type variation type and we're
  6019. 4:55:19going to give it ID number we're going
  6020. 4:55:23to give it name to be
  6021. 4:55:26string we're going to give it type to be
  6022. 4:55:29one of the three available types select
  6023. 4:55:33or
  6024. 4:55:34radio or
  6025. 4:55:37image okay and I'm going to give it also
  6026. 4:55:40options variation type has
  6027. 4:55:44variation type option array of variation
  6028. 4:55:48type options and I'm going to also
  6029. 4:55:51Define export type variation uppercase
  6030. 4:55:55fee variation type
  6031. 4:55:57option cool now let's give it ID number
  6032. 4:56:02give it name String give it images to be
  6033. 4:56:07an array of image type which just
  6034. 4:56:10defined and we're going to also have
  6035. 4:56:13type of
  6036. 4:56:16variation
  6037. 4:56:18variation type okay cool however this
  6038. 4:56:22type uh we know that the variation type
  6039. 4:56:24option actually belongs to variation
  6040. 4:56:27type so we can Define this if we need
  6041. 4:56:29that if we don't need that we can omit
  6042. 4:56:31this okay so on the product also we need
  6043. 4:56:35a couple of more additional data so we
  6044. 4:56:38add this variation types and variations
  6045. 4:56:40but we also need a list of images so
  6046. 4:56:43let's add images which is going to be or
  6047. 4:56:47this is this is what I
  6048. 4:56:50advise
  6049. 4:56:52so we defined product list resource
  6050. 4:56:56which has the following type right and
  6051. 4:56:59we're going to Define product Resource
  6052. 4:57:01as well which will have much more data
  6053. 4:57:04so we can do something similar right
  6054. 4:57:07here and we have this product and we can
  6055. 4:57:09call this
  6056. 4:57:10product and leave this as a product or
  6057. 4:57:12we can rename this and call this product
  6058. 4:57:16list item okay uh or we can add
  6059. 4:57:20additional data right
  6060. 4:57:22here so if we create new type and if we
  6061. 4:57:26call this product list item and the new
  6062. 4:57:28one will be product details as an
  6063. 4:57:30example then the product list item can
  6064. 4:57:33have much less data and product list
  6065. 4:57:35item um sorry product list item can have
  6066. 4:57:38much less data and product
  6067. 4:57:40um item um product details needs to have
  6068. 4:57:45um sorry yeah as I mentioned I have been
  6069. 4:57:48TR traveling the entire day seven hours
  6070. 4:57:51I was on the countryside on funeral and
  6071. 4:57:54I'm a little bit tired so um sorry my
  6072. 4:58:00apologies so in this specific case I
  6073. 4:58:03just want to create a single type um I
  6074. 4:58:06don't want to Define two different types
  6075. 4:58:09for product list item and product so I'm
  6076. 4:58:11going to combine them into a single type
  6077. 4:58:13and we're going to have product images
  6078. 4:58:17and with the variation types and
  6079. 4:58:18variations here and I'm going to here
  6080. 4:58:20add array of images as well
  6081. 4:58:24okay and we also need
  6082. 4:58:27description which is going to be
  6083. 4:58:29string right here and I'm going to also
  6084. 4:58:32add short
  6085. 4:58:34description which is going to be also
  6086. 4:58:36string we don't have short description
  6087. 4:58:38in the database but we're going to
  6088. 4:58:40generate that on a
  6089. 4:58:43fly now let's go into Carousel so we
  6090. 4:58:46defined the image we imported that image
  6091. 4:58:48now we're going to Define images uh prop
  6092. 4:58:51right here inside the props we're going
  6093. 4:58:52to take out images which will be array
  6094. 4:58:55of
  6095. 4:58:56images then we're going to create the
  6096. 4:58:59template which I actually copied from
  6097. 4:59:02dayi so we use the following um element
  6098. 4:59:05Flex item start Gap 8 so then inside
  6099. 4:59:09here we're going to have a
  6100. 4:59:11uh div so and this is going to be for uh
  6101. 4:59:15thumbnails okay so I'm going to display
  6102. 4:59:18thumbnails let's open the browser I'm
  6103. 4:59:20going to display thumbnails on the left
  6104. 4:59:22side okay and then on the right side
  6105. 4:59:25we're going to have the actual large
  6106. 4:59:27image just like Amazon does so we're
  6107. 4:59:29going to have thumbnails like
  6108. 4:59:33this okay cool um let's keep doing so
  6109. 4:59:36then we're going to start iterating our
  6110. 4:59:38images and and each image has as we saw
  6111. 4:59:42right
  6112. 4:59:43here uh those variations the conversions
  6113. 4:59:47thumbnail small medium and large so now
  6114. 4:59:50we're going to render the aex for
  6115. 4:59:53thumbnails give it hre we're going to
  6116. 4:59:55give it proper class name and give it
  6117. 4:59:58also key inside there we're going to put
  6118. 5:00:01the actual image tag with image
  6119. 5:00:03thumb okay then down below we're going
  6120. 5:00:06to create this csel and inside there
  6121. 5:00:10we're going to start iterating our
  6122. 5:00:11images second time and we're going to
  6123. 5:00:13create divs with the ID the same string
  6124. 5:00:17what we gave inside the H ref right here
  6125. 5:00:20okay then we're going to give it also
  6126. 5:00:22class name carousal item W full give it
  6127. 5:00:25key and render image inside okay after
  6128. 5:00:30this I think the carousel class is kind
  6129. 5:00:33of ready and let me open product
  6130. 5:00:36resource uh we Define the product
  6131. 5:00:38additional properties right here and we
  6132. 5:00:40need to return um this product from the
  6133. 5:00:43product resource okay so we need ID we
  6134. 5:00:47need Title we need slug description
  6135. 5:00:49price quantity image
  6136. 5:00:53okay additionally we need images array
  6137. 5:00:56and we're going to access images array
  6138. 5:00:58in the following way this get media
  6139. 5:01:01images and we're going to map each media
  6140. 5:01:04into something else and image right here
  6141. 5:01:06is an instance of media model so then
  6142. 5:01:10the uh we're going to take the media ID
  6143. 5:01:13thumbnail small large so we don't even
  6144. 5:01:17have medium do we actually have medium
  6145. 5:01:21now I get
  6146. 5:01:23curious uh let me check
  6147. 5:01:27product.php we registered a couple of
  6148. 5:01:30conversions right thumb small and large
  6149. 5:01:34we don't have
  6150. 5:01:36medium yeah that's correct so initially
  6151. 5:01:40I I decided to have medium then I
  6152. 5:01:42changed my mind so probably we shouldn't
  6153. 5:01:46have medium here so I'm just going to
  6154. 5:01:48remove that we are not going to have
  6155. 5:01:50medium do we have this medium anywhere
  6156. 5:01:53else
  6157. 5:01:55written this is not related to image
  6158. 5:01:58okay my
  6159. 5:02:00bed go into product resource so we
  6160. 5:02:03return thumb small large then we're
  6161. 5:02:05going to continue and we are going to
  6162. 5:02:07return the user information with the ID
  6163. 5:02:09in name and we're going to return also
  6164. 5:02:11Department information and we're going
  6165. 5:02:13to return variation types as well so
  6166. 5:02:17we're going to iterate over the
  6167. 5:02:18variation types and we're going to
  6168. 5:02:20return the variation type ID name the
  6169. 5:02:23variation type itself whether it is
  6170. 5:02:25Select radio image and we are going to
  6171. 5:02:29also return options each variation type
  6172. 5:02:32has multiple options and we're going to
  6173. 5:02:34iterate over these variation options and
  6174. 5:02:37map it into the following array ID name
  6175. 5:02:41and each variation option might have its
  6176. 5:02:45own set of images and just like we are
  6177. 5:02:48taking product images right here in the
  6178. 5:02:50same way we are going to take variation
  6179. 5:02:54type options images so we we're
  6180. 5:02:57accessing those images
  6181. 5:02:59collection and we're going to return ID
  6182. 5:03:02thumbnail small and
  6183. 5:03:05large and finally we are going to also
  6184. 5:03:08return variations with product
  6185. 5:03:11variations for this we're going to
  6186. 5:03:13return ID variation type option IDs
  6187. 5:03:16which is going to be
  6188. 5:03:18Json and quantity and
  6189. 5:03:22price okay that giant product object
  6190. 5:03:25will be pushed into show TS6 and this is
  6191. 5:03:30the place we are going to access um that
  6192. 5:03:34from the product right
  6193. 5:03:36here now this file is a little bit
  6194. 5:03:40complicated and also really interesting
  6195. 5:03:43so you're going to bear with me so if
  6196. 5:03:45you don't understand certain things
  6197. 5:03:48immediately just repeat the video and
  6198. 5:03:50I'm going to re explain also things in a
  6199. 5:03:53more understandable way okay so this
  6200. 5:03:57file will have a lot of functionality so
  6201. 5:04:00we are going to prepare data uh for Ed
  6202. 5:04:03to card functionality so in this
  6203. 5:04:05component we're going to have Ed to card
  6204. 5:04:06Button as well and the Ed to card fun
  6205. 5:04:09functionality will also consider
  6206. 5:04:11different variation options variation
  6207. 5:04:14option IDs and we're going to send those
  6208. 5:04:17variation option IDs alongside with the
  6209. 5:04:19add to click because if we add
  6210. 5:04:23green um headset in our cart then we
  6211. 5:04:27want it to be green not the black one
  6212. 5:04:29right so we're going to pass that
  6213. 5:04:30additional variation type option IDs as
  6214. 5:04:34well and we're going to also update the
  6215. 5:04:37images section based on the selected
  6216. 5:04:40option so a lot of things is going on in
  6217. 5:04:42this object so in this component so bear
  6218. 5:04:44with me as I mentioned so first we're
  6219. 5:04:46going to define the form and that form
  6220. 5:04:50will have option IDs which we're going
  6221. 5:04:51to send to the server and the option IDs
  6222. 5:04:54is going to be actually object where the
  6223. 5:04:57key is going to be the
  6224. 5:04:59variation type
  6225. 5:05:03ID this one and the corresponding number
  6226. 5:05:06will be the the option ID for that
  6227. 5:05:10variation type so if we have a look at
  6228. 5:05:12our example if the ID for the color is
  6229. 5:05:15one and the ID for Blake is one as well
  6230. 5:05:20so we are going to send on the server H
  6231. 5:05:23Json let me open now scratch file a
  6232. 5:05:28Json like
  6233. 5:05:31this one which is going to be actually
  6234. 5:05:33string one one so one variation type ID
  6235. 5:05:38has the corresponding variation type
  6236. 5:05:40option ID added into the cart so
  6237. 5:05:42additionally we're going to give it also
  6238. 5:05:44quantity and the price is um kind of
  6239. 5:05:48optional so we're going to still pass
  6240. 5:05:49the price and that price uh can be used
  6241. 5:05:53on the back end or if we don't provide
  6242. 5:05:55any price we can take it or take the
  6243. 5:05:57default price um as well from the server
  6244. 5:06:00okay but the price might be different
  6245. 5:06:03based on which variation option we're
  6246. 5:06:06going to choose right so that's why
  6247. 5:06:08we're going to send the prices as
  6248. 5:06:11well so next uh we're going to Define
  6249. 5:06:14the types so these are actually um types
  6250. 5:06:18for our form now we're going to assign
  6251. 5:06:20default value so option IDs is going to
  6252. 5:06:22be object quantity is going to be one
  6253. 5:06:24price is going to be null and we're
  6254. 5:06:26going to implement that to populate the
  6255. 5:06:28price on the variation uh option
  6256. 5:06:31change next we're going to Define we're
  6257. 5:06:34going to take the URL from the current
  6258. 5:06:36page um and uh the use form and use page
  6259. 5:06:39P needs to be imported and we're going
  6260. 5:06:40to do it after I finish the code right
  6261. 5:06:43here so we're going to take the URL and
  6262. 5:06:46we will use that URL when we change the
  6263. 5:06:49option so when we change the option
  6264. 5:06:51remember so in the URL we're going to
  6265. 5:06:53have those options right here and those
  6266. 5:06:57options will be updated when we start
  6267. 5:06:59clicking on different options right here
  6268. 5:07:02that's why we take the current URL and
  6269. 5:07:04push the options qer parameter inside
  6270. 5:07:07that URL by the way I mentioned that
  6271. 5:07:09that op options needs to be a plain
  6272. 5:07:11array like this this is what I
  6273. 5:07:15mentioned but actually I improved that
  6274. 5:07:18part as well and instead of having these
  6275. 5:07:20options as plain array of one and six
  6276. 5:07:23I'm going to also use variation type ID
  6277. 5:07:26here so variation type ID like one is
  6278. 5:07:29the color has
  6279. 5:07:32um option one and variation type two has
  6280. 5:07:37um id6 so these are the options um I
  6281. 5:07:42want to add I want to view right now at
  6282. 5:07:44the moment on on the screen okay hit the
  6283. 5:07:47enter we see that the URL will be
  6284. 5:07:48updated it's going to be encoded I think
  6285. 5:07:51no it wasn't anyway okay so next we are
  6286. 5:07:54going to Define state in that state is
  6287. 5:07:56going to be selected options so we might
  6288. 5:07:59have uh only one variation type or maybe
  6289. 5:08:03more like in our case we have two
  6290. 5:08:05variation types color and size and we
  6291. 5:08:08might even have three or four so all
  6292. 5:08:10these selected options will be saved
  6293. 5:08:13right here in the selected options and
  6294. 5:08:15this is going to be actually an array
  6295. 5:08:17okay um array of certain things and this
  6296. 5:08:21is um what I'm going to uh Define so
  6297. 5:08:25these selected options will be an array
  6298. 5:08:28where the key is going to be number and
  6299. 5:08:31that number is going to be variation
  6300. 5:08:33type ID like we had right here one but
  6301. 5:08:38the value is going to to the entire
  6302. 5:08:40variation type option what we already
  6303. 5:08:42have defined right here and that
  6304. 5:08:45variation type option will have ID name
  6305. 5:08:48images and type as well but I think we
  6306. 5:08:50are not going to use type uh if we don't
  6307. 5:08:52use it I'm going to remove the type but
  6308. 5:08:54the main thing is that the variation
  6309. 5:08:56type will have ID name and images and
  6310. 5:08:58we're going to use these three
  6311. 5:09:00properties from this variation type
  6312. 5:09:02option okay cool
  6313. 5:09:05then whenever the product and select
  6314. 5:09:09options will be changed either product
  6315. 5:09:12or selected options will be changed I
  6316. 5:09:14want to calculate the images okay and
  6317. 5:09:18for this I'm using this use memo hook
  6318. 5:09:21I'm going to calculate the images and
  6319. 5:09:23return those images so if the current
  6320. 5:09:27product has no images no sorry if the
  6321. 5:09:31current product has no variation types
  6322. 5:09:34then we take the images from the current
  6323. 5:09:37product images area
  6324. 5:09:40right however if the current product has
  6325. 5:09:43variation types and some of the
  6326. 5:09:45variation type has its own
  6327. 5:09:48images uh those variation the images are
  6328. 5:09:53um actually inside the variation type
  6329. 5:09:55options right so we have black option
  6330. 5:09:58and black option has images so right
  6331. 5:10:00here we're going to calculate and return
  6332. 5:10:02the corresponding images okay let me
  6333. 5:10:04finish this and I think this will get
  6334. 5:10:06very clear so we're going to iterate
  6335. 5:10:08over selected options we're going to get
  6336. 5:10:11the key so inside the selected options
  6337. 5:10:13the uh key will be type ID and we're
  6338. 5:10:16going to have object variation type
  6339. 5:10:17option we're going to take the option
  6340. 5:10:19from the selected options and now we're
  6341. 5:10:22going to do the following so if option
  6342. 5:10:23images length is more than zero so if
  6343. 5:10:27option has a li images then we are
  6344. 5:10:30returning these option images as the
  6345. 5:10:32product images however if the uh option
  6346. 5:10:35doesn't have Imes finally at the end of
  6347. 5:10:37this for Loop we are going to return
  6348. 5:10:40product
  6349. 5:10:42images all right and just like this
  6350. 5:10:44we're going to have always uh calculated
  6351. 5:10:47images if nothing is selected no option
  6352. 5:10:50is selected however if there are some uh
  6353. 5:10:53variation types defined like as an
  6354. 5:10:56example color and size we're going to
  6355. 5:10:59always select the first option so it is
  6356. 5:11:02going to always pick up the first option
  6357. 5:11:05corresponding images all right okay okay
  6358. 5:11:09cool uh also yeah one additional thing
  6359. 5:11:12you should also keep in mind is that we
  6360. 5:11:15added
  6361. 5:11:16those uh images to options like we added
  6362. 5:11:19this into black blue purple but we
  6363. 5:11:22didn't add those into other options like
  6364. 5:11:26for small or medium or large so in
  6365. 5:11:31theory if we make this even more complex
  6366. 5:11:34scenario so you might also need to to
  6367. 5:11:40upload different images for different
  6368. 5:11:43combinations of variation types like we
  6369. 5:11:47defined um different quantity and price
  6370. 5:11:50for blue small you might want to upload
  6371. 5:11:53different images for blue small and
  6372. 5:11:55different images for black small and
  6373. 5:11:57different images for black medium and
  6374. 5:12:01all these kind of things and we we can
  6375. 5:12:03do this of course everything is possible
  6376. 5:12:05in programming just um I didn't decide
  6377. 5:12:07to do this because I didn't want to make
  6378. 5:12:09this even more complex so it is not also
  6379. 5:12:13very common to have uh even Amazon has
  6380. 5:12:16like when I checked in different cases
  6381. 5:12:19has only one set of images which is
  6382. 5:12:22dependent on one variation type it's not
  6383. 5:12:25depending on multiple variation types
  6384. 5:12:27maybe there are some cases on Amazon as
  6385. 5:12:29well but we aren't Amazon right so we
  6386. 5:12:31can't build uh something like Amazon in
  6387. 5:12:33in like one video tutorial so it's a
  6388. 5:12:37slightly simpler it can be even more
  6389. 5:12:40complicated just I wanted to mention to
  6390. 5:12:42you how you can make this even more
  6391. 5:12:45complex so in our case if we have inside
  6392. 5:12:47selected options let's say black and
  6393. 5:12:50small we know that uh only one option
  6394. 5:12:53will have images and the first case
  6395. 5:12:56whenever we catch that that specific
  6396. 5:12:58option has images we are returning those
  6397. 5:13:00images so we don't want to check second
  6398. 5:13:02option because we are just interested as
  6399. 5:13:05soon as we find some options in the uh
  6400. 5:13:08variation of options so in our case
  6401. 5:13:11again if we
  6402. 5:13:13upload images on black and if we upload
  6403. 5:13:17images on small as well
  6404. 5:13:21so I one of them will be displayed so
  6405. 5:13:24both of them obviously will not be
  6406. 5:13:26displayed if you select black and small
  6407. 5:13:28the first one right here whichever it's
  6408. 5:13:31going to be we don't know it might be
  6409. 5:13:32small it might be black the
  6410. 5:13:34corresponding images will be
  6411. 5:13:37returned okay I I think
  6412. 5:13:39this is clear we can move on the next
  6413. 5:13:41part and we're going to see what is this
  6414. 5:13:42images as well and how it gets updated
  6415. 5:13:46the next one is that we are going to
  6416. 5:13:47also listen to this product and selected
  6417. 5:13:50options uh second time but in this case
  6418. 5:13:52we are going to return uh computed
  6419. 5:13:56product data and this is necessary for
  6420. 5:13:59price and quantity we have the default
  6421. 5:14:01price and quantity on the product level
  6422. 5:14:04but for different variation options we
  6423. 5:14:06overwrite the price and quantity right
  6424. 5:14:09so here we take the selected option IDs
  6425. 5:14:14so we know that selected options is a
  6426. 5:14:17map where the key is the type ID and the
  6427. 5:14:21um option the value is the variation
  6428. 5:14:24type option so we get the values all
  6429. 5:14:26values here then we call map and get the
  6430. 5:14:29option ID and then we sort that so
  6431. 5:14:32finally inside selected option IDs we're
  6432. 5:14:34going to have always sorted option IDs
  6433. 5:14:38like one and five one and six three and
  6434. 5:14:43five whatever okay so we have that
  6435. 5:14:45selected option idas next is I'm going
  6436. 5:14:47to iterate over product variations so
  6437. 5:14:51product variations is the variations
  6438. 5:14:55what is already defined on the product
  6439. 5:14:58and we have assigned some quantity and
  6440. 5:15:03price this might be also null or empty
  6441. 5:15:06array not null but empty array if we
  6442. 5:15:09decided that we don't want to override
  6443. 5:15:11price and quantity for different
  6444. 5:15:13variation uh variation types then we are
  6445. 5:15:17not going to Define this and the data
  6446. 5:15:19inside product variations table will be
  6447. 5:15:22empty for that specific product and thus
  6448. 5:15:25this will be an empty array if it's an
  6449. 5:15:27empty array it's not a problem it is
  6450. 5:15:29going to take the default product
  6451. 5:15:30quantity and price but if it's not an
  6452. 5:15:33empt array we take the variation and we
  6453. 5:15:36get the variation uh type option IDs and
  6454. 5:15:40sort this as well so we have selected
  6455. 5:15:43option IDs here we
  6456. 5:15:46have uh existing variations type option
  6457. 5:15:50IDs here sorted as well and I want to
  6458. 5:15:52compare now this option IDs into this
  6459. 5:15:56and if they match then I want to take
  6460. 5:15:59the price and quantity from that
  6461. 5:16:00specific variation so I'm going to
  6462. 5:16:03create new function uh arrays are equal
  6463. 5:16:08arrays are equal and I'm going to do
  6464. 5:16:10this inside a new file now which simply
  6465. 5:16:13will compare two arrays like selected
  6466. 5:16:16option IDs and option IDs okay so let's
  6467. 5:16:21imagine that that function already
  6468. 5:16:24exists in one of the files and it does
  6469. 5:16:27the work so it Compares two arrays this
  6470. 5:16:30and this and if they are the same array
  6471. 5:16:33then we're going to do something so if
  6472. 5:16:36they are the same array then we are
  6473. 5:16:37returning the variation price and
  6474. 5:16:39variation quantity however if the
  6475. 5:16:42variation quantity is null it means that
  6476. 5:16:44we have that specific variation with
  6477. 5:16:46unlimited quantity so we're going to
  6478. 5:16:49return number max value otherwise we are
  6479. 5:16:52going to return the variation quantity
  6480. 5:16:54if it is not
  6481. 5:16:56null however after this for Loop if the
  6482. 5:17:00matching wasn't happened then we are
  6483. 5:17:03returning the product price and product
  6484. 5:17:06quantity okay cool now we have this
  6485. 5:17:08imputed product which we're going to use
  6486. 5:17:11in the template will contain price and
  6487. 5:17:14quantity for the selected variation
  6488. 5:17:18options cool next we are going to listen
  6489. 5:17:22to mounted hook and on mounted we're
  6490. 5:17:24going to iterate over the variation
  6491. 5:17:26types and this is what I am going to do
  6492. 5:17:30so from the existing variation options
  6493. 5:17:33that variation options it is what we
  6494. 5:17:35give from the component what we actually
  6495. 5:17:37have in the
  6496. 5:17:39URL right here so we pass those
  6497. 5:17:42variation options from the controller on
  6498. 5:17:45controller we take this from request so
  6499. 5:17:47whatever we have written here like one
  6500. 5:17:50corresponds to one two corresponds to
  6501. 5:17:52six that will be these variation options
  6502. 5:17:57so now what we do here is to take the
  6503. 5:18:01selected option ID from this variation
  6504. 5:18:03options but variation options might be
  6505. 5:18:06also an empty uh object okay or empty
  6506. 5:18:10array so we provide default value as
  6507. 5:18:13array right here so it might be empty uh
  6508. 5:18:16object or array so when we try to take
  6509. 5:18:18type ID from that uh array actually is
  6510. 5:18:21also object in JavaScript when we try to
  6511. 5:18:24take this type ID from this variation
  6512. 5:18:27options if it's empty the selected
  6513. 5:18:29option ID will be
  6514. 5:18:30null if there is something like what we
  6515. 5:18:34have right now and if we also have one
  6516. 5:18:37variation type ID then for one this is
  6517. 5:18:41going to return one as well so if um
  6518. 5:18:46type is two it is going to return six
  6519. 5:18:51and actually we are doing this for all
  6520. 5:18:52the available variation types so in this
  6521. 5:18:54specific case for this specific URL so
  6522. 5:18:57it is going to iterate over the
  6523. 5:18:58variation types and we know that we have
  6524. 5:19:00two variation types for our product um
  6525. 5:19:03with ID one and two and for both of them
  6526. 5:19:07we're going to get the variation option
  6527. 5:19:09ID and then we're going to set that
  6528. 5:19:11variation option so let's print this
  6529. 5:19:14selected option ID and we're going to
  6530. 5:19:15also print the type options but after
  6531. 5:19:18this uh we're going to call the function
  6532. 5:19:21which we're going to create choose
  6533. 5:19:23option so we have now type ID and we are
  6534. 5:19:28going to choose specific option and that
  6535. 5:19:31specific option we're going to Peck from
  6536. 5:19:34the type options type options is array
  6537. 5:19:37of objects we know we Define this right
  6538. 5:19:41here uh right here so using array find
  6539. 5:19:45we are going to try to find the option
  6540. 5:19:48with the selected option ID what we have
  6541. 5:19:51right now selected in the URL like if we
  6542. 5:19:54have selected in the URL six we are
  6543. 5:19:56going to try to find the
  6544. 5:19:58six uh corresponding option
  6545. 5:20:02object okay so we are passing inside
  6546. 5:20:04this choose option three arguments first
  6547. 5:20:06is the type ID second second is the
  6548. 5:20:09option and third is whether we want to
  6549. 5:20:12update the URL right now or not so
  6550. 5:20:15because we are doing this on mounted
  6551. 5:20:17hook we don't want the URL to be updated
  6552. 5:20:20because we are actually reading this
  6553. 5:20:21from the URL right here through this
  6554. 5:20:24variation types but in another place
  6555. 5:20:26when we call choose option whenever we
  6556. 5:20:28click on the specific option we want to
  6557. 5:20:31update the URL so in the second place we
  6558. 5:20:33are going to pass uh true right here in
  6559. 5:20:36this choose option so if the option was
  6560. 5:20:39not found for some reason and that some
  6561. 5:20:42reason might be that we might not have
  6562. 5:20:44anything in the URL like if we delete
  6563. 5:20:47this the URL might look like this in
  6564. 5:20:49which case selected option ID is
  6565. 5:20:51actually empty so and finding the option
  6566. 5:20:55will not work in which case we will
  6567. 5:20:57simply take the first option from type
  6568. 5:21:01options
  6569. 5:21:02cool now next so this was mounted hook
  6570. 5:21:07next we're going to create create that
  6571. 5:21:09get option IDs map that is additional
  6572. 5:21:11helper function which we are going to
  6573. 5:21:14actually
  6574. 5:21:16use so we are going to get the new
  6575. 5:21:20options object as an argument and we're
  6576. 5:21:23going to do the following so we are
  6577. 5:21:25going to call object entries on this new
  6578. 5:21:29options and this is going to actually
  6579. 5:21:32return uh the new options will be type
  6580. 5:21:36it's going to be object where key is
  6581. 5:21:38going to be the type ID and the value is
  6582. 5:21:42go going to be the entire object so
  6583. 5:21:44these new options will have the same
  6584. 5:21:46format as selected
  6585. 5:21:49options okay and we know that the
  6586. 5:21:51selected
  6587. 5:21:52options selected options is something
  6588. 5:21:55like this let me show this to you we we
  6589. 5:21:57we covered this but uh if it's not clear
  6590. 5:22:00I'm going to make this very clear so
  6591. 5:22:01selected options will have ID one and
  6592. 5:22:04its corresponding entire object like the
  6593. 5:22:08object with will have
  6594. 5:22:09ID because this is Json let's make it
  6595. 5:22:12string but we know that the ID is number
  6596. 5:22:14so ID uh let's say one and its
  6597. 5:22:19corresponding name is going to be
  6598. 5:22:23black and uh its corresponding images as
  6599. 5:22:27well so this is going to be uh the
  6600. 5:22:30option so down below from this um get
  6601. 5:22:33option IDs map so we're calling uh
  6602. 5:22:37object entries on this new options which
  6603. 5:22:40converts that into entries then we are
  6604. 5:22:43calling a map on that and we are
  6605. 5:22:46returning this a unchanged which is
  6606. 5:22:50going to be type ID but B is the entire
  6607. 5:22:54object right so we are actually taking
  6608. 5:22:57only ID from this object so after then
  6609. 5:23:00again we call this from entries so after
  6610. 5:23:03this get option IDs map the following
  6611. 5:23:06type of object will be converted
  6612. 5:23:09into something like this okay so instead
  6613. 5:23:14of that object we are mapping into the
  6614. 5:23:16ID only so this is going to be get
  6615. 5:23:19option IDs map so after which now let's
  6616. 5:23:23define this choose option what we
  6617. 5:23:25already used right here so inside choose
  6618. 5:23:28option we're going to accept three
  6619. 5:23:29arguments type ID option and updates
  6620. 5:23:32rouer or Not by default it's going to be
  6621. 5:23:34true and now this is what we are going
  6622. 5:23:37to do we're going to call set selected
  6623. 5:23:40options we are uh providing callback
  6624. 5:23:43here inside the Callback we accept the
  6625. 5:23:45previous selected
  6626. 5:23:47options then we are going to create
  6627. 5:23:50construct this new options which is
  6628. 5:23:52going to be previous options merged with
  6629. 5:23:56the current option what we are trying to
  6630. 5:23:59select what we are trying to choose
  6631. 5:24:01right now so we are using the type ID as
  6632. 5:24:05a key and the entire object as value so
  6633. 5:24:07now have this new new options and if the
  6634. 5:24:10update router is true then we are using
  6635. 5:24:14that current URL which we took at the
  6636. 5:24:17beginning of this component right here
  6637. 5:24:19from this page so and we are calling
  6638. 5:24:22rotor get on that URL and we're
  6639. 5:24:25providing such type of options so we
  6640. 5:24:29know that new options is um ID matched
  6641. 5:24:33on the entire object but on the URL
  6642. 5:24:37inside the URL we want only object
  6643. 5:24:39something like this so we are calling
  6644. 5:24:41this get option IDs map on the new
  6645. 5:24:43options and putting giving this inside
  6646. 5:24:45the URL additionally I'm going to also
  6647. 5:24:47give preserve scroll true and preserve
  6648. 5:24:50State true this is inertia JS um
  6649. 5:24:54parameters and that basically will not
  6650. 5:24:56update the URL and it's going to
  6651. 5:24:58preserve also uh currently selected
  6652. 5:25:02option SEL selected State inside the
  6653. 5:25:06component okay cool rotor is also needs
  6654. 5:25:08to be imported we're going to import
  6655. 5:25:10this um after we finish writing this
  6656. 5:25:12code so next so and finally because
  6657. 5:25:16we're calling actually set selected
  6658. 5:25:18options here from this set selected
  6659. 5:25:21options we are going to return this new
  6660. 5:25:23options because uh inside the set
  6661. 5:25:26selected options you can either provide
  6662. 5:25:27the op the options itself or a call
  6663. 5:25:30function and uh inside the call function
  6664. 5:25:32you're going to return something that
  6665. 5:25:34needs to be assigned to the set selected
  6666. 5:25:37options
  6667. 5:25:39next we are going to Define additional
  6668. 5:25:41functions and we're going to listen on
  6669. 5:25:44quantity change so whenever quantity is
  6670. 5:25:47changed uh we are so obviously we
  6671. 5:25:50haven't even created that quantity uh
  6672. 5:25:54component but uh that's going to be a
  6673. 5:25:56select HTML select element so when the
  6674. 5:26:00quantity is changed this is what we are
  6675. 5:26:02going to do inside the form we are going
  6676. 5:26:04to update the quantity data and we're
  6677. 5:26:07going to par that even Target value
  6678. 5:26:09that's it it's not complicated so this
  6679. 5:26:12is all what we're going to do so we're
  6680. 5:26:14going to also listen to Ed to cart
  6681. 5:26:17button and
  6682. 5:26:19whenever excuse me whenever that happens
  6683. 5:26:21whenever we click on the button we're
  6684. 5:26:23going to send post request to the
  6685. 5:26:26following root which we're going to
  6686. 5:26:28Define of course so we have a lot of
  6687. 5:26:30things to Define but I want to focus on
  6688. 5:26:32this file because I think this file is
  6689. 5:26:35um one of the most complicated so far
  6690. 5:26:40so in this um form post we're providing
  6691. 5:26:43the URL and the product ID but we're
  6692. 5:26:46going to also provide these preserve
  6693. 5:26:48scroll and preserve State parameters
  6694. 5:26:51okay that's for it to cart and we're
  6695. 5:26:53going to just log something in case of
  6696. 5:26:55error now I'm going to create uh two
  6697. 5:26:59more functions and one of them is going
  6698. 5:27:01to be to render product variation types
  6699. 5:27:04and second is going to render AED to
  6700. 5:27:07card button so this is going to be
  6701. 5:27:10really interesting this is slightly
  6702. 5:27:12easier and
  6703. 5:27:14straightforward so I will in Implement
  6704. 5:27:17these functions later and now I'm going
  6705. 5:27:21to do one last thing uh right here
  6706. 5:27:23before I move into the template I want
  6707. 5:27:26to um basically watch at the selected
  6708. 5:27:29options and whenever that changes I want
  6709. 5:27:33to take those selected options and I
  6710. 5:27:37want to create ID map of that selected
  6711. 5:27:40options and I want to print that map and
  6712. 5:27:43I want to put that inside option IDs as
  6713. 5:27:46well so I'm doing something similar what
  6714. 5:27:52has been
  6715. 5:27:54done let's have a look right here
  6716. 5:27:57through this method get option IDs map
  6717. 5:28:00and I was using that get option IDs
  6718. 5:28:03map um
  6719. 5:28:08right here okay but um here I am doing
  6720. 5:28:13this because I want to update the form
  6721. 5:28:15option ID is data okay and basically I'm
  6722. 5:28:20reading this selected options then
  6723. 5:28:22mapping this um we are providing right
  6724. 5:28:25here um actually let me let me redo this
  6725. 5:28:30and re explain this so first we call
  6726. 5:28:33this object entries we convert this into
  6727. 5:28:36entries we get right here type ID and
  6728. 5:28:39option uh we also Define the types the
  6729. 5:28:42type ID is string option is variation
  6730. 5:28:44type option and then we're calling this
  6731. 5:28:47map uh we return type ID and we return
  6732. 5:28:50option ID so we're converting this into
  6733. 5:28:53this okay and finally we're going to
  6734. 5:28:56call object entries from entries right
  6735. 5:28:58here which converts this into ID's map
  6736. 5:29:00so we'll Lo log this ID's map and we
  6737. 5:29:02assign this into option ID so whenever
  6738. 5:29:04we submit the form after this it is
  6739. 5:29:06going to send the following data into
  6740. 5:29:08the server on the backand side now I'm
  6741. 5:29:11going to focus on the template so we use
  6742. 5:29:13the authenticated layout we're going to
  6743. 5:29:15Define this head actually it is home
  6744. 5:29:18right here which probably I copied from
  6745. 5:29:20home but I'm going to change this as
  6746. 5:29:22well okay for now let's leave it because
  6747. 5:29:24if I change something I will not be able
  6748. 5:29:26to actually um quickly paste the the the
  6749. 5:29:30code right
  6750. 5:29:32here so then I'm going to create this
  6751. 5:29:34Con container with t and CSS classes
  6752. 5:29:37inside here I'm going to create
  6753. 5:29:39additional div okay and then with call
  6754. 5:29:43SP 7 so we're going to have the left
  6755. 5:29:45side area and the right side area Okay
  6756. 5:29:48the right side area is going to be where
  6757. 5:29:51we display the A2 C uh button and uh the
  6758. 5:29:56variations okay similar to how Amazon
  6759. 5:29:59does it so we defined the 12 column grid
  6760. 5:30:03on the large screens the left side is
  6761. 5:30:05seven the right side is going to be five
  6762. 5:30:08in the left side we have this Carousel
  6763. 5:30:10of images on the right side we're going
  6764. 5:30:11to have uh the product title we're going
  6765. 5:30:14to have uh the uh price for the product
  6766. 5:30:19and we're going to render the product
  6767. 5:30:21variation type so we are using that
  6768. 5:30:23function which needs to be implemented
  6769. 5:30:26and also we're going to render the um
  6770. 5:30:29we're going to render the like alert
  6771. 5:30:32message if the quantity of the product
  6772. 5:30:35is less than 10 so if the quantity is
  6773. 5:30:37not undefined and if it's less than 10
  6774. 5:30:41then we're going to render something
  6775. 5:30:43with text error that only whatever is
  6776. 5:30:47quantity left so if there are less than
  6777. 5:30:5010 items like if seven so only seven
  6778. 5:30:53items left seven left or something like
  6779. 5:30:56this so this is just information to the
  6780. 5:30:59user after this I'm going to render a to
  6781. 5:31:02cart button and we're going to have also
  6782. 5:31:06um section for the about this item is
  6783. 5:31:08going to be description similar to how
  6784. 5:31:10Amazon does we can have a look again
  6785. 5:31:13here so we're going to have the title
  6786. 5:31:15we're going to have price the
  6787. 5:31:17variations here and then we're going to
  6788. 5:31:20have this about this item
  6789. 5:31:23description
  6790. 5:31:26okay so inside here I'm going to create
  6791. 5:31:28div with what you see like we seewig
  6792. 5:31:32output and I'm going to Dangerously set
  6793. 5:31:35a inner HTML which is going to be
  6794. 5:31:38product description so if you don't know
  6795. 5:31:40what this actually does it renders HTML
  6796. 5:31:45properly okay uh it doesn't encode
  6797. 5:31:49without that dangerously set in your
  6798. 5:31:50HTML if I directly render the product
  6799. 5:31:53description it is going to show the uh
  6800. 5:31:56less than and greater than symbols for
  6801. 5:31:59HTML TXS it is not going to render it
  6802. 5:32:02properly so we want the Bold tags or
  6803. 5:32:05lists or something like this to be
  6804. 5:32:08rendered nicely and
  6805. 5:32:10properly okay we're going to move and
  6806. 5:32:12now we we are I think done on the
  6807. 5:32:15template and I'm going to focus on these
  6808. 5:32:17two functions render product variation
  6809. 5:32:19types so here we're going to iterate
  6810. 5:32:21over the variation types and we are
  6811. 5:32:25going to create deal with the type ID
  6812. 5:32:27we're going to display the type name
  6813. 5:32:29which is going to be color or size then
  6814. 5:32:33we are going to check if the type equals
  6815. 5:32:35image then we're going to render your
  6816. 5:32:39thumbnails just like Amazon
  6817. 5:32:41does okay so here we're going to create
  6818. 5:32:45div uh and then we're going to iterate
  6819. 5:32:48over
  6820. 5:32:49options and because we know that the
  6821. 5:32:52type is images we expect images will be
  6822. 5:32:55uploaded here so option will have some
  6823. 5:32:57images so this is what we are doing so
  6824. 5:33:01we we are also adding onclick listener
  6825. 5:33:03to the Steve so whenever we click on
  6826. 5:33:05that uh image like we doing Amazon so we
  6827. 5:33:09want to update the option so Amazon does
  6828. 5:33:11this on Hover as well but we're going to
  6829. 5:33:13actually do this only on click okay so
  6830. 5:33:18we we call this choose option provide
  6831. 5:33:19the type ID and the
  6832. 5:33:22option well let's give it key as well
  6833. 5:33:25next if the option images exists then we
  6834. 5:33:29display the first image from the option
  6835. 5:33:32images okay and we're going to give it
  6836. 5:33:36classes as well with with 50 pixel and
  6837. 5:33:40if that specific option is selected so
  6838. 5:33:43if inside selected options for the given
  6839. 5:33:49type uh there exists something and its
  6840. 5:33:52ID equals the option ID it means that
  6841. 5:33:56this specific option is actually
  6842. 5:33:59selected and if it is selected we give
  6843. 5:34:01it outline outline four outline primary
  6844. 5:34:04CSS classes otherwise we give it empty
  6845. 5:34:07class classes so that if basically means
  6846. 5:34:10that if that option uh is added inside
  6847. 5:34:14selected
  6848. 5:34:16options uh for that specific type
  6849. 5:34:18ID cool after
  6850. 5:34:24this we are going to handle the second
  6851. 5:34:28type as well so we handled this for Type
  6852. 5:34:31image but the second type what we have
  6853. 5:34:34is radio so if the type equals radio
  6854. 5:34:37then we create this div and that
  6855. 5:34:40actually is um going to be so we have
  6856. 5:34:45that join edit here so let me show this
  6857. 5:34:47to you from da UI so we're going to use
  6858. 5:34:53join which is this okay so if we check
  6859. 5:34:58um I think we don't have that primary
  6860. 5:35:00image example but that that is it and we
  6861. 5:35:03can
  6862. 5:35:06use radio so join radio inputs with
  6863. 5:35:10button style so these are actually radio
  6864. 5:35:12buttons But whichever is chosen it
  6865. 5:35:15changes the color so exactly this is
  6866. 5:35:17what I am going to do in my case so I'm
  6867. 5:35:20using this join item so now so I created
  6868. 5:35:23this D with join and I'm going to
  6869. 5:35:25iterate other options and I'm going to
  6870. 5:35:28create this um input uh and I'm going to
  6871. 5:35:31listen its change whenever it it's it's
  6872. 5:35:35going to be changed then I call this
  6873. 5:35:38choose option with the type ID and the
  6874. 5:35:42option and we're going to give it also
  6875. 5:35:44key and give it some tal C classes join
  6876. 5:35:48item button type radio value option ID
  6877. 5:35:52it's going to be the value and whether
  6878. 5:35:54it is going to be checked or not it
  6879. 5:35:56really depends on if the option ID is
  6880. 5:36:00inside selected options for the given
  6881. 5:36:02type so this selected check is done in
  6882. 5:36:06the same way we did for image right here
  6883. 5:36:10okay and we're going to also give it a
  6884. 5:36:12name and we're going to give it the name
  6885. 5:36:14basically needs to be the same for all
  6886. 5:36:16the inputs because we are going to
  6887. 5:36:18render multiple um inputs uh one for
  6888. 5:36:22each option but all of them will be for
  6889. 5:36:24the same type ID okay and the name will
  6890. 5:36:26be variation type with a type ID of same
  6891. 5:36:29name and area label so after which we
  6892. 5:36:33can move onto the last method which is
  6893. 5:36:36render Ed to card button so we create
  6894. 5:36:39the div we're going to create the select
  6895. 5:36:41with the value form data quantity and
  6896. 5:36:43we're going to listen on change whenever
  6897. 5:36:45this happens we call this on quantity
  6898. 5:36:47change which is a very straightforward
  6899. 5:36:49method so we simply set inside the
  6900. 5:36:51quantity even Target value next we're
  6901. 5:36:54going to add the uh class name which is
  6902. 5:36:56the da UI CSS classes and here we're
  6903. 5:37:00going to create like empty array with
  6904. 5:37:03the length of Maximum 10 so array from
  6905. 5:37:07accepts an object here and we provide
  6906. 5:37:10the length and the length will be
  6907. 5:37:12minimum of 10 and whatever is the
  6908. 5:37:14computed product quantity computed
  6909. 5:37:17product we know that is a
  6910. 5:37:19calculated uh object with a price and
  6911. 5:37:22quantity and it he's also considering
  6912. 5:37:25the currently selected variation types
  6913. 5:37:28so and we take the minimum 10 so we
  6914. 5:37:31don't want more than 10 so and we use
  6915. 5:37:34this to iterate over that and create op
  6916. 5:37:37options maximum 10 options so we have
  6917. 5:37:40value I +1 key I +1 and inside text
  6918. 5:37:44we're going to have also quantity I + 1
  6919. 5:37:48okay so we're going to have quantity 1
  6920. 5:37:49quantity 2 quantity 3 and so on maximum
  6921. 5:37:5210 even if the uh available quantity is
  6922. 5:37:57100 but if the available quantity is
  6923. 5:37:59five is going to pick up the minimum
  6924. 5:38:02which is going to be five and in this
  6925. 5:38:03case we're going to see only quantity
  6926. 5:38:05from 1 to five and find finally we're
  6927. 5:38:07going to put a button uh with ADD uh to
  6928. 5:38:11cart text and add to cart Handler as
  6929. 5:38:14well which is also implemented which
  6930. 5:38:15sends the request to the server with the
  6931. 5:38:17cart store so I think um I think we are
  6932. 5:38:23done here so we did the whole work um it
  6933. 5:38:27took a lot of time but I wanted to make
  6934. 5:38:29this very very clear so now we are about
  6935. 5:38:32to import some of the things so use form
  6936. 5:38:36use page page with alt and enter I'm
  6937. 5:38:39importing these things use State we need
  6938. 5:38:42use memo all these hooks variation type
  6939. 5:38:46option oops
  6940. 5:38:49variation type
  6941. 5:38:53option
  6942. 5:38:55H we have that defined
  6943. 5:39:02here variant type variant type option
  6944. 5:39:06okay variant
  6945. 5:39:10variant type
  6946. 5:39:12option okay let me call this variation
  6947. 5:39:15type
  6948. 5:39:17option okay cool uh that was imported I
  6949. 5:39:21guess so arrays are equal okay I'm going
  6950. 5:39:24to do this last thing because I'm going
  6951. 5:39:25to create new file for this I'm going to
  6952. 5:39:27import this use
  6953. 5:39:29effect uh variation type option I'm
  6954. 5:39:32going to use the same thing right here
  6955. 5:39:34let's import rotor from inertia Js SL
  6956. 5:39:38react that was
  6957. 5:39:41imported uh variation type option I'm
  6958. 5:39:43going to use that variation type option
  6959. 5:39:45here authenticated layout needs to be
  6960. 5:39:49imported uh head needs to be imported
  6961. 5:39:53from inertia JS react and I'm going to
  6962. 5:39:58change this into a product details
  6963. 5:40:02product details and we can even display
  6964. 5:40:06the specific specific um text for that
  6965. 5:40:09product like sorry I mixed that with
  6966. 5:40:12view syntax uh so here we can
  6967. 5:40:15have um product dot
  6968. 5:40:19title we can give it the title as well
  6969. 5:40:23um we're going to import the carousel
  6970. 5:40:26I'm going to import the currency
  6971. 5:40:28format and everything is imported
  6972. 5:40:32except that one method which is arrays
  6973. 5:40:37are
  6974. 5:40:40equal now inside JS folder I'm going to
  6975. 5:40:45create new file a new typescript file
  6976. 5:40:49and I'm going to call this
  6977. 5:40:51helpers and right here I'm going to
  6978. 5:40:54paste a function and I'm going to
  6979. 5:40:56explain that function okay so arrays are
  6980. 5:41:00equal export constant arrays are equal
  6981. 5:41:02we accept two arrays array one and array
  6982. 5:41:05two and these arrays can have have any
  6983. 5:41:07types so I'm providing any right here so
  6984. 5:41:12if the lengths are different it means
  6985. 5:41:14obviously that the arrays are not equal
  6986. 5:41:17they are not same so we immediately
  6987. 5:41:20return false okay however we iterate the
  6988. 5:41:24first array so in this case we iterate
  6989. 5:41:26the first array but you can iterate
  6990. 5:41:28actually the second array as well first
  6991. 5:41:30so we iterate the first array and we are
  6992. 5:41:34checking that on the same index in the
  6993. 5:41:37second array if the value is the same as
  6994. 5:41:42the value inside the first
  6995. 5:41:44array And if every value using this
  6996. 5:41:48every method if every value for every um
  6997. 5:41:52such element that condition is satisfied
  6998. 5:41:56then the arrays are equal okay now we
  6999. 5:42:00are going to import that arrays are
  7000. 5:42:02equal and there are no errors in this
  7001. 5:42:05file that's so awesome
  7002. 5:42:07uh there will be only one error through
  7003. 5:42:10this because of this cart store okay so
  7004. 5:42:14this is something we are going to
  7005. 5:42:16implement a little bit later but for
  7006. 5:42:21now for now let me just open web.php and
  7007. 5:42:25I'm going to
  7008. 5:42:27create um
  7009. 5:42:30rot
  7010. 5:42:32post
  7011. 5:42:34cart SL store for the
  7012. 5:42:40product we passed the product ID so we
  7013. 5:42:43can simply accept product it's going to
  7014. 5:42:45pick up the with the primary key and at
  7015. 5:42:48the moment um I just want to Define an
  7016. 5:42:52empty empty function I will change this
  7017. 5:42:55later into a controller okay for now I
  7018. 5:42:59just don't want the the error to be
  7019. 5:43:01displayed and let's give it also name
  7020. 5:43:04card store now we save it and we are
  7021. 5:43:08going to have a look in the product
  7022. 5:43:10Details page and refresh the page and
  7023. 5:43:13and and and this is one error
  7024. 5:43:21okay
  7025. 5:43:23okay let's have a look so we see image
  7026. 5:43:26we see thumbnail we see only one
  7027. 5:43:31thumbnail this is the title price color
  7028. 5:43:34and size okay we don't see options right
  7029. 5:43:37so options are not displayed right here
  7030. 5:43:40and we don't have also any error so let
  7031. 5:43:46me let me check so inside
  7032. 5:43:50show we iterate over the
  7033. 5:43:53options okay let's do like this I'm
  7034. 5:43:56going to print the variation
  7035. 5:44:00types right here in this main template
  7036. 5:44:03so let's use pre- Tag I'm going to use J
  7037. 5:44:07on. stringify variation types undefined
  7038. 5:44:12to cool look at this okay so we have
  7039. 5:44:15variation types options images are also
  7040. 5:44:18there okay now I have a question why it
  7041. 5:44:21doesn't work render product variation
  7042. 5:44:23types so we iterate over that if the
  7043. 5:44:26type equals
  7044. 5:44:29image uh okay let's return this
  7045. 5:44:34back okay this is it the type equals
  7046. 5:44:38uppercase i image so if we check
  7047. 5:44:42product um how did I call
  7048. 5:44:46this
  7049. 5:44:48variation type type
  7050. 5:44:51enam so we gave it uppercase s radio and
  7051. 5:44:56image okay this is it and that is the
  7052. 5:45:00issue right
  7053. 5:45:02here uh let me open index and we're
  7054. 5:45:06going to change this into s so
  7055. 5:45:08previously I had this um in uppercase s
  7056. 5:45:11r and I so that's the thing so R and
  7057. 5:45:17I and here as well when we do this
  7058. 5:45:23comparison so uppercase R uppercase
  7059. 5:45:29i
  7060. 5:45:32now okay now we see that and let's
  7061. 5:45:36remove the
  7062. 5:45:40print or maybe I can comment out this
  7063. 5:45:44part now we see the different variations
  7064. 5:45:48and this is the coolest part this is
  7065. 5:45:50what I wanted to show to you and so when
  7066. 5:45:53we click on these options it actually
  7067. 5:45:56updates the URL if you pay attention
  7068. 5:45:58right here it updates the
  7069. 5:46:02URL and it also changes the calculated
  7070. 5:46:06images the computed
  7071. 5:46:10images clicking on this also updates the
  7072. 5:46:13URL right here and if I refresh the page
  7073. 5:46:16right
  7074. 5:46:17now we are going to still see black and
  7075. 5:46:20medium if I click on this and refresh
  7076. 5:46:22the page now we are going to still see
  7077. 5:46:26purple and medium and this is the
  7078. 5:46:29coolest part okay so this is how we are
  7079. 5:46:32preserving
  7080. 5:46:34those um and that's just
  7081. 5:46:40awesome okay now I want to upload
  7082. 5:46:43multiple images so let's go
  7083. 5:46:46into let's remove
  7084. 5:46:49this this is black so let me
  7085. 5:46:52upload
  7086. 5:46:57headset black headset
  7087. 5:47:01okay this is black one this is blue okay
  7088. 5:47:06I'm going to change this and call
  7089. 5:47:08these uh what other colors do I
  7090. 5:47:12have
  7091. 5:47:17green
  7092. 5:47:20green and this is
  7093. 5:47:23pink let's delete this one click on
  7094. 5:47:28that and I'm going to choose
  7095. 5:47:31pink okay let's see this wasn't uploaded
  7096. 5:47:36let's retry
  7097. 5:47:38now it got uploaded all of them were
  7098. 5:47:41uploaded here and here and click
  7099. 5:47:44on Save
  7100. 5:47:48changes and we're going to click
  7101. 5:47:52on
  7102. 5:47:54variations we see black small green
  7103. 5:47:56small pink small black medium green
  7104. 5:48:00medium pink medium okay the values we
  7105. 5:48:04updated here as
  7106. 5:48:05well and and if I refresh this page
  7107. 5:48:08right
  7108. 5:48:10now now we probably some of the options
  7109. 5:48:14probably were broken so we have to open
  7110. 5:48:18the root domain and this is how it looks
  7111. 5:48:20like
  7112. 5:48:23so where's the pink thumbnail by the
  7113. 5:48:27way uh I'm not sure maybe it is still
  7114. 5:48:31processing so yeah the queue is actually
  7115. 5:48:35processing and generating very
  7116. 5:48:39Creations yep here we see it cut
  7117. 5:48:42processed uh this is not this is not the
  7118. 5:48:46default image I want so we can adjust
  7119. 5:48:48the default image as
  7120. 5:48:50well so this is the first one that's
  7121. 5:48:53cool I want this to be the first
  7122. 5:48:56one and I want this to be the first
  7123. 5:48:59one click on Save
  7124. 5:49:02changes now refresh it
  7125. 5:49:07okay
  7126. 5:49:16awesome yeah clicking on this right here
  7127. 5:49:20actually
  7128. 5:49:22triggers jumping at the
  7129. 5:49:26Top If we check this
  7130. 5:49:31Carousel so we have this clicking on
  7131. 5:49:34this yeah it also triggers that jumping
  7132. 5:49:38at the
  7133. 5:49:39top which is pretty weird obviously this
  7134. 5:49:42is not something what we
  7135. 5:49:48want we don't want it to jump at the top
  7136. 5:49:52right so I think we can easily take care
  7137. 5:49:55of this if we go into
  7138. 5:49:58Carousel and this is hre so we need on
  7139. 5:50:02click here we're going to accept event
  7140. 5:50:06and we're going to call
  7141. 5:50:08event. prevent
  7142. 5:50:11default let's move this hft
  7143. 5:50:18down have a
  7144. 5:50:21look now prevent
  7145. 5:50:24default doesn't do
  7146. 5:50:26anything at all stop
  7147. 5:50:32propagation now it
  7148. 5:50:34jumps but doesn't do anything
  7149. 5:50:39no it jumps and changes okay and that's
  7150. 5:50:42pretty strange um I will find this out
  7151. 5:50:46outside of the video and tell you how to
  7152. 5:50:49deal with
  7153. 5:50:51that but that is um that variations I
  7154. 5:50:56think is
  7155. 5:50:57the most important
  7156. 5:51:01part yeah one additional thing is
  7157. 5:51:04related into description let me copy
  7158. 5:51:07this list right now this is actually a
  7159. 5:51:11list let's go
  7160. 5:51:13into edit product and put this in the
  7161. 5:51:16description so we have this list right
  7162. 5:51:19and we can make certain things bold as
  7163. 5:51:22well now if we save that and if we have
  7164. 5:51:26a look
  7165. 5:51:27that I think Styles uh are actually lost
  7166. 5:51:32bold is there but least is not
  7167. 5:51:37there and that's because talin CSS
  7168. 5:51:39resets all these Styles and generally I
  7169. 5:51:43recover this in the following way so I
  7170. 5:51:45found find this somewhere um in uh in
  7171. 5:51:51Forum I don't remember exactly where I
  7172. 5:51:52find this but from now on I use this
  7173. 5:51:56from my GitHub existing GitHub
  7174. 5:51:58repository so if I go in my repository
  7175. 5:52:01and that repository is actually open
  7176. 5:52:02source so in this social media website
  7177. 5:52:06as an example example we go under
  7178. 5:52:09resources
  7179. 5:52:11CSS app CSS in here we have those I did
  7180. 5:52:16this with the CK editor so we have those
  7181. 5:52:19classes which simply
  7182. 5:52:21reverts uh some of the content for CK
  7183. 5:52:25editor for the content which is coming
  7184. 5:52:26from wiwi editor so we have these um
  7185. 5:52:30duplicated one for CK content and second
  7186. 5:52:34for CK content output
  7187. 5:52:37so we're going to take the CK content
  7188. 5:52:42output and let's open app. CSS from
  7189. 5:52:47resources CSS and I'm going to put this
  7190. 5:52:50right here
  7191. 5:52:52however download full line code
  7192. 5:52:55completion let's download this for CSS
  7193. 5:52:58and I'm going to replace this CK content
  7194. 5:53:02output uh with
  7195. 5:53:06we
  7196. 5:53:09output okay so let's do this replace now
  7197. 5:53:13for the following elements inside wi
  7198. 5:53:16output it is going to revert those
  7199. 5:53:20changes and we're going to see now the
  7200. 5:53:23styles are actually the least elements
  7201. 5:53:26are actually displayed correctly so uh
  7202. 5:53:28you can have here um additional things
  7203. 5:53:31you can activate tables if you want to
  7204. 5:53:33put tables right there but um
  7205. 5:53:37yeah this
  7206. 5:53:38is this is cool let's refresh the
  7207. 5:53:50page when we click on this thumbnails uh
  7208. 5:53:54besides the fact that it jumps at the
  7209. 5:53:57top uh also the thumbnail is not
  7210. 5:53:59selected so I'm going to take this quick
  7211. 5:54:02challenge for which I'm not actually
  7212. 5:54:03prepared but I'm going to do this um my
  7213. 5:54:06own way so uh selected image set
  7214. 5:54:11selected image this is going to be one
  7215. 5:54:14of the images and by default we are
  7216. 5:54:16picking the first one
  7217. 5:54:20so we have also image ID right yes so we
  7218. 5:54:25have image ID as well so let me remove
  7219. 5:54:27this
  7220. 5:54:31hre or we can
  7221. 5:54:33simply I think we can remove this h we
  7222. 5:54:36can even put their button I
  7223. 5:54:41guess and we can remove the ID
  7224. 5:54:47here now this will probably
  7225. 5:54:53display yeah this is not going to work
  7226. 5:54:55and it's going to display only one item
  7227. 5:54:57if we inspect this we're going to see
  7228. 5:54:58that we have multiple items but the
  7229. 5:55:02others are on the other side
  7230. 5:55:07of it h i want to check one thing so if
  7231. 5:55:11we if we right now click on the second
  7232. 5:55:21one so it does display it based on the
  7233. 5:55:27ID okay anyway so this is as I mentioned
  7234. 5:55:29I'm going to do this in my own way so
  7235. 5:55:33right here instead of displaying all the
  7236. 5:55:34images I'm going to display only current
  7237. 5:55:37image so maybe I can do the following
  7238. 5:55:41just display
  7239. 5:55:43one image which is going to be selected
  7240. 5:55:47image large and the key actually
  7241. 5:55:50something we don't need okay and
  7242. 5:55:53whenever I click on this button on click
  7243. 5:55:57we get the event and we're going to call
  7244. 5:55:59set selected
  7245. 5:56:02image and we're going to provide the
  7246. 5:56:04image to be selected
  7247. 5:56:10now let's have a
  7248. 5:56:14look where is this image coming
  7249. 5:56:21from okay
  7250. 5:56:37so we're going to see what is this
  7251. 5:56:39selected
  7252. 5:56:46image that selected image I guess is
  7253. 5:56:49coming from the product right so if we
  7254. 5:56:52go into products not products but media
  7255. 5:56:55find the one which has ID
  7256. 5:56:5812 this is
  7257. 5:57:02it
  7258. 5:57:04but how do we see that selected
  7259. 5:57:10image from here the images do not
  7260. 5:57:14contain that specific image right so if
  7261. 5:57:17we just
  7262. 5:57:20print let's actually do
  7263. 5:57:23this right here images so I'm printing
  7264. 5:57:26the entire list of images 1 two 3 4 five
  7265. 5:57:30and six so we have
  7266. 5:57:33totally six images
  7267. 5:57:36and selected image is
  7268. 5:57:42actually the first one from
  7269. 5:57:52images okay let me use
  7270. 5:57:55effect I think I know the reason so
  7271. 5:57:57whenever yeah I know the reason so
  7272. 5:58:00whenever this component is actually
  7273. 5:58:03mounted react takes this first one one
  7274. 5:58:06and puts this inside the state and next
  7275. 5:58:09time when the images got updated this
  7276. 5:58:11doesn't happen anymore so we are going
  7277. 5:58:13to actually
  7278. 5:58:15listen to
  7279. 5:58:18images and whenever images are
  7280. 5:58:22changed whenever images are changed I'm
  7281. 5:58:25going to call set selected image the
  7282. 5:58:28first one and by default we can provide
  7283. 5:58:30this to be null or we can even leave
  7284. 5:58:32this image zero but the main thing is
  7285. 5:58:34that whenever images are changed we're
  7286. 5:58:36going to update this select set selected
  7287. 5:58:39image into the first
  7288. 5:58:42one now let's delete this one comment
  7289. 5:58:46out this one and have a
  7290. 5:58:48look uh cool cool cool okay so click on
  7291. 5:58:52this click on this
  7292. 5:59:00okay so yeah clicking on this also
  7293. 5:59:03updates the selected image
  7294. 5:59:08and we can I think add the um on Mouse
  7295. 5:59:12over whatever it
  7296. 5:59:18does this one hover
  7297. 5:59:22border
  7298. 5:59:28low so I'm going to take this part out
  7299. 5:59:32and we're going to add border two
  7300. 5:59:38and then if selected image ID
  7301. 5:59:43equals image
  7302. 5:59:46ID let's put this in
  7303. 5:59:49parenthesis then we are going to add um
  7304. 5:59:53border blue
  7305. 5:59:56500 otherwise we're going to add that on
  7306. 6:00:02Hover let me move this I'm going to uh
  7307. 6:00:07close the parenthesis
  7308. 6:00:08here and let's move this
  7309. 6:00:12down if
  7310. 6:00:15statement okay I think that is
  7311. 6:00:22correct now we see that whichever is
  7312. 6:00:25selected it stays this border we don't
  7313. 6:00:28have this
  7314. 6:00:29jumping uh on
  7315. 6:00:33click and we have
  7316. 6:00:36we have it done
  7317. 6:00:38properly that's great and in the drop
  7318. 6:00:42down whenever we have only three items
  7319. 6:00:43left we see only uh three whenever we
  7320. 6:00:46choose something else we see now 10
  7321. 6:00:48inside the drop down okay I committed
  7322. 6:00:51all the changes so far and I'm going to
  7323. 6:00:53move forward and start working on
  7324. 6:00:56implementing add to card functionality
  7325. 6:00:59in our project okay for this we have to
  7326. 6:01:02create couple of new files and update
  7327. 6:01:04existing ones where we're going to
  7328. 6:01:06listen to the button click right here to
  7329. 6:01:09add the product with different
  7330. 6:01:11variations into the cart but I'm going
  7331. 6:01:14to start with the migration first and
  7332. 6:01:17the model because we're going to create
  7333. 6:01:18cart items table in the
  7334. 6:01:21database let me execute PHP artisan
  7335. 6:01:26make model this is going to be cart item
  7336. 6:01:31model and I'm going to generate
  7337. 6:01:32migration file as well now my
  7338. 6:01:35integration and model was generated I'm
  7339. 6:01:38going to also generate the controller so
  7340. 6:01:41this is going to be card controller PHP
  7341. 6:01:44artisan
  7342. 6:01:46make controller cart controller okay so
  7343. 6:01:51let me generate actually a resource
  7344. 6:01:54controller and I'm going to provide Das
  7345. 6:01:56Dash model or I'm going to skip the
  7346. 6:01:58model let me just generate card
  7347. 6:02:01controller this is going to be resource
  7348. 6:02:03controller and we can open this card
  7349. 6:02:06controller right now and see those
  7350. 6:02:09methods right here we're going to adjust
  7351. 6:02:12these methods but I'm going to also
  7352. 6:02:15generate a service and this is going to
  7353. 6:02:18be service class for cart and the all
  7354. 6:02:22logic adding into the card removing into
  7355. 6:02:25the card will go inside that service
  7356. 6:02:28class and the service class will also
  7357. 6:02:30take care whether the user is
  7358. 6:02:32authenticated or not because I want to
  7359. 6:02:35allow ability to add the products into
  7360. 6:02:38the card even user if even when the user
  7361. 6:02:41is not
  7362. 6:02:41authenticated and whenever user will
  7363. 6:02:45authenticate on the website the items
  7364. 6:02:48which are in the cart inside um cookies
  7365. 6:02:52we're going to save them inside the
  7366. 6:02:54cookies for non-authenticated users they
  7367. 6:02:56will move into the database for
  7368. 6:02:59authenticated users okay so if the user
  7369. 6:03:02is guessed we're going to save the data
  7370. 6:03:04inside cookies
  7371. 6:03:06as soon as they log in we're going to
  7372. 6:03:08move the data into the database okay
  7373. 6:03:11awesome so we have the card controller
  7374. 6:03:13and let me create this new service class
  7375. 6:03:16so inside up services we have this
  7376. 6:03:18custom path generator so let's actually
  7377. 6:03:22execute PHP artisan make service and
  7378. 6:03:28let's call this cart
  7379. 6:03:30service we hit the
  7380. 6:03:33enter okay so I guess there is no make
  7381. 6:03:36service I just didn't remember this so
  7382. 6:03:39simply we can execute make class inside
  7383. 6:03:43Services back slash card service we hit
  7384. 6:03:46the enter the class was generated here
  7385. 6:03:49we see this card service and the idea of
  7386. 6:03:53these cart Services I mentioned is going
  7387. 6:03:54to be to manage the add to cart remove
  7388. 6:03:57from cart uh update the quantity of the
  7389. 6:03:59card and so on so I want to create singl
  7390. 6:04:02ton out of this card service so for this
  7391. 6:04:05I'm going to open up service provider
  7392. 6:04:09and inside this register method I want
  7393. 6:04:13to use this
  7394. 6:04:16app singl ton and we're going to provide
  7395. 6:04:20right here the class name which is going
  7396. 6:04:21to be our cart service class and right
  7397. 6:04:26here from this function we are going to
  7398. 6:04:28return new card service we don't want up
  7399. 6:04:32right here we don't use this and just
  7400. 6:04:34like this we registered that c card
  7401. 6:04:35service and we will be able to use that
  7402. 6:04:39card service with through dependency
  7403. 6:04:43injection in our controller or in any
  7404. 6:04:46other places so if we open this card
  7405. 6:04:48controller right
  7406. 6:04:49now inside index as an example we can
  7407. 6:04:53accept requests if we need but I think
  7408. 6:04:55we don't need request uh at least for
  7409. 6:04:57now but we can access this card service
  7410. 6:05:00in the following way okay and we can
  7411. 6:05:03dump the entire cart service object
  7412. 6:05:06right now and later when we implement
  7413. 6:05:09this we're going to get the items from
  7414. 6:05:10the card service and we're going to
  7415. 6:05:12render them nicely on the page so create
  7416. 6:05:16is something we don't need I'm going to
  7417. 6:05:18remove this we need we will need store
  7418. 6:05:21and I'm going to accept right here
  7419. 6:05:24product which needs to be added into the
  7420. 6:05:26cart and I'm going to accept also card
  7421. 6:05:28service so we have three variables let's
  7422. 6:05:32import this product next I'm going
  7423. 6:05:36to uh remove the show we don't need show
  7424. 6:05:39which is for only one item instead of
  7425. 6:05:43edit yeah I'm going to remove edit as
  7426. 6:05:45well and I'm going to take care of this
  7427. 6:05:48update so in the update we're going to
  7428. 6:05:49accept request we are going to accept
  7429. 6:05:53product for which we are doing the
  7430. 6:05:56update of the quantity and we're going
  7431. 6:05:59to accept also card service as an
  7432. 6:06:01argument scroll down below in the
  7433. 6:06:03destroy we're going to also accept
  7434. 6:06:06request we're going to accept the
  7435. 6:06:09product we want to destroy from the cart
  7436. 6:06:13we are not destroying the product we are
  7437. 6:06:15destroying that specific product from
  7438. 6:06:18the cart for the authenticated user we
  7439. 6:06:20are removing this and we need cart
  7440. 6:06:23service as well okay so this is what we
  7441. 6:06:26need so far maybe we can add more
  7442. 6:06:28methods in the future but we're going to
  7443. 6:06:30stick with these Methods at the moment
  7444. 6:06:33and I think what we're going to focus is
  7445. 6:06:35the store
  7446. 6:06:36method first let's open web.php and
  7447. 6:06:41we're going to Define cart related
  7448. 6:06:43couple of
  7449. 6:06:45methods okay so we have cart store and
  7450. 6:06:49here I'm going to use cart
  7451. 6:06:52controller class and we're going to use
  7452. 6:06:54method called store we can I'm going to
  7453. 6:06:57change this into cart Aid and you know
  7454. 6:06:59what I'm going to actually optimize this
  7455. 6:07:01in the following way so I'm going to use
  7456. 6:07:03root control
  7457. 6:07:06and I'm going to use cart controller
  7458. 6:07:10here and I'm going to group Roots by
  7459. 6:07:13card controller so
  7460. 6:07:16then let me copy and paste this right
  7461. 6:07:18here so then I'm listening to
  7462. 6:07:21post um cart a in here instead of the
  7463. 6:07:26class and then the method we're going to
  7464. 6:07:28just provide the action okay and we give
  7465. 6:07:32it a name card store I think we need uh
  7466. 6:07:36rendering of the cart as well so Road
  7467. 6:07:38get cart index and this is going to have
  7468. 6:07:42a name cart index we will need cart
  7469. 6:07:46update as well we're going to use put or
  7470. 6:07:49patch for this uh and let's actually
  7471. 6:07:52change this into put we are
  7472. 6:07:55updating uh that specific product from
  7473. 6:07:58the
  7474. 6:08:00cart that's cool and let's give it name
  7475. 6:08:03cart update and finally we are going to
  7476. 6:08:07allow removing that specific product
  7477. 6:08:09from the cart so we're going to use this
  7478. 6:08:11destroy method okay and all of them
  7479. 6:08:14actually is allowed for guest users so
  7480. 6:08:17we don't add out middle wear anywhere
  7481. 6:08:19guest users will be able to have a look
  7482. 6:08:21in the inside the cart add items into
  7483. 6:08:24the cart U update them from the cart or
  7484. 6:08:28destroy them um from the cart I'm
  7485. 6:08:32thinking if I missed anything but I
  7486. 6:08:33think I haven't missed anything anything
  7487. 6:08:36so now let's go into card controller and
  7488. 6:08:39I'm going to work on the store method so
  7489. 6:08:42inside the
  7490. 6:08:43store I'm going to accept um so I'm
  7491. 6:08:47going to call request first and I'm
  7492. 6:08:50going to take quantity but if the
  7493. 6:08:53quantity is not provided I'm going to
  7494. 6:08:55assume that the quantity is one so I'm
  7495. 6:08:57going to use method called merge if
  7496. 6:09:00missing and right here we provide uh
  7497. 6:09:03quantity
  7498. 6:09:05and if it is missing we're going to
  7499. 6:09:07assign quantity one okay after this we
  7500. 6:09:10take the data from
  7501. 6:09:13request we're going to call validate and
  7502. 6:09:16we're going to validate basically two uh
  7503. 6:09:19two columns uh one is going to be option
  7504. 6:09:24IDs which um might be actually null so
  7505. 6:09:28if we don't provide any option idas it
  7506. 6:09:30means that uh either the product doesn't
  7507. 6:09:33have any variation options defined
  7508. 6:09:35tall uh or or we might pick up the uh
  7509. 6:09:40first options or in this case let's
  7510. 6:09:42assume that if we don't provide these uh
  7511. 6:09:45option IDs if it's null then the product
  7512. 6:09:48doesn't have any variation IDs and we
  7513. 6:09:51don't want to use them basically in the
  7514. 6:09:54cart item as well okay now let's define
  7515. 6:09:58second field which is going to be
  7516. 6:10:00quantity and let's autocomplete this and
  7517. 6:10:03instead of required I'm going to make
  7518. 6:10:05this
  7519. 6:10:06nullable okay so the quantity is
  7520. 6:10:10nullable
  7521. 6:10:13um because we defined we merge this into
  7522. 6:10:16existing maybe we can make this required
  7523. 6:10:18as well now we know that the quantity
  7524. 6:10:20will be there always okay anyway now on
  7525. 6:10:23this cart service I'm going to Define
  7526. 6:10:25couple of methods and one of them is
  7527. 6:10:27going to be add item to cart so let's
  7528. 6:10:30actually open this cart service and
  7529. 6:10:33Define couple of methods I think we can
  7530. 6:10:35remove this public function add item to
  7531. 6:10:41cart and we are going to accept couple
  7532. 6:10:44of arguments first the product we are
  7533. 6:10:46trying to add into the cart second is
  7534. 6:10:48going to be the quantity for that
  7535. 6:10:50product and third is going to be array
  7536. 6:10:53of option IDs by default an empty
  7537. 6:10:58array so this is one of the method and
  7538. 6:11:01whenever the item is added into the cart
  7539. 6:11:04I think we don't need to return actually
  7540. 6:11:08anything uh let me actually make this
  7541. 6:11:10null so if we it's going to be null if
  7542. 6:11:13we don't provide anything the default
  7543. 6:11:15value okay now in the cart controller we
  7544. 6:11:19are going to call add item to cart we're
  7545. 6:11:21going to provide product we're going to
  7546. 6:11:23provide uh data quantity and we are
  7547. 6:11:26going to provide data option IDs as well
  7548. 6:11:29so assuming that this does its work and
  7549. 6:11:32it's going to add those I this item this
  7550. 6:11:35specific specific product with this
  7551. 6:11:36quantity and with this variation option
  7552. 6:11:39IDs into the cart okay then we are going
  7553. 6:11:43to return uh we're going to go back and
  7554. 6:11:47we're going to go back with some success
  7555. 6:11:49message product add2 card
  7556. 6:11:53successfully okay so this ed2 cart is
  7557. 6:11:56going to work on both cases whether the
  7558. 6:11:58user is guessed or user is authenticated
  7559. 6:12:01and depending on the user State it's
  7560. 6:12:04going to add the
  7561. 6:12:05um product into the card inside cookies
  7562. 6:12:08or inside the
  7563. 6:12:10database now let's focus on the update
  7564. 6:12:13and we're going to validate the quantity
  7565. 6:12:15and we're going to take integer and the
  7566. 6:12:17minimum value should be at least one and
  7567. 6:12:20the update generally will be called
  7568. 6:12:22whenever the product is already added
  7569. 6:12:24into the card and we want to update its
  7570. 6:12:27quantity so then we're going to take the
  7571. 6:12:29option IDs from this request input if we
  7572. 6:12:32are trying to update it okay for which
  7573. 6:12:37variation options we are going to we are
  7574. 6:12:40trying to update that product so we know
  7575. 6:12:44that what's the product but we don't
  7576. 6:12:46know what option IDs we want to update
  7577. 6:12:50without this data okay so we need these
  7578. 6:12:53option ities as well then we're going to
  7579. 6:12:55get um the quantity from this request
  7580. 6:12:57after we perform the validate and then
  7581. 6:13:01I'm going to call on card service update
  7582. 6:13:04item quantity
  7583. 6:13:05we are going to create that method in a
  7584. 6:13:08moment but we're going to provide
  7585. 6:13:10product ID here we're going to provide
  7586. 6:13:12quantity and option IDs so on this
  7587. 6:13:15product we're going to set the following
  7588. 6:13:17quantity and with the following option
  7589. 6:13:21IDs okay next we're going to go back
  7590. 6:13:25with success message quantity was
  7591. 6:13:27updated now let's open card service and
  7592. 6:13:30right here let's add the method public
  7593. 6:13:33function
  7594. 6:13:36what's that public function update we
  7595. 6:13:40call this update item quantity so we're
  7596. 6:13:43going to accept
  7597. 6:13:45integer product ID quantity and option
  7598. 6:13:52IDs okay so we're going to come back to
  7599. 6:13:54this service in a moment and Implement
  7600. 6:13:56all the necessary methods next I'm going
  7601. 6:13:59to scroll down below and implement the
  7602. 6:14:01destroy method so I'm going to accept
  7603. 6:14:03option IDs right right here from request
  7604. 6:14:07so we need we always need option IDs to
  7605. 6:14:10identify which item from the cart needs
  7606. 6:14:14to be removed because the same
  7607. 6:14:17product might be added into the cart
  7608. 6:14:20with different variation option IDs okay
  7609. 6:14:24so here we have the same product and if
  7610. 6:14:27I add black into the card then add green
  7611. 6:14:30into the cart I should see two records
  7612. 6:14:33inside the cart they are actually the
  7613. 6:14:35same product but two different
  7614. 6:14:37variations and I should be a able to
  7615. 6:14:39view them separately inside the card and
  7616. 6:14:42to increase quantity for each of them
  7617. 6:14:44inside the card and remove black one or
  7618. 6:14:47green one but the but to leave the other
  7619. 6:14:50one inside the card so this is how I
  7620. 6:14:53want to make it so then on the card
  7621. 6:14:56service I'm going to call remove item uh
  7622. 6:15:00from cart we're going to provide product
  7623. 6:15:03ID and the option IDs okay and we're
  7624. 6:15:07going to create that method and then I'm
  7625. 6:15:09going to go back with success message
  7626. 6:15:11product was removed from
  7627. 6:15:16cart cool now let's go into cart service
  7628. 6:15:21and we're going to Define this function
  7629. 6:15:22as well remove item from cart we're
  7630. 6:15:25going to accept uh product ID
  7631. 6:15:29and option IDs which is going to be null
  7632. 6:15:33I'm going to start implementing couple
  7633. 6:15:35of helper methods inside this card
  7634. 6:15:38service which will be used in several
  7635. 6:15:41places okay so let's define first I'm
  7636. 6:15:43going to Define get cart items which is
  7637. 6:15:46going to return array depending on
  7638. 6:15:49whether the user is authenticated or not
  7639. 6:15:51this is going to read the information
  7640. 6:15:53from car from cookies or from the
  7641. 6:15:55database I'm going to also Define get
  7642. 6:15:58total quantity and get total price these
  7643. 6:16:02is going to be public methods
  7644. 6:16:04additionally I'm going to Define
  7645. 6:16:05protected methods which will be used
  7646. 6:16:07only internally like update item
  7647. 6:16:10quantity in database we accept product
  7648. 6:16:13ID we accept the new quantity and the
  7649. 6:16:16option ID is to update that record in
  7650. 6:16:18the cart so additionally I'm going to
  7651. 6:16:21also Define update item quantity in
  7652. 6:16:23cookies which has the same signature
  7653. 6:16:26we're going to Define update uh sorry
  7654. 6:16:29save item to database this is going to
  7655. 6:16:32be when we add a new item into to the
  7656. 6:16:35cart okay so for database for cookies
  7657. 6:16:39we're going to also have remove item
  7658. 6:16:41from database and remove item from
  7659. 6:16:44cookies okay and we're going to also
  7660. 6:16:47Define get card items from database and
  7661. 6:16:51get card items from cookies now let's go
  7662. 6:16:56to the top of the class and we are going
  7663. 6:16:58to define a couple of constants and the
  7664. 6:17:03protected meth um property
  7665. 6:17:05like or private properties so first I'm
  7666. 6:17:08going to Define this cached cart items
  7667. 6:17:10which is going to be a cached version of
  7668. 6:17:13the cart items and we're going to use
  7669. 6:17:15this in uh the method get cart items and
  7670. 6:17:19this is going to be important because we
  7671. 6:17:22are going to use this gate cart items
  7672. 6:17:25method couple of
  7673. 6:17:27times this method will be used couple of
  7674. 6:17:29times during a single request and when
  7675. 6:17:32the user is authenticated every time it
  7676. 6:17:35is going to make the database select to
  7677. 6:17:37select the card items but I'm going to
  7678. 6:17:39actually uh cach that save that inside
  7679. 6:17:43these cach card items we're going to see
  7680. 6:17:45this in action so we're going to also
  7681. 6:17:48add one uh static um constant not the
  7682. 6:17:53static but one um protected constant
  7683. 6:17:56cookie name inside which we are going to
  7684. 6:17:58save the cart items and also another
  7685. 6:18:01protected constant cookie lifetime which
  7686. 6:18:03we're going to set in to one yard
  7687. 6:18:05whenever we add something into the cart
  7688. 6:18:07it's going to stays um stay in in the
  7689. 6:18:10cart for one yard you can obviously
  7690. 6:18:12reduce this if you want now I'm going to
  7691. 6:18:16start implementing uh these methods like
  7692. 6:18:19G cart items get total quantity and so
  7693. 6:18:23on so let's start with this G cart items
  7694. 6:18:26so I'm going to use first try catch and
  7695. 6:18:29we need this TR catch uh because if
  7696. 6:18:31something goes wrong uh simply it's
  7697. 6:18:34going to an exception and nothing will
  7698. 6:18:36happen so when if we are not able to
  7699. 6:18:39read the data from cart items we don't
  7700. 6:18:41want the website to be crashed right so
  7701. 6:18:44uh and in this case like reading uh and
  7702. 6:18:47we're going to also use the Json decode
  7703. 6:18:49to decode the data from uh cookies so we
  7704. 6:18:54something might simply go wrong okay so
  7705. 6:18:58now this is the place where we use these
  7706. 6:19:00Cas get um sorry cached cart items so if
  7707. 6:19:05cached card cart items equals null it
  7708. 6:19:09means that we are calling this method
  7709. 6:19:11get cart items the first time in this
  7710. 6:19:13request so we're going to do something
  7711. 6:19:15in this if statement and assign the data
  7712. 6:19:19into this cached cart items okay so
  7713. 6:19:23we're going to do that inside if
  7714. 6:19:25whenever if finishes we are going to
  7715. 6:19:27return this uh cached cart items and now
  7716. 6:19:32we are going to focus on that if
  7717. 6:19:35uh the content of this if so we are
  7718. 6:19:38going to do the following check if the
  7719. 6:19:39user is authenticated we're going to do
  7720. 6:19:42something else retrieve the data from
  7721. 6:19:44the database otherwise we're going to
  7722. 6:19:46retrieve the data from cookies okay so
  7723. 6:19:49cart items equals these get cart items
  7724. 6:19:52from database and here cart items equals
  7725. 6:19:56these G cart items from cookies so we
  7726. 6:19:59are gonna just make sure that cart items
  7727. 6:20:02whether it is selected from the database
  7728. 6:20:05or it is selected from cookies they have
  7729. 6:20:09the same format okay and that format is
  7730. 6:20:13going to be how we're going to save them
  7731. 6:20:15into the database so before I continue
  7732. 6:20:17right here I think we haven't created
  7733. 6:20:20the migration we created the migration
  7734. 6:20:22but we haven't actually written anything
  7735. 6:20:24there so create card items let's open
  7736. 6:20:28this and we're going to add couple of
  7737. 6:20:30columns like
  7738. 6:20:33table let's add foring ID on product ID
  7739. 6:20:38it's going to be constrained into
  7740. 6:20:40products uh let's also add index and I'm
  7741. 6:20:44going to also add uh we have the
  7742. 6:20:47constraint and I'm going to also add
  7743. 6:20:49right here uh Cascade on delete whenever
  7744. 6:20:52product is deleted we want the cart
  7745. 6:20:54items to be deleted as well next I'm
  7746. 6:20:57going to Define this foring ID by user
  7747. 6:21:01ID uh let's give it index as well and
  7748. 6:21:04constraint on
  7749. 6:21:05users uh let's define also quantity and
  7750. 6:21:10price let's Define decimal price give it
  7751. 6:21:1520 on four and table integer not index
  7752. 6:21:21but integer
  7753. 6:21:24quantity so we have product ID we have
  7754. 6:21:27user ID we have quantity we have price
  7755. 6:21:32uh we need variation type option IDs so
  7756. 6:21:36this is going to be Json
  7757. 6:21:38variation type option
  7758. 6:21:42IDs uh and that actually should be
  7759. 6:21:46nullable and finally I'm going to Define
  7760. 6:21:49one additional column which we I hope
  7761. 6:21:53that we have time to implement this uh
  7762. 6:21:55and this is going to be saved for later
  7763. 6:21:59whether that specific product is going
  7764. 6:22:02to be uh saved for later and will not
  7765. 6:22:05participate during checkout I really
  7766. 6:22:08like this feature I use this on Amazon
  7767. 6:22:11um yeah this is um how I want to do it
  7768. 6:22:16and now if we're go in the card service
  7769. 6:22:18I want to return the data in a similar
  7770. 6:22:21format from these gate cart items from
  7771. 6:22:23database and these gate cart items from
  7772. 6:22:26cookie now let's continue right here so
  7773. 6:22:28let's say that we got those cart items
  7774. 6:22:31now we're going to create these cart
  7775. 6:22:33items will be plane array okay so we're
  7776. 6:22:36going to uh create a collection out of
  7777. 6:22:39it then we're are going to map each item
  7778. 6:22:42from this cart item into the product ID
  7779. 6:22:46so finally right here we are going to
  7780. 6:22:48have product
  7781. 6:22:50IDs then I'm going to select products by
  7782. 6:22:53IDs the following IDs and I'm going to
  7783. 6:22:57also select that with
  7784. 6:23:00user and
  7785. 6:23:02vendor Okay so do we have vendor
  7786. 6:23:06information in the database so we don't
  7787. 6:23:09have that and this is something what I
  7788. 6:23:11am going to do so right now I'm just
  7789. 6:23:13going to create a table for vendor but
  7790. 6:23:17later we're going to implement um
  7791. 6:23:19certain things there as
  7792. 6:23:22well now let me execute PHP artisan make
  7793. 6:23:29uh make
  7794. 6:23:30model vendor and we're going to generate
  7795. 6:23:33migration as well well okay now let's
  7796. 6:23:36open
  7797. 6:23:38create vendors
  7798. 6:23:40table and let's do the following
  7799. 6:23:44so uh instead of ID right here I am
  7800. 6:23:47going to change this into big
  7801. 6:23:51integer big integer this is going to be
  7802. 6:23:54user ID I'm changing the name of the
  7803. 6:23:58primary key let's give it unsigned in
  7804. 6:24:01primary because vendor will have
  7805. 6:24:04onetoone connection to user okay a user
  7806. 6:24:09will have its Associated data inside
  7807. 6:24:12vendors table where we're going to save
  7808. 6:24:15couple of
  7809. 6:24:20information okay I'm going to also
  7810. 6:24:22Define forign key from user ID into
  7811. 6:24:25vendor like on table I'm going to use
  7812. 6:24:28foring on user ID which references on ID
  7813. 6:24:33references by ID on users table and we
  7814. 6:24:37are going to give it
  7815. 6:24:41also Cascade on
  7816. 6:24:44delete whenever user is deleted for some
  7817. 6:24:47reason we want the vendor to be deleted
  7818. 6:24:50as well now we're going to also Define
  7819. 6:24:54status of the vendor whether the vendor
  7820. 6:24:56is approved or it's status is actually
  7821. 6:24:59pending and not approved vendor in which
  7822. 6:25:01case admin users need to approve approve
  7823. 6:25:04the vendor okay so we are going to
  7824. 6:25:07Define store name we are going to Define
  7825. 6:25:12store
  7826. 6:25:14address which actually can be null we
  7827. 6:25:19are going to Define
  7828. 6:25:20Also let's define cover cover image of
  7829. 6:25:25the vendor which can be also null and I
  7830. 6:25:29guess that is all so I'm going to leave
  7831. 6:25:31this now so we have the Vendor model we
  7832. 6:25:34have the vendors uh table now let's open
  7833. 6:25:37product and on the product we have I
  7834. 6:25:41think user relation and on that user we
  7835. 6:25:44are going to add has one relation to
  7836. 6:25:47vendor has
  7837. 6:25:51one
  7838. 6:25:52vendor then right here we need vendor
  7839. 6:25:56class and we're going to provide user ID
  7840. 6:26:00so now if we go back into card service
  7841. 6:26:03so we are actually selecting product
  7842. 6:26:05with its user and vendor because I want
  7843. 6:26:08to use the vendor store name when
  7844. 6:26:13rendering the cart
  7845. 6:26:15items in fact I want to group cart items
  7846. 6:26:19by this vendor store name and
  7847. 6:26:22show um let's say I have two vendors
  7848. 6:26:25let's say the first one is the code
  7849. 6:26:27holic is the vendor and second is the
  7850. 6:26:29vendor let's say um I don't know Sony
  7851. 6:26:32Entertainment as an example so I want to
  7852. 6:26:36display products from the vendor under
  7853. 6:26:39the vendor store name this is uh for
  7854. 6:26:43which I actually need to select the
  7855. 6:26:45products with a vendor name so you might
  7856. 6:26:47also have a question why I'm not
  7857. 6:26:49selecting that uh the product itself
  7858. 6:26:53from when I select the cart items from
  7859. 6:26:56the database I can do this however I
  7860. 6:27:00cannot do this
  7861. 6:27:02um When selecting cart items from
  7862. 6:27:05cookies if I'm confusing right now just
  7863. 6:27:09um follow with me okay so this is
  7864. 6:27:13something you just need to bear with me
  7865. 6:27:15you're going to follow and you will
  7866. 6:27:17understand every single thing what we
  7867. 6:27:18are doing right
  7868. 6:27:21now okay I will re explain that specific
  7869. 6:27:24part when I Implement these gate card
  7870. 6:27:26items from the database okay so now
  7871. 6:27:29let's continue and so we have this we
  7872. 6:27:33right here uh I'm going to also create
  7873. 6:27:35another scope and this scope is going to
  7874. 6:27:39select the products for website so at
  7875. 6:27:42the moment we have two scopes for vendor
  7876. 6:27:44and scope published and scope published
  7877. 6:27:47will simply check the status of the
  7878. 6:27:50status of the product but I want to
  7879. 6:27:53create something similar uh but for
  7880. 6:27:57scope for website okay and why I am
  7881. 6:28:03doing this because except other than
  7882. 6:28:07published there might be some other
  7883. 6:28:09conditions if I want to display that
  7884. 6:28:13product on the website or not for
  7885. 6:28:14example let's say that the product need
  7886. 6:28:17to be approved as well if we introduce
  7887. 6:28:19some approval um stage in the future or
  7888. 6:28:24the vendor needs to be approved uh
  7889. 6:28:28so um I want to also open product
  7890. 6:28:32controller to explain this very very
  7891. 6:28:34clearly so we are using published right
  7892. 6:28:37here and we probably need to select
  7893. 6:28:41published products in many places and
  7894. 6:28:43let's say we implemented the following
  7895. 6:28:45way and we have used published scope in
  7896. 6:28:4810 or 12 different places and then we
  7897. 6:28:51introduced a second condition whether
  7898. 6:28:55the product should be displayed on the
  7899. 6:28:56website or not it's not only published
  7900. 6:28:59but it is let's say that the vendor
  7901. 6:29:01needs to be approved as well so then we
  7902. 6:29:04have to update all the other places
  7903. 6:29:07where we have this published used okay
  7904. 6:29:11so but in our case I'm going to create
  7905. 6:29:14this new scope for website which will do
  7906. 6:29:17two things first it's going to make
  7907. 6:29:21sure that the product is published and
  7908. 6:29:24second if we need any other weather
  7909. 6:29:27Clauses we are going to put them right
  7910. 6:29:29here but for now um instead of using the
  7911. 6:29:33published I'm going to use for website
  7912. 6:29:35and I can do this right here in the
  7913. 6:29:38product controller as well for
  7914. 6:29:41website okay so I'm creating a wrapper
  7915. 6:29:45of the published scope calling this for
  7916. 6:29:48website now let's go into card service
  7917. 6:29:51so we are using this cope right here for
  7918. 6:29:53websites we're selecting all the
  7919. 6:29:55products with the IDS with user and
  7920. 6:29:58vendor for website then I'm going to
  7921. 6:30:00index that by ID so now we have that
  7922. 6:30:04products as a associative array where
  7923. 6:30:08the key is ID of the product and the
  7924. 6:30:11value is the entire object next we're
  7925. 6:30:14going to Define this cart item data and
  7926. 6:30:16we're going to iterate over our cart
  7927. 6:30:19items and we're going to do the
  7928. 6:30:21following so from products which we
  7929. 6:30:24indexed right now we are going to get
  7930. 6:30:28the product based on the card item
  7931. 6:30:31product ID okay so we get the product
  7932. 6:30:34right
  7933. 6:30:35here then if the product doesn't exist
  7934. 6:30:38we simply continue so what will be the
  7935. 6:30:41case when the product doesn't exist
  7936. 6:30:43product might not exist If the product
  7937. 6:30:47got deleted or
  7938. 6:30:49unpublished when we added that product
  7939. 6:30:53into the cart okay in which case we
  7940. 6:30:56simply don't display this product
  7941. 6:30:58anymore okay next we are going to Define
  7942. 6:31:02option information
  7943. 6:31:04and we're going to select variation type
  7944. 6:31:07options with the variation type as well
  7945. 6:31:10and inside the we close we're going to
  7946. 6:31:12provide the cart item option
  7947. 6:31:15IDs so because we created that cart
  7948. 6:31:20items table and we have this variation
  7949. 6:31:22type option IDs okay so from the cart
  7950. 6:31:26item we simply we we simply have option
  7951. 6:31:29IDs we are not using this variation type
  7952. 6:31:31option IDs why because those two methods
  7953. 6:31:36get cart items from the database and get
  7954. 6:31:39cart items from cookies will return them
  7955. 6:31:42with option
  7956. 6:31:44IDs okay again bear with me I'm going to
  7957. 6:31:48explain every single line what we are
  7958. 6:31:49doing here and then once we have the
  7959. 6:31:51entire code then we're going to do
  7960. 6:31:54recap okay so next we're going to do get
  7961. 6:31:57to get all the variation type options
  7962. 6:32:00with these IDs alongside with the
  7963. 6:32:02variation type self do we have this
  7964. 6:32:05variation type relation defined in the
  7965. 6:32:08variation type option I'm not sure let's
  7966. 6:32:11open variation type
  7967. 6:32:14option we don't have that relation
  7968. 6:32:17variation type so let's define this
  7969. 6:32:19through belongs to variation type here
  7970. 6:32:26we need variation type
  7971. 6:32:29class cool now we have that relation
  7972. 6:32:31defined next we're going to index T that
  7973. 6:32:34options by IDs um again we're going to
  7974. 6:32:38Key by like reorder them Key by I call
  7975. 6:32:41this indexing basically because now we
  7976. 6:32:43have this ID as a index of this array
  7977. 6:32:48okay so next we are going to generate
  7978. 6:32:51the image URL and this is kind of uh
  7979. 6:32:53interesting and tricky so if we don't
  7980. 6:32:55have any variation types defined on the
  7981. 6:32:57product the image URL will be the
  7982. 6:32:59product URL right however if we have
  7983. 6:33:02those variation type options defined on
  7984. 6:33:05the product then one of those options
  7985. 6:33:08might have its own images it might be
  7986. 6:33:11the case that none of the options have
  7987. 6:33:14extra images and in which case we're
  7988. 6:33:16going to again take the image from the
  7989. 6:33:19product so now we are going to iterate
  7990. 6:33:23over card items option IDs we're going
  7991. 6:33:27to take each option ID then we're going
  7992. 6:33:30to get the option from just selected
  7993. 6:33:33option
  7994. 6:33:35and we're going to check that um if the
  7995. 6:33:39image URL doesn't
  7996. 6:33:41exist then we're going to get the image
  7997. 6:33:43URL from option get First Media URL
  7998. 6:33:48images and
  7999. 6:33:50small okay so let's say that there were
  8000. 6:33:53two options for the first option we know
  8001. 6:33:55that the image URL is null so if will be
  8002. 6:33:59satisfied then let's say that first
  8003. 6:34:01option already has image is so this will
  8004. 6:34:05return the first image image URL will be
  8005. 6:34:07populated the next iteration for the
  8006. 6:34:10second option this if will not be
  8007. 6:34:13satisfied nothing will happen so pretty
  8008. 6:34:15much as long as we find the first option
  8009. 6:34:18which has image we are assigning that
  8010. 6:34:20into image URL okay next we're defining
  8011. 6:34:24the option info here inside option info
  8012. 6:34:27we're going to put uh the option ID
  8013. 6:34:29we're going to put the option name we're
  8014. 6:34:31going to put the type information as
  8015. 6:34:33well such as um the option variation
  8016. 6:34:36type ID and variation type
  8017. 6:34:39name after this for Loop so we have
  8018. 6:34:44image URL and we have option info okay
  8019. 6:34:48we're going to use them so I'm going to
  8020. 6:34:49collapse this option info is actually an
  8021. 6:34:52array pay attention so option info is
  8022. 6:34:54array and we have a the option
  8023. 6:34:57information as well as the type
  8024. 6:34:58information here now let's collapse this
  8025. 6:35:02and finally we're going to construct
  8026. 6:35:03this cart item data which is an array we
  8027. 6:35:07defined outside of this for Loop and
  8028. 6:35:09we're pushing something inside this cart
  8029. 6:35:11item data we're going to push the cart
  8030. 6:35:14item id itself we're going to push the
  8031. 6:35:16product ID we're going to push the title
  8032. 6:35:19of the product slug of the product we
  8033. 6:35:22need that slug to generate the product
  8034. 6:35:25Details page because whenever we open
  8035. 6:35:27the cart items listing we click on the
  8036. 6:35:31title or image of the product from the
  8037. 6:35:33cart items listing we want the product
  8038. 6:35:35Details page to be open so we are using
  8039. 6:35:38that slug for this so we need price as
  8040. 6:35:41well which we're going to take from cart
  8041. 6:35:43item we're going to take the quantity
  8042. 6:35:46again taking from the cart item and we
  8043. 6:35:49need these option IDs again taking from
  8044. 6:35:52the cart item but besides that uh option
  8045. 6:35:55IDs we also have the actual options we
  8046. 6:35:58need that option information to display
  8047. 6:36:00what type of variation option we have
  8048. 6:36:03added into the cart like here we're
  8049. 6:36:06Gathering that variation type option
  8050. 6:36:07info and we know that the variation type
  8051. 6:36:10is color and size so here we're going to
  8052. 6:36:13have color or size as a name however
  8053. 6:36:16inside these options we're going to have
  8054. 6:36:18black blue small or large so we need the
  8055. 6:36:23data to display what type of variations
  8056. 6:36:26we have added into the card like color
  8057. 6:36:29black size small we're going to display
  8058. 6:36:31that information pretty much much in a
  8059. 6:36:34similar way like how Amazon does that so
  8060. 6:36:38if we add this into the cart let's
  8061. 6:36:40select size and click on add to cart
  8062. 6:36:46that was added into the cart we click on
  8063. 6:36:49the cart and we see size extra small
  8064. 6:36:53color black whatever so in the same way
  8065. 6:36:57we're going to display this information
  8066. 6:36:59here and whenever we click on the image
  8067. 6:37:02or title just like Amazon does we're
  8068. 6:37:04going to open the details page cool so
  8069. 6:37:08we are going to render the um we're
  8070. 6:37:11going to also put image information
  8071. 6:37:13inside this array if image URL exists
  8072. 6:37:17right here then we're going to use that
  8073. 6:37:19image URL if it doesn't exist we are
  8074. 6:37:21going to take the First Media URL from
  8075. 6:37:24the product itself the image URL might
  8076. 6:37:26not exist if the there are no variation
  8077. 6:37:29options defined on the product or if
  8078. 6:37:32none of them have images if this if was
  8079. 6:37:35never
  8080. 6:37:36satisfied Okay cool so we push that data
  8081. 6:37:40inside card item data and after this we
  8082. 6:37:44are going to push the user information
  8083. 6:37:45as well now that user inform information
  8084. 6:37:49will have the uh user ID which is
  8085. 6:37:51product created by we're going to have
  8086. 6:37:54the name of the user which is going to
  8087. 6:37:57be the uh store name vendor store name
  8088. 6:38:02so product user vendor store name we
  8089. 6:38:06have the following relation defined and
  8090. 6:38:08in fact when we select products right
  8091. 6:38:10here we're selecting them with this with
  8092. 6:38:13user and vendor cool cool cool cool next
  8093. 6:38:18uh so we actually created this cart item
  8094. 6:38:21data and then after this for
  8095. 6:38:25each right here at the end of this for
  8096. 6:38:29each we're putting that cart item inside
  8097. 6:38:32this cart item data but at the end of
  8098. 6:38:34this for Loop we are re we are assigning
  8099. 6:38:38that cart item data into cached cart
  8100. 6:38:41items so this everything happens inside
  8101. 6:38:44this if statement if the cart item data
  8102. 6:38:48uh cach cart items equals null okay
  8103. 6:38:51however uh on the first execution of the
  8104. 6:38:54these gate card items we populating
  8105. 6:38:57something inside these cash card items
  8106. 6:39:00and on the next execution these card
  8107. 6:39:03item data will not be null the if will
  8108. 6:39:05not be satisfied and the same data will
  8109. 6:39:08be returned without executing all these
  8110. 6:39:11selects and
  8111. 6:39:13everything so we're going to also handle
  8112. 6:39:16the case if there is some exception and
  8113. 6:39:18we're going to put that information
  8114. 6:39:19inside logs and if there is some
  8115. 6:39:21exception we're going to return empty
  8116. 6:39:23array cool now that was the most
  8117. 6:39:26complicated method so far now let's take
  8118. 6:39:29care of this get total quantity okay so
  8119. 6:39:31we have that method which is get cart
  8120. 6:39:34items now we're going to use that get
  8121. 6:39:36cart items to calculate the total
  8122. 6:39:39quantity so we have the get cart items
  8123. 6:39:41iterate over that inside total quantity
  8124. 6:39:44we're going to push item quantity and
  8125. 6:39:46finally we're going to return this total
  8126. 6:39:48quantity in the same way we're going to
  8127. 6:39:50calculate the total price iterate
  8128. 6:39:52overcart items um uh create the like U
  8129. 6:39:56multiply the quantity into the item
  8130. 6:39:58price and push that information add that
  8131. 6:40:01information inside total finally we're
  8132. 6:40:04going to return
  8133. 6:40:05total after this we're going to focus on
  8134. 6:40:08update item quantity in database we take
  8135. 6:40:11the currently authenticated user ID then
  8136. 6:40:14we're going to select cart items so we
  8137. 6:40:18are using this user ID we're going to
  8138. 6:40:20use the product ID we want to find all
  8139. 6:40:24the specific cart item we want to update
  8140. 6:40:28inside the database so we're selecting
  8141. 6:40:30this by user ID by product ID
  8142. 6:40:33but please keep in mind that uh the same
  8143. 6:40:36user might have the same product added
  8144. 6:40:40into the card uh like a couple of times
  8145. 6:40:43and all of them will be different
  8146. 6:40:44records inside card items table in the
  8147. 6:40:47database I haven't executed the
  8148. 6:40:49migration to create the card items maybe
  8149. 6:40:52I should do this right now PHP Artisan
  8150. 6:40:56migrate it created cart items in vendors
  8151. 6:40:58table and if we check right now expand
  8152. 6:41:02cart items so the same user might add
  8153. 6:41:07the same product into the cart couple of
  8154. 6:41:10times and I'm not talking about
  8155. 6:41:11increasing quantity I'm talking about
  8156. 6:41:15creating actually different records in
  8157. 6:41:17this table and this might happen because
  8158. 6:41:20of the variation type option IDs so the
  8159. 6:41:22same product which might be um our
  8160. 6:41:25headset the same user which might be our
  8161. 6:41:29John do user as an example might edit
  8162. 6:41:32the same same
  8163. 6:41:34product second
  8164. 6:41:36times but with different variation type
  8165. 6:41:39option IDs so here we might have one and
  8166. 6:41:43four option IDs but here we might have
  8167. 6:41:45two and five option IDs so this is what
  8168. 6:41:48I want to
  8169. 6:41:51highlight now so we're selecting this
  8170. 6:41:53cart item uh with user product ID but
  8171. 6:41:57we're going to select this with uh
  8172. 6:41:59variation type option IDs as well we are
  8173. 6:42:02using this option IDs here uh and we're
  8174. 6:42:06selecting the first of this cart item if
  8175. 6:42:08the cart item exists we're going to
  8176. 6:42:10perform the update providing new
  8177. 6:42:12quantity if the cart item doesn't
  8178. 6:42:15exist we are not going to do anything so
  8179. 6:42:18right here this this is related to
  8180. 6:42:20update so if the cart item wasn't found
  8181. 6:42:22we are't going to do
  8182. 6:42:24anything so now to take care of the
  8183. 6:42:26update cart item quantity inside the
  8184. 6:42:29cookies we're going to read that uh cart
  8185. 6:42:33items from cookies okay so then we're
  8186. 6:42:37going to sort the option IDs what which
  8187. 6:42:40is given right here um and I'm sorting
  8188. 6:42:44this option IDs just to make sure that I
  8189. 6:42:47have the consistent data okay so first
  8190. 6:42:50we're going to have the lower option ID
  8191. 6:42:52then the larger one and we're going to
  8192. 6:42:55use this uh to
  8193. 6:42:57generate uh to take the cookie item key
  8194. 6:43:01and let me finish this method and I will
  8195. 6:43:03explain what I mean uh in better wording
  8196. 6:43:06and I'm going to show also the sample
  8197. 6:43:08data so I'm generating the following um
  8198. 6:43:12item key so maybe I should have
  8199. 6:43:15implemented this save item to the
  8200. 6:43:17database first and then update yeah
  8201. 6:43:20definitely I should have done this but
  8202. 6:43:22let me open now a new scratch file I'll
  8203. 6:43:25explain this no problem so inside
  8204. 6:43:28cookies we're going to have cart items
  8205. 6:43:31and when we get cart
  8206. 6:43:34items cart items then it is going to be
  8207. 6:43:38associative array and the key of this
  8208. 6:43:42ass associative area is going to be the
  8209. 6:43:44product ID let's say product one and the
  8210. 6:43:48Json encoded version of option IDs like
  8211. 6:43:511 comma 4 so this is going to be the key
  8212. 6:43:55and then we're going to have its
  8213. 6:43:56Associated information like quantity
  8214. 6:44:00price and few other things of this C
  8215. 6:44:02type item and we might have the same
  8216. 6:44:05product one added second time into the
  8217. 6:44:09cart with different variation options
  8218. 6:44:14with different quantity and with
  8219. 6:44:15different area information so this is
  8220. 6:44:18what I'm doing right now so constructing
  8221. 6:44:21this item key to read the data from cart
  8222. 6:44:24items from cookies so then I'm checking
  8223. 6:44:28if that key already exists in the cart
  8224. 6:44:31items um inside the cookie so if for
  8225. 6:44:35example this exists inside the cart
  8226. 6:44:39items then we're going to perform the
  8227. 6:44:41update and the update will be inside
  8228. 6:44:43cart items for the given key we are
  8229. 6:44:45going to update the quantity oops into
  8230. 6:44:49something like this okay next we are
  8231. 6:44:52going to um push that information save
  8232. 6:44:55the updated cart items B inside the
  8233. 6:44:59cookie so I'm using this cookie facade
  8234. 6:45:02uh Q method providing the cookie name
  8235. 6:45:05and providing the Json encoded version
  8236. 6:45:08of cart items and we are also going to
  8237. 6:45:11provide the cookie lifetime
  8238. 6:45:14here okay now we're going to focus on
  8239. 6:45:17the save item to datab base which I
  8240. 6:45:19should have done this before update my
  8241. 6:45:22bad apologies for this but uh I think
  8242. 6:45:25I'm doing my best to explain this very
  8243. 6:45:27clearly so you don't have any questions
  8244. 6:45:29okay now we have this user ID here we're
  8245. 6:45:32going to sore again option IDs and we're
  8246. 6:45:36doing this inside the database at the
  8247. 6:45:38moment okay so we are going to select
  8248. 6:45:41the card
  8249. 6:45:43item okay if that exists we are going to
  8250. 6:45:48update its quantity if it does not exist
  8251. 6:45:50we're going to add that cart item into
  8252. 6:45:52the database and why let's create this
  8253. 6:45:57so if let let me focus on this part so
  8254. 6:46:00if that card item exists in the database
  8255. 6:46:03we are performing the
  8256. 6:46:06database um update cury we provide the
  8257. 6:46:11existing quantity whatever it is in the
  8258. 6:46:14database plus the new quantity what we
  8259. 6:46:17have and so pay attention uh to this
  8260. 6:46:22what we have here versus the update into
  8261. 6:46:25the database so this is just update and
  8262. 6:46:28I plan to use it when performing the
  8263. 6:46:32update from the cart let's say I choose
  8264. 6:46:36five here this is going to execute the
  8265. 6:46:38update so in the database we're going to
  8266. 6:46:41have five straight five but I'm going to
  8267. 6:46:46use this method save item to database
  8268. 6:46:50whenever we are adding the product into
  8269. 6:46:53the cart so we have already added this
  8270. 6:46:55product into the cart we have it with a
  8271. 6:46:57five quantity but if I click on Ed to
  8272. 6:47:01cart once again right here so we're
  8273. 6:47:05doing something similar I know it is
  8274. 6:47:06Amazon it is not our website but when I
  8275. 6:47:09click on this it is going to actually
  8276. 6:47:11update the quantity into the card from
  8277. 6:47:13five to six so this is what we are doing
  8278. 6:47:16so we're going to call Save item to
  8279. 6:47:18database when we click add to cart and
  8280. 6:47:21if the item exists we're going to
  8281. 6:47:23perform the update existing quantity
  8282. 6:47:25plus the new quantity uh however if the
  8283. 6:47:28cart item doesn't exist we're going to
  8284. 6:47:29create that providing user ID product ID
  8285. 6:47:33quantity price and variation type option
  8286. 6:47:37IDs okay and we're done about this save
  8287. 6:47:40update to database we can focus on Save
  8288. 6:47:43item to cookies save item into the
  8289. 6:47:46database here and save item to cookies
  8290. 6:47:48so here we're selecting existing cart
  8291. 6:47:51items from cookies then we're sorting
  8292. 6:47:54the option
  8293. 6:47:55IDs um and then we're going to generate
  8294. 6:47:59this unique key based on the product ID
  8295. 6:48:01and option ID is and we're going to do
  8296. 6:48:04the check so if inside cut items we have
  8297. 6:48:07items key then we're going to perform
  8298. 6:48:11again update and increase the quantity
  8299. 6:48:15just like we did right here we're going
  8300. 6:48:17to increase the quantity button inside
  8301. 6:48:19cookie so for this inside the card items
  8302. 6:48:23for the given item key quantity plus
  8303. 6:48:26equals the quantity and we are going to
  8304. 6:48:29also update the price so the price maybe
  8305. 6:48:34when you added the item into the cart
  8306. 6:48:35the price was 100 but after one week you
  8307. 6:48:39decided to increase the quantity of that
  8308. 6:48:42product into the cart and the price
  8309. 6:48:44might might got changed so we want to
  8310. 6:48:47update that price as well it's is not
  8311. 6:48:49mandatory but um like in some cases it
  8312. 6:48:53will be easier to use the updated price
  8313. 6:48:55from uh cookie rather than selecting
  8314. 6:49:00that price from the database to check
  8315. 6:49:02check whether the price is always up to
  8316. 6:49:04date or not so I'm just adding this
  8317. 6:49:06price into the cart having the up
  8318. 6:49:09to-date price um and that's it so it's
  8319. 6:49:11not like something super crucial for the
  8320. 6:49:15entire card
  8321. 6:49:17system so if the cart items doesn't have
  8322. 6:49:21a given key then I am creating new cart
  8323. 6:49:24items for this I'm using the new ID
  8324. 6:49:27generate the U ID okay so we're going to
  8325. 6:49:31have the product ID quantity price and
  8326. 6:49:34option
  8327. 6:49:35IDs and finally I'm going to save that
  8328. 6:49:38updated cart items back inside cookies
  8329. 6:49:42so cookie Q provide the cookie name Json
  8330. 6:49:45encode inside cart items and the cookie
  8331. 6:49:47lifetime now let's take care of the
  8332. 6:49:49remove item from database we're going to
  8333. 6:49:51use the user ID sort the option IDs and
  8334. 6:49:55from the cart item where the user ID
  8335. 6:49:57equals the user ID product ID equals the
  8336. 6:50:00product ID variation type option IDs
  8337. 6:50:03equals the given option IDs then we're
  8338. 6:50:06going to perform the
  8339. 6:50:08delete so in the same way we're going to
  8340. 6:50:11uh get the cart items basically we are
  8341. 6:50:14directly reading these um C cart items
  8342. 6:50:18and we're calling this um Json
  8343. 6:50:22decode right here so then we are going
  8344. 6:50:26to uh sort the option IDs generate the
  8345. 6:50:29key with the product ID in option IDs
  8346. 6:50:32and where we're going to unset the
  8347. 6:50:34current key from the card items and
  8348. 6:50:37we're going to put that uh card items
  8349. 6:50:39back inside
  8350. 6:50:41cookie and now let's Implement get cart
  8351. 6:50:44items from the database we're going to
  8352. 6:50:46get the user ID and uh again where uh
  8353. 6:50:50we're going to
  8354. 6:50:52select uh okay so we're going to select
  8355. 6:50:54every item based on the user ID okay so
  8356. 6:51:00in this case we don't provide any uh
  8357. 6:51:02like product or something like this we
  8358. 6:51:04just want to read everything the current
  8359. 6:51:06user has inside the
  8360. 6:51:09database so we're calling this user uh
  8361. 6:51:13card item where user ID equals user ID
  8362. 6:51:15get then we're going to call map here
  8363. 6:51:18and map the card item into the following
  8364. 6:51:20array so we have um the ID product ID
  8365. 6:51:25quantity price and option IDs and that
  8366. 6:51:30option IDs is then what we are using um
  8367. 6:51:34inside gate cart items I will get back
  8368. 6:51:37there as
  8369. 6:51:38well okay next we're going to convert
  8370. 6:51:41this into an array because map returns
  8371. 6:51:43in collection so now we have these card
  8372. 6:51:45items to be an array and we're going to
  8373. 6:51:47Simply return this cart items and here
  8374. 6:51:50we are going to read these cart items
  8375. 6:51:52from cookie and we are going to return
  8376. 6:51:56those cart items so in fact I think
  8377. 6:52:01right here inside when calling this
  8378. 6:52:04remove item from cookies instead of this
  8379. 6:52:07cookie get directly I think we should
  8380. 6:52:10call these get card items from
  8381. 6:52:16cookies
  8382. 6:52:18now when we read that uh get cart items
  8383. 6:52:21from the database as I mentioned we map
  8384. 6:52:24this variation type uh
  8385. 6:52:28options actually this should be called
  8386. 6:52:31variation type option
  8387. 6:52:35IDs let me double check this variation
  8388. 6:52:39type option IDs yes option ID because
  8389. 6:52:43this is how we called this in the
  8390. 6:52:45database right so and the cart item is a
  8391. 6:52:48model uh of the cart item
  8392. 6:52:52class okay now if we go back into get
  8393. 6:52:55cart items from database this is the
  8394. 6:52:57place where we are using that we are
  8395. 6:52:59taking that uh cart items here and after
  8396. 6:53:06which we perform the iteration
  8397. 6:53:09here and each cart item has option IDs
  8398. 6:53:13that option IDs is what we return from
  8399. 6:53:17here and also if we have a look inside
  8400. 6:53:22save item to cookies we're going to see
  8401. 6:53:25that when we create new cart item we
  8402. 6:53:28give it also option
  8403. 6:53:30IDs and then later when we we read
  8404. 6:53:32something from the cookies this is the
  8405. 6:53:35format that is returned from
  8406. 6:53:38cookies
  8407. 6:53:40okay so this is great and I think uh we
  8408. 6:53:45have now these three main methods add
  8409. 6:53:48item to cart update item quantity and
  8410. 6:53:51remove from cart which is now um more
  8411. 6:53:55generic methods they don't look at the
  8412. 6:53:58whether it is for the database or not
  8413. 6:54:04now let's obviously implement the first
  8414. 6:54:06one add um item to cart so we have the
  8415. 6:54:09option IDs here as the third argument
  8416. 6:54:12which might be null so we are going to
  8417. 6:54:14check if option IDs is actually
  8418. 6:54:19null then we're going to take the first
  8419. 6:54:24option IDs from the product and add that
  8420. 6:54:27into the cart of course if the option
  8421. 6:54:30IDs are defined and this is necessary
  8422. 6:54:33when implementing a to card
  8423. 6:54:35functionality from product listing if we
  8424. 6:54:38check our page go to the uh homepage so
  8425. 6:54:41when I click Ed to card from
  8426. 6:54:44here uh if the product obviously doesn't
  8427. 6:54:46have any variation types or variation
  8428. 6:54:49type options defined it is going to add
  8429. 6:54:50the product itself into the cart however
  8430. 6:54:53if the product has variation types and
  8431. 6:54:55variation type options defined then I
  8432. 6:54:57want the first variation type options to
  8433. 6:55:01be added into the card which is
  8434. 6:55:02displayed right here as well which
  8435. 6:55:04should be displayed right here as well
  8436. 6:55:05at the moment we also don't display the
  8437. 6:55:07image from the variation type options
  8438. 6:55:10which we should do and we will do we
  8439. 6:55:13display this t-shirt but internally this
  8440. 6:55:15is actually um headset right so we want
  8441. 6:55:18to display um the uh black with small
  8442. 6:55:23variation type when we go back on the
  8443. 6:55:27homepage okay so if there are those um
  8444. 6:55:30variation type options toine and this is
  8445. 6:55:32what we're going to do so we're going to
  8446. 6:55:34generate option IDs equals from the
  8447. 6:55:37product we're going to access variation
  8448. 6:55:41types then actually
  8449. 6:55:44this this should be property so then I'm
  8450. 6:55:49going to call method map with keys
  8451. 6:55:52because I want to generate associative
  8452. 6:55:54array not a direct array so I'm using
  8453. 6:55:57this map with keys method on the
  8454. 6:55:59collection so here we have the this
  8455. 6:56:03variation type uh let me actually
  8456. 6:56:05convert this into Arrow function so we
  8457. 6:56:08accept type here let's call this type
  8458. 6:56:14and then we're going to return type ID
  8459. 6:56:18and we're going to return
  8460. 6:56:21type
  8461. 6:56:22options at index
  8462. 6:56:25zero and ID of that however ID however
  8463. 6:56:31we're going to check that that if the
  8464. 6:56:33option zero exists if it doesn't exist
  8465. 6:56:36this will return simply null okay so
  8466. 6:56:42then we're going to call two array to
  8467. 6:56:45convert this into um array because this
  8468. 6:56:49map with keys returns collection okay so
  8469. 6:56:51when we implement this we're going to
  8470. 6:56:53obviously check everything and make sure
  8471. 6:56:54that it works and when you implement it
  8472. 6:56:57when you are working in real project you
  8473. 6:56:59are going to test this into multiple
  8474. 6:57:01different cases and scenarios which
  8475. 6:57:04we're going to also
  8476. 6:57:05do okay now we have the option idas next
  8477. 6:57:09is to calculate the to get the price
  8478. 6:57:12which should be used to add the item
  8479. 6:57:14into the cart and price is also a tricky
  8480. 6:57:17thing so we can directly access product
  8481. 6:57:19price but based on these option IDs the
  8482. 6:57:23price might actually be different okay
  8483. 6:57:27because we allo that to specify
  8484. 6:57:30different prices for
  8485. 6:57:32um different variation
  8486. 6:57:36options okay so I'm going to uh create
  8487. 6:57:39new method on the product model and
  8488. 6:57:44let's put this at the very bottom and we
  8489. 6:57:46can call this uh
  8490. 6:57:49get price for options and here we're
  8491. 6:57:54going to accept option ID this which is
  8492. 6:57:58actually going to be array associative
  8493. 6:58:01array Maybe
  8494. 6:58:04get price for options let's check so
  8495. 6:58:07because right here we are calling this
  8496. 6:58:09map with keys option ID is is going to
  8497. 6:58:11return associative array where key is
  8498. 6:58:14the type ID and the value is its
  8499. 6:58:16corresponding option ID so here we are
  8500. 6:58:19only interested in options so I'm going
  8501. 6:58:22to convert these option IDs into array
  8502. 6:58:26values with the option IDs okay um
  8503. 6:58:32you probably have a question so if we
  8504. 6:58:34are only interested in uh values not
  8505. 6:58:38keys of these options why we are not
  8506. 6:58:42simply calling uh map right here and
  8507. 6:58:45taking the option IDs instead of map
  8508. 6:58:47with keys and taking the type ID as well
  8509. 6:58:50as a key of these option
  8510. 6:58:53IDs okay so because that associative
  8511. 6:58:56area always gives us more information we
  8512. 6:58:59have also type ID okay at the moment I
  8513. 6:59:02don't need the type ID but I might need
  8514. 6:59:06this in a different place okay so you
  8515. 6:59:10can obviously change this into map and
  8516. 6:59:12use the option IDs and then avoid these
  8517. 6:59:15array values right here which is
  8518. 6:59:17something I'm not going to do okay so
  8519. 6:59:20sort we're going to sort those option
  8520. 6:59:23IDs after which I'm going to start
  8521. 6:59:26iteration over for each
  8522. 6:59:30over uh this which is product these
  8523. 6:59:35variations okay and here we're going to
  8524. 6:59:38have
  8525. 6:59:39variation then the variation has
  8526. 6:59:42variation type option IDs and I'm going
  8527. 6:59:44to just create a temporary variable here
  8528. 6:59:47uh which will be
  8529. 6:59:49variation variation type option IDs now
  8530. 6:59:55this is what I am going to do I'm going
  8531. 6:59:57to sort this a which is variation type
  8532. 7:00:01option ID is for the variation in the
  8533. 7:00:04database and then I'm going to check
  8534. 7:00:09if option IDs my option IDs is the same
  8535. 7:00:14as these variation type option IDs both
  8536. 7:00:16of them are sorted I sorted my option
  8537. 7:00:19IDs and also the variation variation
  8538. 7:00:22type option IDs is also sorted so if
  8539. 7:00:25this happens then I am going to return
  8540. 7:00:28the variation price okay
  8541. 7:00:32um however if that the the if statement
  8542. 7:00:38was not satisfied at the end of the for
  8543. 7:00:41loop I am going to
  8544. 7:00:43return
  8545. 7:00:45this
  8546. 7:00:47price so we should probably test the
  8547. 7:00:50case when uh the specific variation
  8548. 7:00:53doesn't have price the matching might
  8549. 7:00:55happen but the price might be empty in
  8550. 7:01:00which case we should Pro probably return
  8551. 7:01:04uh the product price this price but I'm
  8552. 7:01:07not going to do like this because if the
  8553. 7:01:09price is zero that is um specific case
  8554. 7:01:14so we should not have probably price
  8555. 7:01:16zero right
  8556. 7:01:18so uh yeah depending on uh depending on
  8557. 7:01:22your specific thing you might want to
  8558. 7:01:24give someone some product for free in
  8559. 7:01:26which case you can give it price zero so
  8560. 7:01:29in which case this is what I'm going to
  8561. 7:01:30do so if VAR
  8562. 7:01:32price does not equal to
  8563. 7:01:36null then we're going to use the
  8564. 7:01:38variation price otherwise if it is null
  8565. 7:01:43then we're going to use this price the
  8566. 7:01:45product price if it is zero I'm still
  8567. 7:01:48using this variation price which will be
  8568. 7:01:52zero now go back into card service so
  8569. 7:01:55here now on this product I'm going to
  8570. 7:01:57use get price for options providing
  8571. 7:02:01option IDs here okay so now we have the
  8572. 7:02:04price and I'm going to do check if
  8573. 7:02:07out check happens if the user is
  8574. 7:02:11authenticated then I'm going to call
  8575. 7:02:13this save item to database
  8576. 7:02:17providing um providing product ID we
  8577. 7:02:22need ID providing quantity price and
  8578. 7:02:26option IDs I think we need all of them
  8579. 7:02:29we have these four arguments cool
  8580. 7:02:33if the user is not authenticated then
  8581. 7:02:36we're going to call Save item to cookies
  8582. 7:02:39providing a gain the same type of
  8583. 7:02:42data let's scroll down below and
  8584. 7:02:44Implement update item quantity or it's
  8585. 7:02:47uh much easier so we're going to use out
  8586. 7:02:50check if the user is
  8587. 7:02:52authenticated then this uh we're going
  8588. 7:02:56to
  8589. 7:02:57call update item quantity in database
  8590. 7:03:01we're going to provide the product ID
  8591. 7:03:03quantity and option
  8592. 7:03:05IDs
  8593. 7:03:08else we're going to call this update
  8594. 7:03:11item quantity into cookies providing
  8595. 7:03:13credit ID quantity and option IDs and
  8596. 7:03:16finally we have remove item from cart
  8597. 7:03:19we're going to do if out check then this
  8598. 7:03:22remove item from
  8599. 7:03:24database else this remove item from
  8600. 7:03:30cookies o a lot of work inside card
  8601. 7:03:34service but I think that we have this
  8602. 7:03:37card service right now
  8603. 7:03:39ready and let's go
  8604. 7:03:42into card
  8605. 7:03:45controller and have a look inside store
  8606. 7:03:48which is fully implemented we have the
  8607. 7:03:50root ready as well and I think we're
  8608. 7:03:54going to go
  8609. 7:03:59into let's open show TS six I think we
  8610. 7:04:02also have cart store implemented here
  8611. 7:04:07that's it we are providing the correct
  8612. 7:04:09data so I think we should we should have
  8613. 7:04:10everything ready now let's test this I'm
  8614. 7:04:12looking forward to test this let's click
  8615. 7:04:14on the product Details page this is
  8616. 7:04:16going to open the I'm going to open Dev
  8617. 7:04:18tools as well we have some error it's
  8618. 7:04:21time to fix the
  8619. 7:04:23errors okay the final argument pass to
  8620. 7:04:26use effect changed size between renders
  8621. 7:04:31the order in size of this array must
  8622. 7:04:34remain
  8623. 7:04:38constant interesting
  8624. 7:04:42error okay I am not um right now fully
  8625. 7:04:50sure how that should be fixed I think I
  8626. 7:04:53know the reason um but let me focus on a
  8627. 7:04:58to card first and I will um save your
  8628. 7:05:00time to find that um information
  8629. 7:05:04out so yeah I need the dev tools because
  8630. 7:05:06I'm going to send the request let's go
  8631. 7:05:08into Network and I'm going to click
  8632. 7:05:11this um a to cart let's have a
  8633. 7:05:15look okay uh app service out okay yeah
  8634. 7:05:18yeah of course of course so in the card
  8635. 7:05:21service we have bunch of classes which
  8636. 7:05:24are not imported like we need to import
  8637. 7:05:26this out which is going to be illuminate
  8638. 7:05:29support facad out we have couple of
  8639. 7:05:33other classes like variation type option
  8640. 7:05:36we're going to import that we have this
  8641. 7:05:40log which needs to be imported from
  8642. 7:05:43facad
  8643. 7:05:45log what else information do we have we
  8644. 7:05:48have to import this card
  8645. 7:05:51item and we have to import this que
  8646. 7:05:54which is going to be illuminate support
  8647. 7:05:57facades q and I think we don't have any
  8648. 7:06:01anything else to import we imported
  8649. 7:06:03everything what we need in this file so
  8650. 7:06:06I'm going to save that and click on this
  8651. 7:06:08add to card once again which returned
  8652. 7:06:12successfully we don't have anything in
  8653. 7:06:14the
  8654. 7:06:16errors oh we didn't see the success
  8655. 7:06:18message right so I'm going to click on
  8656. 7:06:21this Ed to cart again we didn't see the
  8657. 7:06:23success message because we didn't use
  8658. 7:06:25that success message uh we return this
  8659. 7:06:28from the controller from here but we
  8660. 7:06:31don't use it and we're going to use this
  8661. 7:06:33but now we can check the card items
  8662. 7:06:36table we checked it we didn't see
  8663. 7:06:40anything uh the current user is not
  8664. 7:06:43authenticated and this is why we didn't
  8665. 7:06:45see anything which gives me a promise
  8666. 7:06:48that the data was saved inside the cart
  8667. 7:06:51so now if we go
  8668. 7:06:56into let me think so I'm going to open
  8669. 7:07:00handle inera JS requests and basically
  8670. 7:07:05right here we are rendering the
  8671. 7:07:07following card drop down and in the
  8672. 7:07:09following dropdown we are going to
  8673. 7:07:11render the card items right so inside
  8674. 7:07:13this handle injs request we have this
  8675. 7:07:16shared data and inside the data we're
  8676. 7:07:19going to pass two things first we're
  8677. 7:07:21going to pass the success what we just
  8678. 7:07:25set inside the card controller so we're
  8679. 7:07:28going to get this from session session
  8680. 7:07:31ESS and second we are going to pass cart
  8681. 7:07:36items and this is going to
  8682. 7:07:40be to use the card service now we can
  8683. 7:07:43use this dependency injection and we're
  8684. 7:07:46going to uh take the class cart
  8685. 7:07:50service
  8686. 7:07:51here and we need few things so we need
  8687. 7:07:55total quantity which is the hardcoded
  8688. 7:07:57eight right here so let's use total
  8689. 7:08:01Quant
  8690. 7:08:02which will be card service get total
  8691. 7:08:06quantity okay I think we cannot use this
  8692. 7:08:09card service like this instead we can
  8693. 7:08:12access this from the application so card
  8694. 7:08:15service equals app card service now we
  8695. 7:08:18get the total quantity we are going to
  8696. 7:08:21get total price card service get total
  8697. 7:08:24price and we're going to have cart items
  8698. 7:08:28as well now I want to print all of them
  8699. 7:08:32let's use DD I want to print total price
  8700. 7:08:37I want to print total quantity and card
  8701. 7:08:40items and let's refresh the
  8702. 7:08:43page uh we have some syntax
  8703. 7:08:46error right here let's put the cart
  8704. 7:08:50items refresh the page now we don't have
  8705. 7:08:53anything inside cookies which is
  8706. 7:08:57actually not good I thought we inserted
  8707. 7:09:00that information
  8708. 7:09:02now we are going to debug
  8709. 7:09:06this let's go into card service and find
  8710. 7:09:11this save item to cookies and we are
  8711. 7:09:16going to print
  8712. 7:09:17existing let's print existing uh cart
  8713. 7:09:21items we're going to print product ID
  8714. 7:09:25quantity price and option IDs when we
  8715. 7:09:27try to add something inside the cookie
  8716. 7:09:30I'm going to click on the and we see the
  8717. 7:09:32following information
  8718. 7:09:34so this is the existing information
  8719. 7:09:37which already exists inside the cookies
  8720. 7:09:41right
  8721. 7:09:44yeah okay so the information is already
  8722. 7:09:47inside the cookies we have it two
  8723. 7:09:53times okay I'm going to undo this and
  8724. 7:09:56let's check get card items
  8725. 7:10:01which selects the cart items from
  8726. 7:10:03cookies now let's print that cart items
  8727. 7:10:09here refresh the page we see those cart
  8728. 7:10:12items okay
  8729. 7:10:16awesome but why don't we
  8730. 7:10:20see these cart items
  8731. 7:10:23here DD cart
  8732. 7:10:26items okay maybe something is messed up
  8733. 7:10:30here so we have this card
  8734. 7:10:32items um we have this card item
  8735. 7:10:36data maybe some exception happens
  8736. 7:10:40definitely some exception happens here
  8737. 7:10:42and because of this we don't see it so
  8738. 7:10:44let's execute throw
  8739. 7:10:47e refresh the
  8740. 7:10:50page attempt to read property store name
  8741. 7:10:53of n exactly so the current um the owner
  8742. 7:10:58of this current product which is
  8743. 7:11:00actually vendor
  8744. 7:11:02all right so if we check the
  8745. 7:11:07products so this is the first product it
  8746. 7:11:09has the created by field to be two and
  8747. 7:11:13created uh the two ID is the vendor okay
  8748. 7:11:16and we need to set a rule that every
  8749. 7:11:21vendor needs to have the corresponding
  8750. 7:11:23record in the vendor table in fact if we
  8751. 7:11:26open user CED I'm going to update that
  8752. 7:11:30part as well and here I create the
  8753. 7:11:34user then we assign
  8754. 7:11:37that role into the
  8755. 7:11:39user but after this I'm going to create
  8756. 7:11:44vendor
  8757. 7:11:48Factory uh vendor doesn't have
  8758. 7:11:51Factory vendor doesn't have Factory but
  8759. 7:11:53it's not important because we don't need
  8760. 7:11:56to Define these fields inside the
  8761. 7:11:58factory we can provide these fields
  8762. 7:12:00right here so I'm going to provide user
  8763. 7:12:01ID I'm going to provide the status for
  8764. 7:12:06the vendor and for this I think I'm
  8765. 7:12:09going to Define new enam and this is
  8766. 7:12:12going to
  8767. 7:12:13be hbr artisan make
  8768. 7:12:16enam
  8769. 7:12:18vendor status
  8770. 7:12:23an we hit the enter that was created
  8771. 7:12:25under app enms vendor status enm now
  8772. 7:12:28let's open vendor
  8773. 7:12:31status
  8774. 7:12:34enam return type is
  8775. 7:12:37string um not return type but the enm
  8776. 7:12:41type and we have
  8777. 7:12:44these actually let me duplicate these
  8778. 7:12:46three times so this is going to be
  8779. 7:12:52pending pending or let me do this
  8780. 7:12:55lowercase pending then we have approved
  8781. 7:13:01approved and we're going to have
  8782. 7:13:07rejected now if we go open this user
  8783. 7:13:10Ceder here inside the status we are
  8784. 7:13:14going to
  8785. 7:13:15use vender status
  8786. 7:13:19enam uh let's make it approved
  8787. 7:13:24okay we need store name as
  8788. 7:13:28well which is going to be something
  8789. 7:13:34we need store address as well let's give
  8790. 7:13:38it some fake
  8791. 7:13:42address and I think we don't need
  8792. 7:13:44anything else so we create this vendor
  8793. 7:13:47for the specific user but we're doing
  8794. 7:13:49this inside the cedar class and I don't
  8795. 7:13:52want to rerun actually all my migrations
  8796. 7:13:55and delete the current product what I
  8797. 7:13:57have in the database created so I'm
  8798. 7:13:59going to create the same type of vendor
  8799. 7:14:03manually so open the vendors table click
  8800. 7:14:07on this user ID is actually two uh this
  8801. 7:14:11is approved store name is vendor store
  8802. 7:14:16store address is some test address and
  8803. 7:14:21we have the cover cover image I'm going
  8804. 7:14:23to leave empty created at is actually
  8805. 7:14:26now and updated at is actually now as
  8806. 7:14:29well
  8807. 7:14:34okay now if we refresh this page we are
  8808. 7:14:38not going to see this
  8809. 7:14:40error that's
  8810. 7:14:42perfect let's go
  8811. 7:14:45inside card service remove this
  8812. 7:14:50through go inside handle initial JS
  8813. 7:14:53request and I'm going to dump C
  8814. 7:14:58items but before these I'm going to dump
  8815. 7:15:00total price and total quantity as well
  8816. 7:15:05refresh the page we see total price is
  8817. 7:15:0850 total quantity is two and right here
  8818. 7:15:12we see the product with its uh ID the
  8819. 7:15:15product ID this ID is actually the our
  8820. 7:15:19generated U ID so we have the title
  8821. 7:15:22slack price everything is here including
  8822. 7:15:25image and we have the user information
  8823. 7:15:27as well and this is so cool so I think
  8824. 7:15:32we just need to provide that information
  8825. 7:15:35inside here inside the shared
  8826. 7:15:39data so I'm going to call
  8827. 7:15:44these uh so total
  8828. 7:15:47price and total quantity okay we provide
  8829. 7:15:52both now we're going to get those card
  8830. 7:15:56items inside
  8831. 7:15:59navbar and here we have eight written
  8832. 7:16:03somewhere this is the place okay so this
  8833. 7:16:06is what I am going to
  8834. 7:16:08change we have the page props and from
  8835. 7:16:11this page props we're going to take
  8836. 7:16:13total price and total
  8837. 7:16:19quantity but these need to be defined
  8838. 7:16:22inside page
  8839. 7:16:24props so for this I'm going to open
  8840. 7:16:28index.ts
  8841. 7:16:30let's open page props here we have out
  8842. 7:16:34and Ziggy and let's add
  8843. 7:16:37total quantity which is going to be
  8844. 7:16:40number and total price which is going to
  8845. 7:16:44be number as well but we also want cart
  8846. 7:16:48items here which is going to be array of
  8847. 7:16:52cart
  8848. 7:16:53item now let me Define this cart item
  8849. 7:16:58class somewhere right here x Port type
  8850. 7:17:02cart
  8851. 7:17:04item and we need ID we need product ID
  8852. 7:17:09we need uh title of the um product we
  8853. 7:17:14need slug we need
  8854. 7:17:18image um we need price as well we need
  8855. 7:17:24quantity we also need option IDs which
  8856. 7:17:28is going to be actually op object so I'm
  8857. 7:17:31using record here string and number the
  8858. 7:17:35key is going to be the uh type ID and
  8859. 7:17:39the value is going to be uh the option
  8860. 7:17:41ID so we can use string in both cases or
  8861. 7:17:44we can use numbers as well in both
  8862. 7:17:47cases um but yeah as I tested like
  8863. 7:17:50string as a key was working better
  8864. 7:17:52speaking of the
  8865. 7:17:55object and we have these options as well
  8866. 7:17:58so this is going to be very viation oops
  8867. 7:18:02variation type option array of these
  8868. 7:18:07variation type options so now here the
  8869. 7:18:10cart items is going to be cart item area
  8870. 7:18:12of cart
  8871. 7:18:14items so we have the total price total
  8872. 7:18:16quantity they are actually uh now autoc
  8873. 7:18:19completed by
  8874. 7:18:21IDE and we are going to find that total
  8875. 7:18:25price and total quantity I think we have
  8876. 7:18:28this total quantity here
  8877. 7:18:32and we don't have total
  8878. 7:18:36price let's
  8879. 7:18:38see refresh the
  8880. 7:18:42page we see two which is the total
  8881. 7:18:44quantity and that is so cool if I click
  8882. 7:18:47on this uh that is the data I want to
  8883. 7:18:51change
  8884. 7:18:53so let's have a look so we have this
  8885. 7:18:56drop down drop down end
  8886. 7:19:00this is the drop down so this drop down
  8887. 7:19:03end I'm going to extract this into a new
  8888. 7:19:07component and that component will
  8889. 7:19:11be application specific component so
  8890. 7:19:15resources ajs components up here I'm
  8891. 7:19:18going to
  8892. 7:19:21create uh mini cart dropdown so we're
  8893. 7:19:25going to have uh probably a separate
  8894. 7:19:28cart component which is going to be for
  8895. 7:19:30the entire page but this is kind of mini
  8896. 7:19:33cards drop down and let's create the
  8897. 7:19:37component inside this mini cart
  8898. 7:19:41dropdown we are going to accept all
  8899. 7:19:43these properties um from the used page
  8900. 7:19:47props so const uh I'm going to
  8901. 7:19:50destructure something here use page.
  8902. 7:19:56props so then I'm going to destructure
  8903. 7:20:02hold on let me think so I'm going to
  8904. 7:20:05destructure and take total
  8905. 7:20:08quantity total price and cart
  8906. 7:20:13items we don't need props
  8907. 7:20:16here let me use this mini card drop down
  8908. 7:20:20in this
  8909. 7:20:21place and we have this boiler plate code
  8910. 7:20:25which I copied and I'm going to put this
  8911. 7:20:28right here
  8912. 7:20:32so we have total eight items I'm going
  8913. 7:20:34to replace these with total
  8914. 7:20:41quantity and here I'm going to
  8915. 7:20:45use l is extra in here I am going to use
  8916. 7:20:49currency
  8917. 7:20:50format so inside subtotal we're going to
  8918. 7:20:54use currency format providing total
  8919. 7:20:57price
  8920. 7:21:00and then we have this view cart uh which
  8921. 7:21:03has the purpose to open the cart Details
  8922. 7:21:05page so I'm going to change this into
  8923. 7:21:07link uh providing h r here
  8924. 7:21:13root uh
  8925. 7:21:15cart.
  8926. 7:21:16index which is something we already
  8927. 7:21:21defined okay so we have more things to
  8928. 7:21:25do inside this dropdown but for now we
  8929. 7:21:27see that we have two total items and the
  8930. 7:21:30sub total is
  8931. 7:21:3250 but now I'm going to actually display
  8932. 7:21:36those uh card items as well in the
  8933. 7:21:39following
  8934. 7:21:42area between this uh number of items and
  8935. 7:21:46subtotal I'm going to display those
  8936. 7:21:49actual cart items so let me create div
  8937. 7:21:52uh div not div but give it margin y4 a
  8938. 7:21:57maximum heit of like 300 pixel and I'm
  8939. 7:22:02going to give it overflow
  8940. 7:22:05Auto then I'm going to iterate over cart
  8941. 7:22:09items call map we
  8942. 7:22:13have the item actually uh before I do
  8943. 7:22:17this I'm going to also check if the cart
  8944. 7:22:20items is empty so if cart items.
  8945. 7:22:24length uh if that equals zero then
  8946. 7:22:30I am going to render something that
  8947. 7:22:33something is going to be div give it
  8948. 7:22:35some classes like pting Y
  8949. 7:22:382 uh text Gray uh 500 and give it text
  8950. 7:22:44Center as well and the message is go
  8951. 7:22:47going to be you don't have any
  8952. 7:22:51items
  8953. 7:22:54yet okay however when I want to iterate
  8954. 7:22:58over my part item I want to create div
  8955. 7:23:03let's give it key to be item. ID uh
  8956. 7:23:08let's give it also class
  8957. 7:23:10names
  8958. 7:23:11Flex gap of four and padding
  8959. 7:23:16three then I'm going to create link and
  8960. 7:23:20that link is going to be for the
  8961. 7:23:23image okay so side link we're going to
  8962. 7:23:26provide hre we are going to use r wrote
  8963. 7:23:34product product. show and we're going to
  8964. 7:23:38provide item slug here because we are
  8965. 7:23:42going to open this
  8966. 7:23:45um using
  8967. 7:23:47slug actually I'm going to create a
  8968. 7:23:52helper helper function um inside the
  8969. 7:23:57helpers file I'm thinking right now so
  8970. 7:24:02let's put an image
  8971. 7:24:04here first I will come back to this um
  8972. 7:24:07product show I think I will come back to
  8973. 7:24:10this definitely so inside this image
  8974. 7:24:13we're going to
  8975. 7:24:14provide um item.
  8976. 7:24:18image we can provide also item. title
  8977. 7:24:23inside alt and inside the class name I'm
  8978. 7:24:26going to move this down let's move alt
  8979. 7:24:29down as as well and inside class name I
  8980. 7:24:32want to provide maximum W full and Max H
  8981. 7:24:39full so next I'm going to create div
  8982. 7:24:42outside of this link so we're going to
  8983. 7:24:44have image on the left side and on the
  8984. 7:24:46right side we're going to have a couple
  8985. 7:24:48of information like title which is going
  8986. 7:24:50to be inside H3 let's give this uh Flex
  8987. 7:24:55one then I'm going to give into this
  8988. 7:24:58H3 class name margin btom 3 font
  8989. 7:25:05semibold and the and then inside here
  8990. 7:25:08we're going to have
  8991. 7:25:11link
  8992. 7:25:14href uh here we're going to have root
  8993. 7:25:19dot product. show with item
  8994. 7:25:24Slug and we're going to Output item.
  8995. 7:25:28title below this H2 we're going to
  8996. 7:25:31display the quantity of the product and
  8997. 7:25:35the price of the product so let's create
  8998. 7:25:38this Steve I'm going to give it
  8999. 7:25:40Flex uh let's give
  9000. 7:25:43it uh justify between and text
  9001. 7:25:48small then I'm going to have one extra D
  9002. 7:25:51for
  9003. 7:25:53quantity item. quantity and I'm going to
  9004. 7:25:57have another D which is going to be for
  9005. 7:25:59price
  9006. 7:26:00currency
  9007. 7:26:02format
  9008. 7:26:04amount item.
  9009. 7:26:09price actually the price is going to be
  9010. 7:26:12item. quantity Multiplied on
  9011. 7:26:21price okay let's save this and have a
  9012. 7:26:24look click on the
  9013. 7:26:27dropdown we see those two items
  9014. 7:26:31I think we have to increase the width of
  9015. 7:26:34the drop down
  9016. 7:26:36right
  9017. 7:26:39let's let's find these card
  9018. 7:26:44element we have card card
  9019. 7:26:47compact uh with width of 52 we're going
  9020. 7:26:52to change this into some fixed withd
  9021. 7:26:55which I'm going to give it 480 pixel
  9022. 7:27:02okay now the image is
  9023. 7:27:07huge let's find this image area and to
  9024. 7:27:11the following link I'm going to give it
  9025. 7:27:13class
  9026. 7:27:15name uh
  9027. 7:27:18W6
  9028. 7:27:22h16 uh
  9029. 7:27:24Flex
  9030. 7:27:26justify
  9031. 7:27:28Center and and we can give it item
  9032. 7:27:31Center as well to put this image inside
  9033. 7:27:33the
  9034. 7:27:35center that's more like
  9035. 7:27:41it and let me find
  9036. 7:27:45subtotal sub total and I want to change
  9037. 7:27:50this text color as
  9038. 7:27:55well yeah I'm going to give it text
  9039. 7:27:59large
  9040. 7:28:03okay that's it so we have two items uh
  9041. 7:28:06the title when we click on this it is
  9042. 7:28:09going to open the product Details
  9043. 7:28:11page
  9044. 7:28:15right clicking on the title is going to
  9045. 7:28:18do the same
  9046. 7:28:21thing
  9047. 7:28:23great next I'm going to start working on
  9048. 7:28:26the dedicated card page when I click
  9049. 7:28:29this view card which should open the
  9050. 7:28:33card Details
  9051. 7:28:35page um this is coming from the card
  9052. 7:28:37controller and we have the card service
  9053. 7:28:39printed right there okay so let's open
  9054. 7:28:42card
  9055. 7:28:44controller find
  9056. 7:28:46index and let's adjust this so we're
  9057. 7:28:50going to return inertia
  9058. 7:28:53render cart slash index and we're going
  9059. 7:28:59to return the following information so
  9060. 7:29:01we need card
  9061. 7:29:02items and we're going to take those card
  9062. 7:29:05items
  9063. 7:29:07from the card
  9064. 7:29:10service uh however this is not exactly
  9065. 7:29:13how I want to pass that uh let's open
  9066. 7:29:17card service and I'm going to add a new
  9067. 7:29:19method inside the card service and I
  9068. 7:29:21want to group cart items based on the
  9069. 7:29:24vendor user the seller user okay and I'm
  9070. 7:29:28going to render them
  9071. 7:29:31like based on the user so let's define
  9072. 7:29:34the method get cart items grouped which
  9073. 7:29:37is going to return an array so I'm going
  9074. 7:29:38to select these gate cart items to get
  9075. 7:29:41the cart items actually then I'm going
  9076. 7:29:43to convert those cart items into
  9077. 7:29:45collection I'm going to call group Pi
  9078. 7:29:48okay and I'm going to uh inside this
  9079. 7:29:50group P I'm going to group those cart
  9080. 7:29:55items based on the item user ID
  9081. 7:30:00okay then I'm going to call map on this
  9082. 7:30:02now we have these items which is going
  9083. 7:30:04to be already so the these already
  9084. 7:30:07perform the grouping right so then this
  9085. 7:30:09is going to be the data values this is
  9086. 7:30:11going to be the key and then I am taking
  9087. 7:30:14from these items which is going to be
  9088. 7:30:17cart items array so I am taking the
  9089. 7:30:22first cart item and the user information
  9090. 7:30:25out of it okay I'm returning that user
  9091. 7:30:29information and I am returning the items
  9092. 7:30:33itself in in in the format of array
  9093. 7:30:37after which we're going to add total
  9094. 7:30:39quantity as well and the total quantity
  9095. 7:30:42will be for each user so for each user
  9096. 7:30:47we're going to also have how many
  9097. 7:30:50items um for each vendor more more
  9098. 7:30:53precisely for each vendor we have user
  9099. 7:30:56here but it's actually vendor
  9100. 7:30:57information right so this is seller as
  9101. 7:31:00well for each seller we're going to also
  9102. 7:31:03have how many total quantity items the
  9103. 7:31:07currently authenticated user has added
  9104. 7:31:10into the cart not not necessarily the
  9105. 7:31:13authenticated but the current user who
  9106. 7:31:15is viewing the browser has added into
  9107. 7:31:18the cart or What's the total price uh
  9108. 7:31:21here so in case of total price we take
  9109. 7:31:24those items which is
  9110. 7:31:26collection of these cart items and we
  9111. 7:31:30are calling sum here to create the sum
  9112. 7:31:33using item price multipli than item
  9113. 7:31:37quantity and thus the total price will
  9114. 7:31:39contain the entire price for this
  9115. 7:31:42specific seller okay then we're calling
  9116. 7:31:45this two area right here this is going
  9117. 7:31:47to return the card items grouped so here
  9118. 7:31:50I am going to use get card items grouped
  9119. 7:31:54okay and we're going to also
  9120. 7:31:57provide here total
  9121. 7:32:01uh total
  9122. 7:32:05quantity well actually I think we have
  9123. 7:32:07total
  9124. 7:32:09quantity and total price provided from
  9125. 7:32:14the handle inertia JS request from here
  9126. 7:32:18okay that actually does the same thing
  9127. 7:32:21okay so we have these card items cool I
  9128. 7:32:23think this is all what we needed now
  9129. 7:32:26let's go into JS and I'm going to create
  9130. 7:32:33here cart slash
  9131. 7:32:37index typescript
  9132. 7:32:41file okay now I'm going to remove this
  9133. 7:32:45Steve I'm going to remove these props
  9134. 7:32:48and remove this
  9135. 7:32:50react now here I'm going to accept
  9136. 7:32:53couple of props so first I'm going to
  9137. 7:32:55import page props class it's a type then
  9138. 7:33:00we're going to Define props right here
  9139. 7:33:02so I will need to implement the checkout
  9140. 7:33:05functionality and for this I will need
  9141. 7:33:07to submit the form not through inertia
  9142. 7:33:11way but in a more traditional way like
  9143. 7:33:15the typical form submission with uh the
  9144. 7:33:18page refresh and reload so for this I
  9145. 7:33:21need to use csrf token because I'm going
  9146. 7:33:24to submit the form with post method and
  9147. 7:33:28for this I will need CSR
  9148. 7:33:30token so I'm going to
  9149. 7:33:33open handle inertia JS requests and
  9150. 7:33:36right here I'm going to add
  9151. 7:33:40csrf token which is going to be the csrf
  9152. 7:33:43token um string basically so then right
  9153. 7:33:48here inside the index I am going to
  9154. 7:33:50accept csrf token but let's actually
  9155. 7:33:52Define this inside page props as well so
  9156. 7:33:55we have
  9157. 7:33:56csrf uncore token which is going going
  9158. 7:33:59to be string and I formatted the code
  9159. 7:34:03and it's going to be also required not
  9160. 7:34:05optional now right here we're going to
  9161. 7:34:08accept csrf token we're going to also
  9162. 7:34:10accept cart items total quantity and
  9163. 7:34:14total price all right and I'm going to
  9164. 7:34:17define the type as well so this has type
  9165. 7:34:20of the following object has type of page
  9166. 7:34:23props however the cart items uh which we
  9167. 7:34:27actually have defined as instance of
  9168. 7:34:29cart items we are going to change its
  9169. 7:34:32type into grouped cart items so this is
  9170. 7:34:35an array we can obviously specified an
  9171. 7:34:38array right here with square brackets um
  9172. 7:34:41like these grouped card items instead of
  9173. 7:34:44the selected text with square brackets
  9174. 7:34:46but this is also going to do the same
  9175. 7:34:49thing same thing okay so and we're going
  9176. 7:34:52to Define this grouped cart items type
  9177. 7:34:55I'm going to do this maybe below this
  9178. 7:34:57cart item export
  9179. 7:35:01um not default but export type grouped
  9180. 7:35:05cart item and each grouped cart item has
  9181. 7:35:09the user
  9182. 7:35:10information and it has items and the
  9183. 7:35:13items is array of cart item so this is
  9184. 7:35:17how we return the cart items from the
  9185. 7:35:19card
  9186. 7:35:20controller as we see so each element
  9187. 7:35:24from this array has user and items
  9188. 7:35:27additionally if we want we can also
  9189. 7:35:29Define total quantity and total price
  9190. 7:35:32and then use them inside the view uh
  9191. 7:35:37template uh let's open this index DTS
  9192. 7:35:40and let's define
  9193. 7:35:42them uh
  9194. 7:35:44total total price let me Define this in
  9195. 7:35:47uppercase way like I have defined it
  9196. 7:35:49total price and total quantity now let's
  9197. 7:35:53go into card service and change this
  9198. 7:35:56into total price and total quantity with
  9199. 7:35:58camel case
  9200. 7:36:00notation now right here uh we're going
  9201. 7:36:04to import this grouped card uh grouped
  9202. 7:36:07card items in a little bit later now
  9203. 7:36:10let's right here focus on the
  9204. 7:36:14um the uh template area so we need
  9205. 7:36:18authenticated layout inside which we're
  9206. 7:36:20going to Define head then we're going to
  9207. 7:36:23have div which is going to be the
  9208. 7:36:24wrapper container with some t one cus
  9209. 7:36:26classes inside here we're going to have
  9210. 7:36:28additional d and that is going to be the
  9211. 7:36:31card okay with background we're going to
  9212. 7:36:33have card body so this is going to be
  9213. 7:36:35the left area uh where we will display
  9214. 7:36:39the card items and we're going to have
  9215. 7:36:41second card as well which is going to be
  9216. 7:36:43on the right side and this is going to
  9217. 7:36:45display the information uh the total
  9218. 7:36:48number of items inside the card total
  9219. 7:36:50price and check out button as
  9220. 7:36:54well okay cool now let's focus on the
  9221. 7:36:57first T which is going to be where we
  9222. 7:36:59display the the items so let's give it a
  9223. 7:37:02title shopping cart and then create
  9224. 7:37:04another div container inside which we
  9225. 7:37:06are going to iterate over our card items
  9226. 7:37:11okay so the card items uh we we take the
  9227. 7:37:15keys of the cart items and the cart
  9228. 7:37:18items actually if we check again in the
  9229. 7:37:20card controller so this is uh
  9230. 7:37:25associative array okay um
  9231. 7:37:30definitely so uh because we are using a
  9232. 7:37:32group by right here so we group those
  9233. 7:37:35card items with the user ID meaning that
  9234. 7:37:38the user ID is the key let me open U
  9235. 7:37:41maybe scratch Json file or maybe scratch
  9236. 7:37:44PHP file and I will show this to you
  9237. 7:37:46exactly so these grouped cart items will
  9238. 7:37:50have the following format so we have the
  9239. 7:37:51user ID here and its
  9240. 7:37:54corresponding uh object where we have
  9241. 7:37:57the user information itself the entire
  9242. 7:38:00user details and we have items which is
  9243. 7:38:02going to be array additionally we also
  9244. 7:38:05have total price which is going to be
  9245. 7:38:07number and we also have total
  9246. 7:38:12quantity which is also number so this is
  9247. 7:38:15how cart items look like and we're going
  9248. 7:38:17to have something
  9249. 7:38:18similar if we added uh multiple cart
  9250. 7:38:21items from different vendor users so
  9251. 7:38:24this will be duplicated for different
  9252. 7:38:26user for different user ID here and user
  9253. 7:38:31details okay let's move this on the
  9254. 7:38:33right side collapse a little bit so to
  9255. 7:38:37get back to this index DTS uh I'm going
  9256. 7:38:39to make one correction because I'm going
  9257. 7:38:43to close this I think this is clear so
  9258. 7:38:45I'm going to close this or move right
  9259. 7:38:46here so because we have that as
  9260. 7:38:50associative array because of that we
  9261. 7:38:52need right here to use record um with
  9262. 7:38:55key to be number user ID and the value
  9263. 7:38:58to be group cart items
  9264. 7:39:01okay now then we check if the object
  9265. 7:39:03keys of this cart items length is equal
  9266. 7:39:05zero if there is nothing added into the
  9267. 7:39:07cart and then we're going to display the
  9268. 7:39:09text you don't have any items yet
  9269. 7:39:12however we're going to start iterating
  9270. 7:39:13over cart items values in our case and
  9271. 7:39:17we are going to obviously create D with
  9272. 7:39:19key cart item user ID so that's the
  9273. 7:39:21outer loop and we are doing this outer
  9274. 7:39:24loop for each user we have two users in
  9275. 7:39:27our example so the Outer Loop will be
  9276. 7:39:29iterated two times okay then we display
  9277. 7:39:33um the another div inside which we're
  9278. 7:39:36going to have the link that link will be
  9279. 7:39:38the usern name uh the that username is
  9280. 7:39:41actually vendor name so if we check in
  9281. 7:39:44the cart service we
  9282. 7:39:46see um inside cart items get cart items
  9283. 7:39:50scroll down
  9284. 7:39:52below when we construct that cart item
  9285. 7:39:56info we have the user user has ID user
  9286. 7:39:59ID and the name is the vendor store name
  9287. 7:40:03all right so that name is used right
  9288. 7:40:06here when vendor store name we're going
  9289. 7:40:09to import all the things after we finish
  9290. 7:40:11working on the template so then we're
  9291. 7:40:13going to have additional div inside
  9292. 7:40:14which we're going to have form this is
  9293. 7:40:16going to be on the right side so the
  9294. 7:40:18vendor name on the left side using this
  9295. 7:40:20justifi between right here and that form
  9296. 7:40:23will be on the right side that form will
  9297. 7:40:26post on cart checkout page page which we
  9298. 7:40:30will create that road and then we're
  9299. 7:40:34going to have input type hidden with a
  9300. 7:40:36token this is CSF token uh which we just
  9301. 7:40:40passed from the handle inertia JS
  9302. 7:40:42request middle we then we're going to
  9303. 7:40:44have additional hidden input and this is
  9304. 7:40:46going to be for vendor ID so if we are
  9305. 7:40:49going to do check out only for this
  9306. 7:40:51vendor then we need the vendor ID as
  9307. 7:40:53well on the server site I'm going to
  9308. 7:40:55create this button button cost and pay
  9309. 7:40:58only for the this seller so whenever
  9310. 7:41:01user clicks on this the post request
  9311. 7:41:04will be made a traditional submission
  9312. 7:41:06will happen on this form with the token
  9313. 7:41:08with this um vendor ID and the back end
  9314. 7:41:11will handle the check out for that
  9315. 7:41:14specific
  9316. 7:41:16vendor there are a few things to make uh
  9317. 7:41:19and one of them is uh this credit credit
  9318. 7:41:22card icon for this we're going to
  9319. 7:41:23install hero icons react package and
  9320. 7:41:27again let's finish working on the
  9321. 7:41:29template and we will come back and do
  9322. 7:41:32the uh following thing so after this
  9323. 7:41:35form then down below we can start
  9324. 7:41:36iterating over the cart items let me
  9325. 7:41:38collapse this section so this was the uh
  9326. 7:41:41header kind of header uh which contains
  9327. 7:41:44the user information as well as the um
  9328. 7:41:47pay only for this seller button now we
  9329. 7:41:50iterate our cart items and we are going
  9330. 7:41:52to create new component cart item pass
  9331. 7:41:56the item itself and the uh key
  9332. 7:41:59after which we can focus on the right
  9333. 7:42:02side of this page where we're going to
  9334. 7:42:04have subtotal which is going to be total
  9335. 7:42:06quantity items we're going to have a
  9336. 7:42:09formatted currency with the total price
  9337. 7:42:12and we're going to have also form here
  9338. 7:42:14with the same action same method now we
  9339. 7:42:17need also csrf token and we need this
  9340. 7:42:20primary button right here which is going
  9341. 7:42:23to have proceed to checkout so we don't
  9342. 7:42:25have the vendor ID right here because
  9343. 7:42:27that proceed to checkout is for the
  9344. 7:42:29entire cart not only for a single
  9345. 7:42:33seller okay now we're going to install
  9346. 7:42:37uh hero icons
  9347. 7:42:40react let's click on this uh we can
  9348. 7:42:43click on the
  9349. 7:42:44npmjs I'm going to copy this open
  9350. 7:42:48Terminal and in a new terminal I'm going
  9351. 7:42:51to paste and hit the enter this is going
  9352. 7:42:53to install hero icons and while this is
  9353. 7:42:55being installed let's include import
  9354. 7:42:59those uh classes like grouped cart items
  9355. 7:43:03we're going to import this from
  9356. 7:43:05types awesome so we're going to import
  9357. 7:43:08this authenticated
  9358. 7:43:11layout cool we are going it is
  9359. 7:43:15indexing it was not able to
  9360. 7:43:23import now it was imported we imported
  9361. 7:43:27head as well group cart items is this
  9362. 7:43:32something grouped cart item okay so I
  9363. 7:43:35call this item but actually it's items
  9364. 7:43:37it is not single item so let's give it
  9365. 7:43:40items as
  9366. 7:43:41well okay scroll down below so we are
  9367. 7:43:44going to create that cart item and let
  9368. 7:43:46me do this right now under resources JS
  9369. 7:43:50components app let's create new
  9370. 7:43:54typescript file cart item
  9371. 7:44:00let's define the component remove this
  9372. 7:44:02react remove this props remove this
  9373. 7:44:05template we're going to work work on
  9374. 7:44:07this component in a moment scroll down
  9375. 7:44:11below we're going to import this
  9376. 7:44:12currency
  9377. 7:44:13format we're going to import this
  9378. 7:44:16primary
  9379. 7:44:17button and we're going to import this
  9380. 7:44:19credit card icon and I'm going to import
  9381. 7:44:22this from outline
  9382. 7:44:26version let's see that was imported as
  9383. 7:44:28well okay and now we have few things
  9384. 7:44:30first is card
  9385. 7:44:33item
  9386. 7:44:34[Music]
  9387. 7:44:36and I guess that is all what's
  9388. 7:44:44this yeah I think that is missing here
  9389. 7:44:48okay
  9390. 7:44:50cool let me actually um do the following
  9391. 7:44:54so I want to display um each item so let
  9392. 7:45:00me use Json
  9393. 7:45:04stringify uh hold on so I'm going to cut
  9394. 7:45:08this and now here let's use Json
  9395. 7:45:14stringify item undefined
  9396. 7:45:18to now let's have a look on the
  9397. 7:45:22page view
  9398. 7:45:25cart let's see I think we had a 500 eror
  9399. 7:45:29there let's click on this view
  9400. 7:45:36cart okay let's try to access SL
  9401. 7:45:39card and have a
  9402. 7:45:45look
  9403. 7:45:46okay maybe this
  9404. 7:45:49server let's let's restart mpm
  9405. 7:45:53randev and have a look refresh the page
  9406. 7:45:57here we have that JS page PES cart
  9407. 7:45:59wasn't found maybe that was causing the
  9408. 7:46:02issue Pages cart index JS Pages cart
  9409. 7:46:06index okay what's going on let's open
  9410. 7:46:09card controller in your sh render cart
  9411. 7:46:13index provide the cart items okay
  9412. 7:46:20cool Pages cart index
  9413. 7:46:30let's check
  9414. 7:46:31Roots we have some stupid issue on
  9415. 7:46:36cart we render this index
  9416. 7:46:41method okay um I have
  9417. 7:46:44a doubt that the issue might be
  9418. 7:46:48inside uh the following area we have
  9419. 7:46:51this handle injs requests where we use
  9420. 7:46:54also cart items right here as a page
  9421. 7:46:56prop and we are passing cart items as a
  9422. 7:46:59page propriate here maybe it conflicts
  9423. 7:47:02to each other so because this is kind of
  9424. 7:47:06um this inside the sandal iner JS
  9425. 7:47:09request is for the header drop down cart
  9426. 7:47:11dropdown data it's a something like mini
  9427. 7:47:14cart I'm going to call this mini mini
  9428. 7:47:18cart items in which case we have to
  9429. 7:47:21open mini cart
  9430. 7:47:24dropdown and we have to instead of cart
  9431. 7:47:27items we're going to accept mini cart
  9432. 7:47:30items um and we're going to iterate over
  9433. 7:47:33mini cart items here and here however
  9434. 7:47:37we're going to open the types and inside
  9435. 7:47:41the page
  9436. 7:47:44props let's find page props and we are
  9437. 7:47:49going to also change this into mini card
  9438. 7:47:56items okay the is gone let's refresh the
  9439. 7:48:02page okay it seems like it is not the
  9440. 7:48:13reason okay I'm going to stop the
  9441. 7:48:15V let's have a
  9442. 7:48:19look
  9443. 7:48:23mpm maybe I created this in a wrong
  9444. 7:48:27place pages
  9445. 7:48:31okay where's this index that's the issue
  9446. 7:48:33I created this index somewhere in a
  9447. 7:48:35stupid place under JS directly that
  9448. 7:48:38should be under Pages that's my
  9449. 7:48:42bad that's that's causing the
  9450. 7:48:46issue yeah the link needs to be also
  9451. 7:48:52imported cool now all errors are gone uh
  9452. 7:48:56we can execute mpm run de again a little
  9453. 7:48:59bit of debugging and now if we refresh
  9454. 7:49:02the
  9455. 7:49:04page we are going to say something
  9456. 7:49:11hopefully
  9457. 7:49:17oops okay now we have a different error
  9458. 7:49:20inside here card checkout is not in the
  9459. 7:49:23root list okay that's logical error so
  9460. 7:49:25we're going to go into our PHP and we're
  9461. 7:49:27going to Define this card check out
  9462. 7:49:29however cart checkout is only for
  9463. 7:49:32authenticated users it is not going to
  9464. 7:49:35be for um for guest
  9465. 7:49:39users okay so far we defined the roots
  9466. 7:49:41for guest users let's give it a comment
  9467. 7:49:44guest
  9468. 7:49:46roads then these are for uh out roads
  9469. 7:49:50and inside out I want to Define another
  9470. 7:49:54middle we which should be verified
  9471. 7:49:58middle wear
  9472. 7:50:00okay the user needs to be authenticated
  9473. 7:50:02as well as verified after which we can
  9474. 7:50:05Define
  9475. 7:50:06root post cart SL checkout we use cart
  9476. 7:50:12controller checkout method and the name
  9477. 7:50:15of the route is also card checkout we
  9478. 7:50:17have to create that checkout method
  9479. 7:50:19inside the card controller so I'm going
  9480. 7:50:20to create blank method at the moment
  9481. 7:50:24refresh the page we see something
  9482. 7:50:27already we we have another issue right
  9483. 7:50:29here each child in the list I think uh
  9484. 7:50:33this is coming from where we have
  9485. 7:50:39this
  9486. 7:50:43um no this is coming from
  9487. 7:50:46here we generally need to follow the
  9488. 7:50:49errors so cart item cart item. user. ID
  9489. 7:50:55is coming from here instead of cart item
  9490. 7:50:57user ID we should use cart item id
  9491. 7:51:01here shouldn't
  9492. 7:51:06we hold on wait
  9493. 7:51:10so no we should use cart
  9494. 7:51:14item user ID because that is outer loop
  9495. 7:51:18and we are
  9496. 7:51:20iterating over the users and then we
  9497. 7:51:23have this pay only for the seller so
  9498. 7:51:26what's the issue right here we have the
  9499. 7:51:27key L added to this it should not be any
  9500. 7:51:37problem okay um I have a question what
  9501. 7:51:40is this why it is not unique so let's
  9502. 7:51:43print out the entire cart item user
  9503. 7:51:47using Json
  9504. 7:51:48stringify uh cart item
  9505. 7:51:52user entire cart item no let's print
  9506. 7:51:55cart item user
  9507. 7:51:58we see we have the user has ID and
  9508. 7:52:01name so if I use cart item user ID
  9509. 7:52:05what's the
  9510. 7:52:08issue I think there is no
  9511. 7:52:14issue so I'm not quite sure about this
  9512. 7:52:17so I will come back to this and um fix
  9513. 7:52:20that but right now what I was interested
  9514. 7:52:22is uh the following area
  9515. 7:52:26where we have
  9516. 7:52:30have yeah let me use the pre-ex here
  9517. 7:52:33where we have this entire uh product so
  9518. 7:52:36we have the information about the cart
  9519. 7:52:38item this is the ID this is the product
  9520. 7:52:40title slug price quantity option IDs
  9521. 7:52:43okay awesome and options as well and
  9522. 7:52:46option uh we have the image as well
  9523. 7:52:49which is going to be taken either from
  9524. 7:52:51the option or from the um product itself
  9525. 7:52:58okay so let's return right here the
  9526. 7:53:02component cart item and I think we can
  9527. 7:53:04work on the cart item component uh but
  9528. 7:53:07let me import that cart item as well
  9529. 7:53:10which was done now inside this cart item
  9530. 7:53:14first I'm going to import the classes
  9531. 7:53:16what I need right here so I will need
  9532. 7:53:19react and user State I will need link
  9533. 7:53:23router and use form from Ina JS react I
  9534. 7:53:27will need cart item type as well but
  9535. 7:53:30because our function is called the same
  9536. 7:53:32name as the type what we have defined
  9537. 7:53:34inside types I'm going to import this
  9538. 7:53:36with a different name card item type so
  9539. 7:53:39then we're going to need text input here
  9540. 7:53:42uh we're going to need currency format
  9541. 7:53:45as well and I'm going to create Now
  9542. 7:53:48product root I'm going to do this inside
  9543. 7:53:51helpers and I'm going to import that as
  9544. 7:53:54well and I will explain why I create
  9545. 7:53:57this product
  9546. 7:53:59product
  9547. 7:54:01root uh function and this is going to be
  9548. 7:54:05to generate the root for the product
  9549. 7:54:08cart
  9550. 7:54:10item okay we can import this cart item
  9551. 7:54:14from from
  9552. 7:54:16types and now this is what we are going
  9553. 7:54:18to do so I'm going to generate create
  9554. 7:54:20params which is going to be new URL
  9555. 7:54:23search params however I'm not going to
  9556. 7:54:26provide anything inside the search I'm
  9557. 7:54:28going to
  9558. 7:54:29construct these params based on the
  9559. 7:54:33item item option uh
  9560. 7:54:37IDs so then um we have this item which
  9561. 7:54:41has option IDs right and that option IDs
  9562. 7:54:44if we have a look is the object where
  9563. 7:54:46the key inside this object is the type
  9564. 7:54:48ID and the value inside this object is
  9565. 7:54:51the option ID so what we want is
  9566. 7:54:55call
  9567. 7:54:56object um and entries right here which
  9568. 7:55:01returns array entries so then I'm going
  9569. 7:55:04to iterate over this and for each we get
  9570. 7:55:08the key value and we can call this um ID
  9571. 7:55:12or we can call this type ID and this is
  9572. 7:55:14going to be option ID okay if you don't
  9573. 7:55:17know how object entries Works basically
  9574. 7:55:19you need to find out this um okay so we
  9575. 7:55:23have parms we have a pend
  9576. 7:55:31uh sorry what I'm doing here I'm doing
  9577. 7:55:33something
  9578. 7:55:35stupid then right here we're going to
  9579. 7:55:41do so basically uh we know that speaking
  9580. 7:55:45about the product Details page if we go
  9581. 7:55:48on the
  9582. 7:55:50homepage if it works yeah when we click
  9583. 7:55:53on this we open the product Details page
  9584. 7:55:55and when we change the variations this
  9585. 7:55:57is what we saw so we are updating the
  9586. 7:55:59URL right here with options where the
  9587. 7:56:02key of the option is type ID and the
  9588. 7:56:05value is the actual option ID so I want
  9589. 7:56:08to generate URL similar to this because
  9590. 7:56:12if I addit a product inside the card uh
  9591. 7:56:16I can do this right now I can add the
  9592. 7:56:18Green version inside the card refresh
  9593. 7:56:20the page um let's have a look now we see
  9594. 7:56:23two items okay and whenever I click the
  9595. 7:56:26second one I want want this to open that
  9596. 7:56:31specific URL considering the options as
  9597. 7:56:33well if I click right now on this it is
  9598. 7:56:35not going to append the URLs in the um
  9599. 7:56:39the options inside the URL this is
  9600. 7:56:41something we are going to also fix from
  9601. 7:56:43these mini card dropdown but yeah this
  9602. 7:56:48is what I'm actually trying to achieve
  9603. 7:56:50right
  9604. 7:56:50now okay cool uh we're going to come
  9605. 7:56:53back to these erors so next on pams I'm
  9606. 7:56:57going to call append I'm going to
  9607. 7:57:00provide options let's use btics uh
  9608. 7:57:04options and inside options for the given
  9609. 7:57:09type ID I'm going to put option
  9610. 7:57:15ID uh option ID but option ID actually
  9611. 7:57:19needs to be string and we have option ID
  9612. 7:57:21to be number so we have to cast this
  9613. 7:57:24into the string convert this into string
  9614. 7:57:27so once we generated those params right
  9615. 7:57:30here so we appended that information
  9616. 7:57:31inside the params then I'm going to
  9617. 7:57:34return
  9618. 7:57:36root product. show we provide item.
  9619. 7:57:42Slug and plus I want to provide params
  9620. 7:57:47to string those Q prams now I'm going to
  9621. 7:57:50use this product rout inside cart item
  9622. 7:57:54so I'm going to import this product rout
  9623. 7:57:56here now let's define the prop which is
  9624. 7:57:58going to be item type of cart item type
  9625. 7:58:02and next I'm going to focus on the
  9626. 7:58:03template first and then create the
  9627. 7:58:05necessary uh react code right here so
  9628. 7:58:10I'm going to uh create this St with a
  9629. 7:58:13key on it which is going to be item id
  9630. 7:58:16then I'm going to create second d right
  9631. 7:58:18here which is going to be divider just
  9632. 7:58:20between multiple card items we're going
  9633. 7:58:21to have this divider then let's create
  9634. 7:58:24the link and this link is going to use
  9635. 7:58:27the product rout inside hre which will
  9636. 7:58:30generate the correct URL considering
  9637. 7:58:32options as well give it withth and hate
  9638. 7:58:35mean withd and minan heate as well and
  9639. 7:58:38inside there I'm just going to put image
  9640. 7:58:41okay so after this link we're going to
  9641. 7:58:43have um second div and the layout of the
  9642. 7:58:46cart items is going to be very much
  9643. 7:58:48similar to this what we have in the mini
  9644. 7:58:50cart items just a image will be a little
  9645. 7:58:52bit larger and there will be additional
  9646. 7:58:54information so I create this div inside
  9647. 7:58:56there we have another div H3 we're going
  9648. 7:58:59to display the product title uh and
  9649. 7:59:02we're going to also use this product
  9650. 7:59:03rule to generate the correct um rout
  9651. 7:59:07then we're going to have additional div
  9652. 7:59:09and inside which I want to display the
  9653. 7:59:12options so I'm just going to have this
  9654. 7:59:14pre right here just in case I need to
  9655. 7:59:15uncomment and see what's the value
  9656. 7:59:17inside item if we have any error so then
  9657. 7:59:20we're going to iterate over item
  9658. 7:59:22options okay we know each item has
  9659. 7:59:25options and options is actually array if
  9660. 7:59:28we check index if we see card item we
  9661. 7:59:31see options and each option is array of
  9662. 7:59:33the following type all right so here I'm
  9663. 7:59:36going to iterate over options uh and I'm
  9664. 7:59:38going to render the option type
  9665. 7:59:41name which we have right here option
  9666. 7:59:44type name and we're going to also
  9667. 7:59:46generate option name so this is what we
  9668. 7:59:49display like color black um second for
  9669. 7:59:53second option size small and so on so
  9670. 7:59:57after this and that ends right here
  9671. 8:00:01after this we're going to create one
  9672. 8:00:03more div and that's going to hold the
  9673. 8:00:05information about quantity that's going
  9674. 8:00:07to be down below uh about quantity and
  9675. 8:00:11we're going to also display the error
  9676. 8:00:13just in case we try to use a larger m
  9677. 8:00:18number of quantity than it is actually
  9678. 8:00:21available so here I'm using this daui
  9679. 8:00:24tool tip component uh we can have a look
  9680. 8:00:27also in the mentation of this
  9681. 8:00:29information and if error exists we add
  9682. 8:00:31those CSS classes and we also add this
  9683. 8:00:33data tap error and inside here we have
  9684. 8:00:36this text input which is going to be the
  9685. 8:00:38quantity text input and we are going to
  9686. 8:00:41listen to its PL event to trigger this
  9687. 8:00:44handle quantity change function which
  9688. 8:00:45we're going to create in a moment after
  9689. 8:00:49this we're going to have uh two buttons
  9690. 8:00:51one is going to be to delete the
  9691. 8:00:54item okay and second is going to uh save
  9692. 8:00:58that cart item for later usage and save
  9693. 8:01:01for later is something I'm not going to
  9694. 8:01:03implement right now I will Implement a
  9695. 8:01:05little bit later but we're going to do
  9696. 8:01:06this delete of course okay now let's
  9697. 8:01:09focus on the react side and we have this
  9698. 8:01:14delete form right here uh we have to
  9699. 8:01:17Define this delete form with option IDs
  9700. 8:01:19and that option IDs will be the item
  9701. 8:01:21option IDs okay then we're going to
  9702. 8:01:24Define state for error I'm going to
  9703. 8:01:26Define on delete click as well where I'm
  9704. 8:01:30going to send the delete request on this
  9705. 8:01:32delete form uh with the following URL
  9706. 8:01:36providing the uh correct product ID in
  9707. 8:01:38the URL and preserve scroll is going to
  9708. 8:01:40be always true so that per will perform
  9709. 8:01:43the delete and let's create the second
  9710. 8:01:45function handle quantity change we
  9711. 8:01:48accept right here HTML in event for HTML
  9712. 8:01:51input element uh we're going to set the
  9713. 8:01:55error to be an empty string so if we
  9714. 8:01:57have some error on the quantity because
  9715. 8:01:58of the quantity when we change the
  9716. 8:02:00quantity we want to disable this error
  9717. 8:02:02just uh hide this error then we send the
  9718. 8:02:06update request on the following route we
  9719. 8:02:10provide the quantity and we provide the
  9720. 8:02:12option IDs and the the question um I
  9721. 8:02:17would have if I were you is that why I
  9722. 8:02:21am
  9723. 8:02:22using right here delete form and why I'm
  9724. 8:02:27using
  9725. 8:02:28a rotor put right here and this is the
  9726. 8:02:32answer basically because we're going to
  9727. 8:02:35immediately send the request inside
  9728. 8:02:39handle quantity change so if we we about
  9729. 8:02:43to add right here quantity for example
  9730. 8:02:47if we we could name this form right just
  9731. 8:02:50form uh then right here it would be form
  9732. 8:02:53delete then we have the option ID is
  9733. 8:02:56here additionally we could add quantity
  9734. 8:02:59here and for delete it's going to work
  9735. 8:03:01in the same way but for update we tried
  9736. 8:03:03to send form. put providing this cart
  9737. 8:03:08update but the thing is that whenever
  9738. 8:03:11the quantity is changed we have to set
  9739. 8:03:13that quantity inside form data right and
  9740. 8:03:17we're going to do this form that form
  9741. 8:03:20dot set data and the set set data is a
  9742. 8:03:25synchronous operation so if we call set
  9743. 8:03:28data right here and then call form. put
  9744. 8:03:31form will still have old quantity it is
  9745. 8:03:35not going to have new quantity okay
  9746. 8:03:38either we have to come up some um
  9747. 8:03:40solutions to uh listen to when the form
  9748. 8:03:43data is actually updated and then send
  9749. 8:03:45the request or we can simply use router
  9750. 8:03:48put in this case this is um easier to
  9751. 8:03:53do okay after this we're going to add
  9752. 8:03:55the third argument which is going to be
  9753. 8:03:58um The Preserve scroll the the options
  9754. 8:04:00basically of the request preserve scroll
  9755. 8:04:03true and we're going to listen on error
  9756. 8:04:04as well if we get some error we're going
  9757. 8:04:06to get the first error and put this
  9758. 8:04:08inside the state hazer and the error
  9759. 8:04:11will be
  9760. 8:04:12displayed okay so after this I'm going
  9761. 8:04:14to display this currency format
  9762. 8:04:18information okay and I think we are done
  9763. 8:04:21so the currency uh information will be
  9764. 8:04:23item price Multiplied on item quantity
  9765. 8:04:26yeah I think we are done we don't need
  9766. 8:04:28anything else let's go into
  9767. 8:04:31index uh I think we don't have any error
  9768. 8:04:35here as well and I'm going to click on
  9769. 8:04:37this view
  9770. 8:04:39cart okay it looks like it is rendered
  9771. 8:04:41nicely as we expect so look at this so
  9772. 8:04:44we
  9773. 8:04:45have um let's close this so we have the
  9774. 8:04:49left side where we have the shopping
  9775. 8:04:50cart items we have the vender store name
  9776. 8:04:52we have the button pay only for this
  9777. 8:04:54seller we have this proess check out
  9778. 8:04:57everything and we have have the product
  9779. 8:04:58information clicking on which should
  9780. 8:05:01open the product Details page but for
  9781. 8:05:04the following variation the variation is
  9782. 8:05:07color green size small in this case here
  9783. 8:05:10we have color black size small as well
  9784. 8:05:13so click on this green now we see color
  9785. 8:05:16green size small that's awesome now
  9786. 8:05:19let's add color green size large into
  9787. 8:05:22the card we see fourth item click on
  9788. 8:05:25this now we see color color green size
  9789. 8:05:28small and color green size large here as
  9790. 8:05:31well and clicking on this opens now
  9791. 8:05:34color green size large and that is
  9792. 8:05:38absolutely
  9793. 8:05:40amazing
  9794. 8:05:42so I think we're good so this is also
  9795. 8:05:45works black and small um now let's try
  9796. 8:05:48to delete something from the cart
  9797. 8:05:50because we have the back end
  9798. 8:05:52ready and it should actually work let's
  9799. 8:05:54click on delete here this is gone it was
  9800. 8:05:57removed refresh the
  9801. 8:05:59page it stays removed we see we have
  9802. 8:06:02totally three items 65 is the total and
  9803. 8:06:05we can start increasing that click on
  9804. 8:06:08outside it will trigger the on blar
  9805. 8:06:11event and that was updated that was
  9806. 8:06:13updated now totally we have eight items
  9807. 8:06:16we can increase this as well we have
  9808. 8:06:20totally 13 items and this is the total
  9809. 8:06:22price and that
  9810. 8:06:24is actually how I want
  9811. 8:06:29it okay the error what we see on the
  9812. 8:06:32product Details page is coming from
  9813. 8:06:34Carousel the following error the final
  9814. 8:06:37argument passed to use effect changed
  9815. 8:06:40size between renders the order and the
  9816. 8:06:42size of this array must remain constant
  9817. 8:06:44and this happens because if we check
  9818. 8:06:48Carousel item so I did a small resarch
  9819. 8:06:51it was actually quite easy to find that
  9820. 8:06:53information so right here I need to
  9821. 8:06:55provide that images inside array
  9822. 8:06:58that was it so uh yeah the size of the
  9823. 8:07:02images were changed but here we just
  9824. 8:07:05need one element and that must be images
  9825. 8:07:08and then use effect starts watching on
  9826. 8:07:10images I refresh the
  9827. 8:07:13page the error is gone let's have a look
  9828. 8:07:19uh we have to use this uh root um
  9829. 8:07:22product route inside mini card drop down
  9830. 8:07:25so let's go into mini card drop down
  9831. 8:07:28and find this product show and here I'm
  9832. 8:07:31going to use um product root
  9833. 8:07:36providing not product but um item right
  9834. 8:07:40it is card item just like this and we
  9835. 8:07:44have this on second place as well
  9836. 8:07:47product root
  9837. 8:07:49item let me search inside entire project
  9838. 8:07:53where we have product show again so we
  9839. 8:07:57have it here that is the product item
  9840. 8:08:01itself but for the product item we can
  9841. 8:08:04leave it because for the product item we
  9842. 8:08:06don't have that
  9843. 8:08:10options yeah I think we can leave that
  9844. 8:08:13least for
  9845. 8:08:15now okay
  9846. 8:08:18nice so we don't have any errors on the
  9847. 8:08:20product page we click on the cart view
  9848. 8:08:24cart we see the information looking
  9849. 8:08:26amazing
  9850. 8:08:29and I think the next part is to start
  9851. 8:08:31working on the checkout before I start
  9852. 8:08:34working on checkout there are a few
  9853. 8:08:37additional things to prepare and to
  9854. 8:08:39implement and one of them is to test add
  9855. 8:08:43to card functionality when the product
  9856. 8:08:45does not have any variations so what we
  9857. 8:08:48implemented so far in our card service
  9858. 8:08:51um which I'm going to just give you an
  9859. 8:08:53overview is only for the cases when
  9860. 8:08:57product has multiple V variations and
  9861. 8:08:59generally this is what I recommend if
  9862. 8:09:01you want to implement some functionality
  9863. 8:09:04which should adapt many different adapt
  9864. 8:09:06many different cases just choose one
  9865. 8:09:09case and Implement your functionality on
  9866. 8:09:11this case test it make sure it works
  9867. 8:09:13well then you can introduce a second
  9868. 8:09:16case and test your own code on this
  9869. 8:09:19second case and you will probably find
  9870. 8:09:22some bucks then you're going to fix
  9871. 8:09:24those bugs uh add additional conditions
  9872. 8:09:27into to your code and so on okay this is
  9873. 8:09:29exactly what we're going to do so far we
  9874. 8:09:31implemented this only for product
  9875. 8:09:33variations but if the product doesn't
  9876. 8:09:35have variation it will probably fail so
  9877. 8:09:38what I did right now is created
  9878. 8:09:40registered second vendor vendor to@
  9879. 8:09:42example.com there's new user and I also
  9880. 8:09:45added model has roles and now this user
  9881. 8:09:48is able to access admin page of course
  9882. 8:09:50this new user doesn't have any kind of
  9883. 8:09:53uh products and this is what we're going
  9884. 8:09:55to do right now test
  9885. 8:09:58product item slug will be autogenerate
  9886. 8:10:01let's put this in
  9887. 8:10:03fashion choose any category some test
  9888. 8:10:06description we don't care these things
  9889. 8:10:09uh we can give it price 50 we can leave
  9890. 8:10:12the quantity I'm going to give it
  9891. 8:10:13published okay so we can give it also
  9892. 8:10:16quantity doesn't matter so let's click
  9893. 8:10:18on create the product is created it is
  9894. 8:10:20published now I'm going to duplicate
  9895. 8:10:23this one for the admin second for the
  9896. 8:10:25website and we're going to see that
  9897. 8:10:27product without images okay let's attach
  9898. 8:10:30an image as
  9899. 8:10:31well oops click on browse I'm going to
  9900. 8:10:35choose these three
  9901. 8:10:41images let's retry the fail
  9902. 8:10:44image okay cool click on Save refresh
  9903. 8:10:48the
  9904. 8:10:50page and we see now these two products
  9905. 8:10:52okay first product and test product item
  9906. 8:10:56uh why do I have this name okay anyway
  9907. 8:10:58so the first product has different
  9908. 8:11:00variations so there is additional bug
  9909. 8:11:02that right here we're displaying the
  9910. 8:11:03product image but when we go inside we
  9911. 8:11:06see the first variation image so if the
  9912. 8:11:09product has variations the product image
  9913. 8:11:11should not even be displayed and this is
  9914. 8:11:13additional thing we have to fix but let
  9915. 8:11:16me first focus on A2 card functionality
  9916. 8:11:18because uh and then check out flow
  9917. 8:11:21because that's is more exciting uh I
  9918. 8:11:23guess for you guys as well so uh here we
  9919. 8:11:27have the images are broken I think
  9920. 8:11:29probably because I restarted the PC and
  9921. 8:11:32we have to execute PHP Artisan uh
  9922. 8:11:37Q
  9923. 8:11:38listen so that it can start
  9924. 8:11:44processing okay I think it's going to do
  9925. 8:11:47this right now refresh the page okay and
  9926. 8:11:51we see those products now this product
  9927. 8:11:53doesn't have variation and I'm actually
  9928. 8:11:56also
  9929. 8:11:57um I will log out and just try to access
  9930. 8:12:02the product in this way so click it to
  9931. 8:12:04cart and now let's see what happens so
  9932. 8:12:06clicking at to cart doesn't do anything
  9933. 8:12:09we don't see the count increasing right
  9934. 8:12:11here okay that's probably because some
  9935. 8:12:14error is happening inside cart
  9936. 8:12:17service let's go into cart uh A2
  9937. 8:12:23cart and we're going to check what is
  9938. 8:12:25going on right here what happened and
  9939. 8:12:27why it is not added into the card and
  9940. 8:12:30because right now we are authent we are
  9941. 8:12:32not
  9942. 8:12:33authenticated the user should add the
  9943. 8:12:35products into cookies so this is the
  9944. 8:12:38place where items should be added okay
  9945. 8:12:42so let's see if code comes right here so
  9946. 8:12:45I'm going to dump right now let's dump
  9947. 8:12:48options let's dump quantity and
  9948. 8:12:54price click on add to cart we see one 50
  9949. 8:12:58and options is empty array okay now
  9950. 8:13:01let's click save item to cookies I guess
  9951. 8:13:04this is also added into the cookies
  9952. 8:13:06because there's nothing that is not
  9953. 8:13:08added into the cookies but I think the
  9954. 8:13:11problem is coming from Reading those
  9955. 8:13:13items so get cardart items here we have
  9956. 8:13:16the strike catch and probably in some
  9957. 8:13:19place it goes inside the catch and we
  9958. 8:13:21can see those errors inside ll. logo
  9959. 8:13:25file so if we SC scroll at the very
  9960. 8:13:28bottom then find the beginning of the
  9961. 8:13:30error attempt to read property store
  9962. 8:13:32name on null and this is coming
  9963. 8:13:36from from here okay uh and that's my bad
  9964. 8:13:41actually because when I created the user
  9965. 8:13:43with id4 I didn't create record inside
  9966. 8:13:46vendors which is
  9967. 8:13:48something um must must do so the status
  9968. 8:13:52is approved uh let's give it name
  9969. 8:13:55Zoomer and um I'm going to leave the
  9970. 8:13:58address let's give it created it
  9971. 8:14:01and the same to be updated yet okay I'm
  9972. 8:14:04going to make the record of that now
  9973. 8:14:08refresh the page items are added into
  9974. 8:14:11the cookie now we see 16 items right
  9975. 8:14:13here okay so it looks like adding those
  9976. 8:14:18um into the cart actually works fine so
  9977. 8:14:20now let's click on this view card and
  9978. 8:14:23we're going to see we don't have any
  9979. 8:14:24kind of variations uh so far far so good
  9980. 8:14:27now let's click on to decrease the
  9981. 8:14:30quantity which doesn't work okay so uh
  9982. 8:14:34we don't see the success message click
  9983. 8:14:37on this
  9984. 8:14:39again okay wa if I refresh the page
  9985. 8:14:43right
  9986. 8:14:44now okay it see it is kind of decreased
  9987. 8:14:48but we don't see the success message so
  9988. 8:14:50now let's open Dev tools and we're going
  9989. 8:14:52to see what's going on what request is
  9990. 8:14:54made so click on applic um the upper
  9991. 8:14:57Arrow
  9992. 8:15:01so okay we don't see any errors which is
  9993. 8:15:04good why don't we see success
  9994. 8:15:07message do we do we show the success
  9995. 8:15:09message at all I think we haven't
  9996. 8:15:11implemented success message right so if
  9997. 8:15:13I click this add to the
  9998. 8:15:15card yeah the count is increased but we
  9999. 8:15:18actually haven't implemented the success
  10000. 8:15:20message which we are going to
  10001. 8:15:23do until now we're going to test um add
  10002. 8:15:27to cart or remove from cart for this
  10003. 8:15:30user which doesn't have any kind of
  10004. 8:15:31variations so let's go into cart
  10005. 8:15:35controller and I'm curious what options
  10006. 8:15:40we're getting right here when storing
  10007. 8:15:42the item into the card or when updating
  10008. 8:15:44that from the card so let's see
  10009. 8:15:48inside options let's print options in
  10010. 8:15:52quantity when updating the
  10011. 8:15:55quantity okay okay so we see options is
  10012. 8:15:58empty array and quantity is actually
  10013. 8:16:02three okay it looks like everything to
  10014. 8:16:06be
  10015. 8:16:09correct however there's one thing so if
  10016. 8:16:13options is empty array then right here
  10017. 8:16:17we're constructing the following item
  10018. 8:16:20key when we perform the update and I
  10019. 8:16:23want to print that key as well which I
  10020. 8:16:26think can be op
  10021. 8:16:31optimized let's decrease the quantity
  10022. 8:16:34now this is the
  10023. 8:16:36key when options is actually
  10024. 8:16:40empty so what if the options is not
  10025. 8:16:44empty but it is null in some cases and
  10026. 8:16:46we provide this as null so on the front
  10027. 8:16:49end it looks like we are always
  10028. 8:16:51providing those
  10029. 8:16:52options let's decrease that have a look
  10030. 8:16:57now um I'm curious in the payload so in
  10031. 8:16:59the in the payload we always see option
  10032. 8:17:01ID so no matter if the current product
  10033. 8:17:05has variations or not we always provide
  10034. 8:17:07option IDs okay so maybe as an
  10035. 8:17:10additional precautious will be to add
  10036. 8:17:13right here fallback if for some reason
  10037. 8:17:15we received null uh on the front end
  10038. 8:17:18from the front end then we're going to
  10039. 8:17:20take empty array okay so if this is null
  10040. 8:17:24then we are in a trouble because right
  10041. 8:17:27here a lot of things will fail we are
  10042. 8:17:29taking these option IDs to be an array
  10043. 8:17:31right here then we are sorting that
  10044. 8:17:34we're then we're constructing this key
  10045. 8:17:36okay and it's going to fail it's going
  10046. 8:17:39to fail so we want to make sure that
  10047. 8:17:41option ID is is
  10048. 8:17:43array okay I'm going to remove this
  10049. 8:17:47part that is good uh on the update next
  10050. 8:17:50we're going to do this inside the store
  10051. 8:17:53so we have data option ities right here
  10052. 8:17:56but if if it is null then let's provide
  10053. 8:17:59empty array as
  10054. 8:18:00well and that might happen also when
  10055. 8:18:04adding item into the card from listing
  10056. 8:18:06like we might receive null now let's go
  10057. 8:18:09into product
  10058. 8:18:10listing
  10059. 8:18:12and click it to
  10060. 8:18:15card which we haven't implemented looks
  10061. 8:18:19like so let me open show T6 and find a
  10062. 8:18:26to card
  10063. 8:18:27part which does the following and now
  10064. 8:18:30let's open product
  10065. 8:18:33item product
  10066. 8:18:36item and we're going to find this add to
  10067. 8:18:39card and I'm going to click add on click
  10068. 8:18:42listener uh add to cart
  10069. 8:18:46here to add this from the listing then
  10070. 8:18:50let's define the function const it to
  10071. 8:18:53cart equals
  10072. 8:18:57this then we're going to define the
  10073. 8:19:00form let me copy this form from
  10074. 8:19:06here so we provide the option like this
  10075. 8:19:09we provide the quantity quantity will be
  10076. 8:19:12null if we are adding this from the
  10077. 8:19:14listing and price is
  10078. 8:19:18something uh I think we can provide
  10079. 8:19:20price as well so price in this case is
  10080. 8:19:22going to be product. price because uh we
  10081. 8:19:26are adding this from the listing um I
  10082. 8:19:32think yeah I think we can even skip the
  10083. 8:19:37price let's see it to cart we calculate
  10084. 8:19:40the price from options so I think we can
  10085. 8:19:42skip the
  10086. 8:19:45price let me remove the price
  10087. 8:19:48completely okay now let's test this
  10088. 8:19:50functionality from um listing product
  10089. 8:19:53listing click it to card the request is
  10090. 8:19:56made let's see we have now 18 items
  10091. 8:19:58let's click on this once again we see 19
  10092. 8:20:01items and it looks like it is working
  10093. 8:20:04perfectly so we are passing empty object
  10094. 8:20:07right
  10095. 8:20:08here but that's totally fine because
  10096. 8:20:11then inside A2
  10097. 8:20:13cart if we print that that converts into
  10098. 8:20:16empty
  10099. 8:20:18array as you see so this is
  10100. 8:20:22great now let's go into method get cart
  10101. 8:20:26items we select this from cookies from
  10102. 8:20:30database then right here we iterate over
  10103. 8:20:32cart items all right so we take then we
  10104. 8:20:36iterate the card item option IDs and now
  10105. 8:20:39this is what I want to print and have a
  10106. 8:20:41look what data this
  10107. 8:20:44contains let's refresh the page uh this
  10108. 8:20:47is for the first product which actually
  10109. 8:20:50is uh has variation so I want to check
  10110. 8:20:54this for the second product which
  10111. 8:20:56doesn't have any kind of variation so
  10112. 8:20:57I'm going to go into cart and I'm going
  10113. 8:20:59to remove delete this delete this as
  10114. 8:21:01well and now we have only one product
  10115. 8:21:03which doesn't have variations and let's
  10116. 8:21:05print the what this card item option ID
  10117. 8:21:08is I'm just trying make sure to avoid
  10118. 8:21:10any kind of bugs in the future so option
  10119. 8:21:13ID is empty array so iterating right
  10120. 8:21:15here will not happen at all and if the
  10121. 8:21:18iteration right here doesn't happen at
  10122. 8:21:20all
  10123. 8:21:22then option info will be actually
  10124. 8:21:26actually empty
  10125. 8:21:31right so if we print this cart item data
  10126. 8:21:36we are going to see one object inside
  10127. 8:21:37there we see option ID is empty options
  10128. 8:21:40empty the image is taken from the
  10129. 8:21:42product um and I think yeah everything
  10130. 8:21:45is good so if we have any kind of issues
  10131. 8:21:49then we probably need to come back to
  10132. 8:21:51these places and find out um what is
  10133. 8:21:55going on like this option ID is right
  10134. 8:21:57now is an array but if for some reason
  10135. 8:21:59that got null we have to fix that and we
  10136. 8:22:02make sure that uh it needs to be an
  10137. 8:22:07array now inside card service method I
  10138. 8:22:10want to card service uh class I want to
  10139. 8:22:13add a new method which will move the
  10140. 8:22:15cart items from cookies into the
  10141. 8:22:17database and we're going to do this on
  10142. 8:22:19authentication stage all right so let's
  10143. 8:22:22define the method move cart items to
  10144. 8:22:24database for the given user ID then
  10145. 8:22:26we're going to select the cart items
  10146. 8:22:28from cookies then we're going to iterate
  10147. 8:22:31th those cart items and we're going to
  10148. 8:22:34select if the cart item already exists
  10149. 8:22:37in the database so we might have
  10150. 8:22:39something in the cookie but the same
  10151. 8:22:41product might also be existed in the
  10152. 8:22:44database and we're going to find those
  10153. 8:22:46cart items for the specific user with
  10154. 8:22:49the product ID and the variation type
  10155. 8:22:52option IDs okay that creates the unique
  10156. 8:22:55product right so we select the first and
  10157. 8:22:57then we check if the item already exists
  10158. 8:23:00we're going to update the existing item
  10159. 8:23:02quantity and let's update the price as
  10160. 8:23:04well in the database however if the
  10161. 8:23:06existing item does not exist we're going
  10162. 8:23:08to create new cart item with user
  10163. 8:23:10product quantity and price and variation
  10164. 8:23:13option IDs so we moved the items from
  10165. 8:23:16cart into the database and then we're
  10166. 8:23:19going to delete the cookie name from
  10167. 8:23:21cookies basically we remove them from
  10168. 8:23:23the
  10169. 8:23:24cookies now we're going to open
  10170. 8:23:26authenticated session controller and we
  10171. 8:23:29when we perform this authentication we
  10172. 8:23:31are going to move the cart items into
  10173. 8:23:33the database and I'm going to do this in
  10174. 8:23:35two places so this is the place where
  10175. 8:23:37the authentication happens let me accept
  10176. 8:23:40right here cart
  10177. 8:23:42service card service and even though
  10178. 8:23:45this is for admin and vendor potentially
  10179. 8:23:48admin and vendor users might also be a
  10180. 8:23:51regular buyers so we want to execute
  10181. 8:23:54this card service move items into the
  10182. 8:23:57database for this as well providing user
  10183. 8:24:00ID and we want to do something similar
  10184. 8:24:03right here for a regular user okay I
  10185. 8:24:07save this let's refresh the page
  10186. 8:24:11now we see those cart items we have six
  10187. 8:24:14cart items and now let me try to
  10188. 8:24:16authenticate with a regular
  10189. 8:24:21user okay and now we have this error the
  10190. 8:24:23first error array to string conversion
  10191. 8:24:26right here into card
  10192. 8:24:29items variation type option IDs and
  10193. 8:24:34where is this coming from I'm going to
  10194. 8:24:36close the right side and where is this
  10195. 8:24:39coming from we're going to find our code
  10196. 8:24:42which is not uh perfectly highlighted
  10197. 8:24:45here that should probably come from card
  10198. 8:24:49service this is it okay so the problem
  10199. 8:24:53is right here it looks like this is
  10200. 8:24:56array and we are
  10201. 8:25:00trying array to string conversion yeah
  10202. 8:25:03we're trying to convert this into string
  10203. 8:25:05okay this is what I'm going to do let's
  10204. 8:25:06go into cart service let's open this
  10205. 8:25:09cart item and I'm going to add right
  10206. 8:25:11here
  10207. 8:25:13casts uh the following column name
  10208. 8:25:17variation type option ID is I'm going to
  10209. 8:25:19provide that this is actually
  10210. 8:25:23array now let's see what happens am I
  10211. 8:25:25authentic at I think I am authenticated
  10212. 8:25:28and there's nothing in the database so
  10213. 8:25:31let's log out now we have the six items
  10214. 8:25:34still in cart now let me try to
  10215. 8:25:37authenticate
  10216. 8:25:39again and see what happens now we have
  10217. 8:25:41another error which is coming
  10218. 8:25:45from why this doesn't perfectly
  10219. 8:25:47highlight it card
  10220. 8:25:51service okay
  10221. 8:25:53count okay this looks like to be an
  10222. 8:25:57empty array and that causes the problem
  10223. 8:26:00what we what I was personally thinking
  10224. 8:26:03to be honest so if I find that
  10225. 8:26:06place not here not here not here this is
  10226. 8:26:09the place so the cart item option I is
  10227. 8:26:12is actually empty array so right
  10228. 8:26:16here oh actually null was given to it so
  10229. 8:26:20if we check in the database inside cart
  10230. 8:26:24items uh what what do we see so we see
  10231. 8:26:27variation type option IDE is to be an
  10232. 8:26:28empt array why null was given to it I'm
  10233. 8:26:31not sure now let's print what is this
  10234. 8:26:34inside card item option
  10235. 8:26:39IDs refresh the page it is null why it
  10236. 8:26:41is null I don't know but we're going to
  10237. 8:26:45find out so I'm selecting these card
  10238. 8:26:47items from the database let me actually
  10239. 8:26:49do this print the entire card items here
  10240. 8:26:54refresh it one item and option it this
  10241. 8:26:56is null let's check now the
  10242. 8:26:59database cart item variation type option
  10243. 8:27:02ID
  10244. 8:27:04this it doesn't
  10245. 8:27:07look
  10246. 8:27:10correct now this is it it has attributes
  10247. 8:27:14and we see that the variation type
  10248. 8:27:15option IDE is is empty
  10249. 8:27:19array but because we added that to be
  10250. 8:27:22array or maybe we should provide that to
  10251. 8:27:24be Json
  10252. 8:27:28let's
  10253. 8:27:31see
  10254. 8:27:33okay so right here uh let me just print
  10255. 8:27:36this cart item variation type option oh
  10256. 8:27:40my
  10257. 8:27:41bad that should be IDs in
  10258. 8:27:46plural that's my bad okay my mistake now
  10259. 8:27:50if I refresh it we're going to see
  10260. 8:27:52variation type option idas to be array
  10261. 8:27:55so I think we can return this into array
  10262. 8:27:57however Json also works um and we have
  10263. 8:28:00now this to be an array we go in the
  10264. 8:28:02card service go back previous place
  10265. 8:28:06where we have this um DD right here I'm
  10266. 8:28:10going to remove refresh
  10267. 8:28:15it and now the items were moved into the
  10268. 8:28:20database let's click on this view card
  10269. 8:28:22and I think now we can start working on
  10270. 8:28:24checkout to start working on the
  10271. 8:28:26checkout flow first we will need stripe
  10272. 8:28:29account go to stripe.com and create an
  10273. 8:28:32account right here if you already have
  10274. 8:28:34an account you might want to create add
  10275. 8:28:36new account from inside your interface
  10276. 8:28:39dashboard so I have couple of accounts
  10277. 8:28:41which I have used for testing but right
  10278. 8:28:43now I'm going to add create uh click on
  10279. 8:28:46this create new
  10280. 8:28:48account and let me call this laravel
  10281. 8:28:52react e-commerce tutorial
  10282. 8:28:57so I'm going to click on
  10283. 8:28:59create so once the account is created
  10284. 8:29:02make sure that you are in the test mode
  10285. 8:29:04okay so the account is created I
  10286. 8:29:06actually have two uh similar name
  10287. 8:29:08accounts L react Ecommerce which is what
  10288. 8:29:11I was testing on and this is LEL react
  10289. 8:29:14e-commerce tutorial which is a brand new
  10290. 8:29:16account which we're going to use for
  10291. 8:29:17this so make sure you are in the test
  10292. 8:29:20mode right here then we're going to copy
  10293. 8:29:23this secret and we're going to put this
  10294. 8:29:25inside projects en file so let me
  10295. 8:29:31open and scroll down below
  10296. 8:29:35and let me just find what I have named
  10297. 8:29:40so yeah I'm going to give it name stripe
  10298. 8:29:45key um sorry what did I
  10299. 8:29:49do reveal click on okay it was copied so
  10300. 8:29:53we have stripe key which is actually
  10301. 8:29:55publishable key which we I think don't
  10302. 8:29:57need but we need is stripe
  10303. 8:30:01secret so this is my stripe secret let
  10304. 8:30:05me copy this and I'm going to put this
  10305. 8:30:07also I of example as an example file and
  10306. 8:30:12not the file but the key okay um
  10307. 8:30:16secret key okay good so we have to also
  10308. 8:30:21install the stripe PHP package now let's
  10309. 8:30:25go into event destinations which is web
  10310. 8:30:28hooks which what we are going to
  10311. 8:30:30actually trigger okay create new event
  10312. 8:30:33destination and testing local
  10313. 8:30:35development this is what we're going to
  10314. 8:30:37do and we have to download the CLI for
  10315. 8:30:40the stripe so if you're windows we have
  10316. 8:30:42to download this as a EX file so I'm
  10317. 8:30:45going to click on this download CLI in a
  10318. 8:30:47new tab open that and we're going to
  10319. 8:30:50find the instruction how we're going to
  10320. 8:30:51set this up but I'm going to show you
  10321. 8:30:53very quickly so we're going to go into
  10322. 8:30:55your operating system and each of them
  10323. 8:30:57shows the
  10324. 8:30:59instructions um on Linux you have to
  10325. 8:31:02download unzip it and then you have to
  10326. 8:31:04you have the following comment on
  10327. 8:31:06Windows I'm going to click on this
  10328. 8:31:08download on
  10329. 8:31:09GitHub this opens it now we are going to
  10330. 8:31:13download the zip file for my operating
  10331. 8:31:16system which I actually have already
  10332. 8:31:19downloaded so I'm going to
  10333. 8:31:23open right now this is it so I
  10334. 8:31:27downloaded that and I have stripe XA
  10335. 8:31:30right here and then I can close this
  10336. 8:31:33GitHub then I have to start this and
  10337. 8:31:35first I have to execute stripe login
  10338. 8:31:39which I have also already done so let me
  10339. 8:31:41open now terminal in this location where
  10340. 8:31:44the stripe XA leaves okay and we have to
  10341. 8:31:49execute stripe XA login so you execute
  10342. 8:31:54this you have it's going to open in the
  10343. 8:31:56browser you have to accept this and then
  10344. 8:31:59you will be authenticated okay so once
  10345. 8:32:01you do this now we can already start
  10346. 8:32:04using this uh stripe
  10347. 8:32:07CLI uh for web Hooks and this is what we
  10348. 8:32:10are going to do so I can close this as
  10349. 8:32:13well I don't need this because the
  10350. 8:32:15download and login has already been done
  10351. 8:32:17and now we're going to listen uh to
  10352. 8:32:20stripe web hooks but actually I think we
  10353. 8:32:23have to install also stripe
  10354. 8:32:26PHP so um composer stripe
  10355. 8:32:30PHP let's click on
  10356. 8:32:34this I'm going to copy the following
  10357. 8:32:37command uh I'm going to collapse this
  10358. 8:32:40not close this because I will need this
  10359. 8:32:42uh to execute for web Hooks and let's
  10360. 8:32:46open PHP storm bring up the terminal and
  10361. 8:32:50I'm going to execute composer requir
  10362. 8:32:52strip
  10363. 8:32:53PHP um okay cool additionally I want to
  10364. 8:32:57also create two new tables one for
  10365. 8:33:00orders and second for order items so I'm
  10366. 8:33:03going to execute PHP artisan make
  10367. 8:33:08model order model with
  10368. 8:33:12migration let's hit the enter that was
  10369. 8:33:15created and I'm going to also create PHP
  10370. 8:33:18artisan make model order order item but
  10371. 8:33:23I'm going to uh skip the migration part
  10372. 8:33:25because I'm going to put the uh inside
  10373. 8:33:28the orders migration file the order
  10374. 8:33:30items itself okay so let's click on
  10375. 8:33:36enter the modu was created now let's
  10376. 8:33:39open create orders
  10377. 8:33:43table now let's add the necessary
  10378. 8:33:46columns on this table so we need order
  10379. 8:33:48total price we need the foring ID to the
  10380. 8:33:51user which is the buyer in this case we
  10381. 8:33:54need foring ID into the user which is
  10382. 8:33:56going to be vendor user ID so that is
  10383. 8:33:59the vendor information so we're going to
  10384. 8:34:01have status order their status and we're
  10385. 8:34:02going to have also stripe session ID I'm
  10386. 8:34:06going to also add few additional columns
  10387. 8:34:09which is going to be for some additional
  10388. 8:34:11calculated amounts information such as
  10389. 8:34:14we're going to have online payment
  10390. 8:34:16commission which is going to be stripe
  10391. 8:34:18commission but I gave this more abstract
  10392. 8:34:21name because if you decide to replace
  10393. 8:34:23stripe with something else this is going
  10394. 8:34:25to be online payment commission so we
  10395. 8:34:28will need also website commission the
  10396. 8:34:31platform commission also and we will
  10397. 8:34:34have the vendor subtotal so if the
  10398. 8:34:36vendor paid if the buyer paid for
  10399. 8:34:38example 100 some part will be online
  10400. 8:34:41payment commission some part will be
  10401. 8:34:43website commission and vendor subtotal
  10402. 8:34:45will be whatever will be commissions
  10403. 8:34:48subtracted into the total price okay now
  10404. 8:34:51I'm going to also create um payment
  10405. 8:34:54intent column where I'm going to save
  10406. 8:34:56the payment intent id coming from stripe
  10407. 8:35:00and I will show this to
  10408. 8:35:02you so I'm going to create order items
  10409. 8:35:04table with ID with the foring ID into
  10410. 8:35:06the orders with product ID with price
  10411. 8:35:10integer and uh V variation type option
  10412. 8:35:13ideas Json field and let's also uh add
  10413. 8:35:17this um inside down to drop these
  10414. 8:35:20tables now I'm going to also create uh
  10415. 8:35:24order state status enam PHP
  10416. 8:35:29artisan make enam order status ANM let's
  10417. 8:35:36hit the enter now let's open order
  10418. 8:35:39status
  10419. 8:35:41ANM let's give it string type and we're
  10420. 8:35:45going to have five um five cases so case
  10421. 8:35:50draft we're going to
  10422. 8:35:52have paid we are going to have have
  10423. 8:35:57shipped we're going to have
  10424. 8:36:00delivered and we're going to have
  10425. 8:36:04canell and let me assign correct strings
  10426. 8:36:07to
  10427. 8:36:10them of course you can add your desired
  10428. 8:36:14types
  10429. 8:36:16here now I'm going to also generate
  10430. 8:36:20public
  10431. 8:36:22static function labels
  10432. 8:36:25and I'm going to return an associative
  10433. 8:36:28array self
  10434. 8:36:30draft we need a value here for Value we
  10435. 8:36:35have right here for a draft we have
  10436. 8:36:37draft label and let's duplicate this and
  10437. 8:36:40we
  10438. 8:36:42have paid we have shipped we have
  10439. 8:36:47delivered and we have
  10440. 8:36:50cancelled so paid
  10441. 8:36:53here shipped here
  10442. 8:36:56delivered
  10443. 8:36:57here cancelled here okay now I'm going
  10444. 8:37:01to open card controller checkout method
  10445. 8:37:03and I'm going to implement this check
  10446. 8:37:05out method right here but before I do
  10447. 8:37:08this I'm going to also
  10448. 8:37:10open up PHP up PHP from config folder
  10449. 8:37:15config up PHP scroll at the very bottom
  10450. 8:37:18and I want to add
  10451. 8:37:21few values right here so I want to add
  10452. 8:37:23currency
  10453. 8:37:25string currency which is going to be
  10454. 8:37:28taken from I uh I'm going to call this
  10455. 8:37:31up currency the default one to be USD
  10456. 8:37:34I'm going to create that in a moment and
  10457. 8:37:36we're going to take uh
  10458. 8:37:38stripe secret key as well which we're
  10459. 8:37:42going to take from in and we call this
  10460. 8:37:45stripe secret okay now let's
  10461. 8:37:50open. and find currency here
  10462. 8:37:55currency we don't have currency here
  10463. 8:37:58so right here I'm going to add
  10464. 8:38:02up
  10465. 8:38:04currency which is going to be
  10466. 8:38:08USD and I'm going to add this inside in
  10467. 8:38:12of
  10468. 8:38:14example
  10469. 8:38:15up
  10470. 8:38:17currency USD okay so we have stripe
  10471. 8:38:20secret now I think we can take those
  10472. 8:38:23values inside checkout so let's go into
  10473. 8:38:25check out and first I'm going to uh
  10474. 8:38:28require request uh import use sorry use
  10475. 8:38:32these parameters request and card
  10476. 8:38:34service then I'm going to set the API
  10477. 8:38:37key inside the stripe which is going to
  10478. 8:38:39be the stripe secret key which will
  10479. 8:38:42generated then I'm going to take the
  10480. 8:38:44vendor ID from the request so if we are
  10481. 8:38:46doing checkout only for this specific
  10482. 8:38:48vendor this is how we are going to take
  10483. 8:38:51the V vendor information and then I'm
  10484. 8:38:53going to get the card items group by
  10485. 8:38:56vendor ID so we have all cart items
  10486. 8:38:58right here then I'm going to start the
  10487. 8:39:00transaction if something is failed I
  10488. 8:39:02want to roll back everything so I
  10489. 8:39:04started transaction I put everything
  10490. 8:39:05inside TR cat and then we're going to
  10491. 8:39:07start so check out cart items equals all
  10492. 8:39:10cart items and if the vendor ID exists
  10493. 8:39:15then we need to check out only the items
  10494. 8:39:18for the vendor so from all cart items I
  10495. 8:39:21am taking the items which belong to the
  10496. 8:39:24specific vendor
  10497. 8:39:26but because we need the format to be an
  10498. 8:39:29array
  10499. 8:39:30of uh vendor associative array so I'm
  10500. 8:39:33still putting this inside uh the array
  10501. 8:39:36so as an example if I open new scratch
  10502. 8:39:39file so cart items look like
  10503. 8:39:43this so we have the vendor ID and it's
  10504. 8:39:46corresponding some data we have second
  10505. 8:39:48vendor ID and is corresponding some data
  10506. 8:39:51so what I'm taking is data for the first
  10507. 8:39:54vendor like this but I am also putting
  10508. 8:39:58this inside associative array not
  10509. 8:40:01associative array but inside array okay
  10510. 8:40:04so in this specific case the checkout
  10511. 8:40:07card items right here is all cart items
  10512. 8:40:10which is associative array like this but
  10513. 8:40:13right here I'm just creating this
  10514. 8:40:16checkout cart items to be normal array
  10515. 8:40:18so it will be like let's put semicolon
  10516. 8:40:21here so card items will be like this so
  10517. 8:40:25if we are checking out the first vendor
  10518. 8:40:28data it will be like this but it doesn't
  10519. 8:40:30matter because we don't need keys we
  10520. 8:40:32don't need this information we only need
  10521. 8:40:34the
  10522. 8:40:35values so now I'm going to uh create
  10523. 8:40:38orders array and the line items array
  10524. 8:40:41the orders array is going to be my
  10525. 8:40:43eloquent moduls and line items for
  10526. 8:40:45stripe then we start iterating over
  10527. 8:40:48these checkout items and we need the
  10528. 8:40:49item information right here so we're
  10529. 8:40:52going to take the user and card it items
  10530. 8:40:55from the item so if we check this get
  10531. 8:40:58cart items grouped we see that each of
  10532. 8:41:00them has user and items and a couple of
  10533. 8:41:03other information as well okay after
  10534. 8:41:06this I'm going to create new order
  10535. 8:41:07providing stripe session ID provide user
  10536. 8:41:11ID provide vendor user ID provide total
  10537. 8:41:14price and Status we're going to import
  10538. 8:41:17all these classes um in a moment after
  10539. 8:41:20we finish writing this method okay so
  10540. 8:41:23then I'm going to put this order into
  10541. 8:41:24orders array and then I'm going to start
  10542. 8:41:26iterating over cart items and I'm going
  10543. 8:41:29to create order items models so
  10544. 8:41:32providing order ID product ID quantity
  10545. 8:41:35price and variation type option IDs all
  10546. 8:41:37of them taken from card item after which
  10547. 8:41:40we're going to create line item so
  10548. 8:41:42inside line item we need product data
  10549. 8:41:44inside product data we need currency and
  10550. 8:41:46we need product data so inside price
  10551. 8:41:48data we need currency and product data
  10552. 8:41:50so inside product data we need the title
  10553. 8:41:53of the product we need images as an
  10554. 8:41:55array so I'm taking the first image and
  10555. 8:41:58putting inside an array so then we need
  10556. 8:42:00unit amount but stripe wants unit
  10557. 8:42:02amounts inside uh cents so we're
  10558. 8:42:05providing uh right here multiplying this
  10559. 8:42:08into 100 so then we have the quantity as
  10560. 8:42:11well cart item quantity and finally
  10561. 8:42:13we're putting this line item inside line
  10562. 8:42:16items array but I want to also Define a
  10563. 8:42:20description and the description uh needs
  10564. 8:42:23to be the variations to give the user
  10565. 8:42:25information what variations they are
  10566. 8:42:26purchasing so we are collecting card
  10567. 8:42:29item options we're creating collection
  10568. 8:42:32out of this then mapping that data and
  10569. 8:42:35returning the cart item option each
  10570. 8:42:38option type name column in the item name
  10571. 8:42:43again if we go back into this method and
  10572. 8:42:46check what type of data is returned from
  10573. 8:42:48here inside items we're going to see
  10574. 8:42:50that each item right here has options
  10575. 8:42:54which is the option option information
  10576. 8:42:55and option information contains the type
  10577. 8:42:58name as well as the option name itself
  10578. 8:43:01okay this is what we are
  10579. 8:43:03taking if we scroll down below this is
  10580. 8:43:05what we are taking in the following
  10581. 8:43:07Place type name and option name and
  10582. 8:43:09finally because we have this map we're
  10583. 8:43:11converting oops we're converting this
  10584. 8:43:14we're imploding this uh with a comma so
  10585. 8:43:17we're converting this into string and
  10586. 8:43:19then we're going to provide description
  10587. 8:43:20right here if description exists then
  10588. 8:43:23inside line item price St data product
  10589. 8:43:26data we're putting the
  10590. 8:43:28description Okay cool so this is uh
  10591. 8:43:32related to iteration so we did the
  10592. 8:43:34iteration we created orders order items
  10593. 8:43:36line items and now we're going to create
  10594. 8:43:37stripe session we're providing the
  10595. 8:43:39customer email address line items the
  10596. 8:43:42mode is payment we're providing the
  10597. 8:43:44success URL and the success URL contains
  10598. 8:43:46the following session ID in the URL as
  10599. 8:43:49well we're providing the cancel URL as
  10600. 8:43:51well and we're going to create those
  10601. 8:43:53rules stripe success and stripe failure
  10602. 8:43:56we are going to create them in a moment
  10603. 8:43:58so then I'm iterating over my orders
  10604. 8:44:01which are just created orders and I'm
  10605. 8:44:03updating their stripe session ID to be
  10606. 8:44:06just generated stripe session ID after
  10607. 8:44:10which we're going to perform the
  10608. 8:44:11database Comet and redirect into the
  10609. 8:44:13session URL which will open the stripe
  10610. 8:44:16payments page and in case there is some
  10611. 8:44:18error we're going to log the error we're
  10612. 8:44:20going to roll back the transaction and
  10613. 8:44:22we're going to redirect user into PE
  10614. 8:44:25with some error that something has gone
  10615. 8:44:29wrong now let's import these classes so
  10616. 8:44:32DB we're going to import
  10617. 8:44:36log we are going to import order
  10618. 8:44:40item order status
  10619. 8:44:43enam and
  10620. 8:44:47order I think the request and card
  10621. 8:44:49service so the request and card service
  10622. 8:44:52needs to be imported as well uh uh
  10623. 8:44:55here's the card service which was
  10624. 8:44:58already imported in this okay so now we
  10625. 8:45:00have this checkout method ready and now
  10626. 8:45:04we're going to Define
  10627. 8:45:05Roots so for this let me open web.php
  10628. 8:45:10and the user needs to be authenticated
  10629. 8:45:13to perform uh checkout so we have the
  10630. 8:45:16checkout actually defined right here but
  10631. 8:45:19I'm going to create now stripe
  10632. 8:45:21controller PHP artisan make
  10633. 8:45:25controller uh let's call this stripe
  10634. 8:45:30controller and inside stripe controller
  10635. 8:45:32I want to Define three methods so one is
  10636. 8:45:37going to be
  10637. 8:45:40success second is going to be
  10638. 8:45:44failure and third is going to be web
  10639. 8:45:49hook and let's open now web.php and I'm
  10640. 8:45:53going to define those rules as well so
  10641. 8:45:55uh
  10642. 8:45:56root
  10643. 8:45:59get um stripe stripe SL success so this
  10644. 8:46:04is the first one we're going to use
  10645. 8:46:07stripe controller success let's move
  10646. 8:46:09this name down let's duplicate this and
  10647. 8:46:13second is going to be failure stripe
  10648. 8:46:17failure so we have these roots names
  10649. 8:46:19used inside the card controller so now
  10650. 8:46:22we make sure that we have those roots
  10651. 8:46:25defined and we have to Define web hook
  10652. 8:46:28as well however web hook needs to be uh
  10653. 8:46:32accessed um basically for guest users as
  10654. 8:46:35well
  10655. 8:46:37so right
  10656. 8:46:39here probably we have the guest Roots so
  10657. 8:46:42here inside root we're going to Define
  10658. 8:46:45post the web hook needs to be accessed
  10659. 8:46:47with a post method it cannot be accessed
  10660. 8:46:50with get and this is going to be stripe
  10661. 8:46:53SL web hook and we have to provide
  10662. 8:46:56stripe controller a web hook here and
  10663. 8:47:01let's move this Dr down stripe web hook
  10664. 8:47:04and I'm going to open now up. PHP but
  10665. 8:47:07from bootstrap folder where we have this
  10666. 8:47:11middle we defined and inside here inside
  10667. 8:47:15this middle wear I want to
  10668. 8:47:18execute except or
  10669. 8:47:23csrf validate csrf tokens and we are
  10670. 8:47:27going to provide accept right here so
  10671. 8:47:30this middle wear should work except the
  10672. 8:47:33following rules and I'm going to provide
  10673. 8:47:35right here pattern stripe SL asterisk so
  10674. 8:47:39csrf tokens will not be validated for
  10675. 8:47:42stripe URLs and that is necessary for
  10676. 8:47:45the following web hook stripe SL webook
  10677. 8:47:49because stripe will send that
  10678. 8:47:51information to us and we have to take
  10679. 8:47:53care of this now I'm going to open this
  10680. 8:47:56terminal and right here we have the
  10681. 8:47:58stripe x file so this is now what we are
  10682. 8:48:00going to
  10683. 8:48:01execute
  10684. 8:48:03stripe we need D- forward
  10685. 8:48:07D2 and we have to provide the local
  10686. 8:48:10address where the stripe web hooks need
  10687. 8:48:12to be forwarded so this we're going to
  10688. 8:48:17take from our application this is the
  10689. 8:48:20application and we need slash stripe
  10690. 8:48:24slash web hook this is the URL where all
  10691. 8:48:27stripe web hooks needs to be forwarded
  10692. 8:48:29we don't need protocol here let me open
  10693. 8:48:32this on full screen we're going to hit
  10694. 8:48:33the
  10695. 8:48:36enter uh stripe oh I missed the commment
  10696. 8:48:41stripe XA
  10697. 8:48:43listen now we have to
  10698. 8:48:49wait and now it generated this web hook
  10699. 8:48:52signing secret key so which we are going
  10700. 8:48:54to
  10701. 8:48:57copy and we are going to
  10702. 8:49:01open and right here I'm going to put
  10703. 8:49:04this so this is going to be
  10704. 8:49:06stripe uh web hook secret equals this
  10705. 8:49:12let's open em example and let's copy the
  10706. 8:49:16name of the key and some secret uh I
  10707. 8:49:21it's it's a good practice to put those
  10708. 8:49:22keys inside the en example as well
  10709. 8:49:25okay now we have the stripe web hook key
  10710. 8:49:27we we're going to take care of the web
  10711. 8:49:28hook but um let's see if the checkout
  10712. 8:49:32actually works and if the order is
  10713. 8:49:34actually created so let's open the
  10714. 8:49:38website refresh the
  10715. 8:49:41page just make sure it works okay now
  10716. 8:49:43I'm going to click on this proed to
  10717. 8:49:45check out and have a look it is thinking
  10718. 8:49:48okay something went wrong and we didn't
  10719. 8:49:50see this error message which is
  10720. 8:49:53something we're going to do
  10721. 8:49:55for this I'm going to open authenticated
  10722. 8:49:58layout and right here I'm going to
  10723. 8:50:01accept error message but we're going to
  10724. 8:50:03pass this error message from handle
  10725. 8:50:05inertial JS request just like we're
  10726. 8:50:07passing success we're going to pass
  10727. 8:50:10error let's do like this then we're
  10728. 8:50:13going to accept this error right here
  10729. 8:50:17let me accept error here we format the
  10730. 8:50:22code so we accept this error U page with
  10731. 8:50:26children okay so we have the header and
  10732. 8:50:29I guess we have
  10733. 8:50:32to actually I think we can take this
  10734. 8:50:35from use page props as well so let me
  10735. 8:50:38Define
  10736. 8:50:41this uh const props equals US
  10737. 8:50:45page. props okay I'm going to Define
  10738. 8:50:49this above then right here we can accept
  10739. 8:50:51this props out user so now this props
  10740. 8:50:55has this error information so maybe
  10741. 8:50:58right here before this header
  10742. 8:51:04um wait I think we don't need even this
  10743. 8:51:07header to I'm going to remove this
  10744. 8:51:10header okay uh and right here I'm going
  10745. 8:51:13to Define if props error exist we are
  10746. 8:51:17going to
  10747. 8:51:18Define div let's give it some classes
  10748. 8:51:21like um let's give it
  10749. 8:51:26container margin X Auto let's give it
  10750. 8:51:29pading X um eight and pting or margin
  10751. 8:51:35top
  10752. 8:51:37eight uh and inside
  10753. 8:51:46here what's going
  10754. 8:51:51on if props error
  10755. 8:52:00I don't see what is the issue
  10756. 8:52:11here okay so
  10757. 8:52:14um uh what mistake do I have
  10758. 8:52:27okay anyway let me let me just write
  10759. 8:52:30maybe uh PHP storm is kind of giving me
  10760. 8:52:33wrong error alert and
  10761. 8:52:36alert error and inside here we're going
  10762. 8:52:39to out put props eror let me save this
  10763. 8:52:42and have a look in the
  10764. 8:52:44browser open Dev tools as well refresh
  10765. 8:52:49it and click on this proed to check
  10766. 8:52:53out undefined array key total price okay
  10767. 8:52:57yeah definitely PHP storm is actually
  10768. 8:52:58complaining on something uh I'm not
  10769. 8:53:00quite sure let me execute mpm run build
  10770. 8:53:03as well mpm run
  10771. 8:53:06build let's
  10772. 8:53:11see I think the reason might be that
  10773. 8:53:14inside page props what we have inside
  10774. 8:53:18index DTS we
  10775. 8:53:20have we don't have that error defined
  10776. 8:53:23anywhere here that might be the thing so
  10777. 8:53:26let's define error to be string and we
  10778. 8:53:30can define success to be string as
  10779. 8:53:36well okay yeah the eror is gone so if we
  10780. 8:53:38execute right now mpm run build that
  10781. 8:53:42should perform the build
  10782. 8:53:48correctly okay cool now let's execute
  10783. 8:53:52mpm uh run Dev again and have a look in
  10784. 8:53:57this error total price and find array
  10785. 8:53:59key total price which is coming from the
  10786. 8:54:03card controller check out now let's see
  10787. 8:54:05where we have this total price we're
  10788. 8:54:07taking this from
  10789. 8:54:09item from each
  10790. 8:54:16item okay that
  10791. 8:54:18item uh is if we check right now card
  10792. 8:54:22service that item
  10793. 8:54:25is the result of this so this we should
  10794. 8:54:29take this in a camel case
  10795. 8:54:32notation let me dump the inside entire
  10796. 8:54:35item and we're going to see it click on
  10797. 8:54:39check out this is the entire item and it
  10798. 8:54:41has total price in camel case so we we
  10799. 8:54:43should have it like
  10800. 8:54:46this okay um we are not using I guess
  10801. 8:54:49this
  10802. 8:54:51item total price anywhere else so now
  10803. 8:54:55let's refresh the
  10804. 8:55:00page okay we haven't executed migration
  10805. 8:55:02to create um orders and Order items
  10806. 8:55:06table so let me execute PHP Artisan
  10807. 8:55:10migrate okay tables we are created now
  10808. 8:55:14we are on the card page click on this
  10809. 8:55:15proed to check out and hopefully we're
  10810. 8:55:17going to see stripe payments
  10811. 8:55:19page okay uh order items has no column
  10812. 8:55:23name updated it that's correct so we
  10813. 8:55:27have not given updated at column to
  10814. 8:55:29order items table so we open
  10815. 8:55:32order order item and we're going to
  10816. 8:55:36Define also fillable on this and on M on
  10817. 8:55:40um order table as well so let's define
  10818. 8:55:45fillable array we are uh we need order
  10819. 8:55:48ID product ID quantity price and we need
  10820. 8:55:53variation option type uh option
  10821. 8:55:57IDs option IDs okay I'm going to move
  10822. 8:56:02them like
  10823. 8:56:06this okay we need to Define uh relations
  10824. 8:56:09as well let's
  10825. 8:56:11define uh belongs to belongs to uh
  10826. 8:56:16belongs to
  10827. 8:56:19order order class now let's open
  10828. 8:56:24uh yeah we need to disable time stamps
  10829. 8:56:26as well so right here I'm going to
  10830. 8:56:28provide time stamps equals false now
  10831. 8:56:32we're going to open order model and
  10832. 8:56:35let's define avilable here and we
  10833. 8:56:40need stripe session ID we need user
  10834. 8:56:49ID user ID we need total price
  10835. 8:56:55and we need
  10836. 8:56:56status uh I'm going to actually move
  10837. 8:56:59them down as well like this and we can
  10838. 8:57:03add other columns here but I'm going to
  10839. 8:57:06implement updating these other columns
  10840. 8:57:08in a different way but just in case uh
  10841. 8:57:12we change something in the future we
  10842. 8:57:14don't have to worry about filling uh
  10843. 8:57:19putting those inside um fillable where's
  10844. 8:57:22the order model here is it okay okay so
  10845. 8:57:24we have those columns let's copy these
  10846. 8:57:27four additional columns and let's put
  10847. 8:57:31them right
  10848. 8:57:36here okay and now let's define also
  10849. 8:57:38relation here I'm going to actually
  10850. 8:57:40Define couple of relations uh like uh I
  10851. 8:57:43need as many into order
  10852. 8:57:48items for this we are using order item
  10853. 8:57:50class let's define also
  10854. 8:57:55belongs to belongs to
  10855. 8:57:59user and for this we need user
  10856. 8:58:03class but I want to also Define belongs
  10857. 8:58:06to
  10858. 8:58:08vendor vendor and in this case I'm going
  10859. 8:58:11to access into vendor class uh through
  10860. 8:58:17user ID foring key
  10861. 8:58:22so now actually this is is
  10862. 8:58:26vendor vendor user
  10863. 8:58:28ID uh
  10864. 8:58:30and then right here we have the owner
  10865. 8:58:33key is the user ID so order has vendor
  10866. 8:58:36user ID using which it relates
  10867. 8:58:41to the user ID however I'm going to
  10868. 8:58:44Define also vendor
  10869. 8:58:47user vendor user so we have the user and
  10870. 8:58:50that user is the buyer who uh
  10871. 8:58:54made this order and vendor user is the
  10872. 8:58:57user for which we made the um
  10873. 8:59:07order so here we need this vender user
  10874. 8:59:11ID okay now if we go into card
  10875. 8:59:16controller um I think we should be good
  10876. 8:59:20let's click on proed to check out what
  10877. 8:59:21other error do we have
  10878. 8:59:25okay array to string conversion okay so
  10879. 8:59:28we have to open order items again and we
  10880. 8:59:30have to create this casts for variation
  10881. 8:59:35type option IDs to be
  10882. 8:59:37array now let's click proceed to check
  10883. 8:59:41out and now we see that stripe payment
  10884. 8:59:45page was open of course the image is
  10885. 8:59:47broken because um we have the local
  10886. 8:59:50environment and we don't have the images
  10887. 8:59:53the it needs to be hosted basically
  10888. 8:59:55somewhere because stripe grabs those um
  10889. 8:59:57image URLs okay so we are in the test
  10890. 9:00:00mode we see total is uh 300 now let's
  10891. 9:00:03see inside orders what happens so we
  10892. 9:00:05have now one order for user one vendor
  10893. 9:00:08user ID four the order status is draft
  10894. 9:00:11because this is uh the initial order and
  10895. 9:00:13we see order items as well one order
  10896. 9:00:16item total quantity variation type
  10897. 9:00:18option like this okay everything looks
  10898. 9:00:20great and now when the payment is made
  10899. 9:00:23we are going to be redirected into the
  10900. 9:00:26success page and we have to take care of
  10901. 9:00:29these things so let me open now
  10902. 9:00:32resources JS pages and right here I'm
  10903. 9:00:36going to
  10904. 9:00:38create uh stripe SL
  10905. 9:00:41success
  10906. 9:00:44component uh like this let's remove this
  10907. 9:00:48props remove this and remove that as
  10908. 9:00:50well and I'm going to now start start
  10909. 9:00:54working
  10910. 9:00:55on um let's open stripe controller and
  10911. 9:00:59I'm going to implement this web hook
  10912. 9:01:01this is the most interesting
  10913. 9:01:05part okay so I'm going to use request
  10914. 9:01:08right here and make sure that the
  10915. 9:01:10request is also imported here so then
  10916. 9:01:13I'm going to create this stripe client
  10917. 9:01:15providing this stripe secret ID and I'm
  10918. 9:01:18going to also open
  10919. 9:01:21this config and I want to add second
  10920. 9:01:25which is going to be for stripe uh web
  10921. 9:01:27hook secret key let's call this
  10922. 9:01:30stripe
  10923. 9:01:32webhook
  10924. 9:01:34secret and let's take it from in stripe
  10925. 9:01:39web hook secret I think we gave it the
  10926. 9:01:43same name let's
  10927. 9:01:47open. stripe web hook
  10928. 9:01:50secret yeah we have that uh name defined
  10929. 9:01:53here okay great now let's open this
  10930. 9:01:58stripe controller and now I'm going to
  10931. 9:02:01create this endpoint secret which is
  10932. 9:02:03going to be what we just
  10933. 9:02:05created here next I'm going to get the
  10934. 9:02:09payload from the request I'm going to
  10935. 9:02:12take the stripe signature header and
  10936. 9:02:14then we're going to validate if the
  10937. 9:02:16payload is coming from the actual stripe
  10938. 9:02:19and it's not modified so we're going to
  10939. 9:02:22create the in event we're going to
  10940. 9:02:23create create the TR catch and we are
  10941. 9:02:25going to construct this event through
  10942. 9:02:28this payload with a signature header and
  10943. 9:02:30endpoint secret so this actually
  10944. 9:02:33performs the validation if the event is
  10945. 9:02:35created we are good if the event was not
  10946. 9:02:38created then uh it will throw an
  10947. 9:02:40exception and then we have to handle
  10948. 9:02:42those exceptions um unexpected value
  10949. 9:02:45exception we're going to print something
  10950. 9:02:47in the logs and invalid payload is going
  10951. 9:02:50to be the response with the status code
  10952. 9:02:52400 and we'll have the signature
  10953. 9:02:54verification exception we're going to
  10954. 9:02:56again print the error and invalid
  10955. 9:02:58payload is what we are going to return
  10956. 9:03:01okay so if the catch didn't happen and
  10957. 9:03:03event was created then down below we are
  10958. 9:03:06going to print that event with a type
  10959. 9:03:10and with um with event itself as well
  10960. 9:03:16okay so uh we just need to have a look I
  10961. 9:03:18I I want to explain few things so I want
  10962. 9:03:22to print them and just have a look so
  10963. 9:03:25now we are gonna uh check what is the
  10964. 9:03:28type of this event and we're going to
  10965. 9:03:31receive multiple types we're going to
  10966. 9:03:33receive four or five events um for
  10967. 9:03:37single payment and we have to take here
  10968. 9:03:39of only two we we need charge updated
  10969. 9:03:42and uh checkout session completed
  10970. 9:03:45checkout session is completed when
  10971. 9:03:46everything was completed and we know
  10972. 9:03:49that the uh payment was completed but we
  10973. 9:03:52have also charge updated which happens a
  10974. 9:03:55little bit later and charge updated
  10975. 9:03:58event will give us information about how
  10976. 9:04:01much
  10977. 9:04:02stripe the stripe uh how much was a
  10978. 9:04:07stripe fee okay so now inside charge
  10979. 9:04:11updated we get what is the actual charge
  10980. 9:04:15which we can always get from even data
  10981. 9:04:17object so that charge is going to be an
  10982. 9:04:19associative array then from the charge
  10983. 9:04:22we're going to take balance transaction
  10984. 9:04:25ID and payment intent so you should also
  10985. 9:04:28keep in mind that first checkout session
  10986. 9:04:32completed uh will be executed if we
  10987. 9:04:35speak about the sequential order first
  10988. 9:04:38checkout session completed will be
  10989. 9:04:40executed and then charge update will be
  10990. 9:04:43executed and whenever checkout session
  10991. 9:04:45completed is executed inside orders
  10992. 9:04:48table in the database we are going to
  10993. 9:04:51save payment intent
  10994. 9:04:53okay so we're going to do this right
  10995. 9:04:55here in this checkout session completed
  10996. 9:04:57uh case so then when the charge updated
  10997. 9:05:01happens we get this payment intent and
  10998. 9:05:04we are going to select orders with this
  10999. 9:05:06payment intent and this is going to be
  11000. 9:05:09the charge updated event will be also
  11001. 9:05:11the case when we send email to buyer or
  11002. 9:05:13to vendor as well that the order has
  11003. 9:05:15been made so we're going to do this
  11004. 9:05:17later not right
  11005. 9:05:18now okay now from this transaction ID
  11006. 9:05:24and through this stripe client we send
  11007. 9:05:26the request in stripe a API to receive
  11008. 9:05:29the balance transaction
  11009. 9:05:31information that balance transaction
  11010. 9:05:33information will contain the stripe fee
  11011. 9:05:35as well now we're going to select orders
  11012. 9:05:38based on the following payment intent
  11013. 9:05:40and those are the orders we need to
  11014. 9:05:43update so we also get the what was the
  11015. 9:05:46total paid amount by this buyer and this
  11016. 9:05:50is going to be balance transaction
  11017. 9:05:53amount
  11018. 9:05:54this is going to be also the same amount
  11019. 9:05:56as sum of total orders so remember a
  11020. 9:06:02buyer can make a single checkout for
  11021. 9:06:06multiple orders and we are creating
  11022. 9:06:08multiple orders right each order for
  11023. 9:06:12each vendor and the total amount is what
  11024. 9:06:16the buyer paid which will be distributed
  11025. 9:06:19across multiple vendors Okay so that
  11026. 9:06:23amount will be the same as sum of total
  11027. 9:06:26prices of these orders so we have the
  11028. 9:06:29stripe vew which I'm going to set this
  11029. 9:06:31into zero okay then uh inside this
  11030. 9:06:35balance transaction we have fee details
  11031. 9:06:37which is array and each fee detail has
  11032. 9:06:40its own type as well so we're going to
  11033. 9:06:42find the feed detail which has stripe um
  11034. 9:06:46which has Type to be stripe fee and we
  11035. 9:06:50are going to take the stripe fee
  11036. 9:06:51whatever will be fee detail amount and
  11037. 9:06:55in the following way we have the stripe
  11038. 9:06:56fee which is going to be in
  11039. 9:06:59cents okay so next we are going to
  11040. 9:07:03calculate what is going to be platform
  11041. 9:07:06fee percentage and this is something I
  11042. 9:07:09want to add inside app config again so
  11043. 9:07:14right here let's add platform fee let's
  11044. 9:07:18give it 10 so platform fee percentage is
  11045. 9:07:2110% and right here we need to calculate
  11046. 9:07:25what um will be these columns if we
  11047. 9:07:28expand order table we're going to
  11048. 9:07:30calculate we know exactly what was the
  11049. 9:07:32stripe fee and that is going to be
  11050. 9:07:34online payment commission okay so we
  11051. 9:07:38need we have to calculate what is going
  11052. 9:07:40to be website commission website
  11053. 9:07:43commission will be
  11054. 9:07:46whatever was remaining after stripe
  11055. 9:07:49after deducting stripe fee on the total
  11056. 9:07:52amount what ever is remaining taking 10%
  11057. 9:07:56of that so let's go ahead and do it so
  11058. 9:08:00now I start iterating over orders and we
  11059. 9:08:02have to update each order and this is a
  11060. 9:08:05place where we have to send email to
  11061. 9:08:07each vendor as well that the New Order
  11062. 9:08:09was made for them
  11063. 9:08:11now let's take what is the vendor share
  11064. 9:08:15of the total amount okay so if two
  11065. 9:08:18orders were made let me open a new text
  11066. 9:08:21file so if two orders were made need
  11067. 9:08:24let's put this on the right side so
  11068. 9:08:26let's say vendor one has $100 and vendor
  11069. 9:08:32two has $200 orders so then the vendor
  11070. 9:08:36share will be whatever was the total so
  11071. 9:08:39for vendor one vendor share will be 100
  11072. 9:08:42divided on 300 because the total amount
  11073. 9:08:46was 300 that was paid by uh buyer so
  11074. 9:08:51then we have this vendor share okay and
  11075. 9:08:53through this vendor share we're going to
  11076. 9:08:55calculate uh what was the online payment
  11077. 9:08:58commission as well we know that user
  11078. 9:09:00paid user paid
  11079. 9:09:04300 okay and commission let's say we
  11080. 9:09:08don't know how much but we we know uh
  11081. 9:09:12this inside the stripe fee variable so
  11082. 9:09:15we know that the stripe fee let's say we
  11083. 9:09:17know that the stripe fee was $9 okay so
  11084. 9:09:21stripe fee
  11085. 9:09:25was $99 okay so we know that the vendor
  11086. 9:09:28one had the its share of the total
  11087. 9:09:31amount um 100 divided on 300 now we're
  11088. 9:09:35going to distribute that stripe fee
  11089. 9:09:39equally on all vendors as
  11090. 9:09:42well okay let me explain this so stripe
  11091. 9:09:46fee let's say it was nine so we're going
  11092. 9:09:49to take and um for vendor
  11093. 9:09:54one let's define field stripe fee for
  11094. 9:09:57vendor one is going to be the stripe
  11095. 9:10:01sheare Multiplied on stripe fee okay
  11096. 9:10:06stripe sheare is 100 ided over 300 and
  11097. 9:10:10if we multiply this on nine let's
  11098. 9:10:12actually open
  11099. 9:10:16calculator
  11100. 9:10:19so 100 divided on 300 multiply this on
  11101. 9:10:25nine so we're going to see three so
  11102. 9:10:28three will be stripe fee for first first
  11103. 9:10:32vendor okay so we are going to continue
  11104. 9:10:36next vendor share Multiplied on stripe
  11105. 9:10:38fee we see three then we're going to
  11106. 9:10:40calculate what's going to be the we
  11107. 9:10:42website commission website commission
  11108. 9:10:44will be the order total price which was
  11109. 9:10:48300 let's write website uh website fee
  11110. 9:10:52so total price which was
  11111. 9:10:54300
  11112. 9:10:56minus online payment commission which
  11113. 9:10:59was the the um for this vendor sorry
  11114. 9:11:03hold on so website commission we're
  11115. 9:11:05speaking about the uh this specific
  11116. 9:11:07order not totally so order total price
  11117. 9:11:10was 100 for the first vendor let's put
  11118. 9:11:13this right here vendor one and then we
  11119. 9:11:17have vendor two so stripe fee for vendor
  11120. 9:11:20one was three website fee is going to be
  11121. 9:11:23total price 100 minus whatever was the
  11122. 9:11:28online payment commission which was
  11123. 9:11:31three and that we know that information
  11124. 9:11:35we have inside
  11125. 9:11:39sents no we don't have that inside
  11126. 9:11:42sense uh okay let me keep doing okay and
  11127. 9:11:46that needs to be multiplied on platform
  11128. 9:11:48fee person so from this we're going to
  11129. 9:11:51calculate 10%
  11130. 9:11:53and if we just divide this into 100 and
  11131. 9:11:57then multiply this into 10 which means
  11132. 9:11:59that dividing this into 10 we're going
  11133. 9:12:01to calculate this 10% which is going to
  11134. 9:12:04be again open calculator
  11135. 9:12:07[Music]
  11136. 9:12:08so 100 minus
  11137. 9:12:123 that needs to be divided on 10 and
  11138. 9:12:16this is going to be website
  11139. 9:12:18fee let's write here
  11140. 9:12:219.7 is going to be the website fee okay
  11141. 9:12:25after this we're going to calculate what
  11142. 9:12:28vendor will
  11143. 9:12:30receive vendor
  11144. 9:12:35subtotal so vendor will receive the
  11145. 9:12:38total price minus online payment
  11146. 9:12:41commission and minus website commission
  11147. 9:12:45so 100 minus three which is the online
  11148. 9:12:48payment commission minus the website
  11149. 9:12:50commission which is 9.7
  11150. 9:12:53is going to
  11151. 9:12:56be 100 - 3 -
  11152. 9:13:019.7 is going to be
  11153. 9:13:0587.3 so
  11154. 9:13:0787.3 is what the vendor vendor will
  11155. 9:13:11receive when the payment is made um on
  11156. 9:13:15100
  11157. 9:13:16amount so that's it so after this we're
  11158. 9:13:19going to save that information into
  11159. 9:13:21orders and in the future we're going to
  11160. 9:13:23and email as well and that is basically
  11161. 9:13:26what happens inside this uh charge
  11162. 9:13:28updated so uh we need that charge
  11163. 9:13:30updated to get the balance transaction
  11164. 9:13:33information and to be able to get that
  11165. 9:13:36fee details we don't have that fee
  11166. 9:13:38details in this checkout session
  11167. 9:13:40completed but now let's talk about
  11168. 9:13:42inside checkout session completed which
  11169. 9:13:44as I mentioned happens before charge
  11170. 9:13:48update it happens okay so here we're
  11171. 9:13:51going to get this session event St data
  11172. 9:13:53object then we're going to get the
  11173. 9:13:55payment intent information from the
  11174. 9:13:57session and we're going to find orders
  11175. 9:14:00by session ID and set the payment intent
  11176. 9:14:03information so order with order items as
  11177. 9:14:06well where stripe session ID equals this
  11178. 9:14:09session ID we find those
  11179. 9:14:11orders and we're going to iterate over
  11180. 9:14:13those orders and update payment intent
  11181. 9:14:15id but we're going to do a few
  11182. 9:14:17additional things as well let me move
  11183. 9:14:20this here we're going to do few
  11184. 9:14:22additional things things so let's start
  11185. 9:14:23iterating over orders we're going to set
  11186. 9:14:26the payment intent to Pi we're going to
  11187. 9:14:28Mark the order to be paid and update the
  11188. 9:14:31order but we're going to also calculate
  11189. 9:14:35which products need to be deleted from
  11190. 9:14:37cart okay because we performed the
  11191. 9:14:40checkout from the cart items database
  11192. 9:14:43table those cart items needs to be
  11193. 9:14:46removed from the cart right so the
  11194. 9:14:49existing cart items we're going to
  11195. 9:14:52destructure these
  11196. 9:14:54because we're doing this basically for
  11197. 9:14:56many orders like a one user as I
  11198. 9:14:58mentioned this many many times one user
  11199. 9:15:01might make the payment for multiple
  11200. 9:15:03orders right and all of these products
  11201. 9:15:05need to be removed from the card so we
  11202. 9:15:07are
  11203. 9:15:08calculating the total product IDs
  11204. 9:15:12products to be deleted from the card and
  11205. 9:15:14that is concatenated with order order
  11206. 9:15:17Items Map and taking the product ID for
  11207. 9:15:21each order item and to where so this
  11208. 9:15:23simply will return product IDs okay so
  11209. 9:15:28there might be the product ID repeated
  11210. 9:15:30many times if we are checking out the
  11211. 9:15:32same product with two or three different
  11212. 9:15:36variations the product ID inside these
  11213. 9:15:39products to be deleted from card array
  11214. 9:15:41might be repeated but it's not big deal
  11215. 9:15:44because anyway we're going to delete
  11216. 9:15:46them from the cart so after this we're
  11217. 9:15:50going to reduce the product quantity so
  11218. 9:15:51we iterate over order items we take the
  11219. 9:15:55options from this variation type option
  11220. 9:15:58IDs and we take the product and this is
  11221. 9:16:01the case what we are where we need to
  11222. 9:16:03have a look at the
  11223. 9:16:04options okay so the product the user
  11224. 9:16:08might purchased a specific variation of
  11225. 9:16:10the product and if the user purchased a
  11226. 9:16:13specific variation let's say one over
  11227. 9:16:15five we have to decrease the quantity
  11228. 9:16:18from here but if the user did not
  11229. 9:16:20purchase any specific variation or if
  11230. 9:16:22the product even didn't have any
  11231. 9:16:24variations then we have to decrease the
  11232. 9:16:26quantity from the product model itself
  11233. 9:16:29so if options exist if there was
  11234. 9:16:32something in the order item variation
  11235. 9:16:34type option IDs which in our case is not
  11236. 9:16:38like this so inside variation type
  11237. 9:16:40option ideas we have empty array and if
  11238. 9:16:43empty array returns false but if options
  11239. 9:16:46exist then we're going to get the
  11240. 9:16:49variations and on that variation we're
  11241. 9:16:52going to find the variation with the
  11242. 9:16:54following options right here and we're
  11243. 9:16:57going to get the first one and then if
  11244. 9:17:00the variation exists and if the
  11245. 9:17:02variation quantity is not null if the
  11246. 9:17:05quantity is null it means that we have
  11247. 9:17:07unlimited uh quantity of that
  11248. 9:17:09variation if the variation is not null
  11249. 9:17:12then we're going to deduct that order
  11250. 9:17:15item quantity from the variation
  11251. 9:17:17quantity and we're going to save that
  11252. 9:17:19okay however if the options in else case
  11253. 9:17:23right here if the options does not exist
  11254. 9:17:27then if the product quantity is not null
  11255. 9:17:30if we don't have product unlimited
  11256. 9:17:31quantity then from the product quantity
  11257. 9:17:34we're going to detect the order item
  11258. 9:17:36quantity after
  11259. 9:17:40which this is for this order items Loop
  11260. 9:17:44so after the end of this order items
  11261. 9:17:46loop we're going to iterate over uh not
  11262. 9:17:50iterate but we're going to directly
  11263. 9:17:51delete
  11264. 9:17:53uh cart items so for the user for the V
  11265. 9:17:57uh order user basically
  11266. 9:18:01um this is something uh I think a
  11267. 9:18:06mistake yeah this is something that is a
  11268. 9:18:09mistake and I will fix that um so
  11269. 9:18:14let's let's let me finish this okay okay
  11270. 9:18:17this is it okay so now we're going to
  11271. 9:18:19delete the cart items with the following
  11272. 9:18:22product IDs so these are the product IDs
  11273. 9:18:24that need to be deleted but we're going
  11274. 9:18:26to delete those products for the user
  11275. 9:18:31for the
  11276. 9:18:32um for the
  11277. 9:18:34buyer and we this actually works
  11278. 9:18:40um but the thing is that okay let me
  11279. 9:18:45explain so all orders right here on this
  11280. 9:18:48place if like there there was like more
  11281. 9:18:52than one order order so all orders will
  11282. 9:18:54be made on the same user right so if I
  11283. 9:18:59added multiple items from two different
  11284. 9:19:02vendors into the card I performed the
  11285. 9:19:04checkout two orders were create created
  11286. 9:19:07in both cases user ID will be me it's
  11287. 9:19:10going to be current user ID right so we
  11288. 9:19:13want to find all the products from cart
  11289. 9:19:15items with a current user
  11290. 9:19:17ID and um with the product IDs so this
  11291. 9:19:22is actually what is going on right here
  11292. 9:19:24and I think this is also fine so we are
  11293. 9:19:26iterating over orders we know that there
  11294. 9:19:30will exist some order for sure okay so
  11295. 9:19:34we know that this for each will happen
  11296. 9:19:36at least once and when this happens
  11297. 9:19:39order variable will be created and that
  11298. 9:19:42order variable is used right here Order
  11299. 9:19:47user ID so for all orders order user ID
  11300. 9:19:51will be the same so we are fine cart
  11301. 9:19:53items with the order user ID Products to
  11302. 9:19:56be deleted we're going to exclude those
  11303. 9:19:59items which have saved for later
  11304. 9:20:02false and we're going to perform delete
  11305. 9:20:06now let me import these classes cart
  11306. 9:20:09item we're going to import order status
  11307. 9:20:11ANM let's import order
  11308. 9:20:15item what else do we need we need to
  11309. 9:20:18import
  11310. 9:20:21order up models
  11311. 9:20:25order and we need import
  11312. 9:20:33log
  11313. 9:20:34okay okay this is good now I want to
  11314. 9:20:39open this Lal log file and we will get
  11315. 9:20:43some output right here so if we scroll
  11316. 9:20:45at the very bottom uh we're going to see
  11317. 9:20:48some output when we perform the checkout
  11318. 9:20:51and I also want to open
  11319. 9:20:53open this place uh where we have this
  11320. 9:20:56web hook up and running and now uh we
  11321. 9:20:59are going to close this we're going to
  11322. 9:21:01go
  11323. 9:21:04back and click on this proceed to check
  11324. 9:21:08out um maybe we can do this for for
  11325. 9:21:12multiple vendors so we have we have two
  11326. 9:21:16vendors let's open this add it into the
  11327. 9:21:18cart maybe maybe we can add different
  11328. 9:21:20variations as well
  11329. 9:21:24um okay now for
  11330. 9:21:27vendor for vendor store we have these
  11331. 9:21:31two products with these prices and right
  11332. 9:21:34here we have um the
  11333. 9:21:37six okay let it be like this we have to
  11334. 9:21:41calculate so totally this will be the
  11335. 9:21:43amount and we're going to see that okay
  11336. 9:21:45anyway let's click on proceed to check
  11337. 9:21:49out and let me choose card here and I'm
  11338. 9:21:52going to fill the card information so we
  11339. 9:21:55can use 42 42 42 as well but I'm
  11340. 9:21:57actually using four uh a lot of zeros
  11341. 9:22:01and then finally 27 so this actually
  11342. 9:22:04fills up uh my stripe balance as well so
  11343. 9:22:09if we check then inside
  11344. 9:22:12balances we have zero balance right here
  11345. 9:22:15so me as a Marketplace have zero balance
  11346. 9:22:18right here but when I perform uh payment
  11347. 9:22:21with this card my balance will be filled
  11348. 9:22:23up so now let's provide that information
  11349. 9:22:26User click on
  11350. 9:22:29pay uh of course we will be redirected
  11351. 9:22:31into success which we don't have uh yet
  11352. 9:22:34implemented
  11353. 9:22:36but uh the web Hook is not
  11354. 9:22:40working let's restart the web
  11355. 9:22:48hook okay we are not going to get
  11356. 9:22:50anything because web hook wasn't
  11357. 9:22:54triggered we have to redo
  11358. 9:23:01this okay let's go into cart also order
  11359. 9:23:04items will not be deleted because
  11360. 9:23:08um the web hook wasn't completed so the
  11361. 9:23:12order will be made but that's not
  11362. 9:23:13important so it's going to be draft
  11363. 9:23:16order let's provide card here
  11364. 9:23:27click on pay and I want to have a look
  11365. 9:23:30this
  11366. 9:23:34part where is web hook
  11367. 9:23:39information
  11368. 9:23:41okay uh we are not properly listening to
  11369. 9:23:47something it is not sending that
  11370. 9:23:49information to us now let's go into
  11371. 9:23:53event
  11372. 9:23:56destinations we on
  11373. 9:24:01local okay something is going
  11374. 9:24:04on I think I know what's going on
  11375. 9:24:07because uh I have to execute login again
  11376. 9:24:11to get connected to this account because
  11377. 9:24:14I have two accounts I was connected with
  11378. 9:24:16this L react Ecommerce and it is
  11379. 9:24:18listening right here not here we don't
  11380. 9:24:21have the listener um let's clear this up
  11381. 9:24:25and I'm going to
  11382. 9:24:27call stripe login so in your case it's
  11383. 9:24:31going to probably work uh okay we're
  11384. 9:24:34going to open this in the
  11385. 9:24:41browser I'm going to now connect to the
  11386. 9:24:48application okay I enter the code now I
  11387. 9:24:50give L access and access was granted
  11388. 9:24:56here okay done stripe C is configured
  11389. 9:24:59for LEL react e-commerce tutorial with
  11390. 9:25:02count I did this perfect and now if we
  11391. 9:25:04execute stripe
  11392. 9:25:06listen uh we need to get a new web hook
  11393. 9:25:10I
  11394. 9:25:10think so let me copy
  11395. 9:25:13this
  11396. 9:25:16open in stripe web hook secret and
  11397. 9:25:20replace this cool now let's go
  11398. 9:25:27back go into view
  11399. 9:25:34cart click on proceed to check out have
  11400. 9:25:36a look
  11401. 9:25:41here uh so far we don't have any web
  11402. 9:25:44hooks let me move this on my second
  11403. 9:25:46screen let's
  11404. 9:25:50provide sometimes we also get web hooks
  11405. 9:25:52when we open the stripe
  11406. 9:25:58page click on
  11407. 9:26:02pay okay now we are receiving workbooks
  11408. 9:26:04now we are talking uh but actually uh
  11409. 9:26:08those web hooks returned with
  11410. 9:26:10400 something is actually gone wrong and
  11411. 9:26:15we are not
  11412. 9:26:16actually we we are not able to correctly
  11413. 9:26:20validate uh the web payload so if we
  11414. 9:26:23have a look in our code in the stripe
  11415. 9:26:28controller so we
  11416. 9:26:31have we are using this stripe endpoint
  11417. 9:26:36secret from up
  11418. 9:26:41config that's my
  11419. 9:26:43bet that's my bet this is stripe web
  11420. 9:26:46hook
  11421. 9:26:48secret yeah I made that
  11422. 9:26:50mistake I made that mistake and because
  11423. 9:26:53of that it wasn't validated okay let's
  11424. 9:26:55go back once again
  11425. 9:26:59into own
  11426. 9:27:02page click on
  11427. 9:27:04cart proceed to check
  11428. 9:27:12out now uh the so we received couple of
  11429. 9:27:17events like check out session completed
  11430. 9:27:18charart succeeded and so on and after
  11431. 9:27:20one minute if you pay attention so after
  11432. 9:27:22one minute we get this balance available
  11433. 9:27:26okay and now it return 200 because we
  11434. 9:27:28managed to fix that web hook and if we
  11435. 9:27:32check lot of logs we are going to see
  11436. 9:27:35right here one log for balance available
  11437. 9:27:39look at this this is it for balance
  11438. 9:27:42available and this is the event and that
  11439. 9:27:46balance is actually what contains the
  11440. 9:27:48side
  11441. 9:27:50there uh uh that's a total available
  11442. 9:27:54balance okay yeah that's the overall
  11443. 9:27:56information about the balance available
  11444. 9:28:00okay good good good good so the main
  11445. 9:28:03thing is that we made the web hook
  11446. 9:28:04working now if we go in the stripe
  11447. 9:28:06controller everything is good let's go
  11448. 9:28:08into the website and F this information
  11449. 9:28:11here
  11450. 9:28:18um user hit the enter now let's check
  11451. 9:28:22the web hooks area now okay all web
  11452. 9:28:25hooks completed successfully but the web
  11453. 9:28:27hook actually we have some error in the
  11454. 9:28:30web hook area we're going to check the
  11455. 9:28:32Lal log okay so now let's see so we have
  11456. 9:28:35these new errors on the following time
  11457. 9:28:38I'm going to search now records by
  11458. 9:28:42time uh okay let's start from the top so
  11459. 9:28:45we received payment intent succeeded we
  11460. 9:28:49received chart succeeded we received
  11461. 9:28:51payment intent created all of them at
  11462. 9:28:54the same time and then we have the
  11463. 9:28:56objects right here the information about
  11464. 9:28:58the objects so this
  11465. 9:29:00is payment intent succeeded which we
  11466. 9:29:03don't need okay we're also printing that
  11467. 9:29:06Json here
  11468. 9:29:09scroll this is also payment in no this
  11469. 9:29:11is actually charge
  11470. 9:29:15information yeah this is the charge
  11471. 9:29:17information and if we have a look at the
  11472. 9:29:19charge information that
  11473. 9:29:24contains uh I want to explain this very
  11474. 9:29:27clearly so we have this charge updated
  11475. 9:29:31and we have the balance transaction here
  11476. 9:29:33so if we check this charge information
  11477. 9:29:36we're going to find balance transaction
  11478. 9:29:38which is actually null so we we receed
  11479. 9:29:41these two times charge created and
  11480. 9:29:43charge updated we have a lot of logs
  11481. 9:29:46checkout session completed is the first
  11482. 9:29:47one which we receive uh we received
  11483. 9:29:53uh where is
  11484. 9:29:54payment intent let's find payment
  11485. 9:29:58intent we have a payment intent so on
  11486. 9:30:02checkout session completed we took the
  11487. 9:30:03payment intent as saved in the orders
  11488. 9:30:06Table after this we have an error
  11489. 9:30:09attempt to read property quantity on
  11490. 9:30:12null which is coming
  11491. 9:30:14from stripe controller
  11492. 9:30:18125 125
  11493. 9:30:22five that's coming from the product
  11494. 9:30:25quantity okay it looks like product
  11495. 9:30:28didn't exist so looks like from the
  11496. 9:30:30order item we didn't Define relation
  11497. 9:30:33belongs to relation into
  11498. 9:30:39product
  11499. 9:30:41product class
  11500. 9:30:44cool we are going to do this once
  11501. 9:30:50again let's see if we have items into
  11502. 9:30:52the cart we still have items into the
  11503. 9:30:54cart because when this
  11504. 9:30:57happened uh the cart items were not
  11505. 9:31:00deleted so let's
  11506. 9:31:03provide proceed provide card
  11507. 9:31:11details we hit the enter let's open web
  11508. 9:31:15hooks terminal all of the web hooks were
  11509. 9:31:17completed successfully and now we
  11510. 9:31:19receive charge updated look at this so
  11511. 9:31:21first we received everything else lately
  11512. 9:31:24we received charge updated and now if we
  11513. 9:31:26have a look in logs we are going to see
  11514. 9:31:30better
  11515. 9:31:32results without any kind of Errors now
  11516. 9:31:35it starts right here charge updated we
  11517. 9:31:38got the charge updated then we have the
  11518. 9:31:40balance transaction ID right here
  11519. 9:31:42through this balance transaction we
  11520. 9:31:44fetch the balance information and from
  11521. 9:31:46that balance information we are able to
  11522. 9:31:48extract the information regarding stripe
  11523. 9:31:51fee um and we have the balance available
  11524. 9:31:54so everything every web hook data is
  11525. 9:31:56logged but now the coolest part is to
  11526. 9:31:59check the orders table and let's find
  11527. 9:32:02the latest order which was completed
  11528. 9:32:05successfully which is paid so that order
  11529. 9:32:09actually we made two orders uh at the
  11530. 9:32:11same time okay if we check if we
  11531. 9:32:17check
  11532. 9:32:20these yeah they are made on the same
  11533. 9:32:22time now have a look so what is the
  11534. 9:32:26total amount total price for the first
  11535. 9:32:29order is 40 for the second is 300 so
  11536. 9:32:33user actually paid 40 and 300 now let's
  11537. 9:32:36check stripe balance first click on
  11538. 9:32:40balances now look at this so we have
  11539. 9:32:42such amount and that happens because we
  11540. 9:32:44made payment many times with the same
  11541. 9:32:48amount uh but uh where we are actually
  11542. 9:32:51testing
  11543. 9:32:52so we did this five times but if we
  11544. 9:32:55check this right now so
  11545. 9:32:57340 was the amount out of this net is
  11546. 9:33:02actually
  11547. 9:33:21we are going to see
  11548. 9:33:24um we are going to see 10.16 I have a
  11549. 9:33:28question why do we have so many digits
  11550. 9:33:31after comma when I remember that we
  11551. 9:33:37provided total with four places
  11552. 9:33:42here
  11553. 9:33:47interesting yeah okay it looks like um
  11554. 9:33:52SQ light doesn't have that decimal type
  11555. 9:33:55of thing and that's because of it so if
  11556. 9:33:58it's where my SQL the other information
  11557. 9:34:00would be lost but now let's open
  11558. 9:34:04calculator and
  11559. 9:34:07this
  11560. 9:34:09plus
  11561. 9:34:11this 10.16 the exact number what we have
  11562. 9:34:15right here so we distributed that
  11563. 9:34:1810.16 uh proportionally to this order so
  11564. 9:34:21because uh that order has 300 uh then
  11565. 9:34:26the fee on that order was much higher
  11566. 9:34:28than this order which has uh 1 point
  11567. 9:34:31something now we also calculated uh the
  11568. 9:34:34website
  11569. 9:34:35commission out of the remaining value
  11570. 9:34:37which is the 10% so if we actually we
  11571. 9:34:41know that the online commission uh on
  11572. 9:34:43this was that so that order has 300 so
  11573. 9:34:48now 300 minus the
  11574. 9:34:52which gives us the following value and
  11575. 9:34:54we're going to calculate 10% of it
  11576. 9:34:56meaning divide this on 10 equals 29
  11577. 9:35:00something which is exactly what we see
  11578. 9:35:03right here okay and then we have the
  11579. 9:35:05wender subtotal information and this is
  11580. 9:35:09pretty
  11581. 9:35:10cool so I think I'm going to close this
  11582. 9:35:13I think the uh the working flow is
  11583. 9:35:16actually pretty clear and just like this
  11584. 9:35:18we have
  11585. 9:35:19implemented um
  11586. 9:35:22check out on multiple orders and I think
  11587. 9:35:27we can we should create now the success
  11588. 9:35:29page right here now let's open stripe
  11589. 9:35:32controller success method and first
  11590. 9:35:34let's uh use request variable here then
  11591. 9:35:38I'm going to get the currently
  11592. 9:35:39authenticated user information and I'm
  11593. 9:35:41going to take the session ID from
  11594. 9:35:43request we know that the session ID is
  11595. 9:35:46in the URL when redirect it back into
  11596. 9:35:48this success page so from the orders
  11597. 9:35:51table I want to find all the orders by
  11598. 9:35:53the session ID then I want to check if
  11599. 9:35:55there are no such orders I want to abort
  11600. 9:35:58immediately with 404 then I iterate over
  11601. 9:36:01the orders and I want to check that if
  11602. 9:36:06for some reason something wrong happened
  11603. 9:36:09and those orders does not belong to the
  11604. 9:36:11currently authenticated user then I'm
  11605. 9:36:14also aborting with
  11606. 9:36:1543 forbidden after which I'm going to
  11607. 9:36:19render stripe success page
  11608. 9:36:22uh inside uh using inertia and I'm
  11609. 9:36:24providing these orders just created
  11610. 9:36:27orders for this I'm going to create
  11611. 9:36:30order view resource so let's execute PHP
  11612. 9:36:33artisan make
  11613. 9:36:36resource order view
  11614. 9:36:41resource now let's open uh this order
  11615. 9:36:45view
  11616. 9:36:46resource which you have to import right
  11617. 9:36:50here so I'm going to open this order
  11618. 9:36:53view
  11619. 9:36:55resource and we are going to uh return
  11620. 9:36:58couple of information from here so we
  11621. 9:37:02need ID we need total price we need
  11622. 9:37:04status created it and I also need the
  11623. 9:37:06vendor information and for this I'm
  11624. 9:37:08going to create new resource vendor user
  11625. 9:37:12resource uh let's actually execute PHP
  11626. 9:37:15artisan make
  11627. 9:37:17resource vendor user resource
  11628. 9:37:22we hit the enter vendor user resource
  11629. 9:37:24was created make sure it is imported
  11630. 9:37:26right here or if it's they are in the
  11631. 9:37:29same name space no need to be imported
  11632. 9:37:31which is exactly our case uh let's open
  11633. 9:37:35this vendor user resource and I'm going
  11634. 9:37:37to actually copy and paste
  11635. 9:37:39the fields what we need here ID name
  11636. 9:37:42email vendor store name and vendor store
  11637. 9:37:45address so now I'm going to continue
  11638. 9:37:48here we need order items I'm going to
  11639. 9:37:50iterate over the order it items and I
  11640. 9:37:52want to render the um I want to return
  11641. 9:37:55the ID quantity price variation type
  11642. 9:37:57option IDs and I want to return the
  11643. 9:38:00product details inside product details I
  11644. 9:38:02want ID title slug I need description
  11645. 9:38:06and image information as well so I'm
  11646. 9:38:08going to create this get image for
  11647. 9:38:10options but I will explain what this
  11648. 9:38:12actually is going to do so because this
  11649. 9:38:14is the order items order items might
  11650. 9:38:16have a specific variation type option
  11651. 9:38:18IDs right so I want to display
  11652. 9:38:22that specific variation type option ID
  11653. 9:38:25is image for the product that was just
  11654. 9:38:28sold so when we display the order
  11655. 9:38:31details uh the user should see exactly
  11656. 9:38:35the color and type of the image they
  11657. 9:38:37have purchased not the default one
  11658. 9:38:40so I'm going to open product.php and I'm
  11659. 9:38:45going to create that function get um
  11660. 9:38:47image for options we're going to expect
  11661. 9:38:50right here option IDs which might be
  11662. 9:38:51also
  11663. 9:38:52null and we are providing empty array or
  11664. 9:38:56null right here if it doesn't exist so
  11665. 9:38:58if it is um if it doesn't exist if it's
  11666. 9:39:01an empty array or null doesn't matter so
  11667. 9:39:04if it exists then in in this case we're
  11668. 9:39:06going to take the values so here we have
  11669. 9:39:08this variation type option IDs inside
  11670. 9:39:11the order
  11671. 9:39:14item which actually uh is um object
  11672. 9:39:19object speaking about the Json but
  11673. 9:39:21associative array speaking from the PHP
  11674. 9:39:24perspective so we have this associative
  11675. 9:39:26array and we are taking values of that
  11676. 9:39:30so we just need the option IDs like in
  11677. 9:39:32in our case we need one and four three
  11678. 9:39:36and five so we take those option IDs and
  11679. 9:39:39then we select the variation type option
  11680. 9:39:42we're providing these option IDs here uh
  11681. 9:39:45I think sorting is not even necessary
  11682. 9:39:47here so we get those options we start
  11683. 9:39:50iterating over the the options uh and we
  11684. 9:39:53take image the first image for this
  11685. 9:39:56option so if the image exists then we
  11686. 9:40:00return it if it doesn't exist we're
  11687. 9:40:01going to return the first image First
  11688. 9:40:03Media URL uh through this spy media
  11689. 9:40:07library helper um of the product itself
  11690. 9:40:10not the variation option okay so and
  11691. 9:40:13just like this we are
  11692. 9:40:15returning uh this order resource we we
  11693. 9:40:18finish this and we're going to get oops
  11694. 9:40:21we're going to get the data in the front
  11695. 9:40:24end so let's go into types typescript
  11696. 9:40:28types and I'm going to Define order item
  11697. 9:40:31to have ID quantity price we're going to
  11698. 9:40:33have this variation type option IDs
  11699. 9:40:35we're going to have product as well uh
  11700. 9:40:37ID title slug description image and I'm
  11701. 9:40:41going to Define also order with ID total
  11702. 9:40:44price status create that we're going to
  11703. 9:40:46have the vendor information as well ID
  11704. 9:40:48name email store name and store address
  11705. 9:40:52and now if we go into success um first
  11706. 9:40:55let me import all the components and
  11707. 9:40:57classes I need I need head and Link from
  11708. 9:41:00injs I need currency format I need this
  11709. 9:41:04check Circle icon from the hero icons I
  11710. 9:41:07need authenticated layout I need page
  11711. 9:41:09props and order then I'm going to take
  11712. 9:41:12orders right here let's create
  11713. 9:41:14authenticated layout inside here we need
  11714. 9:41:17head then let's define the Steve with
  11715. 9:41:19fixed withd shrink with with margin X
  11716. 9:41:22Auto inside here another div and then
  11717. 9:41:25we're going to display this uh check
  11718. 9:41:27Circle icon with a green color and
  11719. 9:41:29message payment was completed and we're
  11720. 9:41:31going to see this thank you for your
  11721. 9:41:33purchase text as well and now I'm going
  11722. 9:41:35to start iterating over my orders and
  11723. 9:41:37I'm going to display card for each order
  11724. 9:41:40so we're going to have the uh background
  11725. 9:41:43white on dark mode we're going to have
  11726. 9:41:45different color background so we're
  11727. 9:41:47going to have the order summary
  11728. 9:41:48information we're going to have who is
  11729. 9:41:50the seller
  11730. 9:41:51which is going to be uh the order vendor
  11731. 9:41:54user. store name is the seller and in
  11732. 9:41:57the future we're going to create a page
  11733. 9:41:58and Link that to the vendor store as
  11734. 9:42:01well so we're going to have also order
  11735. 9:42:05number which is going to be the order ID
  11736. 9:42:07and when we implement the order Details
  11737. 9:42:09page we're going to link this to the
  11738. 9:42:11following um URL as well so we're going
  11739. 9:42:14to have uh total items which is going to
  11740. 9:42:17be order. order items length and we are
  11741. 9:42:20going to also have the total price which
  11742. 9:42:23is going to be order. total
  11743. 9:42:26price
  11744. 9:42:27um formatted nicely so and finally I
  11745. 9:42:32think we need the view order details
  11746. 9:42:33pattern and we're going to have uh the
  11747. 9:42:36back to home now let me see why we have
  11748. 9:42:40this order items property doesn't
  11749. 9:42:44exist uh let's open
  11750. 9:42:46it okay let's add order items here cool
  11751. 9:42:54okay I think this is great and now let
  11752. 9:42:56me test Let me refresh the existing page
  11753. 9:42:58and let's open Dev tools as well just in
  11754. 9:43:00case we have some
  11755. 9:43:02error uh okay read find reading store
  11756. 9:43:07name so we don't have store name let's
  11757. 9:43:11print right here entire orders
  11758. 9:43:16information okay uh okay we need to
  11759. 9:43:20disable we need to disable WP so right
  11760. 9:43:23here we're going to set public static WP
  11761. 9:43:27equals false we don't want R we refresh
  11762. 9:43:31the
  11763. 9:43:32page and now we see that so we see
  11764. 9:43:35payment was completed thank you for your
  11765. 9:43:37purchase and we see two orders the first
  11766. 9:43:39is for Zoomer with 300 amount one item
  11767. 9:43:43order number and then here we have
  11768. 9:43:46totally two items um total price is 40
  11769. 9:43:49for the vendor store
  11770. 9:43:51we see order details and back to home as
  11771. 9:43:54well and this is great so as a challenge
  11772. 9:43:56I give you to you to implement the
  11773. 9:43:59failure and something similar uh you can
  11774. 9:44:02just display this sorry the payment has
  11775. 9:44:04been failed or something like this as
  11776. 9:44:06you wish so you can do this now let me
  11777. 9:44:10Implement showing success message when
  11778. 9:44:12we add item into the cart it is added
  11779. 9:44:15count is increased but we don't see the
  11780. 9:44:16success message and this is what I'm
  11781. 9:44:18going to do right now so let's open
  11782. 9:44:20first handle initial JS request and when
  11783. 9:44:23we put this access message I'm going to
  11784. 9:44:26give this also time when the message was
  11785. 9:44:29generated okay so here we're going to
  11786. 9:44:32have message is going to be session
  11787. 9:44:35success and we need time here which I'm
  11788. 9:44:39going to generate micro time with
  11789. 9:44:43true like this now let's open index. DTS
  11790. 9:44:49and right here I'm going to change this
  11791. 9:44:50as well well so we have message which is
  11792. 9:44:53going to be string and we're going to
  11793. 9:44:55have time which is going to be
  11794. 9:44:58number finally let's open authenticated
  11795. 9:45:01layout and we're going to take care of
  11796. 9:45:03this part we have props here so we can
  11797. 9:45:07access the success meage message through
  11798. 9:45:09props let me Define state right here
  11799. 9:45:11which is going to be success messages
  11800. 9:45:13State array and whenever there's a
  11801. 9:45:17success message we're going to push that
  11802. 9:45:18inside that state so at the same time we
  11803. 9:45:21might have multiple success messages
  11804. 9:45:23displayed on the page so we Define the
  11805. 9:45:25state we provide that and it can contain
  11806. 9:45:28array of anything pretty much so next
  11807. 9:45:31we're going to define the timeout
  11808. 9:45:33reference because I also I also want to
  11809. 9:45:36implement hiding that success message
  11810. 9:45:39after a few seconds and for this I'm
  11811. 9:45:41going to save the timeout references for
  11812. 9:45:45each success message and this is going
  11813. 9:45:47to be a use ref and here we're going to
  11814. 9:45:50provide the type so key is going to be
  11815. 9:45:53number of this object and value is going
  11816. 9:45:57to be whatever is the type of set
  11817. 9:46:00timeout function okay so we're going to
  11818. 9:46:03import this user ref later so then we're
  11819. 9:46:06going to listen to prop success and when
  11820. 9:46:10this is changed so when we uh have new
  11821. 9:46:13success message right here and this is
  11822. 9:46:15going to be changed if message or time
  11823. 9:46:17is changed so when this is changed we
  11824. 9:46:21are going to do the following so we are
  11825. 9:46:22going to check if prop success message
  11826. 9:46:25exists then we're going to create the
  11827. 9:46:27new message we're going to give it the
  11828. 9:46:31um we're going to destructure the
  11829. 9:46:33existing message take the message in
  11830. 9:46:35time and we're going to give it also ID
  11831. 9:46:38as a unique identifier okay which is
  11832. 9:46:40going to be the access type so next we
  11833. 9:46:44are going to call these set success
  11834. 9:46:46messages which will accept a call back
  11835. 9:46:47here so we're going to push that new
  11836. 9:46:50success message in front of the previous
  11837. 9:46:52messages and then that will be
  11838. 9:46:55updated then we're going to set the
  11839. 9:46:57timeout for the specific message so we
  11840. 9:47:00Define this timeout ID set timeout uh
  11841. 9:47:03for 5 seconds after 5 Seconds the
  11842. 9:47:05message should be gone then we call this
  11843. 9:47:07set success messages again after this 5
  11844. 9:47:10seconds and we're going to filter out
  11845. 9:47:12previous messages by the message ID okay
  11846. 9:47:16which we gave it right here and
  11847. 9:47:18whichever has the same ID as
  11848. 9:47:23um as this new message ID right here
  11849. 9:47:26which we just created then we're going
  11850. 9:47:28to um
  11851. 9:47:31return the uh previous messages without
  11852. 9:47:33that message so we are filtering and
  11853. 9:47:36setting removing that message from the
  11854. 9:47:40success messages okay and we're going to
  11855. 9:47:42also delete the timeout
  11856. 9:47:45references uh for the current so we use
  11857. 9:47:48this current because we have this
  11858. 9:47:49timeout references to be refs so for the
  11859. 9:47:53new message ID we are simply deleting
  11860. 9:47:55this okay but whenever we uh create that
  11861. 9:48:00new message and um set the access
  11862. 9:48:02messages we are putting that uh timeout
  11863. 9:48:06ID inside the timeout refs for the
  11864. 9:48:09current message
  11865. 9:48:10ID okay now let's focus on the template
  11866. 9:48:13so we check the access messages length
  11867. 9:48:15if it's more than zero we create the
  11868. 9:48:17toast with the following classes and and
  11869. 9:48:21inside here we iterate our success
  11870. 9:48:22messages and we're going to display
  11871. 9:48:24alert success with the uh
  11872. 9:48:27message okay now let's import use
  11873. 9:48:32effect and use
  11874. 9:48:39ref we have a lot of other things which
  11875. 9:48:41we can remove from here so now let's
  11876. 9:48:44click
  11877. 9:48:45on if we have any error let's have a
  11878. 9:48:49look
  11879. 9:48:52okay let's go on the homepage let's
  11880. 9:48:54click on this Ed to
  11881. 9:48:56cart uh app Services DB not
  11882. 9:49:03found okay we have this issue in the
  11883. 9:49:08cart
  11884. 9:49:11service right here we probably have DB
  11885. 9:49:15not
  11886. 9:49:16imported illuminate support facades DB
  11887. 9:49:20that's it
  11888. 9:49:21okay great now we add this into the cart
  11889. 9:49:24and we see product edit successfully we
  11890. 9:49:26click on this and we see second one and
  11891. 9:49:28the previous one is gone we click on
  11892. 9:49:30this we see the third one and at the
  11893. 9:49:33same time we can have multiple messages
  11894. 9:49:35the new messag is at the top and the
  11895. 9:49:36previous messages are gone after 5
  11896. 9:49:39seconds if we go into the card and we
  11897. 9:49:42change the quantity of it we're going to
  11898. 9:49:44see quantity was updated if we click on
  11899. 9:49:46delete we see product was removed from
  11900. 9:49:48the cart we are returning correct
  11901. 9:49:50message messages from the back end and
  11902. 9:49:52that's why we see
  11903. 9:49:55them nicely now I want to start working
  11904. 9:49:58on email sending and we haven't actually
  11905. 9:50:01sent any kind of email so far even for
  11906. 9:50:03the registration for fake email sending
  11907. 9:50:06or for local email sending I'm going to
  11908. 9:50:08use mail
  11909. 9:50:10pit just uh Google for mail pit open the
  11910. 9:50:13following link right here you can click
  11911. 9:50:16on installation it's going to open the
  11912. 9:50:19following page and you have to download
  11913. 9:50:21the static binary for Windows click on
  11914. 9:50:23releases right here this is going to
  11915. 9:50:25open the GitHub page scroll down below
  11916. 9:50:28and download that zip file for your
  11917. 9:50:30operating system then uh unzip that and
  11918. 9:50:34uh open Terminal where you have that
  11919. 9:50:38mail pit actually in in a similar way
  11920. 9:50:40like we did for stripe so open that
  11921. 9:50:43folder I think I have mail pit somewhere
  11922. 9:50:45here this is it but but I actually made
  11923. 9:50:48this globally available so this is what
  11924. 9:50:51I'm going to
  11925. 9:50:52do uh I'm going to open new terminal
  11926. 9:50:56here and I'm going to type mail pit just
  11927. 9:51:00mail
  11928. 9:51:01pit and now it's started actually
  11929. 9:51:04creating the server so we have this
  11930. 9:51:06Local Host Port 8025 which is the user
  11931. 9:51:09interface and we have to send the set
  11932. 9:51:12the SMTP into
  11933. 9:51:141025 let me
  11934. 9:51:16open. find mail here and change change
  11935. 9:51:21this mailer into
  11936. 9:51:23SMTP and change the port into
  11937. 9:51:271025 now let's open user.php and we are
  11938. 9:51:31going to implement must verify
  11939. 9:51:35email okay cool uh so the registration
  11940. 9:51:38now requires the email verification and
  11941. 9:51:41we can test this now for new
  11942. 9:51:45registration login not login but
  11943. 9:51:48register user two
  11944. 9:51:51uh user
  11945. 9:51:56288 example.com
  11946. 9:52:01we hit the
  11947. 9:52:03enter oh I made a
  11948. 9:52:09mistake we hit the
  11949. 9:52:11enter okay now the registration happened
  11950. 9:52:15and we see new email right here okay
  11951. 9:52:18click on this verify email address
  11952. 9:52:21this is pretty cool the I I love
  11953. 9:52:23actually using M pit it's it's pretty
  11954. 9:52:25nice so now we are actually verified we
  11955. 9:52:27are regular user and we are verified so
  11956. 9:52:29email sending is working I can close
  11957. 9:52:32this so now I want to implement email
  11958. 9:52:35sending when the order is made and uh I
  11959. 9:52:41want to open web hook functionality and
  11960. 9:52:45we have we can remove these logs we
  11961. 9:52:48don't need that anymore so these are the
  11962. 9:52:51two places where I want to implement
  11963. 9:52:53email sending for this I'm going to
  11964. 9:52:54create two mail classes pH HP artisan
  11965. 9:52:59make mail uh New Order mail which is
  11966. 9:53:04going to be to vendor New Order mail
  11967. 9:53:07this is going to go to
  11968. 9:53:09vendor PHP
  11969. 9:53:13Artis I made a mistake PHP
  11970. 9:53:18Artisan okay and the second one is going
  11971. 9:53:21to be checkout
  11972. 9:53:24completed checkout
  11973. 9:53:30completed okay so this is the place
  11974. 9:53:33where we're going to send this into
  11975. 9:53:34vendor so I'm going to use mail
  11976. 9:53:37to uh
  11977. 9:53:39order vendor
  11978. 9:53:41user then we call send new New Order
  11979. 9:53:48mail and we're going to provide the
  11980. 9:53:49order here
  11981. 9:53:51okay now we're going to send a so this
  11982. 9:53:54uh email is sent to every
  11983. 9:53:56vendor uh just let's make sure that
  11984. 9:53:59vendor the order has vendor user it has
  11985. 9:54:04which is cool and now we're going to
  11986. 9:54:06send one email to buyer so mail
  11987. 9:54:12to actually we don't need this back
  11988. 9:54:14slashes we're going to import this mail
  11989. 9:54:17facade like this so mail to
  11990. 9:54:21orders at Z so orders at Z is basically
  11991. 9:54:26uh the first order it it doesn't matter
  11992. 9:54:30if you use orders at zero or orders at
  11993. 9:54:32one because the buyer is always the same
  11994. 9:54:35person right so we're going to use user
  11995. 9:54:38here send new check out completed and
  11996. 9:54:43we're going to provide all the orders in
  11997. 9:54:45this
  11998. 9:54:46case okay so now I want to create two
  11999. 9:54:50files inside resources
  12000. 9:54:54views uh I want to create two
  12001. 9:54:57files inside that's going to be blade
  12002. 9:55:00files let me create PHP file and I'm
  12003. 9:55:04going to put the them inside mail folder
  12004. 9:55:07slash uh new order. blade
  12005. 9:55:13PHP new order. blade and the second one
  12006. 9:55:17is going to be check
  12007. 9:55:22out
  12008. 9:55:24checkout
  12009. 9:55:29completed oops that should be also dot
  12010. 9:55:37blade okay let me remove this and remove
  12011. 9:55:40that as well and in this let's open this
  12012. 9:55:45new order mail and we're going to accept
  12013. 9:55:48right here public
  12014. 9:55:51order like this let's import this order
  12015. 9:55:55and we're going to change the view name
  12016. 9:55:58to be mail. new order now let's open
  12017. 9:56:03check out completed as well in here
  12018. 9:56:07we're going to accept public array of
  12019. 9:56:14orders let me check how we are giving
  12020. 9:56:17the
  12021. 9:56:18orders orders is actually a collection
  12022. 9:56:21so we can
  12023. 9:56:22accept collection here collection of
  12024. 9:56:25orders we can import this illuminate
  12025. 9:56:29support collection cool and check out
  12026. 9:56:33completed and we're going to change this
  12027. 9:56:34into mail check out
  12028. 9:56:37completed let's change this subject also
  12029. 9:56:41thank you for your
  12030. 9:56:46purchase to be able to customize email
  12031. 9:56:49templates or colors or things like that
  12032. 9:56:51we have to publish Lal mail files as
  12033. 9:56:54well so I'm going to open now this kit p
  12034. 9:56:57and let's execute right here PHP Artisan
  12035. 9:57:00or we can do this generally how I do it
  12036. 9:57:03PHP
  12037. 9:57:04Artisan
  12038. 9:57:06vendor publish and D- tag to be LEL
  12039. 9:57:13dmail so we hit the enter now the vendor
  12040. 9:57:18related files were published let's have
  12041. 9:57:20a look so inside the vendor folder uh
  12042. 9:57:23that vendor is not our vendor that is
  12043. 9:57:25the vendor folder uh so vendor mail HTML
  12044. 9:57:29and we see those blade files and we see
  12045. 9:57:32themes CSS as well right here okay so
  12046. 9:57:35we're going to adjust them a little bit
  12047. 9:57:38but first let's open new order
  12048. 9:57:41blade and because we have defined this
  12049. 9:57:43new order mail uh and we have this
  12050. 9:57:46public property order whatever is public
  12051. 9:57:48in this mail class is can be accessed
  12052. 9:57:51inside this blade file as well it's
  12053. 9:57:54corresponding blade file which we have
  12054. 9:57:55right here that blade file actually
  12055. 9:57:57supports markdown syntax and we're going
  12056. 9:57:59to use these components uh these
  12057. 9:58:02markdown components in our blade file
  12058. 9:58:05like the table sub copy um message and
  12059. 9:58:09so on so let's start with message and
  12060. 9:58:12the syntax is the following exmail colon
  12061. 9:58:14colon message and we're going to wrap
  12062. 9:58:16everything in our message so we're going
  12063. 9:58:18to have H1 congratulations you have new
  12064. 9:58:21order this is for the vendor we give it
  12065. 9:58:23some styling and font size and text line
  12066. 9:58:26Center so then we're going to have the
  12067. 9:58:29view order details button uh at the
  12068. 9:58:31moment we don't have the order Details
  12069. 9:58:32page but we're going to create that
  12070. 9:58:34later and we will have that next we're
  12071. 9:58:36going to display the order summary
  12072. 9:58:38information so we're going to create the
  12073. 9:58:40table using this xmail we're going to
  12074. 9:58:42have um the following information like
  12075. 9:58:46this is the summary so order number the
  12076. 9:58:48corresponding number order date date we
  12077. 9:58:51have the order total which is going to
  12078. 9:58:52be nicely formatted order total price
  12079. 9:58:55for the order we're going to have
  12080. 9:58:57payment processing fee which is going to
  12081. 9:58:59be online payment commission but if for
  12082. 9:59:02some reason that doesn't exist we're
  12083. 9:59:03going to provide zero so that the
  12084. 9:59:05currency doesn't thr an exception if
  12085. 9:59:07that is null so also we have the
  12086. 9:59:10platform fee which is going to be the
  12087. 9:59:11website commission we're going to have
  12088. 9:59:13your earnings right here as well and I
  12089. 9:59:17think that's going to be all after we
  12090. 9:59:20which we're going to create second table
  12091. 9:59:22where we display all the items for the
  12092. 9:59:24vendor again table we have item quantity
  12093. 9:59:26and price we're going to iterate over
  12094. 9:59:29the order
  12095. 9:59:30items and we're going to create a couple
  12096. 9:59:32of TDS so inside the first TD I want to
  12097. 9:59:36put another table uh just to display
  12098. 9:59:40image and title next to each other so
  12099. 9:59:43here we have this
  12100. 9:59:45image get get first get image for
  12101. 9:59:49options and these are the variation type
  12102. 9:59:51option IDs so in a similar way how we
  12103. 9:59:54use this in the order view resource all
  12104. 9:59:57right so then we have the product title
  12105. 10:00:00so after which we're going to have
  12106. 10:00:02second TD we can collapse this second TD
  12107. 10:00:05which is going to be order quantity and
  12108. 10:00:07we're going to have thirdd which is
  12109. 10:00:09going to be the order item price and
  12110. 10:00:11then down below I'm just going to put a
  12111. 10:00:13panel here thanks for having business
  12112. 10:00:15with us and thank you message now let's
  12113. 10:00:18open check out completed and implement
  12114. 10:00:20this as well we need message we need H1
  12115. 10:00:22payment was completed successfully this
  12116. 10:00:25is for the buyer so here we have a list
  12117. 10:00:27of orders so here we have public
  12118. 10:00:30property collection of orders so we
  12119. 10:00:32access them we iterate and we display
  12120. 10:00:36table for each order so we have the
  12121. 10:00:38seller information because this email is
  12122. 10:00:41to buyer we're going to display the
  12123. 10:00:42seller
  12124. 10:00:43information uh the order has vendor user
  12125. 10:00:47which is a user user has access into
  12126. 10:00:49vendor and vendor has a store name let
  12127. 10:00:53me check if the user has definitely
  12128. 10:00:55access to vendor yes it has okay so just
  12129. 10:00:59like this we're printing the seller
  12130. 10:01:00information we're going to print the
  12131. 10:01:01order number as well and we're going to
  12132. 10:01:04print the number of items or the total
  12133. 10:01:06price for the items um
  12134. 10:01:10and yeah it should not be total price it
  12135. 10:01:13should be number of items let me finish
  12136. 10:01:14this and I will fix that so then we're
  12137. 10:01:17going to have second table here uh where
  12138. 10:01:20we're going to display the all the uh
  12139. 10:01:23all the items basically okay so here
  12140. 10:01:25we're going to iterate over order
  12141. 10:01:28items and for each order item we're
  12142. 10:01:31going to display something similar so
  12143. 10:01:33image and product title we're going to
  12144. 10:01:35display the order item quantity and
  12145. 10:01:38order item price finally we're going to
  12146. 10:01:40have buttom to view that specific order
  12147. 10:01:43details everything happens inside the
  12148. 10:01:45order Loop so everything is inside a
  12149. 10:01:48single order uh item so view order
  12150. 10:01:51details and after the forage loop we're
  12151. 10:01:53going to have this sub copy which is a
  12152. 10:01:55different type of text and we have this
  12153. 10:01:58panel as
  12154. 10:02:00well okay and finally thanks uh which is
  12155. 10:02:03going to be our application name Lara
  12156. 10:02:05store team or whatever so now let me fix
  12157. 10:02:10this what I said the items is going to
  12158. 10:02:13be order
  12159. 10:02:15items uh order
  12160. 10:02:18items size or count I think it's called
  12161. 10:02:21count and okay that's good now what I
  12162. 10:02:26want to do is to change the Styles
  12163. 10:02:29couple of styling so I'm going to go
  12164. 10:02:32into default CSS and first I want to
  12165. 10:02:35find logo and I want to remove this Max
  12166. 10:02:40he and width from here
  12167. 10:02:43okay also I want to find table here and
  12168. 10:02:48remove this margin buttom completely and
  12169. 10:02:52I want to change the uh text align on
  12170. 10:02:55the th text align to be left on the th
  12171. 10:03:01but more importantly I want to change
  12172. 10:03:04styles on the primary button so I'm
  12173. 10:03:06going to introduce a new new color 6 9
  12174. 10:03:1136 and
  12175. 10:03:14F5 so I want to put this color right
  12176. 10:03:18here uh um okay let me open
  12177. 10:03:23this header as
  12178. 10:03:26well here we have the word
  12179. 10:03:32laravel now let me open this
  12180. 10:03:35message and right here we have the
  12181. 10:03:37following header and if the uh header
  12182. 10:03:40name equals to LEL then it uses the L of
  12183. 10:03:44a logo right here so first I'm going to
  12184. 10:03:46change my application name into Lara
  12185. 10:03:52store so then if I open the message and
  12186. 10:03:55we are using this message in every
  12187. 10:03:58hour our blade file right here so then
  12188. 10:04:02right here I'm going to change this
  12189. 10:04:03header and inside the header I'm going
  12190. 10:04:07to provide we have this application URL
  12191. 10:04:09that's fine I'm going to remove this and
  12192. 10:04:12use image here and I'm going to provide
  12193. 10:04:15my own image and I actually have logo
  12194. 10:04:18for my website
  12195. 10:04:20so let me quickly show this to you so
  12196. 10:04:23this is my lar store branding and I'm
  12197. 10:04:26going to use the following
  12198. 10:04:30image white background or actually we
  12199. 10:04:33need maybe this
  12200. 10:04:38one yeah I think we can get this
  12201. 10:04:45one okay uh let me copy this and insert
  12202. 10:04:50side
  12203. 10:04:52public let me
  12204. 10:04:54create image and paste that Lara sto
  12205. 10:04:59Lara store Blue here so now we can
  12206. 10:05:04provide here
  12207. 10:05:06asset to be from image folder lore blue
  12208. 10:05:11PNG okay we can provide alt as well to
  12209. 10:05:14be whatever like
  12210. 10:05:17config um app do
  12211. 10:05:20name uh
  12212. 10:05:25logo okay so this is great so we changed
  12213. 10:05:29this primary button color and I want to
  12214. 10:05:33set the same color inside Tailwind
  12215. 10:05:35config
  12216. 10:05:37JS you can find this also in the day UI
  12217. 10:05:40documentation how to do this but here
  12218. 10:05:42I'm overriding this Daisy UI
  12219. 10:05:44configuration option providing themes to
  12220. 10:05:46be an array and I'm overriding the
  12221. 10:05:48default light theme uh requiring
  12222. 10:05:51everything existing all existing options
  12223. 10:05:55from this stui Source theming themes for
  12224. 10:05:57the light theme but I'm overriding the
  12225. 10:06:00primary color which basically means that
  12226. 10:06:05my uh the primary color of the button
  12227. 10:06:08will be changed as well so primary color
  12228. 10:06:11everywhere uh right now we just change
  12229. 10:06:15it okay awesome um I think we can
  12230. 10:06:20try we can try email sending can't we so
  12231. 10:06:24I think we have to authenticate first
  12232. 10:06:27let's authenticate with user
  12233. 10:06:31two let's add this into the cart and
  12234. 10:06:34this one as well let's click on this we
  12235. 10:06:37see
  12236. 10:06:39uh let's increase the quantity here and
  12237. 10:06:47here one thing I know noticed is that if
  12238. 10:06:50we open this Details page so we see
  12239. 10:06:52right here um different variations but
  12240. 10:06:56in the card we see we should not see
  12241. 10:06:59this image we should see something else
  12242. 10:07:01and we're going to fix this as well
  12243. 10:07:02click proceed to check
  12244. 10:07:05out let's enter the order
  12245. 10:07:17details let's open work hook
  12246. 10:07:21okay it lookss like it was
  12247. 10:07:25completed uh okay we have some error
  12248. 10:07:27about email
  12249. 10:07:30sending let's
  12250. 10:07:32open ll.
  12251. 10:07:35log one of the web hook actually was
  12252. 10:07:38completed with
  12253. 10:07:41um with the following message which
  12254. 10:07:43means that something was
  12255. 10:07:47wrong let's have a look up services DB
  12256. 10:07:50not
  12257. 10:07:53found okay where do we have this
  12258. 10:07:56DB this is let's open web
  12259. 10:08:02Hook app Services
  12260. 10:08:12DB let's see where this is coming
  12261. 10:08:17from card service to 200 okay art
  12262. 10:08:24Service
  12263. 10:08:28200 that was fixed no this is not it
  12264. 10:08:31that's something else that is old
  12265. 10:08:33message this is old message we're going
  12266. 10:08:35to have new one let's check the last
  12267. 10:08:39one invalid argument exception no hint
  12268. 10:08:44path defined for mail okay I see that
  12269. 10:08:51uh yeah I know the reason so we actually
  12270. 10:08:53using markdown syntax so we have to
  12271. 10:08:56provide right here markdown as well so
  12272. 10:08:59let's
  12273. 10:09:00open check out completed as well and I'm
  12274. 10:09:04going to change these into
  12275. 10:09:12markdown let
  12276. 10:09:13[Music]
  12277. 10:09:16me we're going to do this one once again
  12278. 10:09:20so let's click set to cart both of them
  12279. 10:09:24view card proceed to check
  12280. 10:09:37out let's open web
  12281. 10:09:41hooks it looks like everything
  12282. 10:09:46worked what about emails
  12283. 10:09:50let's
  12284. 10:09:51open Local Host
  12285. 10:09:55825 okay we have three new emails that's
  12286. 10:09:58so awesome so this goes
  12287. 10:10:02to this goes to vendor
  12288. 10:10:072
  12289. 10:10:10okay it is the ugliest possible email we
  12290. 10:10:14could ever have right
  12291. 10:10:20that happens because of the
  12292. 10:10:22formatting so this x component we we
  12293. 10:10:25shouldn't have it like this let
  12294. 10:10:28me format this so we should we when
  12295. 10:10:32using markdown Syntax for sending emails
  12296. 10:10:36you shouldn't have it formatted like
  12297. 10:10:37this so you basically should disable
  12298. 10:10:40autof formatting in your IDE because it
  12299. 10:10:43ruins everything I think this is going
  12300. 10:10:45to work nicely so we can see this check
  12301. 10:10:48out
  12302. 10:10:50completed as
  12303. 10:10:55well
  12304. 10:10:57okay also to my image to my logo image
  12305. 10:11:02I'm going to give it class logo because
  12306. 10:11:04we have that logo defined
  12307. 10:11:06here and it should take the proper
  12308. 10:11:08classes now I'm going to try to make new
  12309. 10:11:12order okay I received new emails
  12310. 10:11:14congratulations we have new order we
  12311. 10:11:16have this nice logo we have the button
  12312. 10:11:18now it looks like more or less okay
  12313. 10:11:21actually I actually like this so we have
  12314. 10:11:23this order summary information here
  12315. 10:11:25everything uh the prices are actually
  12316. 10:11:28break down so uh my earnings is 13.05
  12317. 10:11:33this is the platform fee this is the
  12318. 10:11:35payment processing fee IND the item this
  12319. 10:11:37is emailed to the second vendor I see
  12320. 10:11:40also prices break down here and the
  12321. 10:11:43email to the buyer is actually still
  12322. 10:11:47messed up which I'm going to fix
  12323. 10:11:51so I'm going to format these tables like
  12324. 10:11:58this now I made one more order in this
  12325. 10:12:01case I received the correct information
  12326. 10:12:03payment was completed successfully
  12327. 10:12:05seller information order number items
  12328. 10:12:07total we see the item view order details
  12329. 10:12:10and for the second vendor seller is
  12330. 10:12:12Zoomer now we have different information
  12331. 10:12:15here a VI order details this is up copy
  12332. 10:12:18and this is panel so this is just I put
  12333. 10:12:21this for you if you want to provide
  12334. 10:12:23additional information you can easily do
  12335. 10:12:25that and I think this looks really nice
  12336. 10:12:29and when we Implement actually order
  12337. 10:12:31Details page we will be able to link
  12338. 10:12:33these orders to the proper pages
  12339. 10:12:38and yeah that's
  12340. 10:12:41great also I just try to create new
  12341. 10:12:44account and because we globally changed
  12342. 10:12:46the message and the button we right now
  12343. 10:12:49now see not lot of a logo but this is
  12344. 10:12:51our logo and we see this verify email
  12345. 10:12:53address um button stying different as
  12346. 10:12:57well so it's pretty nice so it's a
  12347. 10:12:59customized uh to our
  12348. 10:13:02application and we also see right here
  12349. 10:13:04our application name now I want to start
  12350. 10:13:07working on vendor Details page vendor
  12351. 10:13:09profile page so when we click profile
  12352. 10:13:12right here we see only the profile
  12353. 10:13:14information generic profile information
  12354. 10:13:16but I want to add right here on the
  12355. 10:13:18right side vendor details such as the
  12356. 10:13:21vendor store name vendor address and if
  12357. 10:13:24you are a regular user and want to
  12358. 10:13:26become a vendor as well right here
  12359. 10:13:28you're going to have a button become a
  12360. 10:13:30vendor and once you are a vendor then
  12361. 10:13:33you can connect to stripe account using
  12362. 10:13:37stripe connect and the marketpl you will
  12363. 10:13:40be connected into Marketplace basically
  12364. 10:13:42and then you will be able to uh do these
  12365. 10:13:46purchases or selling your products
  12366. 10:13:49okay and I'm going to also implement the
  12367. 10:13:51vendor profile page which basically
  12368. 10:13:53means a separate URL for you uh where
  12369. 10:13:58you have the store name in the URL and
  12370. 10:14:00you can copy and send this to anybody
  12371. 10:14:04else uh which will have a list of your
  12372. 10:14:07products only and nothing else okay so
  12373. 10:14:10we're going to start with the back
  12374. 10:14:11inside and I'm going to create a new
  12375. 10:14:13controller if I don't have it vendor
  12376. 10:14:16controller is something we don't have so
  12377. 10:14:18let's execute pH P artisan
  12378. 10:14:22make
  12379. 10:14:24controller
  12380. 10:14:25vendor
  12381. 10:14:27controller we hit the enter okay vendor
  12382. 10:14:30controller was created now let's open
  12383. 10:14:33vendor controller and I'm going to
  12384. 10:14:35Define two methods right here one is
  12385. 10:14:38going to be profile where we accept the
  12386. 10:14:41vendor details right here let's import
  12387. 10:14:44this
  12388. 10:14:44vendor and second is going to be store
  12389. 10:14:49where we're going to store our details
  12390. 10:14:51let's accept request right here I'm
  12391. 10:14:54going to also open vendor and I'm going
  12392. 10:14:56to change few things first I'm going to
  12393. 10:14:58add that the primary key of the Vendor
  12394. 10:15:00model is user ID not the ID which is the
  12395. 10:15:03default one we're going to also add a
  12396. 10:15:05scope right here which is going to
  12397. 10:15:07whether this specific vendor is eligible
  12398. 10:15:10for payout or not okay so eligible for
  12399. 10:15:14payout um and uh here we simply return
  12400. 10:15:18this status of the vendor needs to be uh
  12401. 10:15:21approved and next we're going to define
  12402. 10:15:23the relation into the user and now let's
  12403. 10:15:26import these things so we're going to
  12404. 10:15:27import the belongs to we're going to
  12405. 10:15:29import the vendor status enam and
  12406. 10:15:31Builder as
  12407. 10:15:33well okay cool now on the front end side
  12408. 10:15:37into Pages profile we have this edit and
  12409. 10:15:43inside um maybe inside
  12410. 10:15:47arals I'm going to create new component
  12411. 10:15:51let's call
  12412. 10:15:52this vendor details and this needs to be
  12413. 10:15:57jsx
  12414. 10:16:01file okay before I implement this vendor
  12415. 10:16:05details I want to install new package
  12416. 10:16:08which is going to be necessary for
  12417. 10:16:09stripe connect stripe
  12418. 10:16:13connect LEL if we search for this we are
  12419. 10:16:17going to find a
  12420. 10:16:23package uh it doesn't find so let's
  12421. 10:16:25search for lotel stripe connect I went
  12422. 10:16:29to GitHub
  12423. 10:16:32URL the username is uh Simon Simon um
  12424. 10:16:39hemp I
  12425. 10:16:41think if we search for this that's it
  12426. 10:16:44that's what I used and it is working
  12427. 10:16:51okay yeah this is it so let me actually
  12428. 10:16:54copy this so we're going to install this
  12429. 10:16:56package I'm going to bring up the
  12430. 10:16:58terminal and let's
  12431. 10:17:00execute composer require and then you
  12432. 10:17:03have a look so we're going to set up the
  12433. 10:17:05stripe key which is going to be our
  12434. 10:17:08publishable key we already have secret
  12435. 10:17:11stripe secret and then we're going to
  12436. 10:17:13execute migrate so let's use this stripe
  12437. 10:17:17key which we're going to get from from
  12438. 10:17:19our
  12439. 10:17:21homepage this is the publishable key
  12440. 10:17:24let's open
  12441. 10:17:27do and we're going to provide here
  12442. 10:17:32stripe key equals this now let's open.
  12443. 10:17:37example as well and put them right
  12444. 10:17:45here next we're going to execute this
  12445. 10:17:47mic rate
  12446. 10:17:49once the package is installed only after
  12447. 10:17:51this so we open the package is installed
  12448. 10:17:54now let's execute PHP Artis and migrate
  12449. 10:17:56so the migration has been applied and it
  12450. 10:17:58added stripe connect details to users
  12451. 10:18:00table now if we refresh the database and
  12452. 10:18:03open users table we're going to see two
  12453. 10:18:05new columns stripe account ID and stripe
  12454. 10:18:09account active Okay so after this
  12455. 10:18:13basically we have to use payable on the
  12456. 10:18:16model so we're going to use
  12457. 10:18:19that
  12458. 10:18:22trade payable and we will be able to
  12459. 10:18:26send uh on our user we can transfer
  12460. 10:18:29something from our account from the
  12461. 10:18:31platform uh application account we will
  12462. 10:18:34be able to transfer
  12463. 10:18:35something uh to that user or from from
  12464. 10:18:38one user we will be able to transfer
  12465. 10:18:41into um somebody else so here we need
  12466. 10:18:44this connect so I'm going to copy this
  12467. 10:18:46part uh actually let's open stripe
  12468. 10:18:50controller and Define this connect
  12469. 10:18:52function and we're going to check if the
  12470. 10:18:54user uh get stripe account ID doesn't
  12471. 10:18:58exist then we are going to create stripe
  12472. 10:19:01account
  12473. 10:19:02ID and then if the user is not active
  12474. 10:19:06then we're going to redirect user into
  12475. 10:19:09the strap account link page and the user
  12476. 10:19:12will start the
  12477. 10:19:14onboarding um procedure to get get
  12478. 10:19:17connected to our plat form interface and
  12479. 10:19:20once this is done we're going to
  12480. 10:19:22redirect back with if this doesn't
  12481. 10:19:25happen basically your account is already
  12482. 10:19:27connected now I'm going to open rules
  12483. 10:19:30page and we're going to Define this URL
  12484. 10:19:33stripe connect on the connect method and
  12485. 10:19:36we're going to provide the stripe
  12486. 10:19:38connect name as well and I'm going to
  12487. 10:19:40add a middle we that this is only for
  12488. 10:19:42vendor users R needs to be vendor it is
  12489. 10:19:45not for somebody else and right here we
  12490. 10:19:49have the stripe connect and we are
  12491. 10:19:50listening into post I want to make one
  12492. 10:19:53changes inside put strap up PHP so I
  12493. 10:19:57disabled csrf validation on every route
  12494. 10:20:00starting with stripe slash which is not
  12495. 10:20:03exactly ideal because here we also have
  12496. 10:20:06stripe slash something so I'm going to
  12497. 10:20:09change this into web hook directly
  12498. 10:20:12stripe web hook for stripe web hook
  12499. 10:20:14which is for our web hook where stripe
  12500. 10:20:16will send us the data that's the only
  12501. 10:20:19place where we disable the csrf token
  12502. 10:20:22validation okay so we
  12503. 10:20:25have we have done the bacon side I think
  12504. 10:20:29correctly uh let me show you something
  12505. 10:20:33so if we just try to access stripe slash
  12506. 10:20:38connect uh this will not work because
  12507. 10:20:42the method yeah this method supports
  12508. 10:20:43only Post Yeah we have to submit
  12509. 10:20:45something on that we're going to do this
  12510. 10:20:48um but before I do this I'm going to
  12511. 10:20:50create one uh resource and this going to
  12512. 10:20:54be for the authenticated user details
  12513. 10:20:57like inside this handling njs request we
  12514. 10:21:00return this user information but I want
  12515. 10:21:02actually to change that returned user
  12516. 10:21:05information and um pass this into
  12517. 10:21:08resource because we return a lot of
  12518. 10:21:10information which is something I don't
  12519. 10:21:13want and I also want to return a couple
  12520. 10:21:15of other
  12521. 10:21:16things uh okay so let let me execute PHP
  12522. 10:21:19artisan
  12523. 10:21:21make resource let's call this out
  12524. 10:21:27user resource out user resource awesome
  12525. 10:21:31now let's open out user
  12526. 10:21:35resource and I'm going to adjust
  12527. 10:21:41this we need ID of the user we need
  12528. 10:21:44email email verify date we need the name
  12529. 10:21:47and here I'm going to return return
  12530. 10:21:48actually
  12531. 10:21:49permissions so if you pay attention
  12532. 10:21:51we're going to see that so we added
  12533. 10:21:56permissions and roles on the user and if
  12534. 10:21:58we open user model we see that this has
  12535. 10:22:00roles and it has permissions as well so
  12536. 10:22:03far on the front end side on the react
  12537. 10:22:05side we have not used that permissions
  12538. 10:22:07and roles to hide or show something we
  12539. 10:22:09will need this to do it so that's why we
  12540. 10:22:12are adding permissions right here and
  12541. 10:22:15I'm mapping this e permissions object
  12542. 10:22:17into uh just permission name
  12543. 10:22:20additionally we need the role names as
  12544. 10:22:22well but we need the vendor details and
  12545. 10:22:25we need the stripe account active as
  12546. 10:22:27well and the vendor details so stripe
  12547. 10:22:29account active is going to be the
  12548. 10:22:31Boolean of stripe account active from
  12549. 10:22:33the user table what was just added if
  12550. 10:22:36the vendor doesn't exist we return null
  12551. 10:22:38if the vendor exists we're going to
  12552. 10:22:40return the status of the vendor a vendor
  12553. 10:22:43the status label itself which we're
  12554. 10:22:45going to get this from vendor status and
  12555. 10:22:49let's actually open vendor status NM and
  12556. 10:22:52I'm going to Define two methods right
  12557. 10:22:53here first is going to be labels and
  12558. 10:22:56we're going to associate uh each enm
  12559. 10:23:00case into its label like this and I'm
  12560. 10:23:03going to also Define colors because I
  12561. 10:23:05will need these in the filament admin to
  12562. 10:23:08display all vendors for admin users so
  12563. 10:23:12gray success and danger for different
  12564. 10:23:15states cool now here let's continue and
  12565. 10:23:20we um we need store name to return in
  12566. 10:23:23this out user resource if the vendor
  12567. 10:23:25exists uh we need store address and
  12568. 10:23:29cover image uh and finally we're going
  12569. 10:23:32to import this vendor status inm right
  12570. 10:23:34here now let's go into handle inertia
  12571. 10:23:37request and we're going to check if the
  12572. 10:23:39user exists we are going to return new
  12573. 10:23:43out user out user resource providing
  12574. 10:23:48request user otherwise we're going to
  12575. 10:23:50return null and let's disable
  12576. 10:23:54wrap
  12577. 10:23:58here okay so now we are returning this
  12578. 10:24:00out user resource we have implemented
  12579. 10:24:03the backend side fully ready and I'm
  12580. 10:24:05going to open vendor details and I'm
  12581. 10:24:08going to define the component so first
  12582. 10:24:10let's import a couple of components we
  12583. 10:24:11will need in the spender details we need
  12584. 10:24:14primary button use form use page from
  12585. 10:24:16inertia JS react and we need um
  12586. 10:24:20following things we need secondary
  12587. 10:24:21button we need model we need input label
  12588. 10:24:24and text input uh input ER and I think
  12589. 10:24:27that's it then we're going to Define
  12590. 10:24:29vendor
  12591. 10:24:30details and we're going to accept a
  12592. 10:24:32class name optionally class name and now
  12593. 10:24:35let's define the states so we are going
  12594. 10:24:37to have the following states to show the
  12595. 10:24:40confirmation dialogue to whether the
  12596. 10:24:43current user wants to become a vendor or
  12597. 10:24:45not so we want to display that button
  12598. 10:24:48become a vendor clicking on which will
  12599. 10:24:50trigger the confirmation dialogue and
  12600. 10:24:53we're going to save that it's a Boolean
  12601. 10:24:55thing so we have this access message as
  12602. 10:24:58well which by default empty string we're
  12603. 10:25:00going to get the user information we're
  12604. 10:25:02going to get the csrf token as well
  12605. 10:25:05right here we will need that and then
  12606. 10:25:07we're going to define the form using
  12607. 10:25:09this use form um injs user form hook so
  12608. 10:25:14we're going to take the data set data
  12609. 10:25:16errors post processing in recently
  12610. 10:25:18sucessful from this use form and we're
  12611. 10:25:21going to provide the um store name to be
  12612. 10:25:24user vendor store name or the username
  12613. 10:25:29and let's also open types and Define
  12614. 10:25:32right here stripe account active buan
  12615. 10:25:34vendor
  12616. 10:25:36status um status label store name store
  12617. 10:25:40address and cover image now the ER is
  12618. 10:25:44gone right here next we're going to
  12619. 10:25:46define the store address if the vent
  12620. 10:25:48exists so we use this question mark for
  12621. 10:25:51that store address then we're going to
  12622. 10:25:53listen to store name change okay and
  12623. 10:25:57this is going to be on input HTML input
  12624. 10:25:59elements whenever this happens we are
  12625. 10:26:01going to put that inside store name
  12626. 10:26:04right here however I'm going to convert
  12627. 10:26:07this into lowercase and I'm going to
  12628. 10:26:09also generate slug out of it so it's
  12629. 10:26:11going to be replace all the wi spaces
  12630. 10:26:14using regx with dashes convert
  12631. 10:26:17everything to lower case replace wi
  12632. 10:26:19spaces into dashes okay cool next I'm
  12633. 10:26:22going to create new form event handler
  12634. 10:26:24to become a vendor so we prevent the
  12635. 10:26:27default on submission and then we send
  12636. 10:26:29the request on vendor. store which we're
  12637. 10:26:31going to
  12638. 10:26:33Define okay and on success we're going
  12639. 10:26:36to close the confirmation model because
  12640. 10:26:38that will be only triggered on the
  12641. 10:26:40vendor uh the confirmation model so we
  12642. 10:26:43close the model we we will create this
  12643. 10:26:45close model um in a moment and then uh
  12644. 10:26:49we display this success message you can
  12645. 10:26:52uh now create and publish products so we
  12646. 10:26:55we can optionally handle this on ER as
  12647. 10:26:57well print something or do something I
  12648. 10:26:59just wanted to give that information to
  12649. 10:27:01you so then I'm going to also listen to
  12650. 10:27:03update vendor information to update the
  12651. 10:27:06store name or the store address things
  12652. 10:27:08like that so I'm going to send the
  12653. 10:27:10request into vendor store again and on
  12654. 10:27:13success uh again we have to close the
  12655. 10:27:16model and show some details the um your
  12656. 10:27:20details were updated okay now let's uh
  12657. 10:27:25create this close model which will set
  12658. 10:27:27this show become vendor confirmation
  12659. 10:27:30into false and now we can focus on the
  12660. 10:27:33template itself so we have the following
  12661. 10:27:35section uh and if recently successful is
  12662. 10:27:39true we're going to display the
  12663. 10:27:40following toast with the success uh
  12664. 10:27:44message okay then we have the header
  12665. 10:27:47with the vendor d details at the top
  12666. 10:27:49we're going to have we're going to see
  12667. 10:27:51what's the vendor status if the vendor
  12668. 10:27:53status is pending then we're going to
  12669. 10:27:55display the following BGE with warning
  12670. 10:27:59uh and we're going to use this status
  12671. 10:28:00label which we return from this out user
  12672. 10:28:05resource from from here okay so if the
  12673. 10:28:10vendor status is rejected we're going to
  12674. 10:28:12display um error page if it's approved
  12675. 10:28:15we're going to display success page
  12676. 10:28:17below this header we're going to have
  12677. 10:28:18we're going to check the user vendor
  12678. 10:28:20details if the vendor doesn't exist we
  12679. 10:28:22are going to create this primary button
  12680. 10:28:24become a vendor we're going to listen in
  12681. 10:28:27on click and we're going to trigger that
  12682. 10:28:30model show set show become vendor
  12683. 10:28:33confirmation and this will show the
  12684. 10:28:35model okay so however if the vendor
  12685. 10:28:38exists then we have to do a lot more so
  12686. 10:28:41we have to create the form to update the
  12687. 10:28:43vendor inside which we're going to put
  12688. 10:28:45this input label store name then the ual
  12689. 10:28:48input which is which's going to have the
  12690. 10:28:50value onchange required this Focus all
  12691. 10:28:52these things so we're going to also have
  12692. 10:28:55this input error which looks at this
  12693. 10:28:57error's store name we're going to create
  12694. 10:29:00second input for store address which is
  12695. 10:29:02going to be text area we are listening
  12696. 10:29:04on change and setting inside store
  12697. 10:29:06address we're going to have also the
  12698. 10:29:09input error down below and then we're
  12699. 10:29:11going to have the primary button which
  12700. 10:29:13will trigger the form submission the
  12701. 10:29:14button is disabled if the form is in
  12702. 10:29:16processing stage
  12703. 10:29:19but below this form we have another form
  12704. 10:29:21and this is going to be stripe connect
  12705. 10:29:23form so if the user is vendor we show
  12706. 10:29:28the vendor update form but we also show
  12707. 10:29:31stripe connect form okay so inside this
  12708. 10:29:34stripe connect we are using the csrf
  12709. 10:29:38token here method is post obviously and
  12710. 10:29:42we now check if stripe account is
  12711. 10:29:46active okay then if it's already active
  12712. 10:29:50then we display the following message
  12713. 10:29:51you are successfully connected to
  12714. 10:29:53stripe however if the stripe is not
  12715. 10:29:57active so then we have um sorry uh we
  12716. 10:30:02display the button in any case but the
  12717. 10:30:05button is disabled if stripe account is
  12718. 10:30:07active so they connect to stripe button
  12719. 10:30:10so we still want the user to see
  12720. 10:30:12connector stripe but if it's uh already
  12721. 10:30:15active then we're going to show it as
  12722. 10:30:16disabled okay and then down below we're
  12723. 10:30:19going to display this model show
  12724. 10:30:20confirmation vendor on close we're going
  12725. 10:30:22to call this uh close model we're going
  12726. 10:30:25to have this another forming side which
  12727. 10:30:28will um which will call this become
  12728. 10:30:32vendor on submission and we're going to
  12729. 10:30:34have this confirmation message are ISU
  12730. 10:30:36to become a vendor then we're going to
  12731. 10:30:38have this cancel button and primary
  12732. 10:30:40button which will trigger the form
  12733. 10:30:42submission
  12734. 10:30:45okay uh okay so we have that V
  12735. 10:30:48details kind of
  12736. 10:30:50ready uh however it's my B so these
  12737. 10:30:55components are actually inside core
  12738. 10:30:59folder so we want to get this from core
  12739. 10:31:03so I copied this from another project
  12740. 10:31:06that's why we we didn't have it in core
  12741. 10:31:09so okay this is great we need it like
  12742. 10:31:11this uh now we're going to open
  12743. 10:31:14edit edit TS6 in here we have
  12744. 10:31:19this one
  12745. 10:31:22div uh another
  12746. 10:31:25div cool we have this MX Auto
  12747. 10:31:30here I'm going to remove a few things
  12748. 10:31:33I'm going to remove them uh I'm going to
  12749. 10:31:36also reduce the pading way here but I'm
  12750. 10:31:39going to give it greed so I want grid
  12751. 10:31:42layout grid calls one and above medium
  12752. 10:31:47we need grid calls three let's give it
  12753. 10:31:50also G four and padding four now I want
  12754. 10:31:55to have something like this so
  12755. 10:31:58everything what we have so far will be
  12756. 10:32:01in the first div
  12757. 10:32:05here and we can give this
  12758. 10:32:08one um space y six and call span two
  12759. 10:32:17however we want one second div as well
  12760. 10:32:20which will
  12761. 10:32:21have background
  12762. 10:32:23white uh padding for let's give it
  12763. 10:32:26Shadow as well above small we need
  12764. 10:32:29rounded
  12765. 10:32:31LG uh and let's give it above small uh
  12766. 10:32:35pading eight and on dark mode we can
  12767. 10:32:39give it also BG
  12768. 10:32:41gray 800 so inside this div we are going
  12769. 10:32:45to put this vendor detail tells what we
  12770. 10:32:48just created so let me save this and if
  12771. 10:32:51we didn't have any errors we're going to
  12772. 10:32:53see what we see right now vendor details
  12773. 10:32:57right
  12774. 10:32:58here um of course the layout is not
  12775. 10:33:13identical why it is not
  12776. 10:33:16identical I I am not quite
  12777. 10:33:19sure yeah it is good yeah okay so we
  12778. 10:33:23have the vendor details and when we
  12779. 10:33:24click on this become vendor it is going
  12780. 10:33:26to bring up this um confirmation are you
  12781. 10:33:28sure you want to become a vendor of
  12782. 10:33:30course cancel Works click on confirm
  12783. 10:33:33which send some requests but we don't
  12784. 10:33:36have the backend ready I guess so we're
  12785. 10:33:39going to open vendor
  12786. 10:33:42controller and we have to implement
  12787. 10:33:44these
  12788. 10:33:46methods I'm going to implement store
  12789. 10:33:48first and we're going to validate the
  12790. 10:33:50request and the store name needs to be
  12791. 10:33:52required and it must be reex uh with
  12792. 10:33:56only the following Fields so uh
  12793. 10:33:58lowercase from A to Z then only digits
  12794. 10:34:02and dashes nothing else is actually
  12795. 10:34:03allowed and the store name needs to be
  12796. 10:34:05also unique among vendors store name I'm
  12797. 10:34:08going to add store address as well which
  12798. 10:34:11can be n actually and I'm going to also
  12799. 10:34:13customize the message for this store
  12800. 10:34:16name reex so I'm just going to give it
  12801. 10:34:18text store name must only contain
  12802. 10:34:20lowercase alpha numeric characters and
  12803. 10:34:22dashes so if the validation happens we
  12804. 10:34:25know that the everything is good now
  12805. 10:34:27we're going to get the user information
  12806. 10:34:29and we're going to access the vendor as
  12807. 10:34:31well so if the vendor exists we're going
  12808. 10:34:33to take the vendor if the vendor doesn't
  12809. 10:34:35exist we are creating new vendor this is
  12810. 10:34:38kind of create vendor or update vendor
  12811. 10:34:41method it does both so then once we have
  12812. 10:34:44the vendor we're going to provide the
  12813. 10:34:46user ID if it's if we are creating then
  12814. 10:34:48we need this if we are updating then we
  12815. 10:34:51are simply assigning the same user ID it
  12816. 10:34:53doesn't hurt so here we're going to
  12817. 10:34:55assign the vendor status inm to be
  12818. 10:34:57approved and we are going to provide the
  12819. 10:35:00store name from the request store name
  12820. 10:35:03and we're going to provide the store
  12821. 10:35:04address and we're going to save the
  12822. 10:35:06vendor information and we're going to
  12823. 10:35:08give that user also vendor role so at
  12824. 10:35:12the moment we don't uh we have Auto
  12825. 10:35:15approval of vendors so so every time
  12826. 10:35:18vendor is created vendor is approved but
  12827. 10:35:20of course this can be changed and um
  12828. 10:35:22every new vendor can be manual uh it can
  12829. 10:35:26have status pending which would would
  12830. 10:35:28require approval from admin this can be
  12831. 10:35:30easily changed you can do this I will
  12832. 10:35:32probably do this in the future um on
  12833. 10:35:35this project as well not probably for
  12834. 10:35:38sure okay so now we have uh we have that
  12835. 10:35:42method actually ready so now let me try
  12836. 10:35:46to click on confirm
  12837. 10:35:50again uh okay let's refresh it I think
  12838. 10:35:54vendor tore yeah we don't have this
  12839. 10:35:56method vendor
  12840. 10:35:59store let's open web.php
  12841. 10:36:02and user needs to be authenticated and
  12842. 10:36:05verified to be able
  12843. 10:36:08to uh send that
  12844. 10:36:11request let's
  12845. 10:36:14create right here so wrote
  12846. 10:36:19post um we can call this
  12847. 10:36:23become
  12848. 10:36:26a
  12849. 10:36:28vendor then we use vendor controller
  12850. 10:36:32store here and we are going to
  12851. 10:36:36provide name to be vendor store now let
  12852. 10:36:40me refresh the
  12853. 10:36:43page click on this and click on confirm
  12854. 10:36:48thanks for signing up before getting
  12855. 10:36:50started could you verify your email
  12856. 10:36:52address by clicking on the link we just
  12857. 10:36:54emailed to you okay
  12858. 10:36:57so it looks like I am unverified user so
  12859. 10:37:00I have to resend verification
  12860. 10:37:05email I received that this is the new
  12861. 10:37:07user user
  12862. 10:37:09three uh click verify email
  12863. 10:37:13address we did the verification
  12864. 10:37:17now we can access into my profile
  12865. 10:37:23page become a vendor click on
  12866. 10:37:26confirm
  12867. 10:37:28and that's it seems like that
  12868. 10:37:31worked if we refresh the page what do we
  12869. 10:37:35see we still see become a vendor now I'm
  12870. 10:37:38curious what happens is the vendor
  12871. 10:37:40created or not let's have a
  12872. 10:37:44look okay no new vendor is created
  12873. 10:37:47probably
  12874. 10:37:49because
  12875. 10:37:51um it wasn't
  12876. 10:37:55saved it should be saved
  12877. 10:38:01right okay let's see let's dump the
  12878. 10:38:04vendor and have a look we have to debug
  12879. 10:38:07things when it's not
  12880. 10:38:14working become a vendor
  12881. 10:38:21post okay why does not come here
  12882. 10:38:25probably validation is
  12883. 10:38:29failed yeah definitely validation is
  12884. 10:38:32failed when we try to okay now makes
  12885. 10:38:36sense um this is more like for updates
  12886. 10:38:39so when we try to become a
  12887. 10:38:43vendor we don't provide this tour name
  12888. 10:38:46right and we don't provide the
  12889. 10:38:49address
  12890. 10:38:52details
  12891. 10:38:54uh right here we have this sors in the
  12892. 10:38:57Red Direct store name store name must
  12893. 10:38:59only contain uh lowercase alphanim
  12894. 10:39:02characters and dashes and this is
  12895. 10:39:05because when become a vendor we provide
  12896. 10:39:08the store name to be user space three
  12897. 10:39:12and I know how to fix this if we go in
  12898. 10:39:15the vendor details right right here we
  12899. 10:39:18provide if the store name if the vendor
  12900. 10:39:20doesn't exist or the store name doesn't
  12901. 10:39:22exist we're going to provide the
  12902. 10:39:23user.name so let's convert this into
  12903. 10:39:27lowercase and then I'm going to call
  12904. 10:39:29replace on this with every white space
  12905. 10:39:34globally to be replaced with dashes so
  12906. 10:39:37if I refresh this right
  12907. 10:39:40now and try to become a vendor now it
  12908. 10:39:43should
  12909. 10:39:44work at least we got uh on the the back
  12910. 10:39:47side because we provided right now the
  12911. 10:39:50following store
  12912. 10:39:53name okay so what is this up enum okay
  12913. 10:39:56we don't have that
  12914. 10:39:58label let's open vendor status
  12915. 10:40:03enam and I'm going to add one more
  12916. 10:40:05method right here which is going to be a
  12917. 10:40:07label and it's going to return string
  12918. 10:40:11matching with a
  12919. 10:40:13case now I think we are already
  12920. 10:40:19vendor as you see so vendor details is
  12921. 10:40:22approved we see the store name we see uh
  12922. 10:40:24the address details and we see this
  12923. 10:40:26update test click on update store name
  12924. 10:40:30has already been taken on the
  12925. 10:40:34update we have to exclude
  12926. 10:40:38ourself so let me actually get this user
  12927. 10:40:41before the validation and I'm going to
  12928. 10:40:43now change this into using
  12929. 10:40:48uh rule unique so let me change
  12930. 10:40:52that
  12931. 10:40:54rule that was different rule probably
  12932. 10:40:57rule that needs to be illuminate
  12933. 10:41:00validation rule we need unique vendor
  12934. 10:41:02tore name and we need to provide um
  12935. 10:41:08ignore here
  12936. 10:41:10ignore user ID user ID is the primary
  12937. 10:41:15key of the vendor table
  12938. 10:41:18um that should
  12939. 10:41:20work now click on
  12940. 10:41:23update and let's refresh the page I
  12941. 10:41:26think the error stayed
  12942. 10:41:29there test click on update store name
  12943. 10:41:32has already been
  12944. 10:41:36taken from the vendor store name we are
  12945. 10:41:40using user ID which is the primary key
  12946. 10:41:45of
  12947. 10:41:48model
  12948. 10:41:56right uh that ignor actually doesn't
  12949. 10:41:58look at the Vendor model so we have to
  12950. 10:42:01provide user ID right here as a second
  12951. 10:42:03argument where it needs to check that ID
  12952. 10:42:07now if we open the
  12953. 10:42:09browser and we're going to
  12954. 10:42:12provide something and click on update
  12955. 10:42:14now this
  12956. 10:42:15works uh
  12957. 10:42:20cool okay now let's try to connect to
  12958. 10:42:23stripe so I'm going to click on this
  12959. 10:42:25connect to stripe and let's see what
  12960. 10:42:27happens you can only create new accounts
  12961. 10:42:30if you have signed up for connect okay
  12962. 10:42:32so this is the thing so first we have to
  12963. 10:42:35uh set up the connect in our stripe
  12964. 10:42:39dashboard okay so let me actually open
  12965. 10:42:43the stripe dashboard and click on
  12966. 10:42:45connect and we have to follow this and
  12967. 10:42:49feel some information so on our
  12968. 10:42:53platform stripe dashboard we have to set
  12969. 10:42:56up the connect power your platform with
  12970. 10:42:58connect click get started I'm going to
  12971. 10:43:00click on continue right here it asks me
  12972. 10:43:03a few questions how I want the flow uh
  12973. 10:43:06to be implemented so there are three
  12974. 10:43:08options two options right here seller
  12975. 10:43:10will collect payments directly and buyer
  12976. 10:43:13will purchase from you and each of them
  12977. 10:43:16has its own options like buyer will
  12978. 10:43:18purchase goods and services directly
  12979. 10:43:20from sellers buyers will be anywhere of
  12980. 10:43:23your platform sellers will appear on
  12981. 10:43:25receipts sellers will be responsible for
  12982. 10:43:28refunds and disputes um and so on so you
  12983. 10:43:33have to read this and decide which
  12984. 10:43:36option you
  12985. 10:43:37want so in my case this is what I want
  12986. 10:43:40to where I want to go uh I will receive
  12987. 10:43:43all the purchases and then I will pay
  12988. 10:43:46out to the sellers once in a while so
  12989. 10:43:49I'm going to click on continue here I'm
  12990. 10:43:51going to click on review so you you make
  12991. 10:43:54sure you read this carefully I have
  12992. 10:43:56actually read this and accepted this
  12993. 10:43:58while I Was preparing and then click on
  12994. 10:44:01continue okay I'm going to choose the
  12995. 10:44:03second option here click on continue
  12996. 10:44:06then here I'm going to choose e-commerce
  12997. 10:44:08products click on continue yes they are
  12998. 10:44:11similar not sure so I want on boarding
  12999. 10:44:14hosted by stripe which is the easiest
  13000. 10:44:16one click on continue the first one
  13001. 10:44:19Express dashboard and then this is our
  13002. 10:44:21summary I'm going to click on
  13003. 10:44:23continue and now it is going to set up
  13004. 10:44:27the connect for us okay so right now we
  13005. 10:44:30are not in the test mode and if we are
  13006. 10:44:33not in the test mode we have to go
  13007. 10:44:35through all these test uh the all these
  13008. 10:44:38steps and activate our account and so on
  13009. 10:44:41but I actually want this only in the
  13010. 10:44:43test mode okay I'm not going to activate
  13011. 10:44:46this for the tutorial but of course if
  13012. 10:44:48you are building something on production
  13013. 10:44:51you have to go these tabs add your
  13014. 10:44:53branding access your integration guide
  13015. 10:44:55try out your integration so you're going
  13016. 10:44:57to do all these things and activate your
  13017. 10:44:59account okay but now I have actually
  13018. 10:45:03connected connection already um set up
  13019. 10:45:06the stripe connect is already set up and
  13020. 10:45:08inside connected accounts I don't have
  13021. 10:45:10any accounts at the moment and this is
  13022. 10:45:12what I'm going to do let's go
  13023. 10:45:15back and I'm going to click on this
  13024. 10:45:18connect to stripe okay so now the seller
  13025. 10:45:21onboarding this is the seller onboarding
  13026. 10:45:24screen okay and uh the email is not
  13027. 10:45:27needed in the test mode however we have
  13028. 10:45:29to provide our actual phone number right
  13029. 10:45:32here even though we are in the test mode
  13030. 10:45:34let me pause the recording I don't want
  13031. 10:45:36to reveal my phone
  13032. 10:45:38number okay I entered my phone number it
  13033. 10:45:41send sent me to factor authentication
  13034. 10:45:43code then I entered this and this is the
  13035. 10:45:45next step you have to choose the country
  13036. 10:45:47I'm going to leave this into United
  13037. 10:45:49States click on continue we have to
  13038. 10:45:52enter our legal name so I'm just going
  13039. 10:45:54to type user user we are testing this
  13040. 10:45:57and we have to enter some domain as well
  13041. 10:46:00my domain
  13042. 10:46:02one.com so here we have to select an
  13043. 10:46:04account for the payout and in this case
  13044. 10:46:07I'm just going to write test institution
  13045. 10:46:10which will bring up the following model
  13046. 10:46:11I have to agree and continue connect
  13047. 10:46:14accounts and to save account with with
  13048. 10:46:17the link I'm just going to click not now
  13049. 10:46:19accounts have been connected I see these
  13050. 10:46:21accounts here click on continue and this
  13051. 10:46:24gives me an information uh which I can
  13052. 10:46:26review and change you know what I'm
  13053. 10:46:28going to CH just change my domain into
  13054. 10:46:30my domain three because this is the user
  13055. 10:46:33three so let's give it my domain three
  13056. 10:46:35so that I can easily um associate if I
  13057. 10:46:39need to so agree and submit now this
  13058. 10:46:43redirects us back into our website and
  13059. 10:46:47it will set up the connection fully so
  13060. 10:46:51let's have a look now in the database in
  13061. 10:46:53the users
  13062. 10:46:55table we have that user three which has
  13063. 10:46:59stripe account ID here and the account
  13064. 10:47:02is also active is one here if we check
  13065. 10:47:05right now profile page we're going to
  13066. 10:47:07see you are successfully connected to
  13067. 10:47:09stripe if we check out our page I think
  13068. 10:47:12we will be logged out because we set up
  13069. 10:47:14this uh we started this onboarding flow
  13070. 10:47:17and it actually logged us out um because
  13071. 10:47:21of that now look at this look at this so
  13072. 10:47:25we have one connected account and this
  13073. 10:47:28is the exact same account what we see in
  13074. 10:47:31the database so user three is now
  13075. 10:47:34connected into our platform and this is
  13076. 10:47:37just awesome so I think we are going to
  13077. 10:47:39I'm going to do this for another user
  13078. 10:47:42because I need at least two vendors let
  13079. 10:47:45me authenticate
  13080. 10:47:47with a
  13081. 10:47:48vendor maybe let's authenticate with
  13082. 10:47:50vendor to let's go
  13083. 10:47:54into profile page so this is the store
  13084. 10:47:57name we have to change this into
  13085. 10:48:00lowercase actually if you even start
  13086. 10:48:02typing in the uppercase and even if you
  13087. 10:48:05start typing spaces I'm hitting spaces
  13088. 10:48:08right now it's going to generate dishes
  13089. 10:48:10so this
  13090. 10:48:12is my store name uh let's click on
  13091. 10:48:15update yeah this this is not even
  13092. 10:48:17verified so we have to verify vendor 2
  13093. 10:48:21as well it got verified let's access to
  13094. 10:48:28profile
  13095. 10:48:30okay uh lowercase Zoomer hit the enter
  13096. 10:48:35details we updated now we're going to
  13097. 10:48:37click on connect to stripe and now this
  13098. 10:48:40the the on boarding can be started for
  13099. 10:48:42this user as well so if we check right
  13100. 10:48:45now users table we are going to see that
  13101. 10:48:47a new account has already been created
  13102. 10:48:49for vendor 2 but it is not active yet
  13103. 10:48:54okay so this is something uh I'm going
  13104. 10:48:57to leave this right now because I want
  13105. 10:48:59to test this case I have this case as
  13106. 10:49:01well so I'm going to actually go back
  13107. 10:49:04and I'm going to authenticate now with
  13108. 10:49:06another user which is going to be
  13109. 10:49:11vendor let's go
  13110. 10:49:14into profile
  13111. 10:49:19uh we have to change this as
  13112. 10:49:22well click on
  13113. 10:49:24update connect to stripe and now I'm
  13114. 10:49:27going to just pause the recording and
  13115. 10:49:29quickly go through this and click on
  13116. 10:49:31agree and submit and at this stage we
  13117. 10:49:35have in the
  13118. 10:49:36database now third one which got already
  13119. 10:49:39active so as you see now we have uh two
  13120. 10:49:43vendors so you are successfully
  13121. 10:49:45connected to stripe which which means
  13122. 10:49:46that that user is fully set up to be
  13123. 10:49:49able to um publish the products on the
  13124. 10:49:54website but the vendor 2 user doesn't
  13125. 10:49:58have stripe account verification so that
  13126. 10:50:00user can actually start in my opinion
  13127. 10:50:03that user can actually publish the
  13128. 10:50:05products on the website um but they will
  13129. 10:50:08not get paid unless they verify uh their
  13130. 10:50:12account if we have a look at our
  13131. 10:50:15connected accounts page we're going to
  13132. 10:50:17see that the two of them are actually um
  13133. 10:50:21enabled and one of them is restricted
  13134. 10:50:24because we have not finished this
  13135. 10:50:27onboarding
  13136. 10:50:28flow okay cool now I'm going to do one
  13137. 10:50:32great thing I comment everything what I
  13138. 10:50:34created so far now I'm going to
  13139. 10:50:37create um few things so first is I'm
  13140. 10:50:40going to create payouts table the hbr
  13141. 10:50:44design
  13142. 10:50:45make uh make a model payout model with
  13143. 10:50:51migration okay and I'm going to also
  13144. 10:50:55create HB artisan
  13145. 10:50:58make Command I'm creating command which
  13146. 10:51:02I plan to be executed once in every
  13147. 10:51:05month which will uh do the payout to all
  13148. 10:51:09the vendors so and I'm going to call
  13149. 10:51:11this
  13150. 10:51:13command payout vendors
  13151. 10:51:18okay make common payout vendors
  13152. 10:51:21cool now let me open create payouts
  13153. 10:51:25table and we're going to add few columns
  13154. 10:51:28here we need boring ID for the vendor so
  13155. 10:51:31which is going to refer to the user so
  13156. 10:51:34we are doing the payout for the
  13157. 10:51:37following user and locally we are
  13158. 10:51:39calling this vendor ID so we are going
  13159. 10:51:42to add the amount column how much we're
  13160. 10:51:46going to
  13161. 10:51:47payout we are going to give it the time
  13162. 10:51:49stamp starting from which date we
  13163. 10:51:52perform the payout until which date and
  13164. 10:51:55that's going to be pretty much all here
  13165. 10:51:57so I'm going to open now payout model
  13166. 10:52:00and I'm going to add fillable here with
  13167. 10:52:02vendor ID amount starting from and until
  13168. 10:52:06now I'm going to open payout
  13169. 10:52:09vendors and I'm going to actually remove
  13170. 10:52:13these comments I don't want them and and
  13171. 10:52:16I'm going to give it
  13172. 10:52:19payout uh column vendors and let's give
  13173. 10:52:22it
  13174. 10:52:24description uh perform vendors
  13175. 10:52:28payout um on the
  13176. 10:52:31first of each month actually uh pendor
  13177. 10:52:36perform vendor payout let's do like
  13178. 10:52:38this so now we're going to work on this
  13179. 10:52:42handle now I'm going to write in a log
  13180. 10:52:46the infog starting monthly payout
  13181. 10:52:49process for vendors so the idea of this
  13182. 10:52:52is it's going to run once in a month but
  13183. 10:52:55I'm going to actually also execute this
  13184. 10:52:57manually I will be able to execute this
  13185. 10:52:58manually whenever I need this so this is
  13186. 10:53:01how I'm going to uh do it so on the
  13187. 10:53:04vendor I'm calling this eligible for
  13188. 10:53:07payout which we actually have defined as
  13189. 10:53:11a scope that the vendor status needs to
  13190. 10:53:13be uh approved but I think think we also
  13191. 10:53:17need to um we also need to have a look
  13192. 10:53:23that the account account the user is
  13193. 10:53:25actually active so I think we are going
  13194. 10:53:27to perform here join on
  13195. 10:53:32users where users ID equals vendor user
  13196. 10:53:37ID and we're going to add additional
  13197. 10:53:42we
  13198. 10:53:44users and what is is the exact name of
  13199. 10:53:47this
  13200. 10:53:49column
  13201. 10:53:51stripe account active stripe account
  13202. 10:53:54active user stripe account active equals
  13203. 10:53:57one uh or
  13204. 10:54:04true okay let's go back into vendors
  13205. 10:54:07payout so we're going to select all the
  13206. 10:54:10vendors which are eligible for payout
  13207. 10:54:12then start iterating over each vendor
  13208. 10:54:15and we are going to process the payout
  13209. 10:54:17I'm going to create this function
  13210. 10:54:18process payout for each of them and
  13211. 10:54:20finally I'm going to just print the info
  13212. 10:54:22monthly payout process completed and we
  13213. 10:54:25are going to return with command success
  13214. 10:54:27now let's create this process payout
  13215. 10:54:29because that is the most interesting
  13216. 10:54:31part uh right here so we accept the
  13217. 10:54:34vendor
  13218. 10:54:35here then we're going to print the info
  13219. 10:54:38message right here to process we're
  13220. 10:54:39processing payout for the following
  13221. 10:54:41vendor we're printing the vendor user ID
  13222. 10:54:43as well as the vendor store name okay
  13223. 10:54:47now we're going to put everything inside
  13224. 10:54:49try catch so we begin the transaction
  13225. 10:54:52and we are GNA uh select the date when
  13226. 10:54:58the previous payout happened and we're
  13227. 10:55:01going to select all the orders after
  13228. 10:55:03that date okay so from payouts we're
  13229. 10:55:06going to select where vendor ID is the
  13230. 10:55:08vendor user ID order by until descending
  13231. 10:55:13and we're going to get the until so
  13232. 10:55:14basically we are taking the
  13233. 10:55:17last maximum until from here so it could
  13234. 10:55:21be also Max until but in this case we're
  13235. 10:55:24just ordering by until and taking the
  13236. 10:55:26first
  13237. 10:55:27one cool so then we are going to check
  13238. 10:55:31if it's starting from exist we are
  13239. 10:55:34taking this if it doesn't exist we are
  13240. 10:55:36making the carbon date uh 1970 so
  13241. 10:55:39basically it doesn't exist if we are
  13242. 10:55:42doing the first payout for this specific
  13243. 10:55:44vendor in which case the starting from
  13244. 10:55:47will be actually null and we're taking
  13245. 10:55:49the starting from to be
  13246. 10:55:511970 so then uh um we are going to
  13247. 10:55:55calculate the until and until is going
  13248. 10:55:59to be this uh something like this let me
  13249. 10:56:02open scratch
  13250. 10:56:03file and show this to you so if today is
  13251. 10:56:07like
  13252. 10:56:0823 of um 23 of November okay that's the
  13253. 10:56:13actual date today so
  13254. 10:56:16we are going to do the
  13255. 10:56:19payout until the previous
  13256. 10:56:23month uh first date so the previous
  13257. 10:56:26month is
  13258. 10:56:28October and we are GNA do the payout
  13259. 10:56:33until 1st of
  13260. 10:56:35October and why I'm doing this actually
  13261. 10:56:39uh this code will be executed on the
  13262. 10:56:42first of month so generally speaking on
  13263. 10:56:461st of November this is going to perform
  13264. 10:56:49the payout including 1st of
  13265. 10:56:52October okay from the previous date from
  13266. 10:56:55the previous payout including until 1st
  13267. 10:56:58of October on the 1st of December it is
  13268. 10:57:01going to do the payout until 1st of
  13269. 10:57:04November and so on so uh the date is at
  13270. 10:57:08least one month the the date when the
  13271. 10:57:10payout command is executed will be at
  13272. 10:57:13least one month later uh from the date
  13273. 10:57:16until which we are actually performing
  13274. 10:57:18the
  13275. 10:57:20payout but in this case because it is 23
  13276. 10:57:23of November uh the previous month so we
  13277. 10:57:25are taking this sub Monon no no overflow
  13278. 10:57:29this means calculating one month with no
  13279. 10:57:32overflow this no overflow is actually
  13280. 10:57:35necessary uh for carbon to properly
  13281. 10:57:39calculate uh what is one month
  13282. 10:57:42subtracted one month like if we are
  13283. 10:57:44speaking about 30 30 of March subtract
  13284. 10:57:48one month from 30 of March might you
  13285. 10:57:52might understand that it's a 30 of
  13286. 10:57:54February which doesn't exist right so
  13287. 10:57:56yeah this no overflow is actually
  13288. 10:57:58necessary to make sure that carbon
  13289. 10:58:01correctly calculates the uh one month
  13290. 10:58:04sub subtraction which gives us in our
  13291. 10:58:07case 33 of October but then we take
  13292. 10:58:09start of month which is first of October
  13293. 10:58:13okay so then uh we're going to calculate
  13294. 10:58:16the vendor subtotal how much we should
  13295. 10:58:19transfer from our balance and our
  13296. 10:58:23balance is actually right here so this
  13297. 10:58:26is our account we have this is our
  13298. 10:58:28balance right and uh we have connected
  13299. 10:58:32users so into one of the connected users
  13300. 10:58:35we're going to send the
  13301. 10:58:37money so we're going to select from
  13302. 10:58:40orders with the vendor user ID to be the
  13303. 10:58:42vendor user ID right here so we're going
  13304. 10:58:45to select SCT only paid orders and we're
  13305. 10:58:49going to put the created dat of the
  13306. 10:58:51order in between the starting from and
  13307. 10:58:55until and we are going to calculate the
  13308. 10:58:58sum of vendor subtotal we have many
  13309. 10:59:01colums in the orders table but vendor
  13310. 10:59:05subtotal is what is payout
  13311. 10:59:09amount okay so this is website
  13312. 10:59:12commission uh this is this was taken by
  13313. 10:59:16tribe so the vendor subtotal is what we
  13314. 10:59:18should pay to the vendor so we calculate
  13315. 10:59:20this vendor subtotal and now let's check
  13316. 10:59:23if the vendor subtotal exists meaning
  13317. 10:59:25that if it is more than
  13318. 10:59:26zero uh if it's not more than zero then
  13319. 10:59:29we just write nothing to process but if
  13320. 10:59:31it's more than zero then we are going to
  13321. 10:59:33write a message here payout made with
  13322. 10:59:36amount vendor subtotal and then we're
  13323. 10:59:38going to create this payout record
  13324. 10:59:40providing vendor ID amount starting from
  13325. 10:59:43and until and right here this is the key
  13326. 10:59:47point which you can find in the
  13327. 10:59:49following documentation as well out user
  13328. 10:59:52transfer and this is going to send the
  13329. 10:59:54money so from our account we are
  13330. 10:59:57performing transfer to the vendor user
  13331. 10:59:59account and we are providing the
  13332. 11:00:01following amount so vendor subtotal
  13333. 11:00:05Multiplied on 100 to convert this into
  13334. 11:00:08dollars because sorry to convert this
  13335. 11:00:11into cents because we have provide the
  13336. 11:00:13payout in cents but if we we check
  13337. 11:00:16orders right now we're going to see that
  13338. 11:00:18some of the amounts on the vendors uh
  13339. 11:00:21have a lot of decimal numbers
  13340. 11:00:25right and we are casting this into
  13341. 11:00:28integer because we cannot provide
  13342. 11:00:29decimal value inside the transfer so
  13343. 11:00:32this will be multiplied 100 which will
  13344. 11:00:35be
  13345. 11:00:36483 sorry this is website commission
  13346. 11:00:39this one um which will be
  13347. 11:00:42[Music]
  13348. 11:00:4443 no
  13349. 11:00:484,348 and
  13350. 11:00:514,348 will be sent uh to the vendor so
  13351. 11:00:54the other simply will be
  13352. 11:00:56neglected and just like this we are
  13353. 11:00:58performing this payout let's uh comit
  13354. 11:01:01the transaction if everything happened
  13355. 11:01:03we come the transaction if something is
  13356. 11:01:05going wrong then we roll back and we
  13357. 11:01:08print the error message here as
  13358. 11:01:11well so I think we have to import the
  13359. 11:01:15things hold on I did something weird so
  13360. 11:01:17we have to import this
  13361. 11:01:19vendor we have to import this
  13362. 11:01:22payout up models payout we have to
  13363. 11:01:25import
  13364. 11:01:27carbon import
  13365. 11:01:30order and order status
  13366. 11:01:38enm okay now we
  13367. 11:01:41have we have this ready and I want to
  13368. 11:01:44execute this PHP
  13369. 11:01:47Artisan
  13370. 11:01:48payout vendors we hit the enter let's
  13371. 11:01:52have a look I think table payouts
  13372. 11:01:54doesn't exist because we haven't
  13373. 11:01:56executed PHP Artisan
  13374. 11:01:59migrate okay now let's execute payout
  13375. 11:02:02vendors and have a look so nothing to
  13376. 11:02:05process and this is very logical because
  13377. 11:02:08the dates are
  13378. 11:02:10not uh before 1 of December so if we
  13379. 11:02:14check what is the until
  13380. 11:02:16we are going to
  13381. 11:02:18find that until is 1st of December so we
  13382. 11:02:22want all the orders which was made until
  13383. 11:02:241st of December but we don't have such
  13384. 11:02:26orders right every order is made right
  13385. 11:02:28now and you know what I'm going to
  13386. 11:02:31change the order dates so we have all
  13387. 11:02:35the orders made right now let me change
  13388. 11:02:37this into be made
  13389. 11:02:41in in
  13390. 11:02:44September cool
  13391. 11:02:48uh it is not yeah it converts this into
  13392. 11:02:53time stamp
  13393. 11:02:54because SQ light doesn't have actually
  13394. 11:02:58daytime it has Tim
  13395. 11:03:00stamp and it is saved like this to fix
  13396. 11:03:03this in PHP storm we're going to open
  13397. 11:03:05the database settings go into advanced
  13398. 11:03:07and
  13399. 11:03:09find uh date date class date class to be
  13400. 11:03:13text
  13401. 11:03:19now let's save this in
  13402. 11:03:23September now it was saved as as it
  13403. 11:03:28should be now I want to update all the
  13404. 11:03:31other
  13405. 11:03:32records uh with
  13406. 11:03:34the uh 23 of September I'm going to save
  13407. 11:03:38this
  13408. 11:03:40and okay cool now let's
  13409. 11:03:42execute pay out and have a look
  13410. 11:03:47look at this okay so for vendor store
  13411. 11:03:51vendor 2 for vendor store payout made
  13412. 11:03:55with
  13413. 11:03:56amount 100
  13414. 11:03:59something uh for vendor six which which
  13415. 11:04:03was also
  13416. 11:04:04eligible there was nothing to process
  13417. 11:04:07now let's check
  13418. 11:04:08orders and see all the different vendor
  13419. 11:04:12user ID so we have vendor two for which
  13420. 11:04:15we have made some payments for vendor 4
  13421. 11:04:18we have made some payments but vendor 4
  13422. 11:04:23is actually not eligible for payout
  13423. 11:04:26because vendor
  13424. 11:04:274 which is
  13425. 11:04:29zomer vendor 4 does not have
  13426. 11:04:33account activation
  13427. 11:04:35finished okay so only vendor two was a
  13428. 11:04:40was eligible to pay
  13429. 11:04:43out and
  13430. 11:04:45let's see in the stripe
  13431. 11:04:47dashboard
  13432. 11:04:49so if we just refresh this right now the
  13433. 11:04:53connected
  13434. 11:05:01accounts come
  13435. 11:05:03on now look at this so this is the
  13436. 11:05:07vendor and we perform the pay payout
  13437. 11:05:12129 129 here
  13438. 11:05:16and we see that uh balance for this
  13439. 11:05:20account is right now
  13440. 11:05:22129 and that is um single Transaction
  13441. 11:05:27what we did right
  13442. 11:05:28now okay we made this transfer right now
  13443. 11:05:33okay let's go back and if we check our
  13444. 11:05:36balance we're going to see we we had
  13445. 11:05:38like
  13446. 11:05:391,900 something now something was gone
  13447. 11:05:42from our balance and if we check the all
  13448. 11:05:46activity we're going to see this minus
  13449. 11:05:49uh
  13450. 11:05:50121 so this is a transfer into the
  13451. 11:05:53following account what we so I think
  13452. 11:05:56this is this is it
  13453. 11:05:59so that's that's what we uh wanted to
  13454. 11:06:02achieve let's click on this connected
  13455. 11:06:04accounts Okay cool so we did just pay
  13456. 11:06:07out and also let's check the payouts
  13457. 11:06:10table refresh schema click on payouts
  13458. 11:06:12table now we see one record we see the m
  13459. 11:06:15we see starting from we see until the 1
  13460. 11:06:19of October and if we try
  13461. 11:06:22to execute payout again there will be
  13462. 11:06:25nothing to process because uh now the we
  13463. 11:06:28took everything from uh after uh the
  13464. 11:06:36um after the first of October actually
  13465. 11:06:41in our case even if we make new orders
  13466. 11:06:45right now
  13467. 11:06:46we are going to see let me
  13468. 11:06:49dump uh starting from and
  13469. 11:06:52until we are going to see them they will
  13470. 11:06:56be the
  13471. 11:06:57same they are the same so right now it's
  13472. 11:07:01a 23rd of January as I mentioned and
  13473. 11:07:04whenever it is already December when we
  13474. 11:07:06execute the payout we are going to see
  13475. 11:07:09that
  13476. 11:07:10the the orders which were made in
  13477. 11:07:13November will be paid out
  13478. 11:07:16and this is this is very very
  13479. 11:07:22good now of course we did this manually
  13480. 11:07:26but on production we want this to be
  13481. 11:07:28automated right so we're going to open
  13482. 11:07:30up service provider and right here
  13483. 11:07:33inside the boot we are going to define
  13484. 11:07:37the schedule so let's use schedule
  13485. 11:07:42facade and we're gonna uh we're going to
  13486. 11:07:45perform the scheduling on a commment so
  13487. 11:07:48scheduling is Task scheduling is a very
  13488. 11:07:50very powerful uh Topic in LEL so if we
  13489. 11:07:53open lal.com if we click on
  13490. 11:07:57documentation and search for task
  13491. 11:08:00scheduling you're going to find a lot of
  13492. 11:08:02things so we can schedule the Artisan
  13493. 11:08:04commands Q jobs shell commands and a lot
  13494. 11:08:07of other things and we're going to do
  13495. 11:08:09this Artisan command scheduling at the
  13496. 11:08:11moment so inside the command we're going
  13497. 11:08:13to provide payout vendors this is the
  13498. 11:08:16command uh we are going to schedule this
  13499. 11:08:20monthly on first day of month at let's
  13500. 11:08:24do this overnight like 0 0 00 0 okay and
  13501. 11:08:29then we need to do this without
  13502. 11:08:31overlapping so if there is for some
  13503. 11:08:34reason one command already doing this uh
  13504. 11:08:37payout vendors if we have this in a
  13505. 11:08:40distributed system as an example and one
  13506. 11:08:43server took this and is performing this
  13507. 11:08:46payout the second one should not
  13508. 11:08:49actually do it and just to make sure
  13509. 11:08:52that this command is executed on every
  13510. 11:08:55day for this on not every day but on
  13511. 11:08:58every month on the first of month we
  13512. 11:09:00have to set up the task scheduling
  13513. 11:09:03on uh on production so for this you have
  13514. 11:09:07to edit the crown Tab and this means
  13515. 11:09:10that this should run in every minute you
  13516. 11:09:13have to navigate you have to put the
  13517. 11:09:15following thing in the crown tab
  13518. 11:09:17navigate into your project directory and
  13519. 11:09:21execute PHP Artisan schedule run to
  13520. 11:09:24Output the results uh into Dev now and
  13521. 11:09:27start this in background so technically
  13522. 11:09:30speaking if I took this and if I execute
  13523. 11:09:34it right now schedule run no schedule
  13524. 11:09:37comments are ready to run so right now
  13525. 11:09:39nothing um nothing will be run but if we
  13526. 11:09:43have that schedule
  13527. 11:09:45on let's say on 23rd of November if we
  13528. 11:09:50provide it like
  13529. 11:09:52this uh then we execute this
  13530. 11:09:56um it is not actually doing it but yeah
  13531. 11:10:00you get you get the idea so it doesn't
  13532. 11:10:02find these schedules to run at the
  13533. 11:10:05moment I think I think you want to see
  13534. 11:10:07it running using this schedule
  13535. 11:10:11run so here I provided my time correct
  13536. 11:10:15time in UTC so we see today is 23rd as I
  13537. 11:10:19mentioned monthly on 23rd but I provided
  13538. 11:10:23the time right here as well okay so now
  13539. 11:10:26if I execute this schedule run it is
  13540. 11:10:29catching these payout vendors and
  13541. 11:10:30Performing this right now it obviously
  13542. 11:10:32it doesn't do anything because we have
  13543. 11:10:34done the payout but I'm going to delete
  13544. 11:10:36this payout record from here and it's
  13545. 11:10:38going to do the payout second time so
  13546. 11:10:42let's execute it it is working
  13547. 11:10:45performing some output now in the
  13548. 11:10:47payouts table we're going to probably
  13549. 11:10:50see a new record created and if we check
  13550. 11:10:53right now stripe dashboard we are going
  13551. 11:10:56to see also twice as much amount because
  13552. 11:11:01we did the same payout twice now we see
  13553. 11:11:03200 something and in our balance also we
  13554. 11:11:06see much less amount and just like this
  13555. 11:11:09so we don't need this on 124 we need
  13556. 11:11:12this on 0 0 um 0 and we need this to
  13557. 11:11:17happen on first of uh the month but you
  13558. 11:11:21you just make sure that you
  13559. 11:11:23follow this thing on on your production
  13560. 11:11:26server and um you're going to make it
  13561. 11:11:29working so if you want to see how to
  13562. 11:11:32deploy this project on VPS server or how
  13563. 11:11:35to set up this crop or things like that
  13564. 11:11:37I have a separate video where I um
  13565. 11:11:41actually this video the separate video
  13566. 11:11:44was before this video
  13567. 11:11:45so on my YouTube channel deploy the full
  13568. 11:11:48stack application with service side
  13569. 11:11:49rendering with inertia with react on
  13570. 11:11:52custom domain so everything is there U
  13571. 11:11:55we also have cicd automatic deployment
  13572. 11:11:58there so it's a pretty uh good tutorial
  13573. 11:12:02to get in get started with the um
  13574. 11:12:05fullsack applications with L and react
  13575. 11:12:07um and with deployment part as well so
  13576. 11:12:10in this tutorial you can just add this
  13577. 11:12:12into Crown Tab and you are going to have
  13578. 11:12:15the up and running deployment version
  13579. 11:12:17okay so there are few things I want to
  13580. 11:12:19fix and due to the lack of the time and
  13581. 11:12:22I want to fit this entire project into
  13582. 11:12:2412 hours one YouTube tutorial I had to
  13583. 11:12:27do some work outside and I will just
  13584. 11:12:30show to you what I have done so first if
  13585. 11:12:33we have a look in the interface we're
  13586. 11:12:34going to see t-shirts right here but
  13587. 11:12:36when I click this first product uh two
  13588. 11:12:40right here we see that it's actually
  13589. 11:12:41headset so this happens because we have
  13590. 11:12:45this admin
  13591. 11:12:47area where we from which we uploaded
  13592. 11:12:50different images on the product itself
  13593. 11:12:52and different images uh on the
  13594. 11:12:54variations and this is something which
  13595. 11:12:58you can do but you should not probably
  13596. 11:13:01do so what we are going to do here that
  13597. 11:13:04instead of displaying the product image
  13598. 11:13:05If the product has some variation
  13599. 11:13:07options and at least one of the option
  13600. 11:13:10has some images we're going to use those
  13601. 11:13:12images right here so every time so I I'm
  13602. 11:13:16going to create the I created actually
  13603. 11:13:18the following method get first image URL
  13604. 11:13:22and this on the product model so and
  13605. 11:13:24this actually does the following so it's
  13606. 11:13:26uh I also Define the relation into
  13607. 11:13:28options like this so has many through
  13608. 11:13:31and we can Define this um has many
  13609. 11:13:34through return type as
  13610. 11:13:37well so has many through it has many
  13611. 11:13:40relation into variation type options uh
  13612. 11:13:42through the variation type table uh the
  13613. 11:13:45first key the second key and local key
  13614. 11:13:47and second local key so and just like
  13615. 11:13:49this now I can access options through
  13616. 11:13:52the variation
  13617. 11:13:53types okay so if I scroll down below now
  13618. 11:13:56right here I try to access the options
  13619. 11:13:58and if options count is more than zero
  13620. 11:14:01if it's zero then we simply return the
  13621. 11:14:04first image from the product itself if
  13622. 11:14:06it's more than zero then uh on the
  13623. 11:14:09option I get this First Media URL and if
  13624. 11:14:12the image URL exists I'm returning this
  13625. 11:14:15now I'm going to use this inside product
  13626. 11:14:18list resource when I'm accessing
  13627. 11:14:22this I have to zoom in I guess so when
  13628. 11:14:26I'm accessing this First Media URL I'm
  13629. 11:14:29going to replace it with get first image
  13630. 11:14:32URL right here and now if I refresh the
  13631. 11:14:37page now we see headset right here and
  13632. 11:14:39this is the first variation okay and um
  13633. 11:14:43it works like a charm great
  13634. 11:14:45now we need to do something similar for
  13635. 11:14:48the price as well so here we see that
  13636. 11:14:51the price is 25 on the black one but
  13637. 11:14:53outside we see it to be 15 okay so here
  13638. 11:14:59I actually added a second method get
  13639. 11:15:01price for first options can collapse
  13640. 11:15:05this and I'm going to use this method
  13641. 11:15:07right here get price for first options
  13642. 11:15:09and it is going to return uh 25 which is
  13643. 11:15:14pric for the first
  13644. 11:15:15options additionally I added a few more
  13645. 11:15:18methods
  13646. 11:15:19like um we saw this we saw that so get
  13647. 11:15:24first options map so which is something
  13648. 11:15:28uh which is used internally here as well
  13649. 11:15:30get price for first IM first options so
  13650. 11:15:33we're getting the first options right
  13651. 11:15:35here and then if the first options exist
  13652. 11:15:37meaning that if the product has some
  13653. 11:15:39options then we call this get price for
  13654. 11:15:42options which is something already
  13655. 11:15:43exists so we defined this
  13656. 11:15:46earlier so we reuse the same method
  13657. 11:15:49right here to calculate the price and we
  13658. 11:15:51also have this skate images where we
  13659. 11:15:53check if the options exist um and this
  13660. 11:15:56simply returns all the images so this is
  13661. 11:15:59very similar to get first image URL but
  13662. 11:16:02this one returns all the images and we
  13663. 11:16:04will use this as well let me collapse
  13664. 11:16:06this collapse that so I think we're
  13665. 11:16:09going to use this inside cart service so
  13666. 11:16:13if we find uh um place where we are
  13667. 11:16:16adding the item into the
  13668. 11:16:19cart uh I think this is the place is if
  13669. 11:16:22option ID equals null then on the
  13670. 11:16:25product we we're going to call this get
  13671. 11:16:27first options map which should return
  13672. 11:16:30some options and we're going to use that
  13673. 11:16:32to add this into the card and this now
  13674. 11:16:36actually uh is going to work pretty well
  13675. 11:16:38so if I click this A2 cart here we see
  13676. 11:16:41something was added into the cart and
  13677. 11:16:43that something should have image this
  13678. 11:16:45black headset in price of
  13679. 11:16:4725 uh the image is not the one
  13680. 11:16:51[Music]
  13681. 11:16:52and probably
  13682. 11:16:54we the price is also not the
  13683. 11:16:58one so we're going to see what option
  13684. 11:17:01IDs we have here when we print
  13685. 11:17:05them uh when we are adding
  13686. 11:17:08them homepage click it to card we see
  13687. 11:17:12empty options
  13688. 11:17:15yeah okay so we are uh checking actually
  13689. 11:17:18against null but this is what we're
  13690. 11:17:21going to do if options does not exist
  13691. 11:17:24empty array means also that it doesn't
  13692. 11:17:26exist so we're getting these empty uh
  13693. 11:17:28option IDs from the front end from the
  13694. 11:17:31react that's why this if is not
  13695. 11:17:33satisfied if I save this and click on
  13696. 11:17:36this Ed to cart right now now we see
  13697. 11:17:38those options and that should fix the
  13698. 11:17:42issue uh I'm going to actually remove
  13699. 11:17:45this from
  13700. 11:17:47cart then click on this Ed to cart it
  13701. 11:17:51seems like to
  13702. 11:17:52work okay now that worked and we have
  13703. 11:17:56now the color black and size small
  13704. 11:17:58variation added into the card if we
  13705. 11:18:01check this one this doesn't have any
  13706. 11:18:02variation so that should be
  13707. 11:18:06good to add that into the cart now we
  13708. 11:18:10have a two
  13709. 11:18:13quantity Okay so
  13710. 11:18:15now since we have these get images
  13711. 11:18:20here we're going to use this in another
  13712. 11:18:22place when we when we start working on
  13713. 11:18:26SEO but I think yeah the the issue
  13714. 11:18:29regarding the product listing is
  13715. 11:18:33actually resolved and as soon as there
  13716. 11:18:36is some variation that variation will be
  13717. 11:18:38picked up now let's Implement vendor
  13718. 11:18:41profile
  13719. 11:18:42page on on some UR URL so first let's
  13720. 11:18:46implement the uh
  13721. 11:18:48controller so we have selected the
  13722. 11:18:51products but only those products which
  13723. 11:18:54was created which has created by vendor
  13724. 11:18:58user ID okay then we are going to render
  13725. 11:19:01vendor profile page which we're going to
  13726. 11:19:03create we are using we're passing the
  13727. 11:19:05vendor here and we're passing the
  13728. 11:19:06products through this product least
  13729. 11:19:10resource that's that's
  13730. 11:19:13cool now here we are using this for
  13731. 11:19:16website and I want to check this for
  13732. 11:19:18website and update this for website
  13733. 11:19:21right now only is using published but I
  13734. 11:19:25want to create another scope right here
  13735. 11:19:28which is going to be public function
  13736. 11:19:32scope
  13737. 11:19:34vendor approved so I'm going to use
  13738. 11:19:39Builder
  13739. 11:19:41here and I'm going to return something
  13740. 11:19:45like this let me copy
  13741. 11:19:49so that should be
  13742. 11:19:53Cy so on on the Cy I'm using um join to
  13743. 11:19:58join into the vendors using the user ID
  13744. 11:20:01with the correct columns and I'm
  13745. 11:20:04selecting only those which those
  13746. 11:20:07products which has vendor status to be
  13747. 11:20:09approved so right here I want to use
  13748. 11:20:12vendor approved
  13749. 11:20:14so scope now for website means that the
  13750. 11:20:18product needs to be published and the
  13751. 11:20:19vendor needs to be approved as long as
  13752. 11:20:21the admin user decides to disapprove or
  13753. 11:20:25change the approval status into pending
  13754. 11:20:27or something else the products will be
  13755. 11:20:30gone from the website and we can easily
  13756. 11:20:32test this so on the homepage now we
  13757. 11:20:36see yeah Status is ambigous because
  13758. 11:20:40inside the published we have to use
  13759. 11:20:42right here products. status
  13760. 11:20:46now let's see so on the homepage we see
  13761. 11:20:48now vendor 2 and vendor products and if
  13762. 11:20:51we open vendors page and if we change
  13763. 11:20:56the status approved into pending as an
  13764. 11:21:00example then the product should be gone
  13765. 11:21:02from the homepage so it is practically
  13766. 11:21:04gone from the website so let's return
  13767. 11:21:07this and refresh the page and it will be
  13768. 11:21:11back and that's that's on the homepage
  13769. 11:21:13and that's going to be done also so on
  13770. 11:21:14the profile page Bas basically four
  13771. 11:21:17website cope was completely updated now
  13772. 11:21:20we are going to go into JS
  13773. 11:21:23Pages uh and let's create now another
  13774. 11:21:28typescript file this is going to be
  13775. 11:21:30inside the vendor folder vendor
  13776. 11:21:35profile okay I have to copy that
  13777. 11:21:39typescript file it is going to be very
  13778. 11:21:41much similar into the
  13779. 11:21:43homepage let me actually quick quickly
  13780. 11:21:46copy and paste
  13781. 11:21:49this okay let's have a look so we have
  13782. 11:21:52the product item from the
  13783. 11:21:56app
  13784. 11:21:57[Music]
  13785. 11:21:58um we have few things I think we don't
  13786. 11:22:02have vendor type defined and I think we
  13787. 11:22:06we need to Define this inside the time
  13788. 11:22:09types and we have
  13789. 11:22:11this uh page props as well
  13790. 11:22:17well okay so inside the page props let's
  13791. 11:22:21actually
  13792. 11:22:28Define yeah um my my project which from
  13793. 11:22:33which I copied actually is slightly
  13794. 11:22:35different because I improve this every
  13795. 11:22:36time I you create something you might
  13796. 11:22:38improve it slightly so here products is
  13797. 11:22:42actually something what we have to find
  13798. 11:22:44in the home T6 so we can see product is
  13799. 11:22:48actually paginated props so we can
  13800. 11:22:51provide it like this cool so we have
  13801. 11:22:54vendor which needs to be imported
  13802. 11:22:57actually defined and imported so let's
  13803. 11:22:59go in the types and let's Define export
  13804. 11:23:04type
  13805. 11:23:06vendor and let
  13806. 11:23:09me copy so we don't have many fields on
  13807. 11:23:12the vendor we have ID uh store name and
  13808. 11:23:15store address can close this now in the
  13809. 11:23:18profile vendor is imported everything
  13810. 11:23:20seems to be
  13811. 11:23:22good let's move this down and it's very
  13812. 11:23:25much similar to the homepage so in the
  13813. 11:23:27title we just have the vendor store name
  13814. 11:23:29profile page then we have this stock
  13815. 11:23:32image as a hero section and then down
  13816. 11:23:35below iterate over products and render
  13817. 11:23:37that okay now let's open web.php which
  13818. 11:23:40is going to be vendor profile page
  13819. 11:23:45uh where should we Define
  13820. 11:23:50this okay let's define it right here so
  13821. 11:23:53this is the root I'm using this S as an
  13822. 11:23:56abbreviation for seller um so we're
  13823. 11:24:00going to select the seller by store name
  13824. 11:24:03uh using the following controller
  13825. 11:24:05passing it and this is the um profile so
  13826. 11:24:09vendor profile now if we check actually
  13827. 11:24:13let me update product
  13828. 11:24:17item and
  13829. 11:24:20find right here so we're going to change
  13830. 11:24:22this into
  13831. 11:24:25root vendor. profile
  13832. 11:24:29providing
  13833. 11:24:30product.
  13834. 11:24:32user. store name do we have store name
  13835. 11:24:37user product.
  13836. 11:24:40user okay
  13837. 11:24:49product. user product. user doesn't have
  13838. 11:24:52vendor specific information right so do
  13839. 11:24:56we have user resource
  13840. 11:25:00somewhere no let's open product list
  13841. 11:25:04resource and we are just returning user
  13842. 11:25:07information right here but we want to
  13843. 11:25:10return some other information as well so
  13844. 11:25:13let me actually add right here only
  13845. 11:25:15store
  13846. 11:25:16name this
  13847. 11:25:20user
  13848. 11:25:21vendor store name now inside product
  13849. 11:25:26item right here first inside the types
  13850. 11:25:29we're going to define the store name
  13851. 11:25:31here then I'm using store name as a
  13852. 11:25:39parameter actually my bed this was for
  13853. 11:25:42departments right no it was for the user
  13854. 11:25:45that's correct so let's move this
  13855. 11:25:50down okay great uh if we search for this
  13856. 11:25:55I think there's a second place we are
  13857. 11:25:56using it let's open show.
  13858. 11:26:01TS6 and
  13859. 11:26:03find where we have this title product
  13860. 11:26:06title and below that product title maybe
  13861. 11:26:09we want to put the following
  13862. 11:26:11paragraph let's remove this margin
  13863. 11:26:13buttom from here and add
  13864. 11:26:17that here so if we open right
  13865. 11:26:23now uh we're going to open product
  13866. 11:26:26Resource as well let me explain what I'm
  13867. 11:26:28doing I think you got
  13868. 11:26:30confused so we did this on the product
  13869. 11:26:33list item so we opened product list
  13870. 11:26:35resource we returned store name then we
  13871. 11:26:39accepted this store name right here in
  13872. 11:26:41this product item and we displayed the
  13873. 11:26:43store name name we displayed the proper
  13874. 11:26:45rout okay so we have to do something
  13875. 11:26:48similar in the show page when we display
  13876. 11:26:50all the details about the product so we
  13877. 11:26:53don't even
  13878. 11:26:54display uh where this product by who the
  13879. 11:26:57product is created and in which
  13880. 11:26:59department the product is created we
  13881. 11:27:01didn't even do this on the product
  13882. 11:27:03Details page so this is what I did right
  13883. 11:27:06now so I copied this in the show t uh
  13884. 11:27:10TS6 and the problem is that we don't
  13885. 11:27:13have store name returned on the product
  13886. 11:27:16resource so we want to open product
  13887. 11:27:19resource and find where we are returning
  13888. 11:27:21user and we are going to return store
  13889. 11:27:25name here as
  13890. 11:27:28well now if we refresh the page the
  13891. 11:27:32error should be gone we should see okay
  13892. 11:27:35by vendor 2 and if we click vendor or
  13893. 11:27:37vendor two in the url url looks great
  13894. 11:27:39click on this now this opens this vendor
  13895. 11:27:42store where we see only products that
  13896. 11:27:44are related to the specific vendor so in
  13897. 11:27:48ideal case we are going to have the
  13898. 11:27:49cover image for the vendor we have cover
  13899. 11:27:52image in the database but we haven't
  13900. 11:27:53actually implemented uploading cover
  13901. 11:27:55image for the Ender which probably we
  13902. 11:27:57won't be able to do this in this time
  13903. 11:27:59frame but I'm going to do this of course
  13904. 11:28:01um in the project source code so you can
  13905. 11:28:03check the source code if you get the
  13906. 11:28:05source code uh there will be a lot more
  13907. 11:28:07than this so click on this you're going
  13908. 11:28:10to find that as well pretty cool if we
  13909. 11:28:13go inside
  13910. 11:28:15uh no something is not working as
  13911. 11:28:21expected parameter is required for
  13912. 11:28:24vendor profile let's
  13913. 11:28:27see okay why don't we see the
  13914. 11:28:33parameter parameter is required for
  13915. 11:28:39vendor
  13916. 11:28:42um product user has store
  13917. 11:28:47name okay uh I'm going to print the
  13918. 11:28:50entire product and see what's going on
  13919. 11:28:54there uh product. user let's print print
  13920. 11:28:58product. user so this is the user it has
  13921. 11:29:01a store name store name is somehow
  13922. 11:29:05null because I did something wrong
  13923. 11:29:08vendor store
  13924. 11:29:10name refresh the page let's remove this
  13925. 11:29:13cont console log as well and now we see
  13926. 11:29:17product Details page here we see this by
  13927. 11:29:19vendor in electronics I'm clicking on
  13928. 11:29:21this also works
  13929. 11:29:25perfectly okay great now we have this
  13930. 11:29:28vendor profile page as well where we
  13931. 11:29:30display only the products which belong
  13932. 11:29:32to the specific vendor now I want to
  13933. 11:29:36work on the Departments displaying the
  13934. 11:29:39Departments right here and Implement uh
  13935. 11:29:42searching by Department ments filtering
  13936. 11:29:45by departments as well as a a search
  13937. 11:29:47form right here to search certain things
  13938. 11:29:50by keyword so this going to be pretty
  13939. 11:29:52interesting and useful thing and again I
  13940. 11:29:55will try to speed up a little bit so
  13941. 11:29:58first uh let's open
  13942. 11:30:02navbar not this
  13943. 11:30:04one
  13944. 11:30:06navbar TSX so we we need this I'm going
  13945. 11:30:10to modify this part actually and I'm
  13946. 11:30:12going to also open handle injs request
  13947. 11:30:16and I'm going to actually why I'm
  13948. 11:30:17zooming out this
  13949. 11:30:19um I want to provide departments from
  13950. 11:30:23here so let me select
  13951. 11:30:30departments uh
  13952. 11:30:32Department model uh we're going to find
  13953. 11:30:35published departments and I'm going to
  13954. 11:30:37create scope for these with I'm going to
  13955. 11:30:40select them with
  13956. 11:30:42categories and I'm going to uh limit and
  13957. 11:30:46take only the first 10 or maybe we can
  13958. 11:30:50return even all of them it's okay so now
  13959. 11:30:52if we open
  13960. 11:30:53this uh Department model we're going to
  13961. 11:30:56Define uh scope let me open vendor and
  13962. 11:31:01we're going to find I'm going to copy
  13963. 11:31:04this scope put this right
  13964. 11:31:10here say status need to be department or
  13965. 11:31:15I think we don't have status we have
  13966. 11:31:18active so active needs to be true for
  13967. 11:31:24departments now let's import this
  13968. 11:31:26Builder and this should be eloquent
  13969. 11:31:30Builder and the name should be scope
  13970. 11:31:35published okay we select the Departments
  13971. 11:31:37with categories and I'm going to provide
  13972. 11:31:41them right here
  13973. 11:31:45departments we can provide it like this
  13974. 11:31:48or we can create a department
  13975. 11:31:51resource uh I'm going to actually do the
  13976. 11:31:54following I'm going to create Department
  13977. 11:31:56resource PHP artisan make
  13978. 11:32:00resource
  13979. 11:32:02department
  13980. 11:32:03resource let's open
  13981. 11:32:07this uh let's open
  13982. 11:32:09Department
  13983. 11:32:11resource and I'm going to change change
  13984. 11:32:14this return type so we need ID name slug
  13985. 11:32:16meta title meta description for the
  13986. 11:32:19Departments we need all that and
  13987. 11:32:21categories for categories we only take
  13988. 11:32:23ID and name so I'm going to disable WP
  13989. 11:32:27set the to
  13990. 11:32:29false then right here I'm going to use
  13991. 11:32:33Department
  13992. 11:32:35resource collection
  13993. 11:32:38departments and we are going to actually
  13994. 11:32:41take collection out of f is an array to
  13995. 11:32:48array now we're going to open index. DTS
  13996. 11:32:52and we're going to
  13997. 11:32:53Define departments and categories right
  13998. 11:32:56here so I copied and paste it we see
  13999. 11:32:58this category uh ID and Name ID can be
  14000. 11:33:01actually number it's fine and for
  14001. 11:33:04Department we see ID name slug uh meta
  14002. 11:33:07title met description and categories and
  14003. 11:33:10in the nav bar we are going to accept
  14004. 11:33:14uh
  14005. 11:33:15departments and actually if we check
  14006. 11:33:18page props we are going to add
  14007. 11:33:21departments here as
  14008. 11:33:24well cool now we accept departments here
  14009. 11:33:28uh we don't want this total price and
  14010. 11:33:30total quantity I guess so we take these
  14011. 11:33:35departments and we want to iterate and
  14012. 11:33:39render them so for this I'm going to
  14013. 11:33:41create a fragment here and I'm going to
  14014. 11:33:44actually create second
  14015. 11:33:47navbar so I'm going to quickly copy and
  14016. 11:33:51explain
  14017. 11:33:53it so here is the second now bar now bar
  14018. 11:33:57BG is border top mean head four that's
  14019. 11:34:00it so inside we have this now bar Center
  14020. 11:34:04uh which is uh hidden and display Flex
  14021. 11:34:07uh only on large screens and then we see
  14022. 11:34:10this UL menu menu horizontal menu drop-
  14023. 11:34:13down
  14024. 11:34:14and uh we can remove this as well no
  14025. 11:34:16need I was experimenting something menu
  14026. 11:34:19menu horizontal and we iterate over
  14027. 11:34:21departments and render Li so if I save
  14028. 11:34:25this right now and have a look in the
  14029. 11:34:27browser of course we might have some
  14030. 11:34:29errors we have to take care of the
  14031. 11:34:31errors
  14032. 11:34:32always
  14033. 11:34:35okay map departments doesn't have map
  14034. 11:34:39let's see what are
  14035. 11:34:42departments Department seem to be
  14036. 11:34:47departments it has
  14037. 11:34:51something product by Department okay so
  14038. 11:34:55this is something uh we are going to
  14039. 11:34:57Define so here inside this HF we have
  14040. 11:34:59product by Department which is a new
  14041. 11:35:02route which will display products only
  14042. 11:35:05uh for this department and we are going
  14043. 11:35:08to Define this as well but for now let's
  14044. 11:35:11just provide selection side now we see
  14045. 11:35:15right here departments um nicely
  14046. 11:35:18displayed and now let's define let's
  14047. 11:35:21open product
  14048. 11:35:24controller we have home we have show and
  14049. 11:35:27here I'm going to create a buy
  14050. 11:35:33Department let
  14051. 11:35:36me let me actually copy this method and
  14052. 11:35:40I will explain this to you so first
  14053. 11:35:42right here we need request
  14054. 11:35:44because that should also do the
  14055. 11:35:47filtering uh
  14056. 11:35:49request then we're going to accept
  14057. 11:35:51Department as well and now let's have a
  14058. 11:35:56look so this is the method and we are
  14059. 11:35:59calling abort if the department is not
  14060. 11:36:03active so then from the quer we're going
  14061. 11:36:06to get the keyword when we implement the
  14062. 11:36:08searching by keyword so we get the
  14063. 11:36:10keyword so we select the products for
  14064. 11:36:13website for the specific department and
  14065. 11:36:16then we use that keyword right here if
  14066. 11:36:18the keyword exists we perform the we we
  14067. 11:36:22title like keyword or description like
  14068. 11:36:24keyword we perform
  14069. 11:36:26pinate and then right here we render the
  14070. 11:36:30page Department index we're going to
  14071. 11:36:32create that uh we provide the department
  14072. 11:36:35resource uh here and product list um
  14073. 11:36:39resource and we provide the keyword
  14074. 11:36:41right here as well now let's create
  14075. 11:36:44Department
  14076. 11:36:49index
  14077. 11:36:51Department
  14078. 11:36:53index okay let me copy that part as
  14079. 11:37:01well okay so this is the department
  14080. 11:37:06index uh we we accept right here
  14081. 11:37:10application name as well which we are
  14082. 11:37:12going to provide from props so I'm going
  14083. 11:37:14to open handle inertia JS request and
  14084. 11:37:18I'm going to provide right here app name
  14085. 11:37:21to be config application name now we're
  14086. 11:37:25going to open this page props and we're
  14087. 11:37:27going to add right here app name to be
  14088. 11:37:30string the error is actually gone and
  14089. 11:37:34now this is the department index page
  14090. 11:37:36where we get the application name we get
  14091. 11:37:37the Department itself we're providing
  14092. 11:37:40and we get the products okay and this is
  14093. 11:37:43something related to meta SEO I'm going
  14094. 11:37:46to just remove
  14095. 11:37:49that uh or we're going to leave this
  14096. 11:37:52okay I'm going to leave this so we're
  14097. 11:37:54going to do SEO in any case so I'm going
  14098. 11:37:56to leave this so we are basically
  14099. 11:37:59working on the SEO side here so we
  14100. 11:38:02display the department name inside the
  14101. 11:38:04title we have the meta title it to be
  14102. 11:38:06the department meta title we have the
  14103. 11:38:08meta description so we are using the
  14104. 11:38:10canonical URL which should be the
  14105. 11:38:12product uh by Department we're going to
  14106. 11:38:14Define this root and we also have this
  14107. 11:38:17OG tags the department name description
  14108. 11:38:20URL uh the type and the application name
  14109. 11:38:24and down below we just display the
  14110. 11:38:25department name and we display no
  14111. 11:38:28products found or iterate over the
  14112. 11:38:31products now let's open web.php and we
  14113. 11:38:36are going to
  14114. 11:38:37Define these by
  14115. 11:38:40Department I'm going to copy this route
  14116. 11:38:43put this right here so D then the
  14117. 11:38:47department Slug and then products okay
  14118. 11:38:50and this is the product by Department we
  14119. 11:38:54save
  14120. 11:38:55that and I'm going to open now this
  14121. 11:39:02Navar uh right here and I'm going to
  14122. 11:39:04provide
  14123. 11:39:07root U
  14124. 11:39:08product product by Department providing
  14125. 11:39:15Department
  14126. 11:39:18slug so I'm going to also open product
  14127. 11:39:22list product list item or product item
  14128. 11:39:26how we call this and right here we have
  14129. 11:39:30this department name so we're going to
  14130. 11:39:32change this into
  14131. 11:39:35root product by
  14132. 11:39:40department and we need to do something
  14133. 11:39:42similar
  14134. 11:39:44on show TS6
  14135. 11:39:47page let's open this let's search for
  14136. 11:39:51department and we're going to change
  14137. 11:39:53this into
  14138. 11:39:56root the product by
  14139. 11:39:58department and product.
  14140. 11:40:03department.
  14141. 11:40:06name let's check product
  14142. 11:40:10item product by Department we haven't
  14143. 11:40:12provided
  14144. 11:40:14did product by Department slug should be
  14145. 11:40:17here but here
  14146. 11:40:20product
  14147. 11:40:22department.
  14148. 11:40:25slug now we probably have some error
  14149. 11:40:28let's have a
  14150. 11:40:30look Department parameter is
  14151. 11:40:33required Inside by
  14152. 11:40:37Department okay so we need slug
  14153. 11:40:40here in the product listing and we're
  14154. 11:40:43going to open product list
  14155. 11:40:47resource and right here we're going to
  14156. 11:40:49return slug for the
  14157. 11:40:52Department we're going to also open
  14158. 11:40:55product
  14159. 11:40:59resource and we are going to return slug
  14160. 11:41:03here as
  14161. 11:41:08well now refresh the page
  14162. 11:41:14so clicking on electronics changes the
  14163. 11:41:17URL D Electronics products as you
  14164. 11:41:21see Department Electronics I think we
  14165. 11:41:24can even
  14166. 11:41:26omit products
  14167. 11:41:29right yeah we can do
  14168. 11:41:36that okay so now we see all the products
  14169. 11:41:39in electronics click on this shows the
  14170. 11:41:41fashion products click on this shows H
  14171. 11:41:44garden tools and so on you can work on
  14172. 11:41:48to
  14173. 11:41:49add uh the active class to the
  14174. 11:41:52department which is right now opened I
  14175. 11:41:54think this is going to be a good
  14176. 11:41:55challenge to you so now I'm going to add
  14177. 11:41:59search as well so let's
  14178. 11:42:02open what do we
  14179. 11:42:05have okay there is gone now let's open
  14180. 11:42:10navbar and I'm going to work on the
  14181. 11:42:14search inside the nav
  14182. 11:42:19bar so we have
  14183. 11:42:22this mini card dropdown before which I'm
  14184. 11:42:25going to put the form so that is very
  14185. 11:42:29basic form which has join class so this
  14186. 11:42:32is the join
  14187. 11:42:33form uh which I copied uh the you can
  14188. 11:42:36find the joins in the daisy UI let me
  14189. 11:42:39open Daisy UI or we have the that open
  14190. 11:42:43and if we search for join we are going
  14191. 11:42:47to find these joins and I copied the
  14192. 11:42:51following example we just don't need the
  14193. 11:42:52filter we need on the search uh
  14194. 11:42:55placeholder and search text and I'm
  14195. 11:42:59going to also copy right now from my
  14196. 11:43:03project onsubmit and search form let me
  14197. 11:43:07put them right
  14198. 11:43:09here form even Handler on submit is a
  14199. 11:43:12has type of form event handler I'm going
  14200. 11:43:15to import this and let's import this use
  14201. 11:43:19form and we're going to accept
  14202. 11:43:22keyword right here inside
  14203. 11:43:27props
  14204. 11:43:33um I think keyw doesn't exist inside the
  14205. 11:43:36props
  14206. 11:43:39right yeah it doesn't exist inside the
  14207. 11:43:41props so we can add that into the
  14208. 11:43:46props actually uh we don't want keyword
  14209. 11:43:49to be added inside the page props
  14210. 11:43:51because that page props is for every
  14211. 11:43:54page but the keyword is something on for
  14212. 11:43:58this page so inside this page props I'm
  14213. 11:44:01going to extend and use page props and
  14214. 11:44:05I'm going to provide keyword here to be
  14215. 11:44:11string now
  14216. 11:44:14we are good so now what we are doing
  14217. 11:44:16here is that whenever the form is
  14218. 11:44:17submitted we are uh calling accessing
  14219. 11:44:21get method on the following search form
  14220. 11:44:23providing the current URL but providing
  14221. 11:44:26this keyword right here okay and here
  14222. 11:44:30inside the form magnifying glass icon
  14223. 11:44:33let's import this from
  14224. 11:44:36outline and right here we have this
  14225. 11:44:38input on change we are setting this
  14226. 11:44:41keyword inside the
  14227. 11:44:44uh search form and we have the value as
  14228. 11:44:46well data keyword and this is a button
  14229. 11:44:49which triggers the submission so if I
  14230. 11:44:51save this and we have a look so we're
  14231. 11:44:54going to see the form right here if we
  14232. 11:44:56go on the
  14233. 11:44:58homepage uh if we search for something
  14234. 11:45:01like search for first hit the enter I
  14235. 11:45:04think we haven't implemented this
  14236. 11:45:06keyword search on the homepage but we
  14237. 11:45:08did this on the uh Department page so if
  14238. 11:45:11we search for first hit the enter we see
  14239. 11:45:13the item if we add few more characters
  14240. 11:45:16then this is gone and we don't see
  14241. 11:45:19anything so let's
  14242. 11:45:22open uh product controller and I'm going
  14243. 11:45:25to copy this
  14244. 11:45:27when uh on the homepage as well here and
  14245. 11:45:31I'm going to copy the keyword as
  14246. 11:45:36well and let's accept
  14247. 11:45:39request here and we probably need such
  14248. 11:45:42type of filter in on vendor controller
  14249. 11:45:45as well so we're going to accept this
  14250. 11:45:49request uh request request here and
  14251. 11:45:54we're going to
  14252. 11:45:56provide oops we are going to provide
  14253. 11:45:59this we CLA on the vendor page as
  14254. 11:46:05well okay so if we click on this then we
  14255. 11:46:09search for something test hit on this
  14256. 11:46:14uh it found maybe because of some
  14257. 11:46:17description not sure uh let's write
  14258. 11:46:20something weird now this is gone it did
  14259. 11:46:23it doesn't
  14260. 11:46:26find
  14261. 11:46:29okay uh whatever is inside the keyword
  14262. 11:46:32that should
  14263. 11:46:33be
  14264. 11:46:35populated that should be populated right
  14265. 11:46:38here inside the search so if we open
  14266. 11:46:41product controller we are taking this
  14267. 11:46:45keyword right here and assigning giving
  14268. 11:46:49this into the view and this is what I'm
  14269. 11:46:51going to change also so I'm going to
  14270. 11:46:54copy this I'm going to open handle
  14271. 11:46:56inertial JS request and I'm going to
  14272. 11:46:58provide this keyword right here search
  14273. 11:47:05keyword
  14274. 11:47:07okay
  14275. 11:47:10keyword we need we have two commas
  14276. 11:47:19here what's the issue oh this is the
  14277. 11:47:23issue okay so now we have this keyword
  14278. 11:47:26on every page and if we refresh this
  14279. 11:47:29right
  14280. 11:47:30now we are going to get the keyword from
  14281. 11:47:33here and we can even open this
  14282. 11:47:36index
  14283. 11:47:38DTS and
  14284. 11:47:41inside page props we can e the add this
  14285. 11:47:46keyword keyword equals
  14286. 11:47:49string okay now if we open
  14287. 11:47:53navbar we can remove this from here
  14288. 11:47:56because now page props as keyword inside
  14289. 11:48:01okay so filtering let's remove this now
  14290. 11:48:03filtering uh inside the vendor store
  14291. 11:48:05Works filtering inside
  14292. 11:48:08departments prod this returns something
  14293. 11:48:12this does return
  14294. 11:48:19anything what I want to do when when I
  14295. 11:48:23do this skate I want to preserve scroll
  14296. 11:48:27true and I want to preserve State true
  14297. 11:48:31as well otherwise it feels like a
  14298. 11:48:33traditional application not inertia so
  14299. 11:48:36if I search for something like prod hit
  14300. 11:48:38the enter now this performs the field
  14301. 11:48:42filtering but the cursor still continues
  14302. 11:48:44blinking here and this is exactly what I
  14303. 11:48:46want so we have single page application
  14304. 11:48:49click on test it's still find
  14305. 11:48:52something are you kidding
  14306. 11:48:54me uh Test Pro hit the enter now only
  14307. 11:48:58one is left now the scroll will be
  14308. 11:49:01preserved the state will be preserved
  14309. 11:49:03and that's pretty cool we can test this
  14310. 11:49:05on here as well
  14311. 11:49:07prod
  14312. 11:49:09and yeah the cursor still continues
  14313. 11:49:11blinking there and this is pretty cool
  14314. 11:49:14so filtering by departments is also
  14315. 11:49:19implemented successfully now let's talk
  14316. 11:49:22a little bit about SEO as well because
  14317. 11:49:25that's a very crucial part of building
  14318. 11:49:27an e-commerce website where you want SEO
  14319. 11:49:30capabilities and even though we built
  14320. 11:49:32single page application with react in
  14321. 11:49:34LEL we do have server side rendering and
  14322. 11:49:37we are going to have great SEO and this
  14323. 11:49:39is how we're going to have and we're
  14324. 11:49:41going to see the result as well well so
  14325. 11:49:43I created this new migration to add SEO
  14326. 11:49:45columns to products I executed the
  14327. 11:49:47migration columns we are added then I
  14328. 11:49:50open the product resource from the
  14329. 11:49:52filament folder and right here we addit
  14330. 11:49:56this meta title and meta description
  14331. 11:49:58this is the result right here we see
  14332. 11:50:00this SEO section we can provide SEO meta
  14333. 11:50:04title here and SEO meta description here
  14334. 11:50:08so let me click on Save
  14335. 11:50:10changes good inside product resource
  14336. 11:50:13when we return the product information
  14337. 11:50:16on the product Details page we have this
  14338. 11:50:18meta title and meta description returned
  14339. 11:50:21and I'm going to open the show T6 and
  14340. 11:50:23I'm going to change this so instead of
  14341. 11:50:25providing title as the attribute inside
  14342. 11:50:27the head I'm going to change this and
  14343. 11:50:30put the head right here we need we have
  14344. 11:50:32the product title we need the product
  14345. 11:50:35meta title actually let's open the
  14346. 11:50:38product and add right
  14347. 11:50:40here meta title and meta
  14348. 11:50:49description okay so scroll down
  14349. 11:50:53below so we are using this meta title if
  14350. 11:50:56that doesn't exist we are using the
  14351. 11:50:58product title we using the meta
  14352. 11:50:59description inside the canonical URL we
  14353. 11:51:02provide the product URL uh we have the
  14354. 11:51:05OG related things as well and inside OG
  14355. 11:51:07image we are using images at zero and if
  14356. 11:51:11that exists we are taking the small
  14357. 11:51:13version of it and inside the app name
  14358. 11:51:15we're going to use
  14359. 11:51:18the app name let me import that like
  14360. 11:51:22this uh
  14361. 11:51:28okay so I need to change this
  14362. 11:51:32into page
  14363. 11:51:35props and then we need
  14364. 11:51:39this okay so move this down
  14365. 11:51:44so inside page props we have the app
  14366. 11:51:46name so that's going to be good now
  14367. 11:51:49let's stop these mpm run V server and
  14368. 11:51:52see how server side rendering actually
  14369. 11:51:54works in fact if we have this V server
  14370. 11:51:56up and running and we check the product
  14371. 11:51:58Details page let's see so let's CH
  14372. 11:52:00choose this one click on this so this is
  14373. 11:52:02the product Details page let's click on
  14374. 11:52:05this product Details page okay and if we
  14375. 11:52:07check the page Source we are not going
  14376. 11:52:10to see anything um related so everything
  14377. 11:52:13is client side rendered we don't see the
  14378. 11:52:15meta titles or anything we don't even
  14379. 11:52:17see the product details so if you search
  14380. 11:52:19for the product title which should be
  14381. 11:52:21there uh we see that only in two places
  14382. 11:52:24and that places are actually inside the
  14383. 11:52:26JavaScript array we don't see them
  14384. 11:52:27inside html text so this is um how this
  14385. 11:52:32is what we're going to fix so first
  14386. 11:52:34we're going to execute mpm run build and
  14387. 11:52:36this needs to be part of your deployment
  14388. 11:52:39session so again if you're interested to
  14389. 11:52:41see how to deploy this project on
  14390. 11:52:43production with great SEO and serice
  14391. 11:52:45side rendering imp implemented as well
  14392. 11:52:48check my latest website on the Cod
  14393. 11:52:50holly.com the Cod
  14394. 11:52:53holic you I'm actually tired right now I
  14395. 11:52:58said the cod.com theod holic
  14396. 11:53:00youtube.com/ thee codol and check the
  14397. 11:53:03following video full stack application
  14398. 11:53:07build and deploy LEL 11 plus react fulls
  14399. 11:53:10application so this is it you're you're
  14400. 11:53:12going to check it and you're going to
  14401. 11:53:13see the serice side rendering how to set
  14402. 11:53:15up and continuous integration as well
  14403. 11:53:18okay so in our case we executed mpm run
  14404. 11:53:21build and then we're going to execute
  14405. 11:53:24mpm uh not mpm but PHP Artisan inertia
  14406. 11:53:30start- SSR so this is going to start
  14407. 11:53:33serice side rendering through the using
  14408. 11:53:35this built assets and now look at this
  14409. 11:53:38so first of all our application is going
  14410. 11:53:40to be super smooth we're going to see
  14411. 11:53:41the glitch right here image glitch which
  14412. 11:53:44I'm going to talk about it why it
  14413. 11:53:46happens but this is uh it's going to be
  14414. 11:53:49very super fast navigation everything is
  14415. 11:53:52going to be great and if we refresh that
  14416. 11:53:55specific page now we're going to see a
  14417. 11:53:57few more things so here we see these
  14418. 11:54:00meta titles So Meta title EO meta title
  14419. 11:54:03meta description we see the canonical
  14420. 11:54:05URL we see the title we see description
  14421. 11:54:09inside OG image we see something else
  14422. 11:54:13this is it so inside OG image we see the
  14423. 11:54:15product image not
  14424. 11:54:18the not the variation image what we
  14425. 11:54:21should see right here so we should see
  14426. 11:54:23this black headset but we see something
  14427. 11:54:26else okay and that happens because we
  14428. 11:54:29have something not 100% properly
  14429. 11:54:33implemented and let me tell you what I
  14430. 11:54:35mean so if we open uh product
  14431. 11:54:40resource right here so we are using
  14432. 11:54:42uh inside images these get media images
  14433. 11:54:46and this always returns the product
  14434. 11:54:48images okay then we get those images uh
  14435. 11:54:52from the product images and then we have
  14436. 11:54:54these images and that is calculated
  14437. 11:54:57fully on the front end Side based on the
  14438. 11:55:00selected variations but what if there is
  14439. 11:55:03H
  14440. 11:55:05um if there is something like if we have
  14441. 11:55:08some options selected in the URL we
  14442. 11:55:11refresh it and anyway we still see this
  14443. 11:55:13girl which is the product image and then
  14444. 11:55:16we see the this so this is something
  14445. 11:55:19what we are going to change it and let
  14446. 11:55:23me show you how we can do this so if we
  14447. 11:55:26open
  14448. 11:55:28now the product resource so we're going
  14449. 11:55:32to change how we pass images right here
  14450. 11:55:34okay so this is what we're going to
  14451. 11:55:36change so we have options so let me
  14452. 11:55:40actually take so we have the options
  14453. 11:55:42we're going to take these options from
  14454. 11:55:44the URL from the request and the purpose
  14455. 11:55:47of this is that we are going to always
  14456. 11:55:49return the images for the uh correct
  14457. 11:55:53image from this so first returning
  14458. 11:55:56product image and then on the front side
  14459. 11:55:58on the react side changing in the with
  14460. 11:56:00the variation image is actually causing
  14461. 11:56:03this bad SEO thing so we need to pass
  14462. 11:56:06the proper data from server to react and
  14463. 11:56:09then it will correctly start uh it will
  14464. 11:56:13correctly render this inside server side
  14465. 11:56:16so here we get the options and then I'm
  14466. 11:56:19doing the following so if options exist
  14467. 11:56:21we're getting images for option and we
  14468. 11:56:24do have that method defined in the
  14469. 11:56:27product uh we get the list of images and
  14470. 11:56:30if images doesn't exist we get um images
  14471. 11:56:34and that get images basically is
  14472. 11:56:39taking let's open this product so if we
  14473. 11:56:42see get images so this is taking the
  14474. 11:56:46first image set um from the first option
  14475. 11:56:51okay so this is this is going to take
  14476. 11:56:52the first uh variation option and return
  14477. 11:56:55its
  14478. 11:56:57images uh right here and this is going
  14479. 11:57:01to get images for options uh don't we
  14480. 11:57:05have
  14481. 11:57:07that uh let me quickly get this method
  14482. 11:57:12get images for options we should have
  14483. 11:57:17that
  14484. 11:57:19get images for
  14485. 11:57:21options now we have get image for option
  14486. 11:57:26for single image but we need get images
  14487. 11:57:29for options I see so let's put this get
  14488. 11:57:33images for options which is going to
  14489. 11:57:36return the entire list of images okay so
  14490. 11:57:41now now depending on if we have options
  14491. 11:57:44we're going to get images for the
  14492. 11:57:45options if we don't have options we're
  14493. 11:57:47going to call get images which will also
  14494. 11:57:50check if we have some options defined
  14495. 11:57:52and if they have some images it's going
  14496. 11:57:54to return them otherwise we're going to
  14497. 11:57:56return this get media so now if we
  14498. 11:57:59refresh the page this still happens
  14499. 11:58:02because it is built in a different way
  14500. 11:58:06so let's no hold on uh it should not do
  14501. 11:58:10it let me
  14502. 11:58:12let me go
  14503. 11:58:16back and I'm going to open this product
  14504. 11:58:19resource and I'm going to
  14505. 11:58:23put images
  14506. 11:58:26here images cool now if we refresh this
  14507. 11:58:31now look at this so now we don't see
  14508. 11:58:33this glitch we are using service side
  14509. 11:58:35rendering but uh the SSR server does
  14510. 11:58:38this properly if I refresh the page now
  14511. 11:58:40this is changed
  14512. 11:58:42and this is going to open the black
  14513. 11:58:44headset I guess because the URL belongs
  14514. 11:58:47to the black headset but if I view page
  14515. 11:58:50source for this one which has options
  14516. 11:58:52there as
  14517. 11:58:54well now here we're going to see green
  14518. 11:58:59headset okay and that is done on the
  14519. 11:59:01server side rendering so we have the
  14520. 11:59:03canonical URL right here and here to
  14521. 11:59:05have the to be the URL without
  14522. 11:59:08variations and the cool thing is that if
  14523. 11:59:10you deploy this project and C copy this
  14524. 11:59:12and share it on Facebook Twitter any any
  14525. 11:59:14social media platforms you're going to
  14526. 11:59:16get this nice preview uh be because of
  14527. 11:59:19the OG text and just like this we have
  14528. 11:59:23implemented uh
  14529. 11:59:26great um great SEO on on on our project
  14530. 11:59:31so I'm thinking that yeah we probably
  14531. 11:59:33need to implement SEO on other pages but
  14532. 11:59:36I will leave this part to you the main
  14533. 11:59:37thing is that I showed to you how you're
  14534. 11:59:39going to do this and again I mentioned
  14535. 11:59:41this many times because this is
  14536. 11:59:42important if you want to see how to set
  14537. 11:59:45up this inertia with uh SSR on
  14538. 11:59:48supervisor on VPS server check my other
  14539. 11:59:51tutorial I mentioned and you're going to
  14540. 11:59:53see the full steps how you can deploy
  14541. 11:59:55this

About this transcript

This page contains the full transcript of Build Multi Vendor E-Commerce Marketplace with Laravel & React by The Codeholic, generated from the public captions YouTube serves with the video. The transcript has 97,657 words across 14,541 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.