 people. This is not my usual audience. So cool. So thank you, BHB Conference Asia. It's good to be back in Singapore. I had to be in the region anyway and this really kind of gave me a good reason to be here. So my name is Ben Marks. I work for Magento. I started out as a developer when Magento came out back in kind of 2008 and just kind of accidentally started talking about it too much online so they hired me to kind of continue talking about it. These days I spend most of my time traveling around to lots of Magento events that happen around the world that our community, which is super fantastic, they put on for us like on our behalf around the world. So I had a feeling though that I might not have too many Magento developers in the house. How many of you are working in e-commerce space? BHB. It's this guy down here. Okay. Cool. So I mean really for me I think one of the important things to think about is like, you know, why Magento? Some people have opinions on this I know. But fundamentally we're just trying to solve the problem of commerce. And commerce is, it's a really interesting space. If you've not, if you've not had to develop for like a commercial application, oh you're sweet. Thank you. Is that fresh spring water? Okay, good. So yeah, commerce is a really interesting space. It's full of problems and then when you go, especially when you take, you can solve for problems in one region and then when you have to go to another region and build an application that works sort of all over the world, you end up with really interesting challenges. So the founding principle of Magento, like way back in the day, it just started with a couple of guys from UCLA. They had a web dev company and they were using OS commerce. So this is back like 2005, 2006 for their increasingly sort of higher profile clients and eventually they just said hey, we can't really have reliable release, releases or maintenance with OS commerce. So they had this idea let's build an application, let's build an application that is sort of a framework first and then we'll build the e-commerce app out of that and we'll sort of build it around being customizable. That's been the core tenet of Magento for a long time. So these days, it is still an open source application. So we have kind of two versions if you will. There's our like fully open source, grab it from GitHub version and then we also have an open core so it's still readable but is licensed for enterprise use. And that just comes with more features and support and things like that. And then there's a whole bunch of add-ons that we have, business stuff that probably isn't terribly interesting to most of you. I'm happy to talk about it afterwards. I did throw in Adobe because we kind of fall under now we were just acquired by Adobe and so we fall under their digital experience side. A lot of us know the creative cloud side. But we fit into this whole strategy that they have that's way above my pay grade. I'm just a lowly developer community advocate. So as I said, entirely customizable. It actually is a rapid application development framework. I mean it is already an application in its own right. But underneath all the e-commerce stuff there is essentially a PHP MVC framework that you can work with and build stuff with. We're in version two now but in version one it was actually a community project that took all of the e-commerce stuff out of Magento and just had it as a PHP framework. It was an interesting experiment but you can also do the same thing today. In fact the whole framework is abstracted away from the application space. And then I think one of the important things to remember if you're getting into the Magento world is that it's built for multiple website scopes. Basically if you have an English site and a Mandarin site and a Kanji site, those can all run off of one instance. You can also use that for brands, specific brands or whatever need. Another advantage of using any e-commerce app that has a big community around it is like in the case of Magento you have thousands of third party extensions and then also sometimes that's just changing functionality. A lot of times it's integrating with things like shipping providers and payment providers. For me, like why do I do this? I spend about ten months out of the year on the road going out and hanging out with our community and that's really where it all comes down. Magento actually kind of sucked for a little while when we were under eBay at community relations. We kind of got away from our open source core, like our roots. But recently, February of last year, we pulled five of our top architects together onto a team and now they just go around and help facilitate community contribution. So those of you who know Magento know that it's not small. Our releases tend to have a big footprint. These days over 50% of the code that is new in Magento is written by our community. So I think that's actually a pretty strong example of open source engagement. It's a $5 billion a year service economy that's people in the business of just servicing Magento installations, creating customizations, et cetera. So there's a lot of opportunity there if you're interested. Globally we power a whole lot of commercial volume. But for me, it's really this fantastic developer community. This is from our big event that we have every year in Vegas. So with the preamble out of the way, we have documentation which is good. Back in the Magento one days, we all know the developers lie that we tell ourselves like when we're running up against deadlines, we'll write the documentation when we're done. Unfortunately what some wise people did a couple years ago is they actually hired tech riders to work with our product team and write some documentation. So we have, we actually have some fantastic, I'd say pretty good, maybe stellar documentation. And the cool thing is actually all of this documentation is on GitHub so you can file an issue, you can contribute to it the same way you can to the core. Alright, so installing Magento 2. I will actually, I should probably step back a little bit. Magento 2 is, it's a very big application. It's made to work all over the world. It does a lot out of the box and it's built to be, again, fully customizable. So that comes with a fairly substantial architecture. First thing you should do is read the really freaking good manual that we have. I know you're wondering what I was saying there. We have, that's a really good place to start. You have three options when you want to install, like when you want to work with Magento. There's the composer meta package, right? So you can just, just like you would just do composer create project, that's probably the preferred method, like that's an instance that you're going to maintain for a customer or for yourself to mess around with. We also have a kind of a contribution flow where you would just clone our GitHub repository directly. And then the third option actually isn't an option anymore. It used to be, it was basically this kind of self install, the self install route, but you can ignore that. When you are, when you're getting into Magento development, just like a lot of the frameworks that you all are probably used to working with, we have a console, a developer console tool, Ben Magento, just a CLI, it's a symphony CLI component, relies on the symphony CLI component. It's essentially the, you know, the multi-tool of the Magento world, just does a lot of the low-level stuff that needs to be done to get your job done. There's also a community maintained additional CLI that has, it's like the Swiss Army knife, and that's N98 mage run. Right, so Magento has a couple of modes. It actually has three modes, but one of them doesn't count anymore. You have developer mode and you have production mode. Production mode essentially materializes a lot of the class definitions, the static assets that are used for the front end, basically reduces the overhead of running the application. Developer mode is a little more introspective, and so as a developer, when you're working with Magento, like this is one of the key things when I was, like when I was running a dev shop, that developers would forget actually, is to turn on developer mode. Without that, the application is going to hide a lot of the errors. So you're not going to get that good developer feedback, like, hey, stuff's broken. Cash operations, you're going to disable those as needed. There are multiple caches in Magento, so if I actually, let's see, run status here. So can you see that? Okay. Right, so up here we have multiple cache types, and Magento is pretty aggressive with caching things, but breaks them out, sort of so that you as a developer can enable those and disable those depending on what area you're working in. Really, as a developer, the main thing you have to remember is that you need to, like, if you're making a change in the configuration area, well, you need to actually either disable that configuration cache in order to realize those changes, or just make sure that after you have some development iteration that you refresh that cache. So far, so good. By the way, if you have any questions, feel free to throw them out there. We also added, I think this was a, I think this was a community contribution.idea generation, so those of you who know and love PHP Storm, okay, it's, it really is an essential tool for the Magento, for Magento Development World. I only run into a few people every once in a while who are still hardcore, hardcore VEM enthusiasts that work in the Magento World. Pretty much it's all in PHP Storm these days. But.idea generation just helps with resolving some of the schema definitions and a couple of other things. We also have sample data. So what I have right here is a Magento instance that has no product data, no catalog data. This is essentially just a really, really massive CMS at this point, right? But of course the idea is that you'll have categories, you'll have products, you do have customer account functionality, etc. But there are some, it's actually possible to install, to install our sample data. It'll give you categories, products, some orders, and some customers that you can actually use while you're testing out the application. We also have our data fixture generator. This is the documentation for that here. This allows you to test if you're building a customization that like may impact an index or something. This is what you would want to, this is what you'd want to work with to make sure that your, that your work isn't doing something like loading, loading product data sort of sequentially in a loop. Because it's an expensive operation in Magento. So I, the title of this talk is a Magento module in 40 minutes or less. Now I will give you the caveat that, what do I have like 15 minutes left? I'll give you the caveat that I have not, I haven't exactly been an agency developer in several, several years and probably my last, my last really productive code shipped about a year and a half ago. So we're going to give it a stab. But I think most of us here are working, are familiar working with some framework that we like. Whether it's Laravel, Symphony. And in that world you'd like to pack, pack up your work in, in modules. And Magento is the exact same way. So a module in Magento can actually live in a couple of places. It, it can live if it's a local, if it's a local customization for a client or if you're just, you know, if you're just playing around and kind of digging into the, digging into the application and discovering what it does, you'd put it under app code, your name space, and then some, some module name, right? So just a, just a folder path. If you are distributing a customization, then you would probably have a composer, Jason, declare your version, your dependencies, etc. And it would install here under, just when you, when you do a composer update, it would install here under vendor. In fact, again, here is, here is the Magento installation if you do composer create project is going to live under vendor, vendor Magento in a series of modules, right? So these are all mostly decoupled. There are still some soft dependencies, but those are being kind of teased out slowly. You also have here the framework. So again, this is the actual kind of the, the internal machine of Magento here. And what you'll see with just a couple of exceptions is essentially all of these components are, are, are, are injected into the application space, right? So we don't have, we try to not have hard dependencies. There are a couple that are left over from like the early days of Magento 2. And again, those are also being teased out. Okay. So what is a module in Magento? Well, we have registration.php. This just gives some, some basic information about the component that you have. That could be a theme, that could be a module, a couple of other things. We also have a module.xml. This is just a basic configuration that, that, that Magento needs to, to, to maintain parity between the database and the file system for the purpose of migration. So what that looks like here, if I pull this out. So right now, again, I have, I have this nice, you know, this nice application running my, my normal homepage. Once I actually take this registration module, I'm sorry, the registration.php and essentially register this module. What's going to happen if fingers crossed? Okay. So I, nothing happened. So I need to clear a cache, right? So I will just call cache clear and let's see. While I'm here, let me jump forward. I should also point out that Magento, if, those of you who know Magento, which I guess is just a couple of us, I think if you're familiar with the Java world, it should be pretty apparent to you that it was a lot of Java developers writing PHP to come up with Magento. So, you know, we have, we have a lot of this, the same, similar architecture, architectural patterns. We also have a lot of XML. And in the Magento one world, that really, it was kind of a pain because there was no schema definition, right? So as long as it was sort of syntactically valid, you never knew whether it was like sort of functionally valid. In Magento two, we have schema definitions for all of these and you can, you can create and customize your own schema definitions and XML types if you want. Magento takes all of this XML and merges it into like common DOM trees, right? So you have, you have these, these DOM structures across various configuration types. So we'll see here, I haven't, I haven't broken anything yet. Now what I want to do is I'm going to run then Magento module status. And so what I have here is a list of all the modules that are in the system and enabled. And then you see I have one down here that is not enabled. So I'm just going to run module enable and you can use shortcuts here like in any symphony app. All right, so the system is giving me some good feedback. It found, it basically picked up the fact that there was a registration file there, but it doesn't have an entry for my module inside the database. And the place that it would find that is in setup module. So you can see here also in the database a list of modules that are installed. Now we have just to, according to the feedback, I need to run setup, I need to run setup upgrade. So I think now what will happen, fingers crossed, right? This is actually a good thing. I know certainly in the PHP world we like to at least get output sometimes from, from, from whatever we're working in, even if it's an error, even if it's an error message. So here what we have is the application telling us, hey, you've got this module in the file system, it's, it's been enabled, it's been sort of registered in, in with the application, but it hasn't actually, we haven't run any migrations for this. So the application is aware that there's, there are files in place, but there's not a corresponding migration that's been run in the database. So all we have to do is run setup upgrade. And what's happening is internally, so the application's going, running through and looking actually at the, the, the registered version in the database, as you can see here, and then looking at the, the version in the file system. And I'll show you what that looks like in just a second. And whenever there is either a new module present or module versions have, have changed either up or down, the application is going to look to run just some PHP scripts that, that are designated for updating the schema. So what this looks like in the application, here. What caused this was the combination of the registration. Let's see. Bless you. Presentation mode. There we go. All right. This is what a registration looks like. This is, there's, there's a little bit of boilerplate like in any application. Whenever I'm doing development, all I do is just open up another module and I'll show you a couple reference, reference modules to get going. But open up another module, copy it, change the relevant bits. Or even better, if you're using PHP Storm, just set up a, set up a live template. All right. So we have, that's our registration on PHP and then in our ETC folder, just a little bit of XML. And what this does is this says, hey, you know, here's a, here, here we're registering a module and this is required according to the schema definition, which is, which you can find here. What this is doing is this is actually just saying, hey, we have a module present, this is the version. And so what's going to happen is the application will look for, look for setup scripts, not find any, and then register that module in the database. So if I refresh this view here, you'll see now my module's registered. Right? So used to walking around. So that obviously doesn't do shit. Right? I mean, all that does, I mean, you could, you could play around with the XML and that's one good way to test, actually to test Fingento is to see if your config is being merged in and being evaluated, just break the syntax. Obviously you can, you can set, set up like break points in the, in the parser for the XML, but really it's, it's quick, it's quick just if, if, for example, like my, I hadn't seen this error message here, I might have said, well maybe I've got my stuff in the wrong place. Let me just see if, if my XML is working. And then I could go here and just break that. So that's, that's the practical matter. But I do like to point this out because Fingento is, I think it has a reputation for being big. A big application, big space. This is, this is fundamentally the smallest module that you would have. Right? So, so everything starts from here. And if you happen to have any exposure to Magento one, there was, there was a whole lot of boilerplate configuration that you needed to have to do anything else. We got rid of pretty much all of that. So it's a, it's a bit more conventional now. It'll feel a bit more familiar. Also, I should point out that if you are, again, if you, if you came from the Magento one days, Magento came along at this really strange time, sort of before like the only, I think the only, they're like four people in the world doing unit testing in PHP. And one of them is here. So unfortunately Magento one wasn't covered by testing. It, it wasn't built for a lot of like comm, commodity computing, et cetera. So it's, and it's now whatever, 10 years old. These are a lot of things that have been fixed for M1. And then, and then actually a lot of us coming out of the Magento one days, we were pretty siloed. Like namespace usage wasn't that common. Composer really wasn't in our, wasn't in our, our world. The, the application's been certainly modernized for that purpose. And according, according to Rasmus, is the slowest app ever. Yes. No, I, I, to, to is better. I, I, I'm gonna share, I may share a story that I share about the first time I got to meet Rasmus in New Zealand. We were getting in the little mini bus going to the speaker's dinner and just happened to sit down next to each other in the back. And I said, I'm, I'm Ben from Magento. He's, oh shit. Yeah, it's, it's been, it's been quite a learning experience in, in, you know, sort of meeting our community in the middle, gaining some, gaining some discipline as a product company. And, but I know Rasmus and, and several others have been, Magento is one of those apps that you have to benchmark because it's, it's such a prevalent app in the, in the PHP space. We've definitely benefited a lot from PHP 7. That was, that was like our biggest performance upgrade was just the fact that 7 exists. Okay, so from here what, what else can we do? Well, I'm running out of time, but I will say we can also register a route. This is I think the next most important thing that you can do as, as someone getting used to Magento. And that is just a little bit of configuration. Again, you would copy this from another module. You have an arbitrary ID except it does, it does feed into the view and I'll, I'll run through that in just a second. Front name actually becomes part of the URL. And then after that, you just have basic controller path mapping. So now that I've actually jumped a little bit ahead, I will go to the controller. So you just register a route, a little bit of XML, create your controller action class, and then make note of your front name. So all I have to do to get this to work, theoretically, is create, well, so I've registered my route. Front end, you have, you have several different areas under your configuration folder. Front end, admin, there's a global area and then one or two more. But as someone getting into Magento, you'd probably just play around with the front end to begin with because I always like to have an application, figure out how an application, sort of, I can get it to execute whatever I put in the browser path. So this simply says that I now will have a route that starts with sample. And based on the fact that I have an index folder and an index controller, and the, our controller actions are still one, one of the spaces in the application that inherit their functionality as opposed to having it injected. That's, that is being refactored. Now I execute, just to find the execute method and do whatever I want. So theoretically, if I go to, if I go to the, on the sample route and the index slash index is arbitrary, theoretically I should see something. I actually, I don't think I will here. Oh, oh, oh, well, of course. Well, the good thing is, at least I broke something. Put this up here for a second. That's the observer configuration. What I need to do now is, so actually this is a good, this is a good error to have. What's happened is I have, I have some config XML that's been merged and, and cached. But I've made changes to the file system, but those haven't updated because they've been cached. So what I'll do is I'll just jump in here, do a bin magento cache clear. Nope, that should probably spell that correctly. Config. And then, oops, oh, clean. Cache clean. Config. And then I may actually need to kill some generated code. Now, fingers crossed, I'll have my controller action working. While that's, while that's going on, let me step quickly through some other aspects. We have, just like any PHP app, we have our own ORM. We have our own ORM because we have this whole convoluted data structure for entities with arbitrary attributes like products, customers, addresses, things like that. But essentially they're broken out into three tiers. Model, sort of this entity that you work with in your application. The resource model which is used for, resource model which is used for actual retrieval of data. And then collections which you use to kind of work with groups of entities. As I mentioned earlier, there are schema migrations. We also have an entire service contract layer which basically just PHP interfaces into business operations and data. We're currently working on, we're working with Google on progressive web app for our front end. And along with that, we're working with the community to build out just a full GraphQL implementation for like our entire, for our entire app. And we just merged message queues from our enterprise product back down into our open source product. So that's also there. When you are, when you are looking at, when you're looking at a magento view, you're actually looking at PHP classes for logic that call PHTML template files. And essentially what ties everything together in context is layout XML. Let me see that. For customization, we have, we use dependency injection throughout the app. Again, the framework itself is injected. We also have an observer implementation. And then we have this thing called plugins. So as you, as you start to get into magenta development, I would say look at, look at plugins as, as the ultimate way to extend or modify the application. What it does, what our plugin system does is it allows you just with a little bit of XML to turn every public method into a consumable event in the application. That is really, really powerful and also really, really scary. If you've ever inherited any application from some other developer, you usually did because they screwed up. And the, the, our plugin system actually gives people all sorts of interesting ways to really, really screw up. That configuration, that configuration is just as simple as calling a class or referencing an existing class, calling a class that you create just a standard PHP class, and then matching a method name from this class, and prepending it with before, after or around. And your code will execute before, after or around that code. All right. So as I mentioned, there are, there's a testing framework. We have all the tests. We functional integration, unit testing, of course. I mentioned data fixture generation. We have an extension quality program that actually is an extended set of tests that you can, you can run all of your custom development through that is the same test that we use for all of our third party apps. And then these days we have an open backlog with the community. And that includes architectural collaboration. So again, I mentioned our, I didn't mention them by name, but our community engineering team goes out around the world and is also present every day online, helping to work with our community to fix issues and to build new features. All right. So resources for you if you want to get going. I suppose if you have, if you have some interest in Magento, this is a good, a good reference. Again, our developer documentation is, is, is quite good. We have our Magento engineering, a community engineering team there on Twitter, Magento Engcom. They also have a Slack channel where they're present pretty much 24-7. A really good reference is mage2.tv. This is a, this is a screencast series written by, or authored by my, my very close friend Vee and I caught in Germany. If you really don't want to fuss around with setting things up on a number of community initiatives around developer tooling and developer environments, we of course have our forums. We have the Magento Stack Exchange which I started six, seven years ago, six years ago. And then there are a lot of meetups around the world. There's over a hundred Magento meetups. There's also a 30 event, about a 30 city event series called Meet Magento. That actually I was just in Poland, that's where this shirt came from, that's put on by our community. And then coming up in Bangkok in the beginning of November is Meet Magento Asia. So there are a lot of Magento developers around Asia. Just in Vietnam, Meet Magento Vietnam two years ago was over a thousand people. So I expect that Meet Magento Asia is going to be, going to be pretty big. And of course if you, it's a little bit late but we had Meet Magento Singapore not too long ago, I guess a couple months ago. And that's it. That's literally all you need to get going with Magento. If you have any questions, I'll be around out here and I'll be happy to address them. If you have any questions now, feel free to call them out. Oh shit. How do you make the plug-in thing fast so that before, during, after? Is it all through code generation? Exactly. Good question. So what we do is, so what we have, if you look down, see if you look down here, in var generation, there's actually, or I'm sorry, generation, generated, generated. There we go. Generated code. Yeah, what you have here is, so all that, all that, all the things that have been pluginized as our Ukrainian developers term it, we take these, class definitions and essentially materialize them. So it's part of your developer workflow. One of the things that you'll need to do is, depending on some of the work that you're doing, you may actually have a materialized class here that you'll need to basically refresh that whatever's been compiled. And I think actually if I can tag on to that, one of the questions that I get is why not use one of the existing dependency injection containers? And the big reason is that, you know, on any execution scope, that dependency, like that sort of object management environment is being executed, you know, maybe thousands of times, if you're not in a, if you're not in production mode. So we actually just wrote, we wrote one of our own just so it could be exactly what we need. Right. And just to clarify the, the slowest app ever, that's Magento one. Yeah. Magento two in production mode is pretty damn fast for all the things it does. That is, I actually literally, if I have a heart attack, it's like the happiest heart attack on the planet right now. Now it's been, it's been, it's been a, it's been a really, I, for me, it's always personal. Like I have watched, I have watched my, my friends and peers, people I met in the IRC channel 10 years ago, go from independent developers, they now have companies, they feed families, they're, they feed their employees families, they have houses, they go on vacations and all this stuff is kind of in and around Magento. So this is, it's a very big, it's a very big world. It's, it's a tremendous amount of responsibility for us. It's, it's, it's a tremendous honor for me to be kind of a part of that. And we really, really welcome anyone, anyone to look into things. If you want to get going with Magento again, I'm, I'm, I'm super easy to get a hold of. I don't know what Adobe is going to do to that email address. Someone already has been at Adobe.com, I checked. But please feel free to reach out. So thank you.