zen cart — one way to override function in the folder of includes/functions

zen cart don’t have a build in way to override all functions defined in the folder of includes/functions. PHP will throw out an error of “duplicate declare is not allowed”. well, we know that zen cart have built in mechanism to  override all the files in the includes/init_includes folder. And all the files in the includes/functions folder are loaded via includes/init_includes/init_general_funcs.php. let’s take a look at the php source:

[codesyntax lang=”php”]

<?php
/**
 * load the system wide functions
 * see {@link  http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials#InitSystem wikitutorials} for more details.
 *
 * @package initSystem
 * @copyright Copyright 2003-2005 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: init_general_funcs.php 2845 2006-01-13 06:49:15Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
/**
 * General Functions
 */
require(DIR_WS_FUNCTIONS . 'functions_general.php');
/**
 * html_output functions (href_links, input types etc)
 */
require(DIR_WS_FUNCTIONS . 'html_output.php');
/**
 * basic email functions
 */
require(DIR_WS_FUNCTIONS . 'functions_email.php');
/**
 * EZ-Pages functions
 */
require(DIR_WS_FUNCTIONS . 'functions_ezpages.php');
/**
 * User Defined Functions
 */
include(DIR_WS_MODULES . 'extra_functions.php');
?>

[/codesyntax]

 

To override the includes/functions/functions_general.php, we need make a change of this file.so

First,make a copy of includes/init_includes/init_general_funcs.php to includes/init_includes/overrides/init_general_funcs.php

Second, alter the includes/init_includes/overrides/init_general_funcs.php as below

/**
 * General Functions
 */
require(DIR_WS_FUNCTIONS . 'functions_general.php');

To

/**
 * General Functions
 */
require(DIR_WS_FUNCTIONS . '/overrides/functions_general.php');

Then you can do whatever changes as you want to any functions defined in that file.

if you want to overrides all files in includes/functions folder,just like zen cart build in override mechannism,the you can replace the content of includes/init_includes/overrides/init_general_funcs.php
as below:

[codesyntax lang=”php”]

if ($za_dir = @dir(DIR_WS_INCLUDES . 'includes/functions/overrides')) {
  while ($zv_file = $za_dir->read()) {
    if (preg_match('/\.php$/', $zv_file) > 0) {
      include(DIR_WS_INCLUDES . 'includes/functions/overrides' . $zv_file);
    }
  }
  $za_dir->close();
}

[/codesyntax]

 

 

 

 

 

 

Linux — how to know if php run as cgi or module

For some reason you want to know how is php working with web server like apache. if you are the people who config the server,you got the answer in your head. what if you are not? well,php have a function for this:

php_sapi_name

Per php manual,call this function will returns the type of interface between web server and PHP

[codesyntax lang=”php”]

<?php
php_sapi_name();
?>

[/codesyntax]

The section below is take from the php manual:
Although not exhaustive, the possible return values include aolserver, apache, apache2filter, apache2handler, caudium, cgi (until PHP 5.3), cgi-fcgi, cli, continuity, embed, isapi, litespeed, milter, nsapi, phttpd, pi3web, roxen, thttpd, tux, and webjames.

When php run in CGI mode( or any other mode other that module mode), you can not set php config via php_value directive in the .htaccess file.

you can also take a look at the phpinfo page to decide how php is working with your webserver.

zen cart — adapt zen cart to switch template based upon parameter

well,as a zen cart developer,you may have lots of zen cart template. Don’t you bother with  zen cart installation. Though you can make a batch script to generate mass zen cart websites, it will take you a lot of disk space and make you headache while searching for a special zen cart template.

so why not keep all the zen cart template in a single zen cart website.when you need to test some special zen cart template,specify a parameter with the value of template name and zen cart will take the parameter as the current template,no bother to do zen cart admin setting once and once again.

so how? the adoption of the zen cart core code is simple,as below:

Copy includes/init_includes/init_templates.php to includes/init_includes/overrides/init_templates.php,change the code like below:

