Developer Guide

This document describes Modern Merchant from a developer's perspective.

To learn how to extend Modern Merchant using the plugin system, click here.

MVC - Model, View, Controller

Modern Merchant is built on a popular, proven architecture pattern called MVC. Read further to learn about how Modern Merchant uses MVC.

Controllers

The Controllers are the overarching "backbone" of execution for any given request. The objects representing the Controller are easy to find because they are named with the word 'Controller'. Branching off the controller is the Model and View. The Controller objects in Modern Merchant are each divided into smaller parts called actions. Clients interact with the application by calling individual actions. More than one action may execute during a single request, but only one action may be requested by the client for each request. Each action is represented by a object method with a special naming convention: runXXXXAction().

Here is a partial example of a controller:
<?php
class category_Controller extends admin_Controller
{
    
/**
     * Users can access this action using this URL
     * query: ?a=category.add
     */
    
function runAddAction()
    {
        
$this->category = new category_Category(
                
$this->req('category'));
        if (!
$this->category->save()) {
            
$this->addWarnings($this->category->errors);
            return 
$this->goToView('new');
        }
        
        
$this->addNotice("Category has been added");
        return 
$this->goToRedirect('product.list');
    }
}

Business Objects

Business Objects are the fundamental objects of the application. They represent the business' data and they enforce business' rules.

Here is an example of a Business Object:

<?php
class category_Category extends mvc_Model
{
    public 
$id 0;
    public 
$name null;
    public 
$parent null;
    public 
$parent_id 0;
    public 
$description null;
    public 
$image_id null;
    public 
$comment null;
    public 
$sortorder 0;
    public 
$children = array();
    public 
$image_upload null;
    public 
$delete_image false;
}

Data Access Objects (DAO)

Data Access Objects and Data Objects form the persistence mechanism of the Model.

The Data Access Object is an object design pattern where an interface stores and retrieves business objects from a persistence engine (like a database). These objects are all named so that they end in DAO.

Before the DAOs were introduced into Modern Merchant, all the SQL queries were performed within the Controller actions (see Controller). While this approach makes it easy to see how things work from top to bottom, it results in duplicated code, bloated controllers, and a codebase that is resistant to major changes.

Here is a partial example of a DAO:
<?php
class category_CategoryDAO extends mvc_DataAccess
{
    function 
fetch($id)
    {
       
$query "SELECT * FROM mm_category "
            
" WHERE id=".i($id);
        
$cat $this->fetchByQuery($query);
        
$default_id mm_getSetting('catalog.default_category'); 
        
$cat->default $default_id == $cat->id;
        return 
$cat;
    }
}

Plugins

99% of Modern Merchant's code can be found in the various plugins that are installed. Writing Modern Merchant code means writing plugin code. See the plugin guide on instructions for developing a plugin.