Esempio n. 1
0
 function Calculate($STEP, $SID, $profile, $arOrder, $currency, $TMP = false, $SITE_ID = false)
 {
     global $APPLICATION;
     if (!defined('SALE_DH_INITIALIZED')) {
         CSaleDeliveryHandler::Initialize();
     }
     if (!$SITE_ID) {
         $SITE_ID = SITE_ID;
     }
     $rsDeliveryHandler = CSaleDeliveryHandler::GetBySID($SID, $SITE_ID);
     if (!($arHandler = $rsDeliveryHandler->Fetch())) {
         return array("RESULT" => "ERROR", "TEXT" => GetMessage("SALE_DH_ERROR_HANDLER_NOT_INSTALLED"));
     }
     if (is_callable($arHandler["CALCULATOR"])) {
         $arConfig = $arHandler["CONFIG"]["CONFIG"];
         $arOrder["PRICE"] = CCurrencyRates::ConvertCurrency($arOrder["PRICE"], $currency, $arHandler["BASE_CURRENCY"]);
         if ($res = call_user_func($arHandler["CALCULATOR"], $profile, $arConfig, $arOrder, $STEP, $TMP)) {
             if (is_array($res)) {
                 $arReturn = $res;
             } elseif (is_numeric($res)) {
                 $arReturn = array("RESULT" => "OK", "VALUE" => doubleval($res));
             }
         } else {
             if ($ex = $APPLICATION->GetException()) {
                 return array("RESULT" => "ERROR", "TEXT" => $ex->GetString());
             } else {
                 return array("RESULT" => "OK", "VALUE" => 0);
             }
         }
         if (is_array($arReturn) && $arReturn["RESULT"] == "OK" && $currency != $arHandler["BASE_CURRENCY"] && CModule::IncludeModule('currency')) {
             $arReturn["VALUE"] = CCurrencyRates::ConvertCurrency($arReturn["VALUE"], $arHandler["BASE_CURRENCY"], $currency);
         }
         $arReturn["VALUE"] *= 1 + $arHandler["TAX_RATE"] / 100;
         $arReturn = CSaleDeliveryHandler::__executeCalculateEvents($SID, $profile, $arOrder, $arReturn);
         return $arReturn;
     } else {
         return array("RESULT" => "ERROR", "TEXT" => GetMessage("SALE_DH_ERROR_WRONG_HANDLER_FILE"));
     }
 }