$sql = “select template_dir
from ” . TABLE_TEMPLATE_SELECT . ”
where template_language = ‘” . $_SESSION[‘languages_id’] . “‘”;
$template_query = $db->Execute($sql);
if ($template_query->RecordCount() > 0) {
$template_dir = $template_query->fields[‘template_dir’];
}

// customized by georgezheng
if (isset($_GET[‘t’])  && $_GET[‘t’] != ” ) {
$temp = trim($_GET[‘t’]);
$_SESSION[‘t’] = $temp;
} elseif ( isset($_SESSION[‘t’]) &&  $_SESSION[‘t’] != ” ) {
$temp = $_SESSION[‘t’];
} else {
$temp = ”;
}
//end

if ( $temp != ” && is_dir(DIR_WS_TEMPLATES . $temp) ) {
$template_dir = $temp;
}

save,then browse your zen cart website with url like this http://www.abcdomain.com/?t=temp1.zen cart will looking for the template temp1,if exists temp1 will be set as current template for this session.

zen cart — How to determine if current page is HomePage?

sometims,you need to know if the current page is homepage. for example,you don’t want to show some special content in the homepage,then you need to know whether the current page is homepage.

From zen cart source code,i got some idea,see it below

./includes/init_includes/init_category_path.php:47:
[codesyntax lang=”php”]

$this_is_home_page = ($current_page=='index' && (!isset($_GET['cPath'])) && (!isset($_GET['manufacturers_id'])) && (!isset($_GET['typefilter'])) );

[/codesyntax]

so we can get the result from $this_is_home_page.  this is a global varaible,so you can access it if it’s initiated.

 

zen cart — How to Add a Sidebox to Zen Cart

One of the best way to customize Zen Cart is to create a new Sidebox.A Zen Cart sidebox is what displays various contents in the left or right columns of your Zen Cart store. By default numerous sideboxes will show in either the left or right column of a Zen Cart online store. The followings are some of the most popular zen cart sidebox — The categories sidebox, the search sidebox, and the information sidebox. Zen cart comes with some builtin sidebox which could be a good tutor to start to learn how to add a new sidebox to Zen Cart.

A sidebox consists of three files which are located in the includes directory:

  1. modules/sideboxes/YOUR_TEMPLATE/new_sidebox.php
  2. languages/english/extra_definitions/YOUR_TEMPLATE/new_sidebox_defines.php
  3. templates/YOUR_TEMPLATE/sideboxes/tpl_new_sidebox.php

The ‘new’ up there should be replaced with your own sidebox name.

includes/modules/sideboxes/YOUR_TEMPLATE/new_sidebox.php

[codesyntax lang=”php”]

<?php
 $show_new_sidebox = true;
 if ($show_new_sidebox == true){
   require($template->get_template_dir('tpl_new_sidebox.php',DIR_WS_TEMPLATE,
   $current_page_base,'sideboxes'). '/tpl_new_sidebox.php');
   $title =  BOX_HEADING_NEW_SIDEBOX;
   //do some db query and other processing here

   $left_corner = false;
   $right_corner = false;
   $right_arrow = false;
   require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE,
   $current_page_base,'common') . '/' . $column_box_default);
 }
?>

[/codesyntax]

includes/languages/english/extra_definitions/YOUR_TEMPLATE/new_sidebox_defines.php

[codesyntax lang=”php”]

<?php
  define('BOX_HEADING_NEW_SIDEBOX', 'Gallery');
?>

[/codesyntax]

includes/templates/YOUR_TEMPLATE/sideboxes/tpl_new_sidebox.php

[codesyntax lang=”php”]

<?php
 $content = <<< End_Of_Quote
  Enter your sidebox content here
 End_Of_Quote;
?>

[/codesyntax]

zen cart — how to get the url of the current page

i want to set a anchor in all page.so when the user click on the anchor,it will bring user back to the head of the current page.i just don’t want to call too much javascript code.

[codesyntax lang=”php”]

<a href="#backhome">Back to top</a>

[/codesyntax]

The code up there not work.As the browser will fix the anchor url  which cut the current url from last slash.for example

http://www.abcdomain.com/product-one_p_29.html   => http://www.abcdomain.com/#backhome

