Skip to content

Instantly share code, notes, and snippets.

@devudit
Created July 6, 2016 02:01
Show Gist options
  • Save devudit/45cf2f42b09e840c986f8ebf791c9a55 to your computer and use it in GitHub Desktop.
Save devudit/45cf2f42b09e840c986f8ebf791c9a55 to your computer and use it in GitHub Desktop.
Zencart order total module example
<?php
/* Write this code on order.php */
$customer_whole_obj = $db->Execute('select `customers_whole` from `'.TABLE_CUSTOMERS.'` where `customers_id` ='.$_SESSION['customer_id']);
$customer_whole = $customer_whole_obj->fields['customers_whole'];
if($customer_whole == 4){
if($_SESSION['payment'] == 'paypal' || $_SESSION['payment'] =='authorizenet'){
$this->info['charges'] = 2.5;
$this->info['total_without_charges'] = $this->info['total'];
$this->info['charges_amt'] = ($this->info['total'] * $this->info['charges'])/100;
$this->info['total'] = $this->info['total'] + $this->info['charges_amt'];
}
}
/* Module Language file */
define('MODULE_HANDLING_CHARGES_TITLE', 'Charges');
define('MODULE_HANDLING_CHARGES_DESCRIPTION', 'Handling Charges');
/* Module */
class ot_charges
{
var $title, $output;
function ot_charges()
{
$this->code = 'ot_charges';
$this->title = MODULE_HANDLING_CHARGES_TITLE;
$this->description = MODULE_HANDLING_CHARGES_DESCRIPTION;
$this->sort_order = MODULE_HANDLING_CHARGES_SORT_ORDER;
$this->output = array();
}
function process()
{
global $order, $currencies;
if (isset($order->info['charges'])) {
$this->output[] = array('title' => $this->title . ':',
'text' => $currencies->format($order->info['charges_amt'], true, $order->info['currency'], $order->info['currency_value']),
'value' => $order->info['charges_amt']);
$this->output[] = array('title' => 'Total without charges:',
'text' => $currencies->format($order->info['total_without_charges'], true, $order->info['currency'], $order->info['currency_value']),
'value' => $order->info['total_without_charges']);
} else {
$this->output[] = array('title' => '',
'text' => '',
'value' => '');
}
}
function check()
{
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_HANDLING_CHARGES_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function keys()
{
return array('MODULE_HANDLING_CHARGES_STATUS', 'MODULE_HANDLING_CHARGES_SORT_ORDER');
}
function install()
{
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('This module is installed', 'MODULE_HANDLING_CHARGES_STATUS', 'true', '', '6', '1','zen_cfg_select_option(array(\'true\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HANDLING_CHARGES_SORT_ORDER', '777', 'Sort order of display.', '6', '2', now())");
}
function remove()
{
global $db, $messageStack;
if (!isset($_GET['override']) && $_GET['override'] != '1') {
$messageStack->add('header', ERROR_MODULE_REMOVAL_PROHIBITED . $this->code);
return false;
}
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment