Diese Seite wird aktuell überarbeitet

Compatibility Layer

3 minutes, 11 seconds

How to build an addon compatible with osCommerce, Zencart, CRE Loaded and xtCommerce

Zencart, CRE Loaded and xtCommerce are branches build on osCommerce ms2.2. The general folder structure and framework is very similar, but not the same.

Following a short overview how MailBeez is build to be compatible with all platforms.

Recognize Platform

file: mailhive/common/functions/compatibility.php
[php]
if (function_exists(‘zen_redirect’) ) {
define (‘MH_PLATFORM’, ‘zencart’);
// sorry zencart – didn’t had the time to migrate everything to your DB-Class (might come later – its cool)
// http://www.zen-cart.com/wiki/index.php/Developers_-_Porting_modules_from_osC
require_once(DIR_FS_CATALOG. ‘mailhive/common/functions/osc_database.php’);
} elseif (function_exists(‘xtc_redirect’) ) {
define (‘MH_PLATFORM’, ‘xtc’);
if (!function_exists(‘xtc_date_short’)) {
require_once(DIR_FS_INC.’xtc_date_short.inc.php’);
}
} else {
define (‘MH_PLATFORM’, ‘oscommerce’);
// covers CRE Loaded as well
}
[/php]

Function mapping

switch to function-set of current platform. This example shows how to map to the platform-specific functions, the addon uses “mh_redirect()” as an abstract function call

[php]
function mh_redirect() {
$args = func_get_args();
switch (MH_PLATFORM) {
case ‘oscommerce’:
case ‘creloaded’:
return call_user_func_array(‘tep_redirect’, $args);
break;
case ‘zencart’:
return call_user_func_array(‘zen_redirect’, $args);
break;
case ‘xtc’:
return call_user_func_array(‘xtc_redirect’, $args);
break;
default:
echo ‘platform not supported’;
}
}
[/php]

Database Layer

osCommerce, CRE Loaded and xtCommerce are using the same model for the Database Layer just with their own function names – so it is an easy mapping.

Zen Cart is different since it uses a Database class with an object oriented model. I like this new approach – it is similar to what osCommerce Online Merchant v3.0 uses – but I was to lazy to rebuild everything.

For Zencart I included the original osCommerce Database Layer – it requires only a small adaption

file: mailhive/common/functions/osc_database.php
[php]$db_link = $db->link;[/php]

Afterwards the database layer looks like this (example mh_db_perform() )

[php]
function mh_db_perform() {
$args = func_get_args();
switch (MH_PLATFORM) {
case ‘oscommerce’:
case ‘creloaded’:
return call_user_func_array(‘tep_db_perform’, $args);
break;
case ‘zencart’:
return call_user_func_array(‘tep_db_perform’, $args);
break;
case ‘xtc’:
return call_user_func_array(‘xtc_db_perform’, $args);
break;
default:
echo ‘platform not supported’;
}
}
[/php]

Email Engine

file: mailhive/common/functions/email_engine.php

Since only osCommerce and CRE Loaded are using the same Email Engine the mapping to the platform’s email engine is separated in it own file.

osCommerce, CRE Loaded
[php]
// function for osCommerce
function osc_sendEmail($mail, $email_address, $sender_name, $sender, $output_subject, $output_content_html, $output_content_txt) {
$mimemessage = new emailMailBeez(array(‘X-Mailer: mailbeez.com’));
// add html and alternative text version
$mimemessage->add_html($output_content_html, $output_content_txt);
$mimemessage->build_message(); // encoding -> 76 character linebreak, replacements must be done before
$mimemessage->send($mail['firstname'] . ‘ ‘ . $mail['lastname'], $email_address, $sender_name, $sender, $output_subject, ”);
}
[/php]

Zen Cart
[php]
// function for ZenCart
function zencart_sendEmail($mail, $email_address, $sender_name, $sender, $output_subject, $output_content_html, $output_content_txt) {
$html_msg = array(‘EMAIL_SUBJECT’ => $output_subject,
‘EMAIL_MESSAGE_HTML’ => $output_content_html); // currently complete HTML mail

zen_mail($mail['firstname'] . ‘ ‘ . $mail['lastname'], $email_address, $output_subject, $output_content_txt, $sender_name, $sender, $html_msg, ‘default’);

// email-format is determined by look-up of email-adress in customer base
}
[/php]

xtCommerce
[php]
// function for xtCommerce
function xtc_sendEmail($mail, $email_address, $sender_name, $sender, $output_subject, $output_content_html, $output_content_txt) {

return xtc_php_mail($sender, $sender_name, $email_address, $mail['firstname'] .’ ‘.$mail['lastname'], ”, $sender, $sender_name, ”, ”, $output_subject, $output_content_html, $output_content_txt);
}
[/php]

If you customized your system to work with another email engine you only need to change this file.

Nächster Beitrag    Vorheriger Beitrag

Top