How To Create A Magento Modules

I’ve said previously that you sent me some requests and I’ll try and get to him so I think I saw in the discussion, by I’ve been here can he do some module creation tutorials. And I certainly can. What I did was I had created a very small one and a very simple one, and the reason I did that is because creating a module isn’t difficult. What’s difficult about it is getting the files and folder structures correct and you’ll almost always fail in the first try, just because of the folder structure. Magento is a huge pain in the ass, so the module today is going to be adding something to the log files. It’s going to be adding a file here that tells you when something was updated.


1.How to boost sale with Magento plugins 

2.Top Magento Plugins Development Companies 2017 and others

3. Top Magento 2 Marketplace Plugins 

And this way it also gets you explain more to you rather than just you sitting me watching typing all the time. So we’re going to start going to add etc modules and the way that you name a module is you don’t want to duplicate another modules name because obviously, those would conflict so you start it with or traditionally, you started with your company name underscored your module name that. It’s not going to be another company with the exact same name with the exact same option so it’s an XML file and once again it’s an app etc module. It’s an XML and you go config modules to register your module here, and you have my company name and then underscore and then this one is named log product update. And then all you have to do is set it to active and add the cold pool and in this case, it’s local and I’ll show you why. So that’s what you need to get your module registered, I hope I’m not talking too soon but you can see if your module is registered. If you go to your system configuration and then you go to advanced and my company name, right there.

That’s all you need to tell Magento hey, it’s there. You’re going to need to do it in another place too,  so that one’s a nap etc modules and company name extent module name.  Then we’re going to go to app code and if you’re running a clean install you’ll have echoed community and core. You might not have a community, probably do, comes all these things that the team at variance / Magento have created which include all the base things that you extend in your classes, and community is usually the free extensions that you’ll find. Over for the community I highly don’t recommend that you use Magento connect to install anything which you’re going to use which is better is a called freegento, and what you do is you copy and paste the extension keep there for the free module, submit then you download that and then you’ll get all the files and then you just upload your files to the root directory. Magento connect will leave things behind if you need to remove an extension. And you notice here in our in our etc module as well active is true. If you have an extension that’s bugging you that you installed and you can’t get to the admin panel to disable it, you can just set it to false right here so this is for the free stuff that you’ll find in Magento connect and stuff like that use the base things then you create a local one which is for your company, which is an internal module for you guys. So you have to like I was saying about the file structure you see this payment yes you have to make that the directory structure. Okay and then you go to you create that and then you create an Etc folder and you have another configuration folder.

Now don’t pay attention to the global right now just pay attention up here. We have my company name underscore once again with the file structure and you give it a version, typically what you do is there’s three decimal or two decimal places here the first one is usually for major releases. This is a reminder, this is for somewhat minor releases and these are usually minor bug fixes. So our module is going to be updating a log file so we need to hook on to the save function, so we’re going to add global modules log product update and we’re going to be creating a class in PHP and this is going to be the class, and then you close out of that and then the event that we’re hooking onto is catalog products save after. So once the product is saved, what happens after work?

We’ll observe the class right here, then we have our class name/ method is going to be log update that is the function and type are singletons. If you’re familiar with PH,  a singleton is the only instance of a class. Then you close these out right here pulls out events and it’s all in config, so you have your module registered , and then you tell it what function is going to look for. Within log product update, we have model and observer, and like I said the class that was mentioned in here, is public function right there and it takes an argument. So you use that argument, the object that’s passed in to get the product name, so product observer, get event get product which is the product being saved

Then we’ll get the product name and the SKU and we’ll write that to the log file, so mage vlog name SKU so this will this is literally what will get written to the law file. So the log file will have the product name followed by the product SKU and then we’ll stay updated return null because we don’t need to do anything after that. And then this is the name of the product update file that will appear on the logs. Those are going to matter, going to save, wait for it to save and we’re going to go into our bar logs folder and now this appears. And now it says the test product the SKU of test was updated. You should note a couple things here, make sure your module is enabled, make sure you clear your cache once you’re done. If for some reason that doesn’t clear, go to bar cash and you can manually delete all these right here, that sometimes very helpful if we gentle gets a little buggy which kind of does sometimes a very love/hate relationship with Magento. And the other thing that you want to make sure of: go back to system configuration and I’m going to go down to developer, and go to log settings and put the set to yes. I think by default it is set to No, so save that and you should be good to go with your next module. I hope this helps any other recommendations for tutorials or questions about this, just let me know. So thanks, everybody and have a great day.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s