コード例 #1
0
ファイル: discount.php プロジェクト: DarneoStudio/bitrix
 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;
 }