public static function convertPsBusVal()
    {
        if (\Bitrix\Main\Config\Option::get('main', '~sale_paysystem_converted') == 'Y') {
            return '';
        }
        \Bitrix\Main\Config\Option::set('main', '~sale_paysystem_converted', 'Y');
        if (!\Bitrix\Main\Loader::includeModule('sale')) {
            return '';
        }
        global $DB;
        if ($DB->TableExists('b_sale_pay_system_map') || $DB->TableExists('B_SALE_PAY_SYSTEM_MAP')) {
            return '';
        }
        $dbRes = \Bitrix\Sale\Internals\PaySystemActionTable::getList();
        $oldActionFiles = self::getOldToNewHandlersMap();
        $paySystems = array();
        while ($paySystem = $dbRes->fetch()) {
            $codesAliases = array();
            $params = unserialize($paySystem['PARAMS']);
            if (is_array($params)) {
                if (isset($oldActionFiles[$paySystem['ACTION_FILE']])) {
                    $codesAliases = self::getCodesAliases($oldActionFiles[$paySystem['ACTION_FILE']]);
                }
                foreach ($params as $key => $value) {
                    if (isset($oldActionFiles[$paySystem['ACTION_FILE']])) {
                        if ($key == 'IS_TEST' || $key == 'CHANGE_STATUS_PAY' || $key == 'TEST' || $key == 'DEMO' || $key == 'AUTOPAY') {
                            $keyValue = $value['VALUE'] != 'Y' && $value['VALUE'] != 'N' ? 'N' : $value['VALUE'];
                            $value = array('TYPE' => 'INPUT', 'VALUE' => $keyValue);
                        }
                        if ($key == 'TEST_MODE') {
                            $value = array('TYPE' => 'INPUT', 'VALUE' => $value['VALUE'] == 'TEST' ? 'Y' : 'N');
                        }
                    }
                    if ($value['TYPE'] == 'SELECT' || $value['TYPE'] == 'FILE') {
                        $value['TYPE'] = 'INPUT';
                    }
                    if (isset($codesAliases[$key])) {
                        $params[$codesAliases[$key]] = $value;
                        unset($params[$key]);
                    } else {
                        $params[$key] = $value;
                    }
                }
            }
            if (isset($oldActionFiles[$paySystem['ACTION_FILE']]) && !IsModuleInstalled('intranet')) {
                if (isset($params['PAYMENT_ID'])) {
                    $value = $params['PAYMENT_ID']['VALUE'] == 'ACCOUNT_NUMBER' ? 'ACCOUNT_NUMBER' : 'ID';
                    $params['PAYMENT_ID'] = array('TYPE' => 'PAYMENT', 'VALUE' => $value);
                }
                if (isset($params['PAYMENT_CURRENCY'])) {
                    $params['PAYMENT_CURRENCY'] = array('TYPE' => 'PAYMENT', 'VALUE' => 'CURRENCY');
                }
                if (isset($params['PAYMENT_DATE_INSERT'])) {
                    if ($params['PAYMENT_DATE_INSERT']['VALUE'] == 'DATE_INSERT_DATE' || $params['PAYMENT_DATE_INSERT']['VALUE'] == 'DATE_BILL_DATE') {
                        $date = 'DATE_BILL_DATE';
                    } else {
                        $date = 'DATE_BILL';
                    }
                    $params['PAYMENT_DATE_INSERT'] = array('TYPE' => 'PAYMENT', 'VALUE' => $date);
                }
                if (isset($params['PAYMENT_SHOULD_PAY'])) {
                    $params['PAYMENT_SHOULD_PAY'] = array('TYPE' => 'PAYMENT', 'VALUE' => 'SUM');
                }
                if (isset($params['PAYMENT_VALUE'])) {
                    $paySystem['PS_MODE'] = $params['PAYMENT_VALUE']['VALUE'];
                }
            }
            if (isset($oldActionFiles[$paySystem['ACTION_FILE']])) {
                $paySystem['ACTION_FILE'] = $oldActionFiles[$paySystem['ACTION_FILE']];
            }
            $paySystem['PARAMS'] = $params;
            if (!isset($paySystems[$paySystem['PAY_SYSTEM_ID']])) {
                $paySystems[$paySystem['PAY_SYSTEM_ID']] = array();
            }
            if (!isset($paySystems[$paySystem['PAY_SYSTEM_ID']][$paySystem['ACTION_FILE']])) {
                $paySystems[$paySystem['PAY_SYSTEM_ID']][$paySystem['ACTION_FILE']] = array();
            }
            $paySystems[$paySystem['PAY_SYSTEM_ID']][$paySystem['ACTION_FILE']][] = $paySystem;
        }
        $codes = array();
        foreach ($paySystems as $items) {
            foreach ($items as $psItem) {
                foreach ($psItem as $item) {
                    $params = $item['PARAMS'];
                    if ($params) {
                        foreach ($params as $code => $value) {
                            if ($value['VALUE'] == '') {
                                continue;
                            }
                            if ($value['TYPE'] == '') {
                                $key = 'VALUE|' . $value['VALUE'];
                            } else {
                                $key = $value['TYPE'] . '|' . $value['VALUE'];
                            }
                            if (!isset($codes[$code][$key])) {
                                $codes[$code][$key] = 0;
                            }
                            $codes[$code][$key]++;
                        }
                    }
                }
            }
        }
        $generalBusVal = array();
        foreach ($codes as $code => $values) {
            $generalBusVal[$code] = null;
            foreach ($values as $i => $cnt) {
                if ($generalBusVal[$code] === null || $values[$generalBusVal[$code]] < $cnt) {
                    $generalBusVal[$code] = $i;
                }
            }
        }
        //set general
        foreach ($generalBusVal as $code => $param) {
            list($type, $value) = explode('|', $param);
            \Bitrix\Sale\BusinessValue::setMapping($code, null, null, array('PROVIDER_KEY' => $type, 'PROVIDER_VALUE' => $value));
        }
        $mustDeleted = array();
        $duplicateRecords = array();
        foreach ($paySystems as $actions) {
            foreach ($actions as $items) {
                $firstItem = current($items);
                if (!array_key_exists($firstItem['ID'], $duplicateRecords)) {
                    $duplicateRecords[$firstItem['ID']] = array();
                }
                if (!array_key_exists('PERSON_TYPE_ID', $duplicateRecords[$firstItem['ID']])) {
                    $duplicateRecords[$firstItem['ID']]['PERSON_TYPE_ID'] = array();
                }
                if ($firstItem['PERSON_TYPE_ID'] > 0) {
                    $duplicateRecords[$firstItem['ID']]['PERSON_TYPE_ID'][] = $firstItem['PERSON_TYPE_ID'];
                }
                $duplicateRecords[$firstItem['ID']]['EXTERNAL_ID'] = $firstItem['PAY_SYSTEM_ID'];
                foreach ($items as $ps) {
                    if (in_array($ps['ACTION_FILE'], array('yandex', 'roboxchange')) && $firstItem['PS_MODE'] && $firstItem['PS_MODE'] != $ps['PS_MODE']) {
                        if (!array_key_exists($ps['ID'], $duplicateRecords)) {
                            $duplicateRecords[$ps['ID']] = array();
                        }
                        if (!array_key_exists('PERSON_TYPE_ID', $duplicateRecords[$firstItem['ID']])) {
                            $duplicateRecords[$ps['ID']]['PERSON_TYPE_ID'] = array();
                        }
                        if ($ps['PERSON_TYPE_ID'] > 0) {
                            $duplicateRecords[$ps['ID']]['PERSON_TYPE_ID'][] = $ps['PERSON_TYPE_ID'];
                        }
                        $duplicateRecords[$ps['ID']]['EXTERNAL_ID'] = $ps['PAY_SYSTEM_ID'];
                        $duplicateRecords[$ps['ID']]['NEW_PS'] = 'Y';
                    } else {
                        if ($ps['ID'] == $firstItem['ID']) {
                            continue;
                        }
                        if ($ps['PERSON_TYPE_ID'] > 0) {
                            $duplicateRecords[$firstItem['ID']]['PERSON_TYPE_ID'][] = $ps['PERSON_TYPE_ID'];
                        }
                        if (!isset($mustDeleted[$firstItem['ID']])) {
                            $mustDeleted[$firstItem['ID']] = array();
                        }
                        $mustDeleted[$firstItem['ID']][] = $ps['ID'];
                    }
                }
                foreach ($items as $item) {
                    $itemParams = array();
                    if ($item['PARAMS']) {
                        $itemParams = $item['PARAMS'];
                        if ($itemParams) {
                            foreach ($itemParams as $code => $param) {
                                $type = $param['TYPE'] ?: 'VALUE';
                                $pT = null;
                                $pS = null;
                                if (in_array($item['ACTION_FILE'], array('yandex', 'roboxchange')) && $firstItem['PS_MODE'] && $firstItem['PS_MODE'] != $item['PS_MODE']) {
                                    $consumer = 'PAYSYSTEM_' . $item['ID'];
                                } else {
                                    $consumer = 'PAYSYSTEM_' . $firstItem['ID'];
                                }
                                $cases = array(1 => array('PS' => null, 'PT' => null), 2 => array('PS' => $consumer, 'PT' => $item['PERSON_TYPE_ID']));
                                foreach ($cases as $case) {
                                    if (\Bitrix\Sale\BusinessValue::isSetMapping($code, $case['PS'], $case['PT'])) {
                                        $map = \Bitrix\Sale\BusinessValue::getMapping($code);
                                        if ($map && $map['PROVIDER_KEY'] == $type && $map['PROVIDER_VALUE'] == $param['VALUE']) {
                                            continue 2;
                                        }
                                    } else {
                                        $pT = $case['PT'];
                                        $pS = $case['PS'];
                                        break;
                                    }
                                }
                                $value = is_array($param['VALUE']) ? key($param['VALUE']) : $param['VALUE'];
                                \Bitrix\Sale\BusinessValue::setMapping($code, $pS, $pT, array('PROVIDER_KEY' => $type, 'PROVIDER_VALUE' => $value), true);
                            }
                        }
                    }
                    if (!isset($mustDeleted[$firstItem['ID']][$item['ID']])) {
                        $itemParams['BX_PAY_SYSTEM_ID'] = array('TYPE' => '', 'VALUE' => $item['ID']);
                        $item['PARAMS'] = serialize($itemParams);
                        $itemId = $item['ID'];
                        unset($item['ID']);
                        \Bitrix\Sale\Internals\PaySystemActionTable::update($itemId, $item);
                    }
                }
            }
        }
        global $DB;
        if ($DB->TableExists('b_sale_pay_system_map')) {
            $DB->Query('DROP TABLE b_sale_pay_system_map');
        }
        if ($DB->type == 'MYSQL') {
            $DB->Query('
				create table if not exists b_sale_pay_system_map
				(
					PS_ID_OLD int null,
					PS_ID int null,
					PT_ID int null,
					NEW_PS char(1) not null default \'N\'
				)');
        }
        if ($DB->type == 'MSSQL') {
            $DB->Query('
				CREATE TABLE B_SALE_PAY_SYSTEM_MAP
				(
					PS_ID int NULL,
					PS_ID_OLD int NULL,
					PT_ID int NULL,
					NEW_PS char(1) NOT NULL DEFAULT \'N\'
				)');
        }
        if ($DB->type == 'ORACLE') {
            $DB->Query('
				CREATE TABLE B_SALE_PAY_SYSTEM_MAP
				(
					PS_ID NUMBER(18) NULL,
					PS_ID_OLD NUMBER(18) NULL,
					PT_ID NUMBER(18) NULL,
					NEW_PS CHAR(1 CHAR) DEFAULT \'N\' NOT NULL
				)');
        }
        foreach ($duplicateRecords as $id => $data) {
            if ($data['PERSON_TYPE_ID']) {
                $params = array('filter' => array("SERVICE_ID" => $id, "SERVICE_TYPE" => \Bitrix\Sale\Services\PaySystem\Restrictions\Manager::SERVICE_TYPE_PAYMENT, "=CLASS_NAME" => '\\Bitrix\\Sale\\Services\\PaySystem\\Restrictions\\PersonType'));
                $dbRes = \Bitrix\Sale\Internals\ServiceRestrictionTable::getList($params);
                if (!$dbRes->fetch()) {
                    $fields = array("SERVICE_ID" => $id, "SERVICE_TYPE" => \Bitrix\Sale\Services\PaySystem\Restrictions\Manager::SERVICE_TYPE_PAYMENT, "SORT" => 100, "PARAMS" => array('PERSON_TYPE_ID' => $data['PERSON_TYPE_ID']));
                    \Bitrix\Sale\Services\PaySystem\Restrictions\PersonType::save($fields);
                }
            }
        }
        foreach ($duplicateRecords as $id => $data) {
            if ($data['EXTERNAL_ID'] <= 0) {
                continue;
            }
            $newPs = $data['NEW_PS'] ?: 'N';
            foreach ($data['PERSON_TYPE_ID'] as $personTypeId) {
                $DB->Query('INSERT INTO b_sale_pay_system_map(PS_ID, PS_ID_OLD, PT_ID, NEW_PS) VALUES(' . $id . ', ' . $data['EXTERNAL_ID'] . ', ' . $personTypeId . ', \'' . $newPs . '\' )');
            }
        }
        $DB->Query('
			UPDATE b_sale_order SET
			PAY_SYSTEM_ID = (
				SELECT bspm.PS_ID
				FROM b_sale_pay_system_map bspm
				WHERE bspm.PT_ID=PERSON_TYPE_ID AND bspm.PS_ID_OLD=PAY_SYSTEM_ID
			)');
        if ($DB->type == 'MYSQL' || $DB->type == 'ORACLE') {
            $DB->Query('
				UPDATE b_sale_order_payment bsop SET
				PAY_SYSTEM_ID = (
					SELECT bspm.PS_ID
					FROM b_sale_pay_system_map bspm, b_sale_order bso
					WHERE bspm.PS_ID_OLD = bsop.PAY_SYSTEM_ID
						AND bso.ID = bsop.ORDER_ID
						AND bspm.PT_ID = bso.PERSON_TYPE_ID
				)');
        } elseif ($DB->type == 'MSSQL') {
            $DB->Query('
				UPDATE bsop SET
				PAY_SYSTEM_ID = (
					SELECT bspm.PS_ID
					FROM b_sale_pay_system_map bspm, b_sale_order bso
					WHERE bspm.PS_ID_OLD = bsop.PAY_SYSTEM_ID
						AND bso.ID = bsop.ORDER_ID
						AND bspm.PT_ID = bso.PERSON_TYPE_ID
				)
				FROM b_sale_order_payment bsop');
        }
        //		\Bitrix\Main\Config\Option::set('main', '~sale_paysystem_converted', 'Y');
        foreach ($mustDeleted as $items) {
            foreach ($items as $id) {
                PaySystemActionTable::delete($id);
            }
        }
        /** DELIVERY2PAYSYSTEM */
        if ($DB->type == 'MYSQL') {
            $DB->Query('
				UPDATE b_sale_delivery2paysystem bsd2p
				SET bsd2p.PAYSYSTEM_ID=(SELECT bspm.PS_ID FROM b_sale_pay_system_map bspm WHERE bspm.PS_ID_OLD=bsd2p.PAYSYSTEM_ID AND bspm.NEW_PS=\'N\' LIMIT 1)');
        }
        if ($DB->type == 'ORACLE') {
            $DB->Query('
				UPDATE b_sale_delivery2paysystem bsd2p
				SET bsd2p.PAYSYSTEM_ID=(SELECT bspm.PS_ID FROM b_sale_pay_system_map bspm WHERE bspm.PS_ID_OLD=bsd2p.PAYSYSTEM_ID AND bspm.NEW_PS=\'N\' AND ROWNUM=1)');
        }
        if ($DB->type == 'MSSQL') {
            $DB->Query('
				UPDATE bsd2p
				SET bsd2p.PAYSYSTEM_ID=(SELECT TOP(1) bspm.PS_ID FROM b_sale_pay_system_map bspm WHERE bspm.PS_ID_OLD=bsd2p.PAYSYSTEM_ID AND bspm.NEW_PS=\'N\')
				FROM b_sale_delivery2paysystem bsd2p');
        }
        $DB->Query('
			INSERT INTO b_sale_delivery2paysystem(DELIVERY_ID, PAYSYSTEM_ID, LINK_DIRECTION)
			SELECT d2p.DELIVERY_ID, pm1.PS_ID, d2p.LINK_DIRECTION
			FROM b_sale_delivery2paysystem d2p
				INNER JOIN b_sale_pay_system_map pm ON d2p.PAYSYSTEM_ID = pm.PS_ID AND pm.NEW_PS = \'N\'
				INNER JOIN b_sale_pay_system_map pm1 ON pm1.PS_ID_OLD = pm.PS_ID_OLD AND pm1.NEW_PS = \'Y\'');
        /** ORDER_PROPS_REL */
        if ($DB->type == 'MYSQL') {
            $DB->Query('
				UPDATE b_sale_order_props_relation bsopr
				SET bsopr.ENTITY_ID=(SELECT bspm.PS_ID FROM b_sale_pay_system_map bspm WHERE bspm.PS_ID_OLD=bsopr.ENTITY_ID AND bspm.NEW_PS=\'N\' LIMIT 1)
				WHERE bsopr.ENTITY_TYPE=\'P\'');
        }
        if ($DB->type == 'ORACLE') {
            $DB->Query('
				UPDATE b_sale_order_props_relation bsopr
				SET bsopr.ENTITY_ID=(SELECT bspm.PS_ID FROM b_sale_pay_system_map bspm WHERE bspm.PS_ID_OLD=bsopr.ENTITY_ID AND bspm.NEW_PS=\'N\' AND ROWNUM=1)
				WHERE bsopr.ENTITY_TYPE=\'P\'');
        }
        if ($DB->type == 'MSSQL') {
            $DB->Query('
				UPDATE bsopr
				SET bsopr.ENTITY_ID=(SELECT TOP(1) bspm.PS_ID FROM b_sale_pay_system_map bspm WHERE bspm.PS_ID_OLD=bsopr.ENTITY_ID AND bspm.NEW_PS=\'N\')
				FROM b_sale_order_props_relation bsopr
				WHERE bsopr.ENTITY_TYPE=\'P\'');
        }
        $DB->Query('
			INSERT INTO b_sale_order_props_relation(ENTITY_ID, ENTITY_TYPE, PROPERTY_ID)
			SELECT pm1.PS_ID, opr.ENTITY_TYPE, opr.PROPERTY_ID
			FROM b_sale_order_props_relation opr
				INNER JOIN b_sale_pay_system_map pm ON pm.PS_ID = opr.ENTITY_ID AND pm.NEW_PS = \'N\'
				INNER JOIN b_sale_pay_system_map pm1 ON pm1.PS_ID_OLD = pm.PS_ID_OLD AND pm1.NEW_PS = \'Y\'
			WHERE opr.ENTITY_TYPE = \'P\'');
        $DB->Query('
			INSERT INTO b_sale_service_rstr(SERVICE_ID, SORT, CLASS_NAME, PARAMS, SERVICE_TYPE)
			SELECT bsd2p.PAYSYSTEM_ID, 100, \'Bitrix\\\\Sale\\\\Services\\\\PaySystem\\\\Restrictions\\\\Delivery\', \'a:0:{}\', 1 FROM b_sale_delivery2paysystem bsd2p GROUP BY bsd2p.PAYSYSTEM_ID');
        $DB->Query('UPDATE b_sale_pay_system_action SET psa_name=name');
        if ($DB->type == 'MYSQL' || $DB->type == 'ORACLE') {
            $DB->Query('UPDATE b_sale_pay_system_action psa
				SET psa.name=(
					SELECT name
					FROM b_sale_pay_system ps
					WHERE ps.ID=psa.PAY_SYSTEM_ID
				)');
        } else {
            if ($DB->type == 'MSSQL') {
                $DB->Query('UPDATE psa
				SET psa.name=(
					SELECT name
					FROM b_sale_pay_system ps
					WHERE ps.ID=psa.PAY_SYSTEM_ID
				)
				FROM b_sale_pay_system_action psa');
            }
        }
        return '';
    }
Пример #2
0
 /**
  * @param $deliveryId
  * @param array $params
  * @param $update
  * @return bool
  * @throws \Bitrix\Main\ArgumentException
  * @deprecated
  */
 protected static function saveRestrictionByMaxSize($deliveryId, $maxSize, $update)
 {
     $rfields = array("SERVICE_ID" => $deliveryId, "SERVICE_TYPE" => \Bitrix\Sale\Services\Base\RestrictionManager::SERVICE_TYPE_SHIPMENT, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByMaxSize', "PARAMS" => array("MAX_SIZE" => $maxSize));
     if ($update) {
         $rstrRes = \Bitrix\Sale\Internals\ServiceRestrictionTable::getList(array('filter' => array("=SERVICE_ID" => $deliveryId, "=SERVICE_TYPE" => \Bitrix\Sale\Services\Base\RestrictionManager::SERVICE_TYPE_SHIPMENT, "=CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByMaxSize')));
         if ($restrict = $rstrRes->fetch()) {
             $rres = \Bitrix\Sale\Internals\ServiceRestrictionTable::update($restrict["ID"], $rfields);
         } else {
             $rres = \Bitrix\Sale\Internals\ServiceRestrictionTable::add($rfields);
         }
     } else {
         $rres = \Bitrix\Sale\Internals\ServiceRestrictionTable::add($rfields);
     }
     return $rres->isSuccess();
 }
Пример #3
0
     $logoFileArray = CFile::GetFileArray($f_LOGOTIP);
     $f_LOGOTIP = CFile::ShowImage($logoFileArray, 100, 100, "border=0", "", false);
 }
 $row->AddField("LOGOTIP", $f_LOGOTIP);
 $row->AddField("DESCRIPTION", $f_DESCRIPTION);
 $pTypes = '';
 $aFiles = '';
 $dbRestriction = \Bitrix\Sale\Internals\ServiceRestrictionTable::getList(array('select' => array('PARAMS'), 'filter' => array('SERVICE_ID' => $f_ID, 'SERVICE_TYPE' => \Bitrix\Sale\Services\PaySystem\Restrictions\Manager::SERVICE_TYPE_PAYMENT, '=CLASS_NAME' => '\\Bitrix\\Sale\\Services\\PaySystem\\Restrictions\\PersonType')));
 if ($restriction = $dbRestriction->fetch()) {
     $ptRes = \Bitrix\Sale\PersonTypeTable::getList(array('select' => array('NAME'), 'filter' => array('ID' => $restriction['PARAMS']['PERSON_TYPE_ID'])));
     while ($personType = $ptRes->fetch()) {
         $pTypes .= "<div>" . $personType['NAME'] . "</div>";
     }
 }
 $row->AddField("PERSON_TYPES", $pTypes);
 $dbRestriction = \Bitrix\Sale\Internals\ServiceRestrictionTable::getList(array('select' => array('PARAMS'), 'filter' => array('SERVICE_ID' => $f_ID, 'SERVICE_TYPE' => \Bitrix\Sale\Services\PaySystem\Restrictions\Manager::SERVICE_TYPE_PAYMENT, '=CLASS_NAME' => '\\Bitrix\\Sale\\Services\\PaySystem\\Restrictions\\Site')));
 $pSite = '';
 if ($restriction = $dbRestriction->fetch()) {
     $siteRes = \Bitrix\Main\SiteTable::getList(array('select' => array('NAME', 'LID'), 'filter' => array('LID' => $restriction['PARAMS']['SITE_ID'], 'LANGUAGE_ID' => $context->getLanguage())));
     while ($site = $siteRes->fetch()) {
         $pSite .= "<div>" . $site['NAME'] . " (" . $site['LID'] . ")</div>";
     }
 }
 $row->AddField("LID", $pSite);
 $description = \Bitrix\Sale\PaySystem\Manager::getHandlerDescription($f_ACTION_FILE);
 $row->AddField("ACTION_FILES", $description['NAME']);
 $arActions = array(array("ICON" => "edit", "TEXT" => GetMessage("SALE_EDIT"), "TITLE" => GetMessage("SALE_EDIT_DESCR"), "ACTION" => $lAdmin->ActionRedirect("sale_pay_system_edit.php?ID=" . $f_ID . "&lang=" . $context->getLanguage()), "DEFAULT" => true));
 if ($saleModulePermissions >= "W") {
     $arActions[] = array("SEPARATOR" => true);
     $arActions[] = array("ICON" => "delete", "TEXT" => GetMessage("SALE_DELETE"), "TITLE" => GetMessage("SALE_DELETE_DESCR"), "ACTION" => "if(confirm('" . GetMessage('SALE_CONFIRM_DEL_MESSAGE') . "')) " . $lAdmin->ActionDoGroup($f_ID, "delete"));
 }
Пример #4
0
 public static function GetList($arOrder = array("SORT" => "ASC", "NAME" => "ASC"), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array())
 {
     if (array_key_exists("PSA_PERSON_TYPE_ID", $arFilter)) {
         $arFilter['PERSON_TYPE_ID'] = $arFilter['PSA_PERSON_TYPE_ID'];
         unset($arFilter["PSA_PERSON_TYPE_ID"]);
     }
     $salePaySystemFields = array('ID', 'NAME', 'ACTIVE', 'SORT', 'DESCRIPTION');
     $ignoredFields = array('LID', 'CURRENCY', 'PERSON_TYPE_ID');
     if (!$arSelectFields) {
         $select = array('ID', 'NAME', 'ACTIVE', 'SORT', 'DESCRIPTION');
     } else {
         $select = array();
         foreach ($arSelectFields as $key => $field) {
             if (in_array($field, $ignoredFields)) {
                 continue;
             }
             $select[$key] = self::getAlias($field);
         }
     }
     $filter = array();
     foreach ($arFilter as $key => $value) {
         if (in_array($key, $ignoredFields)) {
             continue;
         }
         $filter[self::getAlias($key)] = $value;
     }
     if (isset($arFilter['PERSON_TYPE_ID'])) {
         $select = array_merge($select, array('PSA_ID' => 'ID', 'PSA_NAME', 'ACTION_FILE', 'RESULT_FILE', 'NEW_WINDOW', 'PERSON_TYPE_ID', 'PARAMS', 'TARIF', 'HAVE_PAYMENT', 'HAVE_ACTION', 'HAVE_RESULT', 'HAVE_PREPAY', 'HAVE_RESULT_RECEIVE', 'ENCODING', 'LOGOTIP'));
     }
     if (in_array('PARAMS', $select) && !array_key_exists('PSA_ID', $select)) {
         $select['PSA_ID'] = 'ID';
     }
     if (in_array('PARAMS', $select) && !in_array('PERSON_TYPE_ID', $select)) {
         $select[] = 'PERSON_TYPE_ID';
     }
     $order = array();
     foreach ($arOrder as $key => $value) {
         $order[self::getAlias($key)] = $value;
     }
     $groupBy = array();
     if ($arGroupBy !== false) {
         $arGroupBy = !is_array($arGroupBy) ? array($arGroupBy) : $arGroupBy;
         foreach ($arGroupBy as $key => $value) {
             $groupBy[$key] = self::getAlias($value);
         }
     }
     $dbRes = PaySystemActionTable::getList(array('select' => $select, 'filter' => $filter, 'order' => $order, 'group' => $groupBy));
     $limit = null;
     if (is_array($arNavStartParams) && isset($arNavStartParams['nTopCount'])) {
         if ($arNavStartParams['nTopCount'] > 0) {
             $limit = $arNavStartParams['nTopCount'];
         }
     }
     $result = array();
     while ($data = $dbRes->fetch()) {
         if ($limit !== null && !$limit) {
             break;
         }
         $dbRestriction = \Bitrix\Sale\Internals\ServiceRestrictionTable::getList(array('filter' => array('SERVICE_ID' => $data['ID'], 'SERVICE_TYPE' => \Bitrix\Sale\Services\PaySystem\Restrictions\Manager::SERVICE_TYPE_PAYMENT)));
         while ($restriction = $dbRestriction->fetch()) {
             if (!CSalePaySystemAction::checkRestriction($restriction, $arFilter)) {
                 continue 2;
             }
         }
         if (isset($data['ACTION_FILE'])) {
             $oldHandler = array_search($data['ACTION_FILE'], CSalePaySystemAction::getOldToNewHandlersMap());
             if ($oldHandler !== false) {
                 $data['ACTION_FILE'] = $oldHandler;
             }
         }
         if (array_key_exists('PARAMS', $data)) {
             $params = CSalePaySystemAction::getParamsByConsumer('PAYSYSTEM_' . $data['PSA_ID'], $data['PERSON_TYPE_ID']);
             $params['BX_PAY_SYSTEM_ID'] = array('TYPE' => '', 'VALUE' => $data['PSA_ID']);
             $data['PARAMS'] = serialize($params);
         }
         foreach ($data as $key => $value) {
             if (!in_array($key, $salePaySystemFields)) {
                 $newKey = self::getAliasBack($key);
                 if ($newKey != $key) {
                     $data[$newKey] = $value;
                     unset($data[$key]);
                 }
             }
         }
         $result[] = $data;
         $limit--;
     }
     $dbRes = new \CDBResult();
     $dbRes->InitFromArray($result);
     return $dbRes;
 }
Пример #5
0
 /**
  * @param array $arOrder
  * @param array $arFilter
  * @param bool $arGroupBy
  * @param bool $arNavStartParams
  * @param array $arSelectFields
  * @return \CDBResult
  * @throws \Bitrix\Main\ArgumentException
  * @deprecated
  */
 public static function GetList($arOrder = array("SORT" => "ASC", "NAME" => "ASC"), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array('*'))
 {
     if (empty($arSelectFields)) {
         $arSelectFields = array('*');
     }
     $params = array('order' => self::convertFilterOldToNew($arOrder), 'filter' => self::convertFilterOldToNew($arFilter), 'group' => self::convertGroupOldToNew($arGroupBy), 'select' => self::convertSelectOldToNew($arSelectFields));
     $services = array();
     $params['filter']['=CLASS_NAME'] = '\\Bitrix\\Sale\\Delivery\\Services\\Configurable';
     $dbRes = \Bitrix\Sale\Delivery\Services\Table::getList($params);
     if (isset($arFilter["WEIGHT"]) && DoubleVal($arFilter["WEIGHT"]) > 0) {
         if (!isset($arFilter["WEIGHT_FROM"]) || floatval($arFilter["WEIGHT"]) > floatval($arFilter["WEIGHT_FROM"])) {
             $arFilter["+<=WEIGHT_FROM"] = $arFilter["WEIGHT"];
         }
         if (!isset($arFilter["WEIGHT_TO"]) || floatval($arFilter["WEIGHT"]) < floatval($arFilter["WEIGHT_TO"])) {
             $arFilter["+>=WEIGHT_TO"] = $arFilter["WEIGHT"];
         }
     }
     if (isset($arFilter["ORDER_PRICE"]) && IntVal($arFilter["ORDER_PRICE"]) > 0) {
         if (!isset($arFilter["ORDER_PRICE_FROM"]) || floatval($arFilter["ORDER_PRICE"]) > floatval($arFilter["ORDER_PRICE_FROM"])) {
             $arFilter["+<=ORDER_PRICE_FROM"] = $arFilter["ORDER_PRICE"];
         }
         if (!isset($arFilter["ORDER_PRICE_TO"]) || floatval($arFilter["ORDER_PRICE"]) < floatval($arFilter["ORDER_PRICE_TO"])) {
             $arFilter["+>=ORDER_PRICE_TO"] = $arFilter["ORDER_PRICE"];
         }
     }
     while ($service = $dbRes->fetch()) {
         $dbRstrRes = \Bitrix\Sale\Internals\ServiceRestrictionTable::getList(array('filter' => array("=SERVICE_ID" => $service["ID"], "=SERVICE_TYPE" => \Bitrix\Sale\Services\Base\RestrictionManager::SERVICE_TYPE_SHIPMENT)));
         while ($restr = $dbRstrRes->fetch()) {
             if (!self::checkRestrictionFilter($restr, $arFilter)) {
                 continue 2;
             }
             $service = self::getSelectedRestrictionField($service, $restr, $arSelectFields);
         }
         $selectAsterisk = in_array('*', $arSelectFields);
         $mofifiedFields = array("LID", "WEIGHT_FROM", "WEIGHT_TO", "ORDER_PRICE_FROM", "ORDER_PRICE_TO", "ORDER_CURRENCY");
         foreach ($mofifiedFields as $field) {
             if (($selectAsterisk || in_array($field, $arSelectFields)) && !array_key_exists($field, $service)) {
                 $service[$field] = "";
             }
         }
         if ($selectAsterisk || in_array("PERIOD_FROM", $arSelectFields)) {
             $service["PERIOD_FROM"] = $service["CONFIG"]["MAIN"]["PERIOD"]["FROM"];
         }
         if ($selectAsterisk || in_array("PERIOD_TO", $arSelectFields)) {
             $service["PERIOD_TO"] = $service["CONFIG"]["MAIN"]["PERIOD"]["TO"];
         }
         if ($selectAsterisk || in_array("PERIOD_TYPE", $arSelectFields)) {
             $service["PERIOD_TYPE"] = $service["CONFIG"]["MAIN"]["PERIOD"]["TYPE"];
         }
         if ($selectAsterisk || in_array("PRICE", $arSelectFields)) {
             $service["CLASS_NAME"] = '\\Bitrix\\Sale\\Delivery\\Services\\Configurable';
             $tmpSrv = \Bitrix\Sale\Delivery\Services\Manager::createObject($service);
             if ($tmpSrv) {
                 $res = $tmpSrv->calculate();
                 $service["PRICE"] = $res->getPrice();
             } else {
                 $service["PRICE"] = 0;
             }
         }
         if ($selectAsterisk || in_array("STORE", $arSelectFields)) {
             $stores = \Bitrix\Sale\Delivery\ExtraServices\Manager::getStoresList($service["ID"]);
             $service["STORE"] = count($stores) > 0 ? serialize($stores) : "";
         }
         if (intval($service["CODE"]) > 0) {
             $service["ID"] = $service["CODE"];
         }
         unset($service["CODE"], $service["CLASS_NAME"], $service["CONFIG"], $service["PARENT_ID"]);
         $services[] = $service;
     }
     if (!empty($arOrder)) {
         foreach ($arOrder as $k => $v) {
             if ($v == 'ASC') {
                 $arOrder[$k] = SORT_ASC;
             } elseif ($v == 'DESC') {
                 $arOrder[$k] = SORT_DESC;
             }
         }
         sortByColumn($services, $arOrder);
     }
     $result = new \CDBResult();
     $result->InitFromArray($services);
     return $result;
 }