5 Reasons to Develop Your Ecommerce Website with Magento

Ccommerce Software Usages

With a business presence on the web world, chances of getting globalized brighten. It is the fashion of eCommerce functionality that is gaining pace and is spreading like a fire in the forest. In the wake of reaching to a maximum amount of clients, companies are grabbing opportunities to move their attention towards eCommerce website development that help them in patronizing global reputation. (more…)

Joomla Module Development Part I

This article is to teach you how to develop your own custom module around joomla CMS. This course will start with simple joomla module development and will move on to teaching extensive joomla development.

Joomla is a most widely used and popular content management system. If you are a professional or freelance website developer, many times your client might ask you to develop website with joomla or you may propose a certain website to be developed with joomla. Joomla comes with lots of features buts its not possible for a CMS to cater all your project requirements. Joomla development skills comes very handy in situations like this.

Developing a Simple Joomla Module – Lets start with a hello world kind of module with joomla. First of all we need to create a folder for our module that will have a name starting with mod_ followed by name of your module. so if we want to create a module having name helloworld, we will create a folder named mod_helloworld in our computer.

Inside that mod_helloworld folder we will create two files (only two files are required for a basic module). One xml file that will tell joomla about our module and one php file to perform our intended task for the module. Name of these two files must be same as the name of our module so two files created will be mod_helloworld.php and mod_helloworld.xml.

What will go inside these two files?

Lets open our favorite text editor (I am fan of adobe dreamweaver) and create a new file xml file and save it the folder you created in starting and name of the file must be mod_helloworld.xml.

Lets understand each line of code one by one:

First line says about the xml version and its character set. Actual code of our module starts with the tag and attributes of this tag defines the type of extension, version of joomla and client. In our case type is module as we are developing a joomla module, that changes to component if we are developing a component or to plugin if we are developing a joomla plugin. Version is the version of joomla for which we are developing our module. 1.6.0 works in all versions of joomla 1.7 and joomla 2.5. Client tells the area for which we are developing the module. Site means we are developing it for site part, other possible value can be admin if we want to develop a module for joomla admin section.

here is the explanation for each tag inside extension tag

<name> tag contains the name of your module that is mod_helloworld in our case. change if you are developing it with your own name.
<author> tells the name of author of the module. change it with your name
<creationDate> of the the module
<copyrights> name of the party, individual having copyrights of this module
<license> license text of the module
<authorEmail> email id of the author
<authorUrl> URL of author’s website
<version> version of your module
<description> description about what your module do.

Next important tag is files. It tells joomla what are the files to upload while installing your module from admin section. Each file is specified individually with a filename tag inside files tag. One important thing to note here is module=”mod_helloworld” in first <filename> tag. It should be always the name of your module.

At the end of this file we close the extension tag. Now lets move on to the another file of our module that is mod_helloworld.php. This file is actually responsible for printing the output of our module.

Just three lines of code and out of that the first one is the start of php tag itself. Second is most important one and goes in every php file of weather we are developing a module, component, plugin or template. We use this line to prevent direct access to our code, that means if our website is www.example.com this line of code prevent direct access to www.example.com/modules/mod_helloworld/mod_helloworld.php in web browser address bar.

Next line is a simple php echo statement, announcing your first joomla module! We can output whatever we want here.

Download the zip file of exercise and post any question comment below. In the next tutorial we will learn how to add module parameters and use that in frontend.

Ajax reqest in joomla 1.6 and later

Due to Mootools version change in joomla 1.6, ajax request would not work the way it used to work in joomla 1.5. In this article we would discuss how to get ajax request in admin part of a joomla component for version higher than 1.5. We will take a typical example of Loading state of a country so that even a new joomla developer can understand it.

I suppose you are following MVC architecture while developing your joomla component. In the edit view of your component open edit.php file (or whatever if you have renamed it). Render the country form field like below –

  • form->getLabel(‘country’); ?> form->getInput(‘country’); ?>

Now add below code to load your default state list box –

  • form->getLabel(‘states’); ?> form->getInput(‘states’); ?>

Note the span tag with ID “ajax-container”. We will load the list of state returned by ajax request here once a user changes country from the above dropdown. We are not done with the html part of our ajax request.

Now we will add a onchange event to our country dropdown using below javascript –

document.addEvent( 'domready' ,  function() {
$('jform_country').addEvent( 'change' ,  function() { 

	$('ajax-container').empty().addClass('ajax-loading');
	
	//Ajax Request start here
	var myElement = document.getElementById('ajax-container');
 	var cid = document.getElementById('jform_country').value;
	//alert(cid);
	var myRequest = new Request({
    url: 'index.php?option=com_country&view=items&task=getstates&format=raw',
    method: 'get',
	evalResponse: 'true', 
	data: { 
	'id' : cid,	 	 
	},
    onRequest: function(){
        myElement.set('text', 'Loading. Please wait...');
		myElement.addClass('loading');
    },
    onSuccess: function(responseText){
        myElement.set('html', responseText);
		myElement.addClass('success');
    },
    onFailure: function(){
        myElement.set('text', 'Sorry, your request failed :(');
		myElement.addClass('error');
    }
}).send();



 } );
});

Now we will create a function in controller file of our component that would respond to our ajax request. Open controller.php located at administrator/components// and below function in that –

	
	function getvendors()
	{
		$db 	=& JFactory::getDBO();
		$query = 'SELECT id, title FROM #__product_vendors where published = 1 and catid  =  '.JRequest::getInt('id');
		$db->setQuery( $query );
		$vendors = $db->loadObjectlist();
		echo '<select id="jform_vendor" name="jform[vendor]">';
		echo '<option value="0">-- Select --</option>';
		for ($i=0, $n=count( $vendors ); $i < $n; $i++)	
		{
			$row = &$vendors[$i];
			echo '<option value="'. $row->id.'">'.$row->title.'</option>';
		}
		echo '</select>';	
	}

That’s it. Your ajax request should load states of the selected country. Please use the comment box below if you face any problem with the above code. Please also comments if you think there is a better way to use ajax in admin part of a joomla component.

Categories