Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
#24: Enable shipping-method language translations
Browse files Browse the repository at this point in the history
  • Loading branch information
lat9 committed Jun 29, 2020
1 parent e55c882 commit c305cc6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 51 deletions.
11 changes: 9 additions & 2 deletions docs/upsxml/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<body>
<h1>UPSXML Shipping Module for Zen Cart 1.5.3 and later</h1>
<h3>Version 1.7.7, by lat9</h3>
<h3>Version 1.7.8, by lat9</h3>
<p>Current Support Thread at Zen Cart Forums: <a href="https://www.zen-cart.com/showthread.php?222903-UPS-XML-Support-Thread" target="_blank">https://www.zen-cart.com/showthread.php?222903-UPS-XML-Support-Thread</a></p>

<h4>Contributers and Copyrights</h4>
Expand All @@ -34,7 +34,7 @@ <h4>Contributers and Copyrights</h4>
<li>Insurance Support 2005 Joe McFrederick, jomcfred@oldeparsonage.com</li>
<li>Modified for zen-cart 1.2.5d by Dennis Sayer - July 9, 2005, dennis.s.sayer@brandnamebatteries.com</li>
<li>Updated for zen-cart 1.5.1 by Brian Gundlach - June 10, 2014, Brian@gundlach-marketing.com</li>
<li>Copyright (C) 2017-2019, <a href="https://vinosdefrutastropicales.com" target="_blank">Vinos de Frutas Tropicales</a> (lat9)</li>
<li>Copyright (C) 2017-2020, <a href="https://vinosdefrutastropicales.com" target="_blank">Vinos de Frutas Tropicales</a> (lat9)</li>
</ul>

<hr />
Expand Down Expand Up @@ -111,6 +111,13 @@ <h2>Configure and Test the Shipping Module</h2>
<hr />
<h2>Version History</h2>
<ul>
<li>1.7.8, 2020-06-29 (lat9)<ul>
<li>BUGFIX: Shipping-method names couldn't be translated.</li>
<li>The following files were changed:<ol>
<li>/includes/modules/shipping/upsxml.php.</li>
</ol></li>
<li><b>Note:</b> This update appends the UPS <em>Service Code</em> to the names of the individually-selectable shipping methods. If you are <em>upgrading</em>, it's very, <em>very</em> important to go to your admin's <b><i>Modules-&gt;Shipping</i></b> for your existing configuration to be updated. Otherwise, your customers won't receive UPS quotes.</li>
</ul></li>
<li>1.7.7, 2019-10-23 (lat9)<ul>
<li>BUGFIX: Correct PHP notice when viewing in admin's <b><i>Modules-&gt;Shipping</i></b>.</li>
<li>CHANGE: Display "New version available" information <b>only</b> when viewing the admin's <b><i>Modules-&gt;Shipping</i></b>.</li>
Expand Down
132 changes: 83 additions & 49 deletions includes/modules/shipping/upsxml.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
class upsxml
{
public $code, $title, $description, $icon, $enabled, $types;
public $moduleVersion = '1.7.7';
public $moduleVersion = '1.7.8';

//***************
function __construct()
Expand All @@ -61,7 +61,10 @@ function __construct()
}

$this->enabled = (defined('MODULE_SHIPPING_UPSXML_RATES_STATUS') && MODULE_SHIPPING_UPSXML_RATES_STATUS == 'True');
$this->sort_order = (defined('MODULE_SHIPPING_UPSXML_RATES_SORT_ORDER')) ? (int)MODULE_SHIPPING_UPSXML_RATES_SORT_ORDER : false;
$this->sort_order = (defined('MODULE_SHIPPING_UPSXML_RATES_SORT_ORDER')) ? (int)MODULE_SHIPPING_UPSXML_RATES_SORT_ORDER : null;
if ($this->sort_order === null) {
return false;
}
if ($this->enabled) {
$this->icon = DIR_WS_TEMPLATE . 'images/icons/shipping_ups.gif';
$this->tax_class = (int)MODULE_SHIPPING_UPSXML_RATES_TAX_CLASS;
Expand Down Expand Up @@ -121,16 +124,54 @@ function __construct()
}

