Ejemplo n.º 1
0
 public function Add($arFields, $boolCalc = false)
 {
     global $DB;
     if (!CCatalogDiscountSave::CheckFields("ADD", $arFields)) {
         return false;
     }
     $arInsert = $DB->PrepareInsert("b_catalog_discount", $arFields);
     $strSql = "INSERT INTO b_catalog_discount(" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")";
     $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $ID = intval($DB->LastID());
     if ($ID > 0) {
         foreach ($arFields['RANGES'] as &$arRange) {
             $arRange['DISCOUNT_ID'] = $ID;
             $arInsert = $DB->PrepareInsert("b_catalog_disc_save_range", $arRange);
             $strSql = "INSERT INTO b_catalog_disc_save_range(" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         foreach ($arFields['GROUP_IDS'] as &$intGroupID) {
             $strSql = "INSERT INTO b_catalog_disc_save_group(DISCOUNT_ID,GROUP_ID) VALUES(" . $ID . "," . $intGroupID . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         $boolCalc = $boolCalc === true ? true : false;
         if ($boolCalc) {
             CCatalogDiscountSave::UserDiscountCalc($ID, $arFields, false);
         }
     }
     return $ID;
 }
Ejemplo n.º 2
0
 public function Add($arFields, $boolCalc = false)
 {
     global $DB;
     global $stackCacheManager;
     global $USER;
     $arFields1 = array();
     if (!(!isset($USER) || !($USER instanceof CUser && 'CUser' == get_class($USER)))) {
         if (!isset($arFields["CREATED_BY"]) || intval($arFields["CREATED_BY"]) <= 0) {
             $arFields["CREATED_BY"] = intval(@$USER->GetID());
         }
         if (!isset($arFields["MODIFIED_BY"]) || intval($arFields["MODIFIED_BY"]) <= 0) {
             $arFields["MODIFIED_BY"] = intval(@$USER->GetID());
         }
     }
     if (array_key_exists('TIMESTAMP_X', $arFields)) {
         unset($arFields['TIMESTAMP_X']);
     }
     if (array_key_exists('DATE_CREATE', $arFields)) {
         unset($arFields['DATE_CREATE']);
     }
     $arFields1['TIMESTAMP_X'] = $DB->GetNowFunction();
     $arFields1['DATE_CREATE'] = $DB->GetNowFunction();
     if (!CCatalogDiscountSave::CheckFields("ADD", $arFields)) {
         return false;
     }
     //$stackCacheManager->Clear("catalog_discount_save");
     $arInsert = $DB->PrepareInsert("b_catalog_discount", $arFields);
     foreach ($arFields1 as $key => $value) {
         if (strlen($arInsert[0]) > 0) {
             $arInsert[0] .= ", ";
             $arInsert[1] .= ", ";
         }
         $arInsert[0] .= $key;
         $arInsert[1] .= $value;
     }
     $strSql = "INSERT INTO b_catalog_discount(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
     $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $ID = intval($DB->LastID());
     if ($ID > 0) {
         foreach ($arFields['RANGES'] as &$arRange) {
             $arRange['DISCOUNT_ID'] = $ID;
             $arInsert = $DB->PrepareInsert("b_catalog_disc_save_range", $arRange);
             $strSql = "INSERT INTO b_catalog_disc_save_range(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         foreach ($arFields['GROUP_IDS'] as &$intGroupID) {
             $strSql = "INSERT INTO b_catalog_disc_save_group(DISCOUNT_ID,GROUP_ID) VALUES(" . $ID . "," . $intGroupID . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         //CCatalogDiscountSave::__AddGroupsCache($ID,$arFields['GROUP_IDS']);
         $boolCalc = $boolCalc === true ? true : false;
         if ($boolCalc) {
             CCatalogDiscountSave::UserDiscountCalc($ID, $arFields, false);
         }
     }
     return $ID;
 }
Ejemplo n.º 3
0
 public function Update($intID, $arFields, $boolCalc = false)
 {
     global $DB;
     $intID = (int) $intID;
     if ($intID <= 0) {
         return false;
     }
     if (!CCatalogDiscountSave::CheckFields('UPDATE', $arFields, $intID)) {
         return false;
     }
     $strUpdate = $DB->PrepareUpdate("b_catalog_discount", $arFields);
     if (!empty($strUpdate)) {
         $strSql = "update b_catalog_discount SET " . $strUpdate . " where ID = " . $intID . " and TYPE = " . self::ENTITY_ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     if (!empty($arFields['RANGES'])) {
         $DB->Query("delete from b_catalog_disc_save_range where DISCOUNT_ID = " . $intID, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         foreach ($arFields['RANGES'] as &$arRange) {
             $arRange['DISCOUNT_ID'] = $intID;
             $arInsert = $DB->PrepareInsert("b_catalog_disc_save_range", $arRange);
             $strSql = "insert into b_catalog_disc_save_range(" . $arInsert[0] . ") values(" . $arInsert[1] . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         unset($arRange);
     }
     if (!empty($arFields['GROUP_IDS'])) {
         $DB->Query("delete from b_catalog_disc_save_group where DISCOUNT_ID = " . $intID, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         foreach ($arFields['GROUP_IDS'] as &$intGroupID) {
             $strSql = "insert into b_catalog_disc_save_group(DISCOUNT_ID,GROUP_ID) values(" . $intID . "," . $intGroupID . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         unset($intGroupID);
     }
     $boolCalc = $boolCalc === true;
     if ($boolCalc) {
         CCatalogDiscountSave::UserDiscountCalc($intID, $arFields, false);
     }
     return $intID;
 }
Ejemplo n.º 4
0
 public function Update($intID, $arFields, $boolCalc = false)
 {
     global $DB;
     global $stackCacheManager;
     global $USER;
     $intID = intval($intID);
     if ($intID <= 0) {
         return false;
     }
     $arFields1 = array();
     if (array_key_exists('CREATED_BY', $arFields)) {
         unset($arFields['CREATED_BY']);
     }
     if (array_key_exists('DATE_CREATE', $arFields)) {
         unset($arFields['DATE_CREATE']);
     }
     if (array_key_exists('TIMESTAMP_X', $arFields)) {
         unset($arFields['TIMESTAMP_X']);
     }
     if (isset($USER) && $USER instanceof CUser && 'CUser' == get_class($USER)) {
         if (!array_key_exists('MODIFIED_BY', $arFields) || intval($arFields["MODIFIED_BY"]) <= 0) {
             $arFields["MODIFIED_BY"] = intval($USER->GetID());
         }
     }
     $arFields1['TIMESTAMP_X'] = $DB->GetNowFunction();
     if (!CCatalogDiscountSave::CheckFields('UPDATE', $arFields, $intID)) {
         return false;
     }
     $strUpdate = $DB->PrepareUpdate("b_catalog_discount", $arFields);
     if (!empty($strUpdate)) {
         foreach ($arFields1 as $key => $value) {
             if (strlen($strUpdate) > 0) {
                 $strUpdate .= ", ";
             }
             $strUpdate .= $key . "=" . $value . " ";
         }
         $strSql = "UPDATE b_catalog_discount SET " . $strUpdate . " WHERE ID = " . $intID . " AND TYPE = " . DISCOUNT_TYPE_SAVE;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     if (!empty($arFields['RANGES'])) {
         $DB->Query("delete from b_catalog_disc_save_range where DISCOUNT_ID = " . $intID, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         foreach ($arFields['RANGES'] as &$arRange) {
             $arRange['DISCOUNT_ID'] = $intID;
             $arInsert = $DB->PrepareInsert("b_catalog_disc_save_range", $arRange);
             $strSql = "INSERT INTO b_catalog_disc_save_range(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         if (isset($arRange)) {
             unset($arRange);
         }
     }
     if (!empty($arFields['GROUP_IDS'])) {
         $DB->Query("delete from b_catalog_disc_save_group where DISCOUNT_ID = " . $intID, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         foreach ($arFields['GROUP_IDS'] as &$intGroupID) {
             $strSql = "INSERT INTO b_catalog_disc_save_group(DISCOUNT_ID,GROUP_ID) VALUES(" . $intID . "," . $intGroupID . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         if (isset($intGroupID)) {
             unset($intGroupID);
         }
     }
     $boolCalc = $boolCalc === true ? true : false;
     if ($boolCalc) {
         CCatalogDiscountSave::UserDiscountCalc($ID, $arFields, false);
     }
     return $intID;
 }