예제 #1
0
 protected function prepareDiscountConditions(&$conditions, &$result, &$handlers, $type)
 {
     global $APPLICATION;
     $obCond = null;
     $result = '';
     $handlers = array();
     $type = (int) $type;
     if ($type != self::PREPARE_CONDITIONS && $type != self::PREPARE_ACTIONS || empty($conditions)) {
         return false;
     }
     if (!is_array($conditions)) {
         if (!CheckSerializedData($conditions)) {
             if ($type == self::PREPARE_CONDITIONS) {
                 $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
             } else {
                 $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS_EXT"), "ACTIONS");
             }
             return false;
         }
         $conditions = unserialize($conditions);
         if (!is_array($conditions) || empty($conditions)) {
             if ($type == self::PREPARE_CONDITIONS) {
                 $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
             } else {
                 $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS_EXT"), "ACTIONS");
             }
             return false;
         }
     }
     if ($type == self::PREPARE_CONDITIONS) {
         $obCond = new CSaleCondTree();
         $boolCond = $obCond->Init(BT_COND_MODE_GENERATE, BT_COND_BUILD_SALE, array());
     } else {
         $obCond = new CSaleActionTree();
         $boolCond = $obCond->Init(BT_COND_MODE_GENERATE, BT_COND_BUILD_SALE_ACTIONS, array());
     }
     if (!$boolCond) {
         return false;
     }
     $result = $obCond->Generate($conditions, array('ORDER' => '$arOrder', 'ORDER_FIELDS' => '$arOrder', 'ORDER_PROPS' => '$arOrder[\'PROPS\']', 'ORDER_BASKET' => '$arOrder[\'BASKET_ITEMS\']', 'BASKET' => '$arBasket', 'BASKET_ROW' => '$row'));
     if ($result == '') {
         if ($type == self::PREPARE_CONDITIONS) {
             $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
         } else {
             $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS_EXT"), "ACTIONS");
         }
         return false;
     } else {
         $handlers = $obCond->GetConditionHandlers();
     }
     $conditions = serialize($conditions);
     return true;
 }
