예제 #1
0
     if (!empty($_POST[$prefix . 'ACTIVE_TO'])) {
         $fields['COUPON']['ACTIVE_TO'] = new Main\Type\DateTime($_POST[$prefix . 'ACTIVE_TO']);
     }
     if (isset($_POST[$prefix . 'TYPE'])) {
         $fields['COUPON']['TYPE'] = $_POST[$prefix . 'TYPE'];
     }
     if (isset($_POST[$prefix . 'MAX_USE'])) {
         $fields['COUPON']['MAX_USE'] = $_POST[$prefix . 'MAX_USE'];
     }
     if (isset($_POST[$prefix . 'COUNT'])) {
         $fields['COUNT'] = (int) $_POST[$prefix . 'COUNT'];
     }
     if ($fields['COUNT'] <= 0) {
         $errors[] = Loc::getMessage('BX_SALE_DISCOUNT_COUPON_ERR_COUPON_COUNT');
     }
     $checkResult = Internals\DiscountCouponTable::checkPacket($fields['COUPON'], false);
     if (!$checkResult->isSuccess(true)) {
         $errors = $checkResult->getErrorMessages();
     } else {
         $couponsResult = Internals\DiscountCouponTable::addPacket($fields['COUPON'], $fields['COUNT']);
         if (!$couponsResult->isSuccess()) {
             $errors = $couponsResult->getErrorMessages();
         }
     }
     unset($checkResult);
 } else {
     if ($subWindow) {
         $fields['DISCOUNT_ID'] = $discountID;
     } elseif (!empty($_POST['DISCOUNT_ID'])) {
         $fields['DISCOUNT_ID'] = $_POST['DISCOUNT_ID'];
     }
예제 #2
0
 }
 $arFields = array("LID" => array_key_exists('LID', $_POST) ? $_POST['LID'] : '', "NAME" => array_key_exists('NAME', $_POST) ? $_POST['NAME'] : '', "ACTIVE_FROM" => array_key_exists('ACTIVE_FROM', $_POST) ? $_POST['ACTIVE_FROM'] : '', "ACTIVE_TO" => array_key_exists('ACTIVE_TO', $_POST) ? $_POST['ACTIVE_TO'] : '', "ACTIVE" => array_key_exists('ACTIVE', $_POST) && 'Y' == $_POST['ACTIVE'] ? 'Y' : 'N', "SORT" => array_key_exists('SORT', $_POST) ? $_POST['SORT'] : 500, "PRIORITY" => array_key_exists('PRIORITY', $_POST) ? $_POST['PRIORITY'] : '', "LAST_DISCOUNT" => array_key_exists('LAST_DISCOUNT', $_POST) && 'N' == $_POST['LAST_DISCOUNT'] ? 'N' : 'Y', "XML_ID" => array_key_exists('XML_ID', $_POST) ? $_POST['XML_ID'] : '', 'CONDITIONS' => $CONDITIONS, 'ACTIONS' => $ACTIONS, 'USER_GROUPS' => $arGroupID);
 if ($discountID == 0 || $copy) {
     $additionalFields = array('COUPON_ADD' => isset($_POST['COUPON_ADD']) && $_POST['COUPON_ADD'] == 'Y' ? 'Y' : 'N', 'COUPON_COUNT' => isset($_POST['COUPON_COUNT']) ? (int) $_POST['COUPON_COUNT'] : 0);
     if ($additionalFields['COUPON_ADD'] == 'Y') {
         if ($additionalFields['COUPON_COUNT'] <= 0) {
             $errors[] = GetMessage('BX_SALE_DISCOUNT_EDIT_ERR_COUPONS_COUNT');
         }
         $couponsFields = array('DISCOUNT_ID' => $discountID, 'ACTIVE' => 'Y');
         if (isset($_POST['COUPON'])) {
             $couponsFields['TYPE'] = isset($_POST['COUPON']['TYPE']) ? (int) $_POST['COUPON']['TYPE'] : 0;
             $couponsFields['ACTIVE_FROM'] = !empty($_POST['COUPON']['ACTIVE_FROM']) ? new Main\Type\DateTime($_POST['COUPON']['ACTIVE_FROM']) : null;
             $couponsFields['ACTIVE_TO'] = !empty($_POST['COUPON']['ACTIVE_TO']) ? new Main\Type\DateTime($_POST['COUPON']['ACTIVE_TO']) : null;
             $couponsFields['MAX_USE'] = isset($_POST['COUPON']['MAX_USE']) ? (int) $_POST['COUPON']['MAX_USE'] : 0;
         }
         $couponsResult = Internals\DiscountCouponTable::checkPacket($couponsFields, $discountID <= 0);
         if (!$couponsResult->isSuccess(true)) {
             $errors = empty($errors) ? $couponsResult->getErrorMessages() : array_merge($errors, $couponsResult->getErrorMessages());
         }
         unset($couponsResult);
         $additionalFields['COUPON'] = $couponsFields;
         $couponsAdd = true;
     }
 }
 if (empty($errors)) {
     if ($discountID > 0 && !$copy) {
         if (!CSaleDiscount::Update($discountID, $arFields)) {
             if ($ex = $APPLICATION->GetException()) {
                 $errors[] = $ex->GetString();
             } else {
                 $errors[] = str_replace('#ID#', $discountID, GetMessage('BT_SALE_DISCOUNT_EDIT_ERR_UPDATE'));