Ejemplo n.º 1
0
 function shk_currency_calc($properties, $base_price, $currency_id, $rate_ratio = 0)
 {
     $inverse = isset($properties['inverse']) ? $properties['inverse'] : false;
     //обратный перевод цены
     if (!$rate_ratio) {
         if (isset($_SESSION['shk_curr_rate']) && is_numeric($_SESSION['shk_curr_rate']) && !$inverse) {
             $rate_ratio = $_SESSION['shk_curr_rate'];
         } else {
             if (!isset($properties['currency_rate'])) {
                 require_once MODX_CORE_PATH . "components/shopkeeper3/model/shopkeeper.class.php";
                 $config = Shopkeeper::getConfig(array('currency_rate'));
                 $properties['currency_rate'] = $config['currency_rate'];
             }
             $rate_ratio = 1;
             if ($properties['currency_default'] != $currency_id) {
                 $rate_default = 1;
                 $rate = 1;
                 //Определяем курс по умолчанию и новый курс
                 foreach ($properties['currency_rate'] as $rt) {
                     if ($rt['id'] == $properties['currency_default']) {
                         $rate_default = Shopkeeper::cleanNumber($rt['value'], 'float');
                     } else {
                         if ($rt['id'] == $currency_id) {
                             $rate = Shopkeeper::cleanNumber($rt['value'], 'float');
                         }
                     }
                 }
                 if (!$inverse) {
                     $rate_ratio = $rate_default / $rate;
                     $_SESSION['shk_curr_rate'] = $rate_ratio;
                 } else {
                     $rate_ratio = $rate / $rate_default;
                 }
             }
         }
     }
     //Считаем цену по курсу
     if ($rate_ratio) {
         $price = $base_price * $rate_ratio;
         $price = round($price, ceil($price) == $price ? 0 : 2);
         return $price;
     } else {
         return $base_price;
     }
 }