Ejemplo n.º 1
0
 public function Add($arFields)
 {
     global $DB;
     $mxRows = self::__ParseArrays($arFields);
     if (!is_array($mxRows) || empty($mxRows)) {
         return false;
     }
     $boolNewVersion = true;
     if (!is_set($arFields, 'CONDITIONS')) {
         self::__ConvertOldConditions('ADD', $arFields);
         $boolNewVersion = false;
     }
     $ID = CCatalogDiscount::_Add($arFields);
     $ID = intval($ID);
     if ($ID <= 0) {
         return false;
     }
     if ($boolNewVersion) {
         $arValuesList = self::__GetConditionValues($arFields);
         if (is_array($arValuesList) && !empty($arValuesList)) {
             self::__GetOldOneEntity($arFields, $arValuesList, 'IBLOCK_IDS', 'CondIBIBlock');
             self::__GetOldOneEntity($arFields, $arValuesList, 'SECTION_IDS', 'CondIBSection');
             self::__GetOldOneEntity($arFields, $arValuesList, 'PRODUCT_IDS', 'CondIBElement');
         }
     }
     if (!CCatalogDiscount::__UpdateSubdiscount($ID, $mxRows)) {
         return false;
     }
     CCatalogDiscount::__UpdateOldEntities($ID, $arFields, false);
     if (is_set($arFields, "CATALOG_COUPONS")) {
         if (!is_array($arFields["CATALOG_COUPONS"])) {
             $arFields["CATALOG_COUPONS"] = array("DISCOUNT_ID" => $ID, "ACTIVE" => "Y", "ONE_TIME" => "Y", "COUPON" => $arFields["CATALOG_COUPONS"], "DATE_APPLY" => false);
         }
         $arKeys = array_keys($arFields["CATALOG_COUPONS"]);
         if (!is_array($arFields["CATALOG_COUPONS"][$arKeys[0]])) {
             $arFields["CATALOG_COUPONS"] = array($arFields["CATALOG_COUPONS"]);
         }
         foreach ($arFields["CATALOG_COUPONS"] as &$arOneCoupon) {
             if (!empty($arOneCoupon['COUPON'])) {
                 $arOneCoupon['DISCOUNT_ID'] = $ID;
                 CCatalogDiscountCoupon::Add($arOneCoupon, false);
             }
             if (isset($arOneCoupon)) {
                 unset($arOneCoupon);
             }
         }
     }
     CCatalogDiscount::SaveFilterOptions();
     foreach (GetModuleEvents("catalog", "OnDiscountAdd", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $arFields));
     }
     return $ID;
 }