// Return the options
return array(
'id' => $this->code,
'icon' => false,
'module' => $this->moduleinfo['name'] . ((MODULE_SHIPPING_FRAKTJAKT_TEST_MODE == 'Ja') ? ' [TEST]' : false) . ' (Fel: '. $error_message .')',
'methods' => array(
array(
'id' => 'fallback',
'title' => MODULE_SHIPPING_FRAKTJAKT_FALLBACK_METHOD_NAME,
'cost' => $gross
)
),
'tax' => $tax_rate
);
}
function get_iso_language($language) {
switch ($language) {
case 'english':
return 'en';
case 'svenska':
case 'swedish':
return 'sv';
default:
return 'en';
}
}
function get_proportional_tax_rate() {
// Give access to global variables
global $order;
// Step through every product in shopping cart
foreach ($order->products as $product) {
// Summarize the total gross cost for all products, no matter which tax groups
$products_gross_total += $product['qty'] * $product['final_price'];
// Summarize the total gross cost for all products, no matter which tax groups
$products_tax_total += $product['qty'] * $product['final_price'] * $product['tax'] / 100;
}
// Return proportional tax rate
return $products_tax_total / $products_gross_total * 100;
}
function calculate_table_cost($table, $weight) {
// Split weight table
$table = array_reverse(explode("|" , $table));
// Step through every class entry
foreach ($table as $entry) {
$entry = explode(':', $entry);
// Set cost
if ($weight <= $entry[0]) $this_cost = $entry[1];
}
return $this_cost;
}
function http_post($url, $headers='', $postfields) {
// Using fopen()
if (MODULE_SHIPPING_FRAKTJAKT_HTTP_METHOD == 'fopen') {
if (is_array($postfields)) {
foreach ($postfields as $key => $value) {
$postfields[$key] = $key .'='. urlencode($value);
}
$postfields = implode('&', $postfields);
}
$params = array(
'http' => array(
'method' => 'POST',
'content' => $postfields,
'header' => @implode("\r\n", $headers),
)
);
while ($response == false && $tries < 2) {
$this->debug[] = '[fopen] Connecting to ' . $url .' at '. date('H:i:s') . '.';
$ctx = @stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
$response = @stream_get_contents($fp);
$this->debug[] = '[fopen] ' . ((!$response) ? 'No response data at '. date('H:i:s') .'('. curl_error() .')' : "Got the following HTTP response at ". date('H:i:s') .":\r\n\r\n" . utf8_decode($response) ."\r\n\r\n");
$tries++;
}
return $response;
// Using libcurl
} else {
// BOF: PHP bug #27040 circumvention (<http://bugs.php.net/bug.php?id=27040>)
// Solution for known bug where CURLOPT_POSTFIELDS doesnt work with arrays
if (is_array($postfields)) {
foreach ($postfields as $key => $value) {
$postfields[$key] = $key .'='. urlencode($value);
}
$postfields = implode('&', $postfields);
}
// EOF: PHP bug #27040 circumvention
while ($response == false && $tries < 2) {
$this->debug[] = '[cURL] Connecting to '. $url .' at '. date('H:i:s') .'.';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FAILONERROR, false); // fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // allow redirects
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); // forces a non-cached connection
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // set http headers
curl_setopt($ch, CURLOPT_POST, true); // initialize post method
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); // variables to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // timeout after 30s
$response = curl_exec($ch);
$this->debug[] = '[cURL] ' . ((!$response) ? 'No response data at '. date('H:i:s') .'('. curl_error() .')' : "Got the following HTTP response at ". date('H:i:s') .":\r\n\r\n" . utf8_decode($response) ."\r\n\r\n");
curl_close($ch);
$tries++;
}
return $response;
}
}
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FRAKTJAKT_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
function install() {
global $db;
$this->remove();
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Tjänsten aktiverad?', 'MODULE_SHIPPING_FRAKTJAKT_STATUS', 'Ja', 'Vill du hämta priser för frakt från Fraktjakt.se?', '6', '0', 'zen_cfg_select_option(array(\'Ja\', \'Nej\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Ikon', 'MODULE_SHIPPING_FRAKTJAKT_ICON', '', 'Om du vill visa en ikon istället för ett textalternativ, ange webbsökväg ex. /images/myicon.gif', '6', '1', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Fraktjakt användarnamn', 'MODULE_SHIPPING_FRAKTJAKT_USERNAME', '', 'Ange användarnamn till adminpanelen hos Fraktjakt.', '6', '2', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Fraktjakt lösenord', 'MODULE_SHIPPING_FRAKTJAKT_PASSWORD', '', 'Ange lösenord till adminpanelen hos Fraktjakt.', '6', '3', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Fraktjakt Consignor ID', 'MODULE_SHIPPING_FRAKTJAKT_CONSIGNOR_ID', '', 'Ange ditt id för Fraktjakt API.', '6', '4', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Fraktjakt Consignor Key', 'MODULE_SHIPPING_FRAKTJAKT_CONSIGNOR_PASSWORD', '', 'Ange ditt lösenord för API.', '6', '5', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Testläge', 'MODULE_SHIPPING_FRAKTJAKT_TEST_MODE', 'Ja', 'Vill du köra mot Fraktjakts testserver? (Kräver separat konto på testserver)', '6', '6', 'zen_cfg_select_option(array(\'Ja\', \'Nej\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Kommunikationsmetod', 'MODULE_SHIPPING_FRAKTJAKT_HTTP_METHOD', 'libcurl', 'Ange önskad serverkomponent för kommunicering.', '6', '0', 'zen_cfg_select_option(array(\'fopen\', \'libcurl\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Felsökningsläge?', 'MODULE_SHIPPING_FRAKTJAKT_DEBUG_STATUS', 'Ja', 'Vill du köra i felsökningsläge? Rapporter kommer att skickas till dig via e-post vid varje API anslutning. Om du inte kör felsökningsläge kommer endast felrapporteringar skickas via e-post.', '6', '7', 'zen_cfg_select_option(array(\'Ja\', \'Nej\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('E-postadress för rapporter', 'MODULE_SHIPPING_FRAKTJAKT_REPORT_EMAIL', '', 'Ange en mottagaradress för tekniska rapporteringar.', '6', '8', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Pristabell för reservutväg vid inrikes sändning', 'MODULE_SHIPPING_FRAKTJAKT_SHIPIPNG_TABLE_DOMESTIC', '3:112|5:128|10:168|15:204|20:236', '', '6', '9', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Pristabell för reservutväg vid utrikes sändning inom Europa', 'MODULE_SHIPPING_FRAKTJAKT_SHIPIPNG_TABLE_EUROPE', '3:210|5:250|10:350|15:450|20:550|25:650|30:750', '', '6', '10', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Pristabell för reservutväg vid utrikes sändning utanför Europa', 'MODULE_SHIPPING_FRAKTJAKT_SHIPIPNG_TABLE_WORLD', '3:321|5:435|10:720|15:1005|20:1290|25:1575|30:1860', '', '6', '11', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Momsfunktion', 'MODULE_SHIPPING_FRAKTJAKT_TAX_TYPE', 'Variabel', 'Ange önskad momsfunktion ex. Standard för att själv ange momsklass nedan eller Variabel för att frakten regelriktigt skall ärva momsen från varorna (OBS! kräver TiM\'s ordertotal-moduler).', '6', '12', 'zen_cfg_select_option(array(\'Standard\', \'Variabel\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Momsklass', 'MODULE_SHIPPING_FRAKTJAKT_TAX_CLASS', '0', 'Ange momsklass för fraktavgiften.', '6', '13', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sortering', 'MODULE_SHIPPING_FRAKTJAKT_SORT_ORDER', '0', 'Ange plats i modulernas sorteringsordning.', '6', '14', now())");
}
function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}
function keys() {
return array (
'MODULE_SHIPPING_FRAKTJAKT_STATUS',
'MODULE_SHIPPING_FRAKTJAKT_ICON',
'MODULE_SHIPPING_FRAKTJAKT_USERNAME',
'MODULE_SHIPPING_FRAKTJAKT_PASSWORD',
'MODULE_SHIPPING_FRAKTJAKT_CONSIGNOR_ID',
'MODULE_SHIPPING_FRAKTJAKT_CONSIGNOR_PASSWORD',
'MODULE_SHIPPING_FRAKTJAKT_TEST_MODE',
'MODULE_SHIPPING_FRAKTJAKT_HTTP_METHOD',
'MODULE_SHIPPING_FRAKTJAKT_DEBUG_STATUS',
'MODULE_SHIPPING_FRAKTJAKT_REPORT_EMAIL',
'MODULE_SHIPPING_FRAKTJAKT_SHIPIPNG_TABLE_DOMESTIC',
'MODULE_SHIPPING_FRAKTJAKT_SHIPIPNG_TABLE_EUROPE',
'MODULE_SHIPPING_FRAKTJAKT_SHIPIPNG_TABLE_WORLD',
'MODULE_SHIPPING_FRAKTJAKT_TAX_TYPE',
'MODULE_SHIPPING_FRAKTJAKT_TAX_CLASS',
'MODULE_SHIPPING_FRAKTJAKT_SORT_ORDER'
);
}
}
?>