Skip to content
mfriesen edited this page Sep 14, 2010 · 2 revisions

#summary Kaching Developer Guide

Introduction

This developer guide assumes that you are familiar with developing in PHP using the [http://cakephp.org CakePHP] framework and that you have the sample store up and running.

Overview

Kaching is built on the premise that everything can be customized very easily. Out of the box, Kaching comes with a very basic online store that is ONLY to be used as an example on how to use Kaching. However, Kaching comes with a fully furnished store administration.

Create your online store

Creating your online store using Kaching will consist of you creating the look and feel of your store and then use Kaching’s controllers as the glue to make your store go. We are going to start off with the example of customizing your shopping cart layout so you can get a feel of what Kaching is all about.

Since Kaching is a CakePHP plugin, you need to understand how to override a plugin’s views and layouts. We are going to start off with changing the default store’s layout.

When CakePHP is determining which view file it is going to display, it actually generates a list of possible path where that file can be located. This makes it really nice to override the default version implementation of our plugin.

The default shopping cart layout is found {{{app/plugins/kaching/views/layouts/carts.ctp}}}. If order to override a plugin’s views we need to create the directory {{{app/views/plugins/kaching/layouts}}} and copy the carts.ctp file into it.

Now, edit the {{{app/views/plugins/kaching/layouts/carts.ctp}}} and make some random text changes. Refresh the sample store and you should see your changes.

Any view / element in {{{app/plugins/kaching/views}}} can be override if created in {{{app/views/plugins/kaching}}}.

Controllers

When creating your online store there will be 2 main controllers that you will be dealing with.

  • app/views/plugins/kaching/controllers/carts_controller.php
  • app/views/plugins/kaching/controllers/checkouts_controller.php

The checkouts_controller.php controls your checkout process. From validating the order, to sending the confirmation email.

The carts_controller controls the rest of the store, from displaying products to adding/removing products from the shopping cart.

We suggest to take a look at the internal documentation of both of these classes to see all of the functionality.

Carts controller

The default layout can be found in app/plugins/kaching/views/layouts/carts.ctp. To override create the file app/views/plugins/kaching/layouts/carts.ctp.

The shopping carts views can be found in app/plugins/kaching/views/carts (To override create directory app/views/plugins/kaching/carts). In that directory you will find the following views and their description:

  • category.ctp – displays a listing of products in a category
  • product.ctp – displays a product
  • search.ctp – displays search results
  • view.ctp – displays current shopping cart

The name of each view corresponds to the method name in the carts_controller.php file.

Checkouts controller

The default layout can be found in app/plugins/kaching/views/layouts/checkouts.ctp. To override create the file app/views/plugins/kaching/layouts/checkouts.ctp.

The checkouts views can be found in app/plugins/kaching/views/checkout (To override create directory app/views/plugins/kaching/checkout). In that directory you will find the following views and their description:

  • index – The main page where user information is collected
  • review – Review of the user
  • complete – The order is completed

The default checkout process consists of the above 3 step.

Validation Rules

Before an order can make it past the checkout’s index page, it must pass validation. The default validation of an order is bare bones ( IE: email, and credit card information). This allow you to the flexibility to tailor your validation to your needs and make it easy to add extra fields to an order.

The adding of more validation is controlled by adding the key “kaching.validation.order” to the app/config/core.php. The value of the key is an array of CakePHP validation rules. For example here is what you could add to the app/config/core.php for the sample store.

{{{
Configure::write(‘kaching.validation.order’,
array(
‘billto_name’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* Name is required’),
‘billto_address’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* Address is required’),
‘billto_city’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* City is required’),
‘billto_region’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* Province is required’),
‘billto_country’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* Country is required’),
‘shipto_name’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* Name is required’),
‘shipto_address’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* Address is required’),
‘shipto_city’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* City is required’),
‘shipto_region’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* Province is required’),
‘shipto_country’ => array(‘rule’ => ‘notEmpty’, ‘message’ => ‘* Country is required’)
)
);
}}}

If you goto the checkouts page and click the Review button, you will now see the additional validation in action.

Disable SSL

By default, the Checkouts controller and the store administration is forced to use SSL. However, sometimes you might not want this. For example on a development machine. To disable add the following to core.php.

{{{Configure::write(“kaching.admin.ssl”, “false”);}}}

.h1 Database Schema

Clone this wiki locally