[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 usps.php

Zen Cart 源代码 usps.php




下载文件

文件名: usps.php
文件类型: PHP文件
文件大小: 37.02 KiB
MD5: 4d5d3512f887b2919dd9a1566bfefffc

usps.php - 关闭高亮
  1. <?php
  2. /**
  3.  * USPS Module for Zen Cart v1.3.x
  4.  * RateV3 Updates to: January 4, 2010
  5.  *
  6.  * @package shippingMethod
  7.  * @copyright Copyright 2003-2010 Zen Cart Development Team
  8.  * @copyright Portions Copyright 2003 osCommerce
  9.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  10.  * @version $Id: usps.php 15881 2010-04-11 16:32:39Z wilt $
  11.  */
  12. /**
  13.  * USPS Shipping Module class
  14.  *
  15.  */
  16. class usps extends base {
  17.   /**
  18.    * Declare shipping module alias code
  19.    *
  20.    * @var string
  21.    */
  22.   var $code;
  23.   /**
  24.    * Shipping module display name
  25.    *
  26.    * @var string
  27.    */
  28.   var $title;
  29.   /**
  30.    * Shipping module display description
  31.    *
  32.    * @var string
  33.    */
  34.   var $description;
  35.   /**
  36.    * Shipping module icon filename/path
  37.    *
  38.    * @var string
  39.    */
  40.   var $icon;
  41.   /**
  42.    * Shipping module status
  43.    *
  44.    * @var boolean
  45.    */
  46.   var $enabled;
  47.   /**
  48.    * Shipping module list of supported countries (unique to USPS/UPS)
  49.    *
  50.    * @var array
  51.    */
  52.   var $countries;
  53.   /**
  54.    * Constructor
  55.    *
  56.    * @return usps
  57.    */
  58.  
  59. // use USPS translations for US shops
  60.    var $usps_countries;
  61.  
  62.   function usps() {
  63.     global $order, $db, $template, $current_page_base;
  64.  
  65.     $this->code = 'usps';
  66.     $this->title = MODULE_SHIPPING_USPS_TEXT_TITLE;
  67.     $this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION;
  68.     $this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER;
  69.     $this->icon = $template->get_template_dir('shipping_usps.gif', DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . 'shipping_usps.gif';
  70.     $this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS;
  71.     $this->tax_basis = MODULE_SHIPPING_USPS_TAX_BASIS;
  72.  
  73.     // disable only when entire cart is free shipping
  74.     if (zen_get_shipping_enabled($this->code)) {
  75.       $this->enabled = ((MODULE_SHIPPING_USPS_STATUS == 'True') ? true : false);
  76.     }
  77.  
  78.     if ($this->enabled) {
  79.       // check MODULE_SHIPPING_USPS_HANDLING_METHOD is in
  80.       $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_HANDLING_METHOD'");
  81.       if ($check_query->EOF) {
  82.         $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Handling Per Order or Per Box', 'MODULE_SHIPPING_USPS_HANDLING_METHOD', 'Box', 'Do you want to charge Handling Fee Per Order or Per Box?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())");
  83.       }
  84.     }
  85.  
  86.     if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {
  87.       $check_flag = false;
  88.       $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_USPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
  89.       while (!$check->EOF) {
  90.         if ($check->fields['zone_id'] < 1) {
  91.           $check_flag = true;
  92.           break;
  93.         } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
  94.           $check_flag = true;
  95.           break;
  96.         }
  97.         $check->MoveNext();
  98.       }
  99.  
  100.       if ($check_flag == false) {
  101.         $this->enabled = false;
  102.       }
  103.     }
  104.  
  105.     $this->types = array('EXPRESS' => 'Express Mail',
  106.         'FIRST CLASS' => 'First-Class Mail',
  107.         'PRIORITY' => 'Priority Mail',
  108.         'PARCEL' => 'Parcel Post',
  109.         'MEDIA' => 'Media Mail',
  110.         'BPM' => 'Bound Printed Matter',
  111.         'LIBRARY' => 'Library'
  112.         );
  113.  
  114.     $this->intl_types = array(
  115.         'Global Express' => 'Global Express Guaranteed (GXG)',
  116.         'Global Express Non-Doc Rect' => 'Global Express Guaranteed Non-Document Rectangular',
  117.         'Global Express Non-Doc Non-Rect' => 'Global Express Guaranteed Non-Document Non-Rectangular',
  118.         'Global Express Envelopes' => 'USPS GXG Envelopes',
  119.         'Express Mail Int' => 'Express Mail International',
  120.         'Express Mail Int Flat Rate Env' => 'Express Mail International Flat Rate Envelope',
  121.         'Priority Mail International' => 'Priority Mail International',
  122.         'Priority Mail Int Flat Rate Env' => 'Priority Mail International Flat Rate Envelope',
  123.         'Priority Mail Int Flat Rate Box' => 'Priority Mail International Flat Rate Box',
  124.         'Priority Mail Int Flat Rate Small Box' => 'Priority Mail International Small Flat Rate Box',
  125.         'Priority Mail Int Flat Rate Med Box' => 'Priority Mail International Medium Flat Rate Box',
  126.         'Priority Mail Int Flat Rate Lrg Box' => 'Priority Mail International Large Flat Rate Box',
  127.         'First Class Mail Int Lrg Env' => 'First-Class Mail International Large Envelope',
  128.         'First Class Mail Int Package' => 'First-Class Mail International Package',
  129.         'First Class Mail Int Letter' => 'First-Class Mail International Letter'
  130.         );
  131.  
  132.  
  133.     $this->countries = $this->country_list();
  134.  
  135. // use USPS translations for US shops
  136.     $this->usps_countries = $this->usps_translation();
  137.  
  138.   }
  139.  
  140.   /**
  141.    * Get quote from shipping provider's API:
  142.    *
  143.    * @param string $method
  144.    * @return array of quotation results
  145.    */
  146.   function quote($method = '') {
  147.     // BOF: UPS USPS
  148.     global $order, $shipping_weight, $shipping_num_boxes, $transittime;
  149.  
  150.     if ( zen_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {
  151.       $this->_setService($method);
  152.     }
  153.  
  154.  
  155.     // usps doesnt accept zero weight send 1 ounce (0.0625) minimum
  156.     $usps_shipping_weight = ($shipping_weight <= 0.0 ? 0.0625 : $shipping_weight);
  157.     $shipping_pounds = floor ($usps_shipping_weight);
  158.     $shipping_ounces = (16 * ($usps_shipping_weight - floor($usps_shipping_weight)));
  159.     // usps currently cannot handle more than 5 digits on international
  160.     $shipping_ounces = zen_round($shipping_ounces, 3);
  161.     // weight must be less than 35lbs and greater than 6 ounces or it is not machinable
  162.     switch(true) {
  163.       case ($shipping_pounds == 0 and $shipping_ounces < 6):
  164.       // override admin choice too light
  165.       $is_machinable = 'False';
  166.       break;
  167.  
  168.       case ($usps_shipping_weight > 35):
  169.       // override admin choice too heavy
  170.       $is_machinable = 'False';
  171.       break;
  172.  
  173.       default:
  174.       // admin choice on what to use
  175.       $is_machinable = MODULE_SHIPPING_USPS_MACHINABLE;
  176.     }
  177.  
  178.     $this->_setMachinable($is_machinable);
  179.     $this->_setContainer('None');
  180.     $this->_setSize('REGULAR');
  181.     $this->_setFirstClassType('FLAT');
  182.  
  183.     $this->_setWeight($shipping_pounds, $shipping_ounces);
  184.     $uspsQuote = $this->_getQuote();
  185.  
  186.     if (is_array($uspsQuote)) {
  187.       if (isset($uspsQuote['error'])) {
  188.         $this->quotes = array('module' => $this->title,
  189.                               'error' => $uspsQuote['error']);
  190.       } else {
  191.  
  192.         // BOF: UPS USPS
  193.         if (in_array('Display weight', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) {
  194.           switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
  195.             case (0):
  196.             $show_box_weight = '';
  197.             break;
  198.             case (1):
  199.             $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')';
  200.             break;
  201.             case (2):
  202.             $show_box_weight = ' (' . number_format($usps_shipping_weight * $shipping_num_boxes,2) . TEXT_SHIPPING_WEIGHT . ')';
  203.             break;
  204.             default:
  205.             $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($usps_shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')';
  206.             break;
  207.           }
  208.         }
  209.         // EOF: UPS USPS
  210.  
  211.         // BOF: UPS USPS
  212.         $this->quotes = array('id' => $this->code,
  213.         'module' => $this->title . $show_box_weight);
  214.         // EOF: UPS USPS
  215.  
  216.         $methods = array();
  217.         $size = sizeof($uspsQuote);
  218.         for ($i=0; $i<$size; $i++) {
  219.           list($type, $cost) = each($uspsQuote[$i]);
  220.  
  221.           // BOF: UPS USPS
  222.           $title = ((isset($this->types[$type])) ? $this->types[$type] : $type);
  223.           if(in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS)))    $title .= $transittime[$type];
  224.           /*
  225.           $methods[] = array('id' => $type,
  226.           'title' => ((isset($this->types[$type])) ? $this->types[$type] : $type),
  227.           'cost' => ($cost + MODULE_SHIPPING_USPS_HANDLING) * $shipping_num_boxes);
  228.           */
  229.           $cost = preg_replace('/[^0-9.]/', '',  $cost);
  230.           $methods[] = array('id' => $type,
  231.                              'title' => $title,
  232.                              'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING) );
  233.  
  234.         }
  235.  
  236.         $this->quotes['methods'] = $methods;
  237.  
  238.         if ($this->tax_class > 0) {
  239.           $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  240.         }
  241.       }
  242.     } elseif ($uspsQuote == -1) {
  243.       $this->quotes = array('module' => $this->title,
  244.                             'error' => MODULE_SHIPPING_USPS_TEXT_SERVER_ERROR . (MODULE_SHIPPING_USPS_SERVER=='test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : ''));
  245.     } else {
  246.       $this->quotes = array('module' => $this->title,
  247.                             'error' => MODULE_SHIPPING_USPS_TEXT_ERROR . (MODULE_SHIPPING_USPS_SERVER=='test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : ''));
  248.     }
  249.  
  250.     if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
  251.  
  252.     return $this->quotes;
  253.   }
  254.   /**
  255.    * check status of module
  256.    *
  257.    * @return boolean
  258.    */
  259.   function check() {
  260.     global $db;
  261.     if (!isset($this->_check)) {
  262.       $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_STATUS'");
  263.       $this->_check = $check_query->RecordCount();
  264.     }
  265.     return $this->_check;
  266.   }
  267.   /**
  268.    * Install this module
  269.    *
  270.    */
  271.   function install() {
  272.     global $db;
  273.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('打开USPS配送模块', 'MODULE_SHIPPING_USPS_STATUS', 'True', '您是否要采用USPS配送方式?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
  274.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('输入USPS网页工具的用户编号', 'MODULE_SHIPPING_USPS_USERID', 'NONE', '输入USPS给您的用于询价的用户ID。', '6', '0', now())");
  275.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('使用的服务器', 'MODULE_SHIPPING_USPS_SERVER', 'production', 'USPS上的帐号连接的服务器', '6', '0', 'zen_cfg_select_option(array(\'test\', \'production\'), ', now())");
  276.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('所有包裹都是标准的', 'MODULE_SHIPPING_USPS_MACHINABLE', 'False', '所有发货的包裹都符合标准C700包裹服务2.0 Nonmachinable PARCEL POST USPS 吗?<br /><br /><strong>提示: 非标准包裹运费较高。<br /><br />包裹重于35lbs的,或小于6 盎司 (.375)的,将被替代并设为False</strong>', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
  277.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('手续费', 'MODULE_SHIPPING_USPS_HANDLING', '0', '该配送方式的手续费。', '6', '0', now())");
  278.  
  279.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('手续费基于订单还是箱数', 'MODULE_SHIPPING_USPS_HANDLING_METHOD', 'Box', '手续费基于订单还是箱数?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())");
  280.  
  281.     $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 ('税率种类', 'MODULE_SHIPPING_USPS_TAX_CLASS', '0', '计算运费使用的税率种类。', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
  282.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('税率基准', 'MODULE_SHIPPING_USPS_TAX_BASIS', 'Shipping', '计算运费税的基准。选项为<br />Shipping - 基于客户的交货人地址<br />Billing - 基于客户的帐单地址<br />Store - 如果帐单地址/送货地区和商店地区相同,则基于商店地址', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())");
  283.     $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 ('送货地区', 'MODULE_SHIPPING_USPS_ZONE', '0', '如果选择了地区,仅该地区采用该配送方式。', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
  284.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('排序顺序', 'MODULE_SHIPPING_USPS_SORT_ORDER', '0', '显示的顺序。', '6', '0', now())");
  285.     // BOF: UPS USPS
  286.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('国内配送方式', 'MODULE_SHIPPING_USPS_TYPES', 'EXPRESS, PRIORITY, FIRST CLASS, PARCEL, MEDIA, BPM, LIBRARY', '选择提供的国内配送服务:', '6', '14', 'zen_cfg_select_multioption(array(\'EXPRESS\', \'PRIORITY\', \'FIRST CLASS\', \'PARCEL\', \'MEDIA\', \'BPM\', \'LIBRARY\'), ',  now())");
  287.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('国际配送方式', 'MODULE_SHIPPING_USPS_TYPES_INTL', 'Global Express, Global Express Non-Doc Rect, Global Express Non-Doc Non-Rect, Global Express Envelopes, Express Mail Int, Express Mail Int Flat Rate Env, Priority Mail International, Priority Mail Int Flat Rate Env, Priority Mail Int Flat Rate Small Box, Priority Mail Int Flat Rate Med Box, Priority Mail Int Flat Rate Lrg Box, First Class Mail Int Lrg Env, First Class Mail Int Package, First Class Mail Int Letter', '选择提供的国际配送服务:', '6', '15', 'zen_cfg_select_multioption(array(\'Global Express\', \'Global Express Non-Doc Rect\', \'Global Express Non-Doc Non-Rect\', \'Global Express Envelopes\', \'Express Mail Int\', \'Express Mail Int Flat Rate Env\', \'Priority Mail International\', \'Priority Mail Int Flat Rate Env\', \'Priority Mail Int Flat Rate Small Box\', \'Priority Mail Int Flat Rate Med Box\', \'Priority Mail Int Flat Rate Lrg Box\', \'First Class Mail Int Lrg Env\', \'First Class Mail Int Package\', \'First Class Mail Int Letter\'), ',  now())");
  288.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('USPS选项', 'MODULE_SHIPPING_USPS_OPTIONS', 'Display weight, Display transit time', '从下面选择USPS选项.', '6', '16', 'zen_cfg_select_multioption(array(\'Display weight\', \'Display transit time\'), ',  now())");
  289.     // EOF: UPS USPS
  290.     $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Debug Mode', 'MODULE_SHIPPING_USPS_DEBUG_MODE', 'Off', 'Would you like to enable debug mode?  A complete detailed log of USPS quote results may be emailed to the store owner.', '6', '0', 'zen_cfg_select_option(array(\'Off\', \'Email\'), ', now())");
  291.   }
  292.   /**
  293.    * Remove this module
  294.    *
  295.    */
  296.   function remove() {
  297.     global $db;
  298.     $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key like 'MODULE\_SHIPPING\_USPS\_%' ");
  299.   }
  300.   /**
  301.    * Build array of keys used for installing/managing this module
  302.    *
  303.    * @return array
  304.    */
  305.   function keys() {
  306.     $keys_list = array('MODULE_SHIPPING_USPS_STATUS', 'MODULE_SHIPPING_USPS_USERID', 'MODULE_SHIPPING_USPS_SERVER', 'MODULE_SHIPPING_USPS_HANDLING', 'MODULE_SHIPPING_USPS_HANDLING_METHOD', 'MODULE_SHIPPING_USPS_TAX_CLASS', 'MODULE_SHIPPING_USPS_TAX_BASIS', 'MODULE_SHIPPING_USPS_ZONE', 'MODULE_SHIPPING_USPS_SORT_ORDER', 'MODULE_SHIPPING_USPS_MACHINABLE', 'MODULE_SHIPPING_USPS_OPTIONS', 'MODULE_SHIPPING_USPS_TYPES', 'MODULE_SHIPPING_USPS_TYPES_INTL');
  307.     $keys_list[]='MODULE_SHIPPING_USPS_DEBUG_MODE';
  308.     return $keys_list;
  309.   }
  310.   /**
  311.    * Set USPS service mode
  312.    *
  313.    * @param string $service
  314.    */
  315.   function _setService($service) {
  316.     $this->service = $service;
  317.   }
  318.   /**
  319.    * Set USPS weight for quotation collection
  320.    *
  321.    * @param integer $pounds
  322.    * @param integer $ounces
  323.    */
  324.   function _setWeight($pounds, $ounces=0) {
  325.     $this->pounds = $pounds;
  326.     $this->ounces = $ounces;
  327.   }
  328.   /**
  329.    * Set USPS container type
  330.    *
  331.    * @param string $container
  332.    */
  333.   function _setContainer($container) {
  334.     $this->container = $container;
  335.   }
  336.  
  337.   /**
  338.    * Set USPS Firs Class type
  339.    *
  340.    * @param string $fctype
  341.    */
  342.   function _setFirstClassType($fctype) {
  343.     $this->fctype = $fctype;
  344.   }
  345.  
  346.   /**
  347.  
  348.    * Set USPS package size
  349.    *
  350.    * @param integer $size
  351.    */
  352.   function _setSize($size) {
  353.     $this->size = $size;
  354.   }
  355.   /**
  356.    * Set USPS machinable flag
  357.    *
  358.    * @param boolean $machinable
  359.    */
  360.   function _setMachinable($machinable) {
  361.     $this->machinable = $machinable;
  362.   }
  363.   /**
  364.    * Get actual quote from USPS
  365.    *
  366.    * @return array of results or boolean false if no results
  367.    */
  368.   function _getQuote() {
  369.     // BOF: UPS USPS
  370.     global $order, $transittime;
  371.     if(in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) $transit = TRUE;
  372.     // EOF: UPS USPS
  373.  
  374. // translate for US Territories
  375. //    if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
  376.     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) {
  377.       $request  = '<RateV3Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">';
  378.       $services_count = 0;
  379.  
  380.       if (isset($this->service)) {
  381.         $this->types = array($this->service => $this->types[$this->service]);
  382.       }
  383.  
  384.       $dest_zip = str_replace(' ', '', $order->delivery['postcode']);
  385. // translate for US Territories
  386.       if ($order->delivery['country']['iso_code_2'] == 'US' || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) $dest_zip = substr($dest_zip, 0, 5);
  387.  
  388.       reset($this->types);
  389.       // BOF: UPS USPS
  390.       $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES);
  391.       while (list($key, $value) = each($this->types)) {
  392.         // BOF: UPS USPS
  393.         if ( !in_array($key, $allowed_types) ) continue;
  394.           //For Options list, go to page 6 of document: http://www.usps.com/webtools/_pdf/Rate-Calculators-v1-2.pdf
  395.           //FIRST CLASS MAIL OPTIONS
  396.           if ($key == 'FIRST CLASS') {
  397.             $this->FirstClassMailType = '<FirstClassMailType>LETTER</FirstClassMailType>';
  398.           } else {
  399.             $this->FirstClassMailType = '';
  400.           }
  401.           //PRIORITY MAIL OPTIONS
  402.           if ($key == 'PRIORITY'){
  403.             $this->container = ''; // Blank, Flate Rate Envelope, or Flat Rate Box // Sm Flat Rate Box, Md Flat Rate Box and Lg Flat Rate Box
  404.  
  405.           }
  406.           //EXPRESS MAIL OPTIONS
  407.           if ($key == 'EXPRESS'){
  408.             $this->container = '';  // Blank, or Flate Rate Envelope
  409.           }
  410.           //PARCEL POST OPTIONS
  411.           if ($key == 'PARCEL'){
  412.             $this->container = 'Regular';
  413.             $this->machinable = 'true';
  414.           }
  415.           //BPM OPTIONS
  416.           //MEDIA MAIL OPTIONS
  417.           //LIBRARY MAIL OPTIONS
  418.         $request .= '<Package ID="' . $services_count . '">' .
  419.         '<Service>' . $key . '</Service>' .
  420.         '<FirstClassMailType>' . $this->fctype . '</FirstClassMailType>' .
  421.         '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' .
  422.         '<ZipDestination>' . $dest_zip . '</ZipDestination>' .
  423.         '<Pounds>' . $this->pounds . '</Pounds>' .
  424.         '<Ounces>' . $this->ounces . '</Ounces>' .
  425.         '<Container>' . $this->container . '</Container>' .
  426.         '<Size>' . $this->size . '</Size>' .
  427.         '<Machinable>' . $this->machinable . '</Machinable>' .
  428.         '</Package>';
  429.         // BOF: UPS USPS
  430.         if($transit){
  431.           $transitreq  = 'USERID="' . MODULE_SHIPPING_USPS_USERID . '">' .
  432.           '<OriginZip>' . STORE_ORIGIN_ZIP . '</OriginZip>' .
  433.           '<DestinationZip>' . $dest_zip . '</DestinationZip>';
  434.  
  435.           switch ($key) {
  436.             case 'EXPRESS':  $transreq[$key] = 'API=ExpressMail&XML=' .
  437.             urlencode( '<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>');
  438.             break;
  439.             case 'PRIORITY': $transreq[$key] = 'API=PriorityMail&XML=' .
  440.             urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>');
  441.             break;
  442.             case 'PARCEL':   $transreq[$key] = 'API=StandardB&XML=' .
  443.             urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>');
  444.             break;
  445.             default:         $transreq[$key] = '';
  446.             break;
  447.           }
  448.         }
  449.         // EOF: UPS USPS
  450.         $services_count++;
  451.       }
  452.       $request .= '</RateV3Request>';
  453.  
  454.       $request = 'API=RateV3&XML=' . urlencode($request);
  455.     } else {
  456.       $request  = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '">' .
  457.       '<Package ID="0">' .
  458.       '<Pounds>' . $this->pounds . '</Pounds>' .
  459.       '<Ounces>' . $this->ounces . '</Ounces>' .
  460.       '<MailType>Package</MailType>' .
  461.       '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' .
  462.       '</Package>' .
  463.       '</IntlRateRequest>';
  464.  
  465.       $request = 'API=IntlRate&XML=' . urlencode($request);
  466.     }
  467.  
  468.     switch (MODULE_SHIPPING_USPS_SERVER) {
  469.       case 'production':
  470.       $usps_server = 'production.shippingapis.com';
  471.       $api_dll = 'shippingapi.dll';
  472.       break;
  473.       case 'test':
  474.       default:
  475.       $usps_server = 'testing.shippingapis.com';
  476.       $api_dll = 'ShippingAPI.dll';
  477.       break;
  478.     }
  479.  
  480.     $body = '';
  481.  
  482.     $http = new httpClient();
  483.     $http->timeout = 5;
  484.     if ($http->Connect($usps_server, 80)) {
  485.       $http->addHeader('Host', $usps_server);
  486.       $http->addHeader('User-Agent', 'Zen Cart');
  487.       $http->addHeader('Connection', 'Close');
  488.  
  489.       if ($http->Get('/' . $api_dll . '?' . $request)) $body = $http->getBody();
  490.       if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Email') mail(STORE_OWNER_EMAIL_ADDRESS, 'Debug: USPS rate quote response', '(You can turn off this debug email by editing your USPS module settings in the admin area of your store.) ' . "\n\n" . $body, 'From: <' . EMAIL_FROM . '>');
  491.       // BOF: UPS USPS
  492.  
  493. // translate for US Territories
  494. //      if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) {
  495.       if ($transit && is_array($transreq) && ( ($order->delivery['country']['id'] == STORE_COUNTRY || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US') )) ) {
  496.         while (list($key, $value) = each($transreq)) {
  497.           if ($http->Get('/' . $api_dll . '?' . $value)) $transresp[$key] = $http->getBody();
  498.         }
  499.       }
  500.       // EOF: UPS USPS
  501.  
  502.       $http->Disconnect();
  503.     } else {
  504.       return -1;
  505.     }
  506.  
  507.     $response = array();
  508.     while (true) {
  509.       if ($start = strpos($body, '<Package ID=')) {
  510.         $body = substr($body, $start);
  511.         $end = strpos($body, '</Package>');
  512.         $response[] = substr($body, 0, $end+10);
  513.         $body = substr($body, $end+9);
  514.       } else {
  515.         break;
  516.       }
  517.     }
  518.  
  519.     $rates = array();
  520.  
  521. // translate for US Territories
  522. //    if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
  523.     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY  || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) {
  524.       if (sizeof($response) == '1') {
  525.         if (preg_match('/<Error>/i', $response[0])) {
  526.           $number = preg_match('/<Number>(.*)<\/Number>/msi', $response[0], $regs);
  527.           $number = $regs[1];
  528.           $description = preg_match('/<Description>(.*)<\/Description>/msi', $response[0], $regs);
  529.           $description = $regs[1];
  530.  
  531.           return array('error' => $number . ' - ' . $description);
  532.         }
  533.       }
  534.  
  535.       $n = sizeof($response);
  536.       for ($i=0; $i<$n; $i++) {
  537.         if (strpos($response[$i], '<Rate>')) {
  538.           $service = preg_match('/<MailService>(.*)<\/MailService>/msi', $response[$i], $regs);
  539.           $service = $regs[1];
  540.           if (preg_match('/Express/i', $service)) $service = 'EXPRESS';
  541.           if (preg_match('/Priority/i', $service)) $service = 'PRIORITY';
  542.           if (preg_match('/First-Class Mail/i', $service)) $service = 'FIRST CLASS';
  543.           if (preg_match('/Parcel/i', $service)) $service = 'PARCEL';
  544.           if (preg_match('/Media/i', $service)) $service = 'MEDIA';
  545.           if (preg_match('/Bound Printed/i', $service)) $service = 'BPM';
  546.           if (preg_match('/Library/i', $service)) $service = 'LIBRARY';
  547.           $postage = preg_match('/<Rate>(.*)<\/Rate>/msi', $response[$i], $regs);
  548.           $postage = $regs[1];
  549.  
  550.           $rates[] = array($service => $postage);
  551.           // BOF: UPS USPS
  552.           if ($transit) {
  553.             switch ($service) {
  554.               case 'EXPRESS':     $time = preg_match('/<MonFriCommitment>(.*)<\/MonFriCommitment>/msi', $transresp[$service], $tregs);
  555.               $time = $tregs[1];
  556.               if ($time == '' || $time == 'No Data') {
  557.                 $time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
  558.               } else {
  559.                 $time = 'Tomorrow by ' . $time;
  560.               }
  561.               break;
  562.               case 'PRIORITY':    $time = preg_match('/<Days>(.*)<\/Days>/msi', $transresp[$service], $tregs);
  563.               $time = $tregs[1];
  564.               if ($time == '' || $time == 'No Data') {
  565.                 $time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
  566.               } elseif ($time == '1') {
  567.                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;
  568.               } else {
  569.                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
  570.               }
  571.               break;
  572.               case 'PARCEL':      $time = preg_match('/<Days>(.*)<\/Days>/msi', $transresp[$service], $tregs);
  573.               $time = $tregs[1];
  574.               if ($time == '' || $time == 'No Data') {
  575.                 $time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
  576.               } elseif ($time == '1') {
  577.                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;
  578.               } else {
  579.                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
  580.               }
  581.               break;
  582.               case 'FIRST CLASS': $time = '2 - 5 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
  583.               break;
  584.  
  585.  
  586.               default:            $time = '';
  587.               break;
  588.             }
  589.             if ($time != '') $transittime[$service] = ' (' . $time . ')';
  590.           }
  591.           // EOF: UPS USPS
  592.         }
  593.       }
  594.     } else {
  595.       if (preg_match('/<Error>/i', $response[0])) {
  596.         $number = preg_match('/<Number>(.*)<\/Number>/msi', $response[0], $regs);
  597.         $number = $regs[1];
  598.         $description = preg_match('/<Description>(.*)<\/Description>/msi', $response[0], $regs);
  599.         $description = $regs[1];
  600.  
  601.         return array('error' => $number . ' - ' . $description);
  602.       } else {
  603.         $body = $response[0];
  604.         $services = array();
  605.         while (true) {
  606.           if ($start = strpos($body, '<Service ID=')) {
  607.             $body = substr($body, $start);
  608.             $end = strpos($body, '</Service>');
  609.             $services[] = substr($body, 0, $end+10);
  610.             $body = substr($body, $end+9);
  611.           } else {
  612.             break;
  613.           }
  614.         }
  615.  
  616.         // BOF: UPS USPS
  617.         $allowed_types = array();
  618.         foreach( explode(", ", MODULE_SHIPPING_USPS_TYPES_INTL) as $value ) $allowed_types[$value] = $this->intl_types[$value];
  619.         // EOF: UPS USPS
  620.  
  621.         $size = sizeof($services);
  622.         for ($i=0, $n=$size; $i<$n; $i++) {
  623.           if (strpos($services[$i], '<Postage>')) {
  624.             $service = preg_match('/<SvcDescription>(.*)<\/SvcDescription>/msi', $services[$i], $regs);
  625.             $service = $regs[1];
  626.             $postage = preg_match('/<Postage>(.*)<\/Postage>/i', $services[$i], $regs);
  627.             $postage = $regs[1];
  628.             // BOF: UPS USPS
  629.             $time = preg_match('/<SvcCommitments>(.*)<\/SvcCommitments>/msi', $services[$i], $tregs);
  630.             $time = $tregs[1];
  631.             $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time);
  632.             $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time);
  633.             $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time);
  634.  
  635.             if( !in_array($service, $allowed_types) ) continue;
  636.             if ($_SESSION['cart']->total > 400 && strstr($services[$i], 'Priority Mail International Flat Rate Envelope')) continue; // skip value > $400 Priority Mail International Flat Rate Envelope
  637.             // EOF: UPS USPS
  638.             if (isset($this->service) && ($service != $this->service) ) {
  639.               continue;
  640.             }
  641.  
  642.             $rates[] = array($service => $postage);
  643.             // BOF: UPS USPS
  644.             if ($time != '') $transittime[$service] = ' (' . $time . ')';
  645.             // EOF: UPS USPS
  646.           }
  647.         }
  648.       }
  649.     }
  650. //echo 'RATE RESPONSE: ' . "\n" . print_r($rates);
  651.  
  652.     return ((sizeof($rates) > 0) ? $rates : false);
  653.   }
  654.   /**
  655.    * USPS Country Code List
  656.    * This list is used to compare the 2-letter ISO code against the order country ISO code, and provide the proper/expected
  657.    * spelling of the country name to USPS in order to obtain a rate quote
  658.    *
  659.    * @return array
  660.    */
  661.   function country_list() {
  662.     $list = array(
  663.     'AF' => 'Afghanistan',
  664.     'AL' => 'Albania',
  665.     'AX' => 'Aland Island (Finland)',
  666.     'DZ' => 'Algeria',
  667.     'AD' => 'Andorra',
  668.     'AO' => 'Angola',
  669.     'AI' => 'Anguilla',
  670.     'AG' => 'Antigua and Barbuda',
  671.     'AR' => 'Argentina',
  672.     'AM' => 'Armenia',
  673.     'AW' => 'Aruba',
  674.     'AU' => 'Australia',
  675.     'AT' => 'Austria',
  676.     'AZ' => 'Azerbaijan',
  677.     'BS' => 'Bahamas',
  678.     'BH' => 'Bahrain',
  679.     'BD' => 'Bangladesh',
  680.     'BB' => 'Barbados',
  681.     'BY' => 'Belarus',
  682.     'BE' => 'Belgium',
  683.     'BZ' => 'Belize',
  684.     'BJ' => 'Benin',
  685.     'BM' => 'Bermuda',
  686.     'BT' => 'Bhutan',
  687.     'BO' => 'Bolivia',
  688.     'BA' => 'Bosnia-Herzegovina',
  689.     'BW' => 'Botswana',
  690.     'BR' => 'Brazil',
  691.     'VG' => 'British Virgin Islands',
  692.     'BN' => 'Brunei Darussalam',
  693.     'BG' => 'Bulgaria',
  694.     'BF' => 'Burkina Faso',
  695.     'MM' => 'Burma',
  696.     'BI' => 'Burundi',
  697.     'KH' => 'Cambodia',
  698.     'CM' => 'Cameroon',
  699.     'CA' => 'Canada',
  700.     'CV' => 'Cape Verde',
  701.     'KY' => 'Cayman Islands',
  702.     'CF' => 'Central African Republic',
  703.     'TD' => 'Chad',
  704.     'CL' => 'Chile',
  705.     'CN' => 'China',
  706.     'CX' => 'Christmas Island (Australia)',
  707.     'CC' => 'Cocos Island (Australia)',
  708.     'CO' => 'Colombia',
  709.     'KM' => 'Comoros',
  710.     'CG' => 'Congo, Republic of the',
  711.     'CD' => 'Congo, Democratic Republic of the',
  712.     'CK' => 'Cook Islands (New Zealand)',
  713.     'CR' => 'Costa Rica',
  714.     'CI' => 'Cote d Ivoire (Ivory Coast)',
  715.     'HR' => 'Croatia',
  716.     'CU' => 'Cuba',
  717.     'CY' => 'Cyprus',
  718.     'CZ' => 'Czech Republic',
  719.     'DK' => 'Denmark',
  720.     'DJ' => 'Djibouti',
  721.     'DM' => 'Dominica',
  722.     'DO' => 'Dominican Republic',
  723.     'EC' => 'Ecuador',
  724.     'EG' => 'Egypt',
  725.     'SV' => 'El Salvador',
  726.     'GQ' => 'Equatorial Guinea',
  727.     'ER' => 'Eritrea',
  728.     'EE' => 'Estonia',
  729.     'ET' => 'Ethiopia',
  730.     'FK' => 'Falkland Islands',
  731.     'FO' => 'Faroe Islands',
  732.     'FJ' => 'Fiji',
  733.     'FI' => 'Finland',
  734.     'FR' => 'France',
  735.     'GF' => 'French Guiana',
  736.     'PF' => 'French Polynesia',
  737.     'GA' => 'Gabon',
  738.     'GM' => 'Gambia',
  739.     'GE' => 'Georgia, Republic of',
  740.     'DE' => 'Germany',
  741.     'GH' => 'Ghana',
  742.     'GI' => 'Gibraltar',
  743.     'GB' => 'Great Britain and Northern Ireland',
  744.     'GR' => 'Greece',
  745.     'GL' => 'Greenland',
  746.     'GD' => 'Grenada',
  747.     'GP' => 'Guadeloupe',
  748.     'GT' => 'Guatemala',
  749.     'GN' => 'Guinea',
  750.     'GW' => 'Guinea-Bissau',
  751.     'GY' => 'Guyana',
  752.     'HT' => 'Haiti',
  753.     'HN' => 'Honduras',
  754.     'HK' => 'Hong Kong',
  755.     'HU' => 'Hungary',
  756.     'IS' => 'Iceland',
  757.     'IN' => 'India',
  758.     'ID' => 'Indonesia',
  759.     'IR' => 'Iran',
  760.     'IQ' => 'Iraq',
  761.     'IE' => 'Ireland',
  762.     'IL' => 'Israel',
  763.     'IT' => 'Italy',
  764.     'JM' => 'Jamaica',
  765.     'JP' => 'Japan',
  766.     'JO' => 'Jordan',
  767.     'KZ' => 'Kazakhstan',
  768.     'KE' => 'Kenya',
  769.     'KI' => 'Kiribati',
  770.     'KW' => 'Kuwait',
  771.     'KG' => 'Kyrgyzstan',
  772.     'LA' => 'Laos',
  773.     'LV' => 'Latvia',
  774.     'LB' => 'Lebanon',
  775.     'LS' => 'Lesotho',
  776.     'LR' => 'Liberia',
  777.     'LY' => 'Libya',
  778.     'LI' => 'Liechtenstein',
  779.     'LT' => 'Lithuania',
  780.     'LU' => 'Luxembourg',
  781.     'MO' => 'Macao',
  782.     'MK' => 'Macedonia, Republic of',
  783.     'MG' => 'Madagascar',
  784.     'MW' => 'Malawi',
  785.     'MY' => 'Malaysia',
  786.     'MV' => 'Maldives',
  787.     'ML' => 'Mali',
  788.     'MT' => 'Malta',
  789.     'MQ' => 'Martinique',
  790.     'MR' => 'Mauritania',
  791.     'MU' => 'Mauritius',
  792.     'YT' => 'Mayotte (France)',
  793.     'MX' => 'Mexico',
  794.     'FM' => 'Micronesia, Federated States of',
  795.     'MD' => 'Moldova',
  796.     'MC' => 'Monaco (France)',
  797.     'MN' => 'Mongolia',
  798.     'MS' => 'Montserrat',
  799.     'MA' => 'Morocco',
  800.     'MZ' => 'Mozambique',
  801.     'NA' => 'Namibia',
  802.     'NR' => 'Nauru',
  803.     'NP' => 'Nepal',
  804.     'NL' => 'Netherlands',
  805.     'AN' => 'Netherlands Antilles',
  806.     'NC' => 'New Caledonia',
  807.     'NZ' => 'New Zealand',
  808.     'NI' => 'Nicaragua',
  809.     'NE' => 'Niger',
  810.     'NG' => 'Nigeria',
  811.     'KP' => 'North Korea (Korea, Democratic People\'s Republic of)',
  812.    'NO' => 'Norway',
  813.    'OM' => 'Oman',
  814.    'PK' => 'Pakistan',
  815.    'PA' => 'Panama',
  816.    'PG' => 'Papua New Guinea',
  817.    'PY' => 'Paraguay',
  818.    'PE' => 'Peru',
  819.    'PH' => 'Philippines',
  820.    'PN' => 'Pitcairn Island',
  821.    'PL' => 'Poland',
  822.    'PT' => 'Portugal',
  823.    'QA' => 'Qatar',
  824.    'RE' => 'Reunion',
  825.    'RO' => 'Romania',
  826.    'RU' => 'Russia',
  827.    'RW' => 'Rwanda',
  828.    'SH' => 'Saint Helena',
  829.    'KN' => 'Saint Kitts (St. Christopher and Nevis)',
  830.    'LC' => 'Saint Lucia',
  831.    'PM' => 'Saint Pierre and Miquelon',
  832.    'VC' => 'Saint Vincent and the Grenadines',
  833.    'SM' => 'San Marino',
  834.    'ST' => 'Sao Tome and Principe',
  835.    'SA' => 'Saudi Arabia',
  836.    'SN' => 'Senegal',
  837.    'RS' => 'Serbia',
  838.    'SC' => 'Seychelles',
  839.    'SL' => 'Sierra Leone',
  840.    'SG' => 'Singapore',
  841.    'SK' => 'Slovak Republic',
  842.    'SI' => 'Slovenia',
  843.    'SB' => 'Solomon Islands',
  844.    'SO' => 'Somalia',
  845.    'ZA' => 'South Africa',
  846.    'GS' => 'South Georgia (Falkland Islands)',
  847.    'KR' => 'South Korea (Korea, Republic of)',
  848.    'ES' => 'Spain',
  849.    'LK' => 'Sri Lanka',
  850.    'SD' => 'Sudan',
  851.    'SR' => 'Suriname',
  852.    'SZ' => 'Swaziland',
  853.    'SE' => 'Sweden',
  854.    'CH' => 'Switzerland',
  855.    'SY' => 'Syrian Arab Republic',
  856.    'TW' => 'Taiwan',
  857.    'TJ' => 'Tajikistan',
  858.    'TZ' => 'Tanzania',
  859.    'TH' => 'Thailand',
  860.    'TL' => 'East Timor (Indonesia)',
  861.    'TG' => 'Togo',
  862.    'TK' => 'Tokelau (Union) Group (Western Samoa)',
  863.    'TO' => 'Tonga',
  864.    'TT' => 'Trinidad and Tobago',
  865.    'TN' => 'Tunisia',
  866.    'TR' => 'Turkey',
  867.    'TM' => 'Turkmenistan',
  868.    'TC' => 'Turks and Caicos Islands',
  869.    'TV' => 'Tuvalu',
  870.    'UG' => 'Uganda',
  871.    'UA' => 'Ukraine',
  872.    'AE' => 'United Arab Emirates',
  873.    'UY' => 'Uruguay',
  874.    'UZ' => 'Uzbekistan',
  875.    'VU' => 'Vanuatu',
  876.    'VA' => 'Vatican City',
  877.    'VE' => 'Venezuela',
  878.    'VN' => 'Vietnam',
  879.    'WF' => 'Wallis and Futuna Islands',
  880.    'WS' => 'Western Samoa',
  881.    'YE' => 'Yemen',
  882.    'ZM' => 'Zambia',
  883.    'ZW' => 'Zimbabwe'
  884.    );
  885.  
  886.    return $list;
  887.  }
  888.  
  889. // translate for US Territories
  890.  function usps_translation() {
  891.    global $order;
  892.    if (SHIPPING_ORIGIN_COUNTRY == '223') {
  893.      switch($order->delivery['country']['iso_code_2']) {
  894.        case 'AS': // Samoa American
  895.        case 'GU': // Guam
  896.        case 'MP': // Northern Mariana Islands
  897.        case 'PW': // Palau
  898.        case 'PR': // Puerto Rico
  899.        case 'VI': // Virgin Islands US
  900.          return 'US';
  901.          break;
  902. // stays as original country
  903.        case 'FM': // Micronesia, Federated States of
  904.        default:
  905.          return $order->delivery['country']['iso_code_2'];
  906.          break;
  907.      }
  908.    } else {
  909.      return $order->delivery['country']['iso_code_2'];
  910.    }
  911.  }
  912. }
  913.  


cron