Build Multi Vendor E-Commerce Marketplace with Laravel & React — Transcript
Full transcript
- 0:00in this video I will teach you how to
- 0:02create multivendor e-commerce
- 0:04marketplace with laravel and react from
- 0:08absolutely scratch the video has time
- 0:10codes so if you want to jump to a
- 0:12specific section you can do this also I
- 0:14have been working on this project for
- 0:15about two months and I did my best to
- 0:18create a single YouTube video that would
- 0:20cover the most complicated e-commerce
- 0:23features such as shopping cart
- 0:25functionality adding items into the cart
- 0:27managing items into the card and also
- 0:30adding items for the guest users
- 0:32creating product variations vendor users
- 0:35will be able to Define different sizes
- 0:38colors and they will also be able to
- 0:40attach different images to different
- 0:42variation options Implement checkout
- 0:44functionality using stripe Implement
- 0:47multivendor functionality use stripe
- 0:50connect to connect vendors into our
- 0:53Marketplace account and Implement
- 0:56payouts to vendors once in a while we're
- 0:58going to also Implement pay a
- 1:00distribution between stripe the platform
- 1:03and the vendor and there are way more
- 1:06than
- 1:08[Music]
- 1:12this hello everyone my name is Zur and
- 1:15I'm the code holic I have 12 plus years
- 1:18of experience working as professional
- 1:20software developer I have created and
- 1:22delivered dozens of projects to my
- 1:24clients even now I work full-time I am
- 1:27dead of three girls and I love teaching
- 1:29so I still somehow manage to find the
- 1:32time to create such massive tutorials so
- 1:34if you find this tutorial helpful please
- 1:36hit the like button and also subscribe
- 1:39to the channel because that really means
- 1:41a lot to me I started working on PHP in
- 1:432013 since 2015 I have been using PHP
- 1:47storm as my primary IDE today I'm super
- 1:51proud to announce that this massive
- 1:53video is sponsored by jet brains and PHP
- 1:56storm if you're a developer writing a
- 1:58code you probably know what is jet brace
- 2:00jet brace creates all kind of IDs and
- 2:03tools for different types of programming
- 2:05languages such as python Java CP
- 2:08JavaScript and so on for PHP they have
- 2:10PHP storm which I personally think that
- 2:12is the best PHP ID out there PHP storm
- 2:15is all-in-one tool it's ready to be used
- 2:19as soon as you install it no need to
- 2:21waste your time or install some plugins
- 2:23or extensions it supports all PHP
- 2:26Frameworks laravel WordPress it has
- 2:28built-in database client which supports
- 2:30almost all the databases and it works
- 2:33perfectly for the front end framework
- 2:35such as Vu react or tan CSS the autoc
- 2:38completion is super smart and very often
- 2:40it suggests the options which I'm
- 2:42actually looking for recently they added
- 2:45full line autoc completion with the help
- 2:47of local AI PHP storm downloads local AI
- 2:51model and it analyzes your project code
- 2:54and gives you Smart Suggestions based on
- 2:56the code context and all that happens
- 2:59without your project code leaving your
- 3:01computer the navigation is super smooth
- 3:04you can jump around between classes
- 3:06methods properties you can move your
- 3:09classes from one folder into another or
- 3:11rename the name space or change the
- 3:13class name everything is smooth and
- 3:16whenever you do such things PHP storm
- 3:18doeses refactoring for you you're going
- 3:20to see this in the video as well when I
- 3:22moved 10 or 12 react files from one
- 3:25folder into another and I have not even
- 3:28updated any Imports in the project
- 3:30everything was done automatically by PHP
- 3:32stor yes that works on react files as
- 3:34well it also has full git integration
- 3:37from inside the ID you can create
- 3:40comment messages you can exclude certain
- 3:42files or even exclude certain changes
- 3:45from the files in the comet message so
- 3:48that you can create separate Comet
- 3:49messages for those files or those
- 3:51changes it's local history actually
- 3:54saved my life in many cases when I lost
- 3:57something which I didn't have commented
- 3:59using git and I was able to recover
- 4:01these only because of the PHP Storm's
- 4:03local history I also use its scratch
- 4:06files features a lot and you're going to
- 4:07see this also in the project when I open
- 4:09the scratch file for some brainstorming
- 4:12for explaining things for some notes it
- 4:14works like a charm even if you close
- 4:16that scratch file it still is associated
- 4:19to the project and you can always reopen
- 4:21this whenever you need that after all if
- 4:23you still want to customize PHP stor
- 4:26this is also possible you can install
- 4:28plugins for themes or for different
- 4:30functionalities Lal idea is a plug-in
- 4:33for Lal developers it adds features like
- 4:36grow and model AO completion code
- 4:39generation and migration support and all
- 4:42that is also compatible with different
- 4:44lateral packages such as filament Live
- 4:47Wire inertia and a lot more I use this
- 4:50package for this specific project also
- 4:53and you're going to see how helpful it
- 4:54is in cases when I want to autocomplete
- 4:57Road names for example in the react
- 4:59files and that happens like a charm of
- 5:02course that's just one example but
- 5:03you're going to see other examples in
- 5:04the project as well PHP storm was kind
- 5:07enough to provide coupon code for my
- 5:08subscribers if you aren subscribed
- 5:10please hit the Subscribe button right
- 5:11now go to the website jb. g/ thee codol
- 5:15or click to the link in the video
- 5:17description in the following form you're
- 5:18going to enter the coupon code the codic
- 5:20your details and you will receive three
- 5:22months PHP storm license on your email
- 5:25for free that will help you to get
- 5:26started with PHP storm and if you like
- 5:28it of course you can extend it and thank
- 5:31you jet brains and PHP storm for
- 5:33sponsoring this video now to get back to
- 5:35our project if you are really into this
- 5:38project but you're a beginner and you
- 5:39don't have any experience on LEL and
- 5:42react I highly recommend to get some
- 5:44beginners courses for LL and react for
- 5:47LL I have amazing course LL for
- 5:50beginners it is 24 hours course it has
- 5:53first couple of modules actually for
- 5:54free you can find this course on my
- 5:56website the cod.com and I really
- 5:58encourage you just to have a look at the
- 6:00first three modules watch it and you
- 6:03will understand what I mean and also
- 6:05have a look at the uh course curriculum
- 6:08you're going to find out all the modules
- 6:10that you're going to teach in this
- 6:11course even though this course is
- 6:13created for beginners actually there are
- 6:16some modules which are appropriate for
- 6:18intermediate developers as well you're
- 6:20going to learn authentication and
- 6:22authorization uh what are Gates and
- 6:24policies how to write tests and how to
- 6:26deploy your projects on production
- 6:28environment on custom domain on VPS
- 6:30server check the course on my website
- 6:32the cool.com and you can find out
- 6:35everything by yourself if you're new to
- 6:36react I recommend to grab some react for
- 6:39beginners course now let's have a look
- 6:41at the full demo of this project on the
- 6:44homepage we see all the published
- 6:46products from our vendors at the moment
- 6:48we have only three products each product
- 6:51has the information by whom this
- 6:53specific product is created and in which
- 6:56department it exists by clicking these
- 6:59links it is going to open separate
- 7:01profile page for this vendor or if we
- 7:04click on the department it's going to
- 7:05open separate departments page we also
- 7:09have ability to search items by keyword
- 7:12generally on the homepage or inside
- 7:14specific Department by clicking on one
- 7:17of the department it is going to filter
- 7:19out and leave only products inside this
- 7:22department we can add items into the
- 7:24card from the homepage just clicking
- 7:27these buttons or we can go inside the
- 7:29the product Details page have a look at
- 7:31the full version of the product and then
- 7:33add that into the cart as we see right
- 7:36now this product has multiple images it
- 7:39has multiple variations each variation
- 7:42option has its own images and we see
- 7:44right here different variations like
- 7:46size style color and so on when we add
- 7:51different variation inside the cart
- 7:53we're going to see this as a different
- 7:55item in the card details so we see black
- 7:59headset and we see this green headset
- 8:01and right here we also see what
- 8:03variation options we used to add that
- 8:07item into the cart so from here we have
- 8:09ability to change the quantity of the
- 8:10item delete that from the cart or save
- 8:13for later we also have ability to pay
- 8:16only for this vendor however clicking
- 8:19proceed to check out will perform the
- 8:21checkout for all the cart items what we
- 8:24have let's check another product this
- 8:26also has variations and I defined
- 8:28different quantity and different size
- 8:31for each variation options let's say the
- 8:34green one is kind of limited it's uh has
- 8:38only three item left and its price is a
- 8:40little bit higher relative to other one
- 8:43so we also have possibility to Define
- 8:45such things and I cannot add more than
- 8:48three items into the cart okay let's add
- 8:51this one as well now let's check out our
- 8:53cart items and right here we have two
- 8:56vendors vendor store and the second
- 8:58which is Zoomer I'm going to click on
- 9:01this proceed to check out which asks me
- 9:03to authenticate first I have
- 9:05authenticated and I'm going to proceed
- 9:07to check out on the Strip page I also
- 9:09get the overview of the items what I am
- 9:12about to check out right now I'm running
- 9:14this demo on my local installation and
- 9:16images are not visible because of this
- 9:19but as soon as you deploy the project
- 9:21somewhere on VPS for example then you
- 9:23are going to see the images right here
- 9:25as well and we see also additional
- 9:27information which type what type of
- 9:29variations we are trying to check out
- 9:32right now so let me fill the information
- 9:35after filling out the user information
- 9:37the payment was made we are redirected
- 9:39back in our website we we see this nice
- 9:41success message payment was completed
- 9:43and we see two orders right here one is
- 9:46for the vendor store with the order
- 9:48number items and total and second is for
- 9:51the Zoomer uh vendor there will be three
- 9:54emails sent totally because of this
- 9:56order so we're going to see emails to
- 9:58each vent one email to each vendor and
- 10:01we're going to see one email to the user
- 10:04as well let's check the user email first
- 10:06you we customized this email completely
- 10:09we used our own logo our own design
- 10:11payment was completed successfully we
- 10:14see the details of the uh seller one
- 10:17order items total we see also the items
- 10:20for the seller one and here we see this
- 10:21view order details button and we have
- 10:23the seller 2 information right here as
- 10:26well with some additional information
- 10:28you can put right here whatever you want
- 10:30now let's see other orders this order is
- 10:33uh sent to vendor one we see vendor
- 10:36details here what was the um order total
- 10:40what was the payment processing fee what
- 10:42was that was basically stripe fee the
- 10:45platform fee which is by default 10% um
- 10:49deducting this payment processing fee
- 10:52and what was the vendors earning out of
- 10:55the following sale so we have the
- 10:57breakdown of the cast
- 10:59and we have additional information here
- 11:01and now we can check the second order
- 11:03email for the vendor too again same type
- 11:06of information order total payment
- 11:08processing fee platform fee and our
- 11:11earnings as a vendor and we see also the
- 11:13details of each product now if I log out
- 11:16from the website and authenticate as
- 11:19vendor user I'm going to see my products
- 11:21and my orders and in my order section I
- 11:24see this latest order with order number
- 11:2620 total price and my total which I
- 11:30earned out of the following order I'm
- 11:32going to sign out from here and I'm
- 11:35going to log in with admin user now so
- 11:37we have three roles admin vendor and
- 11:40regular user and all of them has their
- 11:42own access to data so for the admin user
- 11:46we have departments and vendors admin
- 11:48users will be able to define the
- 11:50Departments they want to be displayed on
- 11:53the website so if I click on electronics
- 11:55we're going to see the electronics
- 11:57department information with a name slack
- 12:00and right here we see all the categories
- 12:02that belongs to electronics department
- 12:05in the vendor section admin users will
- 12:07see all the vendors with their status
- 12:09and the store name and if we want to
- 12:12block certain vendors from the website
- 12:15uh let me actually block this one so I'm
- 12:17going to change this approved status
- 12:19into rejected or even pending which
- 12:21means that it is not actually approved
- 12:24and right now if we try to access the
- 12:26website we are not going to see uh
- 12:29products from this vendor so two
- 12:31products we are actually hidden on the
- 12:32website because the vendor status was
- 12:35changed uh from approved if we set this
- 12:37back into approved by the Admin user
- 12:40then the products for that vendor will
- 12:42be also displayed on the website now
- 12:45let's say I'm a new vendor user and I
- 12:48want to become a member of this
- 12:50Marketplace and start selling the year
- 12:52what should I do so first let me log out
- 12:55and create new account I'm going to use
- 12:57actually my name right here as soon as I
- 12:59create the account I'm authenticated but
- 13:02I need to verify my email address so I
- 13:05receiv received a new email right here
- 13:06ver for your email address I'm going to
- 13:08click on this and verify my email
- 13:10address right now I am just buyer and I
- 13:13can purchase the items add them uh into
- 13:16the cart and check out them but if I
- 13:18want to become a vendor I'm going to go
- 13:20into profile section and right here I
- 13:22have this become a vendor button I'm
- 13:25going to click on this I'm going to
- 13:26confirm this and now I'm immediately ly
- 13:29a vendor user and my status by default
- 13:32is approved so we have this Auto
- 13:34approval process for vendors which you
- 13:36can obviously customize and change it
- 13:38and uh create new vendors with a pending
- 13:41status and then admin users can approve
- 13:43them so because I'm approved I can just
- 13:46um adjust my store name store details I
- 13:48can update them or this is the
- 13:51interesting thing so I can connect to
- 13:53stripe without connecting to stripe I
- 13:56can actually still access my portal uh
- 13:59create the products and display those
- 14:02products onto the website and even other
- 14:04users can actually purchase my products
- 14:07but without connection to stripe I will
- 14:09not be able to earn the money now the
- 14:12platform will not transfer the money to
- 14:15my stripe account so this is something
- 14:18uh we are going to do definitely so I'm
- 14:19going to click on this connect to Stripe
- 14:21Right now this starts stripe onboarding
- 14:25process so this is hosted on the stripe
- 14:27you can see the domain connect .
- 14:29stripe.com and as a vendor I have to
- 14:32provide all the necessary details that
- 14:34stripe requires from me to be able to
- 14:37connect to Marketplace which I'm going
- 14:39to do right now this is the final stage
- 14:42where I review and submit all my
- 14:44information after which I will be
- 14:46redirected back into my website so if I
- 14:49go into my profile right now I'm going
- 14:51to see that you are successfully
- 14:53connected to stripe and now whenever I
- 14:56sell something I will be able to paid
- 14:58out out now I'm going to access my admin
- 15:01area from which I can create new
- 15:04products I'm going to click on the
- 15:05product section new product okay that is
- 15:09Main's t-shirt we're going to choose the
- 15:12department we're going to choose the
- 15:14category I'm going to provide some test
- 15:16description here provide price quantity
- 15:19which if I leave empty means unlimited
- 15:21quantity but let's give it five status
- 15:24is going to be published and here I can
- 15:26also provide SEO related information
- 15:28such as metatype title or description I
- 15:30click on Create and now we can upload
- 15:33images on that product or we can go
- 15:36inside variation types and Define
- 15:38different variations now this is
- 15:41interesting part I'm going to Define two
- 15:43variations for this product we're going
- 15:45to have image variation I'm going to
- 15:48choose image type right here and we're
- 15:51going to give it color so let me
- 15:53actually upload images first let's go
- 15:56into my folder I have this t-shirt and
- 15:59I'm going to choose black one right now
- 16:02upload all of them let's give it also
- 16:04name black I'm going to collapse this
- 16:07and I'm going to no new Option inside
- 16:09image let's upload other images let's
- 16:12give it text white I'm going to collapse
- 16:15this two more
- 16:17options this is going to be
- 16:20red collapse this and one more
- 16:24option this is going to be blue now I'm
- 16:28going to add second second variation
- 16:29type which is going to be size I'm going
- 16:31to choose the type to be radio give it
- 16:34size and let's define as many sizes as
- 16:37you want I'm going to Define small new
- 16:40Option this is going to be medium
- 16:43another option this is going to be large
- 16:46we don't need to upload any images for
- 16:48size so we can collapse this and we can
- 16:51make an overview right here we can
- 16:53reorder the images as well so I'm going
- 16:55to open this I want this one to be the
- 16:57first one second
- 16:59okay fine now I'm going to click on Save
- 17:01changes and we added two variation types
- 17:03right now the product is published and
- 17:06now I'm going to add also variations
- 17:09variation options so we just addit types
- 17:12but right now we have the combination of
- 17:14these variation types we have black
- 17:15small we have white small we have red
- 17:18small we have blue small and so on you
- 17:21get the idea right so and for each this
- 17:23combination we can adjust quantity and
- 17:26the price let's say that the r one is
- 17:30kind of limited so we have it only one
- 17:34and its price is actually 25 now we're
- 17:37going to scroll down below and I'm going
- 17:38to click on Save changes the product is
- 17:41published and if we go on the homepage
- 17:44right now we're going to see one more
- 17:46product right here black is the default
- 17:48one and we see four colors clicking on
- 17:51this updates the UI and we see red small
- 17:55is only one left and red small also has
- 17:58different price now I'm going to log out
- 18:01and log in as a regular user again add
- 18:04Zora's product into the cart and I'm
- 18:06going to perform the checkout after
- 18:08check out we see the success Mage and
- 18:10now if I log out and log in back with
- 18:13zoraa user we're going to see a single
- 18:15order for this user with the total price
- 18:17my subtotal and the order number as well
- 18:19now I'm going to perform payout to
- 18:22venders if I check right now my stripe
- 18:25account we're going to see that I have
- 18:27three connected accounts this is one
- 18:30this one is not connected the onboarding
- 18:32was not finished I did this on purpose
- 18:34and payout will not happen to this
- 18:36vendor but for these three payout should
- 18:39happen if there are some orders and the
- 18:41last one which we connected today is my
- 18:44account Zora's account actually and
- 18:46zoraa should receive something on his
- 18:49balance to perform the payout to vendors
- 18:51we have the following custom Artisan
- 18:53commment written PHP Artisan payout
- 18:55vendors and this is also added inside up
- 18:58service provider with this schedule so
- 19:01if you have schuer configured correctly
- 19:05this command will be executed once in a
- 19:08month on the first of the month
- 19:09overnight and it is going to perform the
- 19:12payout to vendors right now I'm going to
- 19:14execute this by hand and we're going to
- 19:17see the output as well so here we see
- 19:19nothing to process and that happens
- 19:21because there should be at least 30 days
- 19:26past since the order was made but
- 19:29because I simply made the order right
- 19:30now the payout didn't work so I opened
- 19:34orders table and I changed orders
- 19:36created date from 26th of uh November
- 19:39into 26th of September and I'm going to
- 19:42actually save this right now and we're
- 19:44going to reexecute payout vendors now it
- 19:47is processing payouts and it is sending
- 19:50these to the following users for vendor
- 19:52user for user 3 and for Zur as well and
- 19:55to if we check right now inside stripe
- 19:58connection accounts we are going to see
- 20:00my user zoraa has balance
- 20:041283 the entire project is built with L
- 20:06and react but because of the server side
- 20:09rendering we have full SEO capabilities
- 20:12as well for example if we go the product
- 20:14on the product Details page um check
- 20:17specific variations of the products
- 20:19we're going to also see that this
- 20:21updates the URL and in the URLs we see
- 20:23different options what we have just
- 20:25chosen by choosing uh different options
- 20:28right here the URL is also updated and
- 20:31right now we have this pink headset
- 20:34selected and now if we check page source
- 20:38and scroll down below we're going to see
- 20:39right here these meta tags as well so we
- 20:41have meta title meta description uh we
- 20:44have this OG title description OG image
- 20:47as well we have the canonical URL of the
- 20:50product and all that happens with the
- 20:52help of inertia JS uh serice side
- 20:56rendering so if we copy this OG G image
- 20:59URL and open this we're going to see
- 21:00that this is actually a pink headset so
- 21:03this is fully rendered on the server
- 21:05side so you can copy the URLs share it
- 21:08on social media or even Google will
- 21:11start indexing your products nicely if
- 21:13you want to know how to deploy your LL
- 21:15react with serice side rendering on VPS
- 21:18on custom domain I do have a separate
- 21:20video on this as well I hope you like
- 21:22the project and you are as much excited
- 21:24as I was when I started working on this
- 21:26project I plan to improve this project
- 21:28there will be much more features added
- 21:30step by step and if you're interested to
- 21:32know more about this when the new
- 21:34feature is added or generally to get
- 21:37some updates about the project just
- 21:39check the video description this project
- 21:41is not the type of project you're going
- 21:43to watch on mobile or you can watch it
- 21:45and you're going to learn everything
- 21:47there is a lot more to do this so the
- 21:50project duration is 12 hours but
- 21:52actually you might need two three or
- 21:54even five times more than 12 hours to
- 21:58follow follow along and implement the
- 22:00same functionality what is done in the
- 22:01video please be patient just start
- 22:04building follow along if you are stuck
- 22:07you can rewind check the same section
- 22:09second times I'm sure you can do it and
- 22:12you can learn a lot out of this project
- 22:15and whenever you feel something about
- 22:18this project positive or negative please
- 22:21leave a comment down below under the
- 22:23video and we can discuss few things uh
- 22:25in the comment section as well I will be
- 22:27happy to help as as many of you as I can
- 22:31now let's start building this awesome
- 22:33project now let's create new LEL project
- 22:36there are a couple of ways to create new
- 22:38project one of them is to open Lal herd
- 22:41and open sites right here and then click
- 22:45add button here and follow this wizard
- 22:48from the user interface the second way
- 22:50is to create using terminal which is
- 22:52exactly what I'm going to do I'm going
- 22:54to close Lal her and I'm going to open
- 22:57gitbash Which is my pref choice of
- 22:59terminal on Windows you can use any
- 23:01terminal you prefer just make sure you
- 23:04have composer PHP node commands globally
- 23:07available and make sure you also have a
- 23:10Lal installer installed globally using
- 23:13composer for this you're going to
- 23:14execute composer Global require
- 23:19ll/ installer you hit the enter it is
- 23:22going to install a ll installer and
- 23:25you're going to have a ll commment
- 23:26globally available after which we we are
- 23:29going to execute Lal new and the local
- 23:33folder name inside which we are going to
- 23:36create the project but first i'm going
- 23:38to navigate into her folder because this
- 23:41is the folder inside which I want to
- 23:42create my project this is where I have
- 23:45all my projects using LEL herd right
- 23:47here okay so let's clear this up and now
- 23:51I'm going to execute LL new Lal
- 23:56react e-commerce with the enter now we
- 23:59have to choose St I'm going to choose
- 24:02Breeze I'm going to choose react here
- 24:04I'm going to choose dark
- 24:06mode I'm going to choose server side
- 24:10rendering and typescript we hit the
- 24:12enter I'm going to choose the default
- 24:14one which is past and now it's is going
- 24:16to take few seconds or minutes to
- 24:18download and set the project for us now
- 24:21it asks us which database we want to use
- 24:24I'm going to choose the default one
- 24:25which is sqlite so hit the enter and the
- 24:28default one is also to run migrations so
- 24:30I'm going to hit the enter and the
- 24:31migrations we are executed after which
- 24:35it is going to install Lal Bree with
- 24:38inertia and it's going to finish the
- 24:41project setup it is going to execute uh
- 24:43also mpm run build and npm run install
- 24:46it is going to also install a LEL pest
- 24:49in our project okay the project setup
- 24:52was completed it executed mpm run build
- 24:56right here with a typescript build for
- 24:59uh serice side rendering as well and
- 25:01finally we need to navigate into the
- 25:03following folder and we can already
- 25:04access the project on the following URL
- 25:07so I'm going to open this right now in
- 25:10my browser and this domain was assigned
- 25:14using Lal herd so we can access this if
- 25:16you don't use Lal herd use um zamp or
- 25:20something else you can always start the
- 25:22project using composer run de which is
- 25:25relatively new command so because
- 25:28because we have these started using
- 25:30laral herd we don't need to execute a
- 25:32PHP Artisan serve the only thing we need
- 25:34to execute is mpm run Dev for
- 25:38development okay I'm going to explain
- 25:40this in more detailed way but first
- 25:42let's open the project using PHP store
- 25:46I'm going to open explorer. EXA the
- 25:49current
- 25:50folder and here we have all the projects
- 25:54and Lal react Ecommerce is our project
- 25:57so I'm going to open this using PHP stor
- 26:01okay so this is Project already opened U
- 26:05because of lot of well um because of the
- 26:08windows def Ender so we have to exclude
- 26:10some of the folders from the def Ender
- 26:13to increase the
- 26:14performance of the project so we have to
- 26:17exclude this here we have to agree on
- 26:21that and then I'm going to open PHP
- 26:24storms buil-in
- 26:26terminal and if you don't use Lal her
- 26:30you can start the project by executing
- 26:33composer run Dev which runs couple of
- 26:37commments this is relatively new
- 26:40composer command in Lal projects and it
- 26:43is going to execute mpm run Dev as well
- 26:46so here we have the V server it is going
- 26:49to start the Artisan server as well on
- 26:51Port 8,000 let's click on this and we're
- 26:54going to see Lal application up and
- 26:56running on Port 8,000 as well as well so
- 26:59if you're running this using this
- 27:01composer randev or PHP Artisan serve you
- 27:04might need to change the application URL
- 27:08in file so we should probably change
- 27:11this into local hostport 8000 like this
- 27:14but I'm going to actually use this on
- 27:17Lal herd installation on the following
- 27:20domain so I'm going to close this and
- 27:22because I'm going to use that I'm going
- 27:24to leave this URL in the file just like
- 27:27this
- 27:29and I also don't need to execute
- 27:31composer run Dev which runs all these
- 27:33commments it actually runs um Q command
- 27:37uh V server it is going to run also pale
- 27:40command but in my installation it
- 27:42requires the following extension which
- 27:44is not a big deal I don't um actually
- 27:47need to use this pale in in this case um
- 27:51but yeah so I'm going to just stop this
- 27:55and I'm going to execute mpm run Dev so
- 27:58I primarily need two servers Artisan
- 28:01server U PHP server and the V server
- 28:05okay so PHP server is right here using
- 28:09herd and engine X and I just need mpm
- 28:11run and just like this I have my
- 28:13application up and running and I'm going
- 28:15to leave this mpm run Dev always running
- 28:18I'm going to open second terminal from
- 28:20which I'm going to execute PHP artisan
- 28:23and as you see the PHP storms new
- 28:25terminal actually autocompletes a few
- 28:28things for us we can see the folders and
- 28:31commments and many other things PHP
- 28:34Artisan um
- 28:37Storage storage colum link we hit the
- 28:41enter the storage link was created now
- 28:45let's explore typescript related project
- 28:48folder and file structure I think this
- 28:50is really interesting so we're going to
- 28:52go into resources JS and this is the
- 28:55place where all the react applications
- 28:58react files are located and here we have
- 29:01this main app. T6 which is the main
- 29:04application it creates the inertia
- 29:06application and inside setup it has two
- 29:09versions if the server side rendering is
- 29:11enabled it uses this hydrate route
- 29:14otherwise it uses this create route and
- 29:16finally everything is rendered inside
- 29:18this app uh component okay let's open
- 29:22this um this bootstrap TS is very simple
- 29:25nothing complicated let's open this
- 29:27server side range rendering right here
- 29:29and here we see this function create
- 29:32server which has the following render
- 29:34common so everything is rendered so that
- 29:36file is basically responsible to render
- 29:40the application with serers side
- 29:41rendering when we actually have the
- 29:44server side rendering server up and
- 29:46running and here we have this resolve
- 29:49page component as well to and this is
- 29:52the location where all the pages is
- 29:54going to reside so that's the main file
- 29:57for server side rendering basically okay
- 30:00and it use this uh Ziggy roads right
- 30:03here for resolving roads as well okay
- 30:06now let's go into types that's really
- 30:09interesting so inside This Global we
- 30:11have this window and root which is
- 30:14actually Ziggy Ro imported from this
- 30:17Ziggy JS Ziggy basically is a package
- 30:20which registers all the Lal Roots into
- 30:24react um into JavaScript so that we can
- 30:27use these Roots by root name into react
- 30:30application and we also have the
- 30:32following U Declaration of module for
- 30:35inera JS core we we overwrite this page
- 30:38props which actually extends two things
- 30:41it extends inura page props now which is
- 30:45coming from inertia core page props and
- 30:47it also extends the application page
- 30:49props um right here so and the
- 30:52application page props uh leaves in its
- 30:55own file index. d. TS this is it and
- 31:01right here we have two main types the
- 31:03user interface uh which has the
- 31:05following fields and the page props
- 31:07which um is kind of uh has
- 31:10this abstract type of definition so that
- 31:14we can extend these page props and
- 31:16additional types right there and the
- 31:19page props uh actually has is has
- 31:22additional things added to it as well
- 31:25which is out and zigy and if we open
- 31:28other Pages like uh welcome for example
- 31:32we can see that right here we are
- 31:33accepting the following props and using
- 31:37typescript we Define that the following
- 31:39object basically will have the type of
- 31:42page Props Plus edit Lal version field
- 31:46which is string and PHP version which is
- 31:49string so we are actually taking out
- 31:51three properties from this object from
- 31:53the props out Lal version and PHP
- 31:56version out is defined inside this page
- 31:59props we can see it right here but this
- 32:02lateral version and PHP version is
- 32:04declared right here so if we remove The
- 32:06Following part basically then um the PHP
- 32:12storm will start complaining about it
- 32:15and we will not be able to execute mpm
- 32:18run build to build our project because
- 32:21typescript simply doesn't know where
- 32:23this lateral version and PHP version is
- 32:26coming from so we can test this we can
- 32:28open Terminal we can open new terminal
- 32:31or we can simply close this terminal
- 32:33inside which we have mpm run Dev running
- 32:36and we can execute mpm run build and
- 32:40we're going to see the error and every
- 32:42time when you execute mpm run build if
- 32:45you have that error you should know that
- 32:47this is the reason okay so this not
- 32:51specifically related to this welcome T6
- 32:53but something is not okay with the
- 32:55typescript and this is exactly right
- 32:57here so I'm going to undo
- 32:59this the following thing and we can
- 33:02execute mpm run build again and
- 33:04everything should be
- 33:07good yeah if it started building it
- 33:09means everything is good now it's
- 33:11building for SSR and finally it was done
- 33:13mpm run
- 33:15Dev okay so we can check other files
- 33:19like um inside dashboard this is pretty
- 33:21simple it doesn't even accept props we
- 33:23can check the profile area profile edit
- 33:26we are accepting this must verify email
- 33:29here and Status so these are again added
- 33:33into the default page props and so on so
- 33:35we're going to of course create new
- 33:37types uh new prop declarations similar
- 33:40to the following one and everything will
- 33:43get more clear just um I generally
- 33:46recommend when you start new project and
- 33:48use some starter kit whether that's the
- 33:51first party starter kit like larel
- 33:53breeze or some third party I recommend
- 33:56to browse into the project and
- 33:59understand its structure how it is
- 34:01structured how certain things are used
- 34:03because that's the standard for that
- 34:06project and sometimes young developers
- 34:08simply delete everything uh what they
- 34:11don't need and start from scratch after
- 34:14the starter kit so that's not actually
- 34:16like really good idea so I I can
- 34:18obviously delete pages and create new
- 34:21pages and whatever I need but you should
- 34:23simply consider how this the developers
- 34:27of this first party or third party
- 34:29starter kit created things so that you
- 34:31can replicate uh in the same way so one
- 34:36thing I want to change is that we see
- 34:38that the indentation is set into four
- 34:40spaces 1 2 3 4 and this is what I want
- 34:43to change and for this I'm going to open
- 34:45editor config find this indent size two
- 34:49for yml files and I'm going to add Ts
- 34:52for TS and TSX files we want to set the
- 34:56indentation to be two as well
- 34:58additionally we can add JS and jsx as
- 35:01well even though we don't have those JS
- 35:03and jsx files and after this if we open
- 35:07edit or dashboard or any other file
- 35:10where the indentation is set into four
- 35:12spaces and we try to reformat the code
- 35:15using um the shortcut on my keyboard or
- 35:18using right click and
- 35:22refactor where is the
- 35:25reformat I almost always use the
- 35:30um yeah anyway so I'm going to still
- 35:32stick with my shortcut control alt and L
- 35:35this going to reformat the code into two
- 35:37spaces okay and this is generally how I
- 35:39prefer I don't want the text go uh go to
- 35:42the right too much and that's it so one
- 35:46thing I want to change is that inside
- 35:48components we have a bunch of components
- 35:50and I'm going to Define two main folders
- 35:52inside components one is going to be for
- 35:56core components and and second is going
- 35:58to be for up related components
- 36:01generally I differentiate these two
- 36:04folders in the following way everything
- 36:06that is specific to this project like
- 36:09the application logo for example uh
- 36:12before I move this I will explain
- 36:14everything that is specific to this
- 36:16project like the application logo for
- 36:17example I'm going to move this into app
- 36:20component anything that can be used into
- 36:24another project as well uh it's it is a
- 36:27core component and from Project to
- 36:30project if I create this core folder
- 36:33which contains all the reusable core
- 36:35components I can easily copy and paste
- 36:37from this project into another project
- 36:39this core folder and um just like this I
- 36:43will have every reusable components into
- 36:45a single folder so like checkbox for
- 36:48example danger button drop-down all
- 36:50these are core components and I'm going
- 36:52to move them
- 36:55however there's one thing I want to to
- 36:57show and why I Love Actually PHP storm
- 37:01so if we open for example
- 37:03login. TSX file so here we have those
- 37:08components let's see in the import area
- 37:10we see this checkbox input error input
- 37:12label primary button everything is
- 37:14coming from the components folder now if
- 37:17we take those components like now let's
- 37:20take only one primary button in this
- 37:22case and primary button is a core
- 37:24component which can be used into another
- 37:25project as well so I'm going to move
- 37:27this into core click on refractor and as
- 37:31you see the import of this primary
- 37:34button was also updated and we can try
- 37:36to find out all the other places where
- 37:39that was changed we can find like import
- 37:42primary button into the entire project
- 37:45and we see that it is used inside eight
- 37:47places and all of them we are updated
- 37:50because we moved this primary button
- 37:53using PHP Storm from one folder into
- 37:55another this this is awesome this is why
- 37:58I love using PHP storm and generally jet
- 38:00Brand Products so I'm going to move now
- 38:02this text input secondary button uh
- 38:06maybe the responsive nav link and nav
- 38:08link and modal almost all of
- 38:11them into the
- 38:15core refactor and now we're going to see
- 38:18that all of them we are updated okay now
- 38:20all of them is coming from core and
- 38:22let's move this application logo into up
- 38:25we're going to create more components
- 38:26inside the app folder now the coolest
- 38:29part is that we did all these moving
- 38:31from one folder into another but our
- 38:33application is not broken because
- 38:36everything was refactored we're going to
- 38:37see the login page we're going to see
- 38:40register page everything is there
- 38:42everything is up and
- 38:46running now I'm going to initialize git
- 38:49repository and I'm going to comment
- 38:50everything what I have created so far
- 38:53and this is pretty much initial comment
- 38:55so let's execute actually when working
- 38:58with Git I prefer to use gitbash so I'm
- 39:01going to open gitbash Terminal and I'm
- 39:03going to execute git in it so it
- 39:06initialized the repository right now and
- 39:09additional project icon was added under
- 39:12the project additional Navigation icon
- 39:15was added this is for Comet if we click
- 39:17on this we're going to see that there
- 39:20are2 files at the moment all of them are
- 39:23unv verion files uh we don't need to
- 39:26browse them because this is the initial
- 39:28Comet but we can group them by directory
- 39:31which is awesome and we can browse them
- 39:34uh by directory so in this case I
- 39:37actually don't need to browse anything
- 39:39so this is the initial comment I can
- 39:41just take all of them and just give it
- 39:43message initial
- 39:47comment we're going
- 39:51to do we need to yeah it has something
- 39:55like to analyze all the files and if we
- 39:58have this analyzing all the files active
- 40:00it going to take some time to analyze
- 40:02all the typescript files for us what we
- 40:05are about to comit and if we have some
- 40:08warnings it's going to give us those
- 40:09warnings maybe it's right here no this
- 40:12is not it okay let's hit on Comet and
- 40:15have a
- 40:15look okay the comet was completed it
- 40:18didn't analyze which is exactly what I
- 40:20wanted in this specific case because uh
- 40:23this is the initial project I don't need
- 40:25the analyze from git when I'm initially
- 40:28commenting the whole the whole 100 files
- 40:33okay so far so
- 40:35good now we're going to install da UI
- 40:38which is one of the most popular
- 40:40component library for tyan CSS we can
- 40:42check the entire documentation right
- 40:44here what components it supports and
- 40:47everything and I'm going to use this
- 40:49documentation quite often to copy
- 40:51certain things like the button designs
- 40:54for example we're going to copy these
- 40:55CSS classes into um into our project but
- 40:59first we're going to obviously install
- 41:01the project and for this let's open PHP
- 41:04stor I'm going to open Terminal this is
- 41:06g p terminal I can execute mpm install
- 41:08commands here as well or I can create
- 41:11separate terminal for this actually I'd
- 41:13love to organize these terminals so this
- 41:16is vit I'm going to call this this is
- 41:18vit server and we can call this um
- 41:22Artisan for example some artisan
- 41:24commments and we have gitbash so in this
- 41:26case I'm going to open partisan command
- 41:28and I'm going to execute um npm install
- 41:31and we see the terminal out completes
- 41:34for us mpm install
- 41:37Daisy Daisy UI and it fetched this from
- 41:40the npmjs as well so daui we're going to
- 41:44hit the enter it is going to install
- 41:46Daisy UI which was already done next
- 41:49we're going to open um tan config JS and
- 41:54right here we're going to use this Daisy
- 41:56UI so the pro project is already using
- 41:59forms which is something I want to
- 42:01remove so I'm going to remove this from
- 42:03here and I'm going to remove this from
- 42:05Imports and I'm going to also delete
- 42:08this package so let's bring up the
- 42:10terminal mpm uninstall and paste this
- 42:14tile on CSS SL forms we're going to hit
- 42:16the enter it is going to be uninstalled
- 42:19now let's
- 42:22require Daisy UI okay so far so good so
- 42:26we save this and now our application is
- 42:29actually using da UI we can click onite
- 42:32and we see that two them themes added
- 42:34into the project now let's check our
- 42:37project in the browser we're going to
- 42:39click on login and we see some Styles
- 42:42related to forms are actually broken so
- 42:45this is still tyon CSS some of the
- 42:47common things are there but the forms
- 42:50got broken and this is something we are
- 42:52going to fix now let's search for input
- 42:55error uh not there text input and we're
- 43:00going to find the following input with
- 43:02border let's go into HTML or jsx doesn't
- 43:05matter in this case and there are two
- 43:07main classes input and input bordered
- 43:10this is what we are going to add into
- 43:12the inputs so this is the login form now
- 43:16let's open login. T6 and we don't need
- 43:20this T in config JS so I'm going to
- 43:21close this and let's find now input here
- 43:25we have this input label and text input
- 43:28let's click on this text input now which
- 43:30is a core component so this now leaves
- 43:33inside this core component okay core
- 43:35folder and let's scroll down below and
- 43:37we have a bunch of talin Cs classes
- 43:39which I'm going to remove and only leave
- 43:41input and input bordered now I'm going
- 43:44to save this and if we check in the
- 43:46browser we see that the inputs are now
- 43:48fixed this is awesome uh additionally we
- 43:51can put those the class names into a
- 43:53single line because we don't have that
- 43:56many classes and I'm going to also every
- 43:58time I open this new file I'm going to
- 44:01format the code so that everything is
- 44:03indented into two spaces
- 44:05nicely okay next is to
- 44:08open this um label where's the label
- 44:12input label okay and we can check also
- 44:15ji docks how the label is added right
- 44:18here we can see that everything is
- 44:21inside form control class which is
- 44:22something we can do or cannot do we can
- 44:25avoid that but the main thing is that
- 44:27we're going to use this label class okay
- 44:29and inside label class we're going to
- 44:31have this span with label text okay this
- 44:34is what I'm going to do now so this is
- 44:36label we're going to give it a label
- 44:39class and again we can put this on a
- 44:42single line like this format on two
- 44:46spaces and then we're going to use span
- 44:51here and we're going to add to the span
- 44:54class name label Tex
- 44:57text okay now it is using the labels in
- 45:02the same style that is inside right here
- 45:06inside the daisy UI and the next thing
- 45:08is to change the checkbox so we can find
- 45:11the
- 45:13checkbox and I'm going to go with a
- 45:15primary color checkbox and the main
- 45:18thing is that we're going to add those
- 45:19two classes checkbox checkbox primary to
- 45:22the input so again inside the core
- 45:25component we're going to open checkbox
- 45:28and instead of those classes we are
- 45:30going to Simply a checkbox checkbox
- 45:32primary put everything classes on a
- 45:35single line format the code additionally
- 45:38we can move these props into its own
- 45:40line so that it is not too right so we
- 45:45format the code and now this is this
- 45:47looks like this we can do something
- 45:48similar for
- 45:51labels and for inputs no this is nicely
- 45:55formatted already and let's check now
- 45:59checkbox this is it this is awesome and
- 46:02we have this primary button as well so
- 46:04let's
- 46:05open let's open secondary Button as well
- 46:08and primary button we're going to adjust
- 46:10both of
- 46:11them so this is the primary button we're
- 46:14going to remove all these classes and
- 46:16we're going to give it BTN BTN primary
- 46:20and additionally if the button is
- 46:22disabled we add the opacity 25 which
- 46:25comes with a breeze I'm going to remove
- 46:27this because if it's disabled Daisy UI
- 46:29will apply correct styles to this so I'm
- 46:33going to format this class the
- 46:36component nicely let's open secondary
- 46:38input as well uh and I'm going to remove
- 46:43all these classes but instead of a
- 46:46secondary BTN BTN secondary I'm going to
- 46:49give it a
- 46:51different
- 46:52um just BTN class okay and I will
- 46:56explain why a little bit later because
- 46:58BTN secondary um is not the color I
- 47:01actually want for my secondary button so
- 47:04we can remove this disabled classes
- 47:06again we can put this on a single line
- 47:09format the code uh move this down again
- 47:12format the code and now this is awesome
- 47:15okay so this is the primary button these
- 47:17are inputs so far so good let's click on
- 47:22register
- 47:23and this form also looks
- 47:29nice let's check the login page again
- 47:32and find this link which
- 47:37is right here forgot your password and
- 47:41we can find also links from the
- 47:45documentation okay here we go so this is
- 47:47a simple link and we just need to add a
- 47:50link class instead of all these things
- 47:52so
- 47:54let's change everything and just add
- 47:58link class to it and we're going to do
- 48:00something similar into register so let's
- 48:04search for link and remove all these
- 48:07classes and add link class to it now
- 48:12this link which is Daisy UI link if we
- 48:16go into actually if we click on this
- 48:18already registered now this is also link
- 48:21which is Dai link not the um not the one
- 48:25which comes with um Breeze installation
- 48:28additionally I want to also open
- 48:32authenticated layout and uh this is why
- 48:36I want to change this and first let's
- 48:39search this authenticated layout where
- 48:42it is used I think it is used in the
- 48:44dashboard so let's open pages dashboard
- 48:47TSX we see that the authenticated layout
- 48:50is used actually right here but the
- 48:52thing is that so it is imported from
- 48:55this authenticated layout
- 48:57uh and the import is also called
- 48:59authenticated layout but inside we have
- 49:02this named as authenticated and whenever
- 49:04we try to use
- 49:07authenticated um or authenticated layout
- 49:10if we don't have that import so if we
- 49:12created new file and I want to import
- 49:16authenticated layout it is not able to
- 49:18see authenticated layout it is it says
- 49:21authenticated because this is the name
- 49:23of the function inside this file and
- 49:26this is why I want to change it okay
- 49:29let's return this back and open this
- 49:32file and I'm going to change this into
- 49:34authenticated layout and now whenever I
- 49:36need to use this it's uh the
- 49:38autocomplete will give me this find with
- 49:41the following
- 49:43name now let's sign up on the
- 49:46website let's click on uh actually I
- 49:49think we have to change this no
- 49:51everything's good here okay so we're
- 49:54going to go into register page and I'm
- 49:57going to try to create new account
- 50:00actually when we navigate between Pages
- 50:02as you probably noticed so it is a
- 50:04little bit slow and this is because we
- 50:07are using serers side rendering approach
- 50:10but we don't have the SSR server started
- 50:15running okay and sometimes that works
- 50:18slightly slow but when we actually build
- 50:21this and when we set up the project and
- 50:24when we have the server side rendering
- 50:26server also up and running it is not
- 50:28going to be um that
- 50:30slow it is going to be actually super
- 50:33fast so I'm going to now try to create
- 50:35new account we hit the enter the account
- 50:37was created now let's go into profile
- 50:41and we are using primary buttons right
- 50:43here however this delete account is
- 50:45actually a danger button which is not
- 50:48something what we change so we're going
- 50:50to open this danger button and I'm going
- 50:52to remove these
- 50:54classes and we're going to give it PTM
- 50:56BTN error uh we're going to remove this
- 51:00disabled oppacity class and let's put
- 51:04this on a line format
- 51:07this like this and this is cool now this
- 51:10is the default danger button in daui
- 51:14whenever we click on this now this opens
- 51:16the danger button here and the secondary
- 51:19button right here and this is why I gave
- 51:23the BTN
- 51:25class just BN class into the secondary
- 51:28button so if I give it BTN secondary now
- 51:32these colors are not nice to each other
- 51:35in my opinion so I just leave it as
- 51:39BTN okay I think we just moved into da
- 51:45UI quite successfully now we can move on
- 51:48to the next part which is actually to
- 51:50define the navbar layout of our project
- 51:54so we can search inside Daisy Y navbar
- 51:58and we can find bunch of Navar examples
- 52:01and they look pretty awesome so the
- 52:02basic one and more complex one with some
- 52:05links and dropdowns and we can see the
- 52:08search as well the Avatar with it own
- 52:11drop down this is cool and we even have
- 52:13an example with a cart so this is
- 52:15exactly what I want to use so I'm going
- 52:17to just go into GSX and copy these but
- 52:21before I copy that part I'm going to
- 52:24comment the changes I made previously
- 52:26and generally when building in real
- 52:28project I always recommend to review the
- 52:31changes you made because it is very very
- 52:34common especially for beginner
- 52:36developers so that you make an
- 52:39intentional change into the project or
- 52:41maybe intentional uh but this this this
- 52:45is something you didn't actually want to
- 52:47make uh when when you finally make the
- 52:51review you understand okay yeah I should
- 52:53probably not make this okay so in our
- 52:56case we sh like we should probably make
- 52:59a review but I'm not going to do this
- 53:01right now obviously I'm not going to
- 53:02take your time making these reviews but
- 53:04generally just click double click on
- 53:06this and see every change what you made
- 53:08when you are building a real project
- 53:10especially if you're are fixing
- 53:12something on production you just pull
- 53:13the code the production code make some
- 53:15change there and your comment push for
- 53:18the server just make the review because
- 53:20that saved my life personally many many
- 53:23times in the past when working on the
- 53:25project some times like mistakenly uh
- 53:28the developer modified the G ignore code
- 53:31or I modified the G ignore code I hit an
- 53:33incorrect character on my keyboard and I
- 53:36didn't notice that I modified the G
- 53:38ignore and the entire node modules
- 53:40folder or the vendor folder was about to
- 53:42be commented so just make the review and
- 53:45you you have also these arrows right
- 53:47here to navigate into all reviews even
- 53:51across many files and yeah if something
- 53:56uh doesn't feel right you can always
- 53:58undo the change by clicking right here
- 54:00here now in our case everything is good
- 54:03we want that changes and that's perfect
- 54:05one additional thing I really love in uh
- 54:08using page patform is that so we can
- 54:11actually include partial comment so I
- 54:13want to for example comment everything
- 54:17except inside the checkbox that specific
- 54:21change and this change and I want to
- 54:22include that specific changes into
- 54:24another file into sorry to another
- 54:26comment message this is what I also have
- 54:29done um many times so your comment
- 54:32messages should be Atomic one comment
- 54:35message should be basically for one
- 54:38thing what you did and sometimes we are
- 54:40developers we're working we don't
- 54:42remember always to open the comet and um
- 54:45create the comment message so that's why
- 54:47I very often have many changes in the
- 54:49project but I just open this and just
- 54:53include the files and changes only what
- 54:56I want in the first comet then what I
- 54:58want in the second Comet and so on and
- 55:02here we removed uh the talent SES forms
- 55:05and installed
- 55:07Dy inside these dependencies and which
- 55:11is
- 55:12actually uh I think the day UI should be
- 55:15inside um Dev dependencies yeah but
- 55:20anyway we can leave this so we are going
- 55:22to give this comment message install and
- 55:25activate at uh Daisy
- 55:29UI control and enter everything was
- 55:32committed and now we can focus on the
- 55:34Navar so let's now open authenticated
- 55:39layout right
- 55:41here and we have this nav which is
- 55:45actually nav bar right here just above
- 55:48the header and the header is the
- 55:50following area this is the header and
- 55:52this is the nav bar obviously so we're
- 55:54going to take out this nav and let's
- 55:56create Now new component which is
- 55:58specific to our project so I'm going to
- 56:01put this inside app folder new
- 56:04typescript file js6 file navbar we're
- 56:08going to hit the enter click on add to
- 56:11add this file into git
- 56:14project and here I'm going to use no
- 56:16shortcut to generate the skeleton of my
- 56:18component R SF we're going to hit the
- 56:22tab and the component was created and
- 56:25now let's put the this nav right
- 56:28here actually uh this is what I'm going
- 56:32to
- 56:33do so actually I'm going to put this nav
- 56:37into a new scratch file so Control Alt
- 56:41shift and insert to create new scratch
- 56:44file I'm going to choose HTML scratch
- 56:47file and paste everything here and if we
- 56:51expand this we're going to see this
- 56:52entire nav bar would we copied so far
- 56:54but what I want is is to take this new
- 56:58navbar component so I'm going to copy
- 57:00this paste everything here uh I can
- 57:04remove all these Imports I don't need
- 57:06them at the
- 57:07moment these are props and at the moment
- 57:10I don't want to also accept any props
- 57:12and if we have a look in the browser uh
- 57:14we are not going to see anything because
- 57:16we don't use this newly created navbar
- 57:19so if we go in the authenticated
- 57:23layout uh yeah the the nav bar was
- 57:25actually lost but let's use now
- 57:31navbar save that and now we see this
- 57:34Daisy UI Navar including the drop downs
- 57:37and everything okay now if we go in the
- 57:40nav bar I'm going to change this Daisy
- 57:41UI into Lara store we're going to change
- 57:46this into iner link and specify hre to
- 57:50be just slash and we're going to import
- 57:52that in your link that is awesome now
- 57:56let's scroll down below and find the
- 58:00profile section here we see the profile
- 58:02we're going to change this into inertial
- 58:04link again inside h r we're going to
- 58:07provide a
- 58:08root and this is going to be profile.
- 58:12edit and the autoc completion right here
- 58:14happens using Lal idea plugin okay
- 58:18without the Lal Ida plugin you are not
- 58:21going to get that type of Auto
- 58:23completion for roads in your um
- 58:26T6 files so we're going to use this
- 58:29route edit we're going to remove this
- 58:31new we don't need settings and we're
- 58:33going to change this
- 58:35into uh into the following way and this
- 58:37is going to be link again inside HRI
- 58:40we're going to provide root uh log
- 58:44out and we're going to provide method to
- 58:48be method to be post and we're going to
- 58:53also H give as button so the following
- 58:58link should be
- 59:01button okay so again we form the code
- 59:04save everything now we see the profile
- 59:06page clicking on which activates the
- 59:09profile that's awesome and if I click on
- 59:11log out that actually performs the log
- 59:13out now let's use my credentials to log
- 59:17in back I'm going to leave this drop
- 59:19down at the moment because this is dummy
- 59:21and when we Implement cart we're going
- 59:22to modify this as well but if we check
- 59:25this Nar component examples we have a
- 59:28bunch of other examples we have
- 59:29additional icons we can put we have this
- 59:31drop- down menu items we can put right
- 59:35here and we have the different
- 59:37variations as well so just feel free to
- 59:40configure the nabar as you want you may
- 59:42be want to put this search field inside
- 59:45the now bar so just have a look
- 59:47understand how you can grab the search
- 59:49and put this inside the project so in my
- 59:52case what I want to do is change the uh
- 59:57welcome page as well so I don't want
- 59:58this welcome page I want a nice Navar
- 1:00:01the same type of Navar and maybe a hero
- 1:00:04section as well so now let's do
- 1:00:07additional
- 1:00:09work if we open roads file web.php we're
- 1:00:13going to see that we are rendering this
- 1:00:14welcome page on this slash
- 1:00:18okay so this is something I want to
- 1:00:23change first let me open this welcome
- 1:00:26and scroll down below it has a lot of
- 1:00:28HTML because it has SVG content right
- 1:00:31there and this is something let's clear
- 1:00:35it up
- 1:00:37completely okay remove this save we can
- 1:00:40remove this image as
- 1:00:42well save that and this is now our
- 1:00:45welcome page and I want the welcome page
- 1:00:47to use authenticated layout as well so
- 1:00:50and just like this uh it autocompletes
- 1:00:53this authenticated layout correctly so
- 1:00:56without the change I made right here it
- 1:01:00would not autocomplete this
- 1:01:02authenticated layout it would outut
- 1:01:04complete this as
- 1:01:06authenticated okay nice so we have this
- 1:01:08authenticated layout we can check this
- 1:01:10in the browser already we see this is so
- 1:01:13far so good and this is the homepage
- 1:01:16which we will Implement in the future to
- 1:01:20just display the products and everything
- 1:01:22but for now let's put a dummy hero
- 1:01:25section
- 1:01:27there this is the hero section I'm going
- 1:01:29to copy this I'm going
- 1:01:34to we have this PG gray we probably
- 1:01:37don't need this PG gray or maybe we need
- 1:01:40a div a wrapper for everything but we
- 1:01:44probably don't need
- 1:01:45this or maybe even we don't need this de
- 1:01:48so I'm going to just delete if I need I
- 1:01:50will add this back so here is my um hero
- 1:01:53section which has minimum height of
- 1:01:56screen which is something I want to
- 1:01:57change and let's give it eight of like
- 1:02:00300
- 1:02:02pixel uh and let's give it also BG gray
- 1:02:07200 we save this and have a look okay
- 1:02:11this looks not bad so this is our
- 1:02:14homepage and whenever I am not
- 1:02:18authenticated if we go on
- 1:02:22homepage now I still see this user drop
- 1:02:24down which is something I want to to
- 1:02:26change obviously right now I am not
- 1:02:27authenticated so I cannot actually
- 1:02:29access the profile page right so let's
- 1:02:32go into navbar
- 1:02:35and so we need the user information
- 1:02:37right here so for this we're going to
- 1:02:39access props
- 1:02:41const uh actually props equals use page
- 1:02:46use
- 1:02:48page. props so now I want to destructure
- 1:02:52those props and take out out from it
- 1:02:55because the props if we just uh hit on
- 1:02:59control or Mouse over we're going to see
- 1:03:01that uh it is actually instance of page
- 1:03:04props and if we click control and click
- 1:03:07on this we can actually open that this
- 1:03:11this is coming from this types do um DTS
- 1:03:15from the core but it is using this page
- 1:03:18props but we redefine the page props and
- 1:03:21now uh typescript knows that our page
- 1:03:25props has out inside there okay if we
- 1:03:29check again inside types Global this is
- 1:03:32the page props which we redefined and
- 1:03:34now the page props which is inertia JS
- 1:03:37core page props it extends the inertia
- 1:03:40page props as well as our page props and
- 1:03:43our page props has this out inside there
- 1:03:46so right here we can access this out and
- 1:03:49we can take the user information from
- 1:03:51this we can even destructure this out
- 1:03:53and get the user in the following way
- 1:03:57out now we're going to use that user
- 1:04:00variable down below when we have this
- 1:04:03drop down for the user so this is the
- 1:04:05drop- down for the user so let's take
- 1:04:08this out if the user exists then we
- 1:04:11render the drop down if the user does
- 1:04:14not
- 1:04:15exist then we are going to render two
- 1:04:18buttons one for login second for sign up
- 1:04:21so let's use fragment
- 1:04:23here and inside the fragment we're going
- 1:04:25to we're going to put two uh
- 1:04:28links so this is going to be for login
- 1:04:33rout oops uh not log out but
- 1:04:39login and let's give it also classes
- 1:04:42this is going to be BTN class and
- 1:04:46duplicate this and the second class uh
- 1:04:49second button we have BTN
- 1:04:52primary BTN primary and we can give it
- 1:04:54also text
- 1:04:56um register or sign
- 1:05:00up
- 1:05:01register so now we format this we can
- 1:05:04move this text down and have a look so
- 1:05:09we see this login register however we
- 1:05:11need some
- 1:05:14space between these links we can do the
- 1:05:17following so we can create div and give
- 1:05:19it a display flex and GAP so that we
- 1:05:23create space between login and register
- 1:05:25or I think we need space between all
- 1:05:27these three uh elements so this has a
- 1:05:31flex none and let's give it g four we
- 1:05:35save that and now we have this space
- 1:05:37between the sections login
- 1:05:41register this is dummy we can leave this
- 1:05:44at the moment so I think this looks good
- 1:05:46one last thing I want to do is to
- 1:05:49include the Navar as well for the login
- 1:05:52and register pages so let's open open
- 1:05:56login TSX it uses guest layout at the
- 1:05:59top instead of authenticated layout and
- 1:06:02this is what we are going to change
- 1:06:04authenticated
- 1:06:05layout and we can see now login page
- 1:06:08gets really ugly no problem we're going
- 1:06:10to fix that let's open
- 1:06:14register and change this into
- 1:06:16authenticated layout
- 1:06:19again this looks ugly as well now let's
- 1:06:22open login
- 1:06:23TX uh actually let's
- 1:06:27check uh guest
- 1:06:30layout and here we are using the Lo um
- 1:06:35logo which is actually lost and we we
- 1:06:38are okay with that we don't want this
- 1:06:39logo but we have this um card type CSS
- 1:06:44classes into the GU layout now we're
- 1:06:46going to put this inside login so I'm
- 1:06:48going to wrap
- 1:06:50everything into card let's give it B G
- 1:06:56white and give it also Shadow
- 1:07:01probably and then we have card body not
- 1:07:05card body but card
- 1:07:07body and paste
- 1:07:10everything and we're going to give some
- 1:07:13classes like Max width
- 1:07:16of um 4 20 pixel something like this and
- 1:07:21margin X Auto as well so we're going to
- 1:07:25SA save this and now we see the button
- 1:07:27in the center additionally we can wrap
- 1:07:30it into another div and give this
- 1:07:34div
- 1:07:35pading uh pading four let's give it
- 1:07:38pading
- 1:07:39four now this is the login page or maybe
- 1:07:42four is small we give it piling eight
- 1:07:45now this is awesome register is still
- 1:07:47ugly we're going to open register
- 1:07:50T6 and we're going to wrap it let me
- 1:07:53actually copy
- 1:07:56uh the following three Dives past here
- 1:08:00and now we're going to create ending of
- 1:08:02each div closing text now we format the
- 1:08:07code
- 1:08:09and that's nice and just like this we
- 1:08:11have now login and register Pages which
- 1:08:16um has this header as
- 1:08:20well
- 1:08:22awesome now again we can open the
- 1:08:25kitbash and I'm going to give it corre
- 1:08:27correct message create and use new
- 1:08:32navbar using
- 1:08:34Daisy UI I might not include all the
- 1:08:39comment messages in the video so if you
- 1:08:41find something um while watching this in
- 1:08:44the next sections that I didn't mention
- 1:08:47the comment in the video just to know
- 1:08:49about this so right now we see all the
- 1:08:51new files are the new files are green
- 1:08:54modified files are blue we can see the
- 1:08:56changes right here as well as soon as I
- 1:08:58comment this those changes are actually
- 1:09:01gone and you might notice that I have
- 1:09:03the changes and then the next section
- 1:09:05starts without changes and that's
- 1:09:07because I simply did not include the
- 1:09:09comment message in the video itself now
- 1:09:13I want to start working on roles and
- 1:09:15permissions and for this I'm going to
- 1:09:17use Spa Lal permission package and we're
- 1:09:21going to also browse the documentation
- 1:09:23in certain things to understand um to
- 1:09:26give you information where you can find
- 1:09:28these or that things the permission
- 1:09:30package actually supports roles and
- 1:09:32permissions and users are supposed to be
- 1:09:35assigned roles but also you can assign
- 1:09:37permissions to users and the roles
- 1:09:40should have permissions okay now let's
- 1:09:43install this package and I'm going to
- 1:09:44also uh step by step U give you the
- 1:09:46information so first we have to execute
- 1:09:49the following composer comment let's
- 1:09:50bring up the terminal inside Artisan
- 1:09:52terminal and I'm going to execute
- 1:09:54composer requires but LEL permission uh
- 1:09:57this is something we don't need um this
- 1:09:59is also
- 1:10:00optional no this is not optional we
- 1:10:03should publish the migration uh as well
- 1:10:05as the config file so I'm going to copy
- 1:10:08this and I'm going to paste this here
- 1:10:10we're going to hit the enter and we see
- 1:10:14that the permission file was
- 1:10:20copied actually this was done and then
- 1:10:24this was done
- 1:10:25so two files we say done two times so
- 1:10:28two files we are copied one for config
- 1:10:30second for migration and we will
- 1:10:33obviously need to execute migrate but
- 1:10:35let's have a look before running
- 1:10:37migrations this is not something for us
- 1:10:42so we're going to skip that
- 1:10:45section yeah we probably need to clear
- 1:10:47the config cache let's execute
- 1:10:51this and we execute PHP Artisan config
- 1:10:54clear as
- 1:10:56well in next we can execute PHP Artis
- 1:10:59and my crate it created roles and
- 1:11:02permissions and now it's time to check
- 1:11:05the database and for this I'm going to
- 1:11:07use phb storms built-in database tool
- 1:11:10here we have this databas site file we
- 1:11:12are using sqlite we're going to double
- 1:11:14click on
- 1:11:16this and this brings up the data sources
- 1:11:19in driver's window and I'm going to
- 1:11:21click on okay and on the right side now
- 1:11:24we have
- 1:11:25the database we can have multiple
- 1:11:28databases in a project that's possible
- 1:11:30uh in PHP sh and this supports actually
- 1:11:33a lot of many common databases um a lot
- 1:11:36of so we can expand this and we're going
- 1:11:39to see the tables here and so the tables
- 1:11:44that was created because of these Lal
- 1:11:47spotty uh permissions package is model
- 1:11:50has permissions model has roles roles
- 1:11:55permissions and Ro has permissions and
- 1:11:58we can also check this inside migrations
- 1:12:01open the permissions and we
- 1:12:03see we see create table for permissions
- 1:12:07create table for roles create table for
- 1:12:10model has
- 1:12:11permissions um model has
- 1:12:13roles and R has permissions and that's
- 1:12:17it so the tables we are created and now
- 1:12:22we're going to Define roles and
- 1:12:24permissions in the database or only
- 1:12:26rules depending on our use case so one
- 1:12:28thing what we need to do for sure is
- 1:12:30that we're going to update the user and
- 1:12:32include the following trait inside the
- 1:12:35user mode so let's open user.php
- 1:12:40and has roles trait we need to include
- 1:12:46that next I think there is not much we
- 1:12:49need to actually do uh and now I'm going
- 1:12:53to create anms for roles and
- 1:12:57permissions U I'm going to execute
- 1:12:59Artisan command to create new class but
- 1:13:01actually I'm going to show also this
- 1:13:03double control so in PHP storm I use
- 1:13:06this quite often I just started using it
- 1:13:09recently so double control click on
- 1:13:11control two times it's going to open
- 1:13:13this run anything and right here we can
- 1:13:16execute Artis and commments as well like
- 1:13:18PHP artisan make class and we're going
- 1:13:23to call this um
- 1:13:25rolls rolls enam for example and we're
- 1:13:29going to hit the enter the class was
- 1:13:32created again double control PHP artisan
- 1:13:36make class and the second we're going to
- 1:13:38create is
- 1:13:40permissions enam we're going to hit the
- 1:13:43enter that was also created now I'm
- 1:13:45going to hit double shift let's open
- 1:13:47rolls enam double shift again
- 1:13:51and
- 1:13:53permissions enm
- 1:13:55both of them are actually open they are
- 1:13:57classes because we executed a make class
- 1:13:59I think we can execute make enm as well
- 1:14:03can we make in um permissions in um two
- 1:14:09for example yeah that also works why I
- 1:14:11executed make class I don't know okay we
- 1:14:14open this app folder and those uh
- 1:14:17classes actually let's remove this make
- 1:14:19nm2 and we're going to change them from
- 1:14:22class into NM here
- 1:14:25and enm here and we obviously don't need
- 1:14:28this Constructor because these are
- 1:14:32enms okay now let's define the type of
- 1:14:36this enm permissions enm actually I'm
- 1:14:38thinking that I I just want to give you
- 1:14:41the information how you can set up the
- 1:14:43permissions and roles and connect them
- 1:14:44to each other but in our case I think
- 1:14:47that we are not going to use permissions
- 1:14:49we are only going to use roles and we're
- 1:14:52going to have three main roles in our
- 1:14:54project
- 1:14:55and let's define them um and this is
- 1:14:58cool part so this is now PHP
- 1:15:01storms full line autoc completion which
- 1:15:04is quite intelligent and we're going to
- 1:15:06see this in action uh right now and in
- 1:15:09in the next sections as well case
- 1:15:13administrator case user and we need
- 1:15:16another case which is going to be
- 1:15:20vendor okay now uh I want to change this
- 1:15:24into admin
- 1:15:26case
- 1:15:28admin okay
- 1:15:30cool as for the permissions we can
- 1:15:33create um small permissions for each row
- 1:15:37for example uh the regular user can
- 1:15:41browse the products can add the product
- 1:15:43into the cart can buy the products and
- 1:15:47can uh login can register and so on so
- 1:15:53you should Define for your specific
- 1:15:55project what type of uh these
- 1:15:59permissions you need like byproducts
- 1:16:01browse products um Edge into the cart
- 1:16:04and so on okay so in our case I'm going
- 1:16:08to just use
- 1:16:09rols uh
- 1:16:11and I'm not going to Define any kind of
- 1:16:14specific permissions but I I will show
- 1:16:16you how you can use these permissions as
- 1:16:19well
- 1:16:20okay so then uh the admin user can
- 1:16:24actually do everything it can do what
- 1:16:27the vendor user is doing so we're going
- 1:16:28to have we in your project you're going
- 1:16:31to define those permissions like manage
- 1:16:34um manage vendor vendors for example
- 1:16:38which is only relevant for the
- 1:16:40permissions actually let's let's do the
- 1:16:43following so I'm going to Define uh
- 1:16:45three permissions one corresponds to
- 1:16:48each uh role
- 1:16:51okay and these permissions will be
- 1:16:56um okay
- 1:16:58case I'm thinking right now so approve
- 1:17:05vendors let's say as an example is uh
- 1:17:09buy products which is common for uh user
- 1:17:14and another one sell products which is
- 1:17:17for vendor okay so three roles three
- 1:17:20permissions as I mentioned in more
- 1:17:23complex applications you probably need
- 1:17:25more permissions and you can associate
- 1:17:27more permissions to the roles now we
- 1:17:31have roles we have permissions and I
- 1:17:33want to open the database
- 1:17:36Cedar and I want to um seed some the
- 1:17:41these roles and permissions into the
- 1:17:44database okay or we can actually
- 1:17:48even um create a separate Cedar class
- 1:17:52for this this is also possible we can
- 1:17:53execute uh PHP artisan make Cedar now
- 1:17:57rolls Cedar roll Cedar and then we can
- 1:17:59use that roll Cedar in our project so in
- 1:18:02my case I'm going to put this right here
- 1:18:05um we might also need to
- 1:18:10create uh users and roles as well okay
- 1:18:14let's create now two see there PHP
- 1:18:16artisan
- 1:18:18make Cedar uh one is going to be roll
- 1:18:23Cedar
- 1:18:25and second is going to be user
- 1:18:29Ceder user
- 1:18:32Cedar okay so both seeders we are
- 1:18:37created now right here we don't need
- 1:18:40anything so and I'm going to call uh the
- 1:18:43method call here we're going to pass an
- 1:18:46array first we're going to execute R
- 1:18:49Ceder and then we're going to execute
- 1:18:51user Ceder and as you see the out
- 1:18:53completion helps a lot so inside R here
- 1:18:57we need to define those roles and we
- 1:19:00need to associate permissions to these
- 1:19:03roles now let's use this user Ro equals
- 1:19:09Ro reate and we're going to provide here
- 1:19:13name of the role to
- 1:19:16be uh roles enam
- 1:19:20user value okay we are going to import
- 1:19:25that roll from spoty permission models
- 1:19:28roll okay now let's duplicate these two
- 1:19:30more times next one is going to be
- 1:19:33vendor Ro here we're going to use
- 1:19:37vendor and the last one is going to be
- 1:19:41admin rooll and here we are going to use
- 1:19:45admin now we have all these three roles
- 1:19:47now let's define three permissions as
- 1:19:49well uh one is let's check the
- 1:19:52permissions andm one is approv vendors
- 1:19:55approve
- 1:19:58vendors is going to be
- 1:20:02permission spoty permission models okay
- 1:20:05permission create and inside the name
- 1:20:08we're going to
- 1:20:09use
- 1:20:11permissions enam aove
- 1:20:14vendors not name but
- 1:20:18value okay we're going to dup oh let's
- 1:20:20move this down so that everything is
- 1:20:22visible nicely visible okay let's
- 1:20:24duplicate these two times and this is
- 1:20:27going to be sell products sell
- 1:20:33products right here we're going to use
- 1:20:35sell products and the last one is going
- 1:20:38to be buy
- 1:20:41products buy products and here we need
- 1:20:46buy products as well now we have three
- 1:20:48roles three permissions and we're going
- 1:20:50to synchronize no permissions to those
- 1:20:53roles okay so on the user role we're
- 1:20:56going to call sync permissions and we're
- 1:21:00going to provide array of permissions
- 1:21:02right here so if you defined multiple
- 1:21:05permissions for each role if you have
- 1:21:08multiple permissions here and Define
- 1:21:10multiple permissions for each role
- 1:21:12you're going to synchronize all of them
- 1:21:13into the user Ro at the moment we have
- 1:21:15only one permission for user role and
- 1:21:18that's byproduct so we're going to
- 1:21:20provide byproducts here and we can put
- 1:21:22this probably on single line
- 1:21:25now we need to do something similar for
- 1:21:28vendor roll sync permissions and we're
- 1:21:32going to provide sell products as well
- 1:21:34as buy products so vendor users can
- 1:21:36actually buy products not their own
- 1:21:39products but somebody else's
- 1:21:41products and admin role can sell
- 1:21:44products buy products and also approve
- 1:21:50vendors okay let's make sure that this
- 1:21:53is visible
- 1:21:56now we have three roles we have three
- 1:21:58permissions and we Associated
- 1:22:00permissions to these roles and again if
- 1:22:02you have multiple permissions um 20 30
- 1:22:06whatever permissions you need to
- 1:22:07associate them to the roles and the main
- 1:22:10thing is that now user needs to have
- 1:22:13roles and for this let's
- 1:22:16open user Ceder and we're going to
- 1:22:19create now three users here
- 1:22:24let's use
- 1:22:26user uh
- 1:22:28user Factory create and we're going to
- 1:22:32provide name to be
- 1:22:37user email to be user at
- 1:22:41example example.com
- 1:22:45and the password can be the default one
- 1:22:47which is inside the user Factory let's
- 1:22:49open user Factory as well and have a
- 1:22:52look so the default password is going to
- 1:22:54be just password and we can leave this
- 1:22:57and we created that user let's import
- 1:22:59this user model app models user and
- 1:23:02finally when the user is created we're
- 1:23:04going to assign role to it and the role
- 1:23:07is going to be user role but we're going
- 1:23:09to use rolls
- 1:23:12enam rolls
- 1:23:15enam
- 1:23:17um user value okay and let's now
- 1:23:22duplicate these two more times and this
- 1:23:24is going to be
- 1:23:28vendor uh let's keep it first name and
- 1:23:30last name like vendor whatever vendor
- 1:23:34vendor okay let it be just vendor so
- 1:23:37vendor example.com and that should have
- 1:23:40vendor roll let's create one empty line
- 1:23:44and the last one is going to be
- 1:23:47admin admin example.com and the role
- 1:23:50assigned to it is going to be admin
- 1:23:52rooll okay one one additional thing I
- 1:23:55want to show to you is that we created
- 1:23:57those enms inside app folder directly
- 1:24:01but I actually want to move them into
- 1:24:03the enm folder and this is something I
- 1:24:05did on
- 1:24:06purpose so I'm going to create now enm
- 1:24:10folder or
- 1:24:11enams and now pay attention so we are
- 1:24:14using these um enams already in couple
- 1:24:16of places so for example here in the
- 1:24:20user um user Cedar we are using
- 1:24:26rolls Anam where is the import here we
- 1:24:29see this rolls Anam and we also have the
- 1:24:33permissions enam right here now I'm
- 1:24:36going to move those enms into anms
- 1:24:39folder and click on refactor and the
- 1:24:42refactoring will basically change the
- 1:24:45usage of that as well now we see that
- 1:24:47rolls enam now is coming from anam's
- 1:24:50folder and permissions enm is also
- 1:24:52coming from anam's folder in in stead
- 1:24:55of instead of the app folder
- 1:24:59directly and this is pretty cool now we
- 1:25:02Define the um M the the cedar classes
- 1:25:06and I think we can execute PHP Artisan
- 1:25:08migrate again I'm going to double click
- 1:25:11on control PHP Artisan migrate you can
- 1:25:16open the terminal if you don't follow
- 1:25:18with PHP store hit the
- 1:25:20enter nothing to migrate that's correct
- 1:25:23we're going to execute actually PHP AR
- 1:25:25migrate
- 1:25:27fresh- D seed we're going to hit the
- 1:25:31enter okay everything was completed and
- 1:25:34now let's check so inside users we see
- 1:25:38three users inside roles we see three
- 1:25:41roles inside permissions we see three
- 1:25:43permissions and we also have Ro has
- 1:25:46permissions and we have these defined
- 1:25:48here okay so totally there are six
- 1:25:52records and that's because if we check
- 1:25:54roles right now admin user has three
- 1:25:57roles vendor has two roles and user has
- 1:26:00one Ro totally six records and we also
- 1:26:03have model has roles which is the
- 1:26:06polymorphic table Ro ID the model type
- 1:26:09and the model ID each user has one role
- 1:26:12Associated to
- 1:26:14it inside model has permissions we don't
- 1:26:17have anything because we did not
- 1:26:19explicitly associate user any
- 1:26:22permissions user has roles r has has
- 1:26:25permissions and the user has permissions
- 1:26:27as well and just like this we Define
- 1:26:30roles permissions uh created the correct
- 1:26:32Cedar class and we probably need to
- 1:26:35create comment message
- 1:26:37here install
- 1:26:40spy permissions package and Define roles
- 1:26:45and
- 1:26:48permissions uh again if you're doing
- 1:26:50something on production you should
- 1:26:51probably make a review uh something
- 1:26:55which if you working on an application
- 1:26:58um real application uh for a production
- 1:27:01cool let's close now everything now I'm
- 1:27:04going to install filament PHP and have
- 1:27:07this admin panel admin area for admin
- 1:27:11users as well as for the vendor users
- 1:27:14now I'm going to open filament docs and
- 1:27:17I think I'm going to use the this quite
- 1:27:19a
- 1:27:22lot click on get
- 1:27:25started here and the installation
- 1:27:28instructions the following however I'm
- 1:27:30not going to uh require this specific
- 1:27:32version I'm just going to require
- 1:27:34filament filament just like this because
- 1:27:37I had some issues previously when
- 1:27:39requiring that
- 1:27:413 um two version okay so let's execute
- 1:27:45composer require filament filament after
- 1:27:48which we're going to create install
- 1:27:51panels so let me copy the following
- 1:27:53commment the installation was done now
- 1:27:55we're going to um execute filament
- 1:27:58install D- panels and here we have to
- 1:28:01provide the ID for the panel and we can
- 1:28:04leave this the default one which is
- 1:28:05admin I'm going to hit the
- 1:28:07enter and right now I'm just going type
- 1:28:11no okay so the provider was created if
- 1:28:15we check
- 1:28:16up providers filament we see this admin
- 1:28:20panel provider and now we should be able
- 1:28:23to
- 1:28:24access the URL so on admin URL we see
- 1:28:29this filament admin page however we
- 1:28:31haven't created the filament user we're
- 1:28:33going to execute the following command
- 1:28:35let's bring up the terminal paste hit
- 1:28:38the enter and we have to provide the
- 1:28:39name so we actually already have admin
- 1:28:42user right so do we need to create new
- 1:28:44user I think no so I'm just going to
- 1:28:47cancel this and try to authenticate with
- 1:28:51admin at example.com click on sign in
- 1:28:55and I was able to log in so I don't need
- 1:28:57to execute the following um command and
- 1:29:00right now the thing is that I am able to
- 1:29:04access to this panel with every user
- 1:29:07even the user role is able to access
- 1:29:10this because we don't have that type of
- 1:29:13restriction but obviously user role
- 1:29:16users should not be able to access to
- 1:29:19this panel for this we need to use the
- 1:29:22correct middle We R all middle we from
- 1:29:25the spa permission package so if we
- 1:29:28check the documentation again we're
- 1:29:30going to find this middle wear section
- 1:29:33and if we scroll down below we see U how
- 1:29:36we can add these middle we or what
- 1:29:38middle we there exist so K is basically
- 1:29:42for permissions however we want middle
- 1:29:45wear which refers to roles so if we
- 1:29:47scroll down below uh yeah this is also
- 1:29:50the case where we can Define the uh
- 1:29:53middle we alas is and this is what I'm
- 1:29:55going to do so I'm just going to copy
- 1:29:58this and go into my
- 1:30:03bootstrap up PHP and this is where uh
- 1:30:08inside with middle we I'm going to paste
- 1:30:11this code so I defined the following
- 1:30:13aliases for the roll middle wear
- 1:30:16permission middle wear and roll or
- 1:30:18permission middle middle wear and now if
- 1:30:21we check how we can use this roll middle
- 1:30:23wear is the following so role manager
- 1:30:27and if we want we can specify the guard
- 1:30:31here as well or we can also provide
- 1:30:34multiple roles with pipe so in this case
- 1:30:38this means that uh the following group
- 1:30:41applies to the role for manager or for
- 1:30:45writer now let's open just created admin
- 1:30:50panel provider and if we scroll down
- 1:30:52below here we have this middle wheel
- 1:30:54so also accessing to
- 1:30:59um accessing to admin panel
- 1:31:03provider yeah it it is only for
- 1:31:06authenticated users right so we don't
- 1:31:08need to do any additional out
- 1:31:11here we only need to use roll middle
- 1:31:15wear so for this I'm going to use Sprint
- 1:31:18Sprint function and I'm going to use
- 1:31:21roll colum and then we need uh two roles
- 1:31:26actually one for admin second for vendor
- 1:31:30so let me use this percent s then pipe
- 1:31:34and another percent s and we have to
- 1:31:38provide those two roles here roll uh
- 1:31:43roles in
- 1:31:45um
- 1:31:47admin value and duplicate this and rolls
- 1:31:52enam vendor value value so only admin
- 1:31:56and vendor users will be able to access
- 1:31:58to this admin panel provider and if we
- 1:32:01right
- 1:32:09now yeah we need out as
- 1:32:12well we access the
- 1:32:14homepage user is not authenticated click
- 1:32:17on admin user is not logged
- 1:32:21in let's provide out that is is also
- 1:32:24necessary probably
- 1:32:27here okay it requires authentication and
- 1:32:31I added this out because I don't want to
- 1:32:33access this adamine basically without
- 1:32:37authentication so I'm going to use the
- 1:32:39following login form this login form but
- 1:32:42whenever the login is done in our case
- 1:32:46let's try to log in with the user then
- 1:32:49the user uh will not be able to actually
- 1:32:51access to the admin now user is
- 1:32:55authenticated but user is not able to
- 1:32:59access admin that's correct however if
- 1:33:03admin user will sign up admin at
- 1:33:06example.com click on
- 1:33:09login then access on admin this is
- 1:33:13possible and also
- 1:33:16if also if a
- 1:33:19vendor vendor user will log in
- 1:33:28uh what
- 1:33:30happened password the enter okay and now
- 1:33:33try to access to admin vendor user is
- 1:33:36also able to access the admin area okay
- 1:33:39only user is not able and based on who
- 1:33:43who is authenticated right now I'm going
- 1:33:45to also implement the way to redirect
- 1:33:48user into the correct um correct Road so
- 1:33:54for this let's
- 1:33:56open
- 1:33:58authenticated session controller which
- 1:34:01is the controller inside which we
- 1:34:04Implement user
- 1:34:07login okay after the authenticate
- 1:34:10happens and the session regenerate
- 1:34:12happens let's grab user from out user
- 1:34:16and we can also add this annotation that
- 1:34:18the user is an instance of user model so
- 1:34:21that uh PHP storm giv gives us the cool
- 1:34:25a completion so if user um and I'm going
- 1:34:29to use now has any role and I want to
- 1:34:33provide two roles here if user has any
- 1:34:36role and let's now use roles
- 1:34:39inam
- 1:34:42admin uh actually I think we don't need
- 1:34:45to provide the value so if user has any
- 1:34:49role admin
- 1:34:51and roles and um
- 1:34:56rolls and um
- 1:34:58vendor then we need to redirect user
- 1:35:01into the filament admin Pages dashboard
- 1:35:06okay so we need to know what is the root
- 1:35:09name for um for filament or we can use
- 1:35:14the uh root URL as well so let me tell
- 1:35:18you what I mean so first I'm going to
- 1:35:19use
- 1:35:20inertia location because I want to
- 1:35:23redirect outside of the inertia um page
- 1:35:29okay and then inside the location I can
- 1:35:31provide just admin like this and it's
- 1:35:34going to work okay let let me leave this
- 1:35:36right now and I'm going to come back to
- 1:35:38this and if the user else if the user
- 1:35:43has
- 1:35:44role regular user role then we need to
- 1:35:49do something else okay uh let me Define
- 1:35:53right now now Ro equals
- 1:35:56slash and if the regular user is trying
- 1:36:00to authenticate then I'm going to change
- 1:36:02the root to be let me use
- 1:36:07root root dashboard and I'm going to
- 1:36:12provide uh also
- 1:36:14absolute true
- 1:36:17here and finally we are going to change
- 1:36:22the following part
- 1:36:25uh actually I need absolute false
- 1:36:27because default one is absolute true and
- 1:36:29then I'm going to provide this route
- 1:36:32here so if the authenticated user is
- 1:36:35either admin or vendor we're going to
- 1:36:37redirect into admin location um if the
- 1:36:40user is then regular user we can use
- 1:36:43just else as well in this case so then
- 1:36:46we're going to redirect into dashboard
- 1:36:49okay so if I save this right now and
- 1:36:52click on log out
- 1:36:55then let me try to authenticate as
- 1:37:00admin okay return value must be typed
- 1:37:03okay so I need to change
- 1:37:06this
- 1:37:07uh re redirect response this is not
- 1:37:11redirect response anymore it is
- 1:37:18actually so we are going to use both
- 1:37:25okay let's see if that
- 1:37:32works uh is the user authenticated
- 1:37:36now yeah the user is authenticated let's
- 1:37:38log out click on
- 1:37:41login uh I'm going to use
- 1:37:45admin okay so now I'm redirected into
- 1:37:48the admin page which is exactly what I
- 1:37:50wanted and we can try other two roles as
- 1:37:53well well vendor click on enter redirect
- 1:37:57it into admin and log
- 1:38:01out and
- 1:38:04user enter redirected into something uh
- 1:38:09user doesn't have the right roles so it
- 1:38:12is probably because it still tries to
- 1:38:15access to admin page but this is what
- 1:38:18I'm going to
- 1:38:19do I'm going to log out
- 1:38:25and click on login
- 1:38:28user now we are redirected into
- 1:38:30dashboard which works correctly however
- 1:38:33we don't even want this dashboard page
- 1:38:36so we're going to open web.php and we're
- 1:38:39going to change this uh here so we don't
- 1:38:41need dashboard uh or we can define
- 1:38:45something like this that the dashboard
- 1:38:47is the
- 1:38:49homepage uh I'm going to remove this
- 1:38:52dashboard completely okay so I don't
- 1:38:54need this dashboard uh however the
- 1:38:57dashboard rot name might be used in
- 1:38:59couple of other places so I'm going to
- 1:39:01search for root dashboard that is used
- 1:39:06here um couple of other places so open
- 1:39:11in find
- 1:39:13window let's define um either we have to
- 1:39:16change all the places where the
- 1:39:17dashboard uh Roots name is used and to
- 1:39:21be more specific we're going to search
- 1:39:22for lowercase and words so those are the
- 1:39:25roots names and they are used inside the
- 1:39:27verify email controller and many other
- 1:39:30places so the dashboard is basically the
- 1:39:32homepage right for authenticated users
- 1:39:34only so what I'm going to do right now
- 1:39:36is assign dashboard rout to the
- 1:39:42homepage dashboard just like this and
- 1:39:46now if we go
- 1:39:49back access to login and if I log out
- 1:39:54then if I try to log in as a regular
- 1:39:56user the user will be redirected back to
- 1:39:59the
- 1:40:01homepage now instead of having this
- 1:40:03hardcoded admin route right here this is
- 1:40:06something we can also change and let me
- 1:40:08bring up the terminal and we're going to
- 1:40:11execute PHP Artisan root list and this
- 1:40:15way we're going to see all the Define
- 1:40:17roots and I want to find this admin root
- 1:40:22filament
- 1:40:23admin as you see and it has the
- 1:40:25following root name associated to it
- 1:40:28filament admin Pages dashboard so we can
- 1:40:30copy the following root name and instead
- 1:40:33of hardcoding admin URL here we can use
- 1:40:36root and provide the root name filament
- 1:40:39admin uh Pages dashboard now if we save
- 1:40:43this log
- 1:40:45out try to log in with admin user we
- 1:40:49will be redirected back into the
- 1:40:51dashboard and one last thing just make
- 1:40:54sure everything works correctly I'm
- 1:40:56going to try
- 1:40:58to log in as user and user is is not
- 1:41:02able to access the uh admin this is what
- 1:41:05I wanted to test no this is not for the
- 1:41:09users one last thing I want to do inside
- 1:41:13this admin panel provider is that to
- 1:41:15comment out this out middle we so the
- 1:41:19authenticate uh is the filament
- 1:41:21authenticate which uh basically redirect
- 1:41:23user into the filament login page and if
- 1:41:26you want to have the filament login page
- 1:41:28uh that's also fine and that's also
- 1:41:31possible but in our case I just don't
- 1:41:34want this filament login page let's move
- 1:41:36the semicolon down I'm going to comment
- 1:41:38out this part completely I'm using
- 1:41:40regular out and I'm using regular login
- 1:41:44page even for the filament uh interface
- 1:41:48so the admin and vendors will use this
- 1:41:51login page to access to filament admin
- 1:41:54panel and then based on the roles and
- 1:41:57permissions um not permissions maybe but
- 1:42:00roles we're going to differentiate what
- 1:42:02admin users is going to see and what
- 1:42:04vendor users is going to see or access
- 1:42:07right
- 1:42:08here and now I'm going to make a quick
- 1:42:11comment message I have a look in the
- 1:42:12composer Json filament was installed uh
- 1:42:16do we have anything else here the
- 1:42:18command was added filament upgrade
- 1:42:20command was added into post aoad dump
- 1:42:23that's fine you can make the review
- 1:42:25entire review of this we have new files
- 1:42:27admin panel provider as well as some CSS
- 1:42:30and JavaScript files which is necessary
- 1:42:32for filament and I'm going to include
- 1:42:34all of them right now call this install
- 1:42:39uh filament and create admin
- 1:42:44panel now I'm going to start working on
- 1:42:47displaying departments for admin users
- 1:42:50and managing those departments so the
- 1:42:52idea is that admin users the website
- 1:42:54administrators will Define departments
- 1:42:57and
- 1:42:57categories and those are the Departments
- 1:43:00and categories which is available for
- 1:43:03sales on the website and vendor users
- 1:43:06will use those departments and
- 1:43:09categories to create products from their
- 1:43:12end and just publish them on the website
- 1:43:14so if the department is not defined if
- 1:43:17admin users are not selling special type
- 1:43:20of uh products under the Department then
- 1:43:23the admin users will not be able to
- 1:43:26define the department so uh the the
- 1:43:28vendor users will only be able to sell
- 1:43:31those products which departments are
- 1:43:33already defined by admin users the first
- 1:43:36thing we're going to do is to define the
- 1:43:38department model in
- 1:43:40migration so I'm going to execute PHP
- 1:43:43artisan make model Department DM for
- 1:43:48migration as well the model and the
- 1:43:51migration was created now let's open
- 1:43:53create departments table and we're going
- 1:43:56to define a few Fields uh we need name
- 1:44:00uh we
- 1:44:01need um string slug which actually must
- 1:44:07be unique we
- 1:44:10need uh we need string uh meta title
- 1:44:15which can be null we need meta
- 1:44:17description which can also be null and
- 1:44:20we need table
- 1:44:23Boolean active which by default should
- 1:44:26be
- 1:44:27true okay so we Define those fields and
- 1:44:31now we're going to generate a filament
- 1:44:34resource but before I do this I'm going
- 1:44:37to open providers filament admin panel
- 1:44:40provider and I'm going to unguard all
- 1:44:42the models uh right here so I'm going to
- 1:44:46add here boot
- 1:44:49method
- 1:44:51boot that should should be
- 1:44:55boot okay and I'm going to execute model
- 1:44:59illuminate database eloquent uard so the
- 1:45:03models what I'm going to use in the
- 1:45:06filament uh will be unguarded which
- 1:45:08basically means that uh the if we open
- 1:45:11Department PHP so we don't have anything
- 1:45:15defined in the fiable and generally when
- 1:45:18we load some data into model uh these
- 1:45:22fields
- 1:45:23um should be defined in the failable but
- 1:45:27the
- 1:45:28Ard disables that check basically and it
- 1:45:32is because we are going to only use that
- 1:45:34on the filament side arding model is
- 1:45:37actually a common thing and we can check
- 1:45:39the documentation as well about this uh
- 1:45:42this is mentioned also in the
- 1:45:43documentation um it's not something like
- 1:45:46I came up
- 1:45:49with uh okay now what I'm going to do is
- 1:45:52to generate new
- 1:45:56resource uh okay let's check the getting
- 1:45:58started section uh this is the demo
- 1:46:01project create models everything here's
- 1:46:04the arding example in our um filament
- 1:46:07demo and what we want is to generate now
- 1:46:10department resource so we have the model
- 1:46:13ready we have the table ready we
- 1:46:14probably need to execute migrations PHP
- 1:46:17Artis on
- 1:46:19Migrate okay Department stable was
- 1:46:22created let's clear this up and now
- 1:46:24let's execute actually I think we can
- 1:46:27always use this double Control Paste
- 1:46:29this here PHP artisan make filament
- 1:46:32resource and we're going to call this
- 1:46:36department hit the enter okay Department
- 1:46:39resource was created and now if we check
- 1:46:42the browser we're going to see
- 1:46:44departments right here if we click on
- 1:46:46this we don't see anything if we click
- 1:46:48this new Department we also don't see
- 1:46:51anything and this is something
- 1:46:53we have to take care of and Define
- 1:46:55Fields now let's
- 1:46:58open just created Department resource
- 1:47:02and we're going to find this form area
- 1:47:04and we're going to define a couple of
- 1:47:06fields I'm going to use text input make
- 1:47:09for name uh and I'm going
- 1:47:12to uh it should be
- 1:47:14required and I also uh want to have Slug
- 1:47:18and whenever name is changed I want to
- 1:47:20generate slug from the name so let's
- 1:47:24define slug as well we need comma here
- 1:47:28that should be Slug and we also need to
- 1:47:32Define
- 1:47:36checkbox we need comma here checkbox
- 1:47:40filament forms component checkbox and
- 1:47:43should be active
- 1:47:45checkbox uh
- 1:47:47and let's check the Imports
- 1:47:53yeah text input was imported but why
- 1:47:55wasn't checkbox wasn't imported let's
- 1:47:58import the checkbox as
- 1:48:01well okay now we're going to listen to
- 1:48:05uh we're going to make this live and
- 1:48:07we're going to listen on blur of the
- 1:48:10name and whenever on blur happens now
- 1:48:14I'm going to add a call back after State
- 1:48:19updated okay and whenever state is
- 1:48:22updated
- 1:48:24it returns this state so this is what we
- 1:48:26are going to
- 1:48:33change let's provide regular function
- 1:48:37here uh why do we have so many
- 1:48:40RS probably we have some yeah we don't
- 1:48:43need
- 1:48:44this okay so whenever state is updated
- 1:48:48we're going to update this slag so here
- 1:48:51um the a completion didn't
- 1:48:53quite work perfectly so we have string
- 1:48:56operation what happens whether that was
- 1:48:59um create or update and we have also
- 1:49:03State here and we have cable which is
- 1:49:08set and we are going to call set we are
- 1:49:12going to provide the attribute name Slug
- 1:49:16and we're going to generate the state is
- 1:49:18going to be the actual name and I'm
- 1:49:20going to use St Str
- 1:49:23um support generate slug from State
- 1:49:28let's format the code okay name slugs
- 1:49:31required that's active okay now let's
- 1:49:34have a look refresh the page and we see
- 1:49:36name Slug and active and I'm going to
- 1:49:38call this um Electronics as an example
- 1:49:42and whenever I click on outside that is
- 1:49:45updated we have double e here which is
- 1:49:48not necessary that gets updated I'm
- 1:49:50going to click on active click on create
- 1:49:53and that was actually created and we can
- 1:49:55click on departments and we're going to
- 1:49:57see one record right here but now we
- 1:50:00need to display that information so
- 1:50:03scroll down below in the columns area
- 1:50:07we're going to use text column for name
- 1:50:10we can make this sortable and we can
- 1:50:13make this searchable as well and we can
- 1:50:17also provide right here default sort to
- 1:50:21be by create ated at in descending
- 1:50:26order then we have filters uh inside
- 1:50:29actions we have edit and we probably
- 1:50:32need to add delete action as well and
- 1:50:37inside bulk actions we're going to have
- 1:50:39this um delete action only so if I save
- 1:50:42this right now refresh the page we're
- 1:50:44going to see name right here which is
- 1:50:45sortable searchable and clicking edit
- 1:50:48opens this clicking delete bring UPS
- 1:50:51brings up the confirmation click on
- 1:50:53confirm and the record was
- 1:50:55deleted that's
- 1:50:57awesome now let's add two things right
- 1:51:00here first is that whenever we create
- 1:51:03new
- 1:51:04Department uh we stay on the edit page
- 1:51:07and we want to be redirected into the
- 1:51:09index page so for this let's open the
- 1:51:14department so inside up filament
- 1:51:18resources department resource click on
- 1:51:22this create department and right here
- 1:51:24we're going to add a get redirect URL
- 1:51:29and we are going to redirect user into
- 1:51:33the index road so
- 1:51:36this get
- 1:51:39resource oops get
- 1:51:42resource and then on that we're going to
- 1:51:45call uh get URL for index okay this get
- 1:51:50resource Returns the following class and
- 1:51:53that has the pages right here and we
- 1:51:56need index page and we're going to do
- 1:51:59something similar on Department
- 1:52:02edit edit Department scroll down below
- 1:52:07oops and get redirect URL now if we
- 1:52:11update the record we will be redirected
- 1:52:13into index or if we create new record we
- 1:52:17will be redirected into the index second
- 1:52:21thing is that if we log out right now
- 1:52:24and try
- 1:52:26to log in as
- 1:52:30vendor we access the admin and we are
- 1:52:33able to see the Departments but vendor
- 1:52:34users should not be able to see the
- 1:52:38Departments right so this is something
- 1:52:41we need to uh fix in the department
- 1:52:45resource down below we're going to add
- 1:52:46new function public static function uh
- 1:52:51can view
- 1:52:53any where we're going to overwrite that
- 1:52:55function and we're going to return true
- 1:52:57or false whether the current user has
- 1:52:59access to see list of departments or
- 1:53:04not and so in this case I'm going to
- 1:53:07access user using filament
- 1:53:12user uh actually filament
- 1:53:15Al user and then I'm going to check if
- 1:53:19user
- 1:53:20exists and if
- 1:53:23user has
- 1:53:25rooll
- 1:53:27admin roles
- 1:53:30enam admin only in this case we are
- 1:53:34going to um give the permission to view
- 1:53:38the listing now if I refresh the page it
- 1:53:41is forbidden if I simply access admin
- 1:53:44page now the user is not able the vendor
- 1:53:47user is not even able to see departments
- 1:53:50in the menu item which is exactly what
- 1:53:52we wanted if you log out right now and
- 1:53:55log in as admin user admin user now sees
- 1:53:59these
- 1:54:00departments okay this is awesome now if
- 1:54:02we click on this this is the edit page
- 1:54:05uh and we also want to manage categories
- 1:54:08for the department so the department
- 1:54:10might have multiple categories and we
- 1:54:12want to manage that as
- 1:54:15well now let's create category model and
- 1:54:18Define the migration as well and we're
- 1:54:20going to set up the relation between
- 1:54:21departments and categories for this I'm
- 1:54:24going to execute PHP artisan make a
- 1:54:28category provide the migration as
- 1:54:33well uh I'm sorry I did something stupid
- 1:54:36PHP artisan make model category in the
- 1:54:41migration as well now let's open create
- 1:54:44categories
- 1:54:46table and we're going to Define category
- 1:54:50name we're going to Define
- 1:54:52um boring ID on we need parent ID
- 1:54:57actually so that should be knowable and
- 1:54:59constrainted on categories uh but we
- 1:55:02also need
- 1:55:03table uh foring ID that should be on
- 1:55:09Department ID okay and we can um we need
- 1:55:14that to be constrained and we probably
- 1:55:17need to also add index to
- 1:55:21that uh as as well as the parent
- 1:55:25ID maybe we need to move this
- 1:55:32down so we have name we have the
- 1:55:35department name we have the parent
- 1:55:37category name and we can add additional
- 1:55:40field which is going to be uh Boolean
- 1:55:46active Okay by default we can assign it
- 1:55:49to true so now we have that categories
- 1:55:52table defined as well I'm thinking if I
- 1:55:55missed anything I think I don't
- 1:55:57optionally we can add order attribute as
- 1:55:59well to implement ordering which
- 1:56:01category should be the first which one
- 1:56:02should be the second but I'm going to
- 1:56:04skip that part so now we have this uh
- 1:56:06migration ready let's execute PHP
- 1:56:09Artisan migrate hit the enter migrations
- 1:56:13we applied awesome and now we're going
- 1:56:16to Define relation between Department
- 1:56:19into category so we can create separate
- 1:56:21resource category resource s but this is
- 1:56:23what I'm going to do I'm just going to
- 1:56:24show the category management right here
- 1:56:29on the department page for
- 1:56:33this uh there is something related to
- 1:56:36relation so
- 1:56:39relation uh relation manager introducing
- 1:56:42relation managers I think this is what
- 1:56:45we want exactly okay now I'm going to
- 1:56:47copy the following commment and let's
- 1:56:49execute this and um I will explain this
- 1:56:52so we're going to execute PHP Artis and
- 1:56:54make filament relation manager and we're
- 1:56:57going to provide the parent resource
- 1:56:59which is Department resource okay so
- 1:57:03we're going to define the relation from
- 1:57:06Department resource uh we're going to
- 1:57:09define the field uh the relation field
- 1:57:12which is going to be categories okay and
- 1:57:14we're going to also use the name field
- 1:57:17which will be used in the relation um
- 1:57:20that field is the category field
- 1:57:22name um let's hit the
- 1:57:28enter um let's have a look filament
- 1:57:31relation manager okay make sure to
- 1:57:33register the relation in get relations
- 1:57:37so we have to register that relation but
- 1:57:40we have to also open Department PHP and
- 1:57:43Define has many has many
- 1:57:47categories which goes to category model
- 1:57:52now let's open
- 1:57:54Department
- 1:57:56resource and we are going to find the
- 1:58:01method get relations and right here
- 1:58:04we're going to use categories relation
- 1:58:06manager uh class okay so I save
- 1:58:11this and refresh the page and down below
- 1:58:14we see categories and I click this new
- 1:58:17category which brings up this form and
- 1:58:20this is something we are going to work
- 1:58:23right now and add more um Fields here
- 1:58:27let's open these categories relations
- 1:58:30manager and here we have the form we
- 1:58:33also need a prent ID which is going to
- 1:58:36be select select p in ID uh it is not
- 1:58:40actually required but we have to Define
- 1:58:42what options that should have so I'm
- 1:58:44going to provide options here which
- 1:58:47accepts
- 1:58:49function okay and from here we're going
- 1:58:52to return the array what will be the
- 1:58:56options for that select so we are going
- 1:58:59to do Q from
- 1:59:01category uh we're going to filter and
- 1:59:04take out only those categories which
- 1:59:07belong to this specific department and
- 1:59:11this specific Department basically is
- 1:59:14right here um we can access the record
- 1:59:18in the following way this get owner
- 1:59:22record and this is going the owner in
- 1:59:24this case is the department so we can
- 1:59:25call this
- 1:59:28department all right and then right here
- 1:59:31inside this function we're going to pass
- 1:59:34use department and we're going to find
- 1:59:37those
- 1:59:40categories uh let's provide um
- 1:59:44where where um column name
- 1:59:50Department Department ID equals the
- 1:59:53given
- 1:59:55Department ID all right then I'm going
- 1:59:58to call plaque on this I want
- 2:00:01associative array column name is going
- 2:00:03to be the name the key is going to be
- 2:00:05the ID and finally I'm going to call two
- 2:00:08array on
- 2:00:10this um I think that's good so we have
- 2:00:13the department we're giving the
- 2:00:15department we're filtering categories
- 2:00:18okay so let's give it a label to this
- 2:00:22parent ID the label is going to be pent
- 2:00:26category let's give it
- 2:00:28also reload it is going to be preloaded
- 2:00:32uh without clicking on on this and I'm
- 2:00:35going to make this also
- 2:00:38searchable basically we are preloading
- 2:00:40all the Departments uh sorry all the
- 2:00:44categories uh without this preload and
- 2:00:47searchable it is going to search by the
- 2:00:49given uh keyword what we're going to put
- 2:00:52there okay and we also need checkbox so
- 2:00:55we can use checkbox make active Okay
- 2:01:01cool uh let's focus on the table as well
- 2:01:04here we have the columns we have name at
- 2:01:07the moment and we're going to make
- 2:01:09that name
- 2:01:12sortable and searchable and we're going
- 2:01:15to use additional text column as well
- 2:01:19which is going to be parent name but in
- 2:01:21this case I'm going to access this
- 2:01:23through relation parent. name and let's
- 2:01:27make this
- 2:01:28sortable and searchable as well and
- 2:01:32finally we need um icon column here
- 2:01:36which is going to be
- 2:01:39active however the parent relation does
- 2:01:42not exist at the moment so we're going
- 2:01:44to open category model and we're going
- 2:01:48to Define right here heent relation
- 2:01:51belongs to
- 2:01:52pent and this is going to be category by
- 2:01:56pent
- 2:01:58ID okay and we can also Define um as
- 2:02:02many children but we don't need this at
- 2:02:04the moment so I'm going to skip that
- 2:02:06part now I save this refresh the
- 2:02:10page now let's have a look new
- 2:02:14category name headsets for example the
- 2:02:18parent category nothing click on AC
- 2:02:22create that was created now let's see
- 2:02:27Sony
- 2:02:29headsets parent is headsets active
- 2:02:33create uh active is not displayed for
- 2:02:37some
- 2:02:38reason I column I think we have this
- 2:02:42Boolean as well so this is a Boolean and
- 2:02:45in which case it should display this
- 2:02:47properly okay cool so if I edit this it
- 2:02:51brings up this model deactivate click on
- 2:02:54Save we see that the active Flags like
- 2:02:56this so that's pretty cool so now we can
- 2:02:59search for
- 2:03:01Sony and it filters out those categories
- 2:03:05so just like this now we have crowd for
- 2:03:07departments you can create any
- 2:03:08department so let's define uh
- 2:03:12electronics uh and let's make it active
- 2:03:15click on create that was created and uh
- 2:03:19inside the electronics you can Define
- 2:03:21categories as
- 2:03:23well let me actually Define some C data
- 2:03:27for departments and for categories so
- 2:03:30I'm going to execute PHP artisan make
- 2:03:35Cedar uh this is going to be Department
- 2:03:39Cedar we hit the
- 2:03:41enter and PHP Artisan makes Cedar the
- 2:03:45next one is going to be category Cedar
- 2:03:49we hit the enter okay let's open
- 2:03:52database Cedar and let's add Department
- 2:03:57Cedar here and category Ceder here now
- 2:04:01let's open Department Ceder and I'm
- 2:04:05going to actually
- 2:04:07use uh copy some data from Department
- 2:04:10CED what I have prepared and you can
- 2:04:14grab it from the
- 2:04:16uh video description or you can type it
- 2:04:19or you can uh get it from the source
- 2:04:22code of the project so this is just
- 2:04:25associative array containing six uh
- 2:04:27departments I think it's six so we have
- 2:04:29this name electronics its corresponding
- 2:04:32slack active true and created that and
- 2:04:35update that is now okay so we have this
- 2:04:37departments we have fashion again active
- 2:04:40we have home gardening tools and we can
- 2:04:42import this Str
- 2:04:45Str oops let's import this eliminate
- 2:04:49support St Str uh we generate slug
- 2:04:53basically out of the following name so
- 2:04:56here again we generate um slug out of
- 2:04:59this text and here again we generate
- 2:05:01Slag out of this text and these are all
- 2:05:03the Departments we have and what we need
- 2:05:05to do right now is to
- 2:05:09use DB DB
- 2:05:13table departments insert and let's
- 2:05:17import this illuminate support facades
- 2:05:19DB as well and we're going to do
- 2:05:22something similar into category as well
- 2:05:25so let me copy some category data as
- 2:05:31well
- 2:05:33category
- 2:05:36Cedar and I'm going to paste this let's
- 2:05:38have a look so we have name of the
- 2:05:43category to be electronics and it is uh
- 2:05:46referring to Department ID one assuming
- 2:05:49that the department ID is for electron
- 2:05:52parent ID is null and active is true
- 2:05:55create that updated that next we have
- 2:05:57fashion it's for Department to uh and uh
- 2:06:02and so on basically so we have parent ID
- 2:06:04n here as well but um this is again for
- 2:06:08Department one which is electronics now
- 2:06:10we have computers a second category
- 2:06:12inside electronics and it has PRN ID in
- 2:06:16this case it is a child of electronics
- 2:06:18category and we have smartphones which
- 2:06:20is also
- 2:06:22um here into is electronics so child of
- 2:06:25electronics and we see right here
- 2:06:27laptops and so on so we have desktops
- 2:06:30all of them belong to Department one but
- 2:06:32in this case the parent is uh computers
- 2:06:37right and we have smartphones as well
- 2:06:39pent is
- 2:06:40smartphones um and so on where's
- 2:06:45the we have smartphones as you see if
- 2:06:48you scroll down below then we have
- 2:06:50Android which has PR inti the
- 2:06:52smartphones in the iPhone as well so
- 2:06:55finally let's use
- 2:06:57DB uh table categories insert and just
- 2:07:01like this we're going to have the whole
- 2:07:03data however I'm going to execute PHP
- 2:07:06artisan
- 2:07:07make um not make but
- 2:07:11migrate Fresh So that everything is
- 2:07:13dropped and recreated with D- C data so
- 2:07:17the data what we created right here is
- 2:07:20going to be dropped and new data will be
- 2:07:22created and we will have categories and
- 2:07:24departments for your e-commerce website
- 2:07:27you might need to put more departments
- 2:07:29and more categories in your Cedar uh
- 2:07:33classes but that's up to you so in my
- 2:07:36case let's execute phps and make um PHP
- 2:07:39and migrate Fresh D
- 2:07:43seed okay all the seeders we are
- 2:07:45executed now we will be logged
- 2:07:49out now if we are authenticate with
- 2:07:53admin click on departments we see
- 2:07:57Electronics Fashion Home garden tools
- 2:07:59book and audible okay so far so good
- 2:08:02click on electronics and we see the
- 2:08:04following categories belong to
- 2:08:06electronics department so this one is
- 2:08:08the prent category and now this one the
- 2:08:11other ones uh simply belong to this so
- 2:08:14now we have at least some simple data to
- 2:08:16work with and to create some products
- 2:08:18out of this data clicking on this triers
- 2:08:21editing and we can change the paring
- 2:08:23category we can do anything we want
- 2:08:25clicking on this will um trigger the
- 2:08:27delete and I don't want to delete
- 2:08:29anything at the moment and let's search
- 2:08:32for something uh let's search for
- 2:08:34Android and search also works perfectly
- 2:08:37and even
- 2:08:39sorting and Parn sorting all these
- 2:08:42things are working as they should work
- 2:08:45now let's start working on product crud
- 2:08:48which is going to be added for the
- 2:08:51vendor users not for the admin user so
- 2:08:54actually I think we can sign out and we
- 2:08:58can log in as vendor
- 2:09:01user vendor example.com
- 2:09:05okay here we go now let me
- 2:09:11execute PHP
- 2:09:14artisan make
- 2:09:18model product with migration and I think
- 2:09:22we will need controller as well on the
- 2:09:24front end side and that controller
- 2:09:26should be uh should have um listing of
- 2:09:29the products um should it be resource No
- 2:09:33it should not be resource controllers
- 2:09:34we're going to only have listing of the
- 2:09:36products nothing else but we need
- 2:09:38controller so I think we are good I'm
- 2:09:41going to hit the
- 2:09:43enter okay so the model the migration
- 2:09:47and the controller was generated I'm
- 2:09:49going to also generate enam PHP artisan
- 2:09:54make enam let's call this product status
- 2:09:59Anam and I'm going to put this inside
- 2:10:02anam's
- 2:10:04folder so I'm going to specify name
- 2:10:06space as well we are going to hit the
- 2:10:09enter and finally we are going to
- 2:10:12execute PHP artisan
- 2:10:15make um
- 2:10:17filament resource and we're going to
- 2:10:20provide
- 2:10:22product here okay I'm going to hit the
- 2:10:24enter the product resource was
- 2:10:28generated now let's open migration file
- 2:10:32create products table and Define couple
- 2:10:35of fields so first we need to define the
- 2:10:38title with the length of 2,000 I'm going
- 2:10:41to Define slug as well and then I'm
- 2:10:44going to Define long text description we
- 2:10:47need foring ID to Department to
- 2:10:50Department table and to call the column
- 2:10:51foring idid I'm going to Define index on
- 2:10:54that as well and it must be constrained
- 2:10:56on departments in the same way we're
- 2:10:58going to Define category ID with index
- 2:11:01and with constraint next I'm going to
- 2:11:04Define price field with total 20 and
- 2:11:06places four I'm going to Define string
- 2:11:10which is going to be status and I'm
- 2:11:13going to Define also quantity here and
- 2:11:16uh I'm going to Define created by and
- 2:11:19updated by which be the user who created
- 2:11:23or modified this specific product in
- 2:11:26most cases or in all cases in
- 2:11:28specific in our specific project created
- 2:11:31by and updated by is going to be the
- 2:11:33same so this is going to be the vendor
- 2:11:35but if you want to improve this in the
- 2:11:37future and add also ability that vendor
- 2:11:39users give possibility to add other
- 2:11:43users to manage their stock then created
- 2:11:47by and updated by might be actually
- 2:11:50different okay so we also need to add
- 2:11:54deleted at which is going to be nullable
- 2:11:57Tim stamp and we are going to add I
- 2:12:00think yeah that's it so we're going to
- 2:12:02import now user model because we are
- 2:12:05using that user model and we are done on
- 2:12:07the migration side now let's open
- 2:12:10product status ANM and right here I'm
- 2:12:14going to give it the type of string and
- 2:12:16Define two cases draft and published and
- 2:12:20then I'm going to Define two function
- 2:12:21functions one for labels second for
- 2:12:23colors inside labels we're going to
- 2:12:25return an associative array we are draft
- 2:12:28key corresponds to draft and published
- 2:12:31corresponds to published and the same
- 2:12:33way we are going to Define
- 2:12:36colors where uh gray color corresponds
- 2:12:39to draft value and success uh color
- 2:12:42corresponds to published value so here
- 2:12:44we are using this underscore underscore
- 2:12:46function which is for internalization
- 2:12:49for translating these texts so we are
- 2:12:52not actually building our project uh
- 2:12:55translatable and I'm not going to
- 2:12:57implement anything related to
- 2:12:59translations but having these underscore
- 2:13:02uncore functions right here doesn't Hur
- 2:13:05it so if in the future you decide that
- 2:13:08you want to implement translations you
- 2:13:09know that you don't have to find all the
- 2:13:11places where we have written strings and
- 2:13:16we can just use this underscore uncore
- 2:13:18parenthesis I know probably I am not
- 2:13:20using this underscore
- 2:13:22underscore function in every place where
- 2:13:25I should be using but that's only
- 2:13:27because I am not actually implementing
- 2:13:29translations but in the places where it
- 2:13:31is already used you don't need to touch
- 2:13:33it and you can just directly activate
- 2:13:35translations if you want that in the
- 2:13:37future okay so we Define the status and
- 2:13:41next is to
- 2:13:43open a product
- 2:13:46model and right here I want to Define um
- 2:13:50two Rel ation uh both of them will be
- 2:13:52belongs to so belongs to category so
- 2:13:55product belongs to category we're going
- 2:13:57to use category class here and second or
- 2:14:00maybe first we should have Department in
- 2:14:03then category because department is kind
- 2:14:05of apperent of the category as well now
- 2:14:08belongs to so this is just my personal
- 2:14:10preference of course you can have
- 2:14:12category first and Department second um
- 2:14:16department and here we need Department
- 2:14:20class okay cool and finally we're going
- 2:14:23to open product
- 2:14:25resource and right here in the um
- 2:14:28columns and in the uh form section we
- 2:14:31are going to Define some of the fields
- 2:14:34let's start with
- 2:14:35the with the forms and first we're going
- 2:14:38to um Define a title text input uh for
- 2:14:42title we're going to listen to its
- 2:14:45change on blur basically we uh first it
- 2:14:49needs to be required but we're going to
- 2:14:51listen to on blar and whenever the state
- 2:14:53is changed we are going to update slug
- 2:14:57as well so we will import this St class
- 2:15:00in a moment so text input similar to
- 2:15:03what we did for the Departments we have
- 2:15:05text input whenever it changes we update
- 2:15:07the slack next we're going to define the
- 2:15:09slack which needs to be required we're
- 2:15:11going to Define Department ID and we are
- 2:15:13going to associate that field into
- 2:15:16Department relation with the and we're
- 2:15:19going to use this name field to display
- 2:15:23departments in this drop-down okay we're
- 2:15:26going to give it also label Department
- 2:15:28which is going to be translatable we're
- 2:15:29going to give it a preload so all the
- 2:15:31Departments will be preloaded it is
- 2:15:33going to be searchable and it's going to
- 2:15:35be required okay it's going to be also
- 2:15:38reactive to make um to um adapt some
- 2:15:42changes on um on that and whenever the
- 2:15:45department is changed this is why we
- 2:15:46need reactive whenever the department is
- 2:15:49changed we are going to
- 2:15:51set the category ID to be null whenever
- 2:15:54we choose something if the category is
- 2:15:55already set we're going to reset the
- 2:15:57category
- 2:15:59okay uh now let's define the category
- 2:16:03field the category field has a
- 2:16:05relationship uh similar to how
- 2:16:07department has relationship but it has
- 2:16:09slightly more complex relationship so um
- 2:16:12the name of the relation is category and
- 2:16:15the title attribute is name however we
- 2:16:17need to modify the query as well so we
- 2:16:20only want to those categories which are
- 2:16:22for the selected
- 2:16:24department for this we are going to get
- 2:16:27the Department first using this uh
- 2:16:30callable get okay so we get the
- 2:16:33Department then we check if the
- 2:16:35department exists we are going to write
- 2:16:38the following we we Department ID is the
- 2:16:40selected Department ID and that
- 2:16:43basically filters categories based on
- 2:16:45the department all right so next we need
- 2:16:48to associate label to it category we're
- 2:16:51going to preload all the categories
- 2:16:53we're going to make it searchable and
- 2:16:54required as well and after this
- 2:16:58basically which
- 2:17:00is um the following
- 2:17:05greed okay so after this grid down
- 2:17:11below we are going to Define reach
- 2:17:13editor okay so which needs to be for the
- 2:17:17description field which needs to be
- 2:17:18required it's it's it's going to have
- 2:17:21column spun for two it's going to be
- 2:17:22stretch on two columns and we're going
- 2:17:25to customize the toolbar buttons as well
- 2:17:27so we're going to have the following
- 2:17:28buttons block quote bold buet bullet
- 2:17:32list H2 H3 italic link order list redo
- 2:17:35strike underline undo and table okay and
- 2:17:39then we're going to Define price which
- 2:17:41is going to be numeric Fielder required
- 2:17:43quantity which is going to be integer
- 2:17:46status which is going to have the um
- 2:17:49options from the product status enm
- 2:17:52we're going to import all these
- 2:18:20input and then we're going to inut this
- 2:18:23product status in um as well okay so I
- 2:18:27think we don't have anything that is not
- 2:18:30imported okay now we're going to save
- 2:18:33this and let's refresh it and as you see
- 2:18:37right here we have the products if we
- 2:18:39click on the
- 2:18:41products uh okay the products table is
- 2:18:43not created so we're going to execute
- 2:18:47migration PHP Artisan migrate hit the
- 2:18:49enter that was executed good refresh the
- 2:18:53page and now we see the products empty
- 2:18:56table and if we click on this um a
- 2:18:59product now this gives us the following
- 2:19:02form we have title slug Department
- 2:19:05category we have some description price
- 2:19:07quantity and
- 2:19:09status now let's try to create our first
- 2:19:13product first product the slack should
- 2:19:16be generated we're going to choose the
- 2:19:19department to be Electronics
- 2:19:21uh we see all the elect Electronics um
- 2:19:24categories I'm going to choose computers
- 2:19:27some test
- 2:19:28description let's give it some price I'm
- 2:19:32going to leave the quantity empty and
- 2:19:34click on
- 2:19:36Create and we have the following problem
- 2:19:38so the created by is actually required
- 2:19:41field in the database but we didn't
- 2:19:43provide anything so to fix this we are
- 2:19:46going to open
- 2:19:50filament resources product resource
- 2:19:53create product and right here we need to
- 2:19:56override method mutate form data before
- 2:20:01create and we have the data here and
- 2:20:04inside the data we are going to put
- 2:20:07updated by
- 2:20:09equals um out ID and created by equals
- 2:20:14Al
- 2:20:16ID and finally we are going to return
- 2:20:20that data from here and if we try now
- 2:20:25retry to create new
- 2:20:28product created so we see that the
- 2:20:30product was created we see right now
- 2:20:32product edit page and we can check this
- 2:20:35in the database as well refresh the
- 2:20:37database we see products click on this
- 2:20:40and we see this single product that was
- 2:20:42already created in the database okay so
- 2:20:46if we want to restrict access to the
- 2:20:49products page only for uh vendor users
- 2:20:53now we can add right here can view any
- 2:20:57similar to how we have for Department
- 2:21:01resource can view any but the thing is
- 2:21:05that product resources is used only
- 2:21:07inside filament admin inside filament
- 2:21:10admin only two role users can access
- 2:21:12admin user and vendor user if we add
- 2:21:15right here can view any for vendor Ro it
- 2:21:19means that the admin user is not able to
- 2:21:22view products which kind of makes sense
- 2:21:25so it really depends how you want do you
- 2:21:27want admin users to create new products
- 2:21:29or not if you want to create admin users
- 2:21:33new products then you should not put
- 2:21:36this but I'm going to actually put this
- 2:21:38so admin users will do the admin side
- 2:21:41and um vendor users will do vendor
- 2:21:44related things so I'm going to put a
- 2:21:46vendor here which means that admin users
- 2:21:48will not be able to see this products
- 2:21:50menu item okay so that's fine um next we
- 2:21:56are going to see the product listing and
- 2:21:58we're going to display some of the
- 2:22:00information from the products
- 2:22:03table now in the table function in the
- 2:22:07columns area let's define some of the
- 2:22:09columns like we need Title and we're
- 2:22:12going to make this title sortable but
- 2:22:14we're going to take only first 10 words
- 2:22:16from the title we don't want the entire
- 2:22:18title let's make this searchable in and
- 2:22:21um yeah that's it the second field is
- 2:22:23going to be status uh we're going to
- 2:22:26activate uh page we're going to make
- 2:22:28this status column as bable so call it
- 2:22:32so and the following colors will be used
- 2:22:34to display bed padges um then we're
- 2:22:39going to display Department name and
- 2:22:42category name as well and we're going to
- 2:22:44display created that um as a daytime
- 2:22:47format so if I save this right now
- 2:22:51and refresh it this is how it looks like
- 2:22:55okay so I think the next step will be to
- 2:22:59start working on images for the products
- 2:23:02and variations so we have this create of
- 2:23:06the product typical crud is actually
- 2:23:09done uh let's turn this into
- 2:23:13published go into products and we see
- 2:23:17publish right
- 2:23:18here okay good
- 2:23:21uh I think we can also add some of the
- 2:23:23filters to this
- 2:23:26so here I'm going to use select filter
- 2:23:30for status and we're going to provide
- 2:23:33options that will be product status andm
- 2:23:37labels second is going to be select
- 2:23:39filer for Department ID and I'm going to
- 2:23:42Define relationship with Department name
- 2:23:46so if I save this and refresh it right
- 2:23:48here we see this filtering section and I
- 2:23:50can filter draft items it chose empty or
- 2:23:55published items it chose this one or all
- 2:23:58it chose all of them and we can also
- 2:24:00filter them by Department like I want to
- 2:24:02find books and audible or Electronics
- 2:24:05which finds something fashion and so so
- 2:24:08we have this nice filtering section as
- 2:24:10well for images and uploading images on
- 2:24:13the product we are going to use another
- 2:24:16spatius package or spatius another
- 2:24:19package um and this is media library or
- 2:24:24can search this spati
- 2:24:27m media library and I want the filament
- 2:24:32version of it because we are actually
- 2:24:34using filament and I want to use this
- 2:24:36inside
- 2:24:37filament okay so the idea of this
- 2:24:40filament this partty media library is
- 2:24:43that it creates polymorphic tables in
- 2:24:48the database and you can implement image
- 2:24:51or basically media upload on any table
- 2:24:54on any um any records okay and this is
- 2:24:59how simple is that so let's go ahead and
- 2:25:02install this P media library plug-in so
- 2:25:05I'm going to copy
- 2:25:07this let's bring up the terminal and I'm
- 2:25:10going to
- 2:25:13hit actually uh let me comment
- 2:25:17everything while this is being installed
- 2:25:21in composer Json we have the spum media
- 2:25:23library so this is the case when I don't
- 2:25:24want this to be included because I'm
- 2:25:27actually committing the previous changes
- 2:25:28I made so
- 2:25:33Implement
- 2:25:35Implement product
- 2:25:39Rod okay let's click on
- 2:25:43comit now we have two
- 2:25:45changes let's close everything that was
- 2:25:49installed
- 2:25:51next uh we have to
- 2:25:55publish migration
- 2:26:01files okay so it's publish this
- 2:26:05migration file and we can have a look
- 2:26:07inside this create media
- 2:26:10table create media table and look at
- 2:26:14this so it has this morphs type of
- 2:26:17column on model so it has the uid it has
- 2:26:21the collection name um and basically
- 2:26:24let's go ahead and implement the file
- 2:26:27upload and then when there is a record
- 2:26:29already inserted in the table then it
- 2:26:32will make um much more
- 2:26:35sense so that's pretty powerful Library
- 2:26:38actually so now we're going to execute
- 2:26:39PHP Artisan
- 2:26:44migrate okay the tables we are created
- 2:26:47we can see that media table right here
- 2:26:52awesome okay um we can close this and
- 2:26:55now I'm going to
- 2:26:56open product resource and I'm going to
- 2:27:00create subnavigation um inside that
- 2:27:04resource so maybe here after Pages I'm
- 2:27:08going to add um get record sub
- 2:27:12navigation I'm going to overwrite that
- 2:27:14method
- 2:27:18basically and on that page page we have
- 2:27:21the page here on that page I'm going to
- 2:27:24generate navigation items okay and I'm
- 2:27:27going to have a few items one is going
- 2:27:29to be edit
- 2:27:31product uh edit
- 2:27:35product class this is going to be one
- 2:27:38and we are going to import that edit
- 2:27:41product which is filament edit page we
- 2:27:44can go ahead this edit product and this
- 2:27:48extends edit record
- 2:27:51okay so this is one now if we save this
- 2:27:54and have a look in the
- 2:27:56browser uh and if we click on the
- 2:28:01product okay argument
- 2:28:07one oh sorry I should directly return
- 2:28:10this generate um navigation
- 2:28:14items refresh the page okay now we see
- 2:28:18that the uh sub sub navigation is right
- 2:28:21here on the left so we're going to add
- 2:28:24um more subnavigation
- 2:28:28items first let's scroll up and I'm
- 2:28:31going to change the subnavigation
- 2:28:34position subnavigation position is going
- 2:28:37to be sub navigation position end so we
- 2:28:42want that on the right side rather than
- 2:28:46on the left side
- 2:28:50now similar to edit product I want to
- 2:28:54create another page which extends edit
- 2:28:58record and this is going to be for
- 2:29:02images so let me duplicate this edit
- 2:29:06product and I'm going to call this
- 2:29:09product
- 2:29:12images okay now here we can
- 2:29:16Define
- 2:29:18form and we are going to return um some
- 2:29:23of the fields let's open this product
- 2:29:33resource okay in here I want to use now
- 2:29:36this spatty media library
- 2:29:39to return and render these fields and
- 2:29:42the field is called this the the class
- 2:29:45name is spati Media
- 2:29:48Library by file upload okay let's take
- 2:29:55this and put this right here we are
- 2:29:59going to import that however
- 2:30:03that should be on images we don't have
- 2:30:08Avatar I'm going to change this into
- 2:30:10images and then we're going to add a
- 2:30:13couple of methods like this is going to
- 2:30:16be image uh multiple
- 2:30:20we're going to uh give it also openable
- 2:30:23so that each image can be opened we're
- 2:30:25going to give it panel layout to be
- 2:30:30grid let's give it uh the images should
- 2:30:33be saved inside the collection called
- 2:30:36images that collection is a column name
- 2:30:38in this media table we're going to add
- 2:30:41Also
- 2:30:44reorderable let's give it also upend
- 2:30:46files because every new file is added uh
- 2:30:49as a first first file so we want new
- 2:30:51files to be at the bottom and we're
- 2:30:54going to give it preserve preserve file
- 2:30:57names and also let's give it column span
- 2:31:01to be
- 2:31:02to now we're going to open this product
- 2:31:06resource and scroll down below find
- 2:31:11this get pages and we are going to add
- 2:31:15right here
- 2:31:18images from Pages we're going to access
- 2:31:22product
- 2:31:24images and let's define the road this is
- 2:31:27going to be record images and in
- 2:31:29subnavigation we're going to also Define
- 2:31:33product images now if we save
- 2:31:36that and have a look now we see this
- 2:31:40product images obviously we can change
- 2:31:41this um image icon but when we click on
- 2:31:46this let's have a look
- 2:31:51yeah okay the model should um should
- 2:31:55Implement should extend should use sorry
- 2:31:58should use this has media trait and
- 2:32:00let's check the documentation for this
- 2:32:03okay so this is how we
- 2:32:07can this is something specific
- 2:32:10to filament what we are interested
- 2:32:14in spoty Media Library without filament
- 2:32:21let's check
- 2:32:24this click on base installation so we're
- 2:32:28going to require that we published that
- 2:32:29we execute
- 2:32:31migrations um the publishing the config
- 2:32:33find is optional scroll down
- 2:32:40below this is also optional yeah then we
- 2:32:44need to set up the queue which we will
- 2:32:46do for the image manipulation such as
- 2:32:49the conversion
- 2:32:50or generating different um variations of
- 2:32:54the image small thumbnail and so
- 2:32:57on uh but what I'm interested
- 2:33:01is preparing your modu basic usage okay
- 2:33:05so we are going to implement an
- 2:33:07interface as media and usually trade
- 2:33:09interacts with media so let's open
- 2:33:13product.php product.php
- 2:33:19P why it finds that okay and this
- 2:33:24implements has
- 2:33:26media and it uses interacts with media
- 2:33:32okay now if we refresh the page we see
- 2:33:36the drag and drop section for images I'm
- 2:33:39going to click on this browse and I'm
- 2:33:41going to choose three images click on
- 2:33:43open the images have been dropped here
- 2:33:47they were uploaded
- 2:33:50and click on Save changes that was saved
- 2:33:53but let's have a look what else do we
- 2:33:55need so here we have this register media
- 2:33:57conversions so this is for to generate
- 2:34:00different conversions for the
- 2:34:03media how to associate the
- 2:34:06files how how we can
- 2:34:09access um how we can add new files how
- 2:34:13we can access these new files okay this
- 2:34:16is what I'm going to do I'm going to
- 2:34:17open the media and have a look so we
- 2:34:19have three
- 2:34:20images here model ID this is the
- 2:34:25collection this is the file name this is
- 2:34:28the collection name we have the mime
- 2:34:31type we have the disk and we have the uh
- 2:34:35conversions disk and we're going to find
- 2:34:37those images
- 2:34:39into storage up public and we see one
- 2:34:44two and
- 2:34:47three this is good
- 2:34:52now let's open this product model again
- 2:34:54and we are going to register media
- 2:34:57conversions for uh different resolutions
- 2:35:00so
- 2:35:02register
- 2:35:04media uh
- 2:35:06conversions okay and we accept right
- 2:35:09here
- 2:35:10media which we don't need I think so on
- 2:35:14this a media conversion uh we're going
- 2:35:17to give it name this conversion is
- 2:35:19thumbnail and let's give it width and
- 2:35:21the width is going to be 100 for
- 2:35:24thumbnail okay this is one conversion we
- 2:35:27registered second is going to be
- 2:35:31small let's give it width of
- 2:35:3548 for different screen resolutions and
- 2:35:39then we are going to have
- 2:35:43large which is going to
- 2:35:46be 1,200 okay and and we're going to
- 2:35:50also have original which will be the
- 2:35:52very large uh and we have now four
- 2:35:56resolutions for each image and we have
- 2:35:59to also start Q otherwise these images
- 2:36:02will not be processed because these
- 2:36:03images are actually processed inside the
- 2:36:05Q but before I activate the Q we're
- 2:36:09going to see the result without Q as
- 2:36:13well now let's
- 2:36:17delete those files
- 2:36:20and click save now let's choose them
- 2:36:26again uh in the database we can see that
- 2:36:29there are no data because we deleted
- 2:36:31that and click on Save changes that was
- 2:36:34saved on the file system we see four
- 2:36:37five and six as you see and right here
- 2:36:41we see these three items okay and if we
- 2:36:45expand this four five and six we only
- 2:36:47see one image for each okay now let's
- 2:36:50start
- 2:36:52Q I'm going to bring up the
- 2:36:55terminal so this is white this is
- 2:36:57Artisan inside
- 2:37:00Artisan let's call this
- 2:37:03Q PHP
- 2:37:06Artisan Q
- 2:37:10listen okay now it started
- 2:37:13processing perform conversion jobs it is
- 2:37:17doing this processing it has completed
- 2:37:21that and if we have a
- 2:37:23look right here look at this so we have
- 2:37:27these generated conversions right now we
- 2:37:30have thumbnail small and large
- 2:37:33conversions generated and if we check
- 2:37:35file system storage up public for we see
- 2:37:40the original one as well as the
- 2:37:42conversions three different resolution
- 2:37:44this is large this is small this is
- 2:37:47thumbnail okay so we have different um
- 2:37:50conversions already registered now what
- 2:37:53I want to change is this path so here we
- 2:37:57have the ID and we want to customize
- 2:38:00this for
- 2:38:02this uh I want to publish config
- 2:38:06file let's come right here go
- 2:38:10back go
- 2:38:14back okay this is the part I want to
- 2:38:17copy Media Library config this is what I
- 2:38:20want to publish so this is Q which is
- 2:38:23running I'm going to open another
- 2:38:24terminal where I can put this right here
- 2:38:26hit the enter the config file media Li
- 2:38:30media library config file was published
- 2:38:33now let's open this and find path uh
- 2:38:40generator this one path generator which
- 2:38:43uses um from this py media library
- 2:38:47default path generator okay so what I
- 2:38:51want to do is to create new class maybe
- 2:38:56inside um app Services let's
- 2:39:00define new
- 2:39:02folder services and then inside here I
- 2:39:06want to create new class custom path
- 2:39:11generator and I think this might be also
- 2:39:13mentioned in the documentation somewhere
- 2:39:15I previously found that um in the
- 2:39:18documentation or there was a video maybe
- 2:39:20about this this should implements path
- 2:39:22generator from SP media library okay
- 2:39:26cool and we have to implement these
- 2:39:28methods okay three methods get path get
- 2:39:33path uh for conversions and get path for
- 2:39:36responsive media okay so
- 2:39:40now let's
- 2:39:42return we're going to take the media uh
- 2:39:45media
- 2:39:46ID which is going to be one two three
- 2:39:50and sequential number and we're going to
- 2:39:52concatenate this with the
- 2:39:55config of applications key and we are
- 2:40:01going to
- 2:40:02create md5 out of
- 2:40:06it and then we're going to add slash now
- 2:40:10let's copy these path
- 2:40:13generated and here we need convergence
- 2:40:21and here we need
- 2:40:24responsive
- 2:40:27images cool and we're going to use this
- 2:40:30C custom path generator right now in
- 2:40:33this media library instead of this so
- 2:40:37let's call this custom path
- 2:40:41generator cool now let me delete these
- 2:40:48files and
- 2:40:51again click on Save they must be deleted
- 2:40:55from the file
- 2:40:59system they were deleted from here maybe
- 2:41:02because we Chang this
- 2:41:05um custom path
- 2:41:08generator yeah they stayed here anyway
- 2:41:10we can delete them manually they will
- 2:41:12not stay in the future now we can upload
- 2:41:16these three images again
- 2:41:24Okay click on Save the que is there it
- 2:41:28is working it is going to catch and
- 2:41:34process and here we see now this random
- 2:41:38uh
- 2:41:39md5 names okay so and here we
- 2:41:43have I think I missed slash
- 2:41:50extra slash
- 2:41:52here and
- 2:41:56here okay again we can delete them by
- 2:42:00hand we can delete these from the file
- 2:42:14system it is being uploaded click on
- 2:42:17Save
- 2:42:19and here we see now the conversions are
- 2:42:22not yet generated now we see
- 2:42:25them okay awesome and now the thing is
- 2:42:30that how we can access those images and
- 2:42:34for example display in the product
- 2:42:36listing right here we want the thumbnail
- 2:42:39to be displayed here as
- 2:42:41well let's open product resource and
- 2:42:46find table section and right here we are
- 2:42:49going to use
- 2:42:51spaty uh media
- 2:42:56library why does not
- 2:42:59autocomplete
- 2:43:07spoty okay uh let me check this in the
- 2:43:11documentation it should be out to
- 2:43:12complete it Sparty media
- 2:43:17library um image column and just like
- 2:43:22this we need
- 2:43:24to get it and put this right here
- 2:43:28however
- 2:43:30the that should be for images we're
- 2:43:32going to give it
- 2:43:35also
- 2:43:37collection for images put a comma here
- 2:43:42let's import this P media library it was
- 2:43:45imported Okay cool so we're going to
- 2:43:47take only first so we're going to call
- 2:43:49limit one and we also want uh
- 2:43:53conversion uh thumbnail okay thumb now
- 2:43:58we save
- 2:43:59this and have a look here and we see
- 2:44:03from many images we can give it also
- 2:44:06label label to be
- 2:44:10image so we see an image right here if
- 2:44:13we click on this and click on product
- 2:44:15images we can change the ordering like
- 2:44:18we can move this black want of the first
- 2:44:19one click on Save changes and that will
- 2:44:22be updated in the database as well and
- 2:44:25if we click on the product listing now
- 2:44:27we see Blake right here okay uh in the
- 2:44:31database we
- 2:44:33see order column right here which
- 2:44:36defines the ordering for
- 2:44:39that okay so we have product editing we
- 2:44:43have a product images and I want to
- 2:44:45change this icon right now
- 2:44:49and that icon is used in the product
- 2:44:54images uh because this is for edit
- 2:44:58record this one has the view and
- 2:45:02Navigation icon as
- 2:45:04well and this icon is actually coming
- 2:45:08from it's a hero icon o pencil square
- 2:45:13right so we have to override this
- 2:45:16Navigation icon
- 2:45:19Navigation icon equals to something
- 2:45:22let's give it hero icon o collection and
- 2:45:25have a
- 2:45:29look SVG by name O collection from set
- 2:45:32not found okay so this is the thing so
- 2:45:35filament PHP is
- 2:45:39using set of icons and I want to find
- 2:45:44this right now
- 2:45:49uh let's check this in the package lock
- 2:45:54um it is using this blade UI kit and
- 2:45:59blade hero
- 2:46:00icons so if we check right now what is
- 2:46:03blade UI kit it is using only hero icons
- 2:46:06at the moment I think it is not using
- 2:46:10blade UI kit so it is not using any
- 2:46:13other things from this play UI kit right
- 2:46:20it is using it is only using uh it is
- 2:46:23using blade icons as
- 2:46:28well blade
- 2:46:30icons and blade hero icons so this is
- 2:46:34one two one one blade
- 2:46:39icons okay so if we check these blade UI
- 2:46:42icons we are going to see that this is a
- 2:46:46huge list of
- 2:46:51I want to find those icons huge list of
- 2:46:55icons okay and this is a hero icon
- 2:46:58example we can search for icons we see
- 2:47:02more than 100,000 icons and if we search
- 2:47:06for uh blade icons or if we search for
- 2:47:10hero
- 2:47:11icons that's it now we can filter inside
- 2:47:15the hero icon list if we search for
- 2:47:17image
- 2:47:19uh it is not there uh
- 2:47:22picture or photo maybe now we find this
- 2:47:27okay we can take this
- 2:47:30one which is hero icon C photo and this
- 2:47:35is coming from these blade hero icons so
- 2:47:38if you don't have these blade hero icons
- 2:47:40installed in the project this is not
- 2:47:42going to work if you have it it is going
- 2:47:44to work so we're going to copy this hero
- 2:47:46icon C photo open this product
- 2:47:50images and paste this here
- 2:47:54save refresh it and now we see product
- 2:47:57images icon right here I think we can
- 2:48:00change this uh product listing as
- 2:48:06well uh maybe we can use some
- 2:48:08list or
- 2:48:11product not sure let's take this one
- 2:48:15here ion s Square list let's get this
- 2:48:19and it is going to be inserted inside
- 2:48:22product
- 2:48:26resource
- 2:48:29okay refresh the page now this was
- 2:48:32updated this was
- 2:48:34updated and to talk a little bit
- 2:48:37of uh spy media library as well I'm
- 2:48:40going to open the table and have a look
- 2:48:42so we see that this is a polymorphic
- 2:48:44table and we have the following column
- 2:48:48for the mode type and mod ID we have
- 2:48:50this uh U ID also Associated to each
- 2:48:53image we have the collection name which
- 2:48:55is something we gave when we tried to
- 2:48:58upload images inside this product images
- 2:49:01right here we give it collection of
- 2:49:03images and we have the name which is are
- 2:49:06the which are the original names we have
- 2:49:08the file names as well M type disk where
- 2:49:11those files are located and the media
- 2:49:13library also supports multiple discs you
- 2:49:15can upload them on S3 or any other dis
- 2:49:18you want and we have the conversion dis
- 2:49:21this is also possible you can have the
- 2:49:23original images saved in one dis but the
- 2:49:25conversions into another disk we have
- 2:49:27the size we can have additional
- 2:49:30manipulations like add Watermark to the
- 2:49:34images and save them as additional
- 2:49:36things and so on we can also generate um
- 2:49:40responsive variants for those images and
- 2:49:43this is also possible right here they
- 2:49:45will be saved right here we have the
- 2:49:46order column created and up dated it we
- 2:49:49are not going to use every single um
- 2:49:52feature of this media library but what
- 2:49:54we are using is quite good enough we
- 2:49:56have the que started we generate the
- 2:49:58conversions and we're going to use
- 2:49:59different images different conversions
- 2:50:02for different um in different cases in
- 2:50:05our project quick puse if you're
- 2:50:07watching this follow with me and if
- 2:50:10you're enjoying this please leave a like
- 2:50:13And subscribe now I'm going to start
- 2:50:15working on product variations and this
- 2:50:18is one of the most exciting thing for me
- 2:50:22personally okay and also it's a quite
- 2:50:24challenging compared to what we did so
- 2:50:26far now first I'm going to create three
- 2:50:30models PHP artisan make model one of
- 2:50:34them is going to be
- 2:50:37variation type variation type model uh
- 2:50:41and I'm not going to generate migration
- 2:50:43for that so it's just model variation
- 2:50:47type we hit the ENT enter next I'm going
- 2:50:50to generate second model which is going
- 2:50:52to be variation type option variation
- 2:50:56type has options okay I'm just going to
- 2:51:00generate model again and then I'm going
- 2:51:03to generate uh product variation and I'm
- 2:51:06going to generate
- 2:51:08migration for it as well and I'm going
- 2:51:10to put inside that single migration file
- 2:51:15all three tables related to product
- 2:51:18variation
- 2:51:20right
- 2:51:22here okay now let's define on table we
- 2:51:26have foring ID on the product it has
- 2:51:31constrained to
- 2:51:34products and we can add also index to
- 2:51:40it and we're going to make this also
- 2:51:43nullable not nullable sorry um Cascade
- 2:51:47on delete
- 2:51:49okay whenever product is deleted its
- 2:51:52variation types should be also deleted
- 2:51:56next is to Define string which is going
- 2:52:00to be the variation type name and I'm
- 2:52:03going to also define variation um type
- 2:52:09type so variation type might
- 2:52:13be sorry so this is going to be
- 2:52:17variation
- 2:52:19types okay variation type might be color
- 2:52:23size as an example uh and color will
- 2:52:28have a type of image and we're going to
- 2:52:31have different images for different
- 2:52:35colors well we might not have but we we
- 2:52:38are going to implement support it's up
- 2:52:40to wonder if they upload different
- 2:52:42images for different colors or not but
- 2:52:43we actually is going to give them
- 2:52:46possibility to upload different images
- 2:52:48for different
- 2:52:50colors if the variation type is for
- 2:52:52example radio we're going to just have
- 2:52:55um simply radio type of options and I
- 2:52:59think the best example um is um
- 2:53:03Amazon
- 2:53:05amazon.com so if we can access this I
- 2:53:08will show you exactly what I mean
- 2:53:13tfj now if we choose any of the dress
- 2:53:19so now we have a size which is in this
- 2:53:22case select type of variation and we
- 2:53:26have color color is different variation
- 2:53:29and we see that we have different images
- 2:53:32for different colors okay so in this
- 2:53:35case the size is has type of Select
- 2:53:38color has type of image so this is
- 2:53:41something like this we're going to do
- 2:53:43okay next let me actually copy this two
- 2:53:50times okay and next is going to be
- 2:53:53variation type options okay so this has
- 2:53:59foreign key on variation type
- 2:54:03ID uh we can give it index uh
- 2:54:06constrainted
- 2:54:07on variation types and Cascade on delete
- 2:54:11also works here whenever uh variation
- 2:54:14type is deleted the variation type
- 2:54:16options should also be deleted deleted
- 2:54:19and we're going to have just the name of
- 2:54:21this variation type option and I'm going
- 2:54:24to delete the type and we also don't
- 2:54:26need time stamp here and here so if the
- 2:54:29variation type is color then the name
- 2:54:32right here will be black what about
- 2:54:35images so we're going to do images using
- 2:54:38spaty media library again and we have
- 2:54:41this table ready it's a polymorphic
- 2:54:43table and we're going to Simply
- 2:54:45associate that to the option model we're
- 2:54:48going to do
- 2:54:49this and finally we have this um
- 2:54:53product
- 2:54:55variations and we're going to have let
- 2:54:58me remove these
- 2:55:00fields so we are going to have um foring
- 2:55:05ID on
- 2:55:07product okay this product we can give it
- 2:55:11again index
- 2:55:14and constraint on products
- 2:55:18move this
- 2:55:21down and we can give it also Cascade on
- 2:55:24delete
- 2:55:26okay however we are going to all add one
- 2:55:30Json
- 2:55:32field which is going to be uh
- 2:55:36variation
- 2:55:39variation uh
- 2:55:41type option
- 2:55:44IDs okay this is how I'm going to call
- 2:55:46this and that actually should be
- 2:55:50required so I'm just going to make it
- 2:55:51nullable and I will explain what that
- 2:55:54table will contain
- 2:55:57additionally for each variation type so
- 2:56:01okay let me try to explain it so now we
- 2:56:03have defined let's say two variations we
- 2:56:06we have defined two variation types so
- 2:56:10um size and color okay and we have I'm
- 2:56:15going to open text file we Define two
- 2:56:18variation types size and color okay and
- 2:56:23we defined options for each of them like
- 2:56:25size is small we have medium and we have
- 2:56:30large and we also defined three
- 2:56:33different colors or let's say two
- 2:56:35different colors for Simplicity okay red
- 2:56:38and
- 2:56:39white okay now we have six combinations
- 2:56:43of these products right so we have small
- 2:56:48small red we
- 2:56:51have
- 2:56:53small uh White we have medium red okay
- 2:56:57you get the idea okay I'm just going to
- 2:56:59um simply leave only medium and small
- 2:57:02and then we're going to duplicate this
- 2:57:04and here we need medium and for each
- 2:57:08each variation is a different type of
- 2:57:11product and we need quantity and maybe
- 2:57:15price Associated to it like this will
- 2:57:18have quantity of 10 and price 15 is an
- 2:57:21example so this will have quantity of 10
- 2:57:23but price is 13 um and so on so for
- 2:57:29each um so right here in this product
- 2:57:33variations
- 2:57:35table let's say that this is the product
- 2:57:38variations
- 2:57:40table so here we're going to have
- 2:57:43information in the following format
- 2:57:45obviously we're going to have the ID
- 2:57:47primary key then we're going to have the
- 2:57:49product ID okay product
- 2:57:52first okay uh product first then
- 2:57:57quantity 10 price is going to be 15 and
- 2:58:02then we're going to have the variation
- 2:58:04types uh variation type options more
- 2:58:07specifically so we have four options
- 2:58:10defined two for uh the size variation
- 2:58:13type two for color and each of them will
- 2:58:16have their own ID right right uh here
- 2:58:19we're going to have two three and four
- 2:58:24okay and in this product variations
- 2:58:27table this is the primary key we can
- 2:58:29omit
- 2:58:30this first product 10 quantity uh 15
- 2:58:35price and for the following variations
- 2:58:38and that variations will be small red so
- 2:58:42here will be written one and
- 2:58:45three and now product
- 2:58:49One Price 10 uh sorry quantity 10 price
- 2:58:54uh we can give it this is product ID
- 2:58:58then we have quantity then we have price
- 2:59:03then we have
- 2:59:05variations
- 2:59:09now this is
- 2:59:13it this is
- 2:59:16quantity this is price
- 2:59:21and this is product
- 2:59:24variations and here we're going to have
- 2:59:27variation of one and four small and
- 2:59:33white and just like this for each
- 2:59:37product if we Define prices and
- 2:59:40quantities for each variation we're
- 2:59:42going to have in this case four records
- 2:59:45in the product
- 2:59:47variations I hope this makes sense
- 2:59:49that's why we Define this variation type
- 2:59:52option IDs to be Json and we need to
- 2:59:55Define um integer quantity which can be
- 3:00:02nullable I guess and we're going to
- 3:00:08Define
- 3:00:10um decimal price if it's null it means
- 3:00:13that um we're going to pick up the
- 3:00:15default quantity or it should not be
- 3:00:17null in my op opinion so if we Define
- 3:00:19the
- 3:00:20variation yeah if we Define quantity
- 3:00:22null it means it's probably unlimited
- 3:00:25okay and that's
- 3:00:27it so we're we're going to leave this
- 3:00:30quantity nullable for the price we're
- 3:00:32going to make it like 20 on four and I'm
- 3:00:35going to make this nullable as
- 3:00:39well if the price is not specified it
- 3:00:44means that uh we're going to pick up the
- 3:00:46default price which is saved in the
- 3:00:48products table okay now we have these
- 3:00:52tables ready now let's execute migration
- 3:00:55PHP Artisan
- 3:00:59migrate okay the migration has been
- 3:01:01applied so three more tables should be
- 3:01:04created in the database we can
- 3:01:05synchronize this and have a look product
- 3:01:09product variations we say variation
- 3:01:12types and variation type
- 3:01:15options now let's close the data and we
- 3:01:18are going to add new page into the
- 3:01:21product area right here and this is
- 3:01:25going to be product variation
- 3:01:28types let's go into up
- 3:01:32filament product resource and I'm going
- 3:01:35to copy these product
- 3:01:39images that should be product
- 3:01:43variation
- 3:01:46types where we're going to click on add
- 3:01:49to this it extends this edit record
- 3:01:51which is fine uh product variation types
- 3:01:55we're going to remove this schema we
- 3:01:58don't need this let's go into product
- 3:02:03resource open that scroll down below
- 3:02:06find
- 3:02:09the get
- 3:02:11pages and I'm going to duplicate this
- 3:02:13and this is going to be variation types
- 3:02:19variation types and here let's call this
- 3:02:23variation types as
- 3:02:28well product variation types now I'm
- 3:02:32going to save this and we're going to
- 3:02:35edit right here as well product
- 3:02:38variation types class now if I refresh
- 3:02:41the page we're going to see this product
- 3:02:43variation types here uh on that we're
- 3:02:46going to change the image we're going to
- 3:02:47do this later but right now we see this
- 3:02:49empty
- 3:02:51page I'm going to also Define another
- 3:02:55enm this is going to be make enm inside
- 3:03:00enum's folder
- 3:03:03product variation oops we need Pascal
- 3:03:07case product
- 3:03:08variation types inum so product
- 3:03:12variation types is going to be the enm
- 3:03:15um
- 3:03:18yeah I
- 3:03:23think types
- 3:03:26enum let's hit the
- 3:03:28enter uh that was created let's open now
- 3:03:32inside
- 3:03:35enms
- 3:03:40oops okay make in
- 3:03:44um yeah that's my bed product status enm
- 3:03:48I created this in a nested enms folder
- 3:03:52here which is kind of a problem not a
- 3:03:55problem but not an ideal as well so we
- 3:03:58are using this in couple of places
- 3:04:00obviously because we are using PHP storm
- 3:04:02we can simply take this out from here
- 3:04:04and it's going to do refactoring let's
- 3:04:07move this out as well and we can delete
- 3:04:10this enams
- 3:04:11folder and now we're going to
- 3:04:14Define couple of cases here I'm going to
- 3:04:17Define
- 3:04:18um basically three cases or two cases um
- 3:04:23case we can have
- 3:04:26select case select we're going to have
- 3:04:30case radio and we're going to have case
- 3:04:33uh
- 3:04:35image and let me Define public static
- 3:04:39function labels which should return
- 3:04:43array and we are going to return self
- 3:04:50select and let's use value here
- 3:04:54duplicate this two more
- 3:04:57times and here we're going to have radio
- 3:05:00and here we are going to have
- 3:05:03image
- 3:05:05radio and image now let's open this
- 3:05:10product variation types
- 3:05:13page and find this form and we are going
- 3:05:16to implement this okay
- 3:05:19so this is how I am going to do it on
- 3:05:23the following page I am going to use
- 3:05:25filament repeater so we can have a look
- 3:05:28in the filament repeater
- 3:05:30documentation uh and if we have some
- 3:05:32images that's going to be good we're
- 3:05:34going to have
- 3:05:38repeater we're going to have some
- 3:05:40understanding this is it okay so this is
- 3:05:42a repeater example and uh we can add
- 3:05:46more blocks so the repeater can have um
- 3:05:49add new Option or add new block button
- 3:05:54right here we have this add to members
- 3:05:56and in the following way we will be able
- 3:05:58to add new variation types so our goal
- 3:06:02is to add variation types and for each
- 3:06:06type we are going to add variation type
- 3:06:09options as well so we're going to have a
- 3:06:11repeater we're going to use this
- 3:06:13repeater so repeater make for variation
- 3:06:16types and this variation types needs to
- 3:06:19be defined on products product.php we
- 3:06:23have Department category let's define as
- 3:06:27many variation types and here we're
- 3:06:31going to use variation type class okay
- 3:06:36cool now we're going to Define
- 3:06:39relationship uh this is because this is
- 3:06:42a repeater we Define the relationship
- 3:06:43we're going to make this collapsible the
- 3:06:46default items is going to be one we're
- 3:06:48going to add the action label add new
- 3:06:50variation type and we're going to
- 3:06:53display the content into two columns uh
- 3:06:55we're going to stretch the entire
- 3:06:57repeater into two
- 3:06:58columns and we're going to define the
- 3:07:00schema for the repeater itself okay so
- 3:07:04we're going to have um inside these
- 3:07:06variation types each variation type
- 3:07:09pretty much is going to have name it
- 3:07:11must be required it will have a type
- 3:07:14which will be a drop- down and we are
- 3:07:16going to use this product variation um
- 3:07:19type enm uh did I call this correctly
- 3:07:22product variation types enm I call this
- 3:07:25product variation types enm I should
- 3:07:28call this type
- 3:07:30enm uh let's do the
- 3:07:36refactoring okay so next we're going to
- 3:07:39we're going to make this required um
- 3:07:42then so we have name and type for each
- 3:07:45variation type but we're going to Define
- 3:07:48also options and this is going to be
- 3:07:50nested repeater okay and we're going to
- 3:07:53also
- 3:07:54open uh variation type and we are going
- 3:07:57to Define right here has many options so
- 3:08:01each variation type has many product
- 3:08:07variation uh or variation type
- 3:08:11options like this and the foreign key
- 3:08:15name is variation type it
- 3:08:18PHP store helps okay next let's open
- 3:08:24this page and continue so we have this
- 3:08:26relationship on options we're going to
- 3:08:28make this collapsible and we're going to
- 3:08:30Define schema and we're going to also
- 3:08:33give it column span two on the repeater
- 3:08:36inside schema we're going to have name
- 3:08:38each option will have name uh with
- 3:08:40column span two and each option will
- 3:08:45have might have images
- 3:08:48so even
- 3:08:50though uh we might Define option called
- 3:08:53for size uh even size might have some
- 3:08:59additional images so we are using Spa
- 3:09:01media library right here for images we
- 3:09:05are going to give it filter of image
- 3:09:07multiple openable panel layout grid
- 3:09:10collection is going to be images
- 3:09:12reorderable up and files preserve file
- 3:09:15names columns p and so on so just like
- 3:09:19this we defined the uh schema for form
- 3:09:23now let's import this text input we
- 3:09:27import the repeater we import the select
- 3:09:32and we're going to import this product
- 3:09:33variation type let me think so we have
- 3:09:38permissions product status and um rules
- 3:09:42enam yeah so it's a kind of inconsistent
- 3:09:45so sometimes we have the plural form
- 3:09:48permissions andam and sometimes we have
- 3:09:50in singular form I think singular makes
- 3:09:55sense product variation type in I'm
- 3:09:58going to leave this singular okay now
- 3:10:01we're going to import this
- 3:10:03and now the last thing is to
- 3:10:07open product
- 3:10:10variation type option because uh that
- 3:10:15option is used right here here make
- 3:10:18options with relationship and it each
- 3:10:20option has this images so each option
- 3:10:25should
- 3:10:26Implement uh his
- 3:10:28media and we're going to use interacts
- 3:10:32with media here as well and we're going
- 3:10:35to also
- 3:10:37Define the uh variations the
- 3:10:41conversions so I'm going to copy this
- 3:10:45function and put them right
- 3:10:50here now it's time to have a
- 3:10:58look what's
- 3:11:01this okay add variation
- 3:11:07type Let me refresh
- 3:11:11it
- 3:11:16um okay okay if I simply remove this
- 3:11:19schema this is repeater okay default
- 3:11:22items is
- 3:11:24one why don't we see this one
- 3:11:29item anyway so now let's define the type
- 3:11:33we're going to see
- 3:11:36color has a type of image now let's
- 3:11:40define options so the first option is
- 3:11:45black and we're going to attach an image
- 3:11:48to
- 3:11:49it collapse that and another option
- 3:11:54which is going to be
- 3:11:58blue upload that and add another option
- 3:12:03which is going to be
- 3:12:06purple and choose
- 3:12:08that so we
- 3:12:10defined option color with three options
- 3:12:14variation type color with three options
- 3:12:17now I'm going to add new variation type
- 3:12:19which is going to be size now this is
- 3:12:23radio and we're going to
- 3:12:25Define uh
- 3:12:28small add another option this is going
- 3:12:31to be
- 3:12:33medium add another option this is going
- 3:12:36to be large now I'm going to hit on Save
- 3:12:39changes and we
- 3:12:42see okay variation types has no column
- 3:12:46named update it that's correct we are
- 3:12:50going to open variation type and we are
- 3:12:54going to disable time
- 3:12:57stamps we're going to disable time
- 3:12:59stamps on variation type options as
- 3:13:04well uh time stamps equals
- 3:13:08false okay now let's click on Save
- 3:13:12again it looks like something was saved
- 3:13:15and we're going to see what happened
- 3:13:19here we see again blue image but let's
- 3:13:23see in the database so we have variation
- 3:13:26types okay two variation type was added
- 3:13:29here which is awesome inside variation
- 3:13:32type options we have totally six options
- 3:13:36this is for the first variation type
- 3:13:38this is for the second variation type
- 3:13:40this is also good inside
- 3:13:43media now there should be images for
- 3:13:50for blue for the
- 3:13:52second for first second and third there
- 3:13:55should be
- 3:13:56records okay look at this so for the
- 3:13:59model variation type option for first
- 3:14:02second and third they are our records
- 3:14:06and we also have generated
- 3:14:09conversions and this is pretty
- 3:14:12cool so if we refresh the page we see
- 3:14:16the data is also
- 3:14:21prepopulated
- 3:14:25color yeah this is this is cool I'm
- 3:14:28going to remove this this is purple
- 3:14:30let's attach
- 3:14:35purple and click on Save changes that
- 3:14:39was
- 3:14:43saved refresh it and
- 3:14:48and okay additional Improvement will be
- 3:14:52whenever we don't choose right here
- 3:14:54image um and we choose radio we probably
- 3:14:58should not display the following images
- 3:15:01component um and that's going to be an
- 3:15:04improvement which we can add later um
- 3:15:08but so far this
- 3:15:10looks really good now let's adjust this
- 3:15:13icon for the product variation types I'm
- 3:15:17not sure what icon would apply to
- 3:15:20this something that is many
- 3:15:24like uh nothing something maybe related
- 3:15:28to
- 3:15:33list okay I don't know maybe we can
- 3:15:35choose this one hero icon aim numbered
- 3:15:40list let's open this variation types
- 3:15:43scroll up we're going to change this
- 3:15:48and we can also assign title to it it's
- 3:15:51it's uh one of the greatest things I
- 3:15:53love in PHP stor is that whenever the
- 3:15:56class overwrites
- 3:15:58um something um else and they we we try
- 3:16:03to use a property from the parent class
- 3:16:06it autocompletes this for me so I know
- 3:16:08that there's something like title so I
- 3:16:12have to I start typing it how to complet
- 3:16:14this and now using this full I
- 3:16:16completion it gives us the following
- 3:16:20text variation
- 3:16:22types now refresh the page we see
- 3:16:25variation types right here what is
- 3:16:30this oh this is I know what is this so
- 3:16:34this is coming from here because this is
- 3:16:36variation types it Associated label to
- 3:16:39it but the entire page basically is for
- 3:16:42variation type so maybe we simply need
- 3:16:46to
- 3:16:47remove the label if that works like
- 3:16:51this okay cool variation types and here
- 3:16:54we have the
- 3:16:55list and here we have the
- 3:16:58options if we go in the product images
- 3:17:01this has the title edit product we're
- 3:17:04going to change this product
- 3:17:11images
- 3:17:14title images
- 3:17:17cool
- 3:17:19refresh okay we see images right here I
- 3:17:21think we need to remove
- 3:17:23this so we are going to give it label
- 3:17:28equals
- 3:17:32false nice okay now we did one part of
- 3:17:38the product
- 3:17:41variations
- 3:17:43that was The Following part so we Define
- 3:17:47size and small and medium color red and
- 3:17:49white and we even uploaded images but
- 3:17:52now this is the part what is remaining
- 3:17:55on the product we're going to define the
- 3:17:58combination of the variation options
- 3:18:00what we have small red small white
- 3:18:04medium red medium white in their
- 3:18:07Associated quantity
- 3:18:09price
- 3:18:10um and yeah that's it and if we have
- 3:18:14three variations like we have size
- 3:18:17color and something else like if we are
- 3:18:20speaking about the keyboard the keyboard
- 3:18:22might have color might have design
- 3:18:25whether it is USB or uh or another
- 3:18:29interface and also compatibility whether
- 3:18:32it's for like Xbox or whatever okay so
- 3:18:37we might have more than two combinations
- 3:18:39in which case we're going to make it
- 3:18:43like the result is going to be um even
- 3:18:46um result will have even more
- 3:18:49records okay but this is something we're
- 3:18:52going to do uh and right now I'm going
- 3:18:54to comment all the things what I made so
- 3:18:57far I'm going to create one more page
- 3:19:00right here which is going to be to
- 3:19:03Define quantities and prices for the
- 3:19:07combination of these variation types but
- 3:19:11before that let me actually reduce this
- 3:19:13navigation size right here I'm going to
- 3:19:15open admin pan Chanel
- 3:19:19provider sidebar width by default this
- 3:19:23is 20 Ram I'm going to reduce this into
- 3:19:2514 Ram refresh it okay much better now
- 3:19:30let's define new
- 3:19:33page let's open up filament product
- 3:19:37resources and I'm going to copy this
- 3:19:40product variation types and let's call
- 3:19:43these product variations
- 3:19:48copy and paste hit on ADD product
- 3:19:51variations
- 3:19:53okay
- 3:19:55variations we're going to change the
- 3:19:57hero icon the icon basically let's let's
- 3:20:01choose this
- 3:20:08one okay I'm going to remove everything
- 3:20:11at the moment from form we're going to
- 3:20:13have something custom right here
- 3:20:18and let me open product resource scroll
- 3:20:22down below find
- 3:20:25that get Pages section duplicate these
- 3:20:30variations and we're going to use
- 3:20:32product variations
- 3:20:37here okay and we're going to add this
- 3:20:42product variations
- 3:20:47here as
- 3:20:49well okay so let me remove this page
- 3:20:52import that
- 3:20:55cool now let's refresh the page and we
- 3:20:58have this variations here I'm going to
- 3:21:00click on this and it displays this empty
- 3:21:02page here I want to display the
- 3:21:05combination of all available variation
- 3:21:09types and let's see an example on the
- 3:21:13database I'm going to open variation
- 3:21:16type of options table and we see that we
- 3:21:18have two variation types this is for
- 3:21:21color this is for size and each of them
- 3:21:24has three variation type options so
- 3:21:28speaking about the combination of all of
- 3:21:30them which is also called Cartesian
- 3:21:32product so we have nine combinations of
- 3:21:36this I'm going to open new text scratch
- 3:21:39file let's move this on the right side
- 3:21:42and have a look so we have I'm I'm just
- 3:21:44going to use first two letters like
- 3:21:47black so we have black purple we have
- 3:21:52black sorry black small not purple black
- 3:21:57small we have black medium we have black
- 3:22:01large we have
- 3:22:04blue uh it's also BL so let's just use B
- 3:22:08so this is blue uh blue
- 3:22:11small blue
- 3:22:13medium blue large
- 3:22:16all right and we also have purple small
- 3:22:19purple medium purple large so totally as
- 3:22:22you probably guessed we have nine
- 3:22:25combinations so 3 * three and what we
- 3:22:28want is to display all these
- 3:22:31combinations and next to the next to
- 3:22:34each combination we are going to also
- 3:22:37add quantity and price input Fields so
- 3:22:42how many items what is the quantity
- 3:22:46of uh black variation type with small
- 3:22:51size so let's say that the vendor has
- 3:22:53black small 10 and the price is 15 it
- 3:22:58has black medium nine and the price is
- 3:23:0111 whatever so you have ability to
- 3:23:04configure the quantity and price for
- 3:23:06each variation type and so far this is
- 3:23:10the most challenging part we have done
- 3:23:13and just I want to follow with me and be
- 3:23:16just be patient because you might not
- 3:23:19immediately understand everything I will
- 3:23:22explain it and I will probably re
- 3:23:25explain it second times okay so this is
- 3:23:28good uh we can just move this to the
- 3:23:30right side whenever we want it um now
- 3:23:34I'm going to go into product variations
- 3:23:38okay and I want to override filament
- 3:23:41method which is called mutate form data
- 3:23:45before fill so we get the following data
- 3:23:48and we want to do the mutation before it
- 3:23:52is filled okay so now what we are going
- 3:23:56to
- 3:23:57do uh first we're going to return the
- 3:23:59data right here but we're going to put
- 3:24:01something inside the data so we are
- 3:24:03going to get uh the variations all the
- 3:24:06variations what we have so far and this
- 3:24:09record in this case refers to the edit
- 3:24:12record and this record is product so
- 3:24:15product has relation into variations
- 3:24:18which is called in our database uh
- 3:24:20product variations just let's make sure
- 3:24:24we have this relation defined in product
- 3:24:27PHP we have variation types but we don't
- 3:24:30have variations so let's define as many
- 3:24:34variations and this is going to be
- 3:24:37product variation and we're going to set
- 3:24:40up with a column product ID the foring
- 3:24:43key is the product ID okay now we have
- 3:24:45the variations and from product This
- 3:24:47Record refers to product from product we
- 3:24:50can access to variations and we need an
- 3:24:53array so we just need a plain array out
- 3:24:55of these variations we don't want
- 3:24:57collection we're going to work on the
- 3:24:59plain array next now this is the
- 3:25:02interesting part next we are going to
- 3:25:04generate some data and put this inside
- 3:25:07data
- 3:25:08variations and for this we are going to
- 3:25:10create new method merge Cartesian with
- 3:25:15existing so this is how I am going to
- 3:25:18call my method and this will accept two
- 3:25:21arguments This Record variation types
- 3:25:24and we know that the variation types are
- 3:25:27just color and size nothing else
- 3:25:32okay we are going to merge this with the
- 3:25:35variation types the first argument is
- 3:25:37the variation types we're going to pass
- 3:25:39and the second argument is going to be
- 3:25:41all the variations we already have in
- 3:25:43the database for this product and this
- 3:25:46is actually necessary the merging is
- 3:25:49actually necessary for the following
- 3:25:51case so far we saw that we have nine
- 3:25:55combinations
- 3:25:57totally and the um ninth one is actually
- 3:26:01so purple small purple medium and purple
- 3:26:07large okay now let's say that vendor
- 3:26:12decided to add a new size which is going
- 3:26:15to be extra large so that totally
- 3:26:19changes the picture so if so far we have
- 3:26:22nine variations if we add one more
- 3:26:25variation right here so then we're going
- 3:26:27to have 12 variations so if I add extra
- 3:26:31large here and let's say that we
- 3:26:33Associated some prices and quantities
- 3:26:36for each variation and let's say for all
- 3:26:38of them the quantity is 10 and the price
- 3:26:40is 20 or
- 3:26:42$19 okay so we added price in quantity
- 3:26:47for each variation now so this is going
- 3:26:50to be called existing data which will
- 3:26:54be right here these record variations
- 3:26:58and that data will be saved inside
- 3:27:01product variations table where we have
- 3:27:04the primary key we have the product ID
- 3:27:06we have these variation type option IDs
- 3:27:09in which case we will have the ID for
- 3:27:12black ID for small so this um IDs let's
- 3:27:18actually have a look again inside
- 3:27:20options so the ID for Blake is one if I
- 3:27:23interpret this in a different way if I
- 3:27:27simply copy and paste here ID for
- 3:27:30black is going to be one ID for small is
- 3:27:34four so this is going to be the option
- 3:27:37IDs inside product variations right here
- 3:27:41variation type option IDs right so one
- 3:27:45and four and here we're going to have
- 3:27:47one and
- 3:27:50five here we're going to have one and
- 3:27:54six then here we're going to have what's
- 3:27:57the ID for blue it is two what's the ID
- 3:28:00for small it is four so here we're going
- 3:28:02to have
- 3:28:04oops two and four and so on I'm not
- 3:28:08going to do this for all of them but
- 3:28:10this is how the data will be saved
- 3:28:12inside product variations okay and right
- 3:28:15here in this product variations when we
- 3:28:17get the existing variations this is
- 3:28:19going to be the ex existing data into
- 3:28:22the database table but if we added new
- 3:28:26variation type let's say extra large
- 3:28:28that changes the picture so right here
- 3:28:31we're going to
- 3:28:32have additional black extra large but it
- 3:28:36doesn't have price and quantity here
- 3:28:39we're going to have blue extra large
- 3:28:42it's not going to have price and
- 3:28:44quantity again and we're going to have
- 3:28:45purple
- 3:28:47extra large and it is not going to have
- 3:28:49price and quantity however if it doesn't
- 3:28:51have price and quantity I want to set
- 3:28:54the default price and quantity that is
- 3:28:58available inside the products table okay
- 3:29:02and this is what this merge cartisian
- 3:29:04with existing is going to do so I'm just
- 3:29:06going to generate such type of data
- 3:29:10without prices so in in this
- 3:29:13case without this data so I will
- 3:29:16generate the following
- 3:29:19data but I know that in the database I
- 3:29:23already have some data for the following
- 3:29:25things for the first three for this and
- 3:29:28for this as well so then I'm going to do
- 3:29:31the
- 3:29:32merging and right here I will get the
- 3:29:35following result and I'm going to plus
- 3:29:36right here here and here at the default
- 3:29:39values okay I think right now we can
- 3:29:42continue enough talking and we're going
- 3:29:44to create that merge C Tian with
- 3:29:47existing function so let's define this
- 3:29:50function it is going to accept these two
- 3:29:52arguments variation types and existing
- 3:29:55data and now we are going to get the
- 3:29:59default quantity which is going to be
- 3:30:00the product quantity and we're going to
- 3:30:03get the default price which is going to
- 3:30:05be product price then we're going to
- 3:30:08create one more function which is going
- 3:30:10to be the cartisian
- 3:30:11product that cartisian product is going
- 3:30:14to take the variation typ types default
- 3:30:17quantity and default price and this is
- 3:30:20going to
- 3:30:21generate such type of data imagine that
- 3:30:24we don't have anything in this T table
- 3:30:28and this is our case right now we don't
- 3:30:30have anything in this table so what we
- 3:30:32want is to generate such type of data
- 3:30:35let's actually do the following so we
- 3:30:38want to generate such type of
- 3:30:41data
- 3:30:43but we want it to generated with the
- 3:30:47default quantity and default price and
- 3:30:50the default quantity and default price
- 3:30:51as I mentioned is going to be taken from
- 3:30:53product so right here we're going to
- 3:30:55have default quantity from the product
- 3:30:57let's say 10 and the default price will
- 3:30:59be 90 so this
- 3:31:02is this is the format of the data but
- 3:31:05instead of BL and S we're going to have
- 3:31:08these IDs option IDs this is the format
- 3:31:12we're going to
- 3:31:13generate with this cartisian
- 3:31:15product function okay and if we assume
- 3:31:19that we already have such type of data
- 3:31:21generated more
- 3:31:23specifically I think I'm going to show
- 3:31:26the Json structure of the data or I'm
- 3:31:29going to show the Json example but uh
- 3:31:31you can easily interpret this into an
- 3:31:33associative array we can also create
- 3:31:35associative array but I think Json is
- 3:31:37easier to actually work with
- 3:31:39so we're going to have array and we're
- 3:31:43going to have um bunch of object
- 3:31:46the variation types okay so let's take
- 3:31:49the first one so this will have
- 3:31:52variation type ID uh or variation type
- 3:31:56one okay so and this will correspond to
- 3:32:02some data so it is going to have like ID
- 3:32:06of the option which is going to be
- 3:32:09whatever is the option ID uh let's check
- 3:32:13right here ID of the option let's start
- 3:32:16with black so ID of the option is one
- 3:32:19it's going to have the name of the
- 3:32:21option which is going to be black and
- 3:32:24we're going to also put the type
- 3:32:27variation type this is going to be for
- 3:32:30color so variation type one now here
- 3:32:34we're going to have variation type two
- 3:32:37and
- 3:32:38variation um type no we're going we we
- 3:32:41have only two variation types in the
- 3:32:43specific case so we're going to have
- 3:32:44variation type two
- 3:32:46um here we're going to have
- 3:32:49small uh which is size ID or and
- 3:32:55additionally we're going to have here
- 3:32:59quantity let's say 10 and price let's
- 3:33:04say
- 3:33:0519 so this is now one variation uh type
- 3:33:10object and imagine that we have all the
- 3:33:13other variation type so totally we're
- 3:33:17going to have such type of object nine
- 3:33:20in our case because we have the
- 3:33:22combination gives us basical nine so
- 3:33:24here we have this
- 3:33:26six 7 8 and nine and imagine that we
- 3:33:31just change right here the ID the
- 3:33:35name and simply duplicate this part
- 3:33:39like
- 3:33:412
- 3:33:433 4
- 3:33:47five
- 3:33:486
- 3:33:507
- 3:33:528 and
- 3:33:54nine so if we check the text file again
- 3:33:56so if we remove this extra large we
- 3:33:58don't have it uh we have uh this nine
- 3:34:02variations so far and we started with
- 3:34:06this one one and
- 3:34:08four and it is going to end with
- 3:34:11whatever is the ID for purple and the ID
- 3:34:14for large so three and six so imagine
- 3:34:19that we fill that data with the correct
- 3:34:21IDs right here and finally the last
- 3:34:24record we will have variation type one
- 3:34:28which is this variation type one will
- 3:34:31have purple which is
- 3:34:34three the name is purple its color and
- 3:34:39variation type two is large so ID six
- 3:34:45it is large and its type is size and
- 3:34:50this is the
- 3:34:51format uh that method right here the
- 3:34:54cartisian product method should return
- 3:34:58okay let's collapse the right side again
- 3:35:01and let's continue right here so this is
- 3:35:03going to return such type of array
- 3:35:06associative array no it's not
- 3:35:08associative it's a plain array of um sub
- 3:35:11arrays where each sub array is already
- 3:35:14associative array
- 3:35:17cool now let's continue so we take that
- 3:35:20cartisian product and we want to add we
- 3:35:23want to merge this with existing um
- 3:35:27existing data right here and finally
- 3:35:29we're going to have the similar type of
- 3:35:32output but instead of this default
- 3:35:35quantity 10 and 19 which we provide rate
- 3:35:39here default quantity and default price
- 3:35:41which is taken from the product instead
- 3:35:43of this 10 and 19 every time we are
- 3:35:47going to override the data which already
- 3:35:50exists in the database so in our
- 3:35:52specific case there's no data in the
- 3:35:54database but whenever there is some data
- 3:35:57and we're implementing update then the
- 3:36:00updated data will overwrite this this 10
- 3:36:03and
- 3:36:0519 okay continue we're going to start
- 3:36:08iterating of this cartisian product as
- 3:36:12product then we're going to start
- 3:36:14extracting the option IDs from the
- 3:36:18current uh product combination okay so
- 3:36:21we're going to just convert that product
- 3:36:24which looks like this into a collection
- 3:36:28okay so this going to be converted into
- 3:36:30collection next we are going to do
- 3:36:34filtering on this so we get the value
- 3:36:37and we get the key because this is a
- 3:36:39associative array what I have selected
- 3:36:41right now on the right side when we
- 3:36:44convert this into collection and start
- 3:36:45filtering we have value and key and then
- 3:36:49during filtering we are going to only
- 3:36:51take those keys which starts with
- 3:36:55variation type so we have quantity and
- 3:36:57price here as well but we want to take
- 3:37:00this and this so we are filtering which
- 3:37:02starts with variation type next I want
- 3:37:06to call map so we filtered and left only
- 3:37:09these
- 3:37:10two then we call map on this and we just
- 3:37:14take the ID and these are the option IDs
- 3:37:18through this map this returns finally
- 3:37:22collection of one and four in the in the
- 3:37:26first for the first object for the
- 3:37:28second object it's going to have one and
- 3:37:30five um one and six and so on and for
- 3:37:33the final one it is going to be um here
- 3:37:36it should not be one it should be three
- 3:37:39three and six okay so then we get the
- 3:37:42values out of this because we simply
- 3:37:45this this still is an associative array
- 3:37:48but we simply want values and then we
- 3:37:51call to array to convert this into a
- 3:37:54plane array not a collection and finally
- 3:37:56option idas is going to be a plain array
- 3:37:59of one and
- 3:38:01four okay
- 3:38:05next uh we're going to find matching
- 3:38:08array in existing data so the existing
- 3:38:11data is the objects of the following
- 3:38:15table
- 3:38:16if I zoom out slightly or show the
- 3:38:19actual column names so we have variation
- 3:38:21type option IDs we have quantity price
- 3:38:25and we have created at and updated at
- 3:38:27but we don't care them at the moment so
- 3:38:29what we care is the product ID variation
- 3:38:32type option IDs which is going to be the
- 3:38:36array of the same type what we just
- 3:38:39generated and the option ID is is an
- 3:38:41array of one and four okay so you
- 3:38:45probably I need to open a PHP scratch
- 3:38:47file as well and option
- 3:38:50IDs option IDs will have a format of
- 3:38:56combination of option IDs like one and
- 3:38:58four um it's going to have three and six
- 3:39:02and so on such type of vary and also in
- 3:39:05this product variations table we're
- 3:39:07going to have exactly same type of data
- 3:39:10and now here what we want to do is to
- 3:39:13filter the existing data data okay uh
- 3:39:18with the option IDs and we want to find
- 3:39:20if inside existing data there exists a
- 3:39:24matching of these option IDs so for this
- 3:39:29we uh in in the array filter we pass
- 3:39:31this function we use the option IDs and
- 3:39:34finally we're going to return if
- 3:39:37existing option which is as I mentioned
- 3:39:40record of the following table okay if
- 3:39:43existing options variation type option
- 3:39:46ID equals these option IDs what we just
- 3:39:51generated so if inside existing options
- 3:39:54that exist it means that the specific
- 3:39:57option IDs we already have in the
- 3:39:58database there exists record right here
- 3:40:02in the following table so it has its own
- 3:40:05quantity and price so in this case we're
- 3:40:10going to do check if the matching is not
- 3:40:12empty if the matching was found then
- 3:40:15we're going to take the first element
- 3:40:17from this matching okay through this
- 3:40:20reset method we take this first element
- 3:40:23and inside product which is something
- 3:40:26what we iterate right here inside this
- 3:40:29product we are going to add quantity
- 3:40:31from existing entry and price also from
- 3:40:35existing entry which existed in the
- 3:40:38database table and just like this we
- 3:40:42generated um the default dat with the
- 3:40:45default quantity and
- 3:40:48price but then let's say that for black
- 3:40:52large we had different price in the
- 3:40:54database which was let's say 24 so this
- 3:40:57will override and it will be 24 if like
- 3:41:00a purple small we had only five then
- 3:41:03it's going to override and we will have
- 3:41:05only five in the final um data however
- 3:41:10if the matching wasn't found then the
- 3:41:12product quantity and the product price
- 3:41:14will be the default one so which we
- 3:41:17provided right
- 3:41:19here inside this cartisian with
- 3:41:23existing Okay cool so finally we have
- 3:41:26this product and finally we're going to
- 3:41:27put this product inside merge merged
- 3:41:30results and then we are going to return
- 3:41:33this merged result from the following
- 3:41:36function merge cartisian with existing
- 3:41:39now we have this function to implement
- 3:41:41cartisian product and this is going to
- 3:41:43be interesting okay so let's define the
- 3:41:45function cartisian product we're going
- 3:41:47to accept variation types we're going to
- 3:41:49accept default quantity and we're going
- 3:41:52to accept default price now this is the
- 3:41:55most challenging part um but be with me
- 3:41:59um if you have any questions you can
- 3:42:02leave the comments down below but I
- 3:42:05think I'm like trying to explain
- 3:42:07everything very clearly and slowly so
- 3:42:10here we are going to generate this
- 3:42:12cartisian product and we need three
- 3:42:14nested Lopes so the result is going to
- 3:42:18be the array final array inside which we
- 3:42:22are going to put the entire data so now
- 3:42:27we we know that the format of the data
- 3:42:29should look like this right so um the
- 3:42:32product variations is something we can
- 3:42:35close we have this scratch PHP okay I
- 3:42:37can close this as well but I'm going to
- 3:42:39open now new Json scratch file and I'm
- 3:42:43going to like St step by step granularly
- 3:42:47uh like add content inside this scratch
- 3:42:51Json file so that you can show how the
- 3:42:53data is grown here so we have the
- 3:42:56variation types default quantity and
- 3:42:58default price and the result is
- 3:43:00something like this so array with the
- 3:43:04first element to be also associative
- 3:43:06array like if if it's going to make
- 3:43:10thing easier for you I think we can have
- 3:43:13uh like this data or
- 3:43:15result something
- 3:43:18like this as well okay like it is here
- 3:43:21and then we can put some data inside
- 3:43:24okay next we start iterating over
- 3:43:27variation types we get the index and the
- 3:43:29variation type variation types simply is
- 3:43:32a uh is an array of the variation types
- 3:43:36from the database where do we provide
- 3:43:39this yeah it's simply collection of
- 3:43:42objects from the inside the database so
- 3:43:45we start iterating over the variation
- 3:43:46types and I create a new temporary array
- 3:43:51and inside this we're going to put some
- 3:43:53data then I start iterating over for
- 3:43:56each variation type I start iterating
- 3:43:58over its
- 3:43:59options and then I do one more iteration
- 3:44:04of the current results what we have so
- 3:44:07far so we have three nested Loops right
- 3:44:12now okay so at the moment the result is
- 3:44:17an array which has only one element so
- 3:44:19if we start this from scratch we have
- 3:44:23two variation types one is color second
- 3:44:26is size so the outer loop will be
- 3:44:29iterated two
- 3:44:30times each variation type has three
- 3:44:33options so the nested Loop option will
- 3:44:36be iterated three times for each
- 3:44:39variation type and this is something
- 3:44:41what we know for sure okay so here we
- 3:44:46have two this is actually two this is
- 3:44:49actually uh three so the following Loop
- 3:44:54the following code basically will be
- 3:44:56executed totally six times so this is
- 3:44:59two each option each variation type has
- 3:45:03um two three options so this code will
- 3:45:06be executed six times but depending on
- 3:45:11the result and we're going to
- 3:45:13gradually um put some data inside
- 3:45:16results so totally we're going to have
- 3:45:18nine iterations and the result will be
- 3:45:22um will have nine records exactly as we
- 3:45:25planned so now this is what we're going
- 3:45:28to do so we're going to take the
- 3:45:29existing combination which is the which
- 3:45:33is the following object which is empty
- 3:45:35object at the moment so we take the
- 3:45:37existing combination and we merge it
- 3:45:39with something new and something new is
- 3:45:42going to be the new variation type
- 3:45:45in our case because this is the first
- 3:45:48iteration variation type with ID one so
- 3:45:52this is the key and its corresponding
- 3:45:55content option ID option name and type
- 3:45:58so
- 3:46:00here so
- 3:46:02this basically will become something
- 3:46:05like this
- 3:46:07variation type ID or it's not ID I think
- 3:46:11variation type
- 3:46:13one is the this ID
- 3:46:18oops ID
- 3:46:20one name is going to be
- 3:46:23black and
- 3:46:26type is going to be uh color so this is
- 3:46:31what we did so far right here so we have
- 3:46:33now new combination which is merged of
- 3:46:36the existing combination which was empty
- 3:46:38thing with this one and now we have this
- 3:46:42new combination what I have selected
- 3:46:44right now and we're going to put this
- 3:46:46new combination inside final temp array
- 3:46:49so let me
- 3:46:51create um so this actually let's call
- 3:46:55this I want to make this very clear so
- 3:46:57let's call this final
- 3:47:00result so so far we don't have anything
- 3:47:04in the result in the result we still
- 3:47:06have something like this okay inside
- 3:47:09this result but we took this empty array
- 3:47:12I'm going to create one more scratch
- 3:47:13file but I'm going to put this down okay
- 3:47:18so the result is still such type of empt
- 3:47:20array what we defined so far right here
- 3:47:23but what we did here was a new
- 3:47:27combination so let me Define new
- 3:47:32combination and the new combination now
- 3:47:35looks like this so this is the new
- 3:47:38combination and we took that new
- 3:47:41combination and put this inside temp
- 3:47:44let's define temp here as well which is
- 3:47:46an array and we put this new combination
- 3:47:49inside temp so finally temp looks like
- 3:47:55this okay now what we did so the
- 3:47:57iteration of result was finished because
- 3:48:00it only contained one element so we
- 3:48:02iterated basically we finished and we
- 3:48:06moved into the outer loop and we're
- 3:48:08going to move into the second option
- 3:48:11second option for the color is blue
- 3:48:15right so now we start that the same
- 3:48:19thing and now let's see what happens so
- 3:48:22now inside result we still have one
- 3:48:25element and the result is still this
- 3:48:28type of thing so the result is still
- 3:48:31looking like this now we come here the
- 3:48:34new combination was actually new
- 3:48:37combination was reseted and we're going
- 3:48:39to recreate new combination right here
- 3:48:42it's an existing combination existing
- 3:48:44combination is the first element of
- 3:48:45result so this this is going to be
- 3:48:48merged with the variation type and the
- 3:48:51variation type is is still the first one
- 3:48:55okay so this is going to be merged with
- 3:48:58variation type one but it is going to be
- 3:49:03for the second option second option so
- 3:49:06we provide
- 3:49:08ID which is going to be two we provide
- 3:49:12name which is going to be blue blue
- 3:49:15second option and we provide type which
- 3:49:18is of course going to be color uppercase
- 3:49:22see okay so now we created this new
- 3:49:25combination and we're going to put this
- 3:49:27new combination inside temp so I'm just
- 3:49:30going to take
- 3:49:32that new
- 3:49:34combination and we're going to put this
- 3:49:37inside temp now inside temp we have this
- 3:49:40variation type one which is one black
- 3:49:44color
- 3:49:46we have the um variation type one again
- 3:49:51two blue color and finally it's going to
- 3:49:54go with the third option and again
- 3:49:58result is still something like this so
- 3:50:01we're going to have variation type uh
- 3:50:04one again but with the third option
- 3:50:06which is the purple color so finally
- 3:50:09when this Loop finishes the work for all
- 3:50:12three options for the first variation
- 3:50:15type we are going to have data like this
- 3:50:18in the temp variation type one
- 3:50:22ID3
- 3:50:24color purple and this is going to be the
- 3:50:28color so now this Loop finished the work
- 3:50:32inside temp we have that three elements
- 3:50:35I can zoom out so that you can have a in
- 3:50:37like overall look right here so we have
- 3:50:40these three elements all of them are for
- 3:50:42variation type
- 3:50:43one here here and here and now let's
- 3:50:46continue inside the code so after that
- 3:50:49Loop is finished so we take that temp
- 3:50:54and assign it into the result so now we
- 3:50:58take the entire
- 3:51:02temp
- 3:51:03oops copy and assign that into the
- 3:51:09result now this is something interesting
- 3:51:12so after we change the result so then we
- 3:51:17start iterating for the next variation
- 3:51:20type which is variation type two now
- 3:51:24let's see what happens here variation
- 3:51:26type two is size size has three options
- 3:51:30small medium and large and this Loop
- 3:51:32will be iterated three times but now
- 3:51:35inside results we have three options
- 3:51:38already okay so we see those three
- 3:51:41options in the result now we reset the
- 3:51:46temp so down
- 3:51:48below this
- 3:51:50temp become an empty
- 3:51:54array and the new combination even
- 3:51:56doesn't exist but right here when we
- 3:51:58start iterating over result and we take
- 3:52:01each element from this result the
- 3:52:04combination is this now we take an
- 3:52:08existing combination and merge it with
- 3:52:12the variation type now in in this case
- 3:52:14the variation type ID is two so we take
- 3:52:18that data I want to take this
- 3:52:21data and we're going to merge this into
- 3:52:24variation type two which is going to be
- 3:52:27size so variation type two it is going
- 3:52:30to have uh ID will be the corresponding
- 3:52:36ID for small and I think small has ID
- 3:52:40four we're going to have name
- 3:52:45to be small and we're going to have type
- 3:52:49to be not color but size so this is what
- 3:52:53we did for the new combination and now
- 3:52:55new combination is the following element
- 3:52:59and we take it and assign it to Temp so
- 3:53:02down below not assign but push it into
- 3:53:05the temp now right here we're going to
- 3:53:07push that data now we took this first
- 3:53:12combination right here in this results
- 3:53:14but we're going to move into the next
- 3:53:15one because we are iterating over
- 3:53:17results here we took the first one and
- 3:53:20this one so we moved into the second one
- 3:53:22we took this right here the existing
- 3:53:26combination and merge it with another
- 3:53:29variation uh another option so let's
- 3:53:32move up let's create this new
- 3:53:36combination we took this one and merge
- 3:53:39it with variation type two in this case
- 3:53:42we're going to have ID five
- 3:53:45name is going to be medium size and type
- 3:53:50is going to be size okay so we take this
- 3:53:54new combination
- 3:53:56now and push it into
- 3:53:59temp right
- 3:54:01here now we took the second com second
- 3:54:05uh combination from the result but we
- 3:54:07still have to do this take the third one
- 3:54:09so we're going to take the third
- 3:54:12one so inside this new combination we
- 3:54:15are going to merge it with again
- 3:54:18variation type uh two with the last
- 3:54:22option which is going to be the large
- 3:54:24option so ID is going to be six name is
- 3:54:28going to be large and the type is going
- 3:54:32to be size again we take
- 3:54:37this uh we take the entire new
- 3:54:41combination and we push put this inside
- 3:54:46temp
- 3:54:48okay now we addit the data inside the
- 3:54:52temp right here so now this is what
- 3:54:56happens uh
- 3:55:00finally we assign that temp into the
- 3:55:04result so whatever we have right now
- 3:55:07inside
- 3:55:09temp
- 3:55:12uh so we have let's see so we have
- 3:55:16this
- 3:55:18one
- 3:55:20two
- 3:55:23three uh sorry I think I missed one
- 3:55:27thing while explaining so actually this
- 3:55:30code works but one thing was actually
- 3:55:34missed while I was explaining so we took
- 3:55:38the um we took the first one first uh
- 3:55:42thing from the result first combination
- 3:55:44from from the result this so it was
- 3:55:47merged with the new
- 3:55:49Option okay so we have um this is going
- 3:55:53to be a one result so if we count how
- 3:55:56many records we're going to have temp so
- 3:55:58inside temp we're going to have nine
- 3:55:59records but because I missed something
- 3:56:02during explanation we totally have um
- 3:56:05three records inside the temp which is
- 3:56:07not what we expected but we're going to
- 3:56:10have nine because uh for the second
- 3:56:13variation type
- 3:56:15uh this Loop right here iterates three
- 3:56:18times okay and the result also contains
- 3:56:22three elements so we totally do the nine
- 3:56:26iteration so the new combination is
- 3:56:28created nine times so and we push this
- 3:56:31new combination inside temp so finally
- 3:56:33we're going to have nine elements so if
- 3:56:36I quickly re explain this part so the
- 3:56:39temp becomes empty we start iterating
- 3:56:42over options so then we take the first
- 3:56:45element from the result it is going to
- 3:56:47be merged with the first option of this
- 3:56:50second variation type and it is going to
- 3:56:54be inserted inside temp with the merged
- 3:56:56one uh I'm not going to actually do this
- 3:56:59um IDs and all the things but let's
- 3:57:01imagine that um it contains all the data
- 3:57:04and you don't need to imagine it is
- 3:57:06going to actually contain the um correct
- 3:57:08data so we take existing variation type
- 3:57:12ID which is for one we merged it into
- 3:57:16with the variation type ID which is for
- 3:57:18two and with the uh option which is
- 3:57:21going to be small so this merged with um
- 3:57:28id4 with small let's call this just
- 3:57:30small so black merged with small and
- 3:57:33this is going to be inside here so then
- 3:57:36for the second
- 3:57:38combination
- 3:57:39this is going to be merged with also
- 3:57:43small because we are still talking about
- 3:57:46the same option right here so this will
- 3:57:48be merged with small as well and then
- 3:57:51the third element from the result which
- 3:57:54is combination will be merged with small
- 3:57:56as well so we're going to have black
- 3:57:59small blue small purple small and we're
- 3:58:04going to have those three elements
- 3:58:06inside temp Now we move into the second
- 3:58:09option second option is medium so we're
- 3:58:12going to have black medium blue medium
- 3:58:17purple medium and each of them is pushed
- 3:58:20inside temp so black
- 3:58:23medium blue
- 3:58:25medium and oops and purple medium and
- 3:58:31finally we're going to move onto the
- 3:58:32third option which is going to be
- 3:58:36um large so it is going to be black
- 3:58:39large Blue large and purple large so we
- 3:58:44to this and totally there will be nine
- 3:58:47data nine uh elements inside the data
- 3:58:50and the result will have similar
- 3:58:54structure but in format of array of
- 3:58:57course this is Json without quantity and
- 3:58:59price this is important so far so we're
- 3:59:02going to have only variation type one
- 3:59:04variation type
- 3:59:06two now after this Loop actually
- 3:59:10finished this variation types so then
- 3:59:13we're going to do one more iteration
- 3:59:15over the result and finally because we
- 3:59:17are assigning this temp into the result
- 3:59:20after we have this temp that temp will
- 3:59:24be assigned into the result right here
- 3:59:29and the result will have those nine
- 3:59:32elements there now we start iterating
- 3:59:35over these
- 3:59:38results we're going to get each
- 3:59:40combination from these results and as I
- 3:59:44mentioned the format of each element
- 3:59:48right here will be something like this
- 3:59:51variation type one variation type two
- 3:59:53without quantity and price so far
- 3:59:55because we're going to add those
- 3:59:56quantity and price so right here then
- 3:59:58we're going to do check if count of
- 4:00:00combination which is actually two is the
- 4:00:03same as variation types count which is
- 4:00:06also true so if we added all the
- 4:00:08variation types that that means pretty
- 4:00:10much this this if can be also removed
- 4:00:13just I added this Force extra extra
- 4:00:16check so in in all the cases the
- 4:00:19combination the count of combination
- 4:00:20will be the same as count of variation
- 4:00:22types so if the counts match then inside
- 4:00:25the combination we're going to add
- 4:00:27quantity which is going to be the
- 4:00:28default quantity and we're going to add
- 4:00:30price which is going to be the default
- 4:00:32price and finally we are going to return
- 4:00:35this
- 4:00:37result okay a lot of
- 4:00:40talking but I wanted to make uh I wanted
- 4:00:44to make this very very clear so after
- 4:00:47this cartisian product now we have that
- 4:00:49data in the following format having
- 4:00:52price and quantity as well and now it is
- 4:00:55time to render the data
- 4:00:59inside inside form right
- 4:01:02here now we're going to take the
- 4:01:05variation types right here and we're
- 4:01:07going to create the proper form fields
- 4:01:10to render the data what we just created
- 4:01:13okay so we're going to create Fields
- 4:01:15array then we're going to start
- 4:01:16iterating over types the variation types
- 4:01:20which is going to be one um that's color
- 4:01:24second this is size and right here
- 4:01:27inside the fields we are going to uh
- 4:01:31create that inputs so text input make
- 4:01:34the variation type one so the I I
- 4:01:38obviously starts with zero so we get the
- 4:01:40variation type
- 4:01:42one ID
- 4:01:44and the variation type and that that ID
- 4:01:48field actually is going to be hidden by
- 4:01:50the way here it should not be ID it
- 4:01:53should be um sorry it should not be I it
- 4:01:56should be type ID I'm going to change
- 4:01:59this so I'm going to change this just
- 4:02:01let me finish this um code
- 4:02:04inserting and I will I will come back to
- 4:02:07this and change this okay so we're going
- 4:02:09to put also ID but that ID inside Fields
- 4:02:12is going to be hidden field
- 4:02:14okay I want this whenever I process the
- 4:02:16data so that ID to be also uh processed
- 4:02:21so in the same way we are going to
- 4:02:23display the variation type name here
- 4:02:27variation type one. name which basically
- 4:02:30means that variation type
- 4:02:33one. name it is going to display this it
- 4:02:36is not the actual variation type name
- 4:02:39but from this sub array it is going to
- 4:02:41display the option name so that that is
- 4:02:44actually option name the the type name
- 4:02:47itself is the type right here color but
- 4:02:51that name right here the ID is the
- 4:02:54option ID the name is the option
- 4:02:58name so we create those
- 4:03:01fields um and this is going to have the
- 4:03:05label to be the variation type name and
- 4:03:09the uh label is going to be black okay
- 4:03:14so let's move on and inside the schema
- 4:03:16we're going to use the repeater and
- 4:03:20because when we prepare that data the
- 4:03:22merge cartisian with existing data we
- 4:03:24put that data inside variations so we're
- 4:03:27going to make that repeater on these
- 4:03:30variations what we just generated okay
- 4:03:34and then each variation is the following
- 4:03:37object like the following object right
- 4:03:41so then on that variation we make this
- 4:03:43variation collapsible um default items
- 4:03:46one and inside schema um we're going to
- 4:03:50Define some Fields but we're going to
- 4:03:51also add two columns and column col
- 4:03:54spine to be two and then we're going to
- 4:03:56make some section inside section we are
- 4:03:59going to put Fields so because this is
- 4:04:03actually a repeater it is going to be
- 4:04:05repeated as many times as many elements
- 4:04:09there are inside
- 4:04:10variations and inside variations just
- 4:04:13like how we generated we know that in
- 4:04:15our specific case we have nine items
- 4:04:18inside variations what we just generated
- 4:04:21so this repeater will repeat it nine
- 4:04:24times and for each there will be these
- 4:04:29fields and this will be uh the ID and
- 4:04:33the name will be for each field the ID
- 4:04:35will be hidden so we're going to make
- 4:04:38this uh layout in three columns and
- 4:04:42we're going to Now display so after we
- 4:04:44display those options then we display
- 4:04:48quantity and we display price so we have
- 4:04:52those two additional input Fields now uh
- 4:04:56I want to import that
- 4:05:00section let's import this section which
- 4:05:04is going to be filament forms component
- 4:05:07section okay and I think we can have a
- 4:05:10look right now in the browser so let's
- 4:05:13refresh the page and just have a look
- 4:05:16look at this so now we have color black
- 4:05:20size small and is corresponding quantity
- 4:05:22and price and quantity and price is the
- 4:05:25default one taken from the product right
- 4:05:27now blue small quantity price purple
- 4:05:31small quantity price black
- 4:05:35medium uh we have black small here as
- 4:05:38well so black small blue small purple
- 4:05:42small black medium blue medium purple
- 4:05:45medium uh black large Blue large and
- 4:05:49purple large and because we layout this
- 4:05:51into three columns we see additional
- 4:05:53space right here uh and yeah this is
- 4:05:56exactly what we wanted so adding this
- 4:05:59new variation doesn't actually do
- 4:06:01anything because we don't have anything
- 4:06:03else so we can even remove that uh
- 4:06:07edible we we should not have that edible
- 4:06:10and additional thing is that I'm going
- 4:06:11to change this uh instead of using this
- 4:06:14index plus one here we are going to
- 4:06:17use
- 4:06:19type type ID let me change this into
- 4:06:24type ID as well so the i+ one um was
- 4:06:29like by mistake I had I was using index
- 4:06:33previously When I Was preparing for for
- 4:06:35the project and then I switched into the
- 4:06:37ID so in the database if the variation
- 4:06:40types have different IDs instead of one
- 4:06:44and two right here on production
- 4:06:46obviously when there are a lot of data
- 4:06:48we're going to have different ideas it's
- 4:06:50going to be like 119
- 4:06:53and 20 whatever so this is going to be
- 4:06:56used right here
- 4:06:58119 120 here instead of the one and two
- 4:07:02just like what we had
- 4:07:05before okay and I think this repeater uh
- 4:07:08we
- 4:07:09can uh we can disable eding by providing
- 4:07:13edible false refresh it and we don't see
- 4:07:17this add new
- 4:07:19anymore now I think we can work on
- 4:07:23saving the data so so far that was good
- 4:07:26but we have to save that data and we
- 4:07:28have the label here as well which we
- 4:07:31can uh set into false as well the entire
- 4:07:34page is for variations so we don't need
- 4:07:37this title and we have expand all
- 4:07:40collapse all just in case we need that
- 4:07:43to work on saving the data we're going
- 4:07:46to go into our product variation class
- 4:07:51and we're going to override method
- 4:07:52called mutate form data before save okay
- 4:07:58this is the um filaments buil-in method
- 4:08:01so we over readen over write that method
- 4:08:05here so we get the data we have to
- 4:08:07modify mutate that data and return that
- 4:08:11modified data so we take the data return
- 4:08:13it now let's work on modifying the data
- 4:08:17so I want to initialize a new array and
- 4:08:19that's going to change hold the format
- 4:08:21data so the new format data so we have
- 4:08:25now data coming from the form in the
- 4:08:28following way just in a PHP array not
- 4:08:32Json so we want to modify this and
- 4:08:36convert that format into format which is
- 4:08:41applicable for the database in the
- 4:08:44database has the following format not
- 4:08:47this table but product variations table
- 4:08:51this
- 4:08:52one so let me try to simulate one record
- 4:08:57creation so this is one variation so
- 4:09:01we're going to take the option ID one
- 4:09:04we're going to take option ID 4 put this
- 4:09:07right here
- 4:09:09as as array one and four we're going to
- 4:09:13provide the quantity to be 10 and we're
- 4:09:17going to provide price to be 19 and
- 4:09:20obviously we have to provide the product
- 4:09:21ID for which we're doing this and
- 4:09:24created it and updated it but I'm going
- 4:09:25to leave this so now this is how we're
- 4:09:29going to convert the data that data into
- 4:09:32the following format so that that data
- 4:09:34will be saved into the database okay I'm
- 4:09:37going to delete this now and let's open
- 4:09:40this product variations again and
- 4:09:41continue
- 4:09:44so then we start iterating over the data
- 4:09:46variations which has the following
- 4:09:48format we get option okay each option is
- 4:09:53this this is each option so option has
- 4:09:58quantity price and the variation types
- 4:10:00so from that option we're going to take
- 4:10:02the IDS this is what we are doing I'm
- 4:10:05going to Define new array variation type
- 4:10:07option IDs and then I'm going to start
- 4:10:10iterating over the product Vari iation
- 4:10:13types which is going to be color and
- 4:10:16size in the corresponding objects then
- 4:10:20inside this variation type option IDs
- 4:10:23which has the purpose to save one and
- 4:10:26four there so this is what we are doing
- 4:10:29from the option which
- 4:10:32is the following object from the option
- 4:10:35we are taking variation type underscore
- 4:10:39and the variation type ID so for the
- 4:10:42corresponding variation type one or two
- 4:10:44it is going to give us the following
- 4:10:46object from the following object we're
- 4:10:48going to take ID so this will return the
- 4:10:52following number so we are pushing that
- 4:10:55ID into the variation type IDs and we
- 4:10:57are doing this for all the variation
- 4:10:59types for the first one and for the
- 4:11:03second one we take one and four push
- 4:11:06into the variation type option IDs
- 4:11:08awesome next we're going to take the
- 4:11:10quantity from the option
- 4:11:13and price from the option as well and
- 4:11:16then we're going to create that um
- 4:11:19formatted data so inside formatted data
- 4:11:23we're going to push the following array
- 4:11:25it is going to have these variation type
- 4:11:27option IDs which is the column name
- 4:11:29already database column name with a
- 4:11:32variation type option ideas what we just
- 4:11:34generated containing one and four we're
- 4:11:37going to give it also quantity and we're
- 4:11:40going to give it price and Final
- 4:11:43inside data variations we are going to
- 4:11:47put that formatted data and because
- 4:11:51product model has this relation into
- 4:11:54variations and we are mutating this
- 4:11:57before saving so that data which has now
- 4:12:01correct format variation type option IDs
- 4:12:03quantity and price that data will be
- 4:12:06saved into the
- 4:12:08database this is so awesome to see the
- 4:12:11result so we can provide that the black
- 4:12:14are kind of expensive we can give it
- 4:12:16price like 25 and also black are limited
- 4:12:19we have only three options for black
- 4:12:22let's search for black
- 4:12:25325 another Black 3 quantity 25 so we
- 4:12:30modified the variations as we wanted and
- 4:12:33I'm going to click on
- 4:12:35this save
- 4:12:37changes uh maybe we should also disable
- 4:12:41the delete so we want to Define
- 4:12:43something for every variation type so I
- 4:12:45will probably disable remove that delete
- 4:12:47button so I'm going to click of sa click
- 4:12:50on Save changes and let's see what
- 4:12:51happens we have the error no such column
- 4:12:57variations update products set
- 4:12:59variations okay I think I know the
- 4:13:01reason so we are going to go into
- 4:13:04product and we are going to add right
- 4:13:07here uh inside casts we are going to add
- 4:13:12variations
- 4:13:13to be
- 4:13:15array now let's close the model and hit
- 4:13:18on Save
- 4:13:21again okay we still have the same error
- 4:13:25yeah I know the reason so right here in
- 4:13:30this product
- 4:13:31variations uh we just prepared the data
- 4:13:34and put the variations right here but
- 4:13:37that variations um is not going to be
- 4:13:40saved into the database because that is
- 4:13:42actually an array so we have to
- 4:13:43overwrite one more method which is going
- 4:13:46to be handle record update so let me
- 4:13:49overwrite this right now handle record
- 4:13:52update so in which case we're going to
- 4:13:55receive a record in data so this model
- 4:13:58is actually product and data is the data
- 4:14:02what was returned from this
- 4:14:05mutate um Data before save so right here
- 4:14:10instead of calling parent this is what
- 4:14:12I'm going to do
- 4:14:14so finally I'm going to return record so
- 4:14:18return
- 4:14:20record but before I return the record um
- 4:14:24I want to take the
- 4:14:27variations from data variations because
- 4:14:31when there is some data inside when
- 4:14:35there is some key inside the data now
- 4:14:38filament tries to save that data into
- 4:14:41the database so and and because of that
- 4:14:43we have this error because we have
- 4:14:45variations inside the data filament
- 4:14:48tries to find the column variations in
- 4:14:51the database to put that data but we're
- 4:14:53going to take out those variations and
- 4:14:55we're going to
- 4:14:57unset unset data
- 4:14:59variations now data doesn't have
- 4:15:02variations and we're going to do the
- 4:15:04following I'm going to call record
- 4:15:06update so we are doing the actual update
- 4:15:10of the data and instead of calling
- 4:15:12record update we can also call the
- 4:15:14parent and parent will do also the
- 4:15:17update
- 4:15:19because the data um now doesn't contain
- 4:15:22variations there but let's leave it
- 4:15:25right now like this and we can try the
- 4:15:26second way as well record update data
- 4:15:29then on the
- 4:15:30record variations relation so we have
- 4:15:33that variations relation I want to
- 4:15:36delete all the variations what we have
- 4:15:38in the database at the moment we don't
- 4:15:41have
- 4:15:43any re variations in the database so
- 4:15:46we're going to delete that and then on
- 4:15:49the
- 4:15:50record
- 4:15:52variations we are going
- 4:15:54to create many variations with the
- 4:15:58following array okay now let's save
- 4:16:02it and let's click on Save
- 4:16:06changes now we have another error
- 4:16:08argument one values must be type of
- 4:16:11array and string was
- 4:16:14given
- 4:16:17inside okay where is this coming from so
- 4:16:21we have that
- 4:16:23data create
- 4:16:26many variations we call this
- 4:16:34delete the error is actually coming from
- 4:16:37the following line record variations
- 4:16:39create manyu and let's have a look let's
- 4:16:42debug it
- 4:16:43and have a look what data we have inside
- 4:16:46variations so after we update and after
- 4:16:49after we call these variations delete or
- 4:16:52maybe before delete we can print what
- 4:16:55are inside
- 4:16:57variations okay variation type option
- 4:17:03IDs okay now that makes sense so
- 4:17:07variation type option IDs is actually an
- 4:17:10array okay and we try to put in the D
- 4:17:12database the array but the product
- 4:17:18variation needs to have cast field like
- 4:17:23similar to what we added into product so
- 4:17:26inside product actually I think we did
- 4:17:28not need that variations but inside
- 4:17:31product variation we have to add that
- 4:17:33cast field and this is going to be
- 4:17:36variation type option IDs to be Json
- 4:17:40because this is actually an array
- 4:17:44okay I think that should be
- 4:17:46it we can remove
- 4:17:50that click on Save changes and we see
- 4:17:55right here saved now let's have a look
- 4:17:58in product variations table in the
- 4:18:01database look at this so we
- 4:18:05have we have nine
- 4:18:08records for the same product we have the
- 4:18:11variation type option IDs here here 1 4
- 4:18:132 4 3 4 1 5 all of them as we expect we
- 4:18:17have quantities and for some of them it
- 4:18:19was actually uh empty the default one
- 4:18:22but for the black ones and the black
- 4:18:24option has ID one so whenever we have
- 4:18:28one
- 4:18:29mentioned we gave different price and
- 4:18:33limited quantity three and just like
- 4:18:36this we have that working and this is so
- 4:18:40awesome now if we hit on Save changes
- 4:18:43again so this is going to delete the
- 4:18:45records and recreate them which is not a
- 4:18:49problem of course we can optimize this
- 4:18:52and do some additional analysis um but
- 4:18:55this is not also a problem uh we are not
- 4:18:57going to use these IDs anywhere so every
- 4:19:00time we make this update although I
- 4:19:02don't expect this um updates very very
- 4:19:06often but anyway it's not a problem so
- 4:19:08we delete delete that recreate that um
- 4:19:12generally um I would optimize that um if
- 4:19:16I am about to put this
- 4:19:19um like on
- 4:19:22production so I would try to optimize
- 4:19:24this but right now for this video Simply
- 4:19:27I want to focus on the most important
- 4:19:29stuff and leave the optimizations um for
- 4:19:32the later stage if I have time for
- 4:19:35this um okay what I want to try however
- 4:19:38is that instead of calling This Record
- 4:19:40update so maybe we can call this
- 4:19:44parent um so record equals we can do the
- 4:19:49following as well so we can do this
- 4:19:51variation delete variation create menu
- 4:19:55and then we can call parent handle
- 4:19:59record update providing recording
- 4:20:02data just like
- 4:20:05this uh and the data I think doesn't
- 4:20:09even contain anything else right so the
- 4:20:13data doesn't actually do the product
- 4:20:16update so yeah the data is actually
- 4:20:19absolutely empty so we don't even need
- 4:20:21to call appearent or we don't even need
- 4:20:25to update the record we can simply
- 4:20:28return the record so the the whole
- 4:20:30purpose of this page is to update the
- 4:20:32variations and this is something what we
- 4:20:35are actually already
- 4:20:37doing I generally don't like leave um
- 4:20:42some question questions to some students
- 4:20:44how they can do this or that thing so
- 4:20:46probably you have a question how I can
- 4:20:48do exactly this uh updating of the
- 4:20:53variation product variation so that
- 4:20:56every time I don't have to delete the
- 4:20:58data and then recreate the data which
- 4:21:00happens right now okay so if we refresh
- 4:21:03it click on Save right now that does the
- 4:21:06update refresh it and we're going to see
- 4:21:08that the data is actually deleted and
- 4:21:10recreated so I decided that after a
- 4:21:13little bit of research Let's Do It um
- 4:21:15it's not going to take too much time so
- 4:21:18here we're we're going to provide
- 4:21:19instead of create menu we're going to
- 4:21:21provide upsert and we're going to
- 4:21:23provide the data in the uh column based
- 4:21:26on which we're going to do the detection
- 4:21:28so The Logical one is going to be ID so
- 4:21:31here we provide the ID and then we're
- 4:21:34going to provide the columns which we
- 4:21:36want to update from that variation sta
- 4:21:40okay so this is going to be variation
- 4:21:42type um option IDs we're going to have
- 4:21:47quantity and price so we're going to
- 4:21:50update the following data however these
- 4:21:55variations do not contain IDs so
- 4:21:59whenever we
- 4:22:01are whenever we are generating the data
- 4:22:05right here in this merge cartisian with
- 4:22:07existing so the existing data right here
- 4:22:12is variations taken from the database so
- 4:22:16that variations contains ID so if we
- 4:22:19follow that the existing data contains
- 4:22:21ID so it's an array and each element
- 4:22:24contains ID so here we have that
- 4:22:27existing data we do the matching we take
- 4:22:30the first existing entry if the matching
- 4:22:33happened which means that if the
- 4:22:35matching happens we are going to do
- 4:22:37update okay not create so right here
- 4:22:40inside product
- 4:22:43ID we're going to provide existing entry
- 4:22:47and then ID okay and after this when we
- 4:22:51do this mutate form data before save so
- 4:22:54now the data will contain that uh ID so
- 4:22:59that ID is actually added next to the
- 4:23:02quantity and price so if we have a look
- 4:23:04in our Json structure we are going to
- 4:23:07have ID eded right here and that ID is
- 4:23:13going to be product variations primary
- 4:23:16key like 20 so that 20 will be added
- 4:23:19right here so we can change this into
- 4:23:21one two three four five 6 7even 8 oops
- 4:23:26what I
- 4:23:28four five six 7 8 and nine awesome now
- 4:23:34here we have one so if we go into
- 4:23:38product
- 4:23:39variations scroll down below
- 4:23:43so right here we have the data we have
- 4:23:45the options each option is the following
- 4:23:47object and from that option we take
- 4:23:50quantity price and right here we're
- 4:23:52going to also take ID this is going to
- 4:23:55be option ID now if I scroll down below
- 4:24:00and dump variations we're going to see
- 4:24:04that each variation has ID there click
- 4:24:06on Save changes we see ID which is 20
- 4:24:10white is 20 by the way
- 4:24:13because I haven't saved that data let's
- 4:24:16save it refresh it click on Save now we
- 4:24:20see that the ID is one and right here we
- 4:24:24do this upsert but this is not going to
- 4:24:27work we're going to have an error
- 4:24:28because variation type option IDs is
- 4:24:31actually an array and this upsert
- 4:24:33doesn't use eloquent models anymore and
- 4:24:37we are directly inserting the data or
- 4:24:39updating the data in the database and
- 4:24:41it's going to give us an error because
- 4:24:43that variation type option IDs is array
- 4:24:46so let's try this click on Save we get
- 4:24:49the uh get that error and this is what
- 4:24:52we are going to do so
- 4:24:57oops variations equals we can call um
- 4:25:01array map for example or we can use a
- 4:25:04collection method to do the collection I
- 4:25:07actually love working with collections
- 4:25:09so I'm going to use collect variations
- 4:25:12and we're going to return the following
- 4:25:17format with a semicolon so we need all
- 4:25:20the columns pretty much so we need ID
- 4:25:23variation ID we need variation type
- 4:25:26option IDs which is going to be Json
- 4:25:30encode okay so we do this Json encoding
- 4:25:34then we're going to have quantity and
- 4:25:36price so we just change this variation
- 4:25:38type option IDs and then we provide the
- 4:25:41variations here which should work click
- 4:25:45on Save
- 4:25:47changes upsert okay values must be type
- 4:25:50of array collection given that's correct
- 4:25:53the collect map Returns the collection
- 4:25:55so finally we have to call to array on
- 4:26:00this okay now we click on Save changes
- 4:26:05it will saved and if we check right now
- 4:26:09inside product variations table nothing
- 4:26:12thing got changed and if we provide some
- 4:26:16data like quantity 1500 price 1500 save
- 4:26:23changes refresh it we see that the data
- 4:26:26is actually changed but the IDS it is
- 4:26:28not actually deleted and
- 4:26:30recreated
- 4:26:32um it is actually deleted but this line
- 4:26:35can be completely removed it is not
- 4:26:37necessary anymore you can test this one
- 4:26:40final time
- 4:26:42click on Save
- 4:26:44changes
- 4:26:47oops refresh it and we see the data
- 4:26:50right here I have commented all the
- 4:26:52changes what I had so far and now before
- 4:26:56we move on the front and side on the
- 4:26:58website part and start rendering
- 4:27:00products let's make small changes right
- 4:27:04here so this is product resource and at
- 4:27:08the moment we are return uh we are
- 4:27:10returning and rendering all the products
- 4:27:13but we won't obviously restrict this in
- 4:27:16return on the products which belong to
- 4:27:20this vendor so for this we have to
- 4:27:23override method get eloquent
- 4:27:26cury and from here this called this per
- 4:27:29and get eloquent cury and on that I am
- 4:27:33going to add a we Clause to filter for
- 4:27:36the currently authenticated vendor for
- 4:27:39this I'm going to create for Simplicity
- 4:27:41I'm going to create
- 4:27:43scope we can open product.php
- 4:27:47which is right
- 4:27:50here and right here I'm going to add
- 4:27:53public function
- 4:27:55scope um
- 4:27:58for vendor okay so return and this
- 4:28:04actually scope for R vendor is going to
- 4:28:07accept uh cery Builder so here we need
- 4:28:10Builder build
- 4:28:12Builder database quer
- 4:28:15Builder Builder okay then on that or we
- 4:28:19can call this Cy I
- 4:28:21think on that Cy we can call
- 4:28:27we uh created
- 4:28:30by
- 4:28:32equals currently
- 4:28:34authenticated user
- 4:28:36ID scope for vendor I'm going to add
- 4:28:40additional Scopes right here which I'm
- 4:28:42going to use on the front and side
- 4:28:44public function scope published as an
- 4:28:50example we accept
- 4:28:52Builder return scope we
- 4:28:56published uh not published but we have
- 4:28:59status where status equals product
- 4:29:03status
- 4:29:05ANM published value or we can leave this
- 4:29:10published as well
- 4:29:12and both of them actually should return
- 4:29:14an instance of Builder so we have for
- 4:29:17vendor and
- 4:29:19published and and and I think that's it
- 4:29:23okay let's go into product resource and
- 4:29:24right here I'm going to use for vendor
- 4:29:27so I want products for vendor which
- 4:29:29means for the currently authenticated
- 4:29:32vendor and if we click on products right
- 4:29:36now scope for
- 4:29:39vendor the Q must be type of okay
- 4:29:42database query Builder eloquent Builder
- 4:29:45given um my bet so here instead of Q
- 4:29:51Builder that accepts eloquent
- 4:29:55Builder okay perfect so now if I want to
- 4:30:01test this so we have one product which
- 4:30:02has created by created by two which is
- 4:30:08the currently authenticated user but I'm
- 4:30:10going to change this into one and if I
- 4:30:12refresh the page right now the current
- 4:30:14vendor doesn't see any products because
- 4:30:16that product does not belong to this
- 4:30:18vendor without that CER get eloquent
- 4:30:21query basically the current vendor is
- 4:30:23able to see every product that is in the
- 4:30:25database which is obviously something we
- 4:30:28don't want we don't see any product now
- 4:30:30we change the ID into
- 4:30:32two and now we see the product right
- 4:30:36here now let's open this in a new tab
- 4:30:40and we're going to move on the front and
- 4:30:42side and start rendering the
- 4:30:45products let
- 4:30:49me close everything and we need a new
- 4:30:53controller pro probably we have actually
- 4:30:57we have the product controller so let's
- 4:30:59use it so right here we need index
- 4:31:02method and we are going to select the uh
- 4:31:06products and render them
- 4:31:09so let's call this product
- 4:31:12[Music]
- 4:31:14products product we need we and we want
- 4:31:18to select only published products so we
- 4:31:21can actually let me call cury here and
- 4:31:25then we need to call um published so we
- 4:31:28added let's import the product so we
- 4:31:31added that
- 4:31:32scope published scope so we can select
- 4:31:37published products right here and then
- 4:31:41I'm going to call P inate on
- 4:31:44this uh let it be 12 and then I am going
- 4:31:48to return
- 4:31:50inertia
- 4:31:52render um let's use
- 4:31:58home um and we're going to pass
- 4:32:03products okay how however right here I'm
- 4:32:07going to use uh resource so for this let
- 4:32:11me create PHP artisan make
- 4:32:15resource product
- 4:32:18resource or because I want to use this
- 4:32:21to display listing of the product I'm
- 4:32:24going to use product list resource
- 4:32:26because the data what we are going to
- 4:32:29return into react what we're going to
- 4:32:31pass into react will be different for
- 4:32:34the listing and for the product Details
- 4:32:36page so we're going to create that under
- 4:32:39HTTP resources product list resource I'm
- 4:32:43going to come back to this resource and
- 4:32:44implement this
- 4:32:47but let's check
- 4:32:49the resources
- 4:32:52JS uh pages and we have this welcome
- 4:32:55which which I want to rename I'm going
- 4:32:58to call this
- 4:33:01home let's try to rename it in every
- 4:33:05place okay uh let's open home and right
- 4:33:11here uh we don't need this handle image
- 4:33:13error I'm going to remove this but down
- 4:33:15below I want to iterate over the
- 4:33:18products we're going to accept products
- 4:33:20right here we can remove this as well
- 4:33:23this as well so we're going to accept
- 4:33:24prop product iterate and for each
- 4:33:27product I also want to create a new
- 4:33:29component and I'm going to put this
- 4:33:31inside up let's call
- 4:33:35this product product item uh it should
- 4:33:41not be just six it should be TS6 so
- 4:33:43we're going to create typescript file
- 4:33:47product
- 4:33:51item okay maybe I was creating the same
- 4:33:54one product item uh TSX file okay rsf
- 4:34:01product item we're going to accept the
- 4:34:02props we're going to handle um this
- 4:34:06part okay cool and so we are going to
- 4:34:11work on the resource we are going to
- 4:34:13pass that data into home we're going to
- 4:34:16accept the data here then iterate here
- 4:34:19and render it nicely I'm going to change
- 4:34:23this part and use product list resource
- 4:34:26collection providing products right here
- 4:34:29because we are returning collection that
- 4:34:32is going to be an object and it's going
- 4:34:34to have data and couple of pagination
- 4:34:37related fields and we're going to get
- 4:34:40those products on the homepage right
- 4:34:43here however I'm going to Define new
- 4:34:47data type on the homage for these
- 4:34:51products for this I'm going to open
- 4:34:53index.
- 4:34:55D.S and right here let's define new type
- 4:34:59for product which will have an ID title
- 4:35:04slug price quantity image and user and
- 4:35:08Department as well okay and I'm going to
- 4:35:12also open this product list resource and
- 4:35:14I'm going to return the same type of
- 4:35:16data from here inside this two array so
- 4:35:19we need ID title slug price quantity
- 4:35:23image user which is the vendor user and
- 4:35:28Department as well however if we check
- 4:35:32product PHP do we have the relation to
- 4:35:35Department yes we do have so this is
- 4:35:39good now go into to home and we are
- 4:35:43going to use now these products right
- 4:35:45here and I think I also need to define a
- 4:35:49pagination type so here I'm going to
- 4:35:51Define this pagination props type of um
- 4:35:55type pretty much and this is um abstract
- 4:35:59definition and this gives us possibility
- 4:36:02to use the generics T right here and the
- 4:36:05data is array of T and in our case the
- 4:36:09product is going to be pagination props
- 4:36:14for product and we're going to import
- 4:36:16pagination props in
- 4:36:19product and now these products is going
- 4:36:22to be an instance of pagination props
- 4:36:25which will have data data will have will
- 4:36:28be an array of products okay and that
- 4:36:32pagination props will have additional
- 4:36:34Fields like links and meta but uh we
- 4:36:38don't need that at the moment and
- 4:36:40whenever we need that
- 4:36:42we can add this information um right
- 4:36:45here okay cool now inside inside this
- 4:36:48homepage we can start iterating over the
- 4:36:50product so down below I'm going to
- 4:36:52create one grid which will have some
- 4:36:54responsive t one CSS classes as well and
- 4:36:57pading and then I'm going to start
- 4:37:00iterating our products data we're going
- 4:37:03to get each product and I'm going to
- 4:37:05call product item okay and I'm going to
- 4:37:08provide two things right here I'm going
- 4:37:10to provide the product itself and the
- 4:37:13key as well for the product and
- 4:37:15obviously at the top we're going to also
- 4:37:17import this product item from the
- 4:37:19components up product item now let's
- 4:37:22open we're going to save this uh why do
- 4:37:26we have error on the homepage yeah
- 4:37:29because the product in key is not
- 4:37:30defined on the product item let's open
- 4:37:33Now product
- 4:37:35item and right here we are going to
- 4:37:38accept Now product as a prop which will
- 4:37:41be an instance of the product what we
- 4:37:43defined in the types right here so we're
- 4:37:47going to import that product and let's
- 4:37:49also import link we will need this
- 4:37:51inside the template now we're going to
- 4:37:54create card and that card is actually
- 4:37:56Daisy UI card we give it background and
- 4:38:00some Shadow as well then I'm going to
- 4:38:03create a link and that link will be to
- 4:38:07product Details page okay and we don't
- 4:38:11have that product show yet defined do we
- 4:38:14have uh I think we don't have that but
- 4:38:17we're going to Define this we don't have
- 4:38:19anything related to product defined yet
- 4:38:22but we're going to Define it okay but
- 4:38:24I'm going to use slug instead of the
- 4:38:28URL uh when uh accessing the product
- 4:38:32Details page okay so next we're going to
- 4:38:35put an image we're going to use product
- 4:38:37image we're going to use product title
- 4:38:39inside alt and give it some some um
- 4:38:42talin CSS classes like aspect square and
- 4:38:45object cover we're going to display the
- 4:38:48card body and inside we need the product
- 4:38:51title and we are going to display the
- 4:38:55information about the vendor as well
- 4:38:58product usern
- 4:38:59name um and let me show the product
- 4:39:03Department name as well so this is the
- 4:39:06product title which will be let's say
- 4:39:09mouse Logitech mouse Whatever by then
- 4:39:13we're going to have the vendor Name by
- 4:39:15zoraa okay and that vendor name um in
- 4:39:19the future will be a clickable link to
- 4:39:21the vendor Details page vendor profile
- 4:39:24page right now it moves into slash and
- 4:39:28it is also into a department which might
- 4:39:31be Mouse mous is as a department so that
- 4:39:35the department will also be something
- 4:39:37clickable in the future okay and then
- 4:39:39we're going to do card action
- 4:39:41at the bottom and uh inside card actions
- 4:39:44we're going to display edit to card
- 4:39:46button and we're going to display also
- 4:39:49cart the product
- 4:39:52price okay so if we go in the homepage
- 4:39:55the error is gone product item is ready
- 4:40:00resources ready controller is ready
- 4:40:02let's update no roots so on the home
- 4:40:05page instead of this welcome we're going
- 4:40:08to use Now product
- 4:40:12product
- 4:40:13controller class this is going to be
- 4:40:17index or we can call this home I think
- 4:40:21let's replace this import the qualifier
- 4:40:24with
- 4:40:25import uh let's remove unused Imports
- 4:40:28here and in the pr controller I'm going
- 4:40:31to change this into
- 4:40:38home okay now let's try to access to the
- 4:40:42homepage and have a
- 4:40:47look let's refresh it canot Rate
- 4:40:50Property ID on null this is
- 4:40:54coming where this is coming from why
- 4:40:56doesn't highlight that
- 4:41:02part user in
- 4:41:08Department product least resource 20
- 4:41:125 right
- 4:41:15here
- 4:41:18okay the
- 4:41:21product okay has created by let's go
- 4:41:24into product PHP and find
- 4:41:28the user okay we don't have relation
- 4:41:31defined to user and this is the thing um
- 4:41:35let's define this as the first relation
- 4:41:38right here user uh return return this
- 4:41:42belongs to user but the field is created
- 4:41:45by and let's give it return type as well
- 4:41:49belongs to refresh
- 4:41:54it okay we have an error that's probably
- 4:41:57typescript error click on errors okay
- 4:42:00product show is not defined which is
- 4:42:02logical I expected that let's go into
- 4:42:05product controller and Define empty
- 4:42:07function at the moment
- 4:42:10show we are going to accept product
- 4:42:13right here and then we will do something
- 4:42:16in the future but for now let's just
- 4:42:21Define uh root get we're going to access
- 4:42:26to a specific product product slash
- 4:42:30we're going to all the variable product
- 4:42:33we're going to access it by
- 4:42:35Slug and here we're using product
- 4:42:38controller show and the root name Will
- 4:42:41will be product show as
- 4:42:43well so this should be
- 4:42:47enough let's see now this error is gone
- 4:42:50this is something else and we see one
- 4:42:53product is displayed right here it has
- 4:42:56this product title image by vendor in
- 4:43:01electronics department we see price
- 4:43:03right here we need to format the price
- 4:43:05we will come back to this but if we go
- 4:43:08into product details and unpublish this
- 4:43:12into
- 4:43:13draft and refresh it we are not going to
- 4:43:16see anything because we are only
- 4:43:18selecting and displaying published
- 4:43:19products which is actually pretty cool
- 4:43:21it works as it should work now let's
- 4:43:26create let's create another core
- 4:43:29component in react components core and
- 4:43:33I'm going to call this
- 4:43:35component uh
- 4:43:37currency
- 4:43:40format
- 4:43:42js6
- 4:43:44okay now we have this currency format
- 4:43:46and I'm going to accept right
- 4:43:50here we're going to accept amount that
- 4:43:54needs to be formatted we are going to
- 4:43:57accept currency and we're going to
- 4:44:00accept
- 4:44:02local let's define the type as
- 4:44:05well so currency um amount will be
- 4:44:10number
- 4:44:13um currency is actually going to
- 4:44:16be uh string but I'm going to assign
- 4:44:20default value to currency and this is
- 4:44:22going to be USD so I'm going to make
- 4:44:25this currency to be actually optional so
- 4:44:28let me move this down and make this more
- 4:44:35readable okay like
- 4:44:38this and like this so we have now
- 4:44:42currency optional string and we have
- 4:44:45local which is going to be also optional
- 4:44:48and
- 4:44:49string and now inside this uh instead of
- 4:44:53div maybe I can direct directly return
- 4:44:58new Intel
- 4:45:01inl number format and we're going to
- 4:45:04provide local
- 4:45:06here and we're going to provide Style to
- 4:45:11be
- 4:45:12currency and we're going to provide
- 4:45:15currency to be the given currency and
- 4:45:19we're going to call format on
- 4:45:25amount okay with format the code nice
- 4:45:28now let's go into product item and
- 4:45:31instead of price we're going to
- 4:45:34use currency format amount product.
- 4:45:39price
- 4:45:42we save it and now we see price is
- 4:45:45formatted nicely I made comment all the
- 4:45:49changes what we had so far and that was
- 4:45:52actually product listing on the homepage
- 4:45:55and now I'm going to start working on
- 4:45:56product Details page let's open HTTP
- 4:46:00controllers product controller and we're
- 4:46:03going to implement this show method
- 4:46:05right here we're going to
- 4:46:07return inertia render
- 4:46:12product slash show and right here we're
- 4:46:16going to provide the product
- 4:46:18details and for this I'm going to
- 4:46:20actually create new resource so we have
- 4:46:23product list resource which contains
- 4:46:25only few information but product details
- 4:46:29resource or product resource need to
- 4:46:31contain much more information than this
- 4:46:34so let me execute PHP artisan make
- 4:46:39resource
- 4:46:41uppercase P product resource we're going
- 4:46:45to hit the enter product resource was
- 4:46:48created now here we are using this
- 4:46:50product resource providing the product
- 4:46:53correctly and
- 4:46:56optionally not optionally but I want to
- 4:46:59also provide uh the options so this is
- 4:47:03what I plan uh let me actually uh create
- 4:47:06this show first and I will show you
- 4:47:08exactly what I mean so first I need to
- 4:47:11Simply render something on the page so
- 4:47:14let's go into resources JS pages and I'm
- 4:47:18going to create new folder here um let's
- 4:47:21create new typescript file and this is
- 4:47:24going to be inside product folder and
- 4:47:26let's call this show so it created
- 4:47:29product folder show inside there rsf and
- 4:47:33this is called show okay cool let's
- 4:47:36remove this props from here this import
- 4:47:38of react is also not NE accessory and
- 4:47:42let's just write test at the moment okay
- 4:47:45so however we're going to accept right
- 4:47:47here product this is kind of something
- 4:47:50we know for sure and the
- 4:47:53product has type of
- 4:47:56product okay
- 4:47:59cool and let's go into web.php and I I
- 4:48:02think we have these root defined
- 4:48:04properly so we should be good
- 4:48:07let's click on this
- 4:48:11and it doesn't actually show the page
- 4:48:13let's have a
- 4:48:16look product by
- 4:48:22slug okay yeah I stopped the recording
- 4:48:26yesterday continue today so I have this
- 4:48:27mpm run Dev missing and let's also start
- 4:48:31PHP Artisan you
- 4:48:36listen Okay cool now let's see
- 4:48:43let's open Dev tools just in case we
- 4:48:45have some issues click on this okay this
- 4:48:48opens the product Details page and we
- 4:48:50see test right here um so this is now
- 4:48:53what I want to show to you what I want
- 4:48:55to implement so this page is going to
- 4:48:59render the product Details page and we
- 4:49:00will be able to choose different
- 4:49:03variations of the products like we
- 4:49:05defined in the
- 4:49:07interface from the admin panel
- 4:49:13click on this we have the variation
- 4:49:16types we have color size and the user
- 4:49:19will be able to choose different color
- 4:49:21and different different size of item and
- 4:49:23then add that into the product however I
- 4:49:26want to also Implement one very cool
- 4:49:29feature to preserve the URL when user
- 4:49:32makes some changes for example if I
- 4:49:34choose color black and size large I want
- 4:49:38that information to be saved in the URL
- 4:49:41so in the URL I plan to do something
- 4:49:44like this inside options query parameter
- 4:49:46which needs to be an array I'm going to
- 4:49:49add the variation type option ID like
- 4:49:53one uh option ID one we know that it
- 4:49:57refers to
- 4:49:59Black right so one refers to Black so
- 4:50:03option ID one
- 4:50:05and
- 4:50:07options second option let's say large
- 4:50:10six so we're going to exit six right
- 4:50:13here so these Q parameters options one
- 4:50:16and six will Define which variation type
- 4:50:20needs to be selected on the page so that
- 4:50:22whenever I copy the URL send it to my
- 4:50:24wife telling that hey I really like this
- 4:50:27black uh black large um T-shirt whatever
- 4:50:31uh what do you think about it so it's
- 4:50:33going to open the one what I selected in
- 4:50:36the variation options not the first one
- 4:50:37not the default one that's I think
- 4:50:40really useful feature and this is what
- 4:50:41I'm going to do as well so here I'm
- 4:50:45going to pass
- 4:50:48variation
- 4:50:51VAR variation
- 4:50:54options uh I have been traveling the
- 4:50:56entire day today six or seven hours I'm
- 4:50:59kind of tired then it's quite late right
- 4:51:03now and I'm recording options Okay cool
- 4:51:07so we're going to take th those options
- 4:51:10and if the options doesn't exist we're
- 4:51:11going to pass this um empty array uh why
- 4:51:15do we get right here this
- 4:51:18product new product okay this is
- 4:51:20different product
- 4:51:22resource no this is filament product
- 4:51:24resource this is something we don't want
- 4:51:27we
- 4:51:28want HTTP resources product resource
- 4:51:31Okay cool so now we get these options
- 4:51:33and passing these into the view so the
- 4:51:35variation options let's now go
- 4:51:38into this show
- 4:51:41T um TSX file and we're going to accept
- 4:51:43those those variation options
- 4:51:48which we can Define that variation
- 4:51:50options is an array of numbers so now
- 4:51:55right here we're going to print what is
- 4:51:57product and what is
- 4:52:00variation variation options let's have a
- 4:52:04look product let's refresh
- 4:52:09it okay so product actually has the data
- 4:52:12so I think we can remove that
- 4:52:14data
- 4:52:17um inside WP we're going to set this to
- 4:52:25false and we still have that data and
- 4:52:28then we have this entire thing right
- 4:52:31here which is the entire product thing
- 4:52:32so we're going to work on the product
- 4:52:34resource and we have these options here
- 4:52:37as well so now I think we're going to
- 4:52:39focus on this Source right here not this
- 4:52:42one
- 4:52:44but the product
- 4:52:47resource product resource from HTTP
- 4:52:53resources so like
- 4:52:56this so we're going to work on this
- 4:52:58product resource we're going to work on
- 4:53:00this show TSX and this show TS6 is going
- 4:53:03to also show a carousel of the images so
- 4:53:07inside components core I want to create
- 4:53:12a new TSX
- 4:53:15file let's call this Carousel
- 4:53:19TS6 and for the
- 4:53:21carousel we are going to use the
- 4:53:24carousel from the dais y so if we search
- 4:53:28caral right here we're going to find the
- 4:53:31correct example uh we are interested
- 4:53:35inside this one or this one where do
- 4:53:37have we need arrows as well so we have
- 4:53:39this controls okay so I think we can use
- 4:53:42this one which has the uh instead of the
- 4:53:44numbers right here we're going to use
- 4:53:46thumbnails so we render the thumbnails
- 4:53:49and uh we display the image when
- 4:53:51clicking on the thumbnail I think that's
- 4:53:53that's going to be pretty cool okay now
- 4:53:55let's focus on the actual
- 4:53:58work I'm going to remove these props
- 4:54:01right here remove this return and remove
- 4:54:05this react now on the carousel first
- 4:54:08let's import the image type which we are
- 4:54:10going to Define in the index. D.S file
- 4:54:15and here we're going to do a couple of
- 4:54:17other things as well so let's just
- 4:54:19Define image type and we're going to
- 4:54:21give it a number we're going to give it
- 4:54:24the different variations conversions of
- 4:54:27the images so we're going to have
- 4:54:29thumbnail we're going to have small
- 4:54:31we're going to have medium and large
- 4:54:34additionally on the product I am going
- 4:54:37to add variation types which is going to
- 4:54:41be array of variation types which we are
- 4:54:45going to also Define here and I'm going
- 4:54:48to also Define variations which is going
- 4:54:50to be also array and each variation from
- 4:54:54this array will have the following
- 4:54:56format it is going to have ID number
- 4:54:59variation type option IDs which will be
- 4:55:02array of numbers we're going to have
- 4:55:04quantity and price okay so now let's
- 4:55:10let's define variation type right here
- 4:55:15export type variation type and we're
- 4:55:19going to give it ID number we're going
- 4:55:23to give it name to be
- 4:55:26string we're going to give it type to be
- 4:55:29one of the three available types select
- 4:55:33or
- 4:55:34radio or
- 4:55:37image okay and I'm going to give it also
- 4:55:40options variation type has
- 4:55:44variation type option array of variation
- 4:55:48type options and I'm going to also
- 4:55:51Define export type variation uppercase
- 4:55:55fee variation type
- 4:55:57option cool now let's give it ID number
- 4:56:02give it name String give it images to be
- 4:56:07an array of image type which just
- 4:56:10defined and we're going to also have
- 4:56:13type of
- 4:56:16variation
- 4:56:18variation type okay cool however this
- 4:56:22type uh we know that the variation type
- 4:56:24option actually belongs to variation
- 4:56:27type so we can Define this if we need
- 4:56:29that if we don't need that we can omit
- 4:56:31this okay so on the product also we need
- 4:56:35a couple of more additional data so we
- 4:56:38add this variation types and variations
- 4:56:40but we also need a list of images so
- 4:56:43let's add images which is going to be or
- 4:56:47this is this is what I
- 4:56:50advise
- 4:56:52so we defined product list resource
- 4:56:56which has the following type right and
- 4:56:59we're going to Define product Resource
- 4:57:01as well which will have much more data
- 4:57:04so we can do something similar right
- 4:57:07here and we have this product and we can
- 4:57:09call this
- 4:57:10product and leave this as a product or
- 4:57:12we can rename this and call this product
- 4:57:16list item okay uh or we can add
- 4:57:20additional data right
- 4:57:22here so if we create new type and if we
- 4:57:26call this product list item and the new
- 4:57:28one will be product details as an
- 4:57:30example then the product list item can
- 4:57:33have much less data and product list
- 4:57:35item um sorry product list item can have
- 4:57:38much less data and product
- 4:57:40um item um product details needs to have
- 4:57:45um sorry yeah as I mentioned I have been
- 4:57:48TR traveling the entire day seven hours
- 4:57:51I was on the countryside on funeral and
- 4:57:54I'm a little bit tired so um sorry my
- 4:58:00apologies so in this specific case I
- 4:58:03just want to create a single type um I
- 4:58:06don't want to Define two different types
- 4:58:09for product list item and product so I'm
- 4:58:11going to combine them into a single type
- 4:58:13and we're going to have product images
- 4:58:17and with the variation types and
- 4:58:18variations here and I'm going to here
- 4:58:20add array of images as well
- 4:58:24okay and we also need
- 4:58:27description which is going to be
- 4:58:29string right here and I'm going to also
- 4:58:32add short
- 4:58:34description which is going to be also
- 4:58:36string we don't have short description
- 4:58:38in the database but we're going to
- 4:58:40generate that on a
- 4:58:43fly now let's go into Carousel so we
- 4:58:46defined the image we imported that image
- 4:58:48now we're going to Define images uh prop
- 4:58:51right here inside the props we're going
- 4:58:52to take out images which will be array
- 4:58:55of
- 4:58:56images then we're going to create the
- 4:58:59template which I actually copied from
- 4:59:02dayi so we use the following um element
- 4:59:05Flex item start Gap 8 so then inside
- 4:59:09here we're going to have a
- 4:59:11uh div so and this is going to be for uh
- 4:59:15thumbnails okay so I'm going to display
- 4:59:18thumbnails let's open the browser I'm
- 4:59:20going to display thumbnails on the left
- 4:59:22side okay and then on the right side
- 4:59:25we're going to have the actual large
- 4:59:27image just like Amazon does so we're
- 4:59:29going to have thumbnails like
- 4:59:33this okay cool um let's keep doing so
- 4:59:36then we're going to start iterating our
- 4:59:38images and and each image has as we saw
- 4:59:42right
- 4:59:43here uh those variations the conversions
- 4:59:47thumbnail small medium and large so now
- 4:59:50we're going to render the aex for
- 4:59:53thumbnails give it hre we're going to
- 4:59:55give it proper class name and give it
- 4:59:58also key inside there we're going to put
- 5:00:01the actual image tag with image
- 5:00:03thumb okay then down below we're going
- 5:00:06to create this csel and inside there
- 5:00:10we're going to start iterating our
- 5:00:11images second time and we're going to
- 5:00:13create divs with the ID the same string
- 5:00:17what we gave inside the H ref right here
- 5:00:20okay then we're going to give it also
- 5:00:22class name carousal item W full give it
- 5:00:25key and render image inside okay after
- 5:00:30this I think the carousel class is kind
- 5:00:33of ready and let me open product
- 5:00:36resource uh we Define the product
- 5:00:38additional properties right here and we
- 5:00:40need to return um this product from the
- 5:00:43product resource okay so we need ID we
- 5:00:47need Title we need slug description
- 5:00:49price quantity image
- 5:00:53okay additionally we need images array
- 5:00:56and we're going to access images array
- 5:00:58in the following way this get media
- 5:01:01images and we're going to map each media
- 5:01:04into something else and image right here
- 5:01:06is an instance of media model so then
- 5:01:10the uh we're going to take the media ID
- 5:01:13thumbnail small large so we don't even
- 5:01:17have medium do we actually have medium
- 5:01:21now I get
- 5:01:23curious uh let me check
- 5:01:27product.php we registered a couple of
- 5:01:30conversions right thumb small and large
- 5:01:34we don't have
- 5:01:36medium yeah that's correct so initially
- 5:01:40I I decided to have medium then I
- 5:01:42changed my mind so probably we shouldn't
- 5:01:46have medium here so I'm just going to
- 5:01:48remove that we are not going to have
- 5:01:50medium do we have this medium anywhere
- 5:01:53else
- 5:01:55written this is not related to image
- 5:01:58okay my
- 5:02:00bed go into product resource so we
- 5:02:03return thumb small large then we're
- 5:02:05going to continue and we are going to
- 5:02:07return the user information with the ID
- 5:02:09in name and we're going to return also
- 5:02:11Department information and we're going
- 5:02:13to return variation types as well so
- 5:02:17we're going to iterate over the
- 5:02:18variation types and we're going to
- 5:02:20return the variation type ID name the
- 5:02:23variation type itself whether it is
- 5:02:25Select radio image and we are going to
- 5:02:29also return options each variation type
- 5:02:32has multiple options and we're going to
- 5:02:34iterate over these variation options and
- 5:02:37map it into the following array ID name
- 5:02:41and each variation option might have its
- 5:02:45own set of images and just like we are
- 5:02:48taking product images right here in the
- 5:02:50same way we are going to take variation
- 5:02:54type options images so we we're
- 5:02:57accessing those images
- 5:02:59collection and we're going to return ID
- 5:03:02thumbnail small and
- 5:03:05large and finally we are going to also
- 5:03:08return variations with product
- 5:03:11variations for this we're going to
- 5:03:13return ID variation type option IDs
- 5:03:16which is going to be
- 5:03:18Json and quantity and
- 5:03:22price okay that giant product object
- 5:03:25will be pushed into show TS6 and this is
- 5:03:30the place we are going to access um that
- 5:03:34from the product right
- 5:03:36here now this file is a little bit
- 5:03:40complicated and also really interesting
- 5:03:43so you're going to bear with me so if
- 5:03:45you don't understand certain things
- 5:03:48immediately just repeat the video and
- 5:03:50I'm going to re explain also things in a
- 5:03:53more understandable way okay so this
- 5:03:57file will have a lot of functionality so
- 5:04:00we are going to prepare data uh for Ed
- 5:04:03to card functionality so in this
- 5:04:05component we're going to have Ed to card
- 5:04:06Button as well and the Ed to card fun
- 5:04:09functionality will also consider
- 5:04:11different variation options variation
- 5:04:14option IDs and we're going to send those
- 5:04:17variation option IDs alongside with the
- 5:04:19add to click because if we add
- 5:04:23green um headset in our cart then we
- 5:04:27want it to be green not the black one
- 5:04:29right so we're going to pass that
- 5:04:30additional variation type option IDs as
- 5:04:34well and we're going to also update the
- 5:04:37images section based on the selected
- 5:04:40option so a lot of things is going on in
- 5:04:42this object so in this component so bear
- 5:04:44with me as I mentioned so first we're
- 5:04:46going to define the form and that form
- 5:04:50will have option IDs which we're going
- 5:04:51to send to the server and the option IDs
- 5:04:54is going to be actually object where the
- 5:04:57key is going to be the
- 5:04:59variation type
- 5:05:03ID this one and the corresponding number
- 5:05:06will be the the option ID for that
- 5:05:10variation type so if we have a look at
- 5:05:12our example if the ID for the color is
- 5:05:15one and the ID for Blake is one as well
- 5:05:20so we are going to send on the server H
- 5:05:23Json let me open now scratch file a
- 5:05:28Json like
- 5:05:31this one which is going to be actually
- 5:05:33string one one so one variation type ID
- 5:05:38has the corresponding variation type
- 5:05:40option ID added into the cart so
- 5:05:42additionally we're going to give it also
- 5:05:44quantity and the price is um kind of
- 5:05:48optional so we're going to still pass
- 5:05:49the price and that price uh can be used
- 5:05:53on the back end or if we don't provide
- 5:05:55any price we can take it or take the
- 5:05:57default price um as well from the server
- 5:06:00okay but the price might be different
- 5:06:03based on which variation option we're
- 5:06:06going to choose right so that's why
- 5:06:08we're going to send the prices as
- 5:06:11well so next uh we're going to Define
- 5:06:14the types so these are actually um types
- 5:06:18for our form now we're going to assign
- 5:06:20default value so option IDs is going to
- 5:06:22be object quantity is going to be one
- 5:06:24price is going to be null and we're
- 5:06:26going to implement that to populate the
- 5:06:28price on the variation uh option
- 5:06:31change next we're going to Define we're
- 5:06:34going to take the URL from the current
- 5:06:36page um and uh the use form and use page
- 5:06:39P needs to be imported and we're going
- 5:06:40to do it after I finish the code right
- 5:06:43here so we're going to take the URL and
- 5:06:46we will use that URL when we change the
- 5:06:49option so when we change the option
- 5:06:51remember so in the URL we're going to
- 5:06:53have those options right here and those
- 5:06:57options will be updated when we start
- 5:06:59clicking on different options right here
- 5:07:02that's why we take the current URL and
- 5:07:04push the options qer parameter inside
- 5:07:07that URL by the way I mentioned that
- 5:07:09that op options needs to be a plain
- 5:07:11array like this this is what I
- 5:07:15mentioned but actually I improved that
- 5:07:18part as well and instead of having these
- 5:07:20options as plain array of one and six
- 5:07:23I'm going to also use variation type ID
- 5:07:26here so variation type ID like one is
- 5:07:29the color has
- 5:07:32um option one and variation type two has
- 5:07:37um id6 so these are the options um I
- 5:07:42want to add I want to view right now at
- 5:07:44the moment on on the screen okay hit the
- 5:07:47enter we see that the URL will be
- 5:07:48updated it's going to be encoded I think
- 5:07:51no it wasn't anyway okay so next we are
- 5:07:54going to Define state in that state is
- 5:07:56going to be selected options so we might
- 5:07:59have uh only one variation type or maybe
- 5:08:03more like in our case we have two
- 5:08:05variation types color and size and we
- 5:08:08might even have three or four so all
- 5:08:10these selected options will be saved
- 5:08:13right here in the selected options and
- 5:08:15this is going to be actually an array
- 5:08:17okay um array of certain things and this
- 5:08:21is um what I'm going to uh Define so
- 5:08:25these selected options will be an array
- 5:08:28where the key is going to be number and
- 5:08:31that number is going to be variation
- 5:08:33type ID like we had right here one but
- 5:08:38the value is going to to the entire
- 5:08:40variation type option what we already
- 5:08:42have defined right here and that
- 5:08:45variation type option will have ID name
- 5:08:48images and type as well but I think we
- 5:08:50are not going to use type uh if we don't
- 5:08:52use it I'm going to remove the type but
- 5:08:54the main thing is that the variation
- 5:08:56type will have ID name and images and
- 5:08:58we're going to use these three
- 5:09:00properties from this variation type
- 5:09:02option okay cool
- 5:09:05then whenever the product and select
- 5:09:09options will be changed either product
- 5:09:12or selected options will be changed I
- 5:09:14want to calculate the images okay and
- 5:09:18for this I'm using this use memo hook
- 5:09:21I'm going to calculate the images and
- 5:09:23return those images so if the current
- 5:09:27product has no images no sorry if the
- 5:09:31current product has no variation types
- 5:09:34then we take the images from the current
- 5:09:37product images area
- 5:09:40right however if the current product has
- 5:09:43variation types and some of the
- 5:09:45variation type has its own
- 5:09:48images uh those variation the images are
- 5:09:53um actually inside the variation type
- 5:09:55options right so we have black option
- 5:09:58and black option has images so right
- 5:10:00here we're going to calculate and return
- 5:10:02the corresponding images okay let me
- 5:10:04finish this and I think this will get
- 5:10:06very clear so we're going to iterate
- 5:10:08over selected options we're going to get
- 5:10:11the key so inside the selected options
- 5:10:13the uh key will be type ID and we're
- 5:10:16going to have object variation type
- 5:10:17option we're going to take the option
- 5:10:19from the selected options and now we're
- 5:10:22going to do the following so if option
- 5:10:23images length is more than zero so if
- 5:10:27option has a li images then we are
- 5:10:30returning these option images as the
- 5:10:32product images however if the uh option
- 5:10:35doesn't have Imes finally at the end of
- 5:10:37this for Loop we are going to return
- 5:10:40product
- 5:10:42images all right and just like this
- 5:10:44we're going to have always uh calculated
- 5:10:47images if nothing is selected no option
- 5:10:50is selected however if there are some uh
- 5:10:53variation types defined like as an
- 5:10:56example color and size we're going to
- 5:10:59always select the first option so it is
- 5:11:02going to always pick up the first option
- 5:11:05corresponding images all right okay okay
- 5:11:09cool uh also yeah one additional thing
- 5:11:12you should also keep in mind is that we
- 5:11:15added
- 5:11:16those uh images to options like we added
- 5:11:19this into black blue purple but we
- 5:11:22didn't add those into other options like
- 5:11:26for small or medium or large so in
- 5:11:31theory if we make this even more complex
- 5:11:34scenario so you might also need to to
- 5:11:40upload different images for different
- 5:11:43combinations of variation types like we
- 5:11:47defined um different quantity and price
- 5:11:50for blue small you might want to upload
- 5:11:53different images for blue small and
- 5:11:55different images for black small and
- 5:11:57different images for black medium and
- 5:12:01all these kind of things and we we can
- 5:12:03do this of course everything is possible
- 5:12:05in programming just um I didn't decide
- 5:12:07to do this because I didn't want to make
- 5:12:09this even more complex so it is not also
- 5:12:13very common to have uh even Amazon has
- 5:12:16like when I checked in different cases
- 5:12:19has only one set of images which is
- 5:12:22dependent on one variation type it's not
- 5:12:25depending on multiple variation types
- 5:12:27maybe there are some cases on Amazon as
- 5:12:29well but we aren't Amazon right so we
- 5:12:31can't build uh something like Amazon in
- 5:12:33in like one video tutorial so it's a
- 5:12:37slightly simpler it can be even more
- 5:12:40complicated just I wanted to mention to
- 5:12:42you how you can make this even more
- 5:12:45complex so in our case if we have inside
- 5:12:47selected options let's say black and
- 5:12:50small we know that uh only one option
- 5:12:53will have images and the first case
- 5:12:56whenever we catch that that specific
- 5:12:58option has images we are returning those
- 5:13:00images so we don't want to check second
- 5:13:02option because we are just interested as
- 5:13:05soon as we find some options in the uh
- 5:13:08variation of options so in our case
- 5:13:11again if we
- 5:13:13upload images on black and if we upload
- 5:13:17images on small as well
- 5:13:21so I one of them will be displayed so
- 5:13:24both of them obviously will not be
- 5:13:26displayed if you select black and small
- 5:13:28the first one right here whichever it's
- 5:13:31going to be we don't know it might be
- 5:13:32small it might be black the
- 5:13:34corresponding images will be
- 5:13:37returned okay I I think
- 5:13:39this is clear we can move on the next
- 5:13:41part and we're going to see what is this
- 5:13:42images as well and how it gets updated
- 5:13:46the next one is that we are going to
- 5:13:47also listen to this product and selected
- 5:13:50options uh second time but in this case
- 5:13:52we are going to return uh computed
- 5:13:56product data and this is necessary for
- 5:13:59price and quantity we have the default
- 5:14:01price and quantity on the product level
- 5:14:04but for different variation options we
- 5:14:06overwrite the price and quantity right
- 5:14:09so here we take the selected option IDs
- 5:14:14so we know that selected options is a
- 5:14:17map where the key is the type ID and the
- 5:14:21um option the value is the variation
- 5:14:24type option so we get the values all
- 5:14:26values here then we call map and get the
- 5:14:29option ID and then we sort that so
- 5:14:32finally inside selected option IDs we're
- 5:14:34going to have always sorted option IDs
- 5:14:38like one and five one and six three and
- 5:14:43five whatever okay so we have that
- 5:14:45selected option idas next is I'm going
- 5:14:47to iterate over product variations so
- 5:14:51product variations is the variations
- 5:14:55what is already defined on the product
- 5:14:58and we have assigned some quantity and
- 5:15:03price this might be also null or empty
- 5:15:06array not null but empty array if we
- 5:15:09decided that we don't want to override
- 5:15:11price and quantity for different
- 5:15:13variation uh variation types then we are
- 5:15:17not going to Define this and the data
- 5:15:19inside product variations table will be
- 5:15:22empty for that specific product and thus
- 5:15:25this will be an empty array if it's an
- 5:15:27empty array it's not a problem it is
- 5:15:29going to take the default product
- 5:15:30quantity and price but if it's not an
- 5:15:33empt array we take the variation and we
- 5:15:36get the variation uh type option IDs and
- 5:15:40sort this as well so we have selected
- 5:15:43option IDs here we
- 5:15:46have uh existing variations type option
- 5:15:50IDs here sorted as well and I want to
- 5:15:52compare now this option IDs into this
- 5:15:56and if they match then I want to take
- 5:15:59the price and quantity from that
- 5:16:00specific variation so I'm going to
- 5:16:03create new function uh arrays are equal
- 5:16:08arrays are equal and I'm going to do
- 5:16:10this inside a new file now which simply
- 5:16:13will compare two arrays like selected
- 5:16:16option IDs and option IDs okay so let's
- 5:16:21imagine that that function already
- 5:16:24exists in one of the files and it does
- 5:16:27the work so it Compares two arrays this
- 5:16:30and this and if they are the same array
- 5:16:33then we're going to do something so if
- 5:16:36they are the same array then we are
- 5:16:37returning the variation price and
- 5:16:39variation quantity however if the
- 5:16:42variation quantity is null it means that
- 5:16:44we have that specific variation with
- 5:16:46unlimited quantity so we're going to
- 5:16:49return number max value otherwise we are
- 5:16:52going to return the variation quantity
- 5:16:54if it is not
- 5:16:56null however after this for Loop if the
- 5:17:00matching wasn't happened then we are
- 5:17:03returning the product price and product
- 5:17:06quantity okay cool now we have this
- 5:17:08imputed product which we're going to use
- 5:17:11in the template will contain price and
- 5:17:14quantity for the selected variation
- 5:17:18options cool next we are going to listen
- 5:17:22to mounted hook and on mounted we're
- 5:17:24going to iterate over the variation
- 5:17:26types and this is what I am going to do
- 5:17:30so from the existing variation options
- 5:17:33that variation options it is what we
- 5:17:35give from the component what we actually
- 5:17:37have in the
- 5:17:39URL right here so we pass those
- 5:17:42variation options from the controller on
- 5:17:45controller we take this from request so
- 5:17:47whatever we have written here like one
- 5:17:50corresponds to one two corresponds to
- 5:17:52six that will be these variation options
- 5:17:57so now what we do here is to take the
- 5:18:01selected option ID from this variation
- 5:18:03options but variation options might be
- 5:18:06also an empty uh object okay or empty
- 5:18:10array so we provide default value as
- 5:18:13array right here so it might be empty uh
- 5:18:16object or array so when we try to take
- 5:18:18type ID from that uh array actually is
- 5:18:21also object in JavaScript when we try to
- 5:18:24take this type ID from this variation
- 5:18:27options if it's empty the selected
- 5:18:29option ID will be
- 5:18:30null if there is something like what we
- 5:18:34have right now and if we also have one
- 5:18:37variation type ID then for one this is
- 5:18:41going to return one as well so if um
- 5:18:46type is two it is going to return six
- 5:18:51and actually we are doing this for all
- 5:18:52the available variation types so in this
- 5:18:54specific case for this specific URL so
- 5:18:57it is going to iterate over the
- 5:18:58variation types and we know that we have
- 5:19:00two variation types for our product um
- 5:19:03with ID one and two and for both of them
- 5:19:07we're going to get the variation option
- 5:19:09ID and then we're going to set that
- 5:19:11variation option so let's print this
- 5:19:14selected option ID and we're going to
- 5:19:15also print the type options but after
- 5:19:18this uh we're going to call the function
- 5:19:21which we're going to create choose
- 5:19:23option so we have now type ID and we are
- 5:19:28going to choose specific option and that
- 5:19:31specific option we're going to Peck from
- 5:19:34the type options type options is array
- 5:19:37of objects we know we Define this right
- 5:19:41here uh right here so using array find
- 5:19:45we are going to try to find the option
- 5:19:48with the selected option ID what we have
- 5:19:51right now selected in the URL like if we
- 5:19:54have selected in the URL six we are
- 5:19:56going to try to find the
- 5:19:58six uh corresponding option
- 5:20:02object okay so we are passing inside
- 5:20:04this choose option three arguments first
- 5:20:06is the type ID second second is the
- 5:20:09option and third is whether we want to
- 5:20:12update the URL right now or not so
- 5:20:15because we are doing this on mounted
- 5:20:17hook we don't want the URL to be updated
- 5:20:20because we are actually reading this
- 5:20:21from the URL right here through this
- 5:20:24variation types but in another place
- 5:20:26when we call choose option whenever we
- 5:20:28click on the specific option we want to
- 5:20:31update the URL so in the second place we
- 5:20:33are going to pass uh true right here in
- 5:20:36this choose option so if the option was
- 5:20:39not found for some reason and that some
- 5:20:42reason might be that we might not have
- 5:20:44anything in the URL like if we delete
- 5:20:47this the URL might look like this in
- 5:20:49which case selected option ID is
- 5:20:51actually empty so and finding the option
- 5:20:55will not work in which case we will
- 5:20:57simply take the first option from type
- 5:21:01options
- 5:21:02cool now next so this was mounted hook
- 5:21:07next we're going to create create that
- 5:21:09get option IDs map that is additional
- 5:21:11helper function which we are going to
- 5:21:14actually
- 5:21:16use so we are going to get the new
- 5:21:20options object as an argument and we're
- 5:21:23going to do the following so we are
- 5:21:25going to call object entries on this new
- 5:21:29options and this is going to actually
- 5:21:32return uh the new options will be type
- 5:21:36it's going to be object where key is
- 5:21:38going to be the type ID and the value is
- 5:21:42go going to be the entire object so
- 5:21:44these new options will have the same
- 5:21:46format as selected
- 5:21:49options okay and we know that the
- 5:21:51selected
- 5:21:52options selected options is something
- 5:21:55like this let me show this to you we we
- 5:21:57we covered this but uh if it's not clear
- 5:22:00I'm going to make this very clear so
- 5:22:01selected options will have ID one and
- 5:22:04its corresponding entire object like the
- 5:22:08object with will have
- 5:22:09ID because this is Json let's make it
- 5:22:12string but we know that the ID is number
- 5:22:14so ID uh let's say one and its
- 5:22:19corresponding name is going to be
- 5:22:23black and uh its corresponding images as
- 5:22:27well so this is going to be uh the
- 5:22:30option so down below from this um get
- 5:22:33option IDs map so we're calling uh
- 5:22:37object entries on this new options which
- 5:22:40converts that into entries then we are
- 5:22:43calling a map on that and we are
- 5:22:46returning this a unchanged which is
- 5:22:50going to be type ID but B is the entire
- 5:22:54object right so we are actually taking
- 5:22:57only ID from this object so after then
- 5:23:00again we call this from entries so after
- 5:23:03this get option IDs map the following
- 5:23:06type of object will be converted
- 5:23:09into something like this okay so instead
- 5:23:14of that object we are mapping into the
- 5:23:16ID only so this is going to be get
- 5:23:19option IDs map so after which now let's
- 5:23:23define this choose option what we
- 5:23:25already used right here so inside choose
- 5:23:28option we're going to accept three
- 5:23:29arguments type ID option and updates
- 5:23:32rouer or Not by default it's going to be
- 5:23:34true and now this is what we are going
- 5:23:37to do we're going to call set selected
- 5:23:40options we are uh providing callback
- 5:23:43here inside the Callback we accept the
- 5:23:45previous selected
- 5:23:47options then we are going to create
- 5:23:50construct this new options which is
- 5:23:52going to be previous options merged with
- 5:23:56the current option what we are trying to
- 5:23:59select what we are trying to choose
- 5:24:01right now so we are using the type ID as
- 5:24:05a key and the entire object as value so
- 5:24:07now have this new new options and if the
- 5:24:10update router is true then we are using
- 5:24:14that current URL which we took at the
- 5:24:17beginning of this component right here
- 5:24:19from this page so and we are calling
- 5:24:22rotor get on that URL and we're
- 5:24:25providing such type of options so we
- 5:24:29know that new options is um ID matched
- 5:24:33on the entire object but on the URL
- 5:24:37inside the URL we want only object
- 5:24:39something like this so we are calling
- 5:24:41this get option IDs map on the new
- 5:24:43options and putting giving this inside
- 5:24:45the URL additionally I'm going to also
- 5:24:47give preserve scroll true and preserve
- 5:24:50State true this is inertia JS um
- 5:24:54parameters and that basically will not
- 5:24:56update the URL and it's going to
- 5:24:58preserve also uh currently selected
- 5:25:02option SEL selected State inside the
- 5:25:06component okay cool rotor is also needs
- 5:25:08to be imported we're going to import
- 5:25:10this um after we finish writing this
- 5:25:12code so next so and finally because
- 5:25:16we're calling actually set selected
- 5:25:18options here from this set selected
- 5:25:21options we are going to return this new
- 5:25:23options because uh inside the set
- 5:25:26selected options you can either provide
- 5:25:27the op the options itself or a call
- 5:25:30function and uh inside the call function
- 5:25:32you're going to return something that
- 5:25:34needs to be assigned to the set selected
- 5:25:37options
- 5:25:39next we are going to Define additional
- 5:25:41functions and we're going to listen on
- 5:25:44quantity change so whenever quantity is
- 5:25:47changed uh we are so obviously we
- 5:25:50haven't even created that quantity uh
- 5:25:54component but uh that's going to be a
- 5:25:56select HTML select element so when the
- 5:26:00quantity is changed this is what we are
- 5:26:02going to do inside the form we are going
- 5:26:04to update the quantity data and we're
- 5:26:07going to par that even Target value
- 5:26:09that's it it's not complicated so this
- 5:26:12is all what we're going to do so we're
- 5:26:14going to also listen to Ed to cart
- 5:26:17button and
- 5:26:19whenever excuse me whenever that happens
- 5:26:21whenever we click on the button we're
- 5:26:23going to send post request to the
- 5:26:26following root which we're going to
- 5:26:28Define of course so we have a lot of
- 5:26:30things to Define but I want to focus on
- 5:26:32this file because I think this file is
- 5:26:35um one of the most complicated so far
- 5:26:40so in this um form post we're providing
- 5:26:43the URL and the product ID but we're
- 5:26:46going to also provide these preserve
- 5:26:48scroll and preserve State parameters
- 5:26:51okay that's for it to cart and we're
- 5:26:53going to just log something in case of
- 5:26:55error now I'm going to create uh two
- 5:26:59more functions and one of them is going
- 5:27:01to be to render product variation types
- 5:27:04and second is going to render AED to
- 5:27:07card button so this is going to be
- 5:27:10really interesting this is slightly
- 5:27:12easier and
- 5:27:14straightforward so I will in Implement
- 5:27:17these functions later and now I'm going
- 5:27:21to do one last thing uh right here
- 5:27:23before I move into the template I want
- 5:27:26to um basically watch at the selected
- 5:27:29options and whenever that changes I want
- 5:27:33to take those selected options and I
- 5:27:37want to create ID map of that selected
- 5:27:40options and I want to print that map and
- 5:27:43I want to put that inside option IDs as
- 5:27:46well so I'm doing something similar what
- 5:27:52has been
- 5:27:54done let's have a look right here
- 5:27:57through this method get option IDs map
- 5:28:00and I was using that get option IDs
- 5:28:03map um
- 5:28:08right here okay but um here I am doing
- 5:28:13this because I want to update the form
- 5:28:15option ID is data okay and basically I'm
- 5:28:20reading this selected options then
- 5:28:22mapping this um we are providing right
- 5:28:25here um actually let me let me redo this
- 5:28:30and re explain this so first we call
- 5:28:33this object entries we convert this into
- 5:28:36entries we get right here type ID and
- 5:28:39option uh we also Define the types the
- 5:28:42type ID is string option is variation
- 5:28:44type option and then we're calling this
- 5:28:47map uh we return type ID and we return
- 5:28:50option ID so we're converting this into
- 5:28:53this okay and finally we're going to
- 5:28:56call object entries from entries right
- 5:28:58here which converts this into ID's map
- 5:29:00so we'll Lo log this ID's map and we
- 5:29:02assign this into option ID so whenever
- 5:29:04we submit the form after this it is
- 5:29:06going to send the following data into
- 5:29:08the server on the backand side now I'm
- 5:29:11going to focus on the template so we use
- 5:29:13the authenticated layout we're going to
- 5:29:15Define this head actually it is home
- 5:29:18right here which probably I copied from
- 5:29:20home but I'm going to change this as
- 5:29:22well okay for now let's leave it because
- 5:29:24if I change something I will not be able
- 5:29:26to actually um quickly paste the the the
- 5:29:30code right
- 5:29:32here so then I'm going to create this
- 5:29:34Con container with t and CSS classes
- 5:29:37inside here I'm going to create
- 5:29:39additional div okay and then with call
- 5:29:43SP 7 so we're going to have the left
- 5:29:45side area and the right side area Okay
- 5:29:48the right side area is going to be where
- 5:29:51we display the A2 C uh button and uh the
- 5:29:56variations okay similar to how Amazon
- 5:29:59does it so we defined the 12 column grid
- 5:30:03on the large screens the left side is
- 5:30:05seven the right side is going to be five
- 5:30:08in the left side we have this Carousel
- 5:30:10of images on the right side we're going
- 5:30:11to have uh the product title we're going
- 5:30:14to have uh the uh price for the product
- 5:30:19and we're going to render the product
- 5:30:21variation type so we are using that
- 5:30:23function which needs to be implemented
- 5:30:26and also we're going to render the um
- 5:30:29we're going to render the like alert
- 5:30:32message if the quantity of the product
- 5:30:35is less than 10 so if the quantity is
- 5:30:37not undefined and if it's less than 10
- 5:30:41then we're going to render something
- 5:30:43with text error that only whatever is
- 5:30:47quantity left so if there are less than
- 5:30:5010 items like if seven so only seven
- 5:30:53items left seven left or something like
- 5:30:56this so this is just information to the
- 5:30:59user after this I'm going to render a to
- 5:31:02cart button and we're going to have also
- 5:31:06um section for the about this item is
- 5:31:08going to be description similar to how
- 5:31:10Amazon does we can have a look again
- 5:31:13here so we're going to have the title
- 5:31:15we're going to have price the
- 5:31:17variations here and then we're going to
- 5:31:20have this about this item
- 5:31:23description
- 5:31:26okay so inside here I'm going to create
- 5:31:28div with what you see like we seewig
- 5:31:32output and I'm going to Dangerously set
- 5:31:35a inner HTML which is going to be
- 5:31:38product description so if you don't know
- 5:31:40what this actually does it renders HTML
- 5:31:45properly okay uh it doesn't encode
- 5:31:49without that dangerously set in your
- 5:31:50HTML if I directly render the product
- 5:31:53description it is going to show the uh
- 5:31:56less than and greater than symbols for
- 5:31:59HTML TXS it is not going to render it
- 5:32:02properly so we want the Bold tags or
- 5:32:05lists or something like this to be
- 5:32:08rendered nicely and
- 5:32:10properly okay we're going to move and
- 5:32:12now we we are I think done on the
- 5:32:15template and I'm going to focus on these
- 5:32:17two functions render product variation
- 5:32:19types so here we're going to iterate
- 5:32:21over the variation types and we are
- 5:32:25going to create deal with the type ID
- 5:32:27we're going to display the type name
- 5:32:29which is going to be color or size then
- 5:32:33we are going to check if the type equals
- 5:32:35image then we're going to render your
- 5:32:39thumbnails just like Amazon
- 5:32:41does okay so here we're going to create
- 5:32:45div uh and then we're going to iterate
- 5:32:48over
- 5:32:49options and because we know that the
- 5:32:52type is images we expect images will be
- 5:32:55uploaded here so option will have some
- 5:32:57images so this is what we are doing so
- 5:33:01we we are also adding onclick listener
- 5:33:03to the Steve so whenever we click on
- 5:33:05that uh image like we doing Amazon so we
- 5:33:09want to update the option so Amazon does
- 5:33:11this on Hover as well but we're going to
- 5:33:13actually do this only on click okay so
- 5:33:18we we call this choose option provide
- 5:33:19the type ID and the
- 5:33:22option well let's give it key as well
- 5:33:25next if the option images exists then we
- 5:33:29display the first image from the option
- 5:33:32images okay and we're going to give it
- 5:33:36classes as well with with 50 pixel and
- 5:33:40if that specific option is selected so
- 5:33:43if inside selected options for the given
- 5:33:49type uh there exists something and its
- 5:33:52ID equals the option ID it means that
- 5:33:56this specific option is actually
- 5:33:59selected and if it is selected we give
- 5:34:01it outline outline four outline primary
- 5:34:04CSS classes otherwise we give it empty
- 5:34:07class classes so that if basically means
- 5:34:10that if that option uh is added inside
- 5:34:14selected
- 5:34:16options uh for that specific type
- 5:34:18ID cool after
- 5:34:24this we are going to handle the second
- 5:34:28type as well so we handled this for Type
- 5:34:31image but the second type what we have
- 5:34:34is radio so if the type equals radio
- 5:34:37then we create this div and that
- 5:34:40actually is um going to be so we have
- 5:34:45that join edit here so let me show this
- 5:34:47to you from da UI so we're going to use
- 5:34:53join which is this okay so if we check
- 5:34:58um I think we don't have that primary
- 5:35:00image example but that that is it and we
- 5:35:03can
- 5:35:06use radio so join radio inputs with
- 5:35:10button style so these are actually radio
- 5:35:12buttons But whichever is chosen it
- 5:35:15changes the color so exactly this is
- 5:35:17what I am going to do in my case so I'm
- 5:35:20using this join item so now so I created
- 5:35:23this D with join and I'm going to
- 5:35:25iterate other options and I'm going to
- 5:35:28create this um input uh and I'm going to
- 5:35:31listen its change whenever it it's it's
- 5:35:35going to be changed then I call this
- 5:35:38choose option with the type ID and the
- 5:35:42option and we're going to give it also
- 5:35:44key and give it some tal C classes join
- 5:35:48item button type radio value option ID
- 5:35:52it's going to be the value and whether
- 5:35:54it is going to be checked or not it
- 5:35:56really depends on if the option ID is
- 5:36:00inside selected options for the given
- 5:36:02type so this selected check is done in
- 5:36:06the same way we did for image right here
- 5:36:10okay and we're going to also give it a
- 5:36:12name and we're going to give it the name
- 5:36:14basically needs to be the same for all
- 5:36:16the inputs because we are going to
- 5:36:18render multiple um inputs uh one for
- 5:36:22each option but all of them will be for
- 5:36:24the same type ID okay and the name will
- 5:36:26be variation type with a type ID of same
- 5:36:29name and area label so after which we
- 5:36:33can move onto the last method which is
- 5:36:36render Ed to card button so we create
- 5:36:39the div we're going to create the select
- 5:36:41with the value form data quantity and
- 5:36:43we're going to listen on change whenever
- 5:36:45this happens we call this on quantity
- 5:36:47change which is a very straightforward
- 5:36:49method so we simply set inside the
- 5:36:51quantity even Target value next we're
- 5:36:54going to add the uh class name which is
- 5:36:56the da UI CSS classes and here we're
- 5:37:00going to create like empty array with
- 5:37:03the length of Maximum 10 so array from
- 5:37:07accepts an object here and we provide
- 5:37:10the length and the length will be
- 5:37:12minimum of 10 and whatever is the
- 5:37:14computed product quantity computed
- 5:37:17product we know that is a
- 5:37:19calculated uh object with a price and
- 5:37:22quantity and it he's also considering
- 5:37:25the currently selected variation types
- 5:37:28so and we take the minimum 10 so we
- 5:37:31don't want more than 10 so and we use
- 5:37:34this to iterate over that and create op
- 5:37:37options maximum 10 options so we have
- 5:37:40value I +1 key I +1 and inside text
- 5:37:44we're going to have also quantity I + 1
- 5:37:48okay so we're going to have quantity 1
- 5:37:49quantity 2 quantity 3 and so on maximum
- 5:37:5210 even if the uh available quantity is
- 5:37:57100 but if the available quantity is
- 5:37:59five is going to pick up the minimum
- 5:38:02which is going to be five and in this
- 5:38:03case we're going to see only quantity
- 5:38:05from 1 to five and find finally we're
- 5:38:07going to put a button uh with ADD uh to
- 5:38:11cart text and add to cart Handler as
- 5:38:14well which is also implemented which
- 5:38:15sends the request to the server with the
- 5:38:17cart store so I think um I think we are
- 5:38:23done here so we did the whole work um it
- 5:38:27took a lot of time but I wanted to make
- 5:38:29this very very clear so now we are about
- 5:38:32to import some of the things so use form
- 5:38:36use page page with alt and enter I'm
- 5:38:39importing these things use State we need
- 5:38:42use memo all these hooks variation type
- 5:38:46option oops
- 5:38:49variation type
- 5:38:53option
- 5:38:55H we have that defined
- 5:39:02here variant type variant type option
- 5:39:06okay variant
- 5:39:10variant type
- 5:39:12option okay let me call this variation
- 5:39:15type
- 5:39:17option okay cool uh that was imported I
- 5:39:21guess so arrays are equal okay I'm going
- 5:39:24to do this last thing because I'm going
- 5:39:25to create new file for this I'm going to
- 5:39:27import this use
- 5:39:29effect uh variation type option I'm
- 5:39:32going to use the same thing right here
- 5:39:34let's import rotor from inertia Js SL
- 5:39:38react that was
- 5:39:41imported uh variation type option I'm
- 5:39:43going to use that variation type option
- 5:39:45here authenticated layout needs to be
- 5:39:49imported uh head needs to be imported
- 5:39:53from inertia JS react and I'm going to
- 5:39:58change this into a product details
- 5:40:02product details and we can even display
- 5:40:06the specific specific um text for that
- 5:40:09product like sorry I mixed that with
- 5:40:12view syntax uh so here we can
- 5:40:15have um product dot
- 5:40:19title we can give it the title as well
- 5:40:23um we're going to import the carousel
- 5:40:26I'm going to import the currency
- 5:40:28format and everything is imported
- 5:40:32except that one method which is arrays
- 5:40:37are
- 5:40:40equal now inside JS folder I'm going to
- 5:40:45create new file a new typescript file
- 5:40:49and I'm going to call this
- 5:40:51helpers and right here I'm going to
- 5:40:54paste a function and I'm going to
- 5:40:56explain that function okay so arrays are
- 5:41:00equal export constant arrays are equal
- 5:41:02we accept two arrays array one and array
- 5:41:05two and these arrays can have have any
- 5:41:07types so I'm providing any right here so
- 5:41:12if the lengths are different it means
- 5:41:14obviously that the arrays are not equal
- 5:41:17they are not same so we immediately
- 5:41:20return false okay however we iterate the
- 5:41:24first array so in this case we iterate
- 5:41:26the first array but you can iterate
- 5:41:28actually the second array as well first
- 5:41:30so we iterate the first array and we are
- 5:41:34checking that on the same index in the
- 5:41:37second array if the value is the same as
- 5:41:42the value inside the first
- 5:41:44array And if every value using this
- 5:41:48every method if every value for every um
- 5:41:52such element that condition is satisfied
- 5:41:56then the arrays are equal okay now we
- 5:42:00are going to import that arrays are
- 5:42:02equal and there are no errors in this
- 5:42:05file that's so awesome
- 5:42:07uh there will be only one error through
- 5:42:10this because of this cart store okay so
- 5:42:14this is something we are going to
- 5:42:16implement a little bit later but for
- 5:42:21now for now let me just open web.php and
- 5:42:25I'm going to
- 5:42:27create um
- 5:42:30rot
- 5:42:32post
- 5:42:34cart SL store for the
- 5:42:40product we passed the product ID so we
- 5:42:43can simply accept product it's going to
- 5:42:45pick up the with the primary key and at
- 5:42:48the moment um I just want to Define an
- 5:42:52empty empty function I will change this
- 5:42:55later into a controller okay for now I
- 5:42:59just don't want the the error to be
- 5:43:01displayed and let's give it also name
- 5:43:04card store now we save it and we are
- 5:43:08going to have a look in the product
- 5:43:10Details page and refresh the page and
- 5:43:13and and and this is one error
- 5:43:21okay
- 5:43:23okay let's have a look so we see image
- 5:43:26we see thumbnail we see only one
- 5:43:31thumbnail this is the title price color
- 5:43:34and size okay we don't see options right
- 5:43:37so options are not displayed right here
- 5:43:40and we don't have also any error so let
- 5:43:46me let me check so inside
- 5:43:50show we iterate over the
- 5:43:53options okay let's do like this I'm
- 5:43:56going to print the variation
- 5:44:00types right here in this main template
- 5:44:03so let's use pre- Tag I'm going to use J
- 5:44:07on. stringify variation types undefined
- 5:44:12to cool look at this okay so we have
- 5:44:15variation types options images are also
- 5:44:18there okay now I have a question why it
- 5:44:21doesn't work render product variation
- 5:44:23types so we iterate over that if the
- 5:44:26type equals
- 5:44:29image uh okay let's return this
- 5:44:34back okay this is it the type equals
- 5:44:38uppercase i image so if we check
- 5:44:42product um how did I call
- 5:44:46this
- 5:44:48variation type type
- 5:44:51enam so we gave it uppercase s radio and
- 5:44:56image okay this is it and that is the
- 5:45:00issue right
- 5:45:02here uh let me open index and we're
- 5:45:06going to change this into s so
- 5:45:08previously I had this um in uppercase s
- 5:45:11r and I so that's the thing so R and
- 5:45:17I and here as well when we do this
- 5:45:23comparison so uppercase R uppercase
- 5:45:29i
- 5:45:32now okay now we see that and let's
- 5:45:36remove the
- 5:45:40print or maybe I can comment out this
- 5:45:44part now we see the different variations
- 5:45:48and this is the coolest part this is
- 5:45:50what I wanted to show to you and so when
- 5:45:53we click on these options it actually
- 5:45:56updates the URL if you pay attention
- 5:45:58right here it updates the
- 5:46:02URL and it also changes the calculated
- 5:46:06images the computed
- 5:46:10images clicking on this also updates the
- 5:46:13URL right here and if I refresh the page
- 5:46:16right
- 5:46:17now we are going to still see black and
- 5:46:20medium if I click on this and refresh
- 5:46:22the page now we are going to still see
- 5:46:26purple and medium and this is the
- 5:46:29coolest part okay so this is how we are
- 5:46:32preserving
- 5:46:34those um and that's just
- 5:46:40awesome okay now I want to upload
- 5:46:43multiple images so let's go
- 5:46:46into let's remove
- 5:46:49this this is black so let me
- 5:46:52upload
- 5:46:57headset black headset
- 5:47:01okay this is black one this is blue okay
- 5:47:06I'm going to change this and call
- 5:47:08these uh what other colors do I
- 5:47:12have
- 5:47:17green
- 5:47:20green and this is
- 5:47:23pink let's delete this one click on
- 5:47:28that and I'm going to choose
- 5:47:31pink okay let's see this wasn't uploaded
- 5:47:36let's retry
- 5:47:38now it got uploaded all of them were
- 5:47:41uploaded here and here and click
- 5:47:44on Save
- 5:47:48changes and we're going to click
- 5:47:52on
- 5:47:54variations we see black small green
- 5:47:56small pink small black medium green
- 5:48:00medium pink medium okay the values we
- 5:48:04updated here as
- 5:48:05well and and if I refresh this page
- 5:48:08right
- 5:48:10now now we probably some of the options
- 5:48:14probably were broken so we have to open
- 5:48:18the root domain and this is how it looks
- 5:48:20like
- 5:48:23so where's the pink thumbnail by the
- 5:48:27way uh I'm not sure maybe it is still
- 5:48:31processing so yeah the queue is actually
- 5:48:35processing and generating very
- 5:48:39Creations yep here we see it cut
- 5:48:42processed uh this is not this is not the
- 5:48:46default image I want so we can adjust
- 5:48:48the default image as
- 5:48:50well so this is the first one that's
- 5:48:53cool I want this to be the first
- 5:48:56one and I want this to be the first
- 5:48:59one click on Save
- 5:49:02changes now refresh it
- 5:49:07okay
- 5:49:16awesome yeah clicking on this right here
- 5:49:20actually
- 5:49:22triggers jumping at the
- 5:49:26Top If we check this
- 5:49:31Carousel so we have this clicking on
- 5:49:34this yeah it also triggers that jumping
- 5:49:38at the
- 5:49:39top which is pretty weird obviously this
- 5:49:42is not something what we
- 5:49:48want we don't want it to jump at the top
- 5:49:52right so I think we can easily take care
- 5:49:55of this if we go into
- 5:49:58Carousel and this is hre so we need on
- 5:50:02click here we're going to accept event
- 5:50:06and we're going to call
- 5:50:08event. prevent
- 5:50:11default let's move this hft
- 5:50:18down have a
- 5:50:21look now prevent
- 5:50:24default doesn't do
- 5:50:26anything at all stop
- 5:50:32propagation now it
- 5:50:34jumps but doesn't do anything
- 5:50:39no it jumps and changes okay and that's
- 5:50:42pretty strange um I will find this out
- 5:50:46outside of the video and tell you how to
- 5:50:49deal with
- 5:50:51that but that is um that variations I
- 5:50:56think is
- 5:50:57the most important
- 5:51:01part yeah one additional thing is
- 5:51:04related into description let me copy
- 5:51:07this list right now this is actually a
- 5:51:11list let's go
- 5:51:13into edit product and put this in the
- 5:51:16description so we have this list right
- 5:51:19and we can make certain things bold as
- 5:51:22well now if we save that and if we have
- 5:51:26a look
- 5:51:27that I think Styles uh are actually lost
- 5:51:32bold is there but least is not
- 5:51:37there and that's because talin CSS
- 5:51:39resets all these Styles and generally I
- 5:51:43recover this in the following way so I
- 5:51:45found find this somewhere um in uh in
- 5:51:51Forum I don't remember exactly where I
- 5:51:52find this but from now on I use this
- 5:51:56from my GitHub existing GitHub
- 5:51:58repository so if I go in my repository
- 5:52:01and that repository is actually open
- 5:52:02source so in this social media website
- 5:52:06as an example example we go under
- 5:52:09resources
- 5:52:11CSS app CSS in here we have those I did
- 5:52:16this with the CK editor so we have those
- 5:52:19classes which simply
- 5:52:21reverts uh some of the content for CK
- 5:52:25editor for the content which is coming
- 5:52:26from wiwi editor so we have these um
- 5:52:30duplicated one for CK content and second
- 5:52:34for CK content output
- 5:52:37so we're going to take the CK content
- 5:52:42output and let's open app. CSS from
- 5:52:47resources CSS and I'm going to put this
- 5:52:50right here
- 5:52:52however download full line code
- 5:52:55completion let's download this for CSS
- 5:52:58and I'm going to replace this CK content
- 5:53:02output uh with
- 5:53:06we
- 5:53:09output okay so let's do this replace now
- 5:53:13for the following elements inside wi
- 5:53:16output it is going to revert those
- 5:53:20changes and we're going to see now the
- 5:53:23styles are actually the least elements
- 5:53:26are actually displayed correctly so uh
- 5:53:28you can have here um additional things
- 5:53:31you can activate tables if you want to
- 5:53:33put tables right there but um
- 5:53:37yeah this
- 5:53:38is this is cool let's refresh the
- 5:53:50page when we click on this thumbnails uh
- 5:53:54besides the fact that it jumps at the
- 5:53:57top uh also the thumbnail is not
- 5:53:59selected so I'm going to take this quick
- 5:54:02challenge for which I'm not actually
- 5:54:03prepared but I'm going to do this um my
- 5:54:06own way so uh selected image set
- 5:54:11selected image this is going to be one
- 5:54:14of the images and by default we are
- 5:54:16picking the first one
- 5:54:20so we have also image ID right yes so we
- 5:54:25have image ID as well so let me remove
- 5:54:27this
- 5:54:31hre or we can
- 5:54:33simply I think we can remove this h we
- 5:54:36can even put their button I
- 5:54:41guess and we can remove the ID
- 5:54:47here now this will probably
- 5:54:53display yeah this is not going to work
- 5:54:55and it's going to display only one item
- 5:54:57if we inspect this we're going to see
- 5:54:58that we have multiple items but the
- 5:55:02others are on the other side
- 5:55:07of it h i want to check one thing so if
- 5:55:11we if we right now click on the second
- 5:55:21one so it does display it based on the
- 5:55:27ID okay anyway so this is as I mentioned
- 5:55:29I'm going to do this in my own way so
- 5:55:33right here instead of displaying all the
- 5:55:34images I'm going to display only current
- 5:55:37image so maybe I can do the following
- 5:55:41just display
- 5:55:43one image which is going to be selected
- 5:55:47image large and the key actually
- 5:55:50something we don't need okay and
- 5:55:53whenever I click on this button on click
- 5:55:57we get the event and we're going to call
- 5:55:59set selected
- 5:56:02image and we're going to provide the
- 5:56:04image to be selected
- 5:56:10now let's have a
- 5:56:14look where is this image coming
- 5:56:21from okay
- 5:56:37so we're going to see what is this
- 5:56:39selected
- 5:56:46image that selected image I guess is
- 5:56:49coming from the product right so if we
- 5:56:52go into products not products but media
- 5:56:55find the one which has ID
- 5:56:5812 this is
- 5:57:02it
- 5:57:04but how do we see that selected
- 5:57:10image from here the images do not
- 5:57:14contain that specific image right so if
- 5:57:17we just
- 5:57:20print let's actually do
- 5:57:23this right here images so I'm printing
- 5:57:26the entire list of images 1 two 3 4 five
- 5:57:30and six so we have
- 5:57:33totally six images
- 5:57:36and selected image is
- 5:57:42actually the first one from
- 5:57:52images okay let me use
- 5:57:55effect I think I know the reason so
- 5:57:57whenever yeah I know the reason so
- 5:58:00whenever this component is actually
- 5:58:03mounted react takes this first one one
- 5:58:06and puts this inside the state and next
- 5:58:09time when the images got updated this
- 5:58:11doesn't happen anymore so we are going
- 5:58:13to actually
- 5:58:15listen to
- 5:58:18images and whenever images are
- 5:58:22changed whenever images are changed I'm
- 5:58:25going to call set selected image the
- 5:58:28first one and by default we can provide
- 5:58:30this to be null or we can even leave
- 5:58:32this image zero but the main thing is
- 5:58:34that whenever images are changed we're
- 5:58:36going to update this select set selected
- 5:58:39image into the first
- 5:58:42one now let's delete this one comment
- 5:58:46out this one and have a
- 5:58:48look uh cool cool cool okay so click on
- 5:58:52this click on this
- 5:59:00okay so yeah clicking on this also
- 5:59:03updates the selected image
- 5:59:08and we can I think add the um on Mouse
- 5:59:12over whatever it
- 5:59:18does this one hover
- 5:59:22border
- 5:59:28low so I'm going to take this part out
- 5:59:32and we're going to add border two
- 5:59:38and then if selected image ID
- 5:59:43equals image
- 5:59:46ID let's put this in
- 5:59:49parenthesis then we are going to add um
- 5:59:53border blue
- 5:59:56500 otherwise we're going to add that on
- 6:00:02Hover let me move this I'm going to uh
- 6:00:07close the parenthesis
- 6:00:08here and let's move this
- 6:00:12down if
- 6:00:15statement okay I think that is
- 6:00:22correct now we see that whichever is
- 6:00:25selected it stays this border we don't
- 6:00:28have this
- 6:00:29jumping uh on
- 6:00:33click and we have
- 6:00:36we have it done
- 6:00:38properly that's great and in the drop
- 6:00:42down whenever we have only three items
- 6:00:43left we see only uh three whenever we
- 6:00:46choose something else we see now 10
- 6:00:48inside the drop down okay I committed
- 6:00:51all the changes so far and I'm going to
- 6:00:53move forward and start working on
- 6:00:56implementing add to card functionality
- 6:00:59in our project okay for this we have to
- 6:01:02create couple of new files and update
- 6:01:04existing ones where we're going to
- 6:01:06listen to the button click right here to
- 6:01:09add the product with different
- 6:01:11variations into the cart but I'm going
- 6:01:14to start with the migration first and
- 6:01:17the model because we're going to create
- 6:01:18cart items table in the
- 6:01:21database let me execute PHP artisan
- 6:01:26make model this is going to be cart item
- 6:01:31model and I'm going to generate
- 6:01:32migration file as well now my
- 6:01:35integration and model was generated I'm
- 6:01:38going to also generate the controller so
- 6:01:41this is going to be card controller PHP
- 6:01:44artisan
- 6:01:46make controller cart controller okay so
- 6:01:51let me generate actually a resource
- 6:01:54controller and I'm going to provide Das
- 6:01:56Dash model or I'm going to skip the
- 6:01:58model let me just generate card
- 6:02:01controller this is going to be resource
- 6:02:03controller and we can open this card
- 6:02:06controller right now and see those
- 6:02:09methods right here we're going to adjust
- 6:02:12these methods but I'm going to also
- 6:02:15generate a service and this is going to
- 6:02:18be service class for cart and the all
- 6:02:22logic adding into the card removing into
- 6:02:25the card will go inside that service
- 6:02:28class and the service class will also
- 6:02:30take care whether the user is
- 6:02:32authenticated or not because I want to
- 6:02:35allow ability to add the products into
- 6:02:38the card even user if even when the user
- 6:02:41is not
- 6:02:41authenticated and whenever user will
- 6:02:45authenticate on the website the items
- 6:02:48which are in the cart inside um cookies
- 6:02:52we're going to save them inside the
- 6:02:54cookies for non-authenticated users they
- 6:02:56will move into the database for
- 6:02:59authenticated users okay so if the user
- 6:03:02is guessed we're going to save the data
- 6:03:04inside cookies
- 6:03:06as soon as they log in we're going to
- 6:03:08move the data into the database okay
- 6:03:11awesome so we have the card controller
- 6:03:13and let me create this new service class
- 6:03:16so inside up services we have this
- 6:03:18custom path generator so let's actually
- 6:03:22execute PHP artisan make service and
- 6:03:28let's call this cart
- 6:03:30service we hit the
- 6:03:33enter okay so I guess there is no make
- 6:03:36service I just didn't remember this so
- 6:03:39simply we can execute make class inside
- 6:03:43Services back slash card service we hit
- 6:03:46the enter the class was generated here
- 6:03:49we see this card service and the idea of
- 6:03:53these cart Services I mentioned is going
- 6:03:54to be to manage the add to cart remove
- 6:03:57from cart uh update the quantity of the
- 6:03:59card and so on so I want to create singl
- 6:04:02ton out of this card service so for this
- 6:04:05I'm going to open up service provider
- 6:04:09and inside this register method I want
- 6:04:13to use this
- 6:04:16app singl ton and we're going to provide
- 6:04:20right here the class name which is going
- 6:04:21to be our cart service class and right
- 6:04:26here from this function we are going to
- 6:04:28return new card service we don't want up
- 6:04:32right here we don't use this and just
- 6:04:34like this we registered that c card
- 6:04:35service and we will be able to use that
- 6:04:39card service with through dependency
- 6:04:43injection in our controller or in any
- 6:04:46other places so if we open this card
- 6:04:48controller right
- 6:04:49now inside index as an example we can
- 6:04:53accept requests if we need but I think
- 6:04:55we don't need request uh at least for
- 6:04:57now but we can access this card service
- 6:05:00in the following way okay and we can
- 6:05:03dump the entire cart service object
- 6:05:06right now and later when we implement
- 6:05:09this we're going to get the items from
- 6:05:10the card service and we're going to
- 6:05:12render them nicely on the page so create
- 6:05:16is something we don't need I'm going to
- 6:05:18remove this we need we will need store
- 6:05:21and I'm going to accept right here
- 6:05:24product which needs to be added into the
- 6:05:26cart and I'm going to accept also card
- 6:05:28service so we have three variables let's
- 6:05:32import this product next I'm going
- 6:05:36to uh remove the show we don't need show
- 6:05:39which is for only one item instead of
- 6:05:43edit yeah I'm going to remove edit as
- 6:05:45well and I'm going to take care of this
- 6:05:48update so in the update we're going to
- 6:05:49accept request we are going to accept
- 6:05:53product for which we are doing the
- 6:05:56update of the quantity and we're going
- 6:05:59to accept also card service as an
- 6:06:01argument scroll down below in the
- 6:06:03destroy we're going to also accept
- 6:06:06request we're going to accept the
- 6:06:09product we want to destroy from the cart
- 6:06:13we are not destroying the product we are
- 6:06:15destroying that specific product from
- 6:06:18the cart for the authenticated user we
- 6:06:20are removing this and we need cart
- 6:06:23service as well okay so this is what we
- 6:06:26need so far maybe we can add more
- 6:06:28methods in the future but we're going to
- 6:06:30stick with these Methods at the moment
- 6:06:33and I think what we're going to focus is
- 6:06:35the store
- 6:06:36method first let's open web.php and
- 6:06:41we're going to Define cart related
- 6:06:43couple of
- 6:06:45methods okay so we have cart store and
- 6:06:49here I'm going to use cart
- 6:06:52controller class and we're going to use
- 6:06:54method called store we can I'm going to
- 6:06:57change this into cart Aid and you know
- 6:06:59what I'm going to actually optimize this
- 6:07:01in the following way so I'm going to use
- 6:07:03root control
- 6:07:06and I'm going to use cart controller
- 6:07:10here and I'm going to group Roots by
- 6:07:13card controller so
- 6:07:16then let me copy and paste this right
- 6:07:18here so then I'm listening to
- 6:07:21post um cart a in here instead of the
- 6:07:26class and then the method we're going to
- 6:07:28just provide the action okay and we give
- 6:07:32it a name card store I think we need uh
- 6:07:36rendering of the cart as well so Road
- 6:07:38get cart index and this is going to have
- 6:07:42a name cart index we will need cart
- 6:07:46update as well we're going to use put or
- 6:07:49patch for this uh and let's actually
- 6:07:52change this into put we are
- 6:07:55updating uh that specific product from
- 6:07:58the
- 6:08:00cart that's cool and let's give it name
- 6:08:03cart update and finally we are going to
- 6:08:07allow removing that specific product
- 6:08:09from the cart so we're going to use this
- 6:08:11destroy method okay and all of them
- 6:08:14actually is allowed for guest users so
- 6:08:17we don't add out middle wear anywhere
- 6:08:19guest users will be able to have a look
- 6:08:21in the inside the cart add items into
- 6:08:24the cart U update them from the cart or
- 6:08:28destroy them um from the cart I'm
- 6:08:32thinking if I missed anything but I
- 6:08:33think I haven't missed anything anything
- 6:08:36so now let's go into card controller and
- 6:08:39I'm going to work on the store method so
- 6:08:42inside the
- 6:08:43store I'm going to accept um so I'm
- 6:08:47going to call request first and I'm
- 6:08:50going to take quantity but if the
- 6:08:53quantity is not provided I'm going to
- 6:08:55assume that the quantity is one so I'm
- 6:08:57going to use method called merge if
- 6:09:00missing and right here we provide uh
- 6:09:03quantity
- 6:09:05and if it is missing we're going to
- 6:09:07assign quantity one okay after this we
- 6:09:10take the data from
- 6:09:13request we're going to call validate and
- 6:09:16we're going to validate basically two uh
- 6:09:19two columns uh one is going to be option
- 6:09:24IDs which um might be actually null so
- 6:09:28if we don't provide any option idas it
- 6:09:30means that uh either the product doesn't
- 6:09:33have any variation options defined
- 6:09:35tall uh or or we might pick up the uh
- 6:09:40first options or in this case let's
- 6:09:42assume that if we don't provide these uh
- 6:09:45option IDs if it's null then the product
- 6:09:48doesn't have any variation IDs and we
- 6:09:51don't want to use them basically in the
- 6:09:54cart item as well okay now let's define
- 6:09:58second field which is going to be
- 6:10:00quantity and let's autocomplete this and
- 6:10:03instead of required I'm going to make
- 6:10:05this
- 6:10:06nullable okay so the quantity is
- 6:10:10nullable
- 6:10:13um because we defined we merge this into
- 6:10:16existing maybe we can make this required
- 6:10:18as well now we know that the quantity
- 6:10:20will be there always okay anyway now on
- 6:10:23this cart service I'm going to Define
- 6:10:25couple of methods and one of them is
- 6:10:27going to be add item to cart so let's
- 6:10:30actually open this cart service and
- 6:10:33Define couple of methods I think we can
- 6:10:35remove this public function add item to
- 6:10:41cart and we are going to accept couple
- 6:10:44of arguments first the product we are
- 6:10:46trying to add into the cart second is
- 6:10:48going to be the quantity for that
- 6:10:50product and third is going to be array
- 6:10:53of option IDs by default an empty
- 6:10:58array so this is one of the method and
- 6:11:01whenever the item is added into the cart
- 6:11:04I think we don't need to return actually
- 6:11:08anything uh let me actually make this
- 6:11:10null so if we it's going to be null if
- 6:11:13we don't provide anything the default
- 6:11:15value okay now in the cart controller we
- 6:11:19are going to call add item to cart we're
- 6:11:21going to provide product we're going to
- 6:11:23provide uh data quantity and we are
- 6:11:26going to provide data option IDs as well
- 6:11:29so assuming that this does its work and
- 6:11:32it's going to add those I this item this
- 6:11:35specific specific product with this
- 6:11:36quantity and with this variation option
- 6:11:39IDs into the cart okay then we are going
- 6:11:43to return uh we're going to go back and
- 6:11:47we're going to go back with some success
- 6:11:49message product add2 card
- 6:11:53successfully okay so this ed2 cart is
- 6:11:56going to work on both cases whether the
- 6:11:58user is guessed or user is authenticated
- 6:12:01and depending on the user State it's
- 6:12:04going to add the
- 6:12:05um product into the card inside cookies
- 6:12:08or inside the
- 6:12:10database now let's focus on the update
- 6:12:13and we're going to validate the quantity
- 6:12:15and we're going to take integer and the
- 6:12:17minimum value should be at least one and
- 6:12:20the update generally will be called
- 6:12:22whenever the product is already added
- 6:12:24into the card and we want to update its
- 6:12:27quantity so then we're going to take the
- 6:12:29option IDs from this request input if we
- 6:12:32are trying to update it okay for which
- 6:12:37variation options we are going to we are
- 6:12:40trying to update that product so we know
- 6:12:44that what's the product but we don't
- 6:12:46know what option IDs we want to update
- 6:12:50without this data okay so we need these
- 6:12:53option ities as well then we're going to
- 6:12:55get um the quantity from this request
- 6:12:57after we perform the validate and then
- 6:13:01I'm going to call on card service update
- 6:13:04item quantity
- 6:13:05we are going to create that method in a
- 6:13:08moment but we're going to provide
- 6:13:10product ID here we're going to provide
- 6:13:12quantity and option IDs so on this
- 6:13:15product we're going to set the following
- 6:13:17quantity and with the following option
- 6:13:21IDs okay next we're going to go back
- 6:13:25with success message quantity was
- 6:13:27updated now let's open card service and
- 6:13:30right here let's add the method public
- 6:13:33function
- 6:13:36what's that public function update we
- 6:13:40call this update item quantity so we're
- 6:13:43going to accept
- 6:13:45integer product ID quantity and option
- 6:13:52IDs okay so we're going to come back to
- 6:13:54this service in a moment and Implement
- 6:13:56all the necessary methods next I'm going
- 6:13:59to scroll down below and implement the
- 6:14:01destroy method so I'm going to accept
- 6:14:03option IDs right right here from request
- 6:14:07so we need we always need option IDs to
- 6:14:10identify which item from the cart needs
- 6:14:14to be removed because the same
- 6:14:17product might be added into the cart
- 6:14:20with different variation option IDs okay
- 6:14:24so here we have the same product and if
- 6:14:27I add black into the card then add green
- 6:14:30into the cart I should see two records
- 6:14:33inside the cart they are actually the
- 6:14:35same product but two different
- 6:14:37variations and I should be a able to
- 6:14:39view them separately inside the card and
- 6:14:42to increase quantity for each of them
- 6:14:44inside the card and remove black one or
- 6:14:47green one but the but to leave the other
- 6:14:50one inside the card so this is how I
- 6:14:53want to make it so then on the card
- 6:14:56service I'm going to call remove item uh
- 6:15:00from cart we're going to provide product
- 6:15:03ID and the option IDs okay and we're
- 6:15:07going to create that method and then I'm
- 6:15:09going to go back with success message
- 6:15:11product was removed from
- 6:15:16cart cool now let's go into cart service
- 6:15:21and we're going to Define this function
- 6:15:22as well remove item from cart we're
- 6:15:25going to accept uh product ID
- 6:15:29and option IDs which is going to be null
- 6:15:33I'm going to start implementing couple
- 6:15:35of helper methods inside this card
- 6:15:38service which will be used in several
- 6:15:41places okay so let's define first I'm
- 6:15:43going to Define get cart items which is
- 6:15:46going to return array depending on
- 6:15:49whether the user is authenticated or not
- 6:15:51this is going to read the information
- 6:15:53from car from cookies or from the
- 6:15:55database I'm going to also Define get
- 6:15:58total quantity and get total price these
- 6:16:02is going to be public methods
- 6:16:04additionally I'm going to Define
- 6:16:05protected methods which will be used
- 6:16:07only internally like update item
- 6:16:10quantity in database we accept product
- 6:16:13ID we accept the new quantity and the
- 6:16:16option ID is to update that record in
- 6:16:18the cart so additionally I'm going to
- 6:16:21also Define update item quantity in
- 6:16:23cookies which has the same signature
- 6:16:26we're going to Define update uh sorry
- 6:16:29save item to database this is going to
- 6:16:32be when we add a new item into to the
- 6:16:35cart okay so for database for cookies
- 6:16:39we're going to also have remove item
- 6:16:41from database and remove item from
- 6:16:44cookies okay and we're going to also
- 6:16:47Define get card items from database and
- 6:16:51get card items from cookies now let's go
- 6:16:56to the top of the class and we are going
- 6:16:58to define a couple of constants and the
- 6:17:03protected meth um property
- 6:17:05like or private properties so first I'm
- 6:17:08going to Define this cached cart items
- 6:17:10which is going to be a cached version of
- 6:17:13the cart items and we're going to use
- 6:17:15this in uh the method get cart items and
- 6:17:19this is going to be important because we
- 6:17:22are going to use this gate cart items
- 6:17:25method couple of
- 6:17:27times this method will be used couple of
- 6:17:29times during a single request and when
- 6:17:32the user is authenticated every time it
- 6:17:35is going to make the database select to
- 6:17:37select the card items but I'm going to
- 6:17:39actually uh cach that save that inside
- 6:17:43these cach card items we're going to see
- 6:17:45this in action so we're going to also
- 6:17:48add one uh static um constant not the
- 6:17:53static but one um protected constant
- 6:17:56cookie name inside which we are going to
- 6:17:58save the cart items and also another
- 6:18:01protected constant cookie lifetime which
- 6:18:03we're going to set in to one yard
- 6:18:05whenever we add something into the cart
- 6:18:07it's going to stays um stay in in the
- 6:18:10cart for one yard you can obviously
- 6:18:12reduce this if you want now I'm going to
- 6:18:16start implementing uh these methods like
- 6:18:19G cart items get total quantity and so
- 6:18:23on so let's start with this G cart items
- 6:18:26so I'm going to use first try catch and
- 6:18:29we need this TR catch uh because if
- 6:18:31something goes wrong uh simply it's
- 6:18:34going to an exception and nothing will
- 6:18:36happen so when if we are not able to
- 6:18:39read the data from cart items we don't
- 6:18:41want the website to be crashed right so
- 6:18:44uh and in this case like reading uh and
- 6:18:47we're going to also use the Json decode
- 6:18:49to decode the data from uh cookies so we
- 6:18:54something might simply go wrong okay so
- 6:18:58now this is the place where we use these
- 6:19:00Cas get um sorry cached cart items so if
- 6:19:05cached card cart items equals null it
- 6:19:09means that we are calling this method
- 6:19:11get cart items the first time in this
- 6:19:13request so we're going to do something
- 6:19:15in this if statement and assign the data
- 6:19:19into this cached cart items okay so
- 6:19:23we're going to do that inside if
- 6:19:25whenever if finishes we are going to
- 6:19:27return this uh cached cart items and now
- 6:19:32we are going to focus on that if
- 6:19:35uh the content of this if so we are
- 6:19:38going to do the following check if the
- 6:19:39user is authenticated we're going to do
- 6:19:42something else retrieve the data from
- 6:19:44the database otherwise we're going to
- 6:19:46retrieve the data from cookies okay so
- 6:19:49cart items equals these get cart items
- 6:19:52from database and here cart items equals
- 6:19:56these G cart items from cookies so we
- 6:19:59are gonna just make sure that cart items
- 6:20:02whether it is selected from the database
- 6:20:05or it is selected from cookies they have
- 6:20:09the same format okay and that format is
- 6:20:13going to be how we're going to save them
- 6:20:15into the database so before I continue
- 6:20:17right here I think we haven't created
- 6:20:20the migration we created the migration
- 6:20:22but we haven't actually written anything
- 6:20:24there so create card items let's open
- 6:20:28this and we're going to add couple of
- 6:20:30columns like
- 6:20:33table let's add foring ID on product ID
- 6:20:38it's going to be constrained into
- 6:20:40products uh let's also add index and I'm
- 6:20:44going to also add uh we have the
- 6:20:47constraint and I'm going to also add
- 6:20:49right here uh Cascade on delete whenever
- 6:20:52product is deleted we want the cart
- 6:20:54items to be deleted as well next I'm
- 6:20:57going to Define this foring ID by user
- 6:21:01ID uh let's give it index as well and
- 6:21:04constraint on
- 6:21:05users uh let's define also quantity and
- 6:21:10price let's Define decimal price give it
- 6:21:1520 on four and table integer not index
- 6:21:21but integer
- 6:21:24quantity so we have product ID we have
- 6:21:27user ID we have quantity we have price
- 6:21:32uh we need variation type option IDs so
- 6:21:36this is going to be Json
- 6:21:38variation type option
- 6:21:42IDs uh and that actually should be
- 6:21:46nullable and finally I'm going to Define
- 6:21:49one additional column which we I hope
- 6:21:53that we have time to implement this uh
- 6:21:55and this is going to be saved for later
- 6:21:59whether that specific product is going
- 6:22:02to be uh saved for later and will not
- 6:22:05participate during checkout I really
- 6:22:08like this feature I use this on Amazon
- 6:22:11um yeah this is um how I want to do it
- 6:22:16and now if we're go in the card service
- 6:22:18I want to return the data in a similar
- 6:22:21format from these gate cart items from
- 6:22:23database and these gate cart items from
- 6:22:26cookie now let's continue right here so
- 6:22:28let's say that we got those cart items
- 6:22:31now we're going to create these cart
- 6:22:33items will be plane array okay so we're
- 6:22:36going to uh create a collection out of
- 6:22:39it then we're are going to map each item
- 6:22:42from this cart item into the product ID
- 6:22:46so finally right here we are going to
- 6:22:48have product
- 6:22:50IDs then I'm going to select products by
- 6:22:53IDs the following IDs and I'm going to
- 6:22:57also select that with
- 6:23:00user and
- 6:23:02vendor Okay so do we have vendor
- 6:23:06information in the database so we don't
- 6:23:09have that and this is something what I
- 6:23:11am going to do so right now I'm just
- 6:23:13going to create a table for vendor but
- 6:23:17later we're going to implement um
- 6:23:19certain things there as
- 6:23:22well now let me execute PHP artisan make
- 6:23:29uh make
- 6:23:30model vendor and we're going to generate
- 6:23:33migration as well well okay now let's
- 6:23:36open
- 6:23:38create vendors
- 6:23:40table and let's do the following
- 6:23:44so uh instead of ID right here I am
- 6:23:47going to change this into big
- 6:23:51integer big integer this is going to be
- 6:23:54user ID I'm changing the name of the
- 6:23:58primary key let's give it unsigned in
- 6:24:01primary because vendor will have
- 6:24:04onetoone connection to user okay a user
- 6:24:09will have its Associated data inside
- 6:24:12vendors table where we're going to save
- 6:24:15couple of
- 6:24:20information okay I'm going to also
- 6:24:22Define forign key from user ID into
- 6:24:25vendor like on table I'm going to use
- 6:24:28foring on user ID which references on ID
- 6:24:33references by ID on users table and we
- 6:24:37are going to give it
- 6:24:41also Cascade on
- 6:24:44delete whenever user is deleted for some
- 6:24:47reason we want the vendor to be deleted
- 6:24:50as well now we're going to also Define
- 6:24:54status of the vendor whether the vendor
- 6:24:56is approved or it's status is actually
- 6:24:59pending and not approved vendor in which
- 6:25:01case admin users need to approve approve
- 6:25:04the vendor okay so we are going to
- 6:25:07Define store name we are going to Define
- 6:25:12store
- 6:25:14address which actually can be null we
- 6:25:19are going to Define
- 6:25:20Also let's define cover cover image of
- 6:25:25the vendor which can be also null and I
- 6:25:29guess that is all so I'm going to leave
- 6:25:31this now so we have the Vendor model we
- 6:25:34have the vendors uh table now let's open
- 6:25:37product and on the product we have I
- 6:25:41think user relation and on that user we
- 6:25:44are going to add has one relation to
- 6:25:47vendor has
- 6:25:51one
- 6:25:52vendor then right here we need vendor
- 6:25:56class and we're going to provide user ID
- 6:26:00so now if we go back into card service
- 6:26:03so we are actually selecting product
- 6:26:05with its user and vendor because I want
- 6:26:08to use the vendor store name when
- 6:26:13rendering the cart
- 6:26:15items in fact I want to group cart items
- 6:26:19by this vendor store name and
- 6:26:22show um let's say I have two vendors
- 6:26:25let's say the first one is the code
- 6:26:27holic is the vendor and second is the
- 6:26:29vendor let's say um I don't know Sony
- 6:26:32Entertainment as an example so I want to
- 6:26:36display products from the vendor under
- 6:26:39the vendor store name this is uh for
- 6:26:43which I actually need to select the
- 6:26:45products with a vendor name so you might
- 6:26:47also have a question why I'm not
- 6:26:49selecting that uh the product itself
- 6:26:53from when I select the cart items from
- 6:26:56the database I can do this however I
- 6:27:00cannot do this
- 6:27:02um When selecting cart items from
- 6:27:05cookies if I'm confusing right now just
- 6:27:09um follow with me okay so this is
- 6:27:13something you just need to bear with me
- 6:27:15you're going to follow and you will
- 6:27:17understand every single thing what we
- 6:27:18are doing right
- 6:27:21now okay I will re explain that specific
- 6:27:24part when I Implement these gate card
- 6:27:26items from the database okay so now
- 6:27:29let's continue and so we have this we
- 6:27:33right here uh I'm going to also create
- 6:27:35another scope and this scope is going to
- 6:27:39select the products for website so at
- 6:27:42the moment we have two scopes for vendor
- 6:27:44and scope published and scope published
- 6:27:47will simply check the status of the
- 6:27:50status of the product but I want to
- 6:27:53create something similar uh but for
- 6:27:57scope for website okay and why I am
- 6:28:03doing this because except other than
- 6:28:07published there might be some other
- 6:28:09conditions if I want to display that
- 6:28:13product on the website or not for
- 6:28:14example let's say that the product need
- 6:28:17to be approved as well if we introduce
- 6:28:19some approval um stage in the future or
- 6:28:24the vendor needs to be approved uh
- 6:28:28so um I want to also open product
- 6:28:32controller to explain this very very
- 6:28:34clearly so we are using published right
- 6:28:37here and we probably need to select
- 6:28:41published products in many places and
- 6:28:43let's say we implemented the following
- 6:28:45way and we have used published scope in
- 6:28:4810 or 12 different places and then we
- 6:28:51introduced a second condition whether
- 6:28:55the product should be displayed on the
- 6:28:56website or not it's not only published
- 6:28:59but it is let's say that the vendor
- 6:29:01needs to be approved as well so then we
- 6:29:04have to update all the other places
- 6:29:07where we have this published used okay
- 6:29:11so but in our case I'm going to create
- 6:29:14this new scope for website which will do
- 6:29:17two things first it's going to make
- 6:29:21sure that the product is published and
- 6:29:24second if we need any other weather
- 6:29:27Clauses we are going to put them right
- 6:29:29here but for now um instead of using the
- 6:29:33published I'm going to use for website
- 6:29:35and I can do this right here in the
- 6:29:38product controller as well for
- 6:29:41website okay so I'm creating a wrapper
- 6:29:45of the published scope calling this for
- 6:29:48website now let's go into card service
- 6:29:51so we are using this cope right here for
- 6:29:53websites we're selecting all the
- 6:29:55products with the IDS with user and
- 6:29:58vendor for website then I'm going to
- 6:30:00index that by ID so now we have that
- 6:30:04products as a associative array where
- 6:30:08the key is ID of the product and the
- 6:30:11value is the entire object next we're
- 6:30:14going to Define this cart item data and
- 6:30:16we're going to iterate over our cart
- 6:30:19items and we're going to do the
- 6:30:21following so from products which we
- 6:30:24indexed right now we are going to get
- 6:30:28the product based on the card item
- 6:30:31product ID okay so we get the product
- 6:30:34right
- 6:30:35here then if the product doesn't exist
- 6:30:38we simply continue so what will be the
- 6:30:41case when the product doesn't exist
- 6:30:43product might not exist If the product
- 6:30:47got deleted or
- 6:30:49unpublished when we added that product
- 6:30:53into the cart okay in which case we
- 6:30:56simply don't display this product
- 6:30:58anymore okay next we are going to Define
- 6:31:02option information
- 6:31:04and we're going to select variation type
- 6:31:07options with the variation type as well
- 6:31:10and inside the we close we're going to
- 6:31:12provide the cart item option
- 6:31:15IDs so because we created that cart
- 6:31:20items table and we have this variation
- 6:31:22type option IDs okay so from the cart
- 6:31:26item we simply we we simply have option
- 6:31:29IDs we are not using this variation type
- 6:31:31option IDs why because those two methods
- 6:31:36get cart items from the database and get
- 6:31:39cart items from cookies will return them
- 6:31:42with option
- 6:31:44IDs okay again bear with me I'm going to
- 6:31:48explain every single line what we are
- 6:31:49doing here and then once we have the
- 6:31:51entire code then we're going to do
- 6:31:54recap okay so next we're going to do get
- 6:31:57to get all the variation type options
- 6:32:00with these IDs alongside with the
- 6:32:02variation type self do we have this
- 6:32:05variation type relation defined in the
- 6:32:08variation type option I'm not sure let's
- 6:32:11open variation type
- 6:32:14option we don't have that relation
- 6:32:17variation type so let's define this
- 6:32:19through belongs to variation type here
- 6:32:26we need variation type
- 6:32:29class cool now we have that relation
- 6:32:31defined next we're going to index T that
- 6:32:34options by IDs um again we're going to
- 6:32:38Key by like reorder them Key by I call
- 6:32:41this indexing basically because now we
- 6:32:43have this ID as a index of this array
- 6:32:48okay so next we are going to generate
- 6:32:51the image URL and this is kind of uh
- 6:32:53interesting and tricky so if we don't
- 6:32:55have any variation types defined on the
- 6:32:57product the image URL will be the
- 6:32:59product URL right however if we have
- 6:33:02those variation type options defined on
- 6:33:05the product then one of those options
- 6:33:08might have its own images it might be
- 6:33:11the case that none of the options have
- 6:33:14extra images and in which case we're
- 6:33:16going to again take the image from the
- 6:33:19product so now we are going to iterate
- 6:33:23over card items option IDs we're going
- 6:33:27to take each option ID then we're going
- 6:33:30to get the option from just selected
- 6:33:33option
- 6:33:35and we're going to check that um if the
- 6:33:39image URL doesn't
- 6:33:41exist then we're going to get the image
- 6:33:43URL from option get First Media URL
- 6:33:48images and
- 6:33:50small okay so let's say that there were
- 6:33:53two options for the first option we know
- 6:33:55that the image URL is null so if will be
- 6:33:59satisfied then let's say that first
- 6:34:01option already has image is so this will
- 6:34:05return the first image image URL will be
- 6:34:07populated the next iteration for the
- 6:34:10second option this if will not be
- 6:34:13satisfied nothing will happen so pretty
- 6:34:15much as long as we find the first option
- 6:34:18which has image we are assigning that
- 6:34:20into image URL okay next we're defining
- 6:34:24the option info here inside option info
- 6:34:27we're going to put uh the option ID
- 6:34:29we're going to put the option name we're
- 6:34:31going to put the type information as
- 6:34:33well such as um the option variation
- 6:34:36type ID and variation type
- 6:34:39name after this for Loop so we have
- 6:34:44image URL and we have option info okay
- 6:34:48we're going to use them so I'm going to
- 6:34:49collapse this option info is actually an
- 6:34:52array pay attention so option info is
- 6:34:54array and we have a the option
- 6:34:57information as well as the type
- 6:34:58information here now let's collapse this
- 6:35:02and finally we're going to construct
- 6:35:03this cart item data which is an array we
- 6:35:07defined outside of this for Loop and
- 6:35:09we're pushing something inside this cart
- 6:35:11item data we're going to push the cart
- 6:35:14item id itself we're going to push the
- 6:35:16product ID we're going to push the title
- 6:35:19of the product slug of the product we
- 6:35:22need that slug to generate the product
- 6:35:25Details page because whenever we open
- 6:35:27the cart items listing we click on the
- 6:35:31title or image of the product from the
- 6:35:33cart items listing we want the product
- 6:35:35Details page to be open so we are using
- 6:35:38that slug for this so we need price as
- 6:35:41well which we're going to take from cart
- 6:35:43item we're going to take the quantity
- 6:35:46again taking from the cart item and we
- 6:35:49need these option IDs again taking from
- 6:35:52the cart item but besides that uh option
- 6:35:55IDs we also have the actual options we
- 6:35:58need that option information to display
- 6:36:00what type of variation option we have
- 6:36:03added into the cart like here we're
- 6:36:06Gathering that variation type option
- 6:36:07info and we know that the variation type
- 6:36:10is color and size so here we're going to
- 6:36:13have color or size as a name however
- 6:36:16inside these options we're going to have
- 6:36:18black blue small or large so we need the
- 6:36:23data to display what type of variations
- 6:36:26we have added into the card like color
- 6:36:29black size small we're going to display
- 6:36:31that information pretty much much in a
- 6:36:34similar way like how Amazon does that so
- 6:36:38if we add this into the cart let's
- 6:36:40select size and click on add to cart
- 6:36:46that was added into the cart we click on
- 6:36:49the cart and we see size extra small
- 6:36:53color black whatever so in the same way
- 6:36:57we're going to display this information
- 6:36:59here and whenever we click on the image
- 6:37:02or title just like Amazon does we're
- 6:37:04going to open the details page cool so
- 6:37:08we are going to render the um we're
- 6:37:11going to also put image information
- 6:37:13inside this array if image URL exists
- 6:37:17right here then we're going to use that
- 6:37:19image URL if it doesn't exist we are
- 6:37:21going to take the First Media URL from
- 6:37:24the product itself the image URL might
- 6:37:26not exist if the there are no variation
- 6:37:29options defined on the product or if
- 6:37:32none of them have images if this if was
- 6:37:35never
- 6:37:36satisfied Okay cool so we push that data
- 6:37:40inside card item data and after this we
- 6:37:44are going to push the user information
- 6:37:45as well now that user inform information
- 6:37:49will have the uh user ID which is
- 6:37:51product created by we're going to have
- 6:37:54the name of the user which is going to
- 6:37:57be the uh store name vendor store name
- 6:38:02so product user vendor store name we
- 6:38:06have the following relation defined and
- 6:38:08in fact when we select products right
- 6:38:10here we're selecting them with this with
- 6:38:13user and vendor cool cool cool cool next
- 6:38:18uh so we actually created this cart item
- 6:38:21data and then after this for
- 6:38:25each right here at the end of this for
- 6:38:29each we're putting that cart item inside
- 6:38:32this cart item data but at the end of
- 6:38:34this for Loop we are re we are assigning
- 6:38:38that cart item data into cached cart
- 6:38:41items so this everything happens inside
- 6:38:44this if statement if the cart item data
- 6:38:48uh cach cart items equals null okay
- 6:38:51however uh on the first execution of the
- 6:38:54these gate card items we populating
- 6:38:57something inside these cash card items
- 6:39:00and on the next execution these card
- 6:39:03item data will not be null the if will
- 6:39:05not be satisfied and the same data will
- 6:39:08be returned without executing all these
- 6:39:11selects and
- 6:39:13everything so we're going to also handle
- 6:39:16the case if there is some exception and
- 6:39:18we're going to put that information
- 6:39:19inside logs and if there is some
- 6:39:21exception we're going to return empty
- 6:39:23array cool now that was the most
- 6:39:26complicated method so far now let's take
- 6:39:29care of this get total quantity okay so
- 6:39:31we have that method which is get cart
- 6:39:34items now we're going to use that get
- 6:39:36cart items to calculate the total
- 6:39:39quantity so we have the get cart items
- 6:39:41iterate over that inside total quantity
- 6:39:44we're going to push item quantity and
- 6:39:46finally we're going to return this total
- 6:39:48quantity in the same way we're going to
- 6:39:50calculate the total price iterate
- 6:39:52overcart items um uh create the like U
- 6:39:56multiply the quantity into the item
- 6:39:58price and push that information add that
- 6:40:01information inside total finally we're
- 6:40:04going to return
- 6:40:05total after this we're going to focus on
- 6:40:08update item quantity in database we take
- 6:40:11the currently authenticated user ID then
- 6:40:14we're going to select cart items so we
- 6:40:18are using this user ID we're going to
- 6:40:20use the product ID we want to find all
- 6:40:24the specific cart item we want to update
- 6:40:28inside the database so we're selecting
- 6:40:30this by user ID by product ID
- 6:40:33but please keep in mind that uh the same
- 6:40:36user might have the same product added
- 6:40:40into the card uh like a couple of times
- 6:40:43and all of them will be different
- 6:40:44records inside card items table in the
- 6:40:47database I haven't executed the
- 6:40:49migration to create the card items maybe
- 6:40:52I should do this right now PHP Artisan
- 6:40:56migrate it created cart items in vendors
- 6:40:58table and if we check right now expand
- 6:41:02cart items so the same user might add
- 6:41:07the same product into the cart couple of
- 6:41:10times and I'm not talking about
- 6:41:11increasing quantity I'm talking about
- 6:41:15creating actually different records in
- 6:41:17this table and this might happen because
- 6:41:20of the variation type option IDs so the
- 6:41:22same product which might be um our
- 6:41:25headset the same user which might be our
- 6:41:29John do user as an example might edit
- 6:41:32the same same
- 6:41:34product second
- 6:41:36times but with different variation type
- 6:41:39option IDs so here we might have one and
- 6:41:43four option IDs but here we might have
- 6:41:45two and five option IDs so this is what
- 6:41:48I want to
- 6:41:51highlight now so we're selecting this
- 6:41:53cart item uh with user product ID but
- 6:41:57we're going to select this with uh
- 6:41:59variation type option IDs as well we are
- 6:42:02using this option IDs here uh and we're
- 6:42:06selecting the first of this cart item if
- 6:42:08the cart item exists we're going to
- 6:42:10perform the update providing new
- 6:42:12quantity if the cart item doesn't
- 6:42:15exist we are not going to do anything so
- 6:42:18right here this this is related to
- 6:42:20update so if the cart item wasn't found
- 6:42:22we are't going to do
- 6:42:24anything so now to take care of the
- 6:42:26update cart item quantity inside the
- 6:42:29cookies we're going to read that uh cart
- 6:42:33items from cookies okay so then we're
- 6:42:37going to sort the option IDs what which
- 6:42:40is given right here um and I'm sorting
- 6:42:44this option IDs just to make sure that I
- 6:42:47have the consistent data okay so first
- 6:42:50we're going to have the lower option ID
- 6:42:52then the larger one and we're going to
- 6:42:55use this uh to
- 6:42:57generate uh to take the cookie item key
- 6:43:01and let me finish this method and I will
- 6:43:03explain what I mean uh in better wording
- 6:43:06and I'm going to show also the sample
- 6:43:08data so I'm generating the following um
- 6:43:12item key so maybe I should have
- 6:43:15implemented this save item to the
- 6:43:17database first and then update yeah
- 6:43:20definitely I should have done this but
- 6:43:22let me open now a new scratch file I'll
- 6:43:25explain this no problem so inside
- 6:43:28cookies we're going to have cart items
- 6:43:31and when we get cart
- 6:43:34items cart items then it is going to be
- 6:43:38associative array and the key of this
- 6:43:42ass associative area is going to be the
- 6:43:44product ID let's say product one and the
- 6:43:48Json encoded version of option IDs like
- 6:43:511 comma 4 so this is going to be the key
- 6:43:55and then we're going to have its
- 6:43:56Associated information like quantity
- 6:44:00price and few other things of this C
- 6:44:02type item and we might have the same
- 6:44:05product one added second time into the
- 6:44:09cart with different variation options
- 6:44:14with different quantity and with
- 6:44:15different area information so this is
- 6:44:18what I'm doing right now so constructing
- 6:44:21this item key to read the data from cart
- 6:44:24items from cookies so then I'm checking
- 6:44:28if that key already exists in the cart
- 6:44:31items um inside the cookie so if for
- 6:44:35example this exists inside the cart
- 6:44:39items then we're going to perform the
- 6:44:41update and the update will be inside
- 6:44:43cart items for the given key we are
- 6:44:45going to update the quantity oops into
- 6:44:49something like this okay next we are
- 6:44:52going to um push that information save
- 6:44:55the updated cart items B inside the
- 6:44:59cookie so I'm using this cookie facade
- 6:45:02uh Q method providing the cookie name
- 6:45:05and providing the Json encoded version
- 6:45:08of cart items and we are also going to
- 6:45:11provide the cookie lifetime
- 6:45:14here okay now we're going to focus on
- 6:45:17the save item to datab base which I
- 6:45:19should have done this before update my
- 6:45:22bad apologies for this but uh I think
- 6:45:25I'm doing my best to explain this very
- 6:45:27clearly so you don't have any questions
- 6:45:29okay now we have this user ID here we're
- 6:45:32going to sore again option IDs and we're
- 6:45:36doing this inside the database at the
- 6:45:38moment okay so we are going to select
- 6:45:41the card
- 6:45:43item okay if that exists we are going to
- 6:45:48update its quantity if it does not exist
- 6:45:50we're going to add that cart item into
- 6:45:52the database and why let's create this
- 6:45:57so if let let me focus on this part so
- 6:46:00if that card item exists in the database
- 6:46:03we are performing the
- 6:46:06database um update cury we provide the
- 6:46:11existing quantity whatever it is in the
- 6:46:14database plus the new quantity what we
- 6:46:17have and so pay attention uh to this
- 6:46:22what we have here versus the update into
- 6:46:25the database so this is just update and
- 6:46:28I plan to use it when performing the
- 6:46:32update from the cart let's say I choose
- 6:46:36five here this is going to execute the
- 6:46:38update so in the database we're going to
- 6:46:41have five straight five but I'm going to
- 6:46:46use this method save item to database
- 6:46:50whenever we are adding the product into
- 6:46:53the cart so we have already added this
- 6:46:55product into the cart we have it with a
- 6:46:57five quantity but if I click on Ed to
- 6:47:01cart once again right here so we're
- 6:47:05doing something similar I know it is
- 6:47:06Amazon it is not our website but when I
- 6:47:09click on this it is going to actually
- 6:47:11update the quantity into the card from
- 6:47:13five to six so this is what we are doing
- 6:47:16so we're going to call Save item to
- 6:47:18database when we click add to cart and
- 6:47:21if the item exists we're going to
- 6:47:23perform the update existing quantity
- 6:47:25plus the new quantity uh however if the
- 6:47:28cart item doesn't exist we're going to
- 6:47:29create that providing user ID product ID
- 6:47:33quantity price and variation type option
- 6:47:37IDs okay and we're done about this save
- 6:47:40update to database we can focus on Save
- 6:47:43item to cookies save item into the
- 6:47:46database here and save item to cookies
- 6:47:48so here we're selecting existing cart
- 6:47:51items from cookies then we're sorting
- 6:47:54the option
- 6:47:55IDs um and then we're going to generate
- 6:47:59this unique key based on the product ID
- 6:48:01and option ID is and we're going to do
- 6:48:04the check so if inside cut items we have
- 6:48:07items key then we're going to perform
- 6:48:11again update and increase the quantity
- 6:48:15just like we did right here we're going
- 6:48:17to increase the quantity button inside
- 6:48:19cookie so for this inside the card items
- 6:48:23for the given item key quantity plus
- 6:48:26equals the quantity and we are going to
- 6:48:29also update the price so the price maybe
- 6:48:34when you added the item into the cart
- 6:48:35the price was 100 but after one week you
- 6:48:39decided to increase the quantity of that
- 6:48:42product into the cart and the price
- 6:48:44might might got changed so we want to
- 6:48:47update that price as well it's is not
- 6:48:49mandatory but um like in some cases it
- 6:48:53will be easier to use the updated price
- 6:48:55from uh cookie rather than selecting
- 6:49:00that price from the database to check
- 6:49:02check whether the price is always up to
- 6:49:04date or not so I'm just adding this
- 6:49:06price into the cart having the up
- 6:49:09to-date price um and that's it so it's
- 6:49:11not like something super crucial for the
- 6:49:15entire card
- 6:49:17system so if the cart items doesn't have
- 6:49:21a given key then I am creating new cart
- 6:49:24items for this I'm using the new ID
- 6:49:27generate the U ID okay so we're going to
- 6:49:31have the product ID quantity price and
- 6:49:34option
- 6:49:35IDs and finally I'm going to save that
- 6:49:38updated cart items back inside cookies
- 6:49:42so cookie Q provide the cookie name Json
- 6:49:45encode inside cart items and the cookie
- 6:49:47lifetime now let's take care of the
- 6:49:49remove item from database we're going to
- 6:49:51use the user ID sort the option IDs and
- 6:49:55from the cart item where the user ID
- 6:49:57equals the user ID product ID equals the
- 6:50:00product ID variation type option IDs
- 6:50:03equals the given option IDs then we're
- 6:50:06going to perform the
- 6:50:08delete so in the same way we're going to
- 6:50:11uh get the cart items basically we are
- 6:50:14directly reading these um C cart items
- 6:50:18and we're calling this um Json
- 6:50:22decode right here so then we are going
- 6:50:26to uh sort the option IDs generate the
- 6:50:29key with the product ID in option IDs
- 6:50:32and where we're going to unset the
- 6:50:34current key from the card items and
- 6:50:37we're going to put that uh card items
- 6:50:39back inside
- 6:50:41cookie and now let's Implement get cart
- 6:50:44items from the database we're going to
- 6:50:46get the user ID and uh again where uh
- 6:50:50we're going to
- 6:50:52select uh okay so we're going to select
- 6:50:54every item based on the user ID okay so
- 6:51:00in this case we don't provide any uh
- 6:51:02like product or something like this we
- 6:51:04just want to read everything the current
- 6:51:06user has inside the
- 6:51:09database so we're calling this user uh
- 6:51:13card item where user ID equals user ID
- 6:51:15get then we're going to call map here
- 6:51:18and map the card item into the following
- 6:51:20array so we have um the ID product ID
- 6:51:25quantity price and option IDs and that
- 6:51:30option IDs is then what we are using um
- 6:51:34inside gate cart items I will get back
- 6:51:37there as
- 6:51:38well okay next we're going to convert
- 6:51:41this into an array because map returns
- 6:51:43in collection so now we have these card
- 6:51:45items to be an array and we're going to
- 6:51:47Simply return this cart items and here
- 6:51:50we are going to read these cart items
- 6:51:52from cookie and we are going to return
- 6:51:56those cart items so in fact I think
- 6:52:01right here inside when calling this
- 6:52:04remove item from cookies instead of this
- 6:52:07cookie get directly I think we should
- 6:52:10call these get card items from
- 6:52:16cookies
- 6:52:18now when we read that uh get cart items
- 6:52:21from the database as I mentioned we map
- 6:52:24this variation type uh
- 6:52:28options actually this should be called
- 6:52:31variation type option
- 6:52:35IDs let me double check this variation
- 6:52:39type option IDs yes option ID because
- 6:52:43this is how we called this in the
- 6:52:45database right so and the cart item is a
- 6:52:48model uh of the cart item
- 6:52:52class okay now if we go back into get
- 6:52:55cart items from database this is the
- 6:52:57place where we are using that we are
- 6:52:59taking that uh cart items here and after
- 6:53:06which we perform the iteration
- 6:53:09here and each cart item has option IDs
- 6:53:13that option IDs is what we return from
- 6:53:17here and also if we have a look inside
- 6:53:22save item to cookies we're going to see
- 6:53:25that when we create new cart item we
- 6:53:28give it also option
- 6:53:30IDs and then later when we we read
- 6:53:32something from the cookies this is the
- 6:53:35format that is returned from
- 6:53:38cookies
- 6:53:40okay so this is great and I think uh we
- 6:53:45have now these three main methods add
- 6:53:48item to cart update item quantity and
- 6:53:51remove from cart which is now um more
- 6:53:55generic methods they don't look at the
- 6:53:58whether it is for the database or not
- 6:54:04now let's obviously implement the first
- 6:54:06one add um item to cart so we have the
- 6:54:09option IDs here as the third argument
- 6:54:12which might be null so we are going to
- 6:54:14check if option IDs is actually
- 6:54:19null then we're going to take the first
- 6:54:24option IDs from the product and add that
- 6:54:27into the cart of course if the option
- 6:54:30IDs are defined and this is necessary
- 6:54:33when implementing a to card
- 6:54:35functionality from product listing if we
- 6:54:38check our page go to the uh homepage so
- 6:54:41when I click Ed to card from
- 6:54:44here uh if the product obviously doesn't
- 6:54:46have any variation types or variation
- 6:54:49type options defined it is going to add
- 6:54:50the product itself into the cart however
- 6:54:53if the product has variation types and
- 6:54:55variation type options defined then I
- 6:54:57want the first variation type options to
- 6:55:01be added into the card which is
- 6:55:02displayed right here as well which
- 6:55:04should be displayed right here as well
- 6:55:05at the moment we also don't display the
- 6:55:07image from the variation type options
- 6:55:10which we should do and we will do we
- 6:55:13display this t-shirt but internally this
- 6:55:15is actually um headset right so we want
- 6:55:18to display um the uh black with small
- 6:55:23variation type when we go back on the
- 6:55:27homepage okay so if there are those um
- 6:55:30variation type options toine and this is
- 6:55:32what we're going to do so we're going to
- 6:55:34generate option IDs equals from the
- 6:55:37product we're going to access variation
- 6:55:41types then actually
- 6:55:44this this should be property so then I'm
- 6:55:49going to call method map with keys
- 6:55:52because I want to generate associative
- 6:55:54array not a direct array so I'm using
- 6:55:57this map with keys method on the
- 6:55:59collection so here we have the this
- 6:56:03variation type uh let me actually
- 6:56:05convert this into Arrow function so we
- 6:56:08accept type here let's call this type
- 6:56:14and then we're going to return type ID
- 6:56:18and we're going to return
- 6:56:21type
- 6:56:22options at index
- 6:56:25zero and ID of that however ID however
- 6:56:31we're going to check that that if the
- 6:56:33option zero exists if it doesn't exist
- 6:56:36this will return simply null okay so
- 6:56:42then we're going to call two array to
- 6:56:45convert this into um array because this
- 6:56:49map with keys returns collection okay so
- 6:56:51when we implement this we're going to
- 6:56:53obviously check everything and make sure
- 6:56:54that it works and when you implement it
- 6:56:57when you are working in real project you
- 6:56:59are going to test this into multiple
- 6:57:01different cases and scenarios which
- 6:57:04we're going to also
- 6:57:05do okay now we have the option idas next
- 6:57:09is to calculate the to get the price
- 6:57:12which should be used to add the item
- 6:57:14into the cart and price is also a tricky
- 6:57:17thing so we can directly access product
- 6:57:19price but based on these option IDs the
- 6:57:23price might actually be different okay
- 6:57:27because we allo that to specify
- 6:57:30different prices for
- 6:57:32um different variation
- 6:57:36options okay so I'm going to uh create
- 6:57:39new method on the product model and
- 6:57:44let's put this at the very bottom and we
- 6:57:46can call this uh
- 6:57:49get price for options and here we're
- 6:57:54going to accept option ID this which is
- 6:57:58actually going to be array associative
- 6:58:01array Maybe
- 6:58:04get price for options let's check so
- 6:58:07because right here we are calling this
- 6:58:09map with keys option ID is is going to
- 6:58:11return associative array where key is
- 6:58:14the type ID and the value is its
- 6:58:16corresponding option ID so here we are
- 6:58:19only interested in options so I'm going
- 6:58:22to convert these option IDs into array
- 6:58:26values with the option IDs okay um
- 6:58:32you probably have a question so if we
- 6:58:34are only interested in uh values not
- 6:58:38keys of these options why we are not
- 6:58:42simply calling uh map right here and
- 6:58:45taking the option IDs instead of map
- 6:58:47with keys and taking the type ID as well
- 6:58:50as a key of these option
- 6:58:53IDs okay so because that associative
- 6:58:56area always gives us more information we
- 6:58:59have also type ID okay at the moment I
- 6:59:02don't need the type ID but I might need
- 6:59:06this in a different place okay so you
- 6:59:10can obviously change this into map and
- 6:59:12use the option IDs and then avoid these
- 6:59:15array values right here which is
- 6:59:17something I'm not going to do okay so
- 6:59:20sort we're going to sort those option
- 6:59:23IDs after which I'm going to start
- 6:59:26iteration over for each
- 6:59:30over uh this which is product these
- 6:59:35variations okay and here we're going to
- 6:59:38have
- 6:59:39variation then the variation has
- 6:59:42variation type option IDs and I'm going
- 6:59:44to just create a temporary variable here
- 6:59:47uh which will be
- 6:59:49variation variation type option IDs now
- 6:59:55this is what I am going to do I'm going
- 6:59:57to sort this a which is variation type
- 7:00:01option ID is for the variation in the
- 7:00:04database and then I'm going to check
- 7:00:09if option IDs my option IDs is the same
- 7:00:14as these variation type option IDs both
- 7:00:16of them are sorted I sorted my option
- 7:00:19IDs and also the variation variation
- 7:00:22type option IDs is also sorted so if
- 7:00:25this happens then I am going to return
- 7:00:28the variation price okay
- 7:00:32um however if that the the if statement
- 7:00:38was not satisfied at the end of the for
- 7:00:41loop I am going to
- 7:00:43return
- 7:00:45this
- 7:00:47price so we should probably test the
- 7:00:50case when uh the specific variation
- 7:00:53doesn't have price the matching might
- 7:00:55happen but the price might be empty in
- 7:01:00which case we should Pro probably return
- 7:01:04uh the product price this price but I'm
- 7:01:07not going to do like this because if the
- 7:01:09price is zero that is um specific case
- 7:01:14so we should not have probably price
- 7:01:16zero right
- 7:01:18so uh yeah depending on uh depending on
- 7:01:22your specific thing you might want to
- 7:01:24give someone some product for free in
- 7:01:26which case you can give it price zero so
- 7:01:29in which case this is what I'm going to
- 7:01:30do so if VAR
- 7:01:32price does not equal to
- 7:01:36null then we're going to use the
- 7:01:38variation price otherwise if it is null
- 7:01:43then we're going to use this price the
- 7:01:45product price if it is zero I'm still
- 7:01:48using this variation price which will be
- 7:01:52zero now go back into card service so
- 7:01:55here now on this product I'm going to
- 7:01:57use get price for options providing
- 7:02:01option IDs here okay so now we have the
- 7:02:04price and I'm going to do check if
- 7:02:07out check happens if the user is
- 7:02:11authenticated then I'm going to call
- 7:02:13this save item to database
- 7:02:17providing um providing product ID we
- 7:02:22need ID providing quantity price and
- 7:02:26option IDs I think we need all of them
- 7:02:29we have these four arguments cool
- 7:02:33if the user is not authenticated then
- 7:02:36we're going to call Save item to cookies
- 7:02:39providing a gain the same type of
- 7:02:42data let's scroll down below and
- 7:02:44Implement update item quantity or it's
- 7:02:47uh much easier so we're going to use out
- 7:02:50check if the user is
- 7:02:52authenticated then this uh we're going
- 7:02:56to
- 7:02:57call update item quantity in database
- 7:03:01we're going to provide the product ID
- 7:03:03quantity and option
- 7:03:05IDs
- 7:03:08else we're going to call this update
- 7:03:11item quantity into cookies providing
- 7:03:13credit ID quantity and option IDs and
- 7:03:16finally we have remove item from cart
- 7:03:19we're going to do if out check then this
- 7:03:22remove item from
- 7:03:24database else this remove item from
- 7:03:30cookies o a lot of work inside card
- 7:03:34service but I think that we have this
- 7:03:37card service right now
- 7:03:39ready and let's go
- 7:03:42into card
- 7:03:45controller and have a look inside store
- 7:03:48which is fully implemented we have the
- 7:03:50root ready as well and I think we're
- 7:03:54going to go
- 7:03:59into let's open show TS six I think we
- 7:04:02also have cart store implemented here
- 7:04:07that's it we are providing the correct
- 7:04:09data so I think we should we should have
- 7:04:10everything ready now let's test this I'm
- 7:04:12looking forward to test this let's click
- 7:04:14on the product Details page this is
- 7:04:16going to open the I'm going to open Dev
- 7:04:18tools as well we have some error it's
- 7:04:21time to fix the
- 7:04:23errors okay the final argument pass to
- 7:04:26use effect changed size between renders
- 7:04:31the order in size of this array must
- 7:04:34remain
- 7:04:38constant interesting
- 7:04:42error okay I am not um right now fully
- 7:04:50sure how that should be fixed I think I
- 7:04:53know the reason um but let me focus on a
- 7:04:58to card first and I will um save your
- 7:05:00time to find that um information
- 7:05:04out so yeah I need the dev tools because
- 7:05:06I'm going to send the request let's go
- 7:05:08into Network and I'm going to click
- 7:05:11this um a to cart let's have a
- 7:05:15look okay uh app service out okay yeah
- 7:05:18yeah of course of course so in the card
- 7:05:21service we have bunch of classes which
- 7:05:24are not imported like we need to import
- 7:05:26this out which is going to be illuminate
- 7:05:29support facad out we have couple of
- 7:05:33other classes like variation type option
- 7:05:36we're going to import that we have this
- 7:05:40log which needs to be imported from
- 7:05:43facad
- 7:05:45log what else information do we have we
- 7:05:48have to import this card
- 7:05:51item and we have to import this que
- 7:05:54which is going to be illuminate support
- 7:05:57facades q and I think we don't have any
- 7:06:01anything else to import we imported
- 7:06:03everything what we need in this file so
- 7:06:06I'm going to save that and click on this
- 7:06:08add to card once again which returned
- 7:06:12successfully we don't have anything in
- 7:06:14the
- 7:06:16errors oh we didn't see the success
- 7:06:18message right so I'm going to click on
- 7:06:21this Ed to cart again we didn't see the
- 7:06:23success message because we didn't use
- 7:06:25that success message uh we return this
- 7:06:28from the controller from here but we
- 7:06:31don't use it and we're going to use this
- 7:06:33but now we can check the card items
- 7:06:36table we checked it we didn't see
- 7:06:40anything uh the current user is not
- 7:06:43authenticated and this is why we didn't
- 7:06:45see anything which gives me a promise
- 7:06:48that the data was saved inside the cart
- 7:06:51so now if we go
- 7:06:56into let me think so I'm going to open
- 7:07:00handle inera JS requests and basically
- 7:07:05right here we are rendering the
- 7:07:07following card drop down and in the
- 7:07:09following dropdown we are going to
- 7:07:11render the card items right so inside
- 7:07:13this handle injs request we have this
- 7:07:16shared data and inside the data we're
- 7:07:19going to pass two things first we're
- 7:07:21going to pass the success what we just
- 7:07:25set inside the card controller so we're
- 7:07:28going to get this from session session
- 7:07:31ESS and second we are going to pass cart
- 7:07:36items and this is going to
- 7:07:40be to use the card service now we can
- 7:07:43use this dependency injection and we're
- 7:07:46going to uh take the class cart
- 7:07:50service
- 7:07:51here and we need few things so we need
- 7:07:55total quantity which is the hardcoded
- 7:07:57eight right here so let's use total
- 7:08:01Quant
- 7:08:02which will be card service get total
- 7:08:06quantity okay I think we cannot use this
- 7:08:09card service like this instead we can
- 7:08:12access this from the application so card
- 7:08:15service equals app card service now we
- 7:08:18get the total quantity we are going to
- 7:08:21get total price card service get total
- 7:08:24price and we're going to have cart items
- 7:08:28as well now I want to print all of them
- 7:08:32let's use DD I want to print total price
- 7:08:37I want to print total quantity and card
- 7:08:40items and let's refresh the
- 7:08:43page uh we have some syntax
- 7:08:46error right here let's put the cart
- 7:08:50items refresh the page now we don't have
- 7:08:53anything inside cookies which is
- 7:08:57actually not good I thought we inserted
- 7:09:00that information
- 7:09:02now we are going to debug
- 7:09:06this let's go into card service and find
- 7:09:11this save item to cookies and we are
- 7:09:16going to print
- 7:09:17existing let's print existing uh cart
- 7:09:21items we're going to print product ID
- 7:09:25quantity price and option IDs when we
- 7:09:27try to add something inside the cookie
- 7:09:30I'm going to click on the and we see the
- 7:09:32following information
- 7:09:34so this is the existing information
- 7:09:37which already exists inside the cookies
- 7:09:41right
- 7:09:44yeah okay so the information is already
- 7:09:47inside the cookies we have it two
- 7:09:53times okay I'm going to undo this and
- 7:09:56let's check get card items
- 7:10:01which selects the cart items from
- 7:10:03cookies now let's print that cart items
- 7:10:09here refresh the page we see those cart
- 7:10:12items okay
- 7:10:16awesome but why don't we
- 7:10:20see these cart items
- 7:10:23here DD cart
- 7:10:26items okay maybe something is messed up
- 7:10:30here so we have this card
- 7:10:32items um we have this card item
- 7:10:36data maybe some exception happens
- 7:10:40definitely some exception happens here
- 7:10:42and because of this we don't see it so
- 7:10:44let's execute throw
- 7:10:47e refresh the
- 7:10:50page attempt to read property store name
- 7:10:53of n exactly so the current um the owner
- 7:10:58of this current product which is
- 7:11:00actually vendor
- 7:11:02all right so if we check the
- 7:11:07products so this is the first product it
- 7:11:09has the created by field to be two and
- 7:11:13created uh the two ID is the vendor okay
- 7:11:16and we need to set a rule that every
- 7:11:21vendor needs to have the corresponding
- 7:11:23record in the vendor table in fact if we
- 7:11:26open user CED I'm going to update that
- 7:11:30part as well and here I create the
- 7:11:34user then we assign
- 7:11:37that role into the
- 7:11:39user but after this I'm going to create
- 7:11:44vendor
- 7:11:48Factory uh vendor doesn't have
- 7:11:51Factory vendor doesn't have Factory but
- 7:11:53it's not important because we don't need
- 7:11:56to Define these fields inside the
- 7:11:58factory we can provide these fields
- 7:12:00right here so I'm going to provide user
- 7:12:01ID I'm going to provide the status for
- 7:12:06the vendor and for this I think I'm
- 7:12:09going to Define new enam and this is
- 7:12:12going to
- 7:12:13be hbr artisan make
- 7:12:16enam
- 7:12:18vendor status
- 7:12:23an we hit the enter that was created
- 7:12:25under app enms vendor status enm now
- 7:12:28let's open vendor
- 7:12:31status
- 7:12:34enam return type is
- 7:12:37string um not return type but the enm
- 7:12:41type and we have
- 7:12:44these actually let me duplicate these
- 7:12:46three times so this is going to be
- 7:12:52pending pending or let me do this
- 7:12:55lowercase pending then we have approved
- 7:13:01approved and we're going to have
- 7:13:07rejected now if we go open this user
- 7:13:10Ceder here inside the status we are
- 7:13:14going to
- 7:13:15use vender status
- 7:13:19enam uh let's make it approved
- 7:13:24okay we need store name as
- 7:13:28well which is going to be something
- 7:13:34we need store address as well let's give
- 7:13:38it some fake
- 7:13:42address and I think we don't need
- 7:13:44anything else so we create this vendor
- 7:13:47for the specific user but we're doing
- 7:13:49this inside the cedar class and I don't
- 7:13:52want to rerun actually all my migrations
- 7:13:55and delete the current product what I
- 7:13:57have in the database created so I'm
- 7:13:59going to create the same type of vendor
- 7:14:03manually so open the vendors table click
- 7:14:07on this user ID is actually two uh this
- 7:14:11is approved store name is vendor store
- 7:14:16store address is some test address and
- 7:14:21we have the cover cover image I'm going
- 7:14:23to leave empty created at is actually
- 7:14:26now and updated at is actually now as
- 7:14:29well
- 7:14:34okay now if we refresh this page we are
- 7:14:38not going to see this
- 7:14:40error that's
- 7:14:42perfect let's go
- 7:14:45inside card service remove this
- 7:14:50through go inside handle initial JS
- 7:14:53request and I'm going to dump C
- 7:14:58items but before these I'm going to dump
- 7:15:00total price and total quantity as well
- 7:15:05refresh the page we see total price is
- 7:15:0850 total quantity is two and right here
- 7:15:12we see the product with its uh ID the
- 7:15:15product ID this ID is actually the our
- 7:15:19generated U ID so we have the title
- 7:15:22slack price everything is here including
- 7:15:25image and we have the user information
- 7:15:27as well and this is so cool so I think
- 7:15:32we just need to provide that information
- 7:15:35inside here inside the shared
- 7:15:39data so I'm going to call
- 7:15:44these uh so total
- 7:15:47price and total quantity okay we provide
- 7:15:52both now we're going to get those card
- 7:15:56items inside
- 7:15:59navbar and here we have eight written
- 7:16:03somewhere this is the place okay so this
- 7:16:06is what I am going to
- 7:16:08change we have the page props and from
- 7:16:11this page props we're going to take
- 7:16:13total price and total
- 7:16:19quantity but these need to be defined
- 7:16:22inside page
- 7:16:24props so for this I'm going to open
- 7:16:28index.ts
- 7:16:30let's open page props here we have out
- 7:16:34and Ziggy and let's add
- 7:16:37total quantity which is going to be
- 7:16:40number and total price which is going to
- 7:16:44be number as well but we also want cart
- 7:16:48items here which is going to be array of
- 7:16:52cart
- 7:16:53item now let me Define this cart item
- 7:16:58class somewhere right here x Port type
- 7:17:02cart
- 7:17:04item and we need ID we need product ID
- 7:17:09we need uh title of the um product we
- 7:17:14need slug we need
- 7:17:18image um we need price as well we need
- 7:17:24quantity we also need option IDs which
- 7:17:28is going to be actually op object so I'm
- 7:17:31using record here string and number the
- 7:17:35key is going to be the uh type ID and
- 7:17:39the value is going to be uh the option
- 7:17:41ID so we can use string in both cases or
- 7:17:44we can use numbers as well in both
- 7:17:47cases um but yeah as I tested like
- 7:17:50string as a key was working better
- 7:17:52speaking of the
- 7:17:55object and we have these options as well
- 7:17:58so this is going to be very viation oops
- 7:18:02variation type option array of these
- 7:18:07variation type options so now here the
- 7:18:10cart items is going to be cart item area
- 7:18:12of cart
- 7:18:14items so we have the total price total
- 7:18:16quantity they are actually uh now autoc
- 7:18:19completed by
- 7:18:21IDE and we are going to find that total
- 7:18:25price and total quantity I think we have
- 7:18:28this total quantity here
- 7:18:32and we don't have total
- 7:18:36price let's
- 7:18:38see refresh the
- 7:18:42page we see two which is the total
- 7:18:44quantity and that is so cool if I click
- 7:18:47on this uh that is the data I want to
- 7:18:51change
- 7:18:53so let's have a look so we have this
- 7:18:56drop down drop down end
- 7:19:00this is the drop down so this drop down
- 7:19:03end I'm going to extract this into a new
- 7:19:07component and that component will
- 7:19:11be application specific component so
- 7:19:15resources ajs components up here I'm
- 7:19:18going to
- 7:19:21create uh mini cart dropdown so we're
- 7:19:25going to have uh probably a separate
- 7:19:28cart component which is going to be for
- 7:19:30the entire page but this is kind of mini
- 7:19:33cards drop down and let's create the
- 7:19:37component inside this mini cart
- 7:19:41dropdown we are going to accept all
- 7:19:43these properties um from the used page
- 7:19:47props so const uh I'm going to
- 7:19:50destructure something here use page.
- 7:19:56props so then I'm going to destructure
- 7:20:02hold on let me think so I'm going to
- 7:20:05destructure and take total
- 7:20:08quantity total price and cart
- 7:20:13items we don't need props
- 7:20:16here let me use this mini card drop down
- 7:20:20in this
- 7:20:21place and we have this boiler plate code
- 7:20:25which I copied and I'm going to put this
- 7:20:28right here
- 7:20:32so we have total eight items I'm going
- 7:20:34to replace these with total
- 7:20:41quantity and here I'm going to
- 7:20:45use l is extra in here I am going to use
- 7:20:49currency
- 7:20:50format so inside subtotal we're going to
- 7:20:54use currency format providing total
- 7:20:57price
- 7:21:00and then we have this view cart uh which
- 7:21:03has the purpose to open the cart Details
- 7:21:05page so I'm going to change this into
- 7:21:07link uh providing h r here
- 7:21:13root uh
- 7:21:15cart.
- 7:21:16index which is something we already
- 7:21:21defined okay so we have more things to
- 7:21:25do inside this dropdown but for now we
- 7:21:27see that we have two total items and the
- 7:21:30sub total is
- 7:21:3250 but now I'm going to actually display
- 7:21:36those uh card items as well in the
- 7:21:39following
- 7:21:42area between this uh number of items and
- 7:21:46subtotal I'm going to display those
- 7:21:49actual cart items so let me create div
- 7:21:52uh div not div but give it margin y4 a
- 7:21:57maximum heit of like 300 pixel and I'm
- 7:22:02going to give it overflow
- 7:22:05Auto then I'm going to iterate over cart
- 7:22:09items call map we
- 7:22:13have the item actually uh before I do
- 7:22:17this I'm going to also check if the cart
- 7:22:20items is empty so if cart items.
- 7:22:24length uh if that equals zero then
- 7:22:30I am going to render something that
- 7:22:33something is going to be div give it
- 7:22:35some classes like pting Y
- 7:22:382 uh text Gray uh 500 and give it text
- 7:22:44Center as well and the message is go
- 7:22:47going to be you don't have any
- 7:22:51items
- 7:22:54yet okay however when I want to iterate
- 7:22:58over my part item I want to create div
- 7:23:03let's give it key to be item. ID uh
- 7:23:08let's give it also class
- 7:23:10names
- 7:23:11Flex gap of four and padding
- 7:23:16three then I'm going to create link and
- 7:23:20that link is going to be for the
- 7:23:23image okay so side link we're going to
- 7:23:26provide hre we are going to use r wrote
- 7:23:34product product. show and we're going to
- 7:23:38provide item slug here because we are
- 7:23:42going to open this
- 7:23:45um using
- 7:23:47slug actually I'm going to create a
- 7:23:52helper helper function um inside the
- 7:23:57helpers file I'm thinking right now so
- 7:24:02let's put an image
- 7:24:04here first I will come back to this um
- 7:24:07product show I think I will come back to
- 7:24:10this definitely so inside this image
- 7:24:13we're going to
- 7:24:14provide um item.
- 7:24:18image we can provide also item. title
- 7:24:23inside alt and inside the class name I'm
- 7:24:26going to move this down let's move alt
- 7:24:29down as as well and inside class name I
- 7:24:32want to provide maximum W full and Max H
- 7:24:39full so next I'm going to create div
- 7:24:42outside of this link so we're going to
- 7:24:44have image on the left side and on the
- 7:24:46right side we're going to have a couple
- 7:24:48of information like title which is going
- 7:24:50to be inside H3 let's give this uh Flex
- 7:24:55one then I'm going to give into this
- 7:24:58H3 class name margin btom 3 font
- 7:25:05semibold and the and then inside here
- 7:25:08we're going to have
- 7:25:11link
- 7:25:14href uh here we're going to have root
- 7:25:19dot product. show with item
- 7:25:24Slug and we're going to Output item.
- 7:25:28title below this H2 we're going to
- 7:25:31display the quantity of the product and
- 7:25:35the price of the product so let's create
- 7:25:38this Steve I'm going to give it
- 7:25:40Flex uh let's give
- 7:25:43it uh justify between and text
- 7:25:48small then I'm going to have one extra D
- 7:25:51for
- 7:25:53quantity item. quantity and I'm going to
- 7:25:57have another D which is going to be for
- 7:25:59price
- 7:26:00currency
- 7:26:02format
- 7:26:04amount item.
- 7:26:09price actually the price is going to be
- 7:26:12item. quantity Multiplied on
- 7:26:21price okay let's save this and have a
- 7:26:24look click on the
- 7:26:27dropdown we see those two items
- 7:26:31I think we have to increase the width of
- 7:26:34the drop down
- 7:26:36right
- 7:26:39let's let's find these card
- 7:26:44element we have card card
- 7:26:47compact uh with width of 52 we're going
- 7:26:52to change this into some fixed withd
- 7:26:55which I'm going to give it 480 pixel
- 7:27:02okay now the image is
- 7:27:07huge let's find this image area and to
- 7:27:11the following link I'm going to give it
- 7:27:13class
- 7:27:15name uh
- 7:27:18W6
- 7:27:22h16 uh
- 7:27:24Flex
- 7:27:26justify
- 7:27:28Center and and we can give it item
- 7:27:31Center as well to put this image inside
- 7:27:33the
- 7:27:35center that's more like
- 7:27:41it and let me find
- 7:27:45subtotal sub total and I want to change
- 7:27:50this text color as
- 7:27:55well yeah I'm going to give it text
- 7:27:59large
- 7:28:03okay that's it so we have two items uh
- 7:28:06the title when we click on this it is
- 7:28:09going to open the product Details
- 7:28:11page
- 7:28:15right clicking on the title is going to
- 7:28:18do the same
- 7:28:21thing
- 7:28:23great next I'm going to start working on
- 7:28:26the dedicated card page when I click
- 7:28:29this view card which should open the
- 7:28:33card Details
- 7:28:35page um this is coming from the card
- 7:28:37controller and we have the card service
- 7:28:39printed right there okay so let's open
- 7:28:42card
- 7:28:44controller find
- 7:28:46index and let's adjust this so we're
- 7:28:50going to return inertia
- 7:28:53render cart slash index and we're going
- 7:28:59to return the following information so
- 7:29:01we need card
- 7:29:02items and we're going to take those card
- 7:29:05items
- 7:29:07from the card
- 7:29:10service uh however this is not exactly
- 7:29:13how I want to pass that uh let's open
- 7:29:17card service and I'm going to add a new
- 7:29:19method inside the card service and I
- 7:29:21want to group cart items based on the
- 7:29:24vendor user the seller user okay and I'm
- 7:29:28going to render them
- 7:29:31like based on the user so let's define
- 7:29:34the method get cart items grouped which
- 7:29:37is going to return an array so I'm going
- 7:29:38to select these gate cart items to get
- 7:29:41the cart items actually then I'm going
- 7:29:43to convert those cart items into
- 7:29:45collection I'm going to call group Pi
- 7:29:48okay and I'm going to uh inside this
- 7:29:50group P I'm going to group those cart
- 7:29:55items based on the item user ID
- 7:30:00okay then I'm going to call map on this
- 7:30:02now we have these items which is going
- 7:30:04to be already so the these already
- 7:30:07perform the grouping right so then this
- 7:30:09is going to be the data values this is
- 7:30:11going to be the key and then I am taking
- 7:30:14from these items which is going to be
- 7:30:17cart items array so I am taking the
- 7:30:22first cart item and the user information
- 7:30:25out of it okay I'm returning that user
- 7:30:29information and I am returning the items
- 7:30:33itself in in in the format of array
- 7:30:37after which we're going to add total
- 7:30:39quantity as well and the total quantity
- 7:30:42will be for each user so for each user
- 7:30:47we're going to also have how many
- 7:30:50items um for each vendor more more
- 7:30:53precisely for each vendor we have user
- 7:30:56here but it's actually vendor
- 7:30:57information right so this is seller as
- 7:31:00well for each seller we're going to also
- 7:31:03have how many total quantity items the
- 7:31:07currently authenticated user has added
- 7:31:10into the cart not not necessarily the
- 7:31:13authenticated but the current user who
- 7:31:15is viewing the browser has added into
- 7:31:18the cart or What's the total price uh
- 7:31:21here so in case of total price we take
- 7:31:24those items which is
- 7:31:26collection of these cart items and we
- 7:31:30are calling sum here to create the sum
- 7:31:33using item price multipli than item
- 7:31:37quantity and thus the total price will
- 7:31:39contain the entire price for this
- 7:31:42specific seller okay then we're calling
- 7:31:45this two area right here this is going
- 7:31:47to return the card items grouped so here
- 7:31:50I am going to use get card items grouped
- 7:31:54okay and we're going to also
- 7:31:57provide here total
- 7:32:01uh total
- 7:32:05quantity well actually I think we have
- 7:32:07total
- 7:32:09quantity and total price provided from
- 7:32:14the handle inertia JS request from here
- 7:32:18okay that actually does the same thing
- 7:32:21okay so we have these card items cool I
- 7:32:23think this is all what we needed now
- 7:32:26let's go into JS and I'm going to create
- 7:32:33here cart slash
- 7:32:37index typescript
- 7:32:41file okay now I'm going to remove this
- 7:32:45Steve I'm going to remove these props
- 7:32:48and remove this
- 7:32:50react now here I'm going to accept
- 7:32:53couple of props so first I'm going to
- 7:32:55import page props class it's a type then
- 7:33:00we're going to Define props right here
- 7:33:02so I will need to implement the checkout
- 7:33:05functionality and for this I will need
- 7:33:07to submit the form not through inertia
- 7:33:11way but in a more traditional way like
- 7:33:15the typical form submission with uh the
- 7:33:18page refresh and reload so for this I
- 7:33:21need to use csrf token because I'm going
- 7:33:24to submit the form with post method and
- 7:33:28for this I will need CSR
- 7:33:30token so I'm going to
- 7:33:33open handle inertia JS requests and
- 7:33:36right here I'm going to add
- 7:33:40csrf token which is going to be the csrf
- 7:33:43token um string basically so then right
- 7:33:48here inside the index I am going to
- 7:33:50accept csrf token but let's actually
- 7:33:52Define this inside page props as well so
- 7:33:55we have
- 7:33:56csrf uncore token which is going going
- 7:33:59to be string and I formatted the code
- 7:34:03and it's going to be also required not
- 7:34:05optional now right here we're going to
- 7:34:08accept csrf token we're going to also
- 7:34:10accept cart items total quantity and
- 7:34:14total price all right and I'm going to
- 7:34:17define the type as well so this has type
- 7:34:20of the following object has type of page
- 7:34:23props however the cart items uh which we
- 7:34:27actually have defined as instance of
- 7:34:29cart items we are going to change its
- 7:34:32type into grouped cart items so this is
- 7:34:35an array we can obviously specified an
- 7:34:38array right here with square brackets um
- 7:34:41like these grouped card items instead of
- 7:34:44the selected text with square brackets
- 7:34:46but this is also going to do the same
- 7:34:49thing same thing okay so and we're going
- 7:34:52to Define this grouped cart items type
- 7:34:55I'm going to do this maybe below this
- 7:34:57cart item export
- 7:35:01um not default but export type grouped
- 7:35:05cart item and each grouped cart item has
- 7:35:09the user
- 7:35:10information and it has items and the
- 7:35:13items is array of cart item so this is
- 7:35:17how we return the cart items from the
- 7:35:19card
- 7:35:20controller as we see so each element
- 7:35:24from this array has user and items
- 7:35:27additionally if we want we can also
- 7:35:29Define total quantity and total price
- 7:35:32and then use them inside the view uh
- 7:35:37template uh let's open this index DTS
- 7:35:40and let's define
- 7:35:42them uh
- 7:35:44total total price let me Define this in
- 7:35:47uppercase way like I have defined it
- 7:35:49total price and total quantity now let's
- 7:35:53go into card service and change this
- 7:35:56into total price and total quantity with
- 7:35:58camel case
- 7:36:00notation now right here uh we're going
- 7:36:04to import this grouped card uh grouped
- 7:36:07card items in a little bit later now
- 7:36:10let's right here focus on the
- 7:36:14um the uh template area so we need
- 7:36:18authenticated layout inside which we're
- 7:36:20going to Define head then we're going to
- 7:36:23have div which is going to be the
- 7:36:24wrapper container with some t one cus
- 7:36:26classes inside here we're going to have
- 7:36:28additional d and that is going to be the
- 7:36:31card okay with background we're going to
- 7:36:33have card body so this is going to be
- 7:36:35the left area uh where we will display
- 7:36:39the card items and we're going to have
- 7:36:41second card as well which is going to be
- 7:36:43on the right side and this is going to
- 7:36:45display the information uh the total
- 7:36:48number of items inside the card total
- 7:36:50price and check out button as
- 7:36:54well okay cool now let's focus on the
- 7:36:57first T which is going to be where we
- 7:36:59display the the items so let's give it a
- 7:37:02title shopping cart and then create
- 7:37:04another div container inside which we
- 7:37:06are going to iterate over our card items
- 7:37:11okay so the card items uh we we take the
- 7:37:15keys of the cart items and the cart
- 7:37:18items actually if we check again in the
- 7:37:20card controller so this is uh
- 7:37:25associative array okay um
- 7:37:30definitely so uh because we are using a
- 7:37:32group by right here so we group those
- 7:37:35card items with the user ID meaning that
- 7:37:38the user ID is the key let me open U
- 7:37:41maybe scratch Json file or maybe scratch
- 7:37:44PHP file and I will show this to you
- 7:37:46exactly so these grouped cart items will
- 7:37:50have the following format so we have the
- 7:37:51user ID here and its
- 7:37:54corresponding uh object where we have
- 7:37:57the user information itself the entire
- 7:38:00user details and we have items which is
- 7:38:02going to be array additionally we also
- 7:38:05have total price which is going to be
- 7:38:07number and we also have total
- 7:38:12quantity which is also number so this is
- 7:38:15how cart items look like and we're going
- 7:38:17to have something
- 7:38:18similar if we added uh multiple cart
- 7:38:21items from different vendor users so
- 7:38:24this will be duplicated for different
- 7:38:26user for different user ID here and user
- 7:38:31details okay let's move this on the
- 7:38:33right side collapse a little bit so to
- 7:38:37get back to this index DTS uh I'm going
- 7:38:39to make one correction because I'm going
- 7:38:43to close this I think this is clear so
- 7:38:45I'm going to close this or move right
- 7:38:46here so because we have that as
- 7:38:50associative array because of that we
- 7:38:52need right here to use record um with
- 7:38:55key to be number user ID and the value
- 7:38:58to be group cart items
- 7:39:01okay now then we check if the object
- 7:39:03keys of this cart items length is equal
- 7:39:05zero if there is nothing added into the
- 7:39:07cart and then we're going to display the
- 7:39:09text you don't have any items yet
- 7:39:12however we're going to start iterating
- 7:39:13over cart items values in our case and
- 7:39:17we are going to obviously create D with
- 7:39:19key cart item user ID so that's the
- 7:39:21outer loop and we are doing this outer
- 7:39:24loop for each user we have two users in
- 7:39:27our example so the Outer Loop will be
- 7:39:29iterated two times okay then we display
- 7:39:33um the another div inside which we're
- 7:39:36going to have the link that link will be
- 7:39:38the usern name uh the that username is
- 7:39:41actually vendor name so if we check in
- 7:39:44the cart service we
- 7:39:46see um inside cart items get cart items
- 7:39:50scroll down
- 7:39:52below when we construct that cart item
- 7:39:56info we have the user user has ID user
- 7:39:59ID and the name is the vendor store name
- 7:40:03all right so that name is used right
- 7:40:06here when vendor store name we're going
- 7:40:09to import all the things after we finish
- 7:40:11working on the template so then we're
- 7:40:13going to have additional div inside
- 7:40:14which we're going to have form this is
- 7:40:16going to be on the right side so the
- 7:40:18vendor name on the left side using this
- 7:40:20justifi between right here and that form
- 7:40:23will be on the right side that form will
- 7:40:26post on cart checkout page page which we
- 7:40:30will create that road and then we're
- 7:40:34going to have input type hidden with a
- 7:40:36token this is CSF token uh which we just
- 7:40:40passed from the handle inertia JS
- 7:40:42request middle we then we're going to
- 7:40:44have additional hidden input and this is
- 7:40:46going to be for vendor ID so if we are
- 7:40:49going to do check out only for this
- 7:40:51vendor then we need the vendor ID as
- 7:40:53well on the server site I'm going to
- 7:40:55create this button button cost and pay
- 7:40:58only for the this seller so whenever
- 7:41:01user clicks on this the post request
- 7:41:04will be made a traditional submission
- 7:41:06will happen on this form with the token
- 7:41:08with this um vendor ID and the back end
- 7:41:11will handle the check out for that
- 7:41:14specific
- 7:41:16vendor there are a few things to make uh
- 7:41:19and one of them is uh this credit credit
- 7:41:22card icon for this we're going to
- 7:41:23install hero icons react package and
- 7:41:27again let's finish working on the
- 7:41:29template and we will come back and do
- 7:41:32the uh following thing so after this
- 7:41:35form then down below we can start
- 7:41:36iterating over the cart items let me
- 7:41:38collapse this section so this was the uh
- 7:41:41header kind of header uh which contains
- 7:41:44the user information as well as the um
- 7:41:47pay only for this seller button now we
- 7:41:50iterate our cart items and we are going
- 7:41:52to create new component cart item pass
- 7:41:56the item itself and the uh key
- 7:41:59after which we can focus on the right
- 7:42:02side of this page where we're going to
- 7:42:04have subtotal which is going to be total
- 7:42:06quantity items we're going to have a
- 7:42:09formatted currency with the total price
- 7:42:12and we're going to have also form here
- 7:42:14with the same action same method now we
- 7:42:17need also csrf token and we need this
- 7:42:20primary button right here which is going
- 7:42:23to have proceed to checkout so we don't
- 7:42:25have the vendor ID right here because
- 7:42:27that proceed to checkout is for the
- 7:42:29entire cart not only for a single
- 7:42:33seller okay now we're going to install
- 7:42:37uh hero icons
- 7:42:40react let's click on this uh we can
- 7:42:43click on the
- 7:42:44npmjs I'm going to copy this open
- 7:42:48Terminal and in a new terminal I'm going
- 7:42:51to paste and hit the enter this is going
- 7:42:53to install hero icons and while this is
- 7:42:55being installed let's include import
- 7:42:59those uh classes like grouped cart items
- 7:43:03we're going to import this from
- 7:43:05types awesome so we're going to import
- 7:43:08this authenticated
- 7:43:11layout cool we are going it is
- 7:43:15indexing it was not able to
- 7:43:23import now it was imported we imported
- 7:43:27head as well group cart items is this
- 7:43:32something grouped cart item okay so I
- 7:43:35call this item but actually it's items
- 7:43:37it is not single item so let's give it
- 7:43:40items as
- 7:43:41well okay scroll down below so we are
- 7:43:44going to create that cart item and let
- 7:43:46me do this right now under resources JS
- 7:43:50components app let's create new
- 7:43:54typescript file cart item
- 7:44:00let's define the component remove this
- 7:44:02react remove this props remove this
- 7:44:05template we're going to work work on
- 7:44:07this component in a moment scroll down
- 7:44:11below we're going to import this
- 7:44:12currency
- 7:44:13format we're going to import this
- 7:44:16primary
- 7:44:17button and we're going to import this
- 7:44:19credit card icon and I'm going to import
- 7:44:22this from outline
- 7:44:26version let's see that was imported as
- 7:44:28well okay and now we have few things
- 7:44:30first is card
- 7:44:33item
- 7:44:34[Music]
- 7:44:36and I guess that is all what's
- 7:44:44this yeah I think that is missing here
- 7:44:48okay
- 7:44:50cool let me actually um do the following
- 7:44:54so I want to display um each item so let
- 7:45:00me use Json
- 7:45:04stringify uh hold on so I'm going to cut
- 7:45:08this and now here let's use Json
- 7:45:14stringify item undefined
- 7:45:18to now let's have a look on the
- 7:45:22page view
- 7:45:25cart let's see I think we had a 500 eror
- 7:45:29there let's click on this view
- 7:45:36cart okay let's try to access SL
- 7:45:39card and have a
- 7:45:45look
- 7:45:46okay maybe this
- 7:45:49server let's let's restart mpm
- 7:45:53randev and have a look refresh the page
- 7:45:57here we have that JS page PES cart
- 7:45:59wasn't found maybe that was causing the
- 7:46:02issue Pages cart index JS Pages cart
- 7:46:06index okay what's going on let's open
- 7:46:09card controller in your sh render cart
- 7:46:13index provide the cart items okay
- 7:46:20cool Pages cart index
- 7:46:30let's check
- 7:46:31Roots we have some stupid issue on
- 7:46:36cart we render this index
- 7:46:41method okay um I have
- 7:46:44a doubt that the issue might be
- 7:46:48inside uh the following area we have
- 7:46:51this handle injs requests where we use
- 7:46:54also cart items right here as a page
- 7:46:56prop and we are passing cart items as a
- 7:46:59page propriate here maybe it conflicts
- 7:47:02to each other so because this is kind of
- 7:47:06um this inside the sandal iner JS
- 7:47:09request is for the header drop down cart
- 7:47:11dropdown data it's a something like mini
- 7:47:14cart I'm going to call this mini mini
- 7:47:18cart items in which case we have to
- 7:47:21open mini cart
- 7:47:24dropdown and we have to instead of cart
- 7:47:27items we're going to accept mini cart
- 7:47:30items um and we're going to iterate over
- 7:47:33mini cart items here and here however
- 7:47:37we're going to open the types and inside
- 7:47:41the page
- 7:47:44props let's find page props and we are
- 7:47:49going to also change this into mini card
- 7:47:56items okay the is gone let's refresh the
- 7:48:02page okay it seems like it is not the
- 7:48:13reason okay I'm going to stop the
- 7:48:15V let's have a
- 7:48:19look
- 7:48:23mpm maybe I created this in a wrong
- 7:48:27place pages
- 7:48:31okay where's this index that's the issue
- 7:48:33I created this index somewhere in a
- 7:48:35stupid place under JS directly that
- 7:48:38should be under Pages that's my
- 7:48:42bad that's that's causing the
- 7:48:46issue yeah the link needs to be also
- 7:48:52imported cool now all errors are gone uh
- 7:48:56we can execute mpm run de again a little
- 7:48:59bit of debugging and now if we refresh
- 7:49:02the
- 7:49:04page we are going to say something
- 7:49:11hopefully
- 7:49:17oops okay now we have a different error
- 7:49:20inside here card checkout is not in the
- 7:49:23root list okay that's logical error so
- 7:49:25we're going to go into our PHP and we're
- 7:49:27going to Define this card check out
- 7:49:29however cart checkout is only for
- 7:49:32authenticated users it is not going to
- 7:49:35be for um for guest
- 7:49:39users okay so far we defined the roots
- 7:49:41for guest users let's give it a comment
- 7:49:44guest
- 7:49:46roads then these are for uh out roads
- 7:49:50and inside out I want to Define another
- 7:49:54middle we which should be verified
- 7:49:58middle wear
- 7:50:00okay the user needs to be authenticated
- 7:50:02as well as verified after which we can
- 7:50:05Define
- 7:50:06root post cart SL checkout we use cart
- 7:50:12controller checkout method and the name
- 7:50:15of the route is also card checkout we
- 7:50:17have to create that checkout method
- 7:50:19inside the card controller so I'm going
- 7:50:20to create blank method at the moment
- 7:50:24refresh the page we see something
- 7:50:27already we we have another issue right
- 7:50:29here each child in the list I think uh
- 7:50:33this is coming from where we have
- 7:50:39this
- 7:50:43um no this is coming from
- 7:50:46here we generally need to follow the
- 7:50:49errors so cart item cart item. user. ID
- 7:50:55is coming from here instead of cart item
- 7:50:57user ID we should use cart item id
- 7:51:01here shouldn't
- 7:51:06we hold on wait
- 7:51:10so no we should use cart
- 7:51:14item user ID because that is outer loop
- 7:51:18and we are
- 7:51:20iterating over the users and then we
- 7:51:23have this pay only for the seller so
- 7:51:26what's the issue right here we have the
- 7:51:27key L added to this it should not be any
- 7:51:37problem okay um I have a question what
- 7:51:40is this why it is not unique so let's
- 7:51:43print out the entire cart item user
- 7:51:47using Json
- 7:51:48stringify uh cart item
- 7:51:52user entire cart item no let's print
- 7:51:55cart item user
- 7:51:58we see we have the user has ID and
- 7:52:01name so if I use cart item user ID
- 7:52:05what's the
- 7:52:08issue I think there is no
- 7:52:14issue so I'm not quite sure about this
- 7:52:17so I will come back to this and um fix
- 7:52:20that but right now what I was interested
- 7:52:22is uh the following area
- 7:52:26where we have
- 7:52:30have yeah let me use the pre-ex here
- 7:52:33where we have this entire uh product so
- 7:52:36we have the information about the cart
- 7:52:38item this is the ID this is the product
- 7:52:40title slug price quantity option IDs
- 7:52:43okay awesome and options as well and
- 7:52:46option uh we have the image as well
- 7:52:49which is going to be taken either from
- 7:52:51the option or from the um product itself
- 7:52:58okay so let's return right here the
- 7:53:02component cart item and I think we can
- 7:53:04work on the cart item component uh but
- 7:53:07let me import that cart item as well
- 7:53:10which was done now inside this cart item
- 7:53:14first I'm going to import the classes
- 7:53:16what I need right here so I will need
- 7:53:19react and user State I will need link
- 7:53:23router and use form from Ina JS react I
- 7:53:27will need cart item type as well but
- 7:53:30because our function is called the same
- 7:53:32name as the type what we have defined
- 7:53:34inside types I'm going to import this
- 7:53:36with a different name card item type so
- 7:53:39then we're going to need text input here
- 7:53:42uh we're going to need currency format
- 7:53:45as well and I'm going to create Now
- 7:53:48product root I'm going to do this inside
- 7:53:51helpers and I'm going to import that as
- 7:53:54well and I will explain why I create
- 7:53:57this product
- 7:53:59product
- 7:54:01root uh function and this is going to be
- 7:54:05to generate the root for the product
- 7:54:08cart
- 7:54:10item okay we can import this cart item
- 7:54:14from from
- 7:54:16types and now this is what we are going
- 7:54:18to do so I'm going to generate create
- 7:54:20params which is going to be new URL
- 7:54:23search params however I'm not going to
- 7:54:26provide anything inside the search I'm
- 7:54:28going to
- 7:54:29construct these params based on the
- 7:54:33item item option uh
- 7:54:37IDs so then um we have this item which
- 7:54:41has option IDs right and that option IDs
- 7:54:44if we have a look is the object where
- 7:54:46the key inside this object is the type
- 7:54:48ID and the value inside this object is
- 7:54:51the option ID so what we want is
- 7:54:55call
- 7:54:56object um and entries right here which
- 7:55:01returns array entries so then I'm going
- 7:55:04to iterate over this and for each we get
- 7:55:08the key value and we can call this um ID
- 7:55:12or we can call this type ID and this is
- 7:55:14going to be option ID okay if you don't
- 7:55:17know how object entries Works basically
- 7:55:19you need to find out this um okay so we
- 7:55:23have parms we have a pend
- 7:55:31uh sorry what I'm doing here I'm doing
- 7:55:33something
- 7:55:35stupid then right here we're going to
- 7:55:41do so basically uh we know that speaking
- 7:55:45about the product Details page if we go
- 7:55:48on the
- 7:55:50homepage if it works yeah when we click
- 7:55:53on this we open the product Details page
- 7:55:55and when we change the variations this
- 7:55:57is what we saw so we are updating the
- 7:55:59URL right here with options where the
- 7:56:02key of the option is type ID and the
- 7:56:05value is the actual option ID so I want
- 7:56:08to generate URL similar to this because
- 7:56:12if I addit a product inside the card uh
- 7:56:16I can do this right now I can add the
- 7:56:18Green version inside the card refresh
- 7:56:20the page um let's have a look now we see
- 7:56:23two items okay and whenever I click the
- 7:56:26second one I want want this to open that
- 7:56:31specific URL considering the options as
- 7:56:33well if I click right now on this it is
- 7:56:35not going to append the URLs in the um
- 7:56:39the options inside the URL this is
- 7:56:41something we are going to also fix from
- 7:56:43these mini card dropdown but yeah this
- 7:56:48is what I'm actually trying to achieve
- 7:56:50right
- 7:56:50now okay cool uh we're going to come
- 7:56:53back to these erors so next on pams I'm
- 7:56:57going to call append I'm going to
- 7:57:00provide options let's use btics uh
- 7:57:04options and inside options for the given
- 7:57:09type ID I'm going to put option
- 7:57:15ID uh option ID but option ID actually
- 7:57:19needs to be string and we have option ID
- 7:57:21to be number so we have to cast this
- 7:57:24into the string convert this into string
- 7:57:27so once we generated those params right
- 7:57:30here so we appended that information
- 7:57:31inside the params then I'm going to
- 7:57:34return
- 7:57:36root product. show we provide item.
- 7:57:42Slug and plus I want to provide params
- 7:57:47to string those Q prams now I'm going to
- 7:57:50use this product rout inside cart item
- 7:57:54so I'm going to import this product rout
- 7:57:56here now let's define the prop which is
- 7:57:58going to be item type of cart item type
- 7:58:02and next I'm going to focus on the
- 7:58:03template first and then create the
- 7:58:05necessary uh react code right here so
- 7:58:10I'm going to uh create this St with a
- 7:58:13key on it which is going to be item id
- 7:58:16then I'm going to create second d right
- 7:58:18here which is going to be divider just
- 7:58:20between multiple card items we're going
- 7:58:21to have this divider then let's create
- 7:58:24the link and this link is going to use
- 7:58:27the product rout inside hre which will
- 7:58:30generate the correct URL considering
- 7:58:32options as well give it withth and hate
- 7:58:35mean withd and minan heate as well and
- 7:58:38inside there I'm just going to put image
- 7:58:41okay so after this link we're going to
- 7:58:43have um second div and the layout of the
- 7:58:46cart items is going to be very much
- 7:58:48similar to this what we have in the mini
- 7:58:50cart items just a image will be a little
- 7:58:52bit larger and there will be additional
- 7:58:54information so I create this div inside
- 7:58:56there we have another div H3 we're going
- 7:58:59to display the product title uh and
- 7:59:02we're going to also use this product
- 7:59:03rule to generate the correct um rout
- 7:59:07then we're going to have additional div
- 7:59:09and inside which I want to display the
- 7:59:12options so I'm just going to have this
- 7:59:14pre right here just in case I need to
- 7:59:15uncomment and see what's the value
- 7:59:17inside item if we have any error so then
- 7:59:20we're going to iterate over item
- 7:59:22options okay we know each item has
- 7:59:25options and options is actually array if
- 7:59:28we check index if we see card item we
- 7:59:31see options and each option is array of
- 7:59:33the following type all right so here I'm
- 7:59:36going to iterate over options uh and I'm
- 7:59:38going to render the option type
- 7:59:41name which we have right here option
- 7:59:44type name and we're going to also
- 7:59:46generate option name so this is what we
- 7:59:49display like color black um second for
- 7:59:53second option size small and so on so
- 7:59:57after this and that ends right here
- 8:00:01after this we're going to create one
- 8:00:03more div and that's going to hold the
- 8:00:05information about quantity that's going
- 8:00:07to be down below uh about quantity and
- 8:00:11we're going to also display the error
- 8:00:13just in case we try to use a larger m
- 8:00:18number of quantity than it is actually
- 8:00:21available so here I'm using this daui
- 8:00:24tool tip component uh we can have a look
- 8:00:27also in the mentation of this
- 8:00:29information and if error exists we add
- 8:00:31those CSS classes and we also add this
- 8:00:33data tap error and inside here we have
- 8:00:36this text input which is going to be the
- 8:00:38quantity text input and we are going to
- 8:00:41listen to its PL event to trigger this
- 8:00:44handle quantity change function which
- 8:00:45we're going to create in a moment after
- 8:00:49this we're going to have uh two buttons
- 8:00:51one is going to be to delete the
- 8:00:54item okay and second is going to uh save
- 8:00:58that cart item for later usage and save
- 8:01:01for later is something I'm not going to
- 8:01:03implement right now I will Implement a
- 8:01:05little bit later but we're going to do
- 8:01:06this delete of course okay now let's
- 8:01:09focus on the react side and we have this
- 8:01:14delete form right here uh we have to
- 8:01:17Define this delete form with option IDs
- 8:01:19and that option IDs will be the item
- 8:01:21option IDs okay then we're going to
- 8:01:24Define state for error I'm going to
- 8:01:26Define on delete click as well where I'm
- 8:01:30going to send the delete request on this
- 8:01:32delete form uh with the following URL
- 8:01:36providing the uh correct product ID in
- 8:01:38the URL and preserve scroll is going to
- 8:01:40be always true so that per will perform
- 8:01:43the delete and let's create the second
- 8:01:45function handle quantity change we
- 8:01:48accept right here HTML in event for HTML
- 8:01:51input element uh we're going to set the
- 8:01:55error to be an empty string so if we
- 8:01:57have some error on the quantity because
- 8:01:58of the quantity when we change the
- 8:02:00quantity we want to disable this error
- 8:02:02just uh hide this error then we send the
- 8:02:06update request on the following route we
- 8:02:10provide the quantity and we provide the
- 8:02:12option IDs and the the question um I
- 8:02:17would have if I were you is that why I
- 8:02:21am
- 8:02:22using right here delete form and why I'm
- 8:02:27using
- 8:02:28a rotor put right here and this is the
- 8:02:32answer basically because we're going to
- 8:02:35immediately send the request inside
- 8:02:39handle quantity change so if we we about
- 8:02:43to add right here quantity for example
- 8:02:47if we we could name this form right just
- 8:02:50form uh then right here it would be form
- 8:02:53delete then we have the option ID is
- 8:02:56here additionally we could add quantity
- 8:02:59here and for delete it's going to work
- 8:03:01in the same way but for update we tried
- 8:03:03to send form. put providing this cart
- 8:03:08update but the thing is that whenever
- 8:03:11the quantity is changed we have to set
- 8:03:13that quantity inside form data right and
- 8:03:17we're going to do this form that form
- 8:03:20dot set data and the set set data is a
- 8:03:25synchronous operation so if we call set
- 8:03:28data right here and then call form. put
- 8:03:31form will still have old quantity it is
- 8:03:35not going to have new quantity okay
- 8:03:38either we have to come up some um
- 8:03:40solutions to uh listen to when the form
- 8:03:43data is actually updated and then send
- 8:03:45the request or we can simply use router
- 8:03:48put in this case this is um easier to
- 8:03:53do okay after this we're going to add
- 8:03:55the third argument which is going to be
- 8:03:58um The Preserve scroll the the options
- 8:04:00basically of the request preserve scroll
- 8:04:03true and we're going to listen on error
- 8:04:04as well if we get some error we're going
- 8:04:06to get the first error and put this
- 8:04:08inside the state hazer and the error
- 8:04:11will be
- 8:04:12displayed okay so after this I'm going
- 8:04:14to display this currency format
- 8:04:18information okay and I think we are done
- 8:04:21so the currency uh information will be
- 8:04:23item price Multiplied on item quantity
- 8:04:26yeah I think we are done we don't need
- 8:04:28anything else let's go into
- 8:04:31index uh I think we don't have any error
- 8:04:35here as well and I'm going to click on
- 8:04:37this view
- 8:04:39cart okay it looks like it is rendered
- 8:04:41nicely as we expect so look at this so
- 8:04:44we
- 8:04:45have um let's close this so we have the
- 8:04:49left side where we have the shopping
- 8:04:50cart items we have the vender store name
- 8:04:52we have the button pay only for this
- 8:04:54seller we have this proess check out
- 8:04:57everything and we have have the product
- 8:04:58information clicking on which should
- 8:05:01open the product Details page but for
- 8:05:04the following variation the variation is
- 8:05:07color green size small in this case here
- 8:05:10we have color black size small as well
- 8:05:13so click on this green now we see color
- 8:05:16green size small that's awesome now
- 8:05:19let's add color green size large into
- 8:05:22the card we see fourth item click on
- 8:05:25this now we see color color green size
- 8:05:28small and color green size large here as
- 8:05:31well and clicking on this opens now
- 8:05:34color green size large and that is
- 8:05:38absolutely
- 8:05:40amazing
- 8:05:42so I think we're good so this is also
- 8:05:45works black and small um now let's try
- 8:05:48to delete something from the cart
- 8:05:50because we have the back end
- 8:05:52ready and it should actually work let's
- 8:05:54click on delete here this is gone it was
- 8:05:57removed refresh the
- 8:05:59page it stays removed we see we have
- 8:06:02totally three items 65 is the total and
- 8:06:05we can start increasing that click on
- 8:06:08outside it will trigger the on blar
- 8:06:11event and that was updated that was
- 8:06:13updated now totally we have eight items
- 8:06:16we can increase this as well we have
- 8:06:20totally 13 items and this is the total
- 8:06:22price and that
- 8:06:24is actually how I want
- 8:06:29it okay the error what we see on the
- 8:06:32product Details page is coming from
- 8:06:34Carousel the following error the final
- 8:06:37argument passed to use effect changed
- 8:06:40size between renders the order and the
- 8:06:42size of this array must remain constant
- 8:06:44and this happens because if we check
- 8:06:48Carousel item so I did a small resarch
- 8:06:51it was actually quite easy to find that
- 8:06:53information so right here I need to
- 8:06:55provide that images inside array
- 8:06:58that was it so uh yeah the size of the
- 8:07:02images were changed but here we just
- 8:07:05need one element and that must be images
- 8:07:08and then use effect starts watching on
- 8:07:10images I refresh the
- 8:07:13page the error is gone let's have a look
- 8:07:19uh we have to use this uh root um
- 8:07:22product route inside mini card drop down
- 8:07:25so let's go into mini card drop down
- 8:07:28and find this product show and here I'm
- 8:07:31going to use um product root
- 8:07:36providing not product but um item right
- 8:07:40it is card item just like this and we
- 8:07:44have this on second place as well
- 8:07:47product root
- 8:07:49item let me search inside entire project
- 8:07:53where we have product show again so we
- 8:07:57have it here that is the product item
- 8:08:01itself but for the product item we can
- 8:08:04leave it because for the product item we
- 8:08:06don't have that
- 8:08:10options yeah I think we can leave that
- 8:08:13least for
- 8:08:15now okay
- 8:08:18nice so we don't have any errors on the
- 8:08:20product page we click on the cart view
- 8:08:24cart we see the information looking
- 8:08:26amazing
- 8:08:29and I think the next part is to start
- 8:08:31working on the checkout before I start
- 8:08:34working on checkout there are a few
- 8:08:37additional things to prepare and to
- 8:08:39implement and one of them is to test add
- 8:08:43to card functionality when the product
- 8:08:45does not have any variations so what we
- 8:08:48implemented so far in our card service
- 8:08:51um which I'm going to just give you an
- 8:08:53overview is only for the cases when
- 8:08:57product has multiple V variations and
- 8:08:59generally this is what I recommend if
- 8:09:01you want to implement some functionality
- 8:09:04which should adapt many different adapt
- 8:09:06many different cases just choose one
- 8:09:09case and Implement your functionality on
- 8:09:11this case test it make sure it works
- 8:09:13well then you can introduce a second
- 8:09:16case and test your own code on this
- 8:09:19second case and you will probably find
- 8:09:22some bucks then you're going to fix
- 8:09:24those bugs uh add additional conditions
- 8:09:27into to your code and so on okay this is
- 8:09:29exactly what we're going to do so far we
- 8:09:31implemented this only for product
- 8:09:33variations but if the product doesn't
- 8:09:35have variation it will probably fail so
- 8:09:38what I did right now is created
- 8:09:40registered second vendor vendor to@
- 8:09:42example.com there's new user and I also
- 8:09:45added model has roles and now this user
- 8:09:48is able to access admin page of course
- 8:09:50this new user doesn't have any kind of
- 8:09:53uh products and this is what we're going
- 8:09:55to do right now test
- 8:09:58product item slug will be autogenerate
- 8:10:01let's put this in
- 8:10:03fashion choose any category some test
- 8:10:06description we don't care these things
- 8:10:09uh we can give it price 50 we can leave
- 8:10:12the quantity I'm going to give it
- 8:10:13published okay so we can give it also
- 8:10:16quantity doesn't matter so let's click
- 8:10:18on create the product is created it is
- 8:10:20published now I'm going to duplicate
- 8:10:23this one for the admin second for the
- 8:10:25website and we're going to see that
- 8:10:27product without images okay let's attach
- 8:10:30an image as
- 8:10:31well oops click on browse I'm going to
- 8:10:35choose these three
- 8:10:41images let's retry the fail
- 8:10:44image okay cool click on Save refresh
- 8:10:48the
- 8:10:50page and we see now these two products
- 8:10:52okay first product and test product item
- 8:10:56uh why do I have this name okay anyway
- 8:10:58so the first product has different
- 8:11:00variations so there is additional bug
- 8:11:02that right here we're displaying the
- 8:11:03product image but when we go inside we
- 8:11:06see the first variation image so if the
- 8:11:09product has variations the product image
- 8:11:11should not even be displayed and this is
- 8:11:13additional thing we have to fix but let
- 8:11:16me first focus on A2 card functionality
- 8:11:18because uh and then check out flow
- 8:11:21because that's is more exciting uh I
- 8:11:23guess for you guys as well so uh here we
- 8:11:27have the images are broken I think
- 8:11:29probably because I restarted the PC and
- 8:11:32we have to execute PHP Artisan uh
- 8:11:37Q
- 8:11:38listen so that it can start
- 8:11:44processing okay I think it's going to do
- 8:11:47this right now refresh the page okay and
- 8:11:51we see those products now this product
- 8:11:53doesn't have variation and I'm actually
- 8:11:56also
- 8:11:57um I will log out and just try to access
- 8:12:02the product in this way so click it to
- 8:12:04cart and now let's see what happens so
- 8:12:06clicking at to cart doesn't do anything
- 8:12:09we don't see the count increasing right
- 8:12:11here okay that's probably because some
- 8:12:14error is happening inside cart
- 8:12:17service let's go into cart uh A2
- 8:12:23cart and we're going to check what is
- 8:12:25going on right here what happened and
- 8:12:27why it is not added into the card and
- 8:12:30because right now we are authent we are
- 8:12:32not
- 8:12:33authenticated the user should add the
- 8:12:35products into cookies so this is the
- 8:12:38place where items should be added okay
- 8:12:42so let's see if code comes right here so
- 8:12:45I'm going to dump right now let's dump
- 8:12:48options let's dump quantity and
- 8:12:54price click on add to cart we see one 50
- 8:12:58and options is empty array okay now
- 8:13:01let's click save item to cookies I guess
- 8:13:04this is also added into the cookies
- 8:13:06because there's nothing that is not
- 8:13:08added into the cookies but I think the
- 8:13:11problem is coming from Reading those
- 8:13:13items so get cardart items here we have
- 8:13:16the strike catch and probably in some
- 8:13:19place it goes inside the catch and we
- 8:13:21can see those errors inside ll. logo
- 8:13:25file so if we SC scroll at the very
- 8:13:28bottom then find the beginning of the
- 8:13:30error attempt to read property store
- 8:13:32name on null and this is coming
- 8:13:36from from here okay uh and that's my bad
- 8:13:41actually because when I created the user
- 8:13:43with id4 I didn't create record inside
- 8:13:46vendors which is
- 8:13:48something um must must do so the status
- 8:13:52is approved uh let's give it name
- 8:13:55Zoomer and um I'm going to leave the
- 8:13:58address let's give it created it
- 8:14:01and the same to be updated yet okay I'm
- 8:14:04going to make the record of that now
- 8:14:08refresh the page items are added into
- 8:14:11the cookie now we see 16 items right
- 8:14:13here okay so it looks like adding those
- 8:14:18um into the cart actually works fine so
- 8:14:20now let's click on this view card and
- 8:14:23we're going to see we don't have any
- 8:14:24kind of variations uh so far far so good
- 8:14:27now let's click on to decrease the
- 8:14:30quantity which doesn't work okay so uh
- 8:14:34we don't see the success message click
- 8:14:37on this
- 8:14:39again okay wa if I refresh the page
- 8:14:43right
- 8:14:44now okay it see it is kind of decreased
- 8:14:48but we don't see the success message so
- 8:14:50now let's open Dev tools and we're going
- 8:14:52to see what's going on what request is
- 8:14:54made so click on applic um the upper
- 8:14:57Arrow
- 8:15:01so okay we don't see any errors which is
- 8:15:04good why don't we see success
- 8:15:07message do we do we show the success
- 8:15:09message at all I think we haven't
- 8:15:11implemented success message right so if
- 8:15:13I click this add to the
- 8:15:15card yeah the count is increased but we
- 8:15:18actually haven't implemented the success
- 8:15:20message which we are going to
- 8:15:23do until now we're going to test um add
- 8:15:27to cart or remove from cart for this
- 8:15:30user which doesn't have any kind of
- 8:15:31variations so let's go into cart
- 8:15:35controller and I'm curious what options
- 8:15:40we're getting right here when storing
- 8:15:42the item into the card or when updating
- 8:15:44that from the card so let's see
- 8:15:48inside options let's print options in
- 8:15:52quantity when updating the
- 8:15:55quantity okay okay so we see options is
- 8:15:58empty array and quantity is actually
- 8:16:02three okay it looks like everything to
- 8:16:06be
- 8:16:09correct however there's one thing so if
- 8:16:13options is empty array then right here
- 8:16:17we're constructing the following item
- 8:16:20key when we perform the update and I
- 8:16:23want to print that key as well which I
- 8:16:26think can be op
- 8:16:31optimized let's decrease the quantity
- 8:16:34now this is the
- 8:16:36key when options is actually
- 8:16:40empty so what if the options is not
- 8:16:44empty but it is null in some cases and
- 8:16:46we provide this as null so on the front
- 8:16:49end it looks like we are always
- 8:16:51providing those
- 8:16:52options let's decrease that have a look
- 8:16:57now um I'm curious in the payload so in
- 8:16:59the in the payload we always see option
- 8:17:01ID so no matter if the current product
- 8:17:05has variations or not we always provide
- 8:17:07option IDs okay so maybe as an
- 8:17:10additional precautious will be to add
- 8:17:13right here fallback if for some reason
- 8:17:15we received null uh on the front end
- 8:17:18from the front end then we're going to
- 8:17:20take empty array okay so if this is null
- 8:17:24then we are in a trouble because right
- 8:17:27here a lot of things will fail we are
- 8:17:29taking these option IDs to be an array
- 8:17:31right here then we are sorting that
- 8:17:34we're then we're constructing this key
- 8:17:36okay and it's going to fail it's going
- 8:17:39to fail so we want to make sure that
- 8:17:41option ID is is
- 8:17:43array okay I'm going to remove this
- 8:17:47part that is good uh on the update next
- 8:17:50we're going to do this inside the store
- 8:17:53so we have data option ities right here
- 8:17:56but if if it is null then let's provide
- 8:17:59empty array as
- 8:18:00well and that might happen also when
- 8:18:04adding item into the card from listing
- 8:18:06like we might receive null now let's go
- 8:18:09into product
- 8:18:10listing
- 8:18:12and click it to
- 8:18:15card which we haven't implemented looks
- 8:18:19like so let me open show T6 and find a
- 8:18:26to card
- 8:18:27part which does the following and now
- 8:18:30let's open product
- 8:18:33item product
- 8:18:36item and we're going to find this add to
- 8:18:39card and I'm going to click add on click
- 8:18:42listener uh add to cart
- 8:18:46here to add this from the listing then
- 8:18:50let's define the function const it to
- 8:18:53cart equals
- 8:18:57this then we're going to define the
- 8:19:00form let me copy this form from
- 8:19:06here so we provide the option like this
- 8:19:09we provide the quantity quantity will be
- 8:19:12null if we are adding this from the
- 8:19:14listing and price is
- 8:19:18something uh I think we can provide
- 8:19:20price as well so price in this case is
- 8:19:22going to be product. price because uh we
- 8:19:26are adding this from the listing um I
- 8:19:32think yeah I think we can even skip the
- 8:19:37price let's see it to cart we calculate
- 8:19:40the price from options so I think we can
- 8:19:42skip the
- 8:19:45price let me remove the price
- 8:19:48completely okay now let's test this
- 8:19:50functionality from um listing product
- 8:19:53listing click it to card the request is
- 8:19:56made let's see we have now 18 items
- 8:19:58let's click on this once again we see 19
- 8:20:01items and it looks like it is working
- 8:20:04perfectly so we are passing empty object
- 8:20:07right
- 8:20:08here but that's totally fine because
- 8:20:11then inside A2
- 8:20:13cart if we print that that converts into
- 8:20:16empty
- 8:20:18array as you see so this is
- 8:20:22great now let's go into method get cart
- 8:20:26items we select this from cookies from
- 8:20:30database then right here we iterate over
- 8:20:32cart items all right so we take then we
- 8:20:36iterate the card item option IDs and now
- 8:20:39this is what I want to print and have a
- 8:20:41look what data this
- 8:20:44contains let's refresh the page uh this
- 8:20:47is for the first product which actually
- 8:20:50is uh has variation so I want to check
- 8:20:54this for the second product which
- 8:20:56doesn't have any kind of variation so
- 8:20:57I'm going to go into cart and I'm going
- 8:20:59to remove delete this delete this as
- 8:21:01well and now we have only one product
- 8:21:03which doesn't have variations and let's
- 8:21:05print the what this card item option ID
- 8:21:08is I'm just trying make sure to avoid
- 8:21:10any kind of bugs in the future so option
- 8:21:13ID is empty array so iterating right
- 8:21:15here will not happen at all and if the
- 8:21:18iteration right here doesn't happen at
- 8:21:20all
- 8:21:22then option info will be actually
- 8:21:26actually empty
- 8:21:31right so if we print this cart item data
- 8:21:36we are going to see one object inside
- 8:21:37there we see option ID is empty options
- 8:21:40empty the image is taken from the
- 8:21:42product um and I think yeah everything
- 8:21:45is good so if we have any kind of issues
- 8:21:49then we probably need to come back to
- 8:21:51these places and find out um what is
- 8:21:55going on like this option ID is right
- 8:21:57now is an array but if for some reason
- 8:21:59that got null we have to fix that and we
- 8:22:02make sure that uh it needs to be an
- 8:22:07array now inside card service method I
- 8:22:10want to card service uh class I want to
- 8:22:13add a new method which will move the
- 8:22:15cart items from cookies into the
- 8:22:17database and we're going to do this on
- 8:22:19authentication stage all right so let's
- 8:22:22define the method move cart items to
- 8:22:24database for the given user ID then
- 8:22:26we're going to select the cart items
- 8:22:28from cookies then we're going to iterate
- 8:22:31th those cart items and we're going to
- 8:22:34select if the cart item already exists
- 8:22:37in the database so we might have
- 8:22:39something in the cookie but the same
- 8:22:41product might also be existed in the
- 8:22:44database and we're going to find those
- 8:22:46cart items for the specific user with
- 8:22:49the product ID and the variation type
- 8:22:52option IDs okay that creates the unique
- 8:22:55product right so we select the first and
- 8:22:57then we check if the item already exists
- 8:23:00we're going to update the existing item
- 8:23:02quantity and let's update the price as
- 8:23:04well in the database however if the
- 8:23:06existing item does not exist we're going
- 8:23:08to create new cart item with user
- 8:23:10product quantity and price and variation
- 8:23:13option IDs so we moved the items from
- 8:23:16cart into the database and then we're
- 8:23:19going to delete the cookie name from
- 8:23:21cookies basically we remove them from
- 8:23:23the
- 8:23:24cookies now we're going to open
- 8:23:26authenticated session controller and we
- 8:23:29when we perform this authentication we
- 8:23:31are going to move the cart items into
- 8:23:33the database and I'm going to do this in
- 8:23:35two places so this is the place where
- 8:23:37the authentication happens let me accept
- 8:23:40right here cart
- 8:23:42service card service and even though
- 8:23:45this is for admin and vendor potentially
- 8:23:48admin and vendor users might also be a
- 8:23:51regular buyers so we want to execute
- 8:23:54this card service move items into the
- 8:23:57database for this as well providing user
- 8:24:00ID and we want to do something similar
- 8:24:03right here for a regular user okay I
- 8:24:07save this let's refresh the page
- 8:24:11now we see those cart items we have six
- 8:24:14cart items and now let me try to
- 8:24:16authenticate with a regular
- 8:24:21user okay and now we have this error the
- 8:24:23first error array to string conversion
- 8:24:26right here into card
- 8:24:29items variation type option IDs and
- 8:24:34where is this coming from I'm going to
- 8:24:36close the right side and where is this
- 8:24:39coming from we're going to find our code
- 8:24:42which is not uh perfectly highlighted
- 8:24:45here that should probably come from card
- 8:24:49service this is it okay so the problem
- 8:24:53is right here it looks like this is
- 8:24:56array and we are
- 8:25:00trying array to string conversion yeah
- 8:25:03we're trying to convert this into string
- 8:25:05okay this is what I'm going to do let's
- 8:25:06go into cart service let's open this
- 8:25:09cart item and I'm going to add right
- 8:25:11here
- 8:25:13casts uh the following column name
- 8:25:17variation type option ID is I'm going to
- 8:25:19provide that this is actually
- 8:25:23array now let's see what happens am I
- 8:25:25authentic at I think I am authenticated
- 8:25:28and there's nothing in the database so
- 8:25:31let's log out now we have the six items
- 8:25:34still in cart now let me try to
- 8:25:37authenticate
- 8:25:39again and see what happens now we have
- 8:25:41another error which is coming
- 8:25:45from why this doesn't perfectly
- 8:25:47highlight it card
- 8:25:51service okay
- 8:25:53count okay this looks like to be an
- 8:25:57empty array and that causes the problem
- 8:26:00what we what I was personally thinking
- 8:26:03to be honest so if I find that
- 8:26:06place not here not here not here this is
- 8:26:09the place so the cart item option I is
- 8:26:12is actually empty array so right
- 8:26:16here oh actually null was given to it so
- 8:26:20if we check in the database inside cart
- 8:26:24items uh what what do we see so we see
- 8:26:27variation type option IDE is to be an
- 8:26:28empt array why null was given to it I'm
- 8:26:31not sure now let's print what is this
- 8:26:34inside card item option
- 8:26:39IDs refresh the page it is null why it
- 8:26:41is null I don't know but we're going to
- 8:26:45find out so I'm selecting these card
- 8:26:47items from the database let me actually
- 8:26:49do this print the entire card items here
- 8:26:54refresh it one item and option it this
- 8:26:56is null let's check now the
- 8:26:59database cart item variation type option
- 8:27:02ID
- 8:27:04this it doesn't
- 8:27:07look
- 8:27:10correct now this is it it has attributes
- 8:27:14and we see that the variation type
- 8:27:15option IDE is is empty
- 8:27:19array but because we added that to be
- 8:27:22array or maybe we should provide that to
- 8:27:24be Json
- 8:27:28let's
- 8:27:31see
- 8:27:33okay so right here uh let me just print
- 8:27:36this cart item variation type option oh
- 8:27:40my
- 8:27:41bad that should be IDs in
- 8:27:46plural that's my bad okay my mistake now
- 8:27:50if I refresh it we're going to see
- 8:27:52variation type option idas to be array
- 8:27:55so I think we can return this into array
- 8:27:57however Json also works um and we have
- 8:28:00now this to be an array we go in the
- 8:28:02card service go back previous place
- 8:28:06where we have this um DD right here I'm
- 8:28:10going to remove refresh
- 8:28:15it and now the items were moved into the
- 8:28:20database let's click on this view card
- 8:28:22and I think now we can start working on
- 8:28:24checkout to start working on the
- 8:28:26checkout flow first we will need stripe
- 8:28:29account go to stripe.com and create an
- 8:28:32account right here if you already have
- 8:28:34an account you might want to create add
- 8:28:36new account from inside your interface
- 8:28:39dashboard so I have couple of accounts
- 8:28:41which I have used for testing but right
- 8:28:43now I'm going to add create uh click on
- 8:28:46this create new
- 8:28:48account and let me call this laravel
- 8:28:52react e-commerce tutorial
- 8:28:57so I'm going to click on
- 8:28:59create so once the account is created
- 8:29:02make sure that you are in the test mode
- 8:29:04okay so the account is created I
- 8:29:06actually have two uh similar name
- 8:29:08accounts L react Ecommerce which is what
- 8:29:11I was testing on and this is LEL react
- 8:29:14e-commerce tutorial which is a brand new
- 8:29:16account which we're going to use for
- 8:29:17this so make sure you are in the test
- 8:29:20mode right here then we're going to copy
- 8:29:23this secret and we're going to put this
- 8:29:25inside projects en file so let me
- 8:29:31open and scroll down below
- 8:29:35and let me just find what I have named
- 8:29:40so yeah I'm going to give it name stripe
- 8:29:45key um sorry what did I
- 8:29:49do reveal click on okay it was copied so
- 8:29:53we have stripe key which is actually
- 8:29:55publishable key which we I think don't
- 8:29:57need but we need is stripe
- 8:30:01secret so this is my stripe secret let
- 8:30:05me copy this and I'm going to put this
- 8:30:07also I of example as an example file and
- 8:30:12not the file but the key okay um
- 8:30:16secret key okay good so we have to also
- 8:30:21install the stripe PHP package now let's
- 8:30:25go into event destinations which is web
- 8:30:28hooks which what we are going to
- 8:30:30actually trigger okay create new event
- 8:30:33destination and testing local
- 8:30:35development this is what we're going to
- 8:30:37do and we have to download the CLI for
- 8:30:40the stripe so if you're windows we have
- 8:30:42to download this as a EX file so I'm
- 8:30:45going to click on this download CLI in a
- 8:30:47new tab open that and we're going to
- 8:30:50find the instruction how we're going to
- 8:30:51set this up but I'm going to show you
- 8:30:53very quickly so we're going to go into
- 8:30:55your operating system and each of them
- 8:30:57shows the
- 8:30:59instructions um on Linux you have to
- 8:31:02download unzip it and then you have to
- 8:31:04you have the following comment on
- 8:31:06Windows I'm going to click on this
- 8:31:08download on
- 8:31:09GitHub this opens it now we are going to
- 8:31:13download the zip file for my operating
- 8:31:16system which I actually have already
- 8:31:19downloaded so I'm going to
- 8:31:23open right now this is it so I
- 8:31:27downloaded that and I have stripe XA
- 8:31:30right here and then I can close this
- 8:31:33GitHub then I have to start this and
- 8:31:35first I have to execute stripe login
- 8:31:39which I have also already done so let me
- 8:31:41open now terminal in this location where
- 8:31:44the stripe XA leaves okay and we have to
- 8:31:49execute stripe XA login so you execute
- 8:31:54this you have it's going to open in the
- 8:31:56browser you have to accept this and then
- 8:31:59you will be authenticated okay so once
- 8:32:01you do this now we can already start
- 8:32:04using this uh stripe
- 8:32:07CLI uh for web Hooks and this is what we
- 8:32:10are going to do so I can close this as
- 8:32:13well I don't need this because the
- 8:32:15download and login has already been done
- 8:32:17and now we're going to listen uh to
- 8:32:20stripe web hooks but actually I think we
- 8:32:23have to install also stripe
- 8:32:26PHP so um composer stripe
- 8:32:30PHP let's click on
- 8:32:34this I'm going to copy the following
- 8:32:37command uh I'm going to collapse this
- 8:32:40not close this because I will need this
- 8:32:42uh to execute for web Hooks and let's
- 8:32:46open PHP storm bring up the terminal and
- 8:32:50I'm going to execute composer requir
- 8:32:52strip
- 8:32:53PHP um okay cool additionally I want to
- 8:32:57also create two new tables one for
- 8:33:00orders and second for order items so I'm
- 8:33:03going to execute PHP artisan make
- 8:33:08model order model with
- 8:33:12migration let's hit the enter that was
- 8:33:15created and I'm going to also create PHP
- 8:33:18artisan make model order order item but
- 8:33:23I'm going to uh skip the migration part
- 8:33:25because I'm going to put the uh inside
- 8:33:28the orders migration file the order
- 8:33:30items itself okay so let's click on
- 8:33:36enter the modu was created now let's
- 8:33:39open create orders
- 8:33:43table now let's add the necessary
- 8:33:46columns on this table so we need order
- 8:33:48total price we need the foring ID to the
- 8:33:51user which is the buyer in this case we
- 8:33:54need foring ID into the user which is
- 8:33:56going to be vendor user ID so that is
- 8:33:59the vendor information so we're going to
- 8:34:01have status order their status and we're
- 8:34:02going to have also stripe session ID I'm
- 8:34:06going to also add few additional columns
- 8:34:09which is going to be for some additional
- 8:34:11calculated amounts information such as
- 8:34:14we're going to have online payment
- 8:34:16commission which is going to be stripe
- 8:34:18commission but I gave this more abstract
- 8:34:21name because if you decide to replace
- 8:34:23stripe with something else this is going
- 8:34:25to be online payment commission so we
- 8:34:28will need also website commission the
- 8:34:31platform commission also and we will
- 8:34:34have the vendor subtotal so if the
- 8:34:36vendor paid if the buyer paid for
- 8:34:38example 100 some part will be online
- 8:34:41payment commission some part will be
- 8:34:43website commission and vendor subtotal
- 8:34:45will be whatever will be commissions
- 8:34:48subtracted into the total price okay now
- 8:34:51I'm going to also create um payment
- 8:34:54intent column where I'm going to save
- 8:34:56the payment intent id coming from stripe
- 8:35:00and I will show this to
- 8:35:02you so I'm going to create order items
- 8:35:04table with ID with the foring ID into
- 8:35:06the orders with product ID with price
- 8:35:10integer and uh V variation type option
- 8:35:13ideas Json field and let's also uh add
- 8:35:17this um inside down to drop these
- 8:35:20tables now I'm going to also create uh
- 8:35:24order state status enam PHP
- 8:35:29artisan make enam order status ANM let's
- 8:35:36hit the enter now let's open order
- 8:35:39status
- 8:35:41ANM let's give it string type and we're
- 8:35:45going to have five um five cases so case
- 8:35:50draft we're going to
- 8:35:52have paid we are going to have have
- 8:35:57shipped we're going to have
- 8:36:00delivered and we're going to have
- 8:36:04canell and let me assign correct strings
- 8:36:07to
- 8:36:10them of course you can add your desired
- 8:36:14types
- 8:36:16here now I'm going to also generate
- 8:36:20public
- 8:36:22static function labels
- 8:36:25and I'm going to return an associative
- 8:36:28array self
- 8:36:30draft we need a value here for Value we
- 8:36:35have right here for a draft we have
- 8:36:37draft label and let's duplicate this and
- 8:36:40we
- 8:36:42have paid we have shipped we have
- 8:36:47delivered and we have
- 8:36:50cancelled so paid
- 8:36:53here shipped here
- 8:36:56delivered
- 8:36:57here cancelled here okay now I'm going
- 8:37:01to open card controller checkout method
- 8:37:03and I'm going to implement this check
- 8:37:05out method right here but before I do
- 8:37:08this I'm going to also
- 8:37:10open up PHP up PHP from config folder
- 8:37:15config up PHP scroll at the very bottom
- 8:37:18and I want to add
- 8:37:21few values right here so I want to add
- 8:37:23currency
- 8:37:25string currency which is going to be
- 8:37:28taken from I uh I'm going to call this
- 8:37:31up currency the default one to be USD
- 8:37:34I'm going to create that in a moment and
- 8:37:36we're going to take uh
- 8:37:38stripe secret key as well which we're
- 8:37:42going to take from in and we call this
- 8:37:45stripe secret okay now let's
- 8:37:50open. and find currency here
- 8:37:55currency we don't have currency here
- 8:37:58so right here I'm going to add
- 8:38:02up
- 8:38:04currency which is going to be
- 8:38:08USD and I'm going to add this inside in
- 8:38:12of
- 8:38:14example
- 8:38:15up
- 8:38:17currency USD okay so we have stripe
- 8:38:20secret now I think we can take those
- 8:38:23values inside checkout so let's go into
- 8:38:25check out and first I'm going to uh
- 8:38:28require request uh import use sorry use
- 8:38:32these parameters request and card
- 8:38:34service then I'm going to set the API
- 8:38:37key inside the stripe which is going to
- 8:38:39be the stripe secret key which will
- 8:38:42generated then I'm going to take the
- 8:38:44vendor ID from the request so if we are
- 8:38:46doing checkout only for this specific
- 8:38:48vendor this is how we are going to take
- 8:38:51the V vendor information and then I'm
- 8:38:53going to get the card items group by
- 8:38:56vendor ID so we have all cart items
- 8:38:58right here then I'm going to start the
- 8:39:00transaction if something is failed I
- 8:39:02want to roll back everything so I
- 8:39:04started transaction I put everything
- 8:39:05inside TR cat and then we're going to
- 8:39:07start so check out cart items equals all
- 8:39:10cart items and if the vendor ID exists
- 8:39:15then we need to check out only the items
- 8:39:18for the vendor so from all cart items I
- 8:39:21am taking the items which belong to the
- 8:39:24specific vendor
- 8:39:26but because we need the format to be an
- 8:39:29array
- 8:39:30of uh vendor associative array so I'm
- 8:39:33still putting this inside uh the array
- 8:39:36so as an example if I open new scratch
- 8:39:39file so cart items look like
- 8:39:43this so we have the vendor ID and it's
- 8:39:46corresponding some data we have second
- 8:39:48vendor ID and is corresponding some data
- 8:39:51so what I'm taking is data for the first
- 8:39:54vendor like this but I am also putting
- 8:39:58this inside associative array not
- 8:40:01associative array but inside array okay
- 8:40:04so in this specific case the checkout
- 8:40:07card items right here is all cart items
- 8:40:10which is associative array like this but
- 8:40:13right here I'm just creating this
- 8:40:16checkout cart items to be normal array
- 8:40:18so it will be like let's put semicolon
- 8:40:21here so card items will be like this so
- 8:40:25if we are checking out the first vendor
- 8:40:28data it will be like this but it doesn't
- 8:40:30matter because we don't need keys we
- 8:40:32don't need this information we only need
- 8:40:34the
- 8:40:35values so now I'm going to uh create
- 8:40:38orders array and the line items array
- 8:40:41the orders array is going to be my
- 8:40:43eloquent moduls and line items for
- 8:40:45stripe then we start iterating over
- 8:40:48these checkout items and we need the
- 8:40:49item information right here so we're
- 8:40:52going to take the user and card it items
- 8:40:55from the item so if we check this get
- 8:40:58cart items grouped we see that each of
- 8:41:00them has user and items and a couple of
- 8:41:03other information as well okay after
- 8:41:06this I'm going to create new order
- 8:41:07providing stripe session ID provide user
- 8:41:11ID provide vendor user ID provide total
- 8:41:14price and Status we're going to import
- 8:41:17all these classes um in a moment after
- 8:41:20we finish writing this method okay so
- 8:41:23then I'm going to put this order into
- 8:41:24orders array and then I'm going to start
- 8:41:26iterating over cart items and I'm going
- 8:41:29to create order items models so
- 8:41:32providing order ID product ID quantity
- 8:41:35price and variation type option IDs all
- 8:41:37of them taken from card item after which
- 8:41:40we're going to create line item so
- 8:41:42inside line item we need product data
- 8:41:44inside product data we need currency and
- 8:41:46we need product data so inside price
- 8:41:48data we need currency and product data
- 8:41:50so inside product data we need the title
- 8:41:53of the product we need images as an
- 8:41:55array so I'm taking the first image and
- 8:41:58putting inside an array so then we need
- 8:42:00unit amount but stripe wants unit
- 8:42:02amounts inside uh cents so we're
- 8:42:05providing uh right here multiplying this
- 8:42:08into 100 so then we have the quantity as
- 8:42:11well cart item quantity and finally
- 8:42:13we're putting this line item inside line
- 8:42:16items array but I want to also Define a
- 8:42:20description and the description uh needs
- 8:42:23to be the variations to give the user
- 8:42:25information what variations they are
- 8:42:26purchasing so we are collecting card
- 8:42:29item options we're creating collection
- 8:42:32out of this then mapping that data and
- 8:42:35returning the cart item option each
- 8:42:38option type name column in the item name
- 8:42:43again if we go back into this method and
- 8:42:46check what type of data is returned from
- 8:42:48here inside items we're going to see
- 8:42:50that each item right here has options
- 8:42:54which is the option option information
- 8:42:55and option information contains the type
- 8:42:58name as well as the option name itself
- 8:43:01okay this is what we are
- 8:43:03taking if we scroll down below this is
- 8:43:05what we are taking in the following
- 8:43:07Place type name and option name and
- 8:43:09finally because we have this map we're
- 8:43:11converting oops we're converting this
- 8:43:14we're imploding this uh with a comma so
- 8:43:17we're converting this into string and
- 8:43:19then we're going to provide description
- 8:43:20right here if description exists then
- 8:43:23inside line item price St data product
- 8:43:26data we're putting the
- 8:43:28description Okay cool so this is uh
- 8:43:32related to iteration so we did the
- 8:43:34iteration we created orders order items
- 8:43:36line items and now we're going to create
- 8:43:37stripe session we're providing the
- 8:43:39customer email address line items the
- 8:43:42mode is payment we're providing the
- 8:43:44success URL and the success URL contains
- 8:43:46the following session ID in the URL as
- 8:43:49well we're providing the cancel URL as
- 8:43:51well and we're going to create those
- 8:43:53rules stripe success and stripe failure
- 8:43:56we are going to create them in a moment
- 8:43:58so then I'm iterating over my orders
- 8:44:01which are just created orders and I'm
- 8:44:03updating their stripe session ID to be
- 8:44:06just generated stripe session ID after
- 8:44:10which we're going to perform the
- 8:44:11database Comet and redirect into the
- 8:44:13session URL which will open the stripe
- 8:44:16payments page and in case there is some
- 8:44:18error we're going to log the error we're
- 8:44:20going to roll back the transaction and
- 8:44:22we're going to redirect user into PE
- 8:44:25with some error that something has gone
- 8:44:29wrong now let's import these classes so
- 8:44:32DB we're going to import
- 8:44:36log we are going to import order
- 8:44:40item order status
- 8:44:43enam and
- 8:44:47order I think the request and card
- 8:44:49service so the request and card service
- 8:44:52needs to be imported as well uh uh
- 8:44:55here's the card service which was
- 8:44:58already imported in this okay so now we
- 8:45:00have this checkout method ready and now
- 8:45:04we're going to Define
- 8:45:05Roots so for this let me open web.php
- 8:45:10and the user needs to be authenticated
- 8:45:13to perform uh checkout so we have the
- 8:45:16checkout actually defined right here but
- 8:45:19I'm going to create now stripe
- 8:45:21controller PHP artisan make
- 8:45:25controller uh let's call this stripe
- 8:45:30controller and inside stripe controller
- 8:45:32I want to Define three methods so one is
- 8:45:37going to be
- 8:45:40success second is going to be
- 8:45:44failure and third is going to be web
- 8:45:49hook and let's open now web.php and I'm
- 8:45:53going to define those rules as well so
- 8:45:55uh
- 8:45:56root
- 8:45:59get um stripe stripe SL success so this
- 8:46:04is the first one we're going to use
- 8:46:07stripe controller success let's move
- 8:46:09this name down let's duplicate this and
- 8:46:13second is going to be failure stripe
- 8:46:17failure so we have these roots names
- 8:46:19used inside the card controller so now
- 8:46:22we make sure that we have those roots
- 8:46:25defined and we have to Define web hook
- 8:46:28as well however web hook needs to be uh
- 8:46:32accessed um basically for guest users as
- 8:46:35well
- 8:46:37so right
- 8:46:39here probably we have the guest Roots so
- 8:46:42here inside root we're going to Define
- 8:46:45post the web hook needs to be accessed
- 8:46:47with a post method it cannot be accessed
- 8:46:50with get and this is going to be stripe
- 8:46:53SL web hook and we have to provide
- 8:46:56stripe controller a web hook here and
- 8:47:01let's move this Dr down stripe web hook
- 8:47:04and I'm going to open now up. PHP but
- 8:47:07from bootstrap folder where we have this
- 8:47:11middle we defined and inside here inside
- 8:47:15this middle wear I want to
- 8:47:18execute except or
- 8:47:23csrf validate csrf tokens and we are
- 8:47:27going to provide accept right here so
- 8:47:30this middle wear should work except the
- 8:47:33following rules and I'm going to provide
- 8:47:35right here pattern stripe SL asterisk so
- 8:47:39csrf tokens will not be validated for
- 8:47:42stripe URLs and that is necessary for
- 8:47:45the following web hook stripe SL webook
- 8:47:49because stripe will send that
- 8:47:51information to us and we have to take
- 8:47:53care of this now I'm going to open this
- 8:47:56terminal and right here we have the
- 8:47:58stripe x file so this is now what we are
- 8:48:00going to
- 8:48:01execute
- 8:48:03stripe we need D- forward
- 8:48:07D2 and we have to provide the local
- 8:48:10address where the stripe web hooks need
- 8:48:12to be forwarded so this we're going to
- 8:48:17take from our application this is the
- 8:48:20application and we need slash stripe
- 8:48:24slash web hook this is the URL where all
- 8:48:27stripe web hooks needs to be forwarded
- 8:48:29we don't need protocol here let me open
- 8:48:32this on full screen we're going to hit
- 8:48:33the
- 8:48:36enter uh stripe oh I missed the commment
- 8:48:41stripe XA
- 8:48:43listen now we have to
- 8:48:49wait and now it generated this web hook
- 8:48:52signing secret key so which we are going
- 8:48:54to
- 8:48:57copy and we are going to
- 8:49:01open and right here I'm going to put
- 8:49:04this so this is going to be
- 8:49:06stripe uh web hook secret equals this
- 8:49:12let's open em example and let's copy the
- 8:49:16name of the key and some secret uh I
- 8:49:21it's it's a good practice to put those
- 8:49:22keys inside the en example as well
- 8:49:25okay now we have the stripe web hook key
- 8:49:27we we're going to take care of the web
- 8:49:28hook but um let's see if the checkout
- 8:49:32actually works and if the order is
- 8:49:34actually created so let's open the
- 8:49:38website refresh the
- 8:49:41page just make sure it works okay now
- 8:49:43I'm going to click on this proed to
- 8:49:45check out and have a look it is thinking
- 8:49:48okay something went wrong and we didn't
- 8:49:50see this error message which is
- 8:49:53something we're going to do
- 8:49:55for this I'm going to open authenticated
- 8:49:58layout and right here I'm going to
- 8:50:01accept error message but we're going to
- 8:50:03pass this error message from handle
- 8:50:05inertial JS request just like we're
- 8:50:07passing success we're going to pass
- 8:50:10error let's do like this then we're
- 8:50:13going to accept this error right here
- 8:50:17let me accept error here we format the
- 8:50:22code so we accept this error U page with
- 8:50:26children okay so we have the header and
- 8:50:29I guess we have
- 8:50:32to actually I think we can take this
- 8:50:35from use page props as well so let me
- 8:50:38Define
- 8:50:41this uh const props equals US
- 8:50:45page. props okay I'm going to Define
- 8:50:49this above then right here we can accept
- 8:50:51this props out user so now this props
- 8:50:55has this error information so maybe
- 8:50:58right here before this header
- 8:51:04um wait I think we don't need even this
- 8:51:07header to I'm going to remove this
- 8:51:10header okay uh and right here I'm going
- 8:51:13to Define if props error exist we are
- 8:51:17going to
- 8:51:18Define div let's give it some classes
- 8:51:21like um let's give it
- 8:51:26container margin X Auto let's give it
- 8:51:29pading X um eight and pting or margin
- 8:51:35top
- 8:51:37eight uh and inside
- 8:51:46here what's going
- 8:51:51on if props error
- 8:52:00I don't see what is the issue
- 8:52:11here okay so
- 8:52:14um uh what mistake do I have
- 8:52:27okay anyway let me let me just write
- 8:52:30maybe uh PHP storm is kind of giving me
- 8:52:33wrong error alert and
- 8:52:36alert error and inside here we're going
- 8:52:39to out put props eror let me save this
- 8:52:42and have a look in the
- 8:52:44browser open Dev tools as well refresh
- 8:52:49it and click on this proed to check
- 8:52:53out undefined array key total price okay
- 8:52:57yeah definitely PHP storm is actually
- 8:52:58complaining on something uh I'm not
- 8:53:00quite sure let me execute mpm run build
- 8:53:03as well mpm run
- 8:53:06build let's
- 8:53:11see I think the reason might be that
- 8:53:14inside page props what we have inside
- 8:53:18index DTS we
- 8:53:20have we don't have that error defined
- 8:53:23anywhere here that might be the thing so
- 8:53:26let's define error to be string and we
- 8:53:30can define success to be string as
- 8:53:36well okay yeah the eror is gone so if we
- 8:53:38execute right now mpm run build that
- 8:53:42should perform the build
- 8:53:48correctly okay cool now let's execute
- 8:53:52mpm uh run Dev again and have a look in
- 8:53:57this error total price and find array
- 8:53:59key total price which is coming from the
- 8:54:03card controller check out now let's see
- 8:54:05where we have this total price we're
- 8:54:07taking this from
- 8:54:09item from each
- 8:54:16item okay that
- 8:54:18item uh is if we check right now card
- 8:54:22service that item
- 8:54:25is the result of this so this we should
- 8:54:29take this in a camel case
- 8:54:32notation let me dump the inside entire
- 8:54:35item and we're going to see it click on
- 8:54:39check out this is the entire item and it
- 8:54:41has total price in camel case so we we
- 8:54:43should have it like
- 8:54:46this okay um we are not using I guess
- 8:54:49this
- 8:54:51item total price anywhere else so now
- 8:54:55let's refresh the
- 8:55:00page okay we haven't executed migration
- 8:55:02to create um orders and Order items
- 8:55:06table so let me execute PHP Artisan
- 8:55:10migrate okay tables we are created now
- 8:55:14we are on the card page click on this
- 8:55:15proed to check out and hopefully we're
- 8:55:17going to see stripe payments
- 8:55:19page okay uh order items has no column
- 8:55:23name updated it that's correct so we
- 8:55:27have not given updated at column to
- 8:55:29order items table so we open
- 8:55:32order order item and we're going to
- 8:55:36Define also fillable on this and on M on
- 8:55:40um order table as well so let's define
- 8:55:45fillable array we are uh we need order
- 8:55:48ID product ID quantity price and we need
- 8:55:53variation option type uh option
- 8:55:57IDs option IDs okay I'm going to move
- 8:56:02them like
- 8:56:06this okay we need to Define uh relations
- 8:56:09as well let's
- 8:56:11define uh belongs to belongs to uh
- 8:56:16belongs to
- 8:56:19order order class now let's open
- 8:56:24uh yeah we need to disable time stamps
- 8:56:26as well so right here I'm going to
- 8:56:28provide time stamps equals false now
- 8:56:32we're going to open order model and
- 8:56:35let's define avilable here and we
- 8:56:40need stripe session ID we need user
- 8:56:49ID user ID we need total price
- 8:56:55and we need
- 8:56:56status uh I'm going to actually move
- 8:56:59them down as well like this and we can
- 8:57:03add other columns here but I'm going to
- 8:57:06implement updating these other columns
- 8:57:08in a different way but just in case uh
- 8:57:12we change something in the future we
- 8:57:14don't have to worry about filling uh
- 8:57:19putting those inside um fillable where's
- 8:57:22the order model here is it okay okay so
- 8:57:24we have those columns let's copy these
- 8:57:27four additional columns and let's put
- 8:57:31them right
- 8:57:36here okay and now let's define also
- 8:57:38relation here I'm going to actually
- 8:57:40Define couple of relations uh like uh I
- 8:57:43need as many into order
- 8:57:48items for this we are using order item
- 8:57:50class let's define also
- 8:57:55belongs to belongs to
- 8:57:59user and for this we need user
- 8:58:03class but I want to also Define belongs
- 8:58:06to
- 8:58:08vendor vendor and in this case I'm going
- 8:58:11to access into vendor class uh through
- 8:58:17user ID foring key
- 8:58:22so now actually this is is
- 8:58:26vendor vendor user
- 8:58:28ID uh
- 8:58:30and then right here we have the owner
- 8:58:33key is the user ID so order has vendor
- 8:58:36user ID using which it relates
- 8:58:41to the user ID however I'm going to
- 8:58:44Define also vendor
- 8:58:47user vendor user so we have the user and
- 8:58:50that user is the buyer who uh
- 8:58:54made this order and vendor user is the
- 8:58:57user for which we made the um
- 8:59:07order so here we need this vender user
- 8:59:11ID okay now if we go into card
- 8:59:16controller um I think we should be good
- 8:59:20let's click on proed to check out what
- 8:59:21other error do we have
- 8:59:25okay array to string conversion okay so
- 8:59:28we have to open order items again and we
- 8:59:30have to create this casts for variation
- 8:59:35type option IDs to be
- 8:59:37array now let's click proceed to check
- 8:59:41out and now we see that stripe payment
- 8:59:45page was open of course the image is
- 8:59:47broken because um we have the local
- 8:59:50environment and we don't have the images
- 8:59:53the it needs to be hosted basically
- 8:59:55somewhere because stripe grabs those um
- 8:59:57image URLs okay so we are in the test
- 9:00:00mode we see total is uh 300 now let's
- 9:00:03see inside orders what happens so we
- 9:00:05have now one order for user one vendor
- 9:00:08user ID four the order status is draft
- 9:00:11because this is uh the initial order and
- 9:00:13we see order items as well one order
- 9:00:16item total quantity variation type
- 9:00:18option like this okay everything looks
- 9:00:20great and now when the payment is made
- 9:00:23we are going to be redirected into the
- 9:00:26success page and we have to take care of
- 9:00:29these things so let me open now
- 9:00:32resources JS pages and right here I'm
- 9:00:36going to
- 9:00:38create uh stripe SL
- 9:00:41success
- 9:00:44component uh like this let's remove this
- 9:00:48props remove this and remove that as
- 9:00:50well and I'm going to now start start
- 9:00:54working
- 9:00:55on um let's open stripe controller and
- 9:00:59I'm going to implement this web hook
- 9:01:01this is the most interesting
- 9:01:05part okay so I'm going to use request
- 9:01:08right here and make sure that the
- 9:01:10request is also imported here so then
- 9:01:13I'm going to create this stripe client
- 9:01:15providing this stripe secret ID and I'm
- 9:01:18going to also open
- 9:01:21this config and I want to add second
- 9:01:25which is going to be for stripe uh web
- 9:01:27hook secret key let's call this
- 9:01:30stripe
- 9:01:32webhook
- 9:01:34secret and let's take it from in stripe
- 9:01:39web hook secret I think we gave it the
- 9:01:43same name let's
- 9:01:47open. stripe web hook
- 9:01:50secret yeah we have that uh name defined
- 9:01:53here okay great now let's open this
- 9:01:58stripe controller and now I'm going to
- 9:02:01create this endpoint secret which is
- 9:02:03going to be what we just
- 9:02:05created here next I'm going to get the
- 9:02:09payload from the request I'm going to
- 9:02:12take the stripe signature header and
- 9:02:14then we're going to validate if the
- 9:02:16payload is coming from the actual stripe
- 9:02:19and it's not modified so we're going to
- 9:02:22create the in event we're going to
- 9:02:23create create the TR catch and we are
- 9:02:25going to construct this event through
- 9:02:28this payload with a signature header and
- 9:02:30endpoint secret so this actually
- 9:02:33performs the validation if the event is
- 9:02:35created we are good if the event was not
- 9:02:38created then uh it will throw an
- 9:02:40exception and then we have to handle
- 9:02:42those exceptions um unexpected value
- 9:02:45exception we're going to print something
- 9:02:47in the logs and invalid payload is going
- 9:02:50to be the response with the status code
- 9:02:52400 and we'll have the signature
- 9:02:54verification exception we're going to
- 9:02:56again print the error and invalid
- 9:02:58payload is what we are going to return
- 9:03:01okay so if the catch didn't happen and
- 9:03:03event was created then down below we are
- 9:03:06going to print that event with a type
- 9:03:10and with um with event itself as well
- 9:03:16okay so uh we just need to have a look I
- 9:03:18I I want to explain few things so I want
- 9:03:22to print them and just have a look so
- 9:03:25now we are gonna uh check what is the
- 9:03:28type of this event and we're going to
- 9:03:31receive multiple types we're going to
- 9:03:33receive four or five events um for
- 9:03:37single payment and we have to take here
- 9:03:39of only two we we need charge updated
- 9:03:42and uh checkout session completed
- 9:03:45checkout session is completed when
- 9:03:46everything was completed and we know
- 9:03:49that the uh payment was completed but we
- 9:03:52have also charge updated which happens a
- 9:03:55little bit later and charge updated
- 9:03:58event will give us information about how
- 9:04:01much
- 9:04:02stripe the stripe uh how much was a
- 9:04:07stripe fee okay so now inside charge
- 9:04:11updated we get what is the actual charge
- 9:04:15which we can always get from even data
- 9:04:17object so that charge is going to be an
- 9:04:19associative array then from the charge
- 9:04:22we're going to take balance transaction
- 9:04:25ID and payment intent so you should also
- 9:04:28keep in mind that first checkout session
- 9:04:32completed uh will be executed if we
- 9:04:35speak about the sequential order first
- 9:04:38checkout session completed will be
- 9:04:40executed and then charge update will be
- 9:04:43executed and whenever checkout session
- 9:04:45completed is executed inside orders
- 9:04:48table in the database we are going to
- 9:04:51save payment intent
- 9:04:53okay so we're going to do this right
- 9:04:55here in this checkout session completed
- 9:04:57uh case so then when the charge updated
- 9:05:01happens we get this payment intent and
- 9:05:04we are going to select orders with this
- 9:05:06payment intent and this is going to be
- 9:05:09the charge updated event will be also
- 9:05:11the case when we send email to buyer or
- 9:05:13to vendor as well that the order has
- 9:05:15been made so we're going to do this
- 9:05:17later not right
- 9:05:18now okay now from this transaction ID
- 9:05:24and through this stripe client we send
- 9:05:26the request in stripe a API to receive
- 9:05:29the balance transaction
- 9:05:31information that balance transaction
- 9:05:33information will contain the stripe fee
- 9:05:35as well now we're going to select orders
- 9:05:38based on the following payment intent
- 9:05:40and those are the orders we need to
- 9:05:43update so we also get the what was the
- 9:05:46total paid amount by this buyer and this
- 9:05:50is going to be balance transaction
- 9:05:53amount
- 9:05:54this is going to be also the same amount
- 9:05:56as sum of total orders so remember a
- 9:06:02buyer can make a single checkout for
- 9:06:06multiple orders and we are creating
- 9:06:08multiple orders right each order for
- 9:06:12each vendor and the total amount is what
- 9:06:16the buyer paid which will be distributed
- 9:06:19across multiple vendors Okay so that
- 9:06:23amount will be the same as sum of total
- 9:06:26prices of these orders so we have the
- 9:06:29stripe vew which I'm going to set this
- 9:06:31into zero okay then uh inside this
- 9:06:35balance transaction we have fee details
- 9:06:37which is array and each fee detail has
- 9:06:40its own type as well so we're going to
- 9:06:42find the feed detail which has stripe um
- 9:06:46which has Type to be stripe fee and we
- 9:06:50are going to take the stripe fee
- 9:06:51whatever will be fee detail amount and
- 9:06:55in the following way we have the stripe
- 9:06:56fee which is going to be in
- 9:06:59cents okay so next we are going to
- 9:07:03calculate what is going to be platform
- 9:07:06fee percentage and this is something I
- 9:07:09want to add inside app config again so
- 9:07:14right here let's add platform fee let's
- 9:07:18give it 10 so platform fee percentage is
- 9:07:2110% and right here we need to calculate
- 9:07:25what um will be these columns if we
- 9:07:28expand order table we're going to
- 9:07:30calculate we know exactly what was the
- 9:07:32stripe fee and that is going to be
- 9:07:34online payment commission okay so we
- 9:07:38need we have to calculate what is going
- 9:07:40to be website commission website
- 9:07:43commission will be
- 9:07:46whatever was remaining after stripe
- 9:07:49after deducting stripe fee on the total
- 9:07:52amount what ever is remaining taking 10%
- 9:07:56of that so let's go ahead and do it so
- 9:08:00now I start iterating over orders and we
- 9:08:02have to update each order and this is a
- 9:08:05place where we have to send email to
- 9:08:07each vendor as well that the New Order
- 9:08:09was made for them
- 9:08:11now let's take what is the vendor share
- 9:08:15of the total amount okay so if two
- 9:08:18orders were made let me open a new text
- 9:08:21file so if two orders were made need
- 9:08:24let's put this on the right side so
- 9:08:26let's say vendor one has $100 and vendor
- 9:08:32two has $200 orders so then the vendor
- 9:08:36share will be whatever was the total so
- 9:08:39for vendor one vendor share will be 100
- 9:08:42divided on 300 because the total amount
- 9:08:46was 300 that was paid by uh buyer so
- 9:08:51then we have this vendor share okay and
- 9:08:53through this vendor share we're going to
- 9:08:55calculate uh what was the online payment
- 9:08:58commission as well we know that user
- 9:09:00paid user paid
- 9:09:04300 okay and commission let's say we
- 9:09:08don't know how much but we we know uh
- 9:09:12this inside the stripe fee variable so
- 9:09:15we know that the stripe fee let's say we
- 9:09:17know that the stripe fee was $9 okay so
- 9:09:21stripe fee
- 9:09:25was $99 okay so we know that the vendor
- 9:09:28one had the its share of the total
- 9:09:31amount um 100 divided on 300 now we're
- 9:09:35going to distribute that stripe fee
- 9:09:39equally on all vendors as
- 9:09:42well okay let me explain this so stripe
- 9:09:46fee let's say it was nine so we're going
- 9:09:49to take and um for vendor
- 9:09:54one let's define field stripe fee for
- 9:09:57vendor one is going to be the stripe
- 9:10:01sheare Multiplied on stripe fee okay
- 9:10:06stripe sheare is 100 ided over 300 and
- 9:10:10if we multiply this on nine let's
- 9:10:12actually open
- 9:10:16calculator
- 9:10:19so 100 divided on 300 multiply this on
- 9:10:25nine so we're going to see three so
- 9:10:28three will be stripe fee for first first
- 9:10:32vendor okay so we are going to continue
- 9:10:36next vendor share Multiplied on stripe
- 9:10:38fee we see three then we're going to
- 9:10:40calculate what's going to be the we
- 9:10:42website commission website commission
- 9:10:44will be the order total price which was
- 9:10:48300 let's write website uh website fee
- 9:10:52so total price which was
- 9:10:54300
- 9:10:56minus online payment commission which
- 9:10:59was the the um for this vendor sorry
- 9:11:03hold on so website commission we're
- 9:11:05speaking about the uh this specific
- 9:11:07order not totally so order total price
- 9:11:10was 100 for the first vendor let's put
- 9:11:13this right here vendor one and then we
- 9:11:17have vendor two so stripe fee for vendor
- 9:11:20one was three website fee is going to be
- 9:11:23total price 100 minus whatever was the
- 9:11:28online payment commission which was
- 9:11:31three and that we know that information
- 9:11:35we have inside
- 9:11:39sents no we don't have that inside
- 9:11:42sense uh okay let me keep doing okay and
- 9:11:46that needs to be multiplied on platform
- 9:11:48fee person so from this we're going to
- 9:11:51calculate 10%
- 9:11:53and if we just divide this into 100 and
- 9:11:57then multiply this into 10 which means
- 9:11:59that dividing this into 10 we're going
- 9:12:01to calculate this 10% which is going to
- 9:12:04be again open calculator
- 9:12:07[Music]
- 9:12:08so 100 minus
- 9:12:123 that needs to be divided on 10 and
- 9:12:16this is going to be website
- 9:12:18fee let's write here
- 9:12:219.7 is going to be the website fee okay
- 9:12:25after this we're going to calculate what
- 9:12:28vendor will
- 9:12:30receive vendor
- 9:12:35subtotal so vendor will receive the
- 9:12:38total price minus online payment
- 9:12:41commission and minus website commission
- 9:12:45so 100 minus three which is the online
- 9:12:48payment commission minus the website
- 9:12:50commission which is 9.7
- 9:12:53is going to
- 9:12:56be 100 - 3 -
- 9:13:019.7 is going to be
- 9:13:0587.3 so
- 9:13:0787.3 is what the vendor vendor will
- 9:13:11receive when the payment is made um on
- 9:13:15100
- 9:13:16amount so that's it so after this we're
- 9:13:19going to save that information into
- 9:13:21orders and in the future we're going to
- 9:13:23and email as well and that is basically
- 9:13:26what happens inside this uh charge
- 9:13:28updated so uh we need that charge
- 9:13:30updated to get the balance transaction
- 9:13:33information and to be able to get that
- 9:13:36fee details we don't have that fee
- 9:13:38details in this checkout session
- 9:13:40completed but now let's talk about
- 9:13:42inside checkout session completed which
- 9:13:44as I mentioned happens before charge
- 9:13:48update it happens okay so here we're
- 9:13:51going to get this session event St data
- 9:13:53object then we're going to get the
- 9:13:55payment intent information from the
- 9:13:57session and we're going to find orders
- 9:14:00by session ID and set the payment intent
- 9:14:03information so order with order items as
- 9:14:06well where stripe session ID equals this
- 9:14:09session ID we find those
- 9:14:11orders and we're going to iterate over
- 9:14:13those orders and update payment intent
- 9:14:15id but we're going to do a few
- 9:14:17additional things as well let me move
- 9:14:20this here we're going to do few
- 9:14:22additional things things so let's start
- 9:14:23iterating over orders we're going to set
- 9:14:26the payment intent to Pi we're going to
- 9:14:28Mark the order to be paid and update the
- 9:14:31order but we're going to also calculate
- 9:14:35which products need to be deleted from
- 9:14:37cart okay because we performed the
- 9:14:40checkout from the cart items database
- 9:14:43table those cart items needs to be
- 9:14:46removed from the cart right so the
- 9:14:49existing cart items we're going to
- 9:14:52destructure these
- 9:14:54because we're doing this basically for
- 9:14:56many orders like a one user as I
- 9:14:58mentioned this many many times one user
- 9:15:01might make the payment for multiple
- 9:15:03orders right and all of these products
- 9:15:05need to be removed from the card so we
- 9:15:07are
- 9:15:08calculating the total product IDs
- 9:15:12products to be deleted from the card and
- 9:15:14that is concatenated with order order
- 9:15:17Items Map and taking the product ID for
- 9:15:21each order item and to where so this
- 9:15:23simply will return product IDs okay so
- 9:15:28there might be the product ID repeated
- 9:15:30many times if we are checking out the
- 9:15:32same product with two or three different
- 9:15:36variations the product ID inside these
- 9:15:39products to be deleted from card array
- 9:15:41might be repeated but it's not big deal
- 9:15:44because anyway we're going to delete
- 9:15:46them from the cart so after this we're
- 9:15:50going to reduce the product quantity so
- 9:15:51we iterate over order items we take the
- 9:15:55options from this variation type option
- 9:15:58IDs and we take the product and this is
- 9:16:01the case what we are where we need to
- 9:16:03have a look at the
- 9:16:04options okay so the product the user
- 9:16:08might purchased a specific variation of
- 9:16:10the product and if the user purchased a
- 9:16:13specific variation let's say one over
- 9:16:15five we have to decrease the quantity
- 9:16:18from here but if the user did not
- 9:16:20purchase any specific variation or if
- 9:16:22the product even didn't have any
- 9:16:24variations then we have to decrease the
- 9:16:26quantity from the product model itself
- 9:16:29so if options exist if there was
- 9:16:32something in the order item variation
- 9:16:34type option IDs which in our case is not
- 9:16:38like this so inside variation type
- 9:16:40option ideas we have empty array and if
- 9:16:43empty array returns false but if options
- 9:16:46exist then we're going to get the
- 9:16:49variations and on that variation we're
- 9:16:52going to find the variation with the
- 9:16:54following options right here and we're
- 9:16:57going to get the first one and then if
- 9:17:00the variation exists and if the
- 9:17:02variation quantity is not null if the
- 9:17:05quantity is null it means that we have
- 9:17:07unlimited uh quantity of that
- 9:17:09variation if the variation is not null
- 9:17:12then we're going to deduct that order
- 9:17:15item quantity from the variation
- 9:17:17quantity and we're going to save that
- 9:17:19okay however if the options in else case
- 9:17:23right here if the options does not exist
- 9:17:27then if the product quantity is not null
- 9:17:30if we don't have product unlimited
- 9:17:31quantity then from the product quantity
- 9:17:34we're going to detect the order item
- 9:17:36quantity after
- 9:17:40which this is for this order items Loop
- 9:17:44so after the end of this order items
- 9:17:46loop we're going to iterate over uh not
- 9:17:50iterate but we're going to directly
- 9:17:51delete
- 9:17:53uh cart items so for the user for the V
- 9:17:57uh order user basically
- 9:18:01um this is something uh I think a
- 9:18:06mistake yeah this is something that is a
- 9:18:09mistake and I will fix that um so
- 9:18:14let's let's let me finish this okay okay
- 9:18:17this is it okay so now we're going to
- 9:18:19delete the cart items with the following
- 9:18:22product IDs so these are the product IDs
- 9:18:24that need to be deleted but we're going
- 9:18:26to delete those products for the user
- 9:18:31for the
- 9:18:32um for the
- 9:18:34buyer and we this actually works
- 9:18:40um but the thing is that okay let me
- 9:18:45explain so all orders right here on this
- 9:18:48place if like there there was like more
- 9:18:52than one order order so all orders will
- 9:18:54be made on the same user right so if I
- 9:18:59added multiple items from two different
- 9:19:02vendors into the card I performed the
- 9:19:04checkout two orders were create created
- 9:19:07in both cases user ID will be me it's
- 9:19:10going to be current user ID right so we
- 9:19:13want to find all the products from cart
- 9:19:15items with a current user
- 9:19:17ID and um with the product IDs so this
- 9:19:22is actually what is going on right here
- 9:19:24and I think this is also fine so we are
- 9:19:26iterating over orders we know that there
- 9:19:30will exist some order for sure okay so
- 9:19:34we know that this for each will happen
- 9:19:36at least once and when this happens
- 9:19:39order variable will be created and that
- 9:19:42order variable is used right here Order
- 9:19:47user ID so for all orders order user ID
- 9:19:51will be the same so we are fine cart
- 9:19:53items with the order user ID Products to
- 9:19:56be deleted we're going to exclude those
- 9:19:59items which have saved for later
- 9:20:02false and we're going to perform delete
- 9:20:06now let me import these classes cart
- 9:20:09item we're going to import order status
- 9:20:11ANM let's import order
- 9:20:15item what else do we need we need to
- 9:20:18import
- 9:20:21order up models
- 9:20:25order and we need import
- 9:20:33log
- 9:20:34okay okay this is good now I want to
- 9:20:39open this Lal log file and we will get
- 9:20:43some output right here so if we scroll
- 9:20:45at the very bottom uh we're going to see
- 9:20:48some output when we perform the checkout
- 9:20:51and I also want to open
- 9:20:53open this place uh where we have this
- 9:20:56web hook up and running and now uh we
- 9:20:59are going to close this we're going to
- 9:21:01go
- 9:21:04back and click on this proceed to check
- 9:21:08out um maybe we can do this for for
- 9:21:12multiple vendors so we have we have two
- 9:21:16vendors let's open this add it into the
- 9:21:18cart maybe maybe we can add different
- 9:21:20variations as well
- 9:21:24um okay now for
- 9:21:27vendor for vendor store we have these
- 9:21:31two products with these prices and right
- 9:21:34here we have um the
- 9:21:37six okay let it be like this we have to
- 9:21:41calculate so totally this will be the
- 9:21:43amount and we're going to see that okay
- 9:21:45anyway let's click on proceed to check
- 9:21:49out and let me choose card here and I'm
- 9:21:52going to fill the card information so we
- 9:21:55can use 42 42 42 as well but I'm
- 9:21:57actually using four uh a lot of zeros
- 9:22:01and then finally 27 so this actually
- 9:22:04fills up uh my stripe balance as well so
- 9:22:09if we check then inside
- 9:22:12balances we have zero balance right here
- 9:22:15so me as a Marketplace have zero balance
- 9:22:18right here but when I perform uh payment
- 9:22:21with this card my balance will be filled
- 9:22:23up so now let's provide that information
- 9:22:26User click on
- 9:22:29pay uh of course we will be redirected
- 9:22:31into success which we don't have uh yet
- 9:22:34implemented
- 9:22:36but uh the web Hook is not
- 9:22:40working let's restart the web
- 9:22:48hook okay we are not going to get
- 9:22:50anything because web hook wasn't
- 9:22:54triggered we have to redo
- 9:23:01this okay let's go into cart also order
- 9:23:04items will not be deleted because
- 9:23:08um the web hook wasn't completed so the
- 9:23:12order will be made but that's not
- 9:23:13important so it's going to be draft
- 9:23:16order let's provide card here
- 9:23:27click on pay and I want to have a look
- 9:23:30this
- 9:23:34part where is web hook
- 9:23:39information
- 9:23:41okay uh we are not properly listening to
- 9:23:47something it is not sending that
- 9:23:49information to us now let's go into
- 9:23:53event
- 9:23:56destinations we on
- 9:24:01local okay something is going
- 9:24:04on I think I know what's going on
- 9:24:07because uh I have to execute login again
- 9:24:11to get connected to this account because
- 9:24:14I have two accounts I was connected with
- 9:24:16this L react Ecommerce and it is
- 9:24:18listening right here not here we don't
- 9:24:21have the listener um let's clear this up
- 9:24:25and I'm going to
- 9:24:27call stripe login so in your case it's
- 9:24:31going to probably work uh okay we're
- 9:24:34going to open this in the
- 9:24:41browser I'm going to now connect to the
- 9:24:48application okay I enter the code now I
- 9:24:50give L access and access was granted
- 9:24:56here okay done stripe C is configured
- 9:24:59for LEL react e-commerce tutorial with
- 9:25:02count I did this perfect and now if we
- 9:25:04execute stripe
- 9:25:06listen uh we need to get a new web hook
- 9:25:10I
- 9:25:10think so let me copy
- 9:25:13this
- 9:25:16open in stripe web hook secret and
- 9:25:20replace this cool now let's go
- 9:25:27back go into view
- 9:25:34cart click on proceed to check out have
- 9:25:36a look
- 9:25:41here uh so far we don't have any web
- 9:25:44hooks let me move this on my second
- 9:25:46screen let's
- 9:25:50provide sometimes we also get web hooks
- 9:25:52when we open the stripe
- 9:25:58page click on
- 9:26:02pay okay now we are receiving workbooks
- 9:26:04now we are talking uh but actually uh
- 9:26:08those web hooks returned with
- 9:26:10400 something is actually gone wrong and
- 9:26:15we are not
- 9:26:16actually we we are not able to correctly
- 9:26:20validate uh the web payload so if we
- 9:26:23have a look in our code in the stripe
- 9:26:28controller so we
- 9:26:31have we are using this stripe endpoint
- 9:26:36secret from up
- 9:26:41config that's my
- 9:26:43bet that's my bet this is stripe web
- 9:26:46hook
- 9:26:48secret yeah I made that
- 9:26:50mistake I made that mistake and because
- 9:26:53of that it wasn't validated okay let's
- 9:26:55go back once again
- 9:26:59into own
- 9:27:02page click on
- 9:27:04cart proceed to check
- 9:27:12out now uh the so we received couple of
- 9:27:17events like check out session completed
- 9:27:18charart succeeded and so on and after
- 9:27:20one minute if you pay attention so after
- 9:27:22one minute we get this balance available
- 9:27:26okay and now it return 200 because we
- 9:27:28managed to fix that web hook and if we
- 9:27:32check lot of logs we are going to see
- 9:27:35right here one log for balance available
- 9:27:39look at this this is it for balance
- 9:27:42available and this is the event and that
- 9:27:46balance is actually what contains the
- 9:27:48side
- 9:27:50there uh uh that's a total available
- 9:27:54balance okay yeah that's the overall
- 9:27:56information about the balance available
- 9:28:00okay good good good good so the main
- 9:28:03thing is that we made the web hook
- 9:28:04working now if we go in the stripe
- 9:28:06controller everything is good let's go
- 9:28:08into the website and F this information
- 9:28:11here
- 9:28:18um user hit the enter now let's check
- 9:28:22the web hooks area now okay all web
- 9:28:25hooks completed successfully but the web
- 9:28:27hook actually we have some error in the
- 9:28:30web hook area we're going to check the
- 9:28:32Lal log okay so now let's see so we have
- 9:28:35these new errors on the following time
- 9:28:38I'm going to search now records by
- 9:28:42time uh okay let's start from the top so
- 9:28:45we received payment intent succeeded we
- 9:28:49received chart succeeded we received
- 9:28:51payment intent created all of them at
- 9:28:54the same time and then we have the
- 9:28:56objects right here the information about
- 9:28:58the objects so this
- 9:29:00is payment intent succeeded which we
- 9:29:03don't need okay we're also printing that
- 9:29:06Json here
- 9:29:09scroll this is also payment in no this
- 9:29:11is actually charge
- 9:29:15information yeah this is the charge
- 9:29:17information and if we have a look at the
- 9:29:19charge information that
- 9:29:24contains uh I want to explain this very
- 9:29:27clearly so we have this charge updated
- 9:29:31and we have the balance transaction here
- 9:29:33so if we check this charge information
- 9:29:36we're going to find balance transaction
- 9:29:38which is actually null so we we receed
- 9:29:41these two times charge created and
- 9:29:43charge updated we have a lot of logs
- 9:29:46checkout session completed is the first
- 9:29:47one which we receive uh we received
- 9:29:53uh where is
- 9:29:54payment intent let's find payment
- 9:29:58intent we have a payment intent so on
- 9:30:02checkout session completed we took the
- 9:30:03payment intent as saved in the orders
- 9:30:06Table after this we have an error
- 9:30:09attempt to read property quantity on
- 9:30:12null which is coming
- 9:30:14from stripe controller
- 9:30:18125 125
- 9:30:22five that's coming from the product
- 9:30:25quantity okay it looks like product
- 9:30:28didn't exist so looks like from the
- 9:30:30order item we didn't Define relation
- 9:30:33belongs to relation into
- 9:30:39product
- 9:30:41product class
- 9:30:44cool we are going to do this once
- 9:30:50again let's see if we have items into
- 9:30:52the cart we still have items into the
- 9:30:54cart because when this
- 9:30:57happened uh the cart items were not
- 9:31:00deleted so let's
- 9:31:03provide proceed provide card
- 9:31:11details we hit the enter let's open web
- 9:31:15hooks terminal all of the web hooks were
- 9:31:17completed successfully and now we
- 9:31:19receive charge updated look at this so
- 9:31:21first we received everything else lately
- 9:31:24we received charge updated and now if we
- 9:31:26have a look in logs we are going to see
- 9:31:30better
- 9:31:32results without any kind of Errors now
- 9:31:35it starts right here charge updated we
- 9:31:38got the charge updated then we have the
- 9:31:40balance transaction ID right here
- 9:31:42through this balance transaction we
- 9:31:44fetch the balance information and from
- 9:31:46that balance information we are able to
- 9:31:48extract the information regarding stripe
- 9:31:51fee um and we have the balance available
- 9:31:54so everything every web hook data is
- 9:31:56logged but now the coolest part is to
- 9:31:59check the orders table and let's find
- 9:32:02the latest order which was completed
- 9:32:05successfully which is paid so that order
- 9:32:09actually we made two orders uh at the
- 9:32:11same time okay if we check if we
- 9:32:17check
- 9:32:20these yeah they are made on the same
- 9:32:22time now have a look so what is the
- 9:32:26total amount total price for the first
- 9:32:29order is 40 for the second is 300 so
- 9:32:33user actually paid 40 and 300 now let's
- 9:32:36check stripe balance first click on
- 9:32:40balances now look at this so we have
- 9:32:42such amount and that happens because we
- 9:32:44made payment many times with the same
- 9:32:48amount uh but uh where we are actually
- 9:32:51testing
- 9:32:52so we did this five times but if we
- 9:32:55check this right now so
- 9:32:57340 was the amount out of this net is
- 9:33:02actually
- 9:33:21we are going to see
- 9:33:24um we are going to see 10.16 I have a
- 9:33:28question why do we have so many digits
- 9:33:31after comma when I remember that we
- 9:33:37provided total with four places
- 9:33:42here
- 9:33:47interesting yeah okay it looks like um
- 9:33:52SQ light doesn't have that decimal type
- 9:33:55of thing and that's because of it so if
- 9:33:58it's where my SQL the other information
- 9:34:00would be lost but now let's open
- 9:34:04calculator and
- 9:34:07this
- 9:34:09plus
- 9:34:11this 10.16 the exact number what we have
- 9:34:15right here so we distributed that
- 9:34:1810.16 uh proportionally to this order so
- 9:34:21because uh that order has 300 uh then
- 9:34:26the fee on that order was much higher
- 9:34:28than this order which has uh 1 point
- 9:34:31something now we also calculated uh the
- 9:34:34website
- 9:34:35commission out of the remaining value
- 9:34:37which is the 10% so if we actually we
- 9:34:41know that the online commission uh on
- 9:34:43this was that so that order has 300 so
- 9:34:48now 300 minus the
- 9:34:52which gives us the following value and
- 9:34:54we're going to calculate 10% of it
- 9:34:56meaning divide this on 10 equals 29
- 9:35:00something which is exactly what we see
- 9:35:03right here okay and then we have the
- 9:35:05wender subtotal information and this is
- 9:35:09pretty
- 9:35:10cool so I think I'm going to close this
- 9:35:13I think the uh the working flow is
- 9:35:16actually pretty clear and just like this
- 9:35:18we have
- 9:35:19implemented um
- 9:35:22check out on multiple orders and I think
- 9:35:27we can we should create now the success
- 9:35:29page right here now let's open stripe
- 9:35:32controller success method and first
- 9:35:34let's uh use request variable here then
- 9:35:38I'm going to get the currently
- 9:35:39authenticated user information and I'm
- 9:35:41going to take the session ID from
- 9:35:43request we know that the session ID is
- 9:35:46in the URL when redirect it back into
- 9:35:48this success page so from the orders
- 9:35:51table I want to find all the orders by
- 9:35:53the session ID then I want to check if
- 9:35:55there are no such orders I want to abort
- 9:35:58immediately with 404 then I iterate over
- 9:36:01the orders and I want to check that if
- 9:36:06for some reason something wrong happened
- 9:36:09and those orders does not belong to the
- 9:36:11currently authenticated user then I'm
- 9:36:14also aborting with
- 9:36:1543 forbidden after which I'm going to
- 9:36:19render stripe success page
- 9:36:22uh inside uh using inertia and I'm
- 9:36:24providing these orders just created
- 9:36:27orders for this I'm going to create
- 9:36:30order view resource so let's execute PHP
- 9:36:33artisan make
- 9:36:36resource order view
- 9:36:41resource now let's open uh this order
- 9:36:45view
- 9:36:46resource which you have to import right
- 9:36:50here so I'm going to open this order
- 9:36:53view
- 9:36:55resource and we are going to uh return
- 9:36:58couple of information from here so we
- 9:37:02need ID we need total price we need
- 9:37:04status created it and I also need the
- 9:37:06vendor information and for this I'm
- 9:37:08going to create new resource vendor user
- 9:37:12resource uh let's actually execute PHP
- 9:37:15artisan make
- 9:37:17resource vendor user resource
- 9:37:22we hit the enter vendor user resource
- 9:37:24was created make sure it is imported
- 9:37:26right here or if it's they are in the
- 9:37:29same name space no need to be imported
- 9:37:31which is exactly our case uh let's open
- 9:37:35this vendor user resource and I'm going
- 9:37:37to actually copy and paste
- 9:37:39the fields what we need here ID name
- 9:37:42email vendor store name and vendor store
- 9:37:45address so now I'm going to continue
- 9:37:48here we need order items I'm going to
- 9:37:50iterate over the order it items and I
- 9:37:52want to render the um I want to return
- 9:37:55the ID quantity price variation type
- 9:37:57option IDs and I want to return the
- 9:38:00product details inside product details I
- 9:38:02want ID title slug I need description
- 9:38:06and image information as well so I'm
- 9:38:08going to create this get image for
- 9:38:10options but I will explain what this
- 9:38:12actually is going to do so because this
- 9:38:14is the order items order items might
- 9:38:16have a specific variation type option
- 9:38:18IDs right so I want to display
- 9:38:22that specific variation type option ID
- 9:38:25is image for the product that was just
- 9:38:28sold so when we display the order
- 9:38:31details uh the user should see exactly
- 9:38:35the color and type of the image they
- 9:38:37have purchased not the default one
- 9:38:40so I'm going to open product.php and I'm
- 9:38:45going to create that function get um
- 9:38:47image for options we're going to expect
- 9:38:50right here option IDs which might be
- 9:38:51also
- 9:38:52null and we are providing empty array or
- 9:38:56null right here if it doesn't exist so
- 9:38:58if it is um if it doesn't exist if it's
- 9:39:01an empty array or null doesn't matter so
- 9:39:04if it exists then in in this case we're
- 9:39:06going to take the values so here we have
- 9:39:08this variation type option IDs inside
- 9:39:11the order
- 9:39:14item which actually uh is um object
- 9:39:19object speaking about the Json but
- 9:39:21associative array speaking from the PHP
- 9:39:24perspective so we have this associative
- 9:39:26array and we are taking values of that
- 9:39:30so we just need the option IDs like in
- 9:39:32in our case we need one and four three
- 9:39:36and five so we take those option IDs and
- 9:39:39then we select the variation type option
- 9:39:42we're providing these option IDs here uh
- 9:39:45I think sorting is not even necessary
- 9:39:47here so we get those options we start
- 9:39:50iterating over the the options uh and we
- 9:39:53take image the first image for this
- 9:39:56option so if the image exists then we
- 9:40:00return it if it doesn't exist we're
- 9:40:01going to return the first image First
- 9:40:03Media URL uh through this spy media
- 9:40:07library helper um of the product itself
- 9:40:10not the variation option okay so and
- 9:40:13just like this we are
- 9:40:15returning uh this order resource we we
- 9:40:18finish this and we're going to get oops
- 9:40:21we're going to get the data in the front
- 9:40:24end so let's go into types typescript
- 9:40:28types and I'm going to Define order item
- 9:40:31to have ID quantity price we're going to
- 9:40:33have this variation type option IDs
- 9:40:35we're going to have product as well uh
- 9:40:37ID title slug description image and I'm
- 9:40:41going to Define also order with ID total
- 9:40:44price status create that we're going to
- 9:40:46have the vendor information as well ID
- 9:40:48name email store name and store address
- 9:40:52and now if we go into success um first
- 9:40:55let me import all the components and
- 9:40:57classes I need I need head and Link from
- 9:41:00injs I need currency format I need this
- 9:41:04check Circle icon from the hero icons I
- 9:41:07need authenticated layout I need page
- 9:41:09props and order then I'm going to take
- 9:41:12orders right here let's create
- 9:41:14authenticated layout inside here we need
- 9:41:17head then let's define the Steve with
- 9:41:19fixed withd shrink with with margin X
- 9:41:22Auto inside here another div and then
- 9:41:25we're going to display this uh check
- 9:41:27Circle icon with a green color and
- 9:41:29message payment was completed and we're
- 9:41:31going to see this thank you for your
- 9:41:33purchase text as well and now I'm going
- 9:41:35to start iterating over my orders and
- 9:41:37I'm going to display card for each order
- 9:41:40so we're going to have the uh background
- 9:41:43white on dark mode we're going to have
- 9:41:45different color background so we're
- 9:41:47going to have the order summary
- 9:41:48information we're going to have who is
- 9:41:50the seller
- 9:41:51which is going to be uh the order vendor
- 9:41:54user. store name is the seller and in
- 9:41:57the future we're going to create a page
- 9:41:58and Link that to the vendor store as
- 9:42:01well so we're going to have also order
- 9:42:05number which is going to be the order ID
- 9:42:07and when we implement the order Details
- 9:42:09page we're going to link this to the
- 9:42:11following um URL as well so we're going
- 9:42:14to have uh total items which is going to
- 9:42:17be order. order items length and we are
- 9:42:20going to also have the total price which
- 9:42:23is going to be order. total
- 9:42:26price
- 9:42:27um formatted nicely so and finally I
- 9:42:32think we need the view order details
- 9:42:33pattern and we're going to have uh the
- 9:42:36back to home now let me see why we have
- 9:42:40this order items property doesn't
- 9:42:44exist uh let's open
- 9:42:46it okay let's add order items here cool
- 9:42:54okay I think this is great and now let
- 9:42:56me test Let me refresh the existing page
- 9:42:58and let's open Dev tools as well just in
- 9:43:00case we have some
- 9:43:02error uh okay read find reading store
- 9:43:07name so we don't have store name let's
- 9:43:11print right here entire orders
- 9:43:16information okay uh okay we need to
- 9:43:20disable we need to disable WP so right
- 9:43:23here we're going to set public static WP
- 9:43:27equals false we don't want R we refresh
- 9:43:31the
- 9:43:32page and now we see that so we see
- 9:43:35payment was completed thank you for your
- 9:43:37purchase and we see two orders the first
- 9:43:39is for Zoomer with 300 amount one item
- 9:43:43order number and then here we have
- 9:43:46totally two items um total price is 40
- 9:43:49for the vendor store
- 9:43:51we see order details and back to home as
- 9:43:54well and this is great so as a challenge
- 9:43:56I give you to you to implement the
- 9:43:59failure and something similar uh you can
- 9:44:02just display this sorry the payment has
- 9:44:04been failed or something like this as
- 9:44:06you wish so you can do this now let me
- 9:44:10Implement showing success message when
- 9:44:12we add item into the cart it is added
- 9:44:15count is increased but we don't see the
- 9:44:16success message and this is what I'm
- 9:44:18going to do right now so let's open
- 9:44:20first handle initial JS request and when
- 9:44:23we put this access message I'm going to
- 9:44:26give this also time when the message was
- 9:44:29generated okay so here we're going to
- 9:44:32have message is going to be session
- 9:44:35success and we need time here which I'm
- 9:44:39going to generate micro time with
- 9:44:43true like this now let's open index. DTS
- 9:44:49and right here I'm going to change this
- 9:44:50as well well so we have message which is
- 9:44:53going to be string and we're going to
- 9:44:55have time which is going to be
- 9:44:58number finally let's open authenticated
- 9:45:01layout and we're going to take care of
- 9:45:03this part we have props here so we can
- 9:45:07access the success meage message through
- 9:45:09props let me Define state right here
- 9:45:11which is going to be success messages
- 9:45:13State array and whenever there's a
- 9:45:17success message we're going to push that
- 9:45:18inside that state so at the same time we
- 9:45:21might have multiple success messages
- 9:45:23displayed on the page so we Define the
- 9:45:25state we provide that and it can contain
- 9:45:28array of anything pretty much so next
- 9:45:31we're going to define the timeout
- 9:45:33reference because I also I also want to
- 9:45:36implement hiding that success message
- 9:45:39after a few seconds and for this I'm
- 9:45:41going to save the timeout references for
- 9:45:45each success message and this is going
- 9:45:47to be a use ref and here we're going to
- 9:45:50provide the type so key is going to be
- 9:45:53number of this object and value is going
- 9:45:57to be whatever is the type of set
- 9:46:00timeout function okay so we're going to
- 9:46:03import this user ref later so then we're
- 9:46:06going to listen to prop success and when
- 9:46:10this is changed so when we uh have new
- 9:46:13success message right here and this is
- 9:46:15going to be changed if message or time
- 9:46:17is changed so when this is changed we
- 9:46:21are going to do the following so we are
- 9:46:22going to check if prop success message
- 9:46:25exists then we're going to create the
- 9:46:27new message we're going to give it the
- 9:46:31um we're going to destructure the
- 9:46:33existing message take the message in
- 9:46:35time and we're going to give it also ID
- 9:46:38as a unique identifier okay which is
- 9:46:40going to be the access type so next we
- 9:46:44are going to call these set success
- 9:46:46messages which will accept a call back
- 9:46:47here so we're going to push that new
- 9:46:50success message in front of the previous
- 9:46:52messages and then that will be
- 9:46:55updated then we're going to set the
- 9:46:57timeout for the specific message so we
- 9:47:00Define this timeout ID set timeout uh
- 9:47:03for 5 seconds after 5 Seconds the
- 9:47:05message should be gone then we call this
- 9:47:07set success messages again after this 5
- 9:47:10seconds and we're going to filter out
- 9:47:12previous messages by the message ID okay
- 9:47:16which we gave it right here and
- 9:47:18whichever has the same ID as
- 9:47:23um as this new message ID right here
- 9:47:26which we just created then we're going
- 9:47:28to um
- 9:47:31return the uh previous messages without
- 9:47:33that message so we are filtering and
- 9:47:36setting removing that message from the
- 9:47:40success messages okay and we're going to
- 9:47:42also delete the timeout
- 9:47:45references uh for the current so we use
- 9:47:48this current because we have this
- 9:47:49timeout references to be refs so for the
- 9:47:53new message ID we are simply deleting
- 9:47:55this okay but whenever we uh create that
- 9:48:00new message and um set the access
- 9:48:02messages we are putting that uh timeout
- 9:48:06ID inside the timeout refs for the
- 9:48:09current message
- 9:48:10ID okay now let's focus on the template
- 9:48:13so we check the access messages length
- 9:48:15if it's more than zero we create the
- 9:48:17toast with the following classes and and
- 9:48:21inside here we iterate our success
- 9:48:22messages and we're going to display
- 9:48:24alert success with the uh
- 9:48:27message okay now let's import use
- 9:48:32effect and use
- 9:48:39ref we have a lot of other things which
- 9:48:41we can remove from here so now let's
- 9:48:44click
- 9:48:45on if we have any error let's have a
- 9:48:49look
- 9:48:52okay let's go on the homepage let's
- 9:48:54click on this Ed to
- 9:48:56cart uh app Services DB not
- 9:49:03found okay we have this issue in the
- 9:49:08cart
- 9:49:11service right here we probably have DB
- 9:49:15not
- 9:49:16imported illuminate support facades DB
- 9:49:20that's it
- 9:49:21okay great now we add this into the cart
- 9:49:24and we see product edit successfully we
- 9:49:26click on this and we see second one and
- 9:49:28the previous one is gone we click on
- 9:49:30this we see the third one and at the
- 9:49:33same time we can have multiple messages
- 9:49:35the new messag is at the top and the
- 9:49:36previous messages are gone after 5
- 9:49:39seconds if we go into the card and we
- 9:49:42change the quantity of it we're going to
- 9:49:44see quantity was updated if we click on
- 9:49:46delete we see product was removed from
- 9:49:48the cart we are returning correct
- 9:49:50message messages from the back end and
- 9:49:52that's why we see
- 9:49:55them nicely now I want to start working
- 9:49:58on email sending and we haven't actually
- 9:50:01sent any kind of email so far even for
- 9:50:03the registration for fake email sending
- 9:50:06or for local email sending I'm going to
- 9:50:08use mail
- 9:50:10pit just uh Google for mail pit open the
- 9:50:13following link right here you can click
- 9:50:16on installation it's going to open the
- 9:50:19following page and you have to download
- 9:50:21the static binary for Windows click on
- 9:50:23releases right here this is going to
- 9:50:25open the GitHub page scroll down below
- 9:50:28and download that zip file for your
- 9:50:30operating system then uh unzip that and
- 9:50:34uh open Terminal where you have that
- 9:50:38mail pit actually in in a similar way
- 9:50:40like we did for stripe so open that
- 9:50:43folder I think I have mail pit somewhere
- 9:50:45here this is it but but I actually made
- 9:50:48this globally available so this is what
- 9:50:51I'm going to
- 9:50:52do uh I'm going to open new terminal
- 9:50:56here and I'm going to type mail pit just
- 9:51:00mail
- 9:51:01pit and now it's started actually
- 9:51:04creating the server so we have this
- 9:51:06Local Host Port 8025 which is the user
- 9:51:09interface and we have to send the set
- 9:51:12the SMTP into
- 9:51:141025 let me
- 9:51:16open. find mail here and change change
- 9:51:21this mailer into
- 9:51:23SMTP and change the port into
- 9:51:271025 now let's open user.php and we are
- 9:51:31going to implement must verify
- 9:51:35email okay cool uh so the registration
- 9:51:38now requires the email verification and
- 9:51:41we can test this now for new
- 9:51:45registration login not login but
- 9:51:48register user two
- 9:51:51uh user
- 9:51:56288 example.com
- 9:52:01we hit the
- 9:52:03enter oh I made a
- 9:52:09mistake we hit the
- 9:52:11enter okay now the registration happened
- 9:52:15and we see new email right here okay
- 9:52:18click on this verify email address
- 9:52:21this is pretty cool the I I love
- 9:52:23actually using M pit it's it's pretty
- 9:52:25nice so now we are actually verified we
- 9:52:27are regular user and we are verified so
- 9:52:29email sending is working I can close
- 9:52:32this so now I want to implement email
- 9:52:35sending when the order is made and uh I
- 9:52:41want to open web hook functionality and
- 9:52:45we have we can remove these logs we
- 9:52:48don't need that anymore so these are the
- 9:52:51two places where I want to implement
- 9:52:53email sending for this I'm going to
- 9:52:54create two mail classes pH HP artisan
- 9:52:59make mail uh New Order mail which is
- 9:53:04going to be to vendor New Order mail
- 9:53:07this is going to go to
- 9:53:09vendor PHP
- 9:53:13Artis I made a mistake PHP
- 9:53:18Artisan okay and the second one is going
- 9:53:21to be checkout
- 9:53:24completed checkout
- 9:53:30completed okay so this is the place
- 9:53:33where we're going to send this into
- 9:53:34vendor so I'm going to use mail
- 9:53:37to uh
- 9:53:39order vendor
- 9:53:41user then we call send new New Order
- 9:53:48mail and we're going to provide the
- 9:53:49order here
- 9:53:51okay now we're going to send a so this
- 9:53:54uh email is sent to every
- 9:53:56vendor uh just let's make sure that
- 9:53:59vendor the order has vendor user it has
- 9:54:04which is cool and now we're going to
- 9:54:06send one email to buyer so mail
- 9:54:12to actually we don't need this back
- 9:54:14slashes we're going to import this mail
- 9:54:17facade like this so mail to
- 9:54:21orders at Z so orders at Z is basically
- 9:54:26uh the first order it it doesn't matter
- 9:54:30if you use orders at zero or orders at
- 9:54:32one because the buyer is always the same
- 9:54:35person right so we're going to use user
- 9:54:38here send new check out completed and
- 9:54:43we're going to provide all the orders in
- 9:54:45this
- 9:54:46case okay so now I want to create two
- 9:54:50files inside resources
- 9:54:54views uh I want to create two
- 9:54:57files inside that's going to be blade
- 9:55:00files let me create PHP file and I'm
- 9:55:04going to put the them inside mail folder
- 9:55:07slash uh new order. blade
- 9:55:13PHP new order. blade and the second one
- 9:55:17is going to be check
- 9:55:22out
- 9:55:24checkout
- 9:55:29completed oops that should be also dot
- 9:55:37blade okay let me remove this and remove
- 9:55:40that as well and in this let's open this
- 9:55:45new order mail and we're going to accept
- 9:55:48right here public
- 9:55:51order like this let's import this order
- 9:55:55and we're going to change the view name
- 9:55:58to be mail. new order now let's open
- 9:56:03check out completed as well in here
- 9:56:07we're going to accept public array of
- 9:56:14orders let me check how we are giving
- 9:56:17the
- 9:56:18orders orders is actually a collection
- 9:56:21so we can
- 9:56:22accept collection here collection of
- 9:56:25orders we can import this illuminate
- 9:56:29support collection cool and check out
- 9:56:33completed and we're going to change this
- 9:56:34into mail check out
- 9:56:37completed let's change this subject also
- 9:56:41thank you for your
- 9:56:46purchase to be able to customize email
- 9:56:49templates or colors or things like that
- 9:56:51we have to publish Lal mail files as
- 9:56:54well so I'm going to open now this kit p
- 9:56:57and let's execute right here PHP Artisan
- 9:57:00or we can do this generally how I do it
- 9:57:03PHP
- 9:57:04Artisan
- 9:57:06vendor publish and D- tag to be LEL
- 9:57:13dmail so we hit the enter now the vendor
- 9:57:18related files were published let's have
- 9:57:20a look so inside the vendor folder uh
- 9:57:23that vendor is not our vendor that is
- 9:57:25the vendor folder uh so vendor mail HTML
- 9:57:29and we see those blade files and we see
- 9:57:32themes CSS as well right here okay so
- 9:57:35we're going to adjust them a little bit
- 9:57:38but first let's open new order
- 9:57:41blade and because we have defined this
- 9:57:43new order mail uh and we have this
- 9:57:46public property order whatever is public
- 9:57:48in this mail class is can be accessed
- 9:57:51inside this blade file as well it's
- 9:57:54corresponding blade file which we have
- 9:57:55right here that blade file actually
- 9:57:57supports markdown syntax and we're going
- 9:57:59to use these components uh these
- 9:58:02markdown components in our blade file
- 9:58:05like the table sub copy um message and
- 9:58:09so on so let's start with message and
- 9:58:12the syntax is the following exmail colon
- 9:58:14colon message and we're going to wrap
- 9:58:16everything in our message so we're going
- 9:58:18to have H1 congratulations you have new
- 9:58:21order this is for the vendor we give it
- 9:58:23some styling and font size and text line
- 9:58:26Center so then we're going to have the
- 9:58:29view order details button uh at the
- 9:58:31moment we don't have the order Details
- 9:58:32page but we're going to create that
- 9:58:34later and we will have that next we're
- 9:58:36going to display the order summary
- 9:58:38information so we're going to create the
- 9:58:40table using this xmail we're going to
- 9:58:42have um the following information like
- 9:58:46this is the summary so order number the
- 9:58:48corresponding number order date date we
- 9:58:51have the order total which is going to
- 9:58:52be nicely formatted order total price
- 9:58:55for the order we're going to have
- 9:58:57payment processing fee which is going to
- 9:58:59be online payment commission but if for
- 9:59:02some reason that doesn't exist we're
- 9:59:03going to provide zero so that the
- 9:59:05currency doesn't thr an exception if
- 9:59:07that is null so also we have the
- 9:59:10platform fee which is going to be the
- 9:59:11website commission we're going to have
- 9:59:13your earnings right here as well and I
- 9:59:17think that's going to be all after we
- 9:59:20which we're going to create second table
- 9:59:22where we display all the items for the
- 9:59:24vendor again table we have item quantity
- 9:59:26and price we're going to iterate over
- 9:59:29the order
- 9:59:30items and we're going to create a couple
- 9:59:32of TDS so inside the first TD I want to
- 9:59:36put another table uh just to display
- 9:59:40image and title next to each other so
- 9:59:43here we have this
- 9:59:45image get get first get image for
- 9:59:49options and these are the variation type
- 9:59:51option IDs so in a similar way how we
- 9:59:54use this in the order view resource all
- 9:59:57right so then we have the product title
- 10:00:00so after which we're going to have
- 10:00:02second TD we can collapse this second TD
- 10:00:05which is going to be order quantity and
- 10:00:07we're going to have thirdd which is
- 10:00:09going to be the order item price and
- 10:00:11then down below I'm just going to put a
- 10:00:13panel here thanks for having business
- 10:00:15with us and thank you message now let's
- 10:00:18open check out completed and implement
- 10:00:20this as well we need message we need H1
- 10:00:22payment was completed successfully this
- 10:00:25is for the buyer so here we have a list
- 10:00:27of orders so here we have public
- 10:00:30property collection of orders so we
- 10:00:32access them we iterate and we display
- 10:00:36table for each order so we have the
- 10:00:38seller information because this email is
- 10:00:41to buyer we're going to display the
- 10:00:42seller
- 10:00:43information uh the order has vendor user
- 10:00:47which is a user user has access into
- 10:00:49vendor and vendor has a store name let
- 10:00:53me check if the user has definitely
- 10:00:55access to vendor yes it has okay so just
- 10:00:59like this we're printing the seller
- 10:01:00information we're going to print the
- 10:01:01order number as well and we're going to
- 10:01:04print the number of items or the total
- 10:01:06price for the items um
- 10:01:10and yeah it should not be total price it
- 10:01:13should be number of items let me finish
- 10:01:14this and I will fix that so then we're
- 10:01:17going to have second table here uh where
- 10:01:20we're going to display the all the uh
- 10:01:23all the items basically okay so here
- 10:01:25we're going to iterate over order
- 10:01:28items and for each order item we're
- 10:01:31going to display something similar so
- 10:01:33image and product title we're going to
- 10:01:35display the order item quantity and
- 10:01:38order item price finally we're going to
- 10:01:40have buttom to view that specific order
- 10:01:43details everything happens inside the
- 10:01:45order Loop so everything is inside a
- 10:01:48single order uh item so view order
- 10:01:51details and after the forage loop we're
- 10:01:53going to have this sub copy which is a
- 10:01:55different type of text and we have this
- 10:01:58panel as
- 10:02:00well okay and finally thanks uh which is
- 10:02:03going to be our application name Lara
- 10:02:05store team or whatever so now let me fix
- 10:02:10this what I said the items is going to
- 10:02:13be order
- 10:02:15items uh order
- 10:02:18items size or count I think it's called
- 10:02:21count and okay that's good now what I
- 10:02:26want to do is to change the Styles
- 10:02:29couple of styling so I'm going to go
- 10:02:32into default CSS and first I want to
- 10:02:35find logo and I want to remove this Max
- 10:02:40he and width from here
- 10:02:43okay also I want to find table here and
- 10:02:48remove this margin buttom completely and
- 10:02:52I want to change the uh text align on
- 10:02:55the th text align to be left on the th
- 10:03:01but more importantly I want to change
- 10:03:04styles on the primary button so I'm
- 10:03:06going to introduce a new new color 6 9
- 10:03:1136 and
- 10:03:14F5 so I want to put this color right
- 10:03:18here uh um okay let me open
- 10:03:23this header as
- 10:03:26well here we have the word
- 10:03:32laravel now let me open this
- 10:03:35message and right here we have the
- 10:03:37following header and if the uh header
- 10:03:40name equals to LEL then it uses the L of
- 10:03:44a logo right here so first I'm going to
- 10:03:46change my application name into Lara
- 10:03:52store so then if I open the message and
- 10:03:55we are using this message in every
- 10:03:58hour our blade file right here so then
- 10:04:02right here I'm going to change this
- 10:04:03header and inside the header I'm going
- 10:04:07to provide we have this application URL
- 10:04:09that's fine I'm going to remove this and
- 10:04:12use image here and I'm going to provide
- 10:04:15my own image and I actually have logo
- 10:04:18for my website
- 10:04:20so let me quickly show this to you so
- 10:04:23this is my lar store branding and I'm
- 10:04:26going to use the following
- 10:04:30image white background or actually we
- 10:04:33need maybe this
- 10:04:38one yeah I think we can get this
- 10:04:45one okay uh let me copy this and insert
- 10:04:50side
- 10:04:52public let me
- 10:04:54create image and paste that Lara sto
- 10:04:59Lara store Blue here so now we can
- 10:05:04provide here
- 10:05:06asset to be from image folder lore blue
- 10:05:11PNG okay we can provide alt as well to
- 10:05:14be whatever like
- 10:05:17config um app do
- 10:05:20name uh
- 10:05:25logo okay so this is great so we changed
- 10:05:29this primary button color and I want to
- 10:05:33set the same color inside Tailwind
- 10:05:35config
- 10:05:37JS you can find this also in the day UI
- 10:05:40documentation how to do this but here
- 10:05:42I'm overriding this Daisy UI
- 10:05:44configuration option providing themes to
- 10:05:46be an array and I'm overriding the
- 10:05:48default light theme uh requiring
- 10:05:51everything existing all existing options
- 10:05:55from this stui Source theming themes for
- 10:05:57the light theme but I'm overriding the
- 10:06:00primary color which basically means that
- 10:06:05my uh the primary color of the button
- 10:06:08will be changed as well so primary color
- 10:06:11everywhere uh right now we just change
- 10:06:15it okay awesome um I think we can
- 10:06:20try we can try email sending can't we so
- 10:06:24I think we have to authenticate first
- 10:06:27let's authenticate with user
- 10:06:31two let's add this into the cart and
- 10:06:34this one as well let's click on this we
- 10:06:37see
- 10:06:39uh let's increase the quantity here and
- 10:06:47here one thing I know noticed is that if
- 10:06:50we open this Details page so we see
- 10:06:52right here um different variations but
- 10:06:56in the card we see we should not see
- 10:06:59this image we should see something else
- 10:07:01and we're going to fix this as well
- 10:07:02click proceed to check
- 10:07:05out let's enter the order
- 10:07:17details let's open work hook
- 10:07:21okay it lookss like it was
- 10:07:25completed uh okay we have some error
- 10:07:27about email
- 10:07:30sending let's
- 10:07:32open ll.
- 10:07:35log one of the web hook actually was
- 10:07:38completed with
- 10:07:41um with the following message which
- 10:07:43means that something was
- 10:07:47wrong let's have a look up services DB
- 10:07:50not
- 10:07:53found okay where do we have this
- 10:07:56DB this is let's open web
- 10:08:02Hook app Services
- 10:08:12DB let's see where this is coming
- 10:08:17from card service to 200 okay art
- 10:08:24Service
- 10:08:28200 that was fixed no this is not it
- 10:08:31that's something else that is old
- 10:08:33message this is old message we're going
- 10:08:35to have new one let's check the last
- 10:08:39one invalid argument exception no hint
- 10:08:44path defined for mail okay I see that
- 10:08:51uh yeah I know the reason so we actually
- 10:08:53using markdown syntax so we have to
- 10:08:56provide right here markdown as well so
- 10:08:59let's
- 10:09:00open check out completed as well and I'm
- 10:09:04going to change these into
- 10:09:12markdown let
- 10:09:13[Music]
- 10:09:16me we're going to do this one once again
- 10:09:20so let's click set to cart both of them
- 10:09:24view card proceed to check
- 10:09:37out let's open web
- 10:09:41hooks it looks like everything
- 10:09:46worked what about emails
- 10:09:50let's
- 10:09:51open Local Host
- 10:09:55825 okay we have three new emails that's
- 10:09:58so awesome so this goes
- 10:10:02to this goes to vendor
- 10:10:072
- 10:10:10okay it is the ugliest possible email we
- 10:10:14could ever have right
- 10:10:20that happens because of the
- 10:10:22formatting so this x component we we
- 10:10:25shouldn't have it like this let
- 10:10:28me format this so we should we when
- 10:10:32using markdown Syntax for sending emails
- 10:10:36you shouldn't have it formatted like
- 10:10:37this so you basically should disable
- 10:10:40autof formatting in your IDE because it
- 10:10:43ruins everything I think this is going
- 10:10:45to work nicely so we can see this check
- 10:10:48out
- 10:10:50completed as
- 10:10:55well
- 10:10:57okay also to my image to my logo image
- 10:11:02I'm going to give it class logo because
- 10:11:04we have that logo defined
- 10:11:06here and it should take the proper
- 10:11:08classes now I'm going to try to make new
- 10:11:12order okay I received new emails
- 10:11:14congratulations we have new order we
- 10:11:16have this nice logo we have the button
- 10:11:18now it looks like more or less okay
- 10:11:21actually I actually like this so we have
- 10:11:23this order summary information here
- 10:11:25everything uh the prices are actually
- 10:11:28break down so uh my earnings is 13.05
- 10:11:33this is the platform fee this is the
- 10:11:35payment processing fee IND the item this
- 10:11:37is emailed to the second vendor I see
- 10:11:40also prices break down here and the
- 10:11:43email to the buyer is actually still
- 10:11:47messed up which I'm going to fix
- 10:11:51so I'm going to format these tables like
- 10:11:58this now I made one more order in this
- 10:12:01case I received the correct information
- 10:12:03payment was completed successfully
- 10:12:05seller information order number items
- 10:12:07total we see the item view order details
- 10:12:10and for the second vendor seller is
- 10:12:12Zoomer now we have different information
- 10:12:15here a VI order details this is up copy
- 10:12:18and this is panel so this is just I put
- 10:12:21this for you if you want to provide
- 10:12:23additional information you can easily do
- 10:12:25that and I think this looks really nice
- 10:12:29and when we Implement actually order
- 10:12:31Details page we will be able to link
- 10:12:33these orders to the proper pages
- 10:12:38and yeah that's
- 10:12:41great also I just try to create new
- 10:12:44account and because we globally changed
- 10:12:46the message and the button we right now
- 10:12:49now see not lot of a logo but this is
- 10:12:51our logo and we see this verify email
- 10:12:53address um button stying different as
- 10:12:57well so it's pretty nice so it's a
- 10:12:59customized uh to our
- 10:13:02application and we also see right here
- 10:13:04our application name now I want to start
- 10:13:07working on vendor Details page vendor
- 10:13:09profile page so when we click profile
- 10:13:12right here we see only the profile
- 10:13:14information generic profile information
- 10:13:16but I want to add right here on the
- 10:13:18right side vendor details such as the
- 10:13:21vendor store name vendor address and if
- 10:13:24you are a regular user and want to
- 10:13:26become a vendor as well right here
- 10:13:28you're going to have a button become a
- 10:13:30vendor and once you are a vendor then
- 10:13:33you can connect to stripe account using
- 10:13:37stripe connect and the marketpl you will
- 10:13:40be connected into Marketplace basically
- 10:13:42and then you will be able to uh do these
- 10:13:46purchases or selling your products
- 10:13:49okay and I'm going to also implement the
- 10:13:51vendor profile page which basically
- 10:13:53means a separate URL for you uh where
- 10:13:58you have the store name in the URL and
- 10:14:00you can copy and send this to anybody
- 10:14:04else uh which will have a list of your
- 10:14:07products only and nothing else okay so
- 10:14:10we're going to start with the back
- 10:14:11inside and I'm going to create a new
- 10:14:13controller if I don't have it vendor
- 10:14:16controller is something we don't have so
- 10:14:18let's execute pH P artisan
- 10:14:22make
- 10:14:24controller
- 10:14:25vendor
- 10:14:27controller we hit the enter okay vendor
- 10:14:30controller was created now let's open
- 10:14:33vendor controller and I'm going to
- 10:14:35Define two methods right here one is
- 10:14:38going to be profile where we accept the
- 10:14:41vendor details right here let's import
- 10:14:44this
- 10:14:44vendor and second is going to be store
- 10:14:49where we're going to store our details
- 10:14:51let's accept request right here I'm
- 10:14:54going to also open vendor and I'm going
- 10:14:56to change few things first I'm going to
- 10:14:58add that the primary key of the Vendor
- 10:15:00model is user ID not the ID which is the
- 10:15:03default one we're going to also add a
- 10:15:05scope right here which is going to
- 10:15:07whether this specific vendor is eligible
- 10:15:10for payout or not okay so eligible for
- 10:15:14payout um and uh here we simply return
- 10:15:18this status of the vendor needs to be uh
- 10:15:21approved and next we're going to define
- 10:15:23the relation into the user and now let's
- 10:15:26import these things so we're going to
- 10:15:27import the belongs to we're going to
- 10:15:29import the vendor status enam and
- 10:15:31Builder as
- 10:15:33well okay cool now on the front end side
- 10:15:37into Pages profile we have this edit and
- 10:15:43inside um maybe inside
- 10:15:47arals I'm going to create new component
- 10:15:51let's call
- 10:15:52this vendor details and this needs to be
- 10:15:57jsx
- 10:16:01file okay before I implement this vendor
- 10:16:05details I want to install new package
- 10:16:08which is going to be necessary for
- 10:16:09stripe connect stripe
- 10:16:13connect LEL if we search for this we are
- 10:16:17going to find a
- 10:16:23package uh it doesn't find so let's
- 10:16:25search for lotel stripe connect I went
- 10:16:29to GitHub
- 10:16:32URL the username is uh Simon Simon um
- 10:16:39hemp I
- 10:16:41think if we search for this that's it
- 10:16:44that's what I used and it is working
- 10:16:51okay yeah this is it so let me actually
- 10:16:54copy this so we're going to install this
- 10:16:56package I'm going to bring up the
- 10:16:58terminal and let's
- 10:17:00execute composer require and then you
- 10:17:03have a look so we're going to set up the
- 10:17:05stripe key which is going to be our
- 10:17:08publishable key we already have secret
- 10:17:11stripe secret and then we're going to
- 10:17:13execute migrate so let's use this stripe
- 10:17:17key which we're going to get from from
- 10:17:19our
- 10:17:21homepage this is the publishable key
- 10:17:24let's open
- 10:17:27do and we're going to provide here
- 10:17:32stripe key equals this now let's open.
- 10:17:37example as well and put them right
- 10:17:45here next we're going to execute this
- 10:17:47mic rate
- 10:17:49once the package is installed only after
- 10:17:51this so we open the package is installed
- 10:17:54now let's execute PHP Artis and migrate
- 10:17:56so the migration has been applied and it
- 10:17:58added stripe connect details to users
- 10:18:00table now if we refresh the database and
- 10:18:03open users table we're going to see two
- 10:18:05new columns stripe account ID and stripe
- 10:18:09account active Okay so after this
- 10:18:13basically we have to use payable on the
- 10:18:16model so we're going to use
- 10:18:19that
- 10:18:22trade payable and we will be able to
- 10:18:26send uh on our user we can transfer
- 10:18:29something from our account from the
- 10:18:31platform uh application account we will
- 10:18:34be able to transfer
- 10:18:35something uh to that user or from from
- 10:18:38one user we will be able to transfer
- 10:18:41into um somebody else so here we need
- 10:18:44this connect so I'm going to copy this
- 10:18:46part uh actually let's open stripe
- 10:18:50controller and Define this connect
- 10:18:52function and we're going to check if the
- 10:18:54user uh get stripe account ID doesn't
- 10:18:58exist then we are going to create stripe
- 10:19:01account
- 10:19:02ID and then if the user is not active
- 10:19:06then we're going to redirect user into
- 10:19:09the strap account link page and the user
- 10:19:12will start the
- 10:19:14onboarding um procedure to get get
- 10:19:17connected to our plat form interface and
- 10:19:20once this is done we're going to
- 10:19:22redirect back with if this doesn't
- 10:19:25happen basically your account is already
- 10:19:27connected now I'm going to open rules
- 10:19:30page and we're going to Define this URL
- 10:19:33stripe connect on the connect method and
- 10:19:36we're going to provide the stripe
- 10:19:38connect name as well and I'm going to
- 10:19:40add a middle we that this is only for
- 10:19:42vendor users R needs to be vendor it is
- 10:19:45not for somebody else and right here we
- 10:19:49have the stripe connect and we are
- 10:19:50listening into post I want to make one
- 10:19:53changes inside put strap up PHP so I
- 10:19:57disabled csrf validation on every route
- 10:20:00starting with stripe slash which is not
- 10:20:03exactly ideal because here we also have
- 10:20:06stripe slash something so I'm going to
- 10:20:09change this into web hook directly
- 10:20:12stripe web hook for stripe web hook
- 10:20:14which is for our web hook where stripe
- 10:20:16will send us the data that's the only
- 10:20:19place where we disable the csrf token
- 10:20:22validation okay so we
- 10:20:25have we have done the bacon side I think
- 10:20:29correctly uh let me show you something
- 10:20:33so if we just try to access stripe slash
- 10:20:38connect uh this will not work because
- 10:20:42the method yeah this method supports
- 10:20:43only Post Yeah we have to submit
- 10:20:45something on that we're going to do this
- 10:20:48um but before I do this I'm going to
- 10:20:50create one uh resource and this going to
- 10:20:54be for the authenticated user details
- 10:20:57like inside this handling njs request we
- 10:21:00return this user information but I want
- 10:21:02actually to change that returned user
- 10:21:05information and um pass this into
- 10:21:08resource because we return a lot of
- 10:21:10information which is something I don't
- 10:21:13want and I also want to return a couple
- 10:21:15of other
- 10:21:16things uh okay so let let me execute PHP
- 10:21:19artisan
- 10:21:21make resource let's call this out
- 10:21:27user resource out user resource awesome
- 10:21:31now let's open out user
- 10:21:35resource and I'm going to adjust
- 10:21:41this we need ID of the user we need
- 10:21:44email email verify date we need the name
- 10:21:47and here I'm going to return return
- 10:21:48actually
- 10:21:49permissions so if you pay attention
- 10:21:51we're going to see that so we added
- 10:21:56permissions and roles on the user and if
- 10:21:58we open user model we see that this has
- 10:22:00roles and it has permissions as well so
- 10:22:03far on the front end side on the react
- 10:22:05side we have not used that permissions
- 10:22:07and roles to hide or show something we
- 10:22:09will need this to do it so that's why we
- 10:22:12are adding permissions right here and
- 10:22:15I'm mapping this e permissions object
- 10:22:17into uh just permission name
- 10:22:20additionally we need the role names as
- 10:22:22well but we need the vendor details and
- 10:22:25we need the stripe account active as
- 10:22:27well and the vendor details so stripe
- 10:22:29account active is going to be the
- 10:22:31Boolean of stripe account active from
- 10:22:33the user table what was just added if
- 10:22:36the vendor doesn't exist we return null
- 10:22:38if the vendor exists we're going to
- 10:22:40return the status of the vendor a vendor
- 10:22:43the status label itself which we're
- 10:22:45going to get this from vendor status and
- 10:22:49let's actually open vendor status NM and
- 10:22:52I'm going to Define two methods right
- 10:22:53here first is going to be labels and
- 10:22:56we're going to associate uh each enm
- 10:23:00case into its label like this and I'm
- 10:23:03going to also Define colors because I
- 10:23:05will need these in the filament admin to
- 10:23:08display all vendors for admin users so
- 10:23:12gray success and danger for different
- 10:23:15states cool now here let's continue and
- 10:23:20we um we need store name to return in
- 10:23:23this out user resource if the vendor
- 10:23:25exists uh we need store address and
- 10:23:29cover image uh and finally we're going
- 10:23:32to import this vendor status inm right
- 10:23:34here now let's go into handle inertia
- 10:23:37request and we're going to check if the
- 10:23:39user exists we are going to return new
- 10:23:43out user out user resource providing
- 10:23:48request user otherwise we're going to
- 10:23:50return null and let's disable
- 10:23:54wrap
- 10:23:58here okay so now we are returning this
- 10:24:00out user resource we have implemented
- 10:24:03the backend side fully ready and I'm
- 10:24:05going to open vendor details and I'm
- 10:24:08going to define the component so first
- 10:24:10let's import a couple of components we
- 10:24:11will need in the spender details we need
- 10:24:14primary button use form use page from
- 10:24:16inertia JS react and we need um
- 10:24:20following things we need secondary
- 10:24:21button we need model we need input label
- 10:24:24and text input uh input ER and I think
- 10:24:27that's it then we're going to Define
- 10:24:29vendor
- 10:24:30details and we're going to accept a
- 10:24:32class name optionally class name and now
- 10:24:35let's define the states so we are going
- 10:24:37to have the following states to show the
- 10:24:40confirmation dialogue to whether the
- 10:24:43current user wants to become a vendor or
- 10:24:45not so we want to display that button
- 10:24:48become a vendor clicking on which will
- 10:24:50trigger the confirmation dialogue and
- 10:24:53we're going to save that it's a Boolean
- 10:24:55thing so we have this access message as
- 10:24:58well which by default empty string we're
- 10:25:00going to get the user information we're
- 10:25:02going to get the csrf token as well
- 10:25:05right here we will need that and then
- 10:25:07we're going to define the form using
- 10:25:09this use form um injs user form hook so
- 10:25:14we're going to take the data set data
- 10:25:16errors post processing in recently
- 10:25:18sucessful from this use form and we're
- 10:25:21going to provide the um store name to be
- 10:25:24user vendor store name or the username
- 10:25:29and let's also open types and Define
- 10:25:32right here stripe account active buan
- 10:25:34vendor
- 10:25:36status um status label store name store
- 10:25:40address and cover image now the ER is
- 10:25:44gone right here next we're going to
- 10:25:46define the store address if the vent
- 10:25:48exists so we use this question mark for
- 10:25:51that store address then we're going to
- 10:25:53listen to store name change okay and
- 10:25:57this is going to be on input HTML input
- 10:25:59elements whenever this happens we are
- 10:26:01going to put that inside store name
- 10:26:04right here however I'm going to convert
- 10:26:07this into lowercase and I'm going to
- 10:26:09also generate slug out of it so it's
- 10:26:11going to be replace all the wi spaces
- 10:26:14using regx with dashes convert
- 10:26:17everything to lower case replace wi
- 10:26:19spaces into dashes okay cool next I'm
- 10:26:22going to create new form event handler
- 10:26:24to become a vendor so we prevent the
- 10:26:27default on submission and then we send
- 10:26:29the request on vendor. store which we're
- 10:26:31going to
- 10:26:33Define okay and on success we're going
- 10:26:36to close the confirmation model because
- 10:26:38that will be only triggered on the
- 10:26:40vendor uh the confirmation model so we
- 10:26:43close the model we we will create this
- 10:26:45close model um in a moment and then uh
- 10:26:49we display this success message you can
- 10:26:52uh now create and publish products so we
- 10:26:55we can optionally handle this on ER as
- 10:26:57well print something or do something I
- 10:26:59just wanted to give that information to
- 10:27:01you so then I'm going to also listen to
- 10:27:03update vendor information to update the
- 10:27:06store name or the store address things
- 10:27:08like that so I'm going to send the
- 10:27:10request into vendor store again and on
- 10:27:13success uh again we have to close the
- 10:27:16model and show some details the um your
- 10:27:20details were updated okay now let's uh
- 10:27:25create this close model which will set
- 10:27:27this show become vendor confirmation
- 10:27:30into false and now we can focus on the
- 10:27:33template itself so we have the following
- 10:27:35section uh and if recently successful is
- 10:27:39true we're going to display the
- 10:27:40following toast with the success uh
- 10:27:44message okay then we have the header
- 10:27:47with the vendor d details at the top
- 10:27:49we're going to have we're going to see
- 10:27:51what's the vendor status if the vendor
- 10:27:53status is pending then we're going to
- 10:27:55display the following BGE with warning
- 10:27:59uh and we're going to use this status
- 10:28:00label which we return from this out user
- 10:28:05resource from from here okay so if the
- 10:28:10vendor status is rejected we're going to
- 10:28:12display um error page if it's approved
- 10:28:15we're going to display success page
- 10:28:17below this header we're going to have
- 10:28:18we're going to check the user vendor
- 10:28:20details if the vendor doesn't exist we
- 10:28:22are going to create this primary button
- 10:28:24become a vendor we're going to listen in
- 10:28:27on click and we're going to trigger that
- 10:28:30model show set show become vendor
- 10:28:33confirmation and this will show the
- 10:28:35model okay so however if the vendor
- 10:28:38exists then we have to do a lot more so
- 10:28:41we have to create the form to update the
- 10:28:43vendor inside which we're going to put
- 10:28:45this input label store name then the ual
- 10:28:48input which is which's going to have the
- 10:28:50value onchange required this Focus all
- 10:28:52these things so we're going to also have
- 10:28:55this input error which looks at this
- 10:28:57error's store name we're going to create
- 10:29:00second input for store address which is
- 10:29:02going to be text area we are listening
- 10:29:04on change and setting inside store
- 10:29:06address we're going to have also the
- 10:29:09input error down below and then we're
- 10:29:11going to have the primary button which
- 10:29:13will trigger the form submission the
- 10:29:14button is disabled if the form is in
- 10:29:16processing stage
- 10:29:19but below this form we have another form
- 10:29:21and this is going to be stripe connect
- 10:29:23form so if the user is vendor we show
- 10:29:28the vendor update form but we also show
- 10:29:31stripe connect form okay so inside this
- 10:29:34stripe connect we are using the csrf
- 10:29:38token here method is post obviously and
- 10:29:42we now check if stripe account is
- 10:29:46active okay then if it's already active
- 10:29:50then we display the following message
- 10:29:51you are successfully connected to
- 10:29:53stripe however if the stripe is not
- 10:29:57active so then we have um sorry uh we
- 10:30:02display the button in any case but the
- 10:30:05button is disabled if stripe account is
- 10:30:07active so they connect to stripe button
- 10:30:10so we still want the user to see
- 10:30:12connector stripe but if it's uh already
- 10:30:15active then we're going to show it as
- 10:30:16disabled okay and then down below we're
- 10:30:19going to display this model show
- 10:30:20confirmation vendor on close we're going
- 10:30:22to call this uh close model we're going
- 10:30:25to have this another forming side which
- 10:30:28will um which will call this become
- 10:30:32vendor on submission and we're going to
- 10:30:34have this confirmation message are ISU
- 10:30:36to become a vendor then we're going to
- 10:30:38have this cancel button and primary
- 10:30:40button which will trigger the form
- 10:30:42submission
- 10:30:45okay uh okay so we have that V
- 10:30:48details kind of
- 10:30:50ready uh however it's my B so these
- 10:30:55components are actually inside core
- 10:30:59folder so we want to get this from core
- 10:31:03so I copied this from another project
- 10:31:06that's why we we didn't have it in core
- 10:31:09so okay this is great we need it like
- 10:31:11this uh now we're going to open
- 10:31:14edit edit TS6 in here we have
- 10:31:19this one
- 10:31:22div uh another
- 10:31:25div cool we have this MX Auto
- 10:31:30here I'm going to remove a few things
- 10:31:33I'm going to remove them uh I'm going to
- 10:31:36also reduce the pading way here but I'm
- 10:31:39going to give it greed so I want grid
- 10:31:42layout grid calls one and above medium
- 10:31:47we need grid calls three let's give it
- 10:31:50also G four and padding four now I want
- 10:31:55to have something like this so
- 10:31:58everything what we have so far will be
- 10:32:01in the first div
- 10:32:05here and we can give this
- 10:32:08one um space y six and call span two
- 10:32:17however we want one second div as well
- 10:32:20which will
- 10:32:21have background
- 10:32:23white uh padding for let's give it
- 10:32:26Shadow as well above small we need
- 10:32:29rounded
- 10:32:31LG uh and let's give it above small uh
- 10:32:35pading eight and on dark mode we can
- 10:32:39give it also BG
- 10:32:41gray 800 so inside this div we are going
- 10:32:45to put this vendor detail tells what we
- 10:32:48just created so let me save this and if
- 10:32:51we didn't have any errors we're going to
- 10:32:53see what we see right now vendor details
- 10:32:57right
- 10:32:58here um of course the layout is not
- 10:33:13identical why it is not
- 10:33:16identical I I am not quite
- 10:33:19sure yeah it is good yeah okay so we
- 10:33:23have the vendor details and when we
- 10:33:24click on this become vendor it is going
- 10:33:26to bring up this um confirmation are you
- 10:33:28sure you want to become a vendor of
- 10:33:30course cancel Works click on confirm
- 10:33:33which send some requests but we don't
- 10:33:36have the backend ready I guess so we're
- 10:33:39going to open vendor
- 10:33:42controller and we have to implement
- 10:33:44these
- 10:33:46methods I'm going to implement store
- 10:33:48first and we're going to validate the
- 10:33:50request and the store name needs to be
- 10:33:52required and it must be reex uh with
- 10:33:56only the following Fields so uh
- 10:33:58lowercase from A to Z then only digits
- 10:34:02and dashes nothing else is actually
- 10:34:03allowed and the store name needs to be
- 10:34:05also unique among vendors store name I'm
- 10:34:08going to add store address as well which
- 10:34:11can be n actually and I'm going to also
- 10:34:13customize the message for this store
- 10:34:16name reex so I'm just going to give it
- 10:34:18text store name must only contain
- 10:34:20lowercase alpha numeric characters and
- 10:34:22dashes so if the validation happens we
- 10:34:25know that the everything is good now
- 10:34:27we're going to get the user information
- 10:34:29and we're going to access the vendor as
- 10:34:31well so if the vendor exists we're going
- 10:34:33to take the vendor if the vendor doesn't
- 10:34:35exist we are creating new vendor this is
- 10:34:38kind of create vendor or update vendor
- 10:34:41method it does both so then once we have
- 10:34:44the vendor we're going to provide the
- 10:34:46user ID if it's if we are creating then
- 10:34:48we need this if we are updating then we
- 10:34:51are simply assigning the same user ID it
- 10:34:53doesn't hurt so here we're going to
- 10:34:55assign the vendor status inm to be
- 10:34:57approved and we are going to provide the
- 10:35:00store name from the request store name
- 10:35:03and we're going to provide the store
- 10:35:04address and we're going to save the
- 10:35:06vendor information and we're going to
- 10:35:08give that user also vendor role so at
- 10:35:12the moment we don't uh we have Auto
- 10:35:15approval of vendors so so every time
- 10:35:18vendor is created vendor is approved but
- 10:35:20of course this can be changed and um
- 10:35:22every new vendor can be manual uh it can
- 10:35:26have status pending which would would
- 10:35:28require approval from admin this can be
- 10:35:30easily changed you can do this I will
- 10:35:32probably do this in the future um on
- 10:35:35this project as well not probably for
- 10:35:38sure okay so now we have uh we have that
- 10:35:42method actually ready so now let me try
- 10:35:46to click on confirm
- 10:35:50again uh okay let's refresh it I think
- 10:35:54vendor tore yeah we don't have this
- 10:35:56method vendor
- 10:35:59store let's open web.php
- 10:36:02and user needs to be authenticated and
- 10:36:05verified to be able
- 10:36:08to uh send that
- 10:36:11request let's
- 10:36:14create right here so wrote
- 10:36:19post um we can call this
- 10:36:23become
- 10:36:26a
- 10:36:28vendor then we use vendor controller
- 10:36:32store here and we are going to
- 10:36:36provide name to be vendor store now let
- 10:36:40me refresh the
- 10:36:43page click on this and click on confirm
- 10:36:48thanks for signing up before getting
- 10:36:50started could you verify your email
- 10:36:52address by clicking on the link we just
- 10:36:54emailed to you okay
- 10:36:57so it looks like I am unverified user so
- 10:37:00I have to resend verification
- 10:37:05email I received that this is the new
- 10:37:07user user
- 10:37:09three uh click verify email
- 10:37:13address we did the verification
- 10:37:17now we can access into my profile
- 10:37:23page become a vendor click on
- 10:37:26confirm
- 10:37:28and that's it seems like that
- 10:37:31worked if we refresh the page what do we
- 10:37:35see we still see become a vendor now I'm
- 10:37:38curious what happens is the vendor
- 10:37:40created or not let's have a
- 10:37:44look okay no new vendor is created
- 10:37:47probably
- 10:37:49because
- 10:37:51um it wasn't
- 10:37:55saved it should be saved
- 10:38:01right okay let's see let's dump the
- 10:38:04vendor and have a look we have to debug
- 10:38:07things when it's not
- 10:38:14working become a vendor
- 10:38:21post okay why does not come here
- 10:38:25probably validation is
- 10:38:29failed yeah definitely validation is
- 10:38:32failed when we try to okay now makes
- 10:38:36sense um this is more like for updates
- 10:38:39so when we try to become a
- 10:38:43vendor we don't provide this tour name
- 10:38:46right and we don't provide the
- 10:38:49address
- 10:38:52details
- 10:38:54uh right here we have this sors in the
- 10:38:57Red Direct store name store name must
- 10:38:59only contain uh lowercase alphanim
- 10:39:02characters and dashes and this is
- 10:39:05because when become a vendor we provide
- 10:39:08the store name to be user space three
- 10:39:12and I know how to fix this if we go in
- 10:39:15the vendor details right right here we
- 10:39:18provide if the store name if the vendor
- 10:39:20doesn't exist or the store name doesn't
- 10:39:22exist we're going to provide the
- 10:39:23user.name so let's convert this into
- 10:39:27lowercase and then I'm going to call
- 10:39:29replace on this with every white space
- 10:39:34globally to be replaced with dashes so
- 10:39:37if I refresh this right
- 10:39:40now and try to become a vendor now it
- 10:39:43should
- 10:39:44work at least we got uh on the the back
- 10:39:47side because we provided right now the
- 10:39:50following store
- 10:39:53name okay so what is this up enum okay
- 10:39:56we don't have that
- 10:39:58label let's open vendor status
- 10:40:03enam and I'm going to add one more
- 10:40:05method right here which is going to be a
- 10:40:07label and it's going to return string
- 10:40:11matching with a
- 10:40:13case now I think we are already
- 10:40:19vendor as you see so vendor details is
- 10:40:22approved we see the store name we see uh
- 10:40:24the address details and we see this
- 10:40:26update test click on update store name
- 10:40:30has already been taken on the
- 10:40:34update we have to exclude
- 10:40:38ourself so let me actually get this user
- 10:40:41before the validation and I'm going to
- 10:40:43now change this into using
- 10:40:48uh rule unique so let me change
- 10:40:52that
- 10:40:54rule that was different rule probably
- 10:40:57rule that needs to be illuminate
- 10:41:00validation rule we need unique vendor
- 10:41:02tore name and we need to provide um
- 10:41:08ignore here
- 10:41:10ignore user ID user ID is the primary
- 10:41:15key of the vendor table
- 10:41:18um that should
- 10:41:20work now click on
- 10:41:23update and let's refresh the page I
- 10:41:26think the error stayed
- 10:41:29there test click on update store name
- 10:41:32has already been
- 10:41:36taken from the vendor store name we are
- 10:41:40using user ID which is the primary key
- 10:41:45of
- 10:41:48model
- 10:41:56right uh that ignor actually doesn't
- 10:41:58look at the Vendor model so we have to
- 10:42:01provide user ID right here as a second
- 10:42:03argument where it needs to check that ID
- 10:42:07now if we open the
- 10:42:09browser and we're going to
- 10:42:12provide something and click on update
- 10:42:14now this
- 10:42:15works uh
- 10:42:20cool okay now let's try to connect to
- 10:42:23stripe so I'm going to click on this
- 10:42:25connect to stripe and let's see what
- 10:42:27happens you can only create new accounts
- 10:42:30if you have signed up for connect okay
- 10:42:32so this is the thing so first we have to
- 10:42:35uh set up the connect in our stripe
- 10:42:39dashboard okay so let me actually open
- 10:42:43the stripe dashboard and click on
- 10:42:45connect and we have to follow this and
- 10:42:49feel some information so on our
- 10:42:53platform stripe dashboard we have to set
- 10:42:56up the connect power your platform with
- 10:42:58connect click get started I'm going to
- 10:43:00click on continue right here it asks me
- 10:43:03a few questions how I want the flow uh
- 10:43:06to be implemented so there are three
- 10:43:08options two options right here seller
- 10:43:10will collect payments directly and buyer
- 10:43:13will purchase from you and each of them
- 10:43:16has its own options like buyer will
- 10:43:18purchase goods and services directly
- 10:43:20from sellers buyers will be anywhere of
- 10:43:23your platform sellers will appear on
- 10:43:25receipts sellers will be responsible for
- 10:43:28refunds and disputes um and so on so you
- 10:43:33have to read this and decide which
- 10:43:36option you
- 10:43:37want so in my case this is what I want
- 10:43:40to where I want to go uh I will receive
- 10:43:43all the purchases and then I will pay
- 10:43:46out to the sellers once in a while so
- 10:43:49I'm going to click on continue here I'm
- 10:43:51going to click on review so you you make
- 10:43:54sure you read this carefully I have
- 10:43:56actually read this and accepted this
- 10:43:58while I Was preparing and then click on
- 10:44:01continue okay I'm going to choose the
- 10:44:03second option here click on continue
- 10:44:06then here I'm going to choose e-commerce
- 10:44:08products click on continue yes they are
- 10:44:11similar not sure so I want on boarding
- 10:44:14hosted by stripe which is the easiest
- 10:44:16one click on continue the first one
- 10:44:19Express dashboard and then this is our
- 10:44:21summary I'm going to click on
- 10:44:23continue and now it is going to set up
- 10:44:27the connect for us okay so right now we
- 10:44:30are not in the test mode and if we are
- 10:44:33not in the test mode we have to go
- 10:44:35through all these test uh the all these
- 10:44:38steps and activate our account and so on
- 10:44:41but I actually want this only in the
- 10:44:43test mode okay I'm not going to activate
- 10:44:46this for the tutorial but of course if
- 10:44:48you are building something on production
- 10:44:51you have to go these tabs add your
- 10:44:53branding access your integration guide
- 10:44:55try out your integration so you're going
- 10:44:57to do all these things and activate your
- 10:44:59account okay but now I have actually
- 10:45:03connected connection already um set up
- 10:45:06the stripe connect is already set up and
- 10:45:08inside connected accounts I don't have
- 10:45:10any accounts at the moment and this is
- 10:45:12what I'm going to do let's go
- 10:45:15back and I'm going to click on this
- 10:45:18connect to stripe okay so now the seller
- 10:45:21onboarding this is the seller onboarding
- 10:45:24screen okay and uh the email is not
- 10:45:27needed in the test mode however we have
- 10:45:29to provide our actual phone number right
- 10:45:32here even though we are in the test mode
- 10:45:34let me pause the recording I don't want
- 10:45:36to reveal my phone
- 10:45:38number okay I entered my phone number it
- 10:45:41send sent me to factor authentication
- 10:45:43code then I entered this and this is the
- 10:45:45next step you have to choose the country
- 10:45:47I'm going to leave this into United
- 10:45:49States click on continue we have to
- 10:45:52enter our legal name so I'm just going
- 10:45:54to type user user we are testing this
- 10:45:57and we have to enter some domain as well
- 10:46:00my domain
- 10:46:02one.com so here we have to select an
- 10:46:04account for the payout and in this case
- 10:46:07I'm just going to write test institution
- 10:46:10which will bring up the following model
- 10:46:11I have to agree and continue connect
- 10:46:14accounts and to save account with with
- 10:46:17the link I'm just going to click not now
- 10:46:19accounts have been connected I see these
- 10:46:21accounts here click on continue and this
- 10:46:24gives me an information uh which I can
- 10:46:26review and change you know what I'm
- 10:46:28going to CH just change my domain into
- 10:46:30my domain three because this is the user
- 10:46:33three so let's give it my domain three
- 10:46:35so that I can easily um associate if I
- 10:46:39need to so agree and submit now this
- 10:46:43redirects us back into our website and
- 10:46:47it will set up the connection fully so
- 10:46:51let's have a look now in the database in
- 10:46:53the users
- 10:46:55table we have that user three which has
- 10:46:59stripe account ID here and the account
- 10:47:02is also active is one here if we check
- 10:47:05right now profile page we're going to
- 10:47:07see you are successfully connected to
- 10:47:09stripe if we check out our page I think
- 10:47:12we will be logged out because we set up
- 10:47:14this uh we started this onboarding flow
- 10:47:17and it actually logged us out um because
- 10:47:21of that now look at this look at this so
- 10:47:25we have one connected account and this
- 10:47:28is the exact same account what we see in
- 10:47:31the database so user three is now
- 10:47:34connected into our platform and this is
- 10:47:37just awesome so I think we are going to
- 10:47:39I'm going to do this for another user
- 10:47:42because I need at least two vendors let
- 10:47:45me authenticate
- 10:47:47with a
- 10:47:48vendor maybe let's authenticate with
- 10:47:50vendor to let's go
- 10:47:54into profile page so this is the store
- 10:47:57name we have to change this into
- 10:48:00lowercase actually if you even start
- 10:48:02typing in the uppercase and even if you
- 10:48:05start typing spaces I'm hitting spaces
- 10:48:08right now it's going to generate dishes
- 10:48:10so this
- 10:48:12is my store name uh let's click on
- 10:48:15update yeah this this is not even
- 10:48:17verified so we have to verify vendor 2
- 10:48:21as well it got verified let's access to
- 10:48:28profile
- 10:48:30okay uh lowercase Zoomer hit the enter
- 10:48:35details we updated now we're going to
- 10:48:37click on connect to stripe and now this
- 10:48:40the the on boarding can be started for
- 10:48:42this user as well so if we check right
- 10:48:45now users table we are going to see that
- 10:48:47a new account has already been created
- 10:48:49for vendor 2 but it is not active yet
- 10:48:54okay so this is something uh I'm going
- 10:48:57to leave this right now because I want
- 10:48:59to test this case I have this case as
- 10:49:01well so I'm going to actually go back
- 10:49:04and I'm going to authenticate now with
- 10:49:06another user which is going to be
- 10:49:11vendor let's go
- 10:49:14into profile
- 10:49:19uh we have to change this as
- 10:49:22well click on
- 10:49:24update connect to stripe and now I'm
- 10:49:27going to just pause the recording and
- 10:49:29quickly go through this and click on
- 10:49:31agree and submit and at this stage we
- 10:49:35have in the
- 10:49:36database now third one which got already
- 10:49:39active so as you see now we have uh two
- 10:49:43vendors so you are successfully
- 10:49:45connected to stripe which which means
- 10:49:46that that user is fully set up to be
- 10:49:49able to um publish the products on the
- 10:49:54website but the vendor 2 user doesn't
- 10:49:58have stripe account verification so that
- 10:50:00user can actually start in my opinion
- 10:50:03that user can actually publish the
- 10:50:05products on the website um but they will
- 10:50:08not get paid unless they verify uh their
- 10:50:12account if we have a look at our
- 10:50:15connected accounts page we're going to
- 10:50:17see that the two of them are actually um
- 10:50:21enabled and one of them is restricted
- 10:50:24because we have not finished this
- 10:50:27onboarding
- 10:50:28flow okay cool now I'm going to do one
- 10:50:32great thing I comment everything what I
- 10:50:34created so far now I'm going to
- 10:50:37create um few things so first is I'm
- 10:50:40going to create payouts table the hbr
- 10:50:44design
- 10:50:45make uh make a model payout model with
- 10:50:51migration okay and I'm going to also
- 10:50:55create HB artisan
- 10:50:58make Command I'm creating command which
- 10:51:02I plan to be executed once in every
- 10:51:05month which will uh do the payout to all
- 10:51:09the vendors so and I'm going to call
- 10:51:11this
- 10:51:13command payout vendors
- 10:51:18okay make common payout vendors
- 10:51:21cool now let me open create payouts
- 10:51:25table and we're going to add few columns
- 10:51:28here we need boring ID for the vendor so
- 10:51:31which is going to refer to the user so
- 10:51:34we are doing the payout for the
- 10:51:37following user and locally we are
- 10:51:39calling this vendor ID so we are going
- 10:51:42to add the amount column how much we're
- 10:51:46going to
- 10:51:47payout we are going to give it the time
- 10:51:49stamp starting from which date we
- 10:51:52perform the payout until which date and
- 10:51:55that's going to be pretty much all here
- 10:51:57so I'm going to open now payout model
- 10:52:00and I'm going to add fillable here with
- 10:52:02vendor ID amount starting from and until
- 10:52:06now I'm going to open payout
- 10:52:09vendors and I'm going to actually remove
- 10:52:13these comments I don't want them and and
- 10:52:16I'm going to give it
- 10:52:19payout uh column vendors and let's give
- 10:52:22it
- 10:52:24description uh perform vendors
- 10:52:28payout um on the
- 10:52:31first of each month actually uh pendor
- 10:52:36perform vendor payout let's do like
- 10:52:38this so now we're going to work on this
- 10:52:42handle now I'm going to write in a log
- 10:52:46the infog starting monthly payout
- 10:52:49process for vendors so the idea of this
- 10:52:52is it's going to run once in a month but
- 10:52:55I'm going to actually also execute this
- 10:52:57manually I will be able to execute this
- 10:52:58manually whenever I need this so this is
- 10:53:01how I'm going to uh do it so on the
- 10:53:04vendor I'm calling this eligible for
- 10:53:07payout which we actually have defined as
- 10:53:11a scope that the vendor status needs to
- 10:53:13be uh approved but I think think we also
- 10:53:17need to um we also need to have a look
- 10:53:23that the account account the user is
- 10:53:25actually active so I think we are going
- 10:53:27to perform here join on
- 10:53:32users where users ID equals vendor user
- 10:53:37ID and we're going to add additional
- 10:53:42we
- 10:53:44users and what is is the exact name of
- 10:53:47this
- 10:53:49column
- 10:53:51stripe account active stripe account
- 10:53:54active user stripe account active equals
- 10:53:57one uh or
- 10:54:04true okay let's go back into vendors
- 10:54:07payout so we're going to select all the
- 10:54:10vendors which are eligible for payout
- 10:54:12then start iterating over each vendor
- 10:54:15and we are going to process the payout
- 10:54:17I'm going to create this function
- 10:54:18process payout for each of them and
- 10:54:20finally I'm going to just print the info
- 10:54:22monthly payout process completed and we
- 10:54:25are going to return with command success
- 10:54:27now let's create this process payout
- 10:54:29because that is the most interesting
- 10:54:31part uh right here so we accept the
- 10:54:34vendor
- 10:54:35here then we're going to print the info
- 10:54:38message right here to process we're
- 10:54:39processing payout for the following
- 10:54:41vendor we're printing the vendor user ID
- 10:54:43as well as the vendor store name okay
- 10:54:47now we're going to put everything inside
- 10:54:49try catch so we begin the transaction
- 10:54:52and we are GNA uh select the date when
- 10:54:58the previous payout happened and we're
- 10:55:01going to select all the orders after
- 10:55:03that date okay so from payouts we're
- 10:55:06going to select where vendor ID is the
- 10:55:08vendor user ID order by until descending
- 10:55:13and we're going to get the until so
- 10:55:14basically we are taking the
- 10:55:17last maximum until from here so it could
- 10:55:21be also Max until but in this case we're
- 10:55:24just ordering by until and taking the
- 10:55:26first
- 10:55:27one cool so then we are going to check
- 10:55:31if it's starting from exist we are
- 10:55:34taking this if it doesn't exist we are
- 10:55:36making the carbon date uh 1970 so
- 10:55:39basically it doesn't exist if we are
- 10:55:42doing the first payout for this specific
- 10:55:44vendor in which case the starting from
- 10:55:47will be actually null and we're taking
- 10:55:49the starting from to be
- 10:55:511970 so then uh um we are going to
- 10:55:55calculate the until and until is going
- 10:55:59to be this uh something like this let me
- 10:56:02open scratch
- 10:56:03file and show this to you so if today is
- 10:56:07like
- 10:56:0823 of um 23 of November okay that's the
- 10:56:13actual date today so
- 10:56:16we are going to do the
- 10:56:19payout until the previous
- 10:56:23month uh first date so the previous
- 10:56:26month is
- 10:56:28October and we are GNA do the payout
- 10:56:33until 1st of
- 10:56:35October and why I'm doing this actually
- 10:56:39uh this code will be executed on the
- 10:56:42first of month so generally speaking on
- 10:56:461st of November this is going to perform
- 10:56:49the payout including 1st of
- 10:56:52October okay from the previous date from
- 10:56:55the previous payout including until 1st
- 10:56:58of October on the 1st of December it is
- 10:57:01going to do the payout until 1st of
- 10:57:04November and so on so uh the date is at
- 10:57:08least one month the the date when the
- 10:57:10payout command is executed will be at
- 10:57:13least one month later uh from the date
- 10:57:16until which we are actually performing
- 10:57:18the
- 10:57:20payout but in this case because it is 23
- 10:57:23of November uh the previous month so we
- 10:57:25are taking this sub Monon no no overflow
- 10:57:29this means calculating one month with no
- 10:57:32overflow this no overflow is actually
- 10:57:35necessary uh for carbon to properly
- 10:57:39calculate uh what is one month
- 10:57:42subtracted one month like if we are
- 10:57:44speaking about 30 30 of March subtract
- 10:57:48one month from 30 of March might you
- 10:57:52might understand that it's a 30 of
- 10:57:54February which doesn't exist right so
- 10:57:56yeah this no overflow is actually
- 10:57:58necessary to make sure that carbon
- 10:58:01correctly calculates the uh one month
- 10:58:04sub subtraction which gives us in our
- 10:58:07case 33 of October but then we take
- 10:58:09start of month which is first of October
- 10:58:13okay so then uh we're going to calculate
- 10:58:16the vendor subtotal how much we should
- 10:58:19transfer from our balance and our
- 10:58:23balance is actually right here so this
- 10:58:26is our account we have this is our
- 10:58:28balance right and uh we have connected
- 10:58:32users so into one of the connected users
- 10:58:35we're going to send the
- 10:58:37money so we're going to select from
- 10:58:40orders with the vendor user ID to be the
- 10:58:42vendor user ID right here so we're going
- 10:58:45to select SCT only paid orders and we're
- 10:58:49going to put the created dat of the
- 10:58:51order in between the starting from and
- 10:58:55until and we are going to calculate the
- 10:58:58sum of vendor subtotal we have many
- 10:59:01colums in the orders table but vendor
- 10:59:05subtotal is what is payout
- 10:59:09amount okay so this is website
- 10:59:12commission uh this is this was taken by
- 10:59:16tribe so the vendor subtotal is what we
- 10:59:18should pay to the vendor so we calculate
- 10:59:20this vendor subtotal and now let's check
- 10:59:23if the vendor subtotal exists meaning
- 10:59:25that if it is more than
- 10:59:26zero uh if it's not more than zero then
- 10:59:29we just write nothing to process but if
- 10:59:31it's more than zero then we are going to
- 10:59:33write a message here payout made with
- 10:59:36amount vendor subtotal and then we're
- 10:59:38going to create this payout record
- 10:59:40providing vendor ID amount starting from
- 10:59:43and until and right here this is the key
- 10:59:47point which you can find in the
- 10:59:49following documentation as well out user
- 10:59:52transfer and this is going to send the
- 10:59:54money so from our account we are
- 10:59:57performing transfer to the vendor user
- 10:59:59account and we are providing the
- 11:00:01following amount so vendor subtotal
- 11:00:05Multiplied on 100 to convert this into
- 11:00:08dollars because sorry to convert this
- 11:00:11into cents because we have provide the
- 11:00:13payout in cents but if we we check
- 11:00:16orders right now we're going to see that
- 11:00:18some of the amounts on the vendors uh
- 11:00:21have a lot of decimal numbers
- 11:00:25right and we are casting this into
- 11:00:28integer because we cannot provide
- 11:00:29decimal value inside the transfer so
- 11:00:32this will be multiplied 100 which will
- 11:00:35be
- 11:00:36483 sorry this is website commission
- 11:00:39this one um which will be
- 11:00:42[Music]
- 11:00:4443 no
- 11:00:484,348 and
- 11:00:514,348 will be sent uh to the vendor so
- 11:00:54the other simply will be
- 11:00:56neglected and just like this we are
- 11:00:58performing this payout let's uh comit
- 11:01:01the transaction if everything happened
- 11:01:03we come the transaction if something is
- 11:01:05going wrong then we roll back and we
- 11:01:08print the error message here as
- 11:01:11well so I think we have to import the
- 11:01:15things hold on I did something weird so
- 11:01:17we have to import this
- 11:01:19vendor we have to import this
- 11:01:22payout up models payout we have to
- 11:01:25import
- 11:01:27carbon import
- 11:01:30order and order status
- 11:01:38enm okay now we
- 11:01:41have we have this ready and I want to
- 11:01:44execute this PHP
- 11:01:47Artisan
- 11:01:48payout vendors we hit the enter let's
- 11:01:52have a look I think table payouts
- 11:01:54doesn't exist because we haven't
- 11:01:56executed PHP Artisan
- 11:01:59migrate okay now let's execute payout
- 11:02:02vendors and have a look so nothing to
- 11:02:05process and this is very logical because
- 11:02:08the dates are
- 11:02:10not uh before 1 of December so if we
- 11:02:14check what is the until
- 11:02:16we are going to
- 11:02:18find that until is 1st of December so we
- 11:02:22want all the orders which was made until
- 11:02:241st of December but we don't have such
- 11:02:26orders right every order is made right
- 11:02:28now and you know what I'm going to
- 11:02:31change the order dates so we have all
- 11:02:35the orders made right now let me change
- 11:02:37this into be made
- 11:02:41in in
- 11:02:44September cool
- 11:02:48uh it is not yeah it converts this into
- 11:02:53time stamp
- 11:02:54because SQ light doesn't have actually
- 11:02:58daytime it has Tim
- 11:03:00stamp and it is saved like this to fix
- 11:03:03this in PHP storm we're going to open
- 11:03:05the database settings go into advanced
- 11:03:07and
- 11:03:09find uh date date class date class to be
- 11:03:13text
- 11:03:19now let's save this in
- 11:03:23September now it was saved as as it
- 11:03:28should be now I want to update all the
- 11:03:31other
- 11:03:32records uh with
- 11:03:34the uh 23 of September I'm going to save
- 11:03:38this
- 11:03:40and okay cool now let's
- 11:03:42execute pay out and have a look
- 11:03:47look at this okay so for vendor store
- 11:03:51vendor 2 for vendor store payout made
- 11:03:55with
- 11:03:56amount 100
- 11:03:59something uh for vendor six which which
- 11:04:03was also
- 11:04:04eligible there was nothing to process
- 11:04:07now let's check
- 11:04:08orders and see all the different vendor
- 11:04:12user ID so we have vendor two for which
- 11:04:15we have made some payments for vendor 4
- 11:04:18we have made some payments but vendor 4
- 11:04:23is actually not eligible for payout
- 11:04:26because vendor
- 11:04:274 which is
- 11:04:29zomer vendor 4 does not have
- 11:04:33account activation
- 11:04:35finished okay so only vendor two was a
- 11:04:40was eligible to pay
- 11:04:43out and
- 11:04:45let's see in the stripe
- 11:04:47dashboard
- 11:04:49so if we just refresh this right now the
- 11:04:53connected
- 11:05:01accounts come
- 11:05:03on now look at this so this is the
- 11:05:07vendor and we perform the pay payout
- 11:05:12129 129 here
- 11:05:16and we see that uh balance for this
- 11:05:20account is right now
- 11:05:22129 and that is um single Transaction
- 11:05:27what we did right
- 11:05:28now okay we made this transfer right now
- 11:05:33okay let's go back and if we check our
- 11:05:36balance we're going to see we we had
- 11:05:38like
- 11:05:391,900 something now something was gone
- 11:05:42from our balance and if we check the all
- 11:05:46activity we're going to see this minus
- 11:05:49uh
- 11:05:50121 so this is a transfer into the
- 11:05:53following account what we so I think
- 11:05:56this is this is it
- 11:05:59so that's that's what we uh wanted to
- 11:06:02achieve let's click on this connected
- 11:06:04accounts Okay cool so we did just pay
- 11:06:07out and also let's check the payouts
- 11:06:10table refresh schema click on payouts
- 11:06:12table now we see one record we see the m
- 11:06:15we see starting from we see until the 1
- 11:06:19of October and if we try
- 11:06:22to execute payout again there will be
- 11:06:25nothing to process because uh now the we
- 11:06:28took everything from uh after uh the
- 11:06:36um after the first of October actually
- 11:06:41in our case even if we make new orders
- 11:06:45right now
- 11:06:46we are going to see let me
- 11:06:49dump uh starting from and
- 11:06:52until we are going to see them they will
- 11:06:56be the
- 11:06:57same they are the same so right now it's
- 11:07:01a 23rd of January as I mentioned and
- 11:07:04whenever it is already December when we
- 11:07:06execute the payout we are going to see
- 11:07:09that
- 11:07:10the the orders which were made in
- 11:07:13November will be paid out
- 11:07:16and this is this is very very
- 11:07:22good now of course we did this manually
- 11:07:26but on production we want this to be
- 11:07:28automated right so we're going to open
- 11:07:30up service provider and right here
- 11:07:33inside the boot we are going to define
- 11:07:37the schedule so let's use schedule
- 11:07:42facade and we're gonna uh we're going to
- 11:07:45perform the scheduling on a commment so
- 11:07:48scheduling is Task scheduling is a very
- 11:07:50very powerful uh Topic in LEL so if we
- 11:07:53open lal.com if we click on
- 11:07:57documentation and search for task
- 11:08:00scheduling you're going to find a lot of
- 11:08:02things so we can schedule the Artisan
- 11:08:04commands Q jobs shell commands and a lot
- 11:08:07of other things and we're going to do
- 11:08:09this Artisan command scheduling at the
- 11:08:11moment so inside the command we're going
- 11:08:13to provide payout vendors this is the
- 11:08:16command uh we are going to schedule this
- 11:08:20monthly on first day of month at let's
- 11:08:24do this overnight like 0 0 00 0 okay and
- 11:08:29then we need to do this without
- 11:08:31overlapping so if there is for some
- 11:08:34reason one command already doing this uh
- 11:08:37payout vendors if we have this in a
- 11:08:40distributed system as an example and one
- 11:08:43server took this and is performing this
- 11:08:46payout the second one should not
- 11:08:49actually do it and just to make sure
- 11:08:52that this command is executed on every
- 11:08:55day for this on not every day but on
- 11:08:58every month on the first of month we
- 11:09:00have to set up the task scheduling
- 11:09:03on uh on production so for this you have
- 11:09:07to edit the crown Tab and this means
- 11:09:10that this should run in every minute you
- 11:09:13have to navigate you have to put the
- 11:09:15following thing in the crown tab
- 11:09:17navigate into your project directory and
- 11:09:21execute PHP Artisan schedule run to
- 11:09:24Output the results uh into Dev now and
- 11:09:27start this in background so technically
- 11:09:30speaking if I took this and if I execute
- 11:09:34it right now schedule run no schedule
- 11:09:37comments are ready to run so right now
- 11:09:39nothing um nothing will be run but if we
- 11:09:43have that schedule
- 11:09:45on let's say on 23rd of November if we
- 11:09:50provide it like
- 11:09:52this uh then we execute this
- 11:09:56um it is not actually doing it but yeah
- 11:10:00you get you get the idea so it doesn't
- 11:10:02find these schedules to run at the
- 11:10:05moment I think I think you want to see
- 11:10:07it running using this schedule
- 11:10:11run so here I provided my time correct
- 11:10:15time in UTC so we see today is 23rd as I
- 11:10:19mentioned monthly on 23rd but I provided
- 11:10:23the time right here as well okay so now
- 11:10:26if I execute this schedule run it is
- 11:10:29catching these payout vendors and
- 11:10:30Performing this right now it obviously
- 11:10:32it doesn't do anything because we have
- 11:10:34done the payout but I'm going to delete
- 11:10:36this payout record from here and it's
- 11:10:38going to do the payout second time so
- 11:10:42let's execute it it is working
- 11:10:45performing some output now in the
- 11:10:47payouts table we're going to probably
- 11:10:50see a new record created and if we check
- 11:10:53right now stripe dashboard we are going
- 11:10:56to see also twice as much amount because
- 11:11:01we did the same payout twice now we see
- 11:11:03200 something and in our balance also we
- 11:11:06see much less amount and just like this
- 11:11:09so we don't need this on 124 we need
- 11:11:12this on 0 0 um 0 and we need this to
- 11:11:17happen on first of uh the month but you
- 11:11:21you just make sure that you
- 11:11:23follow this thing on on your production
- 11:11:26server and um you're going to make it
- 11:11:29working so if you want to see how to
- 11:11:32deploy this project on VPS server or how
- 11:11:35to set up this crop or things like that
- 11:11:37I have a separate video where I um
- 11:11:41actually this video the separate video
- 11:11:44was before this video
- 11:11:45so on my YouTube channel deploy the full
- 11:11:48stack application with service side
- 11:11:49rendering with inertia with react on
- 11:11:52custom domain so everything is there U
- 11:11:55we also have cicd automatic deployment
- 11:11:58there so it's a pretty uh good tutorial
- 11:12:02to get in get started with the um
- 11:12:05fullsack applications with L and react
- 11:12:07um and with deployment part as well so
- 11:12:10in this tutorial you can just add this
- 11:12:12into Crown Tab and you are going to have
- 11:12:15the up and running deployment version
- 11:12:17okay so there are few things I want to
- 11:12:19fix and due to the lack of the time and
- 11:12:22I want to fit this entire project into
- 11:12:2412 hours one YouTube tutorial I had to
- 11:12:27do some work outside and I will just
- 11:12:30show to you what I have done so first if
- 11:12:33we have a look in the interface we're
- 11:12:34going to see t-shirts right here but
- 11:12:36when I click this first product uh two
- 11:12:40right here we see that it's actually
- 11:12:41headset so this happens because we have
- 11:12:45this admin
- 11:12:47area where we from which we uploaded
- 11:12:50different images on the product itself
- 11:12:52and different images uh on the
- 11:12:54variations and this is something which
- 11:12:58you can do but you should not probably
- 11:13:01do so what we are going to do here that
- 11:13:04instead of displaying the product image
- 11:13:05If the product has some variation
- 11:13:07options and at least one of the option
- 11:13:10has some images we're going to use those
- 11:13:12images right here so every time so I I'm
- 11:13:16going to create the I created actually
- 11:13:18the following method get first image URL
- 11:13:22and this on the product model so and
- 11:13:24this actually does the following so it's
- 11:13:26uh I also Define the relation into
- 11:13:28options like this so has many through
- 11:13:31and we can Define this um has many
- 11:13:34through return type as
- 11:13:37well so has many through it has many
- 11:13:40relation into variation type options uh
- 11:13:42through the variation type table uh the
- 11:13:45first key the second key and local key
- 11:13:47and second local key so and just like
- 11:13:49this now I can access options through
- 11:13:52the variation
- 11:13:53types okay so if I scroll down below now
- 11:13:56right here I try to access the options
- 11:13:58and if options count is more than zero
- 11:14:01if it's zero then we simply return the
- 11:14:04first image from the product itself if
- 11:14:06it's more than zero then uh on the
- 11:14:09option I get this First Media URL and if
- 11:14:12the image URL exists I'm returning this
- 11:14:15now I'm going to use this inside product
- 11:14:18list resource when I'm accessing
- 11:14:22this I have to zoom in I guess so when
- 11:14:26I'm accessing this First Media URL I'm
- 11:14:29going to replace it with get first image
- 11:14:32URL right here and now if I refresh the
- 11:14:37page now we see headset right here and
- 11:14:39this is the first variation okay and um
- 11:14:43it works like a charm great
- 11:14:45now we need to do something similar for
- 11:14:48the price as well so here we see that
- 11:14:51the price is 25 on the black one but
- 11:14:53outside we see it to be 15 okay so here
- 11:14:59I actually added a second method get
- 11:15:01price for first options can collapse
- 11:15:05this and I'm going to use this method
- 11:15:07right here get price for first options
- 11:15:09and it is going to return uh 25 which is
- 11:15:14pric for the first
- 11:15:15options additionally I added a few more
- 11:15:18methods
- 11:15:19like um we saw this we saw that so get
- 11:15:24first options map so which is something
- 11:15:28uh which is used internally here as well
- 11:15:30get price for first IM first options so
- 11:15:33we're getting the first options right
- 11:15:35here and then if the first options exist
- 11:15:37meaning that if the product has some
- 11:15:39options then we call this get price for
- 11:15:42options which is something already
- 11:15:43exists so we defined this
- 11:15:46earlier so we reuse the same method
- 11:15:49right here to calculate the price and we
- 11:15:51also have this skate images where we
- 11:15:53check if the options exist um and this
- 11:15:56simply returns all the images so this is
- 11:15:59very similar to get first image URL but
- 11:16:02this one returns all the images and we
- 11:16:04will use this as well let me collapse
- 11:16:06this collapse that so I think we're
- 11:16:09going to use this inside cart service so
- 11:16:13if we find uh um place where we are
- 11:16:16adding the item into the
- 11:16:19cart uh I think this is the place is if
- 11:16:22option ID equals null then on the
- 11:16:25product we we're going to call this get
- 11:16:27first options map which should return
- 11:16:30some options and we're going to use that
- 11:16:32to add this into the card and this now
- 11:16:36actually uh is going to work pretty well
- 11:16:38so if I click this A2 cart here we see
- 11:16:41something was added into the cart and
- 11:16:43that something should have image this
- 11:16:45black headset in price of
- 11:16:4725 uh the image is not the one
- 11:16:51[Music]
- 11:16:52and probably
- 11:16:54we the price is also not the
- 11:16:58one so we're going to see what option
- 11:17:01IDs we have here when we print
- 11:17:05them uh when we are adding
- 11:17:08them homepage click it to card we see
- 11:17:12empty options
- 11:17:15yeah okay so we are uh checking actually
- 11:17:18against null but this is what we're
- 11:17:21going to do if options does not exist
- 11:17:24empty array means also that it doesn't
- 11:17:26exist so we're getting these empty uh
- 11:17:28option IDs from the front end from the
- 11:17:31react that's why this if is not
- 11:17:33satisfied if I save this and click on
- 11:17:36this Ed to cart right now now we see
- 11:17:38those options and that should fix the
- 11:17:42issue uh I'm going to actually remove
- 11:17:45this from
- 11:17:47cart then click on this Ed to cart it
- 11:17:51seems like to
- 11:17:52work okay now that worked and we have
- 11:17:56now the color black and size small
- 11:17:58variation added into the card if we
- 11:18:01check this one this doesn't have any
- 11:18:02variation so that should be
- 11:18:06good to add that into the cart now we
- 11:18:10have a two
- 11:18:13quantity Okay so
- 11:18:15now since we have these get images
- 11:18:20here we're going to use this in another
- 11:18:22place when we when we start working on
- 11:18:26SEO but I think yeah the the issue
- 11:18:29regarding the product listing is
- 11:18:33actually resolved and as soon as there
- 11:18:36is some variation that variation will be
- 11:18:38picked up now let's Implement vendor
- 11:18:41profile
- 11:18:42page on on some UR URL so first let's
- 11:18:46implement the uh
- 11:18:48controller so we have selected the
- 11:18:51products but only those products which
- 11:18:54was created which has created by vendor
- 11:18:58user ID okay then we are going to render
- 11:19:01vendor profile page which we're going to
- 11:19:03create we are using we're passing the
- 11:19:05vendor here and we're passing the
- 11:19:06products through this product least
- 11:19:10resource that's that's
- 11:19:13cool now here we are using this for
- 11:19:16website and I want to check this for
- 11:19:18website and update this for website
- 11:19:21right now only is using published but I
- 11:19:25want to create another scope right here
- 11:19:28which is going to be public function
- 11:19:32scope
- 11:19:34vendor approved so I'm going to use
- 11:19:39Builder
- 11:19:41here and I'm going to return something
- 11:19:45like this let me copy
- 11:19:49so that should be
- 11:19:53Cy so on on the Cy I'm using um join to
- 11:19:58join into the vendors using the user ID
- 11:20:01with the correct columns and I'm
- 11:20:04selecting only those which those
- 11:20:07products which has vendor status to be
- 11:20:09approved so right here I want to use
- 11:20:12vendor approved
- 11:20:14so scope now for website means that the
- 11:20:18product needs to be published and the
- 11:20:19vendor needs to be approved as long as
- 11:20:21the admin user decides to disapprove or
- 11:20:25change the approval status into pending
- 11:20:27or something else the products will be
- 11:20:30gone from the website and we can easily
- 11:20:32test this so on the homepage now we
- 11:20:36see yeah Status is ambigous because
- 11:20:40inside the published we have to use
- 11:20:42right here products. status
- 11:20:46now let's see so on the homepage we see
- 11:20:48now vendor 2 and vendor products and if
- 11:20:51we open vendors page and if we change
- 11:20:56the status approved into pending as an
- 11:21:00example then the product should be gone
- 11:21:02from the homepage so it is practically
- 11:21:04gone from the website so let's return
- 11:21:07this and refresh the page and it will be
- 11:21:11back and that's that's on the homepage
- 11:21:13and that's going to be done also so on
- 11:21:14the profile page Bas basically four
- 11:21:17website cope was completely updated now
- 11:21:20we are going to go into JS
- 11:21:23Pages uh and let's create now another
- 11:21:28typescript file this is going to be
- 11:21:30inside the vendor folder vendor
- 11:21:35profile okay I have to copy that
- 11:21:39typescript file it is going to be very
- 11:21:41much similar into the
- 11:21:43homepage let me actually quick quickly
- 11:21:46copy and paste
- 11:21:49this okay let's have a look so we have
- 11:21:52the product item from the
- 11:21:56app
- 11:21:57[Music]
- 11:21:58um we have few things I think we don't
- 11:22:02have vendor type defined and I think we
- 11:22:06we need to Define this inside the time
- 11:22:09types and we have
- 11:22:11this uh page props as well
- 11:22:17well okay so inside the page props let's
- 11:22:21actually
- 11:22:28Define yeah um my my project which from
- 11:22:33which I copied actually is slightly
- 11:22:35different because I improve this every
- 11:22:36time I you create something you might
- 11:22:38improve it slightly so here products is
- 11:22:42actually something what we have to find
- 11:22:44in the home T6 so we can see product is
- 11:22:48actually paginated props so we can
- 11:22:51provide it like this cool so we have
- 11:22:54vendor which needs to be imported
- 11:22:57actually defined and imported so let's
- 11:22:59go in the types and let's Define export
- 11:23:04type
- 11:23:06vendor and let
- 11:23:09me copy so we don't have many fields on
- 11:23:12the vendor we have ID uh store name and
- 11:23:15store address can close this now in the
- 11:23:18profile vendor is imported everything
- 11:23:20seems to be
- 11:23:22good let's move this down and it's very
- 11:23:25much similar to the homepage so in the
- 11:23:27title we just have the vendor store name
- 11:23:29profile page then we have this stock
- 11:23:32image as a hero section and then down
- 11:23:35below iterate over products and render
- 11:23:37that okay now let's open web.php which
- 11:23:40is going to be vendor profile page
- 11:23:45uh where should we Define
- 11:23:50this okay let's define it right here so
- 11:23:53this is the root I'm using this S as an
- 11:23:56abbreviation for seller um so we're
- 11:24:00going to select the seller by store name
- 11:24:03uh using the following controller
- 11:24:05passing it and this is the um profile so
- 11:24:09vendor profile now if we check actually
- 11:24:13let me update product
- 11:24:17item and
- 11:24:20find right here so we're going to change
- 11:24:22this into
- 11:24:25root vendor. profile
- 11:24:29providing
- 11:24:30product.
- 11:24:32user. store name do we have store name
- 11:24:37user product.
- 11:24:40user okay
- 11:24:49product. user product. user doesn't have
- 11:24:52vendor specific information right so do
- 11:24:56we have user resource
- 11:25:00somewhere no let's open product list
- 11:25:04resource and we are just returning user
- 11:25:07information right here but we want to
- 11:25:10return some other information as well so
- 11:25:13let me actually add right here only
- 11:25:15store
- 11:25:16name this
- 11:25:20user
- 11:25:21vendor store name now inside product
- 11:25:26item right here first inside the types
- 11:25:29we're going to define the store name
- 11:25:31here then I'm using store name as a
- 11:25:39parameter actually my bed this was for
- 11:25:42departments right no it was for the user
- 11:25:45that's correct so let's move this
- 11:25:50down okay great uh if we search for this
- 11:25:55I think there's a second place we are
- 11:25:56using it let's open show.
- 11:26:01TS6 and
- 11:26:03find where we have this title product
- 11:26:06title and below that product title maybe
- 11:26:09we want to put the following
- 11:26:11paragraph let's remove this margin
- 11:26:13buttom from here and add
- 11:26:17that here so if we open right
- 11:26:23now uh we're going to open product
- 11:26:26Resource as well let me explain what I'm
- 11:26:28doing I think you got
- 11:26:30confused so we did this on the product
- 11:26:33list item so we opened product list
- 11:26:35resource we returned store name then we
- 11:26:39accepted this store name right here in
- 11:26:41this product item and we displayed the
- 11:26:43store name name we displayed the proper
- 11:26:45rout okay so we have to do something
- 11:26:48similar in the show page when we display
- 11:26:50all the details about the product so we
- 11:26:53don't even
- 11:26:54display uh where this product by who the
- 11:26:57product is created and in which
- 11:26:59department the product is created we
- 11:27:01didn't even do this on the product
- 11:27:03Details page so this is what I did right
- 11:27:06now so I copied this in the show t uh
- 11:27:10TS6 and the problem is that we don't
- 11:27:13have store name returned on the product
- 11:27:16resource so we want to open product
- 11:27:19resource and find where we are returning
- 11:27:21user and we are going to return store
- 11:27:25name here as
- 11:27:28well now if we refresh the page the
- 11:27:32error should be gone we should see okay
- 11:27:35by vendor 2 and if we click vendor or
- 11:27:37vendor two in the url url looks great
- 11:27:39click on this now this opens this vendor
- 11:27:42store where we see only products that
- 11:27:44are related to the specific vendor so in
- 11:27:48ideal case we are going to have the
- 11:27:49cover image for the vendor we have cover
- 11:27:52image in the database but we haven't
- 11:27:53actually implemented uploading cover
- 11:27:55image for the Ender which probably we
- 11:27:57won't be able to do this in this time
- 11:27:59frame but I'm going to do this of course
- 11:28:01um in the project source code so you can
- 11:28:03check the source code if you get the
- 11:28:05source code uh there will be a lot more
- 11:28:07than this so click on this you're going
- 11:28:10to find that as well pretty cool if we
- 11:28:13go inside
- 11:28:15uh no something is not working as
- 11:28:21expected parameter is required for
- 11:28:24vendor profile let's
- 11:28:27see okay why don't we see the
- 11:28:33parameter parameter is required for
- 11:28:39vendor
- 11:28:42um product user has store
- 11:28:47name okay uh I'm going to print the
- 11:28:50entire product and see what's going on
- 11:28:54there uh product. user let's print print
- 11:28:58product. user so this is the user it has
- 11:29:01a store name store name is somehow
- 11:29:05null because I did something wrong
- 11:29:08vendor store
- 11:29:10name refresh the page let's remove this
- 11:29:13cont console log as well and now we see
- 11:29:17product Details page here we see this by
- 11:29:19vendor in electronics I'm clicking on
- 11:29:21this also works
- 11:29:25perfectly okay great now we have this
- 11:29:28vendor profile page as well where we
- 11:29:30display only the products which belong
- 11:29:32to the specific vendor now I want to
- 11:29:36work on the Departments displaying the
- 11:29:39Departments right here and Implement uh
- 11:29:42searching by Department ments filtering
- 11:29:45by departments as well as a a search
- 11:29:47form right here to search certain things
- 11:29:50by keyword so this going to be pretty
- 11:29:52interesting and useful thing and again I
- 11:29:55will try to speed up a little bit so
- 11:29:58first uh let's open
- 11:30:02navbar not this
- 11:30:04one
- 11:30:06navbar TSX so we we need this I'm going
- 11:30:10to modify this part actually and I'm
- 11:30:12going to also open handle injs request
- 11:30:16and I'm going to actually why I'm
- 11:30:17zooming out this
- 11:30:19um I want to provide departments from
- 11:30:23here so let me select
- 11:30:30departments uh
- 11:30:32Department model uh we're going to find
- 11:30:35published departments and I'm going to
- 11:30:37create scope for these with I'm going to
- 11:30:40select them with
- 11:30:42categories and I'm going to uh limit and
- 11:30:46take only the first 10 or maybe we can
- 11:30:50return even all of them it's okay so now
- 11:30:52if we open
- 11:30:53this uh Department model we're going to
- 11:30:56Define uh scope let me open vendor and
- 11:31:01we're going to find I'm going to copy
- 11:31:04this scope put this right
- 11:31:10here say status need to be department or
- 11:31:15I think we don't have status we have
- 11:31:18active so active needs to be true for
- 11:31:24departments now let's import this
- 11:31:26Builder and this should be eloquent
- 11:31:30Builder and the name should be scope
- 11:31:35published okay we select the Departments
- 11:31:37with categories and I'm going to provide
- 11:31:41them right here
- 11:31:45departments we can provide it like this
- 11:31:48or we can create a department
- 11:31:51resource uh I'm going to actually do the
- 11:31:54following I'm going to create Department
- 11:31:56resource PHP artisan make
- 11:32:00resource
- 11:32:02department
- 11:32:03resource let's open
- 11:32:07this uh let's open
- 11:32:09Department
- 11:32:11resource and I'm going to change change
- 11:32:14this return type so we need ID name slug
- 11:32:16meta title meta description for the
- 11:32:19Departments we need all that and
- 11:32:21categories for categories we only take
- 11:32:23ID and name so I'm going to disable WP
- 11:32:27set the to
- 11:32:29false then right here I'm going to use
- 11:32:33Department
- 11:32:35resource collection
- 11:32:38departments and we are going to actually
- 11:32:41take collection out of f is an array to
- 11:32:48array now we're going to open index. DTS
- 11:32:52and we're going to
- 11:32:53Define departments and categories right
- 11:32:56here so I copied and paste it we see
- 11:32:58this category uh ID and Name ID can be
- 11:33:01actually number it's fine and for
- 11:33:04Department we see ID name slug uh meta
- 11:33:07title met description and categories and
- 11:33:10in the nav bar we are going to accept
- 11:33:14uh
- 11:33:15departments and actually if we check
- 11:33:18page props we are going to add
- 11:33:21departments here as
- 11:33:24well cool now we accept departments here
- 11:33:28uh we don't want this total price and
- 11:33:30total quantity I guess so we take these
- 11:33:35departments and we want to iterate and
- 11:33:39render them so for this I'm going to
- 11:33:41create a fragment here and I'm going to
- 11:33:44actually create second
- 11:33:47navbar so I'm going to quickly copy and
- 11:33:51explain
- 11:33:53it so here is the second now bar now bar
- 11:33:57BG is border top mean head four that's
- 11:34:00it so inside we have this now bar Center
- 11:34:04uh which is uh hidden and display Flex
- 11:34:07uh only on large screens and then we see
- 11:34:10this UL menu menu horizontal menu drop-
- 11:34:13down
- 11:34:14and uh we can remove this as well no
- 11:34:16need I was experimenting something menu
- 11:34:19menu horizontal and we iterate over
- 11:34:21departments and render Li so if I save
- 11:34:25this right now and have a look in the
- 11:34:27browser of course we might have some
- 11:34:29errors we have to take care of the
- 11:34:31errors
- 11:34:32always
- 11:34:35okay map departments doesn't have map
- 11:34:39let's see what are
- 11:34:42departments Department seem to be
- 11:34:47departments it has
- 11:34:51something product by Department okay so
- 11:34:55this is something uh we are going to
- 11:34:57Define so here inside this HF we have
- 11:34:59product by Department which is a new
- 11:35:02route which will display products only
- 11:35:05uh for this department and we are going
- 11:35:08to Define this as well but for now let's
- 11:35:11just provide selection side now we see
- 11:35:15right here departments um nicely
- 11:35:18displayed and now let's define let's
- 11:35:21open product
- 11:35:24controller we have home we have show and
- 11:35:27here I'm going to create a buy
- 11:35:33Department let
- 11:35:36me let me actually copy this method and
- 11:35:40I will explain this to you so first
- 11:35:42right here we need request
- 11:35:44because that should also do the
- 11:35:47filtering uh
- 11:35:49request then we're going to accept
- 11:35:51Department as well and now let's have a
- 11:35:56look so this is the method and we are
- 11:35:59calling abort if the department is not
- 11:36:03active so then from the quer we're going
- 11:36:06to get the keyword when we implement the
- 11:36:08searching by keyword so we get the
- 11:36:10keyword so we select the products for
- 11:36:13website for the specific department and
- 11:36:16then we use that keyword right here if
- 11:36:18the keyword exists we perform the we we
- 11:36:22title like keyword or description like
- 11:36:24keyword we perform
- 11:36:26pinate and then right here we render the
- 11:36:30page Department index we're going to
- 11:36:32create that uh we provide the department
- 11:36:35resource uh here and product list um
- 11:36:39resource and we provide the keyword
- 11:36:41right here as well now let's create
- 11:36:44Department
- 11:36:49index
- 11:36:51Department
- 11:36:53index okay let me copy that part as
- 11:37:01well okay so this is the department
- 11:37:06index uh we we accept right here
- 11:37:10application name as well which we are
- 11:37:12going to provide from props so I'm going
- 11:37:14to open handle inertia JS request and
- 11:37:18I'm going to provide right here app name
- 11:37:21to be config application name now we're
- 11:37:25going to open this page props and we're
- 11:37:27going to add right here app name to be
- 11:37:30string the error is actually gone and
- 11:37:34now this is the department index page
- 11:37:36where we get the application name we get
- 11:37:37the Department itself we're providing
- 11:37:40and we get the products okay and this is
- 11:37:43something related to meta SEO I'm going
- 11:37:46to just remove
- 11:37:49that uh or we're going to leave this
- 11:37:52okay I'm going to leave this so we're
- 11:37:54going to do SEO in any case so I'm going
- 11:37:56to leave this so we are basically
- 11:37:59working on the SEO side here so we
- 11:38:02display the department name inside the
- 11:38:04title we have the meta title it to be
- 11:38:06the department meta title we have the
- 11:38:08meta description so we are using the
- 11:38:10canonical URL which should be the
- 11:38:12product uh by Department we're going to
- 11:38:14Define this root and we also have this
- 11:38:17OG tags the department name description
- 11:38:20URL uh the type and the application name
- 11:38:24and down below we just display the
- 11:38:25department name and we display no
- 11:38:28products found or iterate over the
- 11:38:31products now let's open web.php and we
- 11:38:36are going to
- 11:38:37Define these by
- 11:38:40Department I'm going to copy this route
- 11:38:43put this right here so D then the
- 11:38:47department Slug and then products okay
- 11:38:50and this is the product by Department we
- 11:38:54save
- 11:38:55that and I'm going to open now this
- 11:39:02Navar uh right here and I'm going to
- 11:39:04provide
- 11:39:07root U
- 11:39:08product product by Department providing
- 11:39:15Department
- 11:39:18slug so I'm going to also open product
- 11:39:22list product list item or product item
- 11:39:26how we call this and right here we have
- 11:39:30this department name so we're going to
- 11:39:32change this into
- 11:39:35root product by
- 11:39:40department and we need to do something
- 11:39:42similar
- 11:39:44on show TS6
- 11:39:47page let's open this let's search for
- 11:39:51department and we're going to change
- 11:39:53this into
- 11:39:56root the product by
- 11:39:58department and product.
- 11:40:03department.
- 11:40:06name let's check product
- 11:40:10item product by Department we haven't
- 11:40:12provided
- 11:40:14did product by Department slug should be
- 11:40:17here but here
- 11:40:20product
- 11:40:22department.
- 11:40:25slug now we probably have some error
- 11:40:28let's have a
- 11:40:30look Department parameter is
- 11:40:33required Inside by
- 11:40:37Department okay so we need slug
- 11:40:40here in the product listing and we're
- 11:40:43going to open product list
- 11:40:47resource and right here we're going to
- 11:40:49return slug for the
- 11:40:52Department we're going to also open
- 11:40:55product
- 11:40:59resource and we are going to return slug
- 11:41:03here as
- 11:41:08well now refresh the page
- 11:41:14so clicking on electronics changes the
- 11:41:17URL D Electronics products as you
- 11:41:21see Department Electronics I think we
- 11:41:24can even
- 11:41:26omit products
- 11:41:29right yeah we can do
- 11:41:36that okay so now we see all the products
- 11:41:39in electronics click on this shows the
- 11:41:41fashion products click on this shows H
- 11:41:44garden tools and so on you can work on
- 11:41:48to
- 11:41:49add uh the active class to the
- 11:41:52department which is right now opened I
- 11:41:54think this is going to be a good
- 11:41:55challenge to you so now I'm going to add
- 11:41:59search as well so let's
- 11:42:02open what do we
- 11:42:05have okay there is gone now let's open
- 11:42:10navbar and I'm going to work on the
- 11:42:14search inside the nav
- 11:42:19bar so we have
- 11:42:22this mini card dropdown before which I'm
- 11:42:25going to put the form so that is very
- 11:42:29basic form which has join class so this
- 11:42:32is the join
- 11:42:33form uh which I copied uh the you can
- 11:42:36find the joins in the daisy UI let me
- 11:42:39open Daisy UI or we have the that open
- 11:42:43and if we search for join we are going
- 11:42:47to find these joins and I copied the
- 11:42:51following example we just don't need the
- 11:42:52filter we need on the search uh
- 11:42:55placeholder and search text and I'm
- 11:42:59going to also copy right now from my
- 11:43:03project onsubmit and search form let me
- 11:43:07put them right
- 11:43:09here form even Handler on submit is a
- 11:43:12has type of form event handler I'm going
- 11:43:15to import this and let's import this use
- 11:43:19form and we're going to accept
- 11:43:22keyword right here inside
- 11:43:27props
- 11:43:33um I think keyw doesn't exist inside the
- 11:43:36props
- 11:43:39right yeah it doesn't exist inside the
- 11:43:41props so we can add that into the
- 11:43:46props actually uh we don't want keyword
- 11:43:49to be added inside the page props
- 11:43:51because that page props is for every
- 11:43:54page but the keyword is something on for
- 11:43:58this page so inside this page props I'm
- 11:44:01going to extend and use page props and
- 11:44:05I'm going to provide keyword here to be
- 11:44:11string now
- 11:44:14we are good so now what we are doing
- 11:44:16here is that whenever the form is
- 11:44:17submitted we are uh calling accessing
- 11:44:21get method on the following search form
- 11:44:23providing the current URL but providing
- 11:44:26this keyword right here okay and here
- 11:44:30inside the form magnifying glass icon
- 11:44:33let's import this from
- 11:44:36outline and right here we have this
- 11:44:38input on change we are setting this
- 11:44:41keyword inside the
- 11:44:44uh search form and we have the value as
- 11:44:46well data keyword and this is a button
- 11:44:49which triggers the submission so if I
- 11:44:51save this and we have a look so we're
- 11:44:54going to see the form right here if we
- 11:44:56go on the
- 11:44:58homepage uh if we search for something
- 11:45:01like search for first hit the enter I
- 11:45:04think we haven't implemented this
- 11:45:06keyword search on the homepage but we
- 11:45:08did this on the uh Department page so if
- 11:45:11we search for first hit the enter we see
- 11:45:13the item if we add few more characters
- 11:45:16then this is gone and we don't see
- 11:45:19anything so let's
- 11:45:22open uh product controller and I'm going
- 11:45:25to copy this
- 11:45:27when uh on the homepage as well here and
- 11:45:31I'm going to copy the keyword as
- 11:45:36well and let's accept
- 11:45:39request here and we probably need such
- 11:45:42type of filter in on vendor controller
- 11:45:45as well so we're going to accept this
- 11:45:49request uh request request here and
- 11:45:54we're going to
- 11:45:56provide oops we are going to provide
- 11:45:59this we CLA on the vendor page as
- 11:46:05well okay so if we click on this then we
- 11:46:09search for something test hit on this
- 11:46:14uh it found maybe because of some
- 11:46:17description not sure uh let's write
- 11:46:20something weird now this is gone it did
- 11:46:23it doesn't
- 11:46:26find
- 11:46:29okay uh whatever is inside the keyword
- 11:46:32that should
- 11:46:33be
- 11:46:35populated that should be populated right
- 11:46:38here inside the search so if we open
- 11:46:41product controller we are taking this
- 11:46:45keyword right here and assigning giving
- 11:46:49this into the view and this is what I'm
- 11:46:51going to change also so I'm going to
- 11:46:54copy this I'm going to open handle
- 11:46:56inertial JS request and I'm going to
- 11:46:58provide this keyword right here search
- 11:47:05keyword
- 11:47:07okay
- 11:47:10keyword we need we have two commas
- 11:47:19here what's the issue oh this is the
- 11:47:23issue okay so now we have this keyword
- 11:47:26on every page and if we refresh this
- 11:47:29right
- 11:47:30now we are going to get the keyword from
- 11:47:33here and we can even open this
- 11:47:36index
- 11:47:38DTS and
- 11:47:41inside page props we can e the add this
- 11:47:46keyword keyword equals
- 11:47:49string okay now if we open
- 11:47:53navbar we can remove this from here
- 11:47:56because now page props as keyword inside
- 11:48:01okay so filtering let's remove this now
- 11:48:03filtering uh inside the vendor store
- 11:48:05Works filtering inside
- 11:48:08departments prod this returns something
- 11:48:12this does return
- 11:48:19anything what I want to do when when I
- 11:48:23do this skate I want to preserve scroll
- 11:48:27true and I want to preserve State true
- 11:48:31as well otherwise it feels like a
- 11:48:33traditional application not inertia so
- 11:48:36if I search for something like prod hit
- 11:48:38the enter now this performs the field
- 11:48:42filtering but the cursor still continues
- 11:48:44blinking here and this is exactly what I
- 11:48:46want so we have single page application
- 11:48:49click on test it's still find
- 11:48:52something are you kidding
- 11:48:54me uh Test Pro hit the enter now only
- 11:48:58one is left now the scroll will be
- 11:49:01preserved the state will be preserved
- 11:49:03and that's pretty cool we can test this
- 11:49:05on here as well
- 11:49:07prod
- 11:49:09and yeah the cursor still continues
- 11:49:11blinking there and this is pretty cool
- 11:49:14so filtering by departments is also
- 11:49:19implemented successfully now let's talk
- 11:49:22a little bit about SEO as well because
- 11:49:25that's a very crucial part of building
- 11:49:27an e-commerce website where you want SEO
- 11:49:30capabilities and even though we built
- 11:49:32single page application with react in
- 11:49:34LEL we do have server side rendering and
- 11:49:37we are going to have great SEO and this
- 11:49:39is how we're going to have and we're
- 11:49:41going to see the result as well well so
- 11:49:43I created this new migration to add SEO
- 11:49:45columns to products I executed the
- 11:49:47migration columns we are added then I
- 11:49:50open the product resource from the
- 11:49:52filament folder and right here we addit
- 11:49:56this meta title and meta description
- 11:49:58this is the result right here we see
- 11:50:00this SEO section we can provide SEO meta
- 11:50:04title here and SEO meta description here
- 11:50:08so let me click on Save
- 11:50:10changes good inside product resource
- 11:50:13when we return the product information
- 11:50:16on the product Details page we have this
- 11:50:18meta title and meta description returned
- 11:50:21and I'm going to open the show T6 and
- 11:50:23I'm going to change this so instead of
- 11:50:25providing title as the attribute inside
- 11:50:27the head I'm going to change this and
- 11:50:30put the head right here we need we have
- 11:50:32the product title we need the product
- 11:50:35meta title actually let's open the
- 11:50:38product and add right
- 11:50:40here meta title and meta
- 11:50:49description okay so scroll down
- 11:50:53below so we are using this meta title if
- 11:50:56that doesn't exist we are using the
- 11:50:58product title we using the meta
- 11:50:59description inside the canonical URL we
- 11:51:02provide the product URL uh we have the
- 11:51:05OG related things as well and inside OG
- 11:51:07image we are using images at zero and if
- 11:51:11that exists we are taking the small
- 11:51:13version of it and inside the app name
- 11:51:15we're going to use
- 11:51:18the app name let me import that like
- 11:51:22this uh
- 11:51:28okay so I need to change this
- 11:51:32into page
- 11:51:35props and then we need
- 11:51:39this okay so move this down
- 11:51:44so inside page props we have the app
- 11:51:46name so that's going to be good now
- 11:51:49let's stop these mpm run V server and
- 11:51:52see how server side rendering actually
- 11:51:54works in fact if we have this V server
- 11:51:56up and running and we check the product
- 11:51:58Details page let's see so let's CH
- 11:52:00choose this one click on this so this is
- 11:52:02the product Details page let's click on
- 11:52:05this product Details page okay and if we
- 11:52:07check the page Source we are not going
- 11:52:10to see anything um related so everything
- 11:52:13is client side rendered we don't see the
- 11:52:15meta titles or anything we don't even
- 11:52:17see the product details so if you search
- 11:52:19for the product title which should be
- 11:52:21there uh we see that only in two places
- 11:52:24and that places are actually inside the
- 11:52:26JavaScript array we don't see them
- 11:52:27inside html text so this is um how this
- 11:52:32is what we're going to fix so first
- 11:52:34we're going to execute mpm run build and
- 11:52:36this needs to be part of your deployment
- 11:52:39session so again if you're interested to
- 11:52:41see how to deploy this project on
- 11:52:43production with great SEO and serice
- 11:52:45side rendering imp implemented as well
- 11:52:48check my latest website on the Cod
- 11:52:50holly.com the Cod
- 11:52:53holic you I'm actually tired right now I
- 11:52:58said the cod.com theod holic
- 11:53:00youtube.com/ thee codol and check the
- 11:53:03following video full stack application
- 11:53:07build and deploy LEL 11 plus react fulls
- 11:53:10application so this is it you're you're
- 11:53:12going to check it and you're going to
- 11:53:13see the serice side rendering how to set
- 11:53:15up and continuous integration as well
- 11:53:18okay so in our case we executed mpm run
- 11:53:21build and then we're going to execute
- 11:53:24mpm uh not mpm but PHP Artisan inertia
- 11:53:30start- SSR so this is going to start
- 11:53:33serice side rendering through the using
- 11:53:35this built assets and now look at this
- 11:53:38so first of all our application is going
- 11:53:40to be super smooth we're going to see
- 11:53:41the glitch right here image glitch which
- 11:53:44I'm going to talk about it why it
- 11:53:46happens but this is uh it's going to be
- 11:53:49very super fast navigation everything is
- 11:53:52going to be great and if we refresh that
- 11:53:55specific page now we're going to see a
- 11:53:57few more things so here we see these
- 11:54:00meta titles So Meta title EO meta title
- 11:54:03meta description we see the canonical
- 11:54:05URL we see the title we see description
- 11:54:09inside OG image we see something else
- 11:54:13this is it so inside OG image we see the
- 11:54:15product image not
- 11:54:18the not the variation image what we
- 11:54:21should see right here so we should see
- 11:54:23this black headset but we see something
- 11:54:26else okay and that happens because we
- 11:54:29have something not 100% properly
- 11:54:33implemented and let me tell you what I
- 11:54:35mean so if we open uh product
- 11:54:40resource right here so we are using
- 11:54:42uh inside images these get media images
- 11:54:46and this always returns the product
- 11:54:48images okay then we get those images uh
- 11:54:52from the product images and then we have
- 11:54:54these images and that is calculated
- 11:54:57fully on the front end Side based on the
- 11:55:00selected variations but what if there is
- 11:55:03H
- 11:55:05um if there is something like if we have
- 11:55:08some options selected in the URL we
- 11:55:11refresh it and anyway we still see this
- 11:55:13girl which is the product image and then
- 11:55:16we see the this so this is something
- 11:55:19what we are going to change it and let
- 11:55:23me show you how we can do this so if we
- 11:55:26open
- 11:55:28now the product resource so we're going
- 11:55:32to change how we pass images right here
- 11:55:34okay so this is what we're going to
- 11:55:36change so we have options so let me
- 11:55:40actually take so we have the options
- 11:55:42we're going to take these options from
- 11:55:44the URL from the request and the purpose
- 11:55:47of this is that we are going to always
- 11:55:49return the images for the uh correct
- 11:55:53image from this so first returning
- 11:55:56product image and then on the front side
- 11:55:58on the react side changing in the with
- 11:56:00the variation image is actually causing
- 11:56:03this bad SEO thing so we need to pass
- 11:56:06the proper data from server to react and
- 11:56:09then it will correctly start uh it will
- 11:56:13correctly render this inside server side
- 11:56:16so here we get the options and then I'm
- 11:56:19doing the following so if options exist
- 11:56:21we're getting images for option and we
- 11:56:24do have that method defined in the
- 11:56:27product uh we get the list of images and
- 11:56:30if images doesn't exist we get um images
- 11:56:34and that get images basically is
- 11:56:39taking let's open this product so if we
- 11:56:42see get images so this is taking the
- 11:56:46first image set um from the first option
- 11:56:51okay so this is this is going to take
- 11:56:52the first uh variation option and return
- 11:56:55its
- 11:56:57images uh right here and this is going
- 11:57:01to get images for options uh don't we
- 11:57:05have
- 11:57:07that uh let me quickly get this method
- 11:57:12get images for options we should have
- 11:57:17that
- 11:57:19get images for
- 11:57:21options now we have get image for option
- 11:57:26for single image but we need get images
- 11:57:29for options I see so let's put this get
- 11:57:33images for options which is going to
- 11:57:36return the entire list of images okay so
- 11:57:41now now depending on if we have options
- 11:57:44we're going to get images for the
- 11:57:45options if we don't have options we're
- 11:57:47going to call get images which will also
- 11:57:50check if we have some options defined
- 11:57:52and if they have some images it's going
- 11:57:54to return them otherwise we're going to
- 11:57:56return this get media so now if we
- 11:57:59refresh the page this still happens
- 11:58:02because it is built in a different way
- 11:58:06so let's no hold on uh it should not do
- 11:58:10it let me
- 11:58:12let me go
- 11:58:16back and I'm going to open this product
- 11:58:19resource and I'm going to
- 11:58:23put images
- 11:58:26here images cool now if we refresh this
- 11:58:31now look at this so now we don't see
- 11:58:33this glitch we are using service side
- 11:58:35rendering but uh the SSR server does
- 11:58:38this properly if I refresh the page now
- 11:58:40this is changed
- 11:58:42and this is going to open the black
- 11:58:44headset I guess because the URL belongs
- 11:58:47to the black headset but if I view page
- 11:58:50source for this one which has options
- 11:58:52there as
- 11:58:54well now here we're going to see green
- 11:58:59headset okay and that is done on the
- 11:59:01server side rendering so we have the
- 11:59:03canonical URL right here and here to
- 11:59:05have the to be the URL without
- 11:59:08variations and the cool thing is that if
- 11:59:10you deploy this project and C copy this
- 11:59:12and share it on Facebook Twitter any any
- 11:59:14social media platforms you're going to
- 11:59:16get this nice preview uh be because of
- 11:59:19the OG text and just like this we have
- 11:59:23implemented uh
- 11:59:26great um great SEO on on on our project
- 11:59:31so I'm thinking that yeah we probably
- 11:59:33need to implement SEO on other pages but
- 11:59:36I will leave this part to you the main
- 11:59:37thing is that I showed to you how you're
- 11:59:39going to do this and again I mentioned
- 11:59:41this many times because this is
- 11:59:42important if you want to see how to set
- 11:59:45up this inertia with uh SSR on
- 11:59:48supervisor on VPS server check my other
- 11:59:51tutorial I mentioned and you're going to
- 11:59:53see the full steps how you can deploy
- 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.