Ejemplo n.º 1
0
if (!$readOnly && ($listID = $adminList->GroupAction())) {
    if ($_REQUEST['action_target'] == 'selected') {
        $listID = array();
        $discountIterator = Internals\DiscountTable::getList(array('select' => array('ID'), 'filter' => $filter));
        while ($discount = $discountIterator->fetch()) {
            $listID[] = $discount['ID'];
        }
    }
    $listID = array_filter($listID);
    if (!empty($listID)) {
        switch ($_REQUEST['action']) {
            case 'activate':
            case 'deactivate':
                $fields = array('ACTIVE' => $_REQUEST['action'] == 'activate' ? 'Y' : 'N');
                foreach ($listID as &$discountID) {
                    $result = Internals\DiscountTable::update($discountID, $fields);
                    if (!$result->isSuccess()) {
                        $adminList->AddGroupError(implode('<br>', $result->getErrorMessages()), $discountID);
                    }
                    unset($result);
                }
                unset($discountID, $fields);
                break;
            case 'delete':
                foreach ($listID as &$discountID) {
                    $result = Internals\DiscountTable::delete($discountID);
                    if (!$result->isSuccess()) {
                        $adminList->AddGroupError(implode('<br>', $result->getErrorMessages()), $discountID);
                    }
                    unset($result);
                }
Ejemplo n.º 2
0
 public function runOperation()
 {
     global $APPLICATION;
     $this->getDeliveryCodes();
     $found = false;
     $filter = array('>ID' => $this->lastID, '=VERSION' => Sale\Internals\DiscountTable::VERSION_NEW);
     $discountsIterator = Sale\Internals\DiscountTable::getList(array('select' => array('ID', 'MODIFIED_BY', 'TIMESTAMP_X', 'CONDITIONS_LIST', 'ACTIONS_LIST', 'NAME'), 'filter' => $filter, 'order' => array('ID' => 'ASC'), 'limit' => $this->maxOperationCounter));
     while ($discount = $discountsIterator->fetch()) {
         $found = true;
         $error = array();
         $this->convertDelivery($discount['CONDITIONS_LIST']);
         $rawFields = array('ID' => $discount['ID'], 'CONDITIONS' => $discount['CONDITIONS_LIST'], 'ACTIONS' => $discount['ACTIONS_LIST']);
         if (\CSaleDiscount::checkFields('UPDATE', $rawFields)) {
             $fields = array('MODIFIED_BY' => $discount['MODIFIED_BY'], 'TIMESTAMP_X' => $discount['TIMESTAMP_X'], 'UNPACK' => $rawFields['UNPACK'], 'CONDITIONS' => $discount['CONDITIONS_LIST'], 'VERSION' => Sale\Internals\DiscountTable::VERSION_15);
             if (isset($rawFields['EXECUTE_MODULE'])) {
                 $fields['EXECUTE_MODULE'] = $rawFields['EXECUTE_MODULE'];
             }
             $updateResult = Sale\Internals\DiscountTable::update($discount['ID'], $fields);
             if ($updateResult->isSuccess()) {
                 if (isset($rawFields['ENTITIES'])) {
                     Sale\Internals\DiscountEntitiesTable::updateByDiscount($discount['ID'], $rawFields['ENTITIES'], true);
                 }
                 if (isset($rawFields['HANDLERS']['MODULES'])) {
                     Sale\Internals\DiscountModuleTable::updateByDiscount($discount['ID'], $rawFields['HANDLERS']['MODULES'], true);
                 }
             } else {
                 $error = $updateResult->getErrorMessages();
             }
         } else {
             if ($ex = $APPLICATION->GetException()) {
                 $error[] = $ex->GetString();
             } else {
                 $error[] = Loc::getMessage('SALE_DISCOUNT_REINDEX_UPDATE_UNKNOWN_ERROR');
             }
         }
         $this->lastID = $discount['ID'];
         $this->allOperationCounter++;
         if (!empty($error)) {
             $this->errorCounter++;
             $this->errors[] = Loc::getMessage('SALE_DISCOUNT_REINDEX_ORDER_ERROR_REPORT', array('#URL#' => str_replace('#ID#', $discount['ID'], $this->discountEditUrl), '#TITLE#' => trim((string) $discount['NAME']) != '' ? $discount['NAME'] : $discount['ID'], '#ERRORS#' => implode('; ', $error)));
         }
         if ($this->maxExecutionTime > 0 && time() - $this->startOperationTime > $this->maxExecutionTime) {
             break;
         }
     }
     unset($discount, $discountsIterator);
     if (!$found) {
         $this->finishOperation = true;
     }
 }