Like Quertime on Facebook!

Best Tips and Tricks to Configure Magento for Development

Filed under Web Development

Anyone who is new to Magento needs to figure out how to set it up properly but fortunately configuring Magento for development is not that difficult. Keep in mind that these tips only apply if the application has been installed.

custom_magento_development

Setting up Magento: Basic Steps

1. Go to System > Cache Management > Disable All.

2. Next go to System > Configuration > Advanced > Developer > and head over to Log Settings. Choose the Enabled option.

3. Again go to System > Configuration and head over to Web and to Search Engine Optimization. Click Yes for the Use Web Server Rewrites.

4. Go to System > Index Management and choose Reindex all.

5. Go to .htaccess and configure the following at the end of the file: etEnv MAGE_IS_DEVELOPER_MODE “true”.

6. Also at .htaccess, set this up: php_value display_errors On somewhere within

<IfModule mod_php5.c>

7. Look for the /errors/local.xml.sample and change it to name to /errors/local.xml.

To test the shipping and payment gateways, create a sample customer address.

The Magento Commerce Request Tab

One of the most common problems that new Magento developers face is simply not knowing where to start. Even assuming you know the architecture of the Model View Controller (MVC) software, you’re still faced with more than 40 controller folders. In addition there are numerous applications, so here’s a guide.

Code Organization in Modules

Magento’s Codes are arranged in several modules. All the files in the program are arranged based on their functionality. So if you are looking for Magento’s checkout functions go to:
app/code/core/Mage/Checkout

If you are looking for the application’s Google Checkout function go to:
app/code/core/Mage/GoogleCheckout

If you want to extend or customize Magento instead of doing some core file editing, you have to make a new set of modules at
app/code/local/Package/Modulename

The “Package” is the name that serves to identify your company. This was created so members of the Magento community will use their own names during module creation so there’s no confusion in the code name.

If you want to make a new module, you have to inform Magento, and you do this by inserting an XML file in the app/etc/modules folder. There are two types of files here. The first is for the individual Module, and called Packagename_Modulename.xml

The second is one that enables several modules from a single Package/Namespace in the Packagename_All.xml form. It isn’t recommended that you turn on numerous modules in one file, the reason being it can disrupt your modules’ modularity.

MVC Configuration

This application is a configuration based MVC and the alternative is the convention based system. With a convention based system if you want to create a new model or install a controller, you make them from the file class and the system will automatically pick it up.

With a configuration based system like Magento, you have to add file/class at the codebase and you have to inform the system about the classes or class. Every module in the application has a config.xml file and has all the configuration details needed by that module. All these files are required in a single configuration tree.

Add Models to a Module

If you want to add models to your Magento module, you have to add code in the config.xml file that the application will use. The code is:

<models>
 <packagename>
 <class>Packagename_Modulename_Model</class>
 <packagename>
</models>

The same procedure is used for Event Handlers, Controller Routes, Blocks and Helpers. If you want to use the power of Magento you need to access and edit the config file.

Controllers

The entry point in PHP systems are in a PHP file while in Magento it is index.php. But you don’t have to code in this file. The file will contain calls and code so it can assess the URL, turn the URL to a controller class and call the Action method. In short the entry point for Magento is a controller file method.

Application Models

Magento provides Object Relational Mapping (ORM) that that won’t require you to wire SQL and permits you to work on a database using PHP code. For instance:

$model = Mage::getModel('catalog/product')->load(27);
$price = $model->getPrice();
$price += 5;
$model->setPrice($price)->setSku('SK83293432');
$model->save();

In this example you are calling the “setPrice” and “getPrice” methods for the product. The Mage_Catalog_Model_Product class doesn’t have any such named methods because the application uses PHP’s magic _call for implementing setters and getters. The method

$product->getPrice();

will fetch the “price” model attribute while the

$product->setPrice();

sets the “price” attribute.

This assumes the Model Class names don’t have methods called “setPrice” or “getPrice” because if there are, the magic methods will be ignored. More information about this can be found in the Varien_Object class.

More about Magento Models

If you want data about a model, use the

$product->getData();

and you will obtain the array’s attributes. You can also chain numerous calls via this method:

$model->setPrice($price)->setSku('SK83293432'); 

The Magento ORM also lets you query several Objects using the Collections interface. In this example you will get a list of products that cost $5:

$products_collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('price','5.00');

If you will notice the application employs a chaining interface, and the Collections rely on the PHP Standard Library for implementing the objects.

Do note that this is just an overview of Magento and it has many more features that are available. By taking the time to study the application you will be able to unleash its power and make full use of its potential and many features. It may take some time but it will be worth it.

Guest Author: James Drayden

James Drayden has been using Magento extensions for responsive web design since it first came out, and now serves as a consultant for several e-commerce companies. His particular specialty is configuring Magento for development at BigDropInc. He is also an expert in setting up plugins for the application and setting up parameters.

Tags: , , ,

Comments are closed.