// -----
// Provide fix-up to change 'Next Day Air Early A.M.' to 'Next Day Air Early'.
// Provide various configuration fix-ups during admin configuration.
//
if (IS_ADMIN_FLAG === true) {
// -----
// Provide fix-up to change 'Next Day Air Early A.M.' to 'Next Day Air Early'.
//
$GLOBALS['db']->Execute(
"UPDATE " . TABLE_CONFIGURATION . "
SET configuration_value = REPLACE(configuration_value, 'Next Day Air Early A.M.', 'Next Day Air Early'),
set_function = REPLACE(set_function, 'Next Day Air Early A.M.', 'Next Day Air Early')
WHERE configuration_key = 'MODULE_SHIPPING_UPSXML_TYPES'
LIMIT 1"
);

// -----
// v1.7.8: The 'serviceCode' values are now parenthetically suffixed to their respective
// names, enabling multi-language configuration.
//
if (strpos(MODULE_SHIPPING_UPSXML_TYPES, '[') === false) {
$upsxml_value_mapping = array(
'Next Day Air' => '01',
'2nd Day Air' => '02',
'Ground' => '03',
'Worldwide Express' => '07',
'Worldwide Expedited' => '08',
'Standard' => '11',
'3 Day Select' => '12',
'Next Day Air Saver' => '13',
'Next Day Air Early' => '14',
'Worldwide Express Plus' => '54',
'2nd Day Air A.M.' => '59',
'Worldwide Saver' => '65',
);
$upsxml_types_configured = explode(',', str_replace(', ', ',', MODULE_SHIPPING_UPSXML_TYPES));
foreach ($upsxml_types_configured as &$upsxml_type) {
$upsxml_type .= (isset($upsxml_value_mapping[$upsxml_type])) ? (' [' . $upsxml_value_mapping[$upsxml_type] . ']') : ' [???]';
}
unset($upsxml_type);
$upsxml_types = implode(', ', $upsxml_types_configured);

$db->Execute(
"UPDATE " . TABLE_CONFIGURATION . "
SET configuration_value = '$upsxml_types',
set_function = 'zen_cfg_select_multioption(array(\'Next Day Air [01]\', \'2nd Day Air [02]\', \'Ground [03]\', \'Worldwide Express [07]\', \'Worldwide Expedited [08]\', \'Standard [11]\', \'3 Day Select [12]\', \'Next Day Air Saver [13]\', \'Next Day Air Early [14]\', \'Worldwide Express Plus [54]\', \'2nd Day Air A.M. [59]\', \'Express Saver [65]\'), '
WHERE configuration_key = 'MODULE_SHIPPING_UPSXML_TYPES'
LIMIT 1"
);
}
}

