Custom Magento Module Development - (Step by Step) - Techstricks [PDF]

Oct 29, 2015 - In this step by step tutorial we are going to cover the following points and actually develop a custom ma

2 downloads 12 Views 1MB Size

Recommend Stories


Step-by-step instructions (PDF)
Ask yourself: What holds me back from being more authentic? Next

Step by step growing
Why complain about yesterday, when you can make a better tomorrow by making the most of today? Anon

Step by Step Procedures
Just as there is no loss of basic energy in the universe, so no thought or action is without its effects,

Hajj Step by Step
So many books, so little time. Frank Zappa

Step-by-step Guide
You miss 100% of the shots you don’t take. Wayne Gretzky

Step-by-Step
Kindness, like a boomerang, always returns. Unknown

step-by-step instructions
Ego says, "Once everything falls into place, I'll feel peace." Spirit says "Find your peace, and then

Step-by-Step Series
Ask yourself: If you have one year left to live, what would you do? Next

step-by-step process
Learn to light a candle in the darkest moments of someone’s life. Be the light that helps others see; i

Step-by-Step Guide
Ask yourself: When was the last time I did something nice for others? Next

Idea Transcript


HOME (/)

SERVICES (HTTPS://TECHSTRICKS.COM/SERVICES/)

(https://techstricks.com/) CONTACT US (HTTPS://TECHSTRICKS.COM/CONTACT-US/)

Blog Post

Home (https://techstricks.com/)

Tutorials (https://techstricks.com/category/tutorials/)

Custom Magento Module Development – (Step By Step Tutorial SMSGupShup Module)

Search here...

Sponsored

Custom Magento Module Development – (Step By Step Tutorial SMSGupShup Module) (https://techstricks.com/custom-magento-module-development-step-by-step/) by Amyth (https://techstricks.com/author/amyth/) October 29, 2015 (https://techstricks.com/custom-magentomodule-development-step-by-step/) BLOG (HTTPS://TECHSTRICKS.COM/CATEGORY/BLOG/), DEV & DESIGN (HTTPS://TECHSTRICKS.COM/CATEGORY/TECH/DEV-AND-DESIGN/), DEVELOPMENT

Tags

(HTTPS://TECHSTRICKS.COM/CATEGORY/DEVELOPMENT/), MAGENTO (HTTPS://TECHSTRICKS.COM/CATEGORY/MAGENTO/), TECH (HTTPS://TECHSTRICKS.COM/CATEGORY/TECH/), TUTORIALS (HTTPS://TECHSTRICKS.COM/CATEGORY/TUTORIALS/)

Android (https://techstricks.com/tag/android/)

17 (https://techstricks.com/custom-magento-module-development-step-by-step/#comments) custom (https://techstricks.com/tag/custom/)

Developing a custom magento module It’s been some time since I wrote my last post as I have been busy working on numerous projects. Today I am going to discuss and step by step explain how to develop a custom magento module. Most of the tutorials, blog posts & articles that I found online explaining a custom magento module development were the “Hello World” examples, that may show you the basics but aren’t that helpful really. In this step by step tutorial we are going to cover the following points and actually develop a custom magento module that integrates SMSGupShup sms gateway (http://enterprise.smsgupshup.com/) to send sms text messages to the customers depending on different events.

development (https://techstricks.com/tag/development/) django (https://techstricks.com/tag/django/) Django Allauth (https://techstricks.com/tag/django-

At the end of this tutorial we will be able to:

allauth/)

Send SMS messages to our customers on the following events using SMSGupShup Gateway Welcome SMS on customer registration

elasticsearch

Thankyou SMS on placing an order

(https://techstricks.com/tag/elasticsearch/)

Shipment ID & Information on shipment sent Enable / Disable the module from the configuration

Error

Enable / Disable sending SMS for any of the aforementioned events Use custom SMS templates for the aforementioned events Use variables in SMS templates Have all of the above configurable via a configuration menu in the admin As this tutorial is going to be pretty extensive, Let’s Break it down into 2 parts:

(https://techstricks.com/tag/error/) fluentd (https://techstricks.com/tag/fluentd/)

1. Implement Customization Options

gcm

2. Using Customization Options

(https://techstricks.com/tag/gcm/)

So without any further ado, let’s get our hands dirty

google api

Custom Magento Module Development: Part 1: Implementing Customization Options

(https://techstricks.com/tag/google-

In magento, There are 3 code-pools that you can put your code into:

(https://techstricks.com/tag/installation/)

1. Core – Used for magento’s core modules 2. Community – Used for community modules that are available to us via Magento Connect (http://www.magentocommerce.com/magento-connect/). 3. Local – Used for locally developed modules, that do not fall into the above categories.

api/) Installation

iOS (https://techstricks.com/tag/ios/) Javascript (https://techstricks.com/tag/javascript/)

We are going to develop our custom magento module in the local codepool as it is neither a core magento module nor are we going to provide it via magento connect (as of now). Now let’s go to our magento root directory.

jQuery

Once you have reached your magento directory, cd in to app/code/local , This is where our custom module code

(https://techstricks.com/tag/jquery/)

will reside. kibana (https://techstricks.com/tag/kibana/)

(http://beyondroid.com/wp-content/uploads/2015/10/Screen-Shotmagento

2015-10-29-at-9.48.23-am.png)

(https://techstricks.com/tag/magento/)

So let’s start with creating a folder named after our company (you can use your own blog/company name). so we type

odd even formula

in mkdir Beyondroid (Beyondroid is our company name) and then cd into it using cd Beyondroid .This folder is root of all the custom modules that we’ll develop for this magento installation.

(http://beyondroid.com/wp-content/uploads/2015/10/Screen-Shot-

(https://techstricks.com/tag/oddeven-formula/) oddevenrides (https://techstricks.com/tag/oddevenrides/) odd even rule

2015-10-29-at-9.58.23-am.png) Now we create our custom magento module directory named Sms . So we do mkdir Sms and then cd into it cd Sms . Notice the capital letters in our directory names S in Sms and B in Beyondroid. This is because of naming

conventions of magento (http://devdocs.magento.com/).

(https://techstricks.com/tag/oddeven-rule/) Online APNS Tester

Now we create a etc folder in our module directory. This etc folder is going to contain our modules configuration files. Once you have created the etc folder go ahead and create a file named config.xml inside the etc folder.

(https://techstricks.com/tag/onlineapns-tester/) Online GCM Tester

(http://beyondroid.com/wp-content/uploads/2015/10/Screen-Shot-

(https://techstricks.com/tag/onlinegcm-tester/)

2015-10-29-at-10.12.16-am.png) options

Now let’s add the following code to our config.xml file

(https://techstricks.com/tag/options/) package (https://techstricks.com/tag/package/) People (https://techstricks.com/tag/people/) permanent redirect (https://techstricks.com/tag/permanentredirect/) Phabricator (https://techstricks.com/tag/phabricator/) phone (https://techstricks.com/tag/phone/)

Let’s see what we have defined in our config.xml file. 1. The tags contain your module information. So all the other blocks go inside the config tag. 2. The tag define the information like location of the module, version of the module. Do note the tag within the modules tag. This tag defines the location of the module i.e. Beyondroid/Sms directory in our code pool. So In case your Folders are named Myextensions and Awesomemodule the tag that you’d be using in your tag should be

pip (https://techstricks.com/tag/pip/) place API (https://techstricks.com/tag/placeapi/)

. Within this tag there is a version that defines the version of this place autocomplete

module. 3. Then we define our Model and Helper class location inside the tag. The global tag defines the scope. You can also use or tags if that is where you will be using your model and helper classes. I just feel comfortable using the global scope. 4. Inside the tag, we define where our models reside. So in this case Beyondroid_Sms_Model and similarly for the tag we have Beyondroid_Sms_Helper . As of now we have not created

(https://techstricks.com/tag/placeautocomplete/) place picker (https://techstricks.com/tag/place-

these directories and classes. So we’ll do that now. Let’s create the Model and the Helper directory inside our Sms module directory. So now it looks like this:

picker/) Plugins (https://techstricks.com/tag/plugins/)

(http://beyondroid.com/wp-content/uploads/2015/10/Screen-Shotpollywood (https://techstricks.com/tag/pollywood/)

2015-10-29-at-10.53.15-am.png) Next thing is to let magento know about our custom module. In order to do so we need to add a xml file named Beyondroid_Sms.xml (according to the magento naming conventions) at the location /magento-root-

properties (https://techstricks.com/tag/properties/)

directory/app/etc/modules/ . So we go to our magento root directory and do vim punjabi actor

app/etc/modules/Beyondroid_Sms.xml

(https://techstricks.com/tag/punjabi-

(http://beyondroid.com/wp-content/uploads/2015/10/Screen-Shot2015-10-29-at-10.59.43-am.png)

actor/) push (https://techstricks.com/tag/push/)

and put the following code into it.

push notifications (https://techstricks.com/tag/pushnotifications/) py2neo (https://techstricks.com/tag/py2neo/)

pymongo

In the above code the tag defines whether the module is enabled or not. The tag defines which code pool our module resides in. Once you have saved the above file, you should be able to see your custom module appear under Disable Modules Output if you go to System > Configuration > Advanced in your magento admin panel.

(https://techstricks.com/tag/pymongo/) PyPI (https://techstricks.com/tag/pypi/) python

(http://beyondroid.com/wp-content/uploads/2015/10/Screen-Shot-

(https://techstricks.com/tag/python/) tool

2015-10-29-at-11.42.21-am.png)

(https://techstricks.com/tag/tool/)



Volley

See it ? Good Enough now let’s get to the planning part.

(https://techstricks.com/tag/volley/)

Now, we need a way to provide customization options to the users in the admin panel. In order to acheive so we need to plan what customization options we will provide and how many sections are we going to divide into. For this custom magento module we are going to create 3 customization sections:

Web Operations (https://techstricks.com/tag/weboperations/)

General

Whatsapp

In general customization options we are going to provide the following settings fields:

(https://techstricks.com/tag/whatsapp/)

Base API Url – Just in case if the api’s base url changes in the future, we need to be able to change it through the admin panel instead of hard-coding it in the code. SMS Gupshup Username – This would be the username for our account with the SMS Gateway. This will be used for authentication on the gateway end.

Follow Us

SMS Gupshup Password – This is the password for our gateway account and again used with the username for authentication. Production Mode – This would be a boolean (yes/no) dropdown that defines whether our module is working in production mode or not. It’s handy to have this switch while you are in the development phase as you may not

(https: (https:

want to send a SMS each time while testing.

//faceb //twitt

Override DND – This is one of the settings provided by SMSGupShup gateway itself. If this is enabled the

ook.co er.com

SMS messages will be sent to the customer phone even if the customer has a DND service enabled with his service provider. Here we’ll just have a (yes/no) boolean switch and pass this data directly to the gateway API.

stricks ricks)

SMS Events

)

Under SMS events section we are going to provide yes/no switches for the events that we would want to send the sms’ on. Currently we will just use 3 basic events as follows: New Customer Registration – This switch will decide whether to send an SMS to customer after he has registered on our website. New Order Placed – This switch enables/disables whether to send an SMS when a new order is placed with our magento store. Order Shipped – This switch enables/disables whether to send a SMS to the customer once his/her shipment has been dispatched.

SMS Template For each event that we have defined in the above section we need an editable template that contains the content to be sent to the respective : New Customer Registration – This will contain the content for the SMS to be sent on new customer registrations. New Order Placed – This will contain the content for the SMS to be sent when a customer places an order. Order Shipped – This will contain the content for the SMS to be sent when a customer order’s shipment has been dispatched. So let’s create a configuration menu item and the above mentioned sections. To do this cd in to your modules root directory (in our case it is magento-root-directory/app/code/local/Beyondroid/Sms ) and create a system.xml file inside the etc folder and put in the following code.

In the above file within the tag we define our configuration tabs , sections and groups . Let’s look at each one of them Within the tabs tag we define our company company label. This will have a tab appear in the System > Configuration’s left side menu with the defined label as the tab heading. You can use the sort_order tag to position your tab in the menu. In the sections tag each entry represents a link under that tab. In the above file we create only one entry under the sections tag i.e. tag. The label for this entry represents the text that is displayed as the link under your tab. Within this section we define a groups tag. Under the groups tag each group would be representing our customization settings sections that we discussed earlier. So we add 3 tags , and . Within each of these tags we defined the fields that we require for the customization of our module.

Under each field use tags like , , , tags. Let’s see what each of these does. The tag represents the field label that is shown in the customization settings. The tag represents the comment i.e. shown under the field to help users understand what this particular field does. The tag specifies what kind of field is to be shown. The defines the position of the

field within the group. There are 3 types of tags each one uses whether the field is to be displayed in the respective view or not. if tag is set to 1 the field will be displayed in the default view in admin. Similarly and tags work to display the fields in the respective views.

To learn more about fields, tags and configuration in general you should also check out this amazing post (http://alanstorm.com/magento_system_configuration_in_depth_tutorial) by Alan Storm. Now in order to view the menu in the admin, there is an additional step that we need to take i.e. create the Data.php file in our modules Helper folder and add the following code to it.

Now log-in to your magento admin panel and navigate to System > Configuration. You should be able to see your custom module tab on the left sidebar

(http://beyondroid.com/wp-content/uploads/2015/10/Screen-Shot-

2015-10-29-at-2.13.13-pm.png) But when you click on the link, it will give you a 404 error. In order to see our configuration sections and field there are 3 additional steps that we need to take. 1. Create a adminhtml.xml file under our module’s etc folder and put the following code into it.

2. Define default values for our fields. (This is optinal but is a good practice.). we will define the default values for the fields in our modules config.xml file. So open that file and add the following code. The following code snippet show the whole content, make sure you have just added the content in the default tag in your existing config.xml

3. Now logout of your admin panel and log back in. Go to System > Configuration > SMS Pro (gupshup gateway) and you should see your configuration options as follows:

(http://beyondroid.com/wp-content/uploads/2015/10/Screen-Shot-

2015-10-29-at-3.24.50-pm.png) So now we have our magento custom module’s customization options in place. To make use of these customization options Go To Page 2 : Custom Magento Module Development: Part 2: Using Customization Options (http://www.techstricks.com/custom-magento-module-development-step-by-step/2/).

Pages: 1 2 (https://techstricks.com/custom-magento-module-development-step-by-step/2/)

Tags In custom (https://techstricks.com/tag/custom/) magento (https://techstricks.com/tag/magento/)



SHARE

m/tech /techst





development (https://techstricks.com/tag/development/)



module (https://techstricks.com/tag/module/)

(https://t

19 / 56

(https://t

echstrick

echstrick

s.com/tr

s.com/cr

ansfer-

eate-

android-

directori

contacts-

es-

to-

recursiv

iphone-

ely-in-

in-

ubuntu/)

under-2minutes/ )

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.