Skip to content
Darryl Hein edited this page Sep 3, 2015 · 8 revisions

Adding the XM Cart to an existing Kohana/CL4/XM project/site:

  • Add the module and docroot module as git submodules:
#!/bin/bash
# add the submodules
git submodule add [email protected]:xmmedia/xm_cart.git modules/xm_cart
git submodule add [email protected]:xmmedia/xm_cart_docroot.git html/xm_cart
git submodule init

# checkout the kohana_v3.3/master branch
echo "-- submodule init & update" &&
git submodule init && git submodule update &&
echo "-- module > XM Cart" &&
cd modules/xm_cart && git checkout master && git pull && git checkout kohana_v3.3/master && git pull &&
echo "-- module > XM Cart Docroot" &&
cd ../../html/xm_cart && git checkout master && git pull && git checkout kohana_v3.3/master && git pull &&
cd ../..
  • Add the module to the top of the module list in bootstrap.php:
<?php
	'xm_cart'  => MODPATH . 'xm_cart',    // xm cart
  • Create the tables. Use the SQL from create.sql. Likely put the SQL in a change script file.

  • Add the config application/config/xm_cart.php. The following is basically a minimum. More config options can be found in config/xm_cart.php.

<?php defined('SYSPATH') or die('No direct script access.');

return array(
	'salt' => '[cart salt]',

	'administrator_email' => array(
		'email' => '[email protected]',
		'name' => 'Cart Admin',
	),

	'payment_processor_config' => array(
		'stripe' => array(
			'test' => array(
				'secret_key' => '',
				'publishable_key' => '',
			),
			'live' => array(
				'secret_key' => '',
				'publishable_key' => '',
			),
		),
	),
);
  • Add the STRIPE_CONFIG constant to each of the inits: define('STRIPE_CONFIG', 'live');

  • By default the spacer.gif file is no longer part of the template. If using the cart, the image is needed for the emails so you'll need to add/create one.

  • Add cart_admin cart_admin to the $nav_items and $sub_nav_items var lists in _private.scss.

  • If you're planning to use https (recommended), you may want to add the following to your .htaccess to redirect the user to https:// when accessing the checkout pages:

  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP_HOST} !^dev\.example\.com
  RewriteRule ^(cart/checkout|cart/save_shipping|cart/save_final|cart/complete_order|cart/completed|cart/payment_failed|login) https://www.example.com%{REQUEST_URI} [R=301,L,NE]
  • If the dev site doesn't have an SSL certificate, you'll want to disable https on the dev site.
<?php
// add the following to your dev config
define('CART_CHECKOUT_HTTPS', FALSE);
// add the following to your production config
define('CART_CHECKOUT_HTTPS', TRUE);

// then in application/config/xm_cart.php add
'checkout_https' => CART_CHECKOUT_HTTPS,
  • Add the cart pieces of the Gulp config:
// in paths.scripts
		// xm cart module
		{
			dest : 'html/xm_cart/js',
			destFile : 'base.min.js',
			files :
				[
					'html/xm_cart/js/src/handlebars.js',
					'html/xm_cart/js/src/underscore.js',
					'html/xm_cart/js/src/backbone.js',
					'html/xm_cart/js/src/jquery.form.js',
					'html/xm_cart/js/src/base.js'
				]
		},
		{
			dest : 'html/xm_cart/js/admin/',
			destFile : 'order.min.js',
			files :
				[
					'html/xm_cart/js/src/admin/order.js'
				]
		},
		{
			dest : 'html/xm_cart/js/admin/',
			destFile : 'shipping.min.js',
			files :
				[
					'html/xm_cart/js/src/admin/shipping.js'
				]
		},
		{
			dest : 'html/xm_cart/js/admin/',
			destFile : 'tax.min.js',
			files :
				[
					'html/xm_cart/js/src/admin/tax.js'
				]
		},
		{
			dest : 'html/xm_cart/js/',
			destFile : 'public.min.js',
			files :
				[
					'html/xm_cart/js/src/public/bootstrap.js',
					'html/xm_cart/js/src/public/models/*.js',
					'html/xm_cart/js/src/public/collections/*.js',
					'html/xm_cart/js/src/public/views/*.js',
					'html/xm_cart/js/src/public/router.js',
					'html/xm_cart/js/src/public.js'
				]
		}

// in paths.styles
		// xm cart module
		{
			src : 'html/xm_cart/css/sass/*.scss',
			dest : 'html/xm_cart/css',
			options : {
				style: 'compressed',
				loadPath: 'html/xm/css/sass',
				container : 'xm_cart_sass'
			}
		}

// watch: add the following globs within watch
'html/xm_cart/js/src/**/*.js'
'html/xm_cart/css/sass/**/*.scss'
// so that it looks like:
gulp.watch(['html/js/src/**/*.js', 'html/xm/js/src/**/*.js', 'html/xm_cart/js/src/**/*.js'], ['scripts']);
gulp.watch(['html/css/sass/**/*.scss', 'html/xm/css/sass/**/*.scss', 'html/xm_cart/css/sass/**/*.scss'], ['styles']);

Note: The public side of the cart requires functions in xm.js and ajax.js inside the XM library so it's probably best to move it from private.min.js to base.min.js.

Clone this wiki locally