Ejemplo n.º 1
0
 /**
  * Returns an array containing all the active shipment conditions.
  *
  * The array has the form
  *  array(
  *    Shipper name => array(
  *      'countries' => array(
  *        country ID => Country name, [...]
  *      ),
  *      'conditions' => array(
  *        Maximum weight => array(
  *          'max_weight' => maximum weight (formatted, or "unlimited"),
  *          'free_from' => no charge lower limit (amount),
  *          'fee' => shipping fee (amount),
  *        ),
  *        [... more ...]
  *      ),
  *    ),
  *    [... more ...]
  *  )
  * Countries are ordered by ascending names.
  * Conditions are ordered by ascending maximum weight.
  * @global  ADONewConnection  $objDatabase
  * @global  array   $_ARRAYLANG
  * @return  array             Countries and conditions array on success,
  *                            false otherwise
  * @static
  */
 static function getShipmentConditions()
 {
     global $objDatabase, $_ARRAYLANG;
     if (empty(self::$arrShippers)) {
         self::init();
     }
     // Get shippers and associated countries (via zones).
     // Make an array(shipper_name => array( array(country, ...), array(conditions) )
     // where the countries are listed as strings of their names,
     // and the conditions look like: array(max_weight, free_from, fee)
     // Return this
     $arrResult = array();
     foreach (self::$arrShippers as $shipper_id => $shipper) {
         // Get countries covered by this shipper
         $arrSqlName = \Cx\Core\Country\Controller\Country::getSqlSnippets();
         $objResult = $objDatabase->Execute("\n                SELECT DISTINCT `country`.`id`," . $arrSqlName['field'] . "\n                  FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_shipper` AS `shipper`\n                 INNER JOIN `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_shipper` AS `rel_shipper`\n                    ON `shipper`.`id`=`rel_shipper`.`shipper_id`\n                 INNER JOIN `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_zones` AS `zone`\n                    ON `rel_shipper`.`zone_id`=`zone`.`id`\n                 INNER JOIN `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_countries` AS `rel_country`\n                    ON `zone`.`id`=`rel_country`.`zone_id`\n                 INNER JOIN `" . DBPREFIX . "core_country` AS `country`\n                    ON `rel_country`.`country_id`=`country`.`id`" . $arrSqlName['join'] . "\n                 WHERE `shipper`.`id`=?\n                   AND `zone`.`active`=1\n                   AND `shipper`.`active`=1\n                   AND `country`.`active`=1\n                 ORDER BY " . $arrSqlName['alias']['name'] . " ASC", $shipper_id);
         if (!$objResult) {
             return self::errorHandler();
         }
         $arrCountries = array();
         while (!$objResult->EOF) {
             $country_id = $objResult->fields['id'];
             $strName = $objResult->fields['name'];
             if (is_null($strName)) {
                 $objText = \Text::getById($country_id, 'Shop', self::TEXT_NAME);
                 if ($objText) {
                     $strName = $objText->content();
                 }
             }
             $arrCountries[$country_id] = $strName;
             $objResult->MoveNext();
         }
         // Now add the conditions, and order them by weight
         $arrConditions = array();
         foreach (self::$arrShipments[$shipper_id] as $arrCond) {
             $arrConditions[$arrCond['max_weight']] = array('max_weight' => $arrCond['max_weight'] > 0 ? $arrCond['max_weight'] : $_ARRAYLANG['TXT_SHOP_WEIGHT_UNLIMITED'], 'free_from' => $arrCond['free_from'] > 0 ? $arrCond['free_from'] : '-', 'fee' => $arrCond['fee'] > 0 ? $arrCond['fee'] : $_ARRAYLANG['TXT_SHOP_COST_FREE']);
         }
         krsort($arrConditions);
         $arrResult[$shipper['name']] = array('countries' => $arrCountries, 'conditions' => $arrConditions);
     }
     return $arrResult;
 }