http://www.abcdomain.com/category1/product-one_p_29.html => http://www.abcdomain.com/category1/#backhome

$_SERVER[‘REQUEST_URI‘] stores the url from the root, see example below

http://www.abcdomain.com/product-one_p_29.html => product-one_p_29.html
http://www.abcdomain.com/category1/product-one_p_29.html  =>
category1/product-one_p_29.html

so the anchor snippet code can be adapter to the following code

[codesyntax lang=”php”]

<a href="<?php echo $_SERVER['REQUEST_URI']?>#backhome">Back to top</a>

[/codesyntax]

 

 

linux — How to extract specified file/directory from a tar ball

well,you got a big tar ball file,but in fact you only need some special file or directory.Then you don’t want to extract  all files from the tar ball if it’s a big file.so how to get specified file or directory from a tar ball?

tar command allows to extract a single file or directory using the following format. It works under UNIX, Linux, and BSD operating systems.

tar xvf big.tar filename
tar -zxvf abc.tar.gz directory-name
tar -zxvf abc.tar.gz path/to/directory-name -C /tmp

Keep in mind that both the filename and directory-name should be existed in the tar ball file,and the path is relative to the tar ball root.

open cart — how to create a payment module for open cart

To be honestly, this is my first module for open cart. I know about open cart years ago(2009),but never study in deep.The installation of open cart is straightforward.After some minutes of playing around open cart frontend and admin backend, i decided to start work.

To create a payment module for open cart,first,we need to create all files for a open cart payment module.As we know,open cart was developed in MVC pattern,so all modules will include a model class,controller class and file for View,detail as below
[the name of the new payment module is callled moneybrace]
catalog/controller/payment/moneybrace.php (Controller class)
catalog/model/payment/moneybrace.php  (Model class)
catalog/language/english/payment/moneybrace.php (Language file for View)
catalog/view/theme/default/template/payment/moneybrace.tpl (Template file for View)
admin/controller/payment/moneybrace.php
admin/language/english/payment/moneybrace.php
admin/view/template/payment/moneybrace.php

It was obviously,all files located under catalog folder is for frontend use,all the others will be called in the admin backend page.

Keep in mind that you must follow the folder structure as the one above.And you’d better put template file in the default theme folder.You would not like to copy and paste file when you change the theme.

Now let’s do some coding work.Let’s start from implementing the payment’s bakend config page.For the Controller class,it should looks like below:
[admin/controller/payment/moneybrace.php]
[codesyntax lang=”php”]

class ControllerPaymentMoneybrace extends Controller {
	private $error = array();

	public function index() {

	}
	private function validate() {
	}
}

[/codesyntax]

 

The classname must start with ControllerPayment and should be a subclass of Controller.It’s very simple,you only need to implement two method: index() and validate() .open cart will help you deal with all the other details.

Below is the language file which stores all lables for all form elements which were used to config the payment module:
[admin/language/english/payment/moneybrace.php]
[codesyntax lang=”php”]

<?php
// Heading
$_['heading_title']			= 'Moneybrace';

// Text
$_['text_payment']			= 'Payment';
$_['text_success']			= 'Success: You have modified Moneybraces!';
$_['text_moneybrace']			= '<a onclick="window.open(\'http://www.moneybrace.com/\');"><img src="http://www.moneybrace.com/templets/default/images/logo.jpg" style="border: 1px solid #EEEEEE;" /></a>';

// Entry
$_['entry_merchantacct']		= 'Merchant Account:';
$_['entry_cert']			= 'Merchant Certificate:';
$_['entry_debug']			= 'Debug Mode:<br/><span class="help">Logs additional information to the system log.</span>';
$_['entry_completed_status']      = 'Completed Status:';
$_['entry_pending_status']		= 'Pending Status:';
$_['entry_processed_status']		= 'Processed Status:';
$_['entry_geo_zone']			= 'Geo Zone:';
$_['entry_status']			= 'Status:';
$_['entry_sort_order']			= 'Sort Order:';

// Error
$_['error_permission']			= 'Warning: You do not have permission to modify payment Moneybrace!';
$_['error_merchantacct']		= 'Merchant Account required!';
$_['error_cert']			= 'Merchant certificates required!';
?>

