Skip to content

Instantly share code, notes, and snippets.

@rsanchez
Created June 21, 2011 14:32
Show Gist options
  • Save rsanchez/1037978 to your computer and use it in GitHub Desktop.
Save rsanchez/1037978 to your computer and use it in GitHub Desktop.
An example extension for CartThrob
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cartthrob_example_extension_ext
{
public $settings = array();
public $name = 'CartThrob Example Extension';
public $version = '1.0.0';
public $description = 'CartThrob Example Extension';
public $settings_exist = 'n';
public $docs_url = 'http://cartthrob.com/';
/**
* constructor
*
* @access public
* @param mixed $settings = ''
* @return void
*/
public function __construct($settings = '')
{
$this->EE =& get_instance();
$this->settings = $settings;
}
/**
* activate_extension
*
* @access public
* @return void
*/
public function activate_extension()
{
$hook = array(
'class' => __CLASS__,
'settings' => '',
'version' => $this->version,
'enabled' => 'y',
'priority' => 10,
'method' => 'cartthrob_on_authorize',
'hook' => 'cartthrob_on_authorize'
);
$this->EE->db->insert('extensions', $hook);
}
/**
* update_extension
*
* @access public
* @param mixed $current = ''
* @return void
*/
public function update_extension($current = '')
{
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
$this->EE->db->update('extensions', array('version' => $this->version), array('class' => __CLASS__));
}
/**
* disable_extension
*
* @access public
* @return void
*/
public function disable_extension()
{
$this->EE->db->delete('extensions', array('class' => __CLASS__));
}
/**
* settings
*
* @access public
* @return void
*/
public function settings()
{
$settings = array();
return $settings;
}
public function cartthrob_on_authorize()
{
//do your magic use EE and CT apis, eg.
//var_dump($this->EE->cartthrob->cart->order());
}
}
/* End of file ext.cartthrob_example_extension.php */
/* Location: ./system/expressionengine/third_party/cartthrob_example_extension/ext.cartthrob_example_extension.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment