Ejemplo n.º 1
0
 public function Delete($ID)
 {
     $ID = (int) $ID;
     if ($ID <= 0) {
         return false;
     }
     $result = Internals\DiscountTable::delete($ID);
     return $result->isSuccess();
 }
Ejemplo n.º 2
0
<?php 
} else {
    if ($couponID > 0 && !$copy) {
        $control->AddViewField($prefix . 'ID', Loc::getMessage('BX_SALE_DISCOUNT_COUPON_FIELD_ID'), $couponID, false);
    }
    $control->AddCheckBoxField($prefix . 'ACTIVE', Loc::getMessage('BX_SALE_DISCOUNT_COUPON_FIELD_ACTIVE'), true, array('Y', 'N'), $coupon['ACTIVE'] == 'Y');
    if ($couponID > 0) {
        $discountName = '<a href="sale_discount_edit.php?lang=' . LANGUAGE_ID . '&ID=' . $coupon['DISCOUNT_ID'] . '">[' . $coupon['DISCOUNT_ID'] . ']</a>';
        if ($coupon['DISCOUNT_NAME'] !== '') {
            $discountName .= ' ' . $coupon['DISCOUNT_NAME'];
        }
        $discountName .= '<input type="hidden" name="DISCOUNT_ID" value="' . $coupon['DISCOUNT_ID'] . '">';
        $control->AddViewField('DISCOUNT_ID', Loc::getMessage('BX_SALE_DISCOUNT_COUPON_FIELD_DISCOUNT'), $discountName, true);
    } elseif (!$subWindow) {
        $discountList = array();
        $discountIterator = Internals\DiscountTable::getList(array('select' => array('ID', 'NAME'), 'filter' => array('=ACTIVE' => 'Y'), 'order' => array('SORT' => 'ASC', 'NAME' => 'ASC')));
        while ($discount = $discountIterator->fetch()) {
            $discount['ID'] = (int) $discount['ID'];
            $discount['NAME'] = (string) $discount['NAME'];
            $discountList[$discount['ID']] = '[' . $discount['ID'] . ']' . ($discount['NAME'] !== '' ? ' ' . $discount['NAME'] : '');
        }
        unset($discount, $discountIterator);
        if (!empty($discountList)) {
            $control->AddDropDownField('DISCOUNT_ID', Loc::getMessage('BX_SALE_DISCOUNT_COUPON_FIELD_DISCOUNT'), true, $discountList, $coupon['DISCOUNT_ID']);
        } else {
            $control->BeginCustomField('DISCOUNT_ID', Loc::getMessage('BX_SALE_DISCOUNT_COUPON_FIELD_DISCOUNT'), true);
            $dicountEditPath = 'sale_discount_edit.php?lang=' . LANGUAGE_ID . '&return_url=' . urlencode($APPLICATION->GetCurPageParam());
            ?>
<tr id="tr_DISCOUNT_ID">
			<td width="40%"><?php 
            echo $control->GetCustomLabelHTML();
Ejemplo n.º 3
0
 /**
  * Create one and more coupons for discount.
  *
  * @param array $data				Coupon data.
  * @param int $count				Coupos count.
  * @param int $limit				Maximum number of attempts.
  * @return Main\Entity\Result
  */
 public static function addPacket(array $data, $count, $limit = 0)
 {
     $result = new Main\Entity\Result();
     $result->setData(array('result' => 0, 'count' => $count, 'limit' => $limit, 'all' => 0));
     $count = (int) $count;
     if ($count <= 0) {
         $result->addError(new Main\Entity\EntityError(Loc::getMessage('DISCOUNT_COUPON_PACKET_COUNT_ERR'), 'COUPON_PACKET'));
     }
     foreach (static::getEntity()->getFields() as $field) {
         if ($field instanceof Main\Entity\ScalarField && !array_key_exists($field->getName(), $data)) {
             $defaultValue = $field->getDefaultValue();
             if ($defaultValue !== null) {
                 $data[$field->getName()] = $field->getDefaultValue();
             }
         }
     }
     $checkResult = static::checkPacket($data, false);
     if (!$checkResult->isSuccess()) {
         foreach ($checkResult->getErrors() as $checkError) {
             $result->addError($checkError);
         }
         unset($checkError);
     }
     unset($checkResult);
     $useCoupons = false;
     $discountIterator = DiscountTable::getList(array('select' => array('ID', 'USE_COUPONS'), 'filter' => array('=ID' => $data['DISCOUNT_ID'])));
     if ($discount = $discountIterator->fetch()) {
         $useCoupons = $discount['USE_COUPONS'] == 'Y';
     } else {
         $result->addError(new Main\Entity\EntityError(Loc::getMessage('DISCOUNT_COUPON_PACKET_DISCOUNT_ERR'), 'COUPON_PACKET'));
     }
     if (!$result->isSuccess(true)) {
         return $result;
     }
     self::setDiscountCheckList($data['DISCOUNT_ID']);
     self::disableCheckCouponsUse();
     $limit = (int) $limit;
     if ($limit < $count) {
         $limit = $count * 2;
     }
     $resultCount = 0;
     $all = 0;
     do {
         $data['COUPON'] = self::generateCoupon(true);
         $couponResult = self::add($data);
         if ($couponResult->isSuccess()) {
             $resultCount++;
         }
         $all++;
     } while ($resultCount < $count && $all < $limit);
     $result->setData(array('result' => $resultCount, 'count' => $count, 'limit' => $limit, 'all' => $all));
     if ($resultCount == 0) {
         $result->addError(new Main\Entity\EntityError($useCoupons ? Loc::getMessage('DISCOUNT_COUPON_PACKET_GENERATE_COUPON_ZERO_ERR') : Loc::getMessage('DISCOUNT_COUPON_PACKET_NEW_GENERATE_COUPON_ZERO_ERR'), 'COUPON_PACKET'));
         self::clearDiscountCheckList();
     } elseif ($resultCount < $count) {
         $result->addError(new Main\Entity\EntityError(Loc::getMessage('DISCOUNT_COUPON_PACKET_GENERATE_COUPON_COUNT_ERR', array('#RESULT#' => $resultCount, '#COUNT#' => $count, '#ALL#' => $all)), 'COUPON_PACKET'));
     }
     self::enableCheckCouponsUse();
     self::updateUseCoupons();
     return $result;
 }
Ejemplo n.º 4
0
    $navyParams = CDBResult::GetNavParams(CAdminResult::GetNavSize($adminListTableID));
    if ($navyParams['SHOW_ALL']) {
        $usePageNavigation = false;
    } else {
        $navyParams['PAGEN'] = (int) $navyParams['PAGEN'];
        $navyParams['SIZEN'] = (int) $navyParams['SIZEN'];
    }
}
$getListParams = array('select' => array_keys($selectFields), 'filter' => $filter, 'order' => array($by => $order));
if ($usePageNavigation) {
    $getListParams['limit'] = $navyParams['SIZEN'];
    $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1);
}
$discountIterator = new CAdminResult(Internals\DiscountTable::getList($getListParams), $adminListTableID);
if ($usePageNavigation) {
    $countQuery = new Main\Entity\Query(Internals\DiscountTable::getEntity());
    $countQuery->addSelect(new Main\Entity\ExpressionField('CNT', 'COUNT(1)'));
    $countQuery->setFilter($getListParams['filter']);
    $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch();
    $totalCount = (int) $totalCount['CNT'];
    $totalPages = ceil($totalCount / $getListParams['limit']);
    unset($countQuery);
    $discountIterator->NavStart($getListParams['limit'], $navyParams['SHOW_ALL'], $navyParams['PAGEN']);
    $discountIterator->NavRecordCount = $totalCount;
    $discountIterator->NavPageCount = $totalPages;
    $discountIterator->NavPageNomer = $navyParams['PAGEN'];
} else {
    $discountIterator->NavStart();
}
$adminList->NavText($discountIterator->GetNavPrint(Loc::getMessage("BT_SALE_DISCOUNT_LIST_MESS_NAV")));
$userList = array();
Ejemplo n.º 5
0
 public static function getAllCounter()
 {
     $countQuery = new Main\Entity\Query(Sale\Internals\DiscountTable::getEntity());
     $countQuery->addSelect(new Main\Entity\ExpressionField('CNT', 'COUNT(1)'));
     $countQuery->setFilter(array('=VERSION' => Sale\Internals\DiscountTable::VERSION_NEW));
     $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch();
     return (int) $totalCount['CNT'];
 }
Ejemplo n.º 6
0
            <div class="grayDownLine"></div>

            <p class="finalCost"><span id="allSum_FORMATED"><?php 
    echo str_replace(" ", "&nbsp;", $arResult["allSum_FORMATED"]);
    ?>
</span></p>
            <p class="finalQuant">Кол-во: <span id="totalQuantity"><?php 
    echo $totalQuantity;
    ?>
</span></p>
            <p class="finalText">Итого</p>
            <?php 
    //TODO сделать автоматический расчет суммы, оставшейся до скидки, основываясь на правилах работы с корзиной
    //получаем правила работы с корзиной
    $filterCoup = array();
    $discountIteratorCoup = Internals\DiscountTable::getList(array('filter' => $filterCoup));
    $arDiscount = $discountIteratorCoup->fetch();
    // arshow($arDiscount);
    ?>
            <?php 
    /*
    <p class="finalDiscount">Вам не хватает 770 руб. до получения скидки в 10%</p>
    */
    ?>

            <p class="promoWrap"><span class="promocode" onclick="$('#coupon').toggle()">Есть промокод?<span></p>

            <div class="bx_ordercart_order_pay_left" id="coupons_block">
                <div class="bx_ordercart_coupon">
                    <input type="text" id="coupon" name="COUPON" value="" onchange="enterCoupon();">
                </div><?php 
Ejemplo n.º 7
0
 /**
  * Load sale discount from database
  *
  * @return void
  * @throws Main\ArgumentException
  */
 protected function loadDiscountList()
 {
     if (empty($this->discountIds)) {
         $this->discountIds = null;
         return;
     }
     $this->getDiscountModules();
     $couponList = DiscountCouponsManager::getForApply(array('MODULE' => 'sale', 'DISCOUNT_ID' => $this->discountIds), array(), true);
     $this->saleDiscountCacheKey = md5('D' . implode('_', $this->discountIds));
     if (!empty($couponList)) {
         $this->saleDiscountCacheKey .= '-C' . implode('_', array_keys($couponList));
     }
     if (!isset($this->saleDiscountCache[$this->saleDiscountCacheKey])) {
         $currentList = array();
         $discountApply = array();
         $currentDatetime = new Main\Type\DateTime();
         $discountSelect = array('ID', 'PRIORITY', 'SORT', 'LAST_DISCOUNT', 'UNPACK', 'APPLICATION', 'USE_COUPONS', 'EXECUTE_MODULE', 'NAME', 'CONDITIONS_LIST', 'ACTIONS_LIST');
         $discountFilter = array('@ID' => $this->discountIds, '=LID' => $this->orderData['SITE_ID'], '@EXECUTE_MODULE' => array('sale', 'all'), array('LOGIC' => 'OR', 'ACTIVE_FROM' => '', '<=ACTIVE_FROM' => $currentDatetime), array('LOGIC' => 'OR', 'ACTIVE_TO' => '', '>=ACTIVE_TO' => $currentDatetime));
         unset($currentDatetime);
         if (empty($couponList)) {
             $discountFilter['=USE_COUPONS'] = 'N';
         } else {
             $discountFilter[] = array('LOGIC' => 'OR', '=USE_COUPONS' => 'N', array('=USE_COUPONS' => 'Y', '@COUPON.COUPON' => array_keys($couponList)));
             $discountSelect['DISCOUNT_COUPON'] = 'COUPON.COUPON';
         }
         $discountIterator = Internals\DiscountTable::getList(array('select' => $discountSelect, 'filter' => $discountFilter, 'order' => array('PRIORITY' => 'DESC', 'SORT' => 'ASC', 'ID' => 'ASC')));
         unset($discountSelect, $discountFilter);
         while ($discount = $discountIterator->fetch()) {
             $discount['ID'] = (int) $discount['ID'];
             if (isset($discountApply[$discount['ID']])) {
                 continue;
             }
             $discountApply[$discount['ID']] = true;
             if (!$this->loadDiscountModules('sale' . $discount['ID'])) {
                 continue;
             }
             if ($discount['USE_COUPONS'] == 'Y') {
                 $discount['COUPON'] = $couponList[$discount['DISCOUNT_COUPON']];
             }
             $discount['CONDITIONS'] = $discount['CONDITIONS_LIST'];
             $discount['ACTIONS'] = $discount['ACTIONS_LIST'];
             $discount['MODULE_ID'] = 'sale';
             if (isset($this->cacheDiscountModules['sale' . $discount['ID']])) {
                 $discount['MODULES'] = $this->cacheDiscountModules['sale' . $discount['ID']];
             }
             unset($discount['ACTIONS_LIST'], $discount['CONDITIONS_LIST']);
             $currentList[$discount['ID']] = $discount;
         }
         unset($discount, $discountIterator, $discountApply);
         $this->saleDiscountCache[$this->saleDiscountCacheKey] = $currentList;
         unset($currentList);
     }
     unset($couponList);
 }
Ejemplo n.º 8
0
 /**
  * Calculate discount by new order.
  *
  * @return Result
  */
 protected function calculateFull()
 {
     $result = new Result();
     $this->discountIds = array();
     if (!$this->isMixedBasket()) {
         $this->fillEmptyDiscountResult();
     } else {
         $this->discountResult['ORDER'] = array();
     }
     $order = $this->getOrder();
     $basket = $order->getBasket();
     /** @var BasketItem $basketItem */
     foreach ($basket as $basketItem) {
         $code = $basketItem->getBasketCode();
         if ($this->isCustomPriceByCode($code)) {
             if (array_key_exists($code, $this->basketDiscountList)) {
                 unset($this->basketDiscountList[$code]);
             }
         } else {
             if (!isset($this->basketDiscountList[$code])) {
                 $this->basketDiscountList[$code] = $basketItem->getField('DISCOUNT_LIST');
                 if ($this->basketDiscountList[$code] === null) {
                     unset($this->basketDiscountList[$code]);
                 }
             }
         }
     }
     unset($code, $basketItem, $basket);
     $this->resetBasketPrices();
     if ($this->isMixedBasket()) {
         DiscountCouponsManager::clearApply(false);
         $basketDiscountResult = $this->calculateMixedBasketDiscount();
     } else {
         DiscountCouponsManager::clearApply();
         $basketDiscountResult = $this->calculateFullBasketDiscount();
     }
     if (!$basketDiscountResult->isSuccess()) {
         $result->addErrors($basketDiscountResult->getErrors());
         unset($basketDiscountResult);
         return $result;
     }
     unset($basketDiscountResult);
     $this->roundBasketPrices();
     $codeList = array_keys($this->orderData['BASKET_ITEMS']);
     switch (self::getApplyMode()) {
         case self::APPLY_MODE_DISABLE:
             foreach ($codeList as &$code) {
                 if (isset($this->basketDiscountList[$code]) && !empty($this->basketDiscountList[$code])) {
                     $this->orderData['BASKET_ITEMS'][$code]['LAST_DISCOUNT'] = 'Y';
                 }
             }
             unset($code);
             break;
         case self::APPLY_MODE_LAST:
             foreach ($codeList as &$code) {
                 if (!isset($this->basketDiscountList[$code]) || empty($this->basketDiscountList[$code])) {
                     continue;
                 }
                 $lastDiscount = end($this->basketDiscountList[$code]);
                 if (!empty($lastDiscount['LAST_DISCOUNT']) && $lastDiscount['LAST_DISCOUNT'] == 'Y') {
                     $this->orderData['BASKET_ITEMS'][$code]['LAST_DISCOUNT'] = 'Y';
                 }
             }
             unset($code);
             break;
         case self::APPLY_MODE_ADD:
             break;
     }
     unset($codeList);
     $userGroups = \CUser::getUserGroup($this->orderData['USER_ID']);
     Main\Type\Collection::normalizeArrayValuesByInt($userGroups);
     $cacheKey = md5('U' . implode('_', $userGroups));
     if (!isset($this->discountByUserCache[$cacheKey])) {
         $discountCache = array();
         $groupDiscountIterator = Internals\DiscountGroupTable::getList(array('select' => array('DISCOUNT_ID'), 'filter' => array('@GROUP_ID' => $userGroups, '=ACTIVE' => 'Y')));
         while ($groupDiscount = $groupDiscountIterator->fetch()) {
             $groupDiscount['DISCOUNT_ID'] = (int) $groupDiscount['DISCOUNT_ID'];
             if ($groupDiscount['DISCOUNT_ID'] > 0) {
                 $discountCache[$groupDiscount['DISCOUNT_ID']] = $groupDiscount['DISCOUNT_ID'];
             }
         }
         unset($groupDiscount, $groupDiscountIterator);
         if (!empty($discountCache)) {
             Main\Type\Collection::normalizeArrayValuesByInt($discountCache);
             $this->discountByUserCache[$cacheKey] = $discountCache;
         }
         unset($discountCache);
     }
     if (!empty($this->discountByUserCache[$cacheKey])) {
         $this->discountIds = $this->discountByUserCache[$cacheKey];
     }
     if (empty($this->discountIds)) {
         $this->discountIds = null;
     } else {
         $this->getDiscountModules();
         $couponList = DiscountCouponsManager::getForApply(array('MODULE' => 'sale', 'DISCOUNT_ID' => $this->discountIds), array(), true);
         $cacheKey = md5('D' . implode('_', $this->discountIds));
         if (!empty($couponList)) {
             $cacheKey .= '-C' . implode('_', array_keys($couponList));
         }
         $currentList = array();
         if (!isset($this->saleDiscountCache[$cacheKey])) {
             $discountApply = array();
             $currentDatetime = new Main\Type\DateTime();
             $discountSelect = array('ID', 'PRIORITY', 'SORT', 'LAST_DISCOUNT', 'UNPACK', 'APPLICATION', 'USE_COUPONS', 'EXECUTE_MODULE', 'NAME', 'CONDITIONS_LIST', 'ACTIONS_LIST');
             $discountOrder = array('PRIORITY' => 'DESC', 'SORT' => 'ASC', 'ID' => 'ASC');
             $discountFilter = array('@ID' => $this->discountIds, '=LID' => $this->orderData['SITE_ID'], '@EXECUTE_MODULE' => array('sale', 'all'), array('LOGIC' => 'OR', 'ACTIVE_FROM' => '', '<=ACTIVE_FROM' => $currentDatetime), array('LOGIC' => 'OR', 'ACTIVE_TO' => '', '>=ACTIVE_TO' => $currentDatetime));
             unset($currentDatetime);
             if (empty($couponList)) {
                 $discountFilter['=USE_COUPONS'] = 'N';
             } else {
                 $discountFilter[] = array('LOGIC' => 'OR', '=USE_COUPONS' => 'N', array('=USE_COUPONS' => 'Y', '@COUPON.COUPON' => array_keys($couponList)));
                 $discountSelect['DISCOUNT_COUPON'] = 'COUPON.COUPON';
             }
             $discountIterator = Internals\DiscountTable::getList(array('select' => $discountSelect, 'filter' => $discountFilter, 'order' => $discountOrder));
             while ($discount = $discountIterator->fetch()) {
                 $discount['ID'] = (int) $discount['ID'];
                 if (isset($discountApply[$discount['ID']])) {
                     continue;
                 }
                 $discountApply[$discount['ID']] = true;
                 if (!$this->loadDiscountModules('sale' . $discount['ID'])) {
                     continue;
                 }
                 if ($discount['USE_COUPONS'] == 'Y') {
                     $discount['COUPON'] = $couponList[$discount['DISCOUNT_COUPON']];
                 }
                 $discount['CONDITIONS'] = $discount['CONDITIONS_LIST'];
                 $discount['ACTIONS'] = $discount['ACTIONS_LIST'];
                 $discount['MODULE_ID'] = 'sale';
                 if (isset($this->cacheDiscountModules['sale' . $discount['ID']])) {
                     $discount['MODULES'] = $this->cacheDiscountModules['sale' . $discount['ID']];
                 }
                 unset($discount['ACTIONS_LIST'], $discount['CONDITIONS_LIST']);
                 $currentList[] = $discount;
             }
             unset($discount, $discountIterator, $discountApply);
             $this->saleDiscountCache[$cacheKey] = $currentList;
         } else {
             $currentList = $this->saleDiscountCache[$cacheKey];
         }
         unset($couponList);
         $this->discountIds = array();
         if (!empty($currentList)) {
             foreach ($currentList as &$discount) {
                 $this->discountIds[] = $discount['ID'];
             }
             unset($discount);
             $this->extendOrderData();
             foreach ($currentList as $indexDiscount => $discount) {
                 $this->fillCurrentStep(array('discount' => $discount));
                 if (!self::checkDiscountConditions()) {
                     continue;
                 }
                 $actionsResult = $this->applySaleDiscount();
                 if (!$actionsResult->isSuccess()) {
                     $result->addErrors($actionsResult->getErrors());
                     unset($actionsResult);
                     return $result;
                 }
                 if ($this->currentStep['stop']) {
                     break;
                 }
             }
             unset($discount, $indexDiscount, $currentList);
         }
         $this->fillEmptyCurrentStep();
     }
     return $result;
 }