[/codesyntax]

 

you need to pay some more attention for the third file,this is where you defined  related configure parameter which will be shown on backend config page. All the configure parameter will be insert into the setting table of the open cart database.The name of the input will be used as config key.You’d better start all key name with same prefix,here i use moneybrace,which is the name of the payment gateway.
[admin/view/template/payment/moneybrace.php]
[codesyntax lang=”php”]

<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/payment.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <table class="form">
          <tr>
            <td><span class="required">*</span> <?php echo $entry_merchantacct; ?></td>
            <td><input type="text" name="moneybrace_merchantacct" value="<?php echo $moneybrace_merchantacct; ?>" />
              <?php if ($error_merchantacct) { ?>
              <span class="error"><?php echo $error_merchantacct; ?></span>
              <?php } ?></td>
          </tr>
          <tr>
            <td><span class="required">*</span> <?php echo $entry_cert; ?></td>
            <td><input type="text" name="moneybrace_cert" value="<?php echo $moneybrace_cert; ?>" />
              <?php if ($error_cert) { ?>
              <span class="error"><?php echo $error_cert; ?></span>
              <?php } ?></td>
          </tr>
          <tr>
            <td><?php echo $entry_debug; ?></td>
            <td><select name="moneybrace_debug">
                <?php if ($moneybrace_debug) { ?>
                <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                <option value="0"><?php echo $text_disabled; ?></option>
                <?php } else { ?>
                <option value="1"><?php echo $text_enabled; ?></option>
                <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                <?php } ?>
              </select></td>
          </tr>zz
          <tr>
            <td><?php echo $entry_pending_status; ?></td>
            <td><select name="moneybrace_pending_status_id">
                <?php foreach ($order_statuses as $order_status) { ?>
                <?php if ($order_status['order_status_id'] == $moneybrace_pending_status_id) { ?>
                <option value="<?php echo $order_status['order_status_id']; ?>" selected="selected"><?php echo $order_status['name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $order_status['order_status_id']; ?>"><?php echo $order_status['name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_processed_status; ?></td>
            <td><select name="moneybrace_processed_status_id">
                <?php foreach ($order_statuses as $order_status) { ?>
                <?php if ($order_status['order_status_id'] == $moneybrace_processed_status_id) { ?>
                <option value="<?php echo $order_status['order_status_id']; ?>" selected="selected"><?php echo $order_status['name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $order_status['order_status_id']; ?>"><?php echo $order_status['name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_geo_zone; ?></td>
            <td><select name="moneybrace_geo_zone_id">
                <option value="0"><?php echo $text_all_zones; ?></option>
                <?php foreach ($geo_zones as $geo_zone) { ?>
                <?php if ($geo_zone['geo_zone_id'] == $moneybrace_geo_zone_id) { ?>
                <option value="<?php echo $geo_zone['geo_zone_id']; ?>" selected="selected"><?php echo $geo_zone['name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $geo_zone['geo_zone_id']; ?>"><?php echo $geo_zone['name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_status; ?></td>
            <td><select name="moneybrace_status">
                <?php if ($moneybrace_status) { ?>
                <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                <option value="0"><?php echo $text_disabled; ?></option>
                <?php } else { ?>
                <option value="1"><?php echo $text_enabled; ?></option>
                <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_sort_order; ?></td>
            <td><input type="text" name="moneybrace_sort_order" value="<?php echo $moneybrace_sort_order; ?>" size="1" /></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</div>
<?php echo $footer; ?>

[/codesyntax]

This file define the following config parameter for the moneybrace open cart payment module:

[codesyntax lang=”php”]

moneybrace_merchantacct
moneybrace_cert
moneybrace_debug
moneybrace_pending_status_id
moneybrace_processed_status_id
moneybrace_geo_zone_id
moneybrace_status
moneybrace_sort_order

[/codesyntax]

By now we had finished all development for the payment backend configure page. let’s move forward to develop the main logic the payment module will do — generating a form with all the payment infomation.
Below is the controller class.Make sure the class name start with ControllerPayment,and it must have  an index method to init all form element value. The class also define a callback() method, which will be used to receive and process payment result. You can name it  whatever you like,but you should told the payment gateway the correct method to call when payment is done.
[catalog/controller/payment/moneybrace.php]
[codesyntax lang=”php”]

<?php
/* Moneybrace online payment
 *
 * @version 1.0
 * @date 11/03/2012
 * @author george zheng <xinhaozheng@gmail.com>
 * @more info available on mzcart.com
 */
class ControllerPaymentMoneybrace extends Controller {
	protected function index() {
		$this->language->load('payment/moneybrace');

		$this->data['button_confirm'] = $this->language->get('button_confirm');

		$this->data['action'] = 'https://payment.moneybrace.com/payment/paypage.aspx';

		$this->load->model('checkout/order');

		$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);

		if ($order_info) {
		    $this->data['merchantid'] = trim($this->config->get('moneybrace_merchantacct'));
			$this->data['encoding'] = 'utf-8';
			$this->data['transtype'] = 'IC';
			$this->data['version'] = '1.0.0';
			$this->data['orderid'] = date('His') . $this->session->data['order_id'];

			switch($this->session->data['language']) {
				case 'de':
					 $this->data['language'] = 'de-de';
					 break;
				case 'fr':
					 $this->data['language'] = 'fr-fr';
					 break;
				case 'it':
					 $this->data['language'] = 'it-it';
					 break;
				case 'es':
					 $this->data['language'] = 'es-es';
					 break;
				case 'pt':
					 $this->data['language'] = 'pt-pt';
					 break;
				case 'jp':
					 $this->data['language'] = 'ja-jp';
					 break;
				default:
					 $this->data['language'] = 'en-us';
		    }
			$this->data['callbackurl'] = $this->url->link('payment/moneybrace/callback');
			$this->data['browserbackurl'] = $this->url->link('checkout/success');
			$this->data['accessurl'] = 'https://payment.moneybrace.coms';
			$this->data['orderdate'] = date('YmdHis');
			$this->data['currency'] = $order_info['currency_code'];
            $allowed_cur = array('USD', 'EUR', 'GBP', 'CAD', 'AUD', 'JPY');
			$currency = $_SESSION['currency'];
			if ( !in_array($currency, $allowed_cur)) {
				$currency = 'USD';
			}

			$this->data['orderamount'] = $this->currency->format($order_info['total'], $currency , false, false);	

			$this->data['first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
			$this->data['last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');	

			$this->data['billemail'] = $order_info['email'];
			$this->data['billphone'] = html_entity_decode($order_info['telephone'], ENT_QUOTES, 'UTF-8');
			$this->data['billaddress'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
			$this->data['billcountry'] = html_entity_decode($order_info['payment_iso_code_2'], ENT_QUOTES, 'UTF-8');
			$this->data['billprovince'] = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');;
			$this->data['billcity'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
			$this->data['billpost'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');	

			$this->data['deliveryname'] = html_entity_decode($order_info['shipping_firstname'] . $order_info['shipping_lastname'], ENT_QUOTES, 'UTF-8');
			$this->data['deliveryaddress'] = html_entity_decode($order_info['shipping_address_1'], ENT_QUOTES, 'UTF-8');
			$this->data['deliverycity'] = html_entity_decode($order_info['shipping_city'], ENT_QUOTES, 'UTF-8');
			$this->data['deliverycountry'] = html_entity_decode($order_info['shipping_iso_code_2'], ENT_QUOTES, 'UTF-8');
			$this->data['deliveryprovince'] = html_entity_decode($order_info['shipping_zone'], ENT_QUOTES, 'UTF-8');
			$this->data['deliveryemail'] = $order_info['email'];
			$this->data['deliveryphone'] = html_entity_decode($order_info['telephone'], ENT_QUOTES, 'UTF-8');
			$this->data['deliverypost'] = html_entity_decode($order_info['shipping_postcode'], ENT_QUOTES, 'UTF-8');

			$strProducts = '';
			$htmlProducts = '';
			foreach ($this->cart->getProducts() as $product) {
			    $pname = trim(str_replace('"', '', $product['name']));

			    if ( $pname == '' && $strProducts == '' && $htmlProducts = '') {
				    $pname = 'Order ' . $this->data['orderid'];
					$psn = $this->data['orderid'];
					$qty = 1;
					$price = $this->currency->format($product['price'], $currency, false, false);
				    $strProducts = 'Order ' . $this->data['orderid'] . '1';
					$htmlProducts = '<input name="productname1" value="" ' . $pname . ' />' .
									'<input name="productsn1" value="" ' . $psn . '/>' .
									'<input name="quantity1" value="" ' . $qty . ' />' .
									'<input name="unit1" value="" ' . $price . '/>' ;
					break;
				}

				$psn = $product['model'];
				$qty = $product['quantity'];
				$price = $this->currency->format($product['price'], $currency, false, false);

				$strProducts =  $pname . $psn . $qty . $price;
				$htmlProducts = '<input type="hidden" name="productname1" value="' . $pname . '" />' .
								'<input type="hidden" name="productsn1" value="' . $psn . '" />' .
								'<input type="hidden" name="quantity1" value="' . $qty . '" />' .
								'<input type="hidden" name="unit1" value="' . $price . '"/>' ;

			}
			$this->data['htmlProducts'] = $htmlProducts;

			$cert = $this->config->get('moneybrace_cert');

			$strSource =$cert . $this->data['version'] . $this->data['encoding'] . $this->data['language'] . $this->data['merchantid'] .
			$this->data['orderid'] . $this->data['orderdate'] . $this->data['currency'] . $this->data['orderamount'] . $this->data['transtype'] .
			$this->data['callbackurl'] . $this->data['browserbackurl'] . $this->data['accessurl'] .
            $strProducts .
			$this->data['billaddress'] . $this->data['billcountry'] . $this->data['billprovince'] . $this->data['billcity'] .
			$this->data['billemail'] . $this->data['billphone'] . $this->data['billpost'] .
			$this->data['deliveryname'] . $this->data['deliveryaddress'] . $this->data['deliverycountry'] . $this->data['deliveryprovince'] .
			$this->data['deliverycity'] . $this->data['deliveryemail'] . $this->data['deliveryphone'] . $this->data['deliverypost'];
            if ($this->config->get('moneybrace_debug')) {
				$this->log->write('Submit source string:' . $strSource);
			}
			$signature = md5($strSource);
			$this->data['signature'] = $signature;

			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/moneybrace.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/payment/moneybrace.tpl';
			} else {
				$this->template = 'default/template/payment/moneybrace.tpl';
			}

			$this->render();
		}
	}

	public function callback() {
		if (isset($this->request->post['orderid'])) {
			$order_id = trim(substr(($this->request->post['orderid']), 6));
		} else {
			die('Illegal Access');
		}		

		$this->load->model('checkout/order');

		$order_info = $this->model_checkout_order->getOrder($order_id);

		if ($order_info) {
		    $data = array_merge($this->request->post,$this->request->get);
			foreach ($data as $key => $value) {
				${$k} = $value;
			}

			$product='';
			for($i=1;$i<=10;$i++) {
				if(!isset($data['productname'.$i]) || $data['productname'.$i] == '') {
					break;
				}
				$product = $product . $data['productname'.$i] . $data['productsn'.$i] . $data['quantity'.$i] . $data['unit'.$i];
			}

			$cert = $this->config->get('moneybrace_cert');
			$strSource = $cert . $version . $encoding . $lang . $merchantid . $transtype . $orderid .
            $orderdate . $currency. $orderamount . $paycurrency . $payamount .$remark1 . $remark2 .
            $remark3 .  $product . $shippingfee . $deliveryname . $deliveryaddress . $deliverycountry .$deliveryprovince.
            $deliverycity . $deliveryemail . $deliveryphone . $deliverypost . $transid . $transdate . $status;

			if ($this->config->get('moneybrace_debug')) {
				$this->log->write('Return source string:' . $strSource);
			}

			$getsignature=md5($strSource);
			if ( $getsignature != $signature) {
			    $order_status_id = $this->config->get('moneybrace_pending_status_id');
			    $this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'));
			    die('Data validate failed');
			}

			//payment was made succ
			if ($status == 'Y' || $status == 'y') {
			    $order_status_id = $this->config->get('moneybrace_processed_status_id');
				if (!$order_info['order_status_id'] || $order_info['order_status_id'] != $order_status_id) {
					$this->model_checkout_order->confirm($order_id, $order_status_id);
				} else {
					$this->model_checkout_order->update($order_id, $order_status_id);
				}
			}
		}
	}
}
?>

[/codesyntax]

Let’s take a look at the model class of the moneybrace payment module:
[catalog/model/payment/moneybrace.php]
[codesyntax lang=”php”]

<?php
/* Moneybrace online payment
 *
 * @version 1.0
 * @date 11/03/2012
 * @author george zheng <xinhaozheng@gmail.com>
 * @more info available on mzcart.com
 */
class ModelPaymentMoneybrace extends Model {
  	public function getMethod($address, $total) {
		$this->load->language('payment/moneybrace');

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('moneybrace_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");

		if ($this->config->get('moneybrace_total') > $total) {
			$status = false;
		} elseif (!$this->config->get('moneybrace_geo_zone_id')) {
			$status = true;
		} elseif ($query->num_rows) {
			$status = true;
		} else {
			$status = false;
		}	

		$currencies = array(
			'AUD',
			'CAD',
			'EUR',
			'GBP',
			'JPY',
			'USD',
			'NZD',
			'CHF',
			'HKD',
			'SGD',
			'SEK',
			'DKK',
			'PLN',
			'NOK',
			'HUF',
			'CZK',
			'ILS',
			'MXN',
			'MYR',
			'BRL',
			'PHP',
			'TWD',
			'THB',
			'CNY',
			'TRY'
		);

		if (!in_array(strtoupper($this->currency->getCode()), $currencies)) {
			$status = false;
		}			

		$method_data = array();

		if ($status) {
      		$method_data = array(
        		'code'       => 'moneybrace',
        		'title'      => $this->language->get('text_title'),
				'sort_order' => $this->config->get('moneybrace_sort_order')
      		);
    	}

    	return $method_data;
  	}
}
?>

[/codesyntax]

If you want to limit the payment module only available to some order over a preset amount,or limit the payment module only available to some countries,currency, you can implement the logic here in the getMethod() method of model class.
[catalog/language/english/payment/moneybrace.php]
[codesyntax lang=”php”]

<?php
/* Moneybrace online payment
 *
 * @version 1.0
 * @date 11/03/2012
 * @author george zheng <xinhaozheng@gmail.com>
 * @more info available on mzcart.com
 */
// Text
$_['text_title']    = '<img src="http://moneybrace.com/pic/mblogo.gif" alt="Moneybrace" style="border:none" />';
$_['text_reason'] 	= 'REASON';
$_['text_total']	= 'Shipping, Handling, Discounts & Taxes';
?>

[/codesyntax]
[catalog/view/theme/default/template/payment/moneybrace.tpl]
[codesyntax lang=”php”]

<form action="<?php echo $action; ?>" method="post">
	<input type="hidden" name="merchantid" value="<?php echo $merchantid; ?>" />
	<input type="hidden" name="orderid" value="<?php echo $orderid; ?>" />
	<input type="hidden" name="encoding" value="<?php echo $encoding; ?>" />
	<input type="hidden"  name="transtype" value="<?php echo $transtype; ?>" />
	<input type="hidden" name="language" value="<?php echo $language; ?>" />
	<input type="hidden" name="callbackurl" value="<?php echo $callbackurl; ?>" />
	<input type="hidden" name="browserbackurl" value="<?php echo $browserbackurl; ?>" />
	<input type="hidden" name="accessurl" value="<?php echo $accessurl; ?>" />
	<input type="hidden" name="orderdate" value="<?php echo $orderdate; ?>" />
	<input type="hidden" name="currency" value="<?php echo $currency; ?>" />
	<input type="hidden" name="orderamount" value="<?php echo $orderamount; ?>" />
    <?php echo $htmlProducts; ?>
	<input type="hidden" name="version" value="<?php echo $version; ?>" />
	<input type="hidden" name="billemail" value="<?php echo $billemail; ?>" />
	<input type="hidden" name="billphone" value="<?php echo $billphone; ?>" />
	<input type="hidden" name="billaddress" value="<?php echo $billaddress; ?>" />
	<input type="hidden" name="billcountry" value="<?php echo $billcountry; ?>" />
	<input type="hidden" name="billprovince" value="<?php echo $billprovince; ?>" />
	<input type="hidden" name="billcity" value="<?php echo $billcity; ?>" />
	<input type="hidden" name="billpost" value="<?php echo $billpost; ?>" />
	<input type="hidden" name="deliveryname" value="<?php echo $deliveryname; ?>" />
	<input type="hidden" name="deliveryaddress" value="<?php echo $deliveryaddress; ?>" />
	<input type="hidden" name="deliverycity" value="<?php echo $deliverycity; ?>" />
	<input type="hidden" name="deliverycountry" value="<?php echo $deliverycountry; ?>" />
	<input type="hidden" name="deliveryprovince" value="<?php echo $deliveryprovince; ?>" />
	<input type="hidden" name="deliveryemail" value="<?php echo $deliveryemail; ?>" />
	<input type="hidden" name="deliveryphone" value="<?php echo $deliveryphone; ?>" />
	<input type="hidden" name="deliverypost" value="<?php echo $deliverypost; ?>" />
	<input type="hidden" name="signature" value="<?php echo $signature; ?>" />

	<div class="buttons">
	<div class="right">
	    <input type="submit" value="<?php echo $button_confirm; ?>" class="button" />
	</div>
	</div>
</form>

[/codesyntax]

 

 

zen cart — all zen cart url with currency parameter will be redirected to home page

i just found that if any url in a zen cart store containing currency=value,then it will be redirected to zen cart website home page.For example,
http://www.abcdomain.com/xxxxxxxxxxx/xxxxxxxxx/?currency=EUR

This url will be redirected to http://www.abcdomain.com/,it’s a 302 redirect.

is this a zen cart bug?

From the code in this file:/includes/init_includes/init_currencies.php

[codesyntax lang=”php”]

<?php
/**
 * initialise currencies
 * see {@link  http://www.zen-cart.com/wiki/index.php/Developers_API_Tutorials#InitSystem wikitutorials} for more details.
 *
 * @package initSystem
 * @copyright Copyright 2003-2007 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: init_currencies.php 6300 2007-05-11 15:49:41Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}

// If no currency is set, use appropriate default
if (!isset($_SESSION['currency']) && !isset($_GET['currency']) ) $_SESSION['currency'] = DEFAULT_CURRENCY;

// Validate selected new currency, if any. Is false if valid not found.
$new_currency = (isset($_GET['currency'])) ? zen_currency_exists($_GET['currency']) : zen_currency_exists($_SESSION['currency']);

// Validate language-currency and default-currency if relevant. Is false if valid not found.
if ($new_currency == false || isset($_GET['language'])) $new_currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? zen_currency_exists(LANGUAGE_CURRENCY) : $new_currency;

// Final check -- if selected currency is bad and the "default" is bad, default to the first-found currency in order of exch rate.
if ($new_currency == false) $new_currency = zen_currency_exists(DEFAULT_CURRENCY, true);
//echo '<br />NEW = ' . $new_currency . '<br />';

// Now apply currency update
if (
   // Has new currency been selected?
  (isset($_GET['currency'])) || 

  // Does language change require currency update?
  (isset($_GET['language']) && USE_DEFAULT_LANGUAGE_CURRENCY == 'true' && LANGUAGE_CURRENCY != $_SESSION['currency']  )

) {
  $_SESSION['currency'] = $new_currency;
  // redraw the page without the currency/language info in the URL
  if (isset($_GET['currency']) || isset($_GET['language'])) zen_redirect(zen_href_link($current_page_base, zen_get_all_get_params(array('currency','language'))));
}
?>

[/codesyntax]

the zen_redirect make this happen.