예제 #2
0
 protected function prepareDiscountConditions(&$conditions, &$result, &$handlers, $type, $site)
 {
     global $APPLICATION;
     $obCond = null;
     $result = '';
     $handlers = array();
     $type = (int) $type;
     if ($type != self::PREPARE_CONDITIONS && $type != self::PREPARE_ACTIONS || empty($conditions)) {
         return false;
     }
     if (!is_array($conditions)) {
         if (!CheckSerializedData($conditions)) {
             if ($type == self::PREPARE_CONDITIONS) {
                 $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
             } else {
                 $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS_EXT"), "ACTIONS");
             }
             return false;
         }
         $conditions = unserialize($conditions);
         if (!is_array($conditions) || empty($conditions)) {
             if ($type == self::PREPARE_CONDITIONS) {
                 $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
             } else {
                 $APPLICATION->ThrowException(Loc::getMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS_EXT"), "ACTIONS");
             }
             return false;
         }
     }
     if ($type == self::PREPARE_CONDITIONS) {
         $obCond = new CSaleCondTree();
         $boolCond = $obCond->Init(BT_COND_MODE_GENERATE, BT_COND_BUILD_SALE, array('INIT_CONTROLS' => array('SITE_ID' => $site, 'CURRENCY' => CSaleLang::GetLangCurrency($site))));
     } else {
         $obCond = new CSaleActionTree();
         $boolCond = $obCond->Init(BT_COND_MODE_GENERATE, BT_COND_BUILD_SALE_ACTIONS, array());
     }
     if (!$boolCond) {
         return false;
     }
     $result = $obCond->Generate($conditions, array('ORDER' => '$arOrder', 'ORDER_FIELDS' => '$arOrder', 'ORDER_PROPS' => '$arOrder[\'PROPS\']', 'ORDER_BASKET' => '$arOrder[\'BASKET_ITEMS\']', 'BASKET' => '$arBasket', 'BASKET_ROW' => '$row'));
     if ($result == '') {
         if ($type == self::PREPARE_CONDITIONS) {
             $APPLICATION->ThrowException(Loc::getMessage('BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS'), 'CONDITIONS');
         } else {
             $APPLICATION->ThrowException(Loc::getMessage('BT_MOD_SALE_DISC_ERR_BAD_ACTIONS_EXT'), 'ACTIONS');
         }
         return false;
     } else {
         $handlers['HANDLERS'] = $obCond->GetConditionHandlers();
         $handlers['ENTITY'] = $obCond->GetUsedEntityList();
         $handlers['EXECUTE_MODULE'] = $obCond->GetExecuteModule();
     }
     $conditions = serialize($conditions);
     return true;
 }
예제 #3
0
 public function CheckFields($ACTION, &$arFields)
 {
     global $DB;
     global $APPLICATION;
     if ((is_set($arFields, "ACTIVE") || $ACTION == "ADD") && $arFields["ACTIVE"] != "Y") {
         $arFields["ACTIVE"] = "N";
     }
     if ((is_set($arFields, "DISCOUNT_TYPE") || $ACTION == "ADD") && $arFields["DISCOUNT_TYPE"] != "P") {
         $arFields["DISCOUNT_TYPE"] = "V";
     }
     if ((is_set($arFields, "SORT") || $ACTION == "ADD") && IntVal($arFields["SORT"]) <= 0) {
         $arFields["SORT"] = 100;
     }
     if ((is_set($arFields, "LID") || $ACTION == "ADD") && strlen($arFields["LID"]) <= 0) {
         return false;
     }
     if (is_set($arFields, "LID")) {
         $dbSite = CSite::GetByID($arFields["LID"]);
         if (!$dbSite->Fetch()) {
             $APPLICATION->ThrowException(str_replace("#ID#", $arFields["LID"], GetMessage("SKGD_NO_SITE")), "ERROR_NO_SITE");
             return false;
         }
         $arFields['CURRENCY'] = CSaleLang::GetLangCurrency($arFields["LID"]);
     }
     if ((is_set($arFields, "CURRENCY") || $ACTION == "ADD") && strlen($arFields["CURRENCY"]) <= 0) {
         return false;
     }
     if (is_set($arFields, "CURRENCY")) {
         if (!($arCurrency = CCurrency::GetByID($arFields["CURRENCY"]))) {
             $APPLICATION->ThrowException(str_replace("#ID#", $arFields["CURRENCY"], GetMessage("SKGD_NO_CURRENCY")), "ERROR_NO_CURRENCY");
             return false;
         }
     }
     if (is_set($arFields, "DISCOUNT_VALUE") || $ACTION == "ADD") {
         if (!is_set($arFields["DISCOUNT_VALUE"])) {
             $arFields["DISCOUNT_VALUE"] = '';
         }
         $arFields["DISCOUNT_VALUE"] = str_replace(",", ".", $arFields["DISCOUNT_VALUE"]);
         $arFields["DISCOUNT_VALUE"] = doubleval($arFields["DISCOUNT_VALUE"]);
     }
     if (is_set($arFields, "PRICE_FROM")) {
         $arFields["PRICE_FROM"] = str_replace(",", ".", $arFields["PRICE_FROM"]);
         $arFields["PRICE_FROM"] = doubleval($arFields["PRICE_FROM"]);
     }
     if (is_set($arFields, "PRICE_TO")) {
         $arFields["PRICE_TO"] = str_replace(",", ".", $arFields["PRICE_TO"]);
         $arFields["PRICE_TO"] = doubleval($arFields["PRICE_TO"]);
     }
     if ((is_set($arFields, "ACTIVE_FROM") || $ACTION == "ADD") && !$DB->IsDate($arFields["ACTIVE_FROM"], false, LANGUAGE_ID, "FULL")) {
         $arFields["ACTIVE_FROM"] = false;
     }
     if ((is_set($arFields, "ACTIVE_TO") || $ACTION == "ADD") && !$DB->IsDate($arFields["ACTIVE_TO"], false, LANGUAGE_ID, "FULL")) {
         $arFields["ACTIVE_TO"] = false;
     }
     if ((is_set($arFields, 'PRIORITY') || $ACTION == 'ADD') && intval($arFields['PRIORITY']) <= 0) {
         $arFields['PRIORITY'] = 1;
     }
     if ((is_set($arFields, 'LAST_DISCOUNT') || $ACTION == 'ADD') && $arFields["LAST_DISCOUNT"] != "N") {
         $arFields["LAST_DISCOUNT"] = 'Y';
     }
     $arFields['VERSION'] = self::VERSION_NEW;
     if (is_set($arFields, 'UNPACK')) {
         unset($arFields['UNPACK']);
     }
     if (is_set($arFields, 'APPLICATION')) {
         unset($arFields['APPLICATION']);
     }
     if (is_set($arFields, 'CONDITIONS') || $ACTION == 'ADD') {
         if (empty($arFields['CONDITIONS'])) {
             $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_EMPTY_CONDITIONS"), "CONDITIONS");
             return false;
         } else {
             if (!is_array($arFields['CONDITIONS'])) {
                 if (!CheckSerializedData($arFields['CONDITIONS'])) {
                     $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
                     return false;
                 }
                 $arFields['CONDITIONS'] = unserialize($arFields['CONDITIONS']);
                 if (!is_array($arFields['CONDITIONS']) || empty($arFields['CONDITIONS'])) {
                     $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
                     return false;
                 }
             }
             $obCond = new CSaleCondTree();
             $boolCond = $obCond->Init(BT_COND_MODE_GENERATE, BT_COND_BUILD_SALE, array());
             if (!$boolCond) {
                 return false;
             }
             $strEval = $obCond->Generate($arFields['CONDITIONS'], array('ORDER' => '$arOrder', 'ORDER_FIELDS' => '$arOrder', 'ORDER_PROPS' => '$arOrder[\'PROPS\']', 'ORDER_BASKET' => '$arOrder[\'BASKET_ITEMS\']', 'BASKET' => '$arBasket', 'BASKET_ROW' => '$row', 'IBLOCK' => '$row[\'IBLOCK\']'));
             if ('' == $strEval) {
                 $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_CONDITIONS"), "CONDITIONS");
                 return false;
             }
             $arFields['UNPACK'] = $strEval;
             $arFields['CONDITIONS'] = serialize($arFields['CONDITIONS']);
         }
     }
     if (is_set($arFields, 'ACTIONS') || $ACTION == 'ADD') {
         if (empty($arFields['ACTIONS'])) {
             $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_EMPTY_ACTIONS"), "ACTIONS");
             return false;
         } else {
             if (!is_array($arFields['ACTIONS'])) {
                 if (!CheckSerializedData($arFields['ACTIONS'])) {
                     $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS"), "ACTIONS");
                     return false;
                 }
                 $arFields['ACTIONS'] = unserialize($arFields['ACTIONS']);
                 if (!is_array($arFields['ACTIONS']) || empty($arFields['ACTIONS'])) {
                     $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS"), "ACTIONS");
                     return false;
                 }
             }
             $obAct = new CSaleActionTree();
             $boolAct = $obAct->Init(BT_COND_MODE_GENERATE, BT_COND_BUILD_SALE_ACTIONS, array());
             if (!$boolAct) {
                 return false;
             }
             $strEval = $obAct->Generate($arFields['ACTIONS'], array('ORDER' => '$arOrder', 'ORDER_FIELDS' => '$arOrder', 'ORDER_BASKET' => '$arOrder[\'BASKET_ITEMS\']', 'BASKET' => '$arBasket', 'BASKET_ROW' => '$row', 'IBLOCK' => '$row[\'IBLOCK\']'));
             if ('' == $strEval) {
                 $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_BAD_ACTIONS"), "ACTIONS");
                 return false;
             }
             $arFields['APPLICATION'] = $strEval;
             $arFields['ACTIONS'] = serialize($arFields['ACTIONS']);
         }
     }
     if ((is_set($arFields, 'USE_COUPONS') || $ACTION == 'ADD') && 'Y' != $arFields['USE_COUPONS']) {
         $arFields['USE_COUPONS'] = 'N';
     }
     if ((is_set($arFields, 'USER_GROUPS') || $ACTION == "ADD") && (!is_array($arFields['USER_GROUPS']) || empty($arFields['USER_GROUPS']))) {
         $APPLICATION->ThrowException(GetMessage("BT_MOD_SALE_DISC_ERR_USER_GROUPS_ABSENT_SHORT"), "USER_GROUPS");
         return false;
     }
     return true;
 }