// -----
Expand Down Expand Up @@ -341,36 +382,41 @@ public function quote($method = '')
'module' => $this->title . $weight_info
);
$methods = array();
foreach ($upsQuote as $quote) {
foreach ($quote as $type => $cost) {
// BOF limit choices
if (!$this->excludeChoices($type)) {
continue;
}
// EOF limit choices
if ($method == '' || $method == $type) {
$_type = $type;
if ($this->displayTransitTime) {
//if (isset($this->servicesTimeintransit[$type])) {
// $_type = $_type . ", ".$this->servicesTimeintransit[$type]["date"];
//}
// instead of just adding the expected delivery date as ", yyyy-mm-dd"
// you might like to change this to your own liking for example by commenting the
// three lines above this and uncommenting/changing the next:
// START doing things differently
if (isset($this->servicesTimeintransit[$type])) {
$eta_array = explode('-', $this->servicesTimeintransit[$type]["date"]);
$months = array (' ', "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$eta_arrival_date = $months[(int)$eta_array[1]]." ".$eta_array[2].", ".$eta_array[0];
$_type .= ", ETA: ".$eta_arrival_date;
}
// END of doing things differently:
}
foreach ($upsQuote as $serviceCode => $quote_info) {
$type = $quote_info['title'];
$cost = $quote_info['cost'];

$methods[] = array('id' => $type, 'title' => $_type, 'cost' => ($this->handling_fee + $cost));
if ($this->excludeChoices($serviceCode)) {
continue;
}

if ($method == '' || $method == $type) {
$_type = $type;
if ($this->displayTransitTime) {
//if (isset($this->servicesTimeintransit[$type])) {
// $_type = $_type . ", ".$this->servicesTimeintransit[$type]["date"];
//}
// instead of just adding the expected delivery date as ", yyyy-mm-dd"
// you might like to change this to your own liking for example by commenting the
// three lines above this and uncommenting/changing the next:
// START doing things differently
if (isset($this->servicesTimeintransit[$type])) {
$eta_array = explode('-', $this->servicesTimeintransit[$type]["date"]);
$months = array (' ', "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$eta_arrival_date = $months[(int)$eta_array[1]]." ".$eta_array[2].", ".$eta_array[0];
$_type .= ", ETA: ".$eta_arrival_date;
}
// END of doing things differently:
}

$methods[] = array(
'id' => $type,
'title' => $_type,
'cost' => ($this->handling_fee + $cost)
);
}
}

if ($this->tax_class > 0) {
$this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
}
Expand Down Expand Up @@ -473,7 +519,7 @@ public function install()
('Sort order of display.', 'MODULE_SHIPPING_UPSXML_RATES_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', 6, 19, NULL, NULL, now()),
('Shipping Methods', 'MODULE_SHIPPING_UPSXML_TYPES', 'Next Day Air, 2nd Day Air, Ground, Worldwide Express, Standard, 3 Day Select', 'Select the UPS services to be offered.', 6, 20, NULL, 'zen_cfg_select_multioption(array(\'Next Day Air\', \'2nd Day Air\', \'Ground\', \'Worldwide Express\', \'Worldwide Expedited\', \'Standard\', \'3 Day Select\', \'Next Day Air Saver\', \'Next Day Air Early\', \'Worldwide Express Plus\', \'2nd Day Air A.M.\', \'Express NA1\', \'Express Saver\'), ', now()),
('Shipping Methods', 'MODULE_SHIPPING_UPSXML_TYPES', 'Next Day Air [01], 2nd Day Air [02], Ground [03], Worldwide Express [07], Standard [11], 3 Day Select [12]', 'Select the UPS services to be offered.', 6, 20, NULL, 'zen_cfg_select_multioption(array(\'Next Day Air [01]\', \'2nd Day Air [02]\', \'Ground [03]\', \'Worldwide Express [07]\', \'Worldwide Expedited [08]\', \'Standard [11]\', \'3 Day Select [12]\', \'Next Day Air Saver [13]\', \'Next Day Air Early [14]\', \'Worldwide Express Plus [54]\', \'2nd Day Air A.M. [59]\', \'Express Saver [65]\'), ', now()),
('Shipping Delay', 'SHIPPING_DAYS_DELAY', '1', 'How many days from when an order is placed to when you ship it (Decimals are allowed). Arrival date estimations are based on this value.', 6, 7, NULL, NULL, now())"
);
Expand Down Expand Up @@ -887,7 +933,10 @@ protected function _parseResult($xmlResult)
if ($aryProducts === false) {
$aryProducts = array();
}
$aryProducts[$i] = array($title => $totalCharge);
$aryProducts[$serviceCode] = array(
'title' => $title,
'cost' => $totalCharge
);
}
return $aryProducts;
}
Expand Down Expand Up @@ -1019,26 +1068,11 @@ protected function _transitparseResult($xmlTransitResult)
//EOF Time In Transit

// -----
// This method checks to see if the UPS shipping 'type' is one that the store has configured.
//
// The 'type' value is submitted as '[UPS]type-value[(stuff)]' and we're looking for just the
// 'type-value' portion, so we'll remove any 'UPS' present in the value and then truncate
// the string at any open-parentheses found prior to checking.
// This method checks to see if the UPS shipping 'serviceCode' is one that the store has configured.
//
protected function excludeChoices($type)
protected function excludeChoices($serviceCode)
{
$type = str_replace('UPS', '', $type);
if (($pos = strpos($type, '(')) !== false) {
$type = substr($type, 0, $pos + 1);
}
$type = trim($type);
$allowed_types = explode(',', MODULE_SHIPPING_UPSXML_TYPES);
foreach ($allowed_types as $current_type) {
if ($type == trim($current_type)) {
return true;
}
}
return false;
return (strpos(MODULE_SHIPPING_UPSXML_TYPES, " [$serviceCode]") === false);
}

protected function debugLog($message, $include_spacer = false)
Expand Down

0 comments on commit c305cc6

Please sign in to comment.