Пример #1
0
 static function testInstallPaysystems()
 {
     var_dump(BusinessValue::install('PAYSYSTEM_WEBMONEY', '/bitrix/modules/sale/lib/payment_system_webmoney.php', array('GROUPS' => array('ORDER' => array('SORT' => 400), 'WEBMONEY' => array('SORT' => 500)), 'CODES' => array('ORDER_NUMBER' => array('GROUP' => 'ORDER', 'SORT' => 100, 'MAP' => array('COMMON' => array('ORDER', 'ACCOUNT_NUMBER'))), 'ORDER_SUM' => array('GROUP' => 'ORDER', 'SORT' => 200, 'MAP' => array('COMMON' => array('ORDER', 'PRICE'))), 'WEBMONEY_WALLET_NUMBER' => array('GROUP' => 'WEBMONEY', 'SORT' => 100)))));
     var_dump(BusinessValue::install('PAYSYSTEM_SBERBANK', '/bitrix/modules/sale/lib/payment_system_sberbank.php', array('GROUPS' => array('COMPANY' => array('SORT' => 100), 'CLIENT' => array('SORT' => 200)), 'CODES' => array('COMPANY_INN' => array('GROUP' => 'COMPANY', 'SORT' => 100, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN, 'MAP' => array(2 => array('PROPERTY', 10))), 'COMPANY_KPP' => array('GROUP' => 'COMPANY', 'SORT' => 200, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN), 'COMPANY_NAME' => array('GROUP' => 'COMPANY', 'SORT' => 300, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN, 'MAP' => array(2 => array('COMPANY', 'NAME'))), 'COMPANY_BANK_BIK' => array('GROUP' => 'COMPANY', 'SORT' => 400, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN), 'COMPANY_BANK_NAME' => array('GROUP' => 'COMPANY', 'SORT' => 500, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN), 'COMPANY_BANK_CITY' => array('GROUP' => 'COMPANY', 'SORT' => 600, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN), 'COMPANY_BANK_ACCOUNT' => array('GROUP' => 'COMPANY', 'SORT' => 700, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN), 'COMPANY_BANK_CORR_ACCOUNT' => array('GROUP' => 'COMPANY', 'SORT' => 800, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN), 'CLIENT_NAME' => array('GROUP' => 'CLIENT', 'SORT' => 100, 'DOMAIN' => BusinessValue::INDIVIDUAL_DOMAIN)))));
 }
Пример #2
0
	<tr>
		<td colspan="2" id="paysystem-business-value-settings" style="padding-top: 10px">
			<?php 
if ($request->get('ACTION_FILE') !== null) {
    $data = PaySystem\Manager::getHandlerDescription($request->get('ACTION_FILE'));
    if ($id > 0) {
        $consumer = 'PAYSYSTEM_' . $id;
        try {
            BusinessValue::changeConsumer($consumer, $data);
        } catch (SystemException $e) {
            BusinessValue::addConsumer('PAYSYSTEM_' . $id, $data);
        }
    } else {
        $consumer = 'PAYSYSTEM_NEW';
        if ($data) {
            BusinessValue::addConsumer($consumer, $data);
        }
    }
    $businessValueControl->renderMap(array('CONSUMER_KEY' => $consumer));
} elseif ($id > 0) {
    $businessValueControl->renderMap(array('CONSUMER_KEY' => 'PAYSYSTEM_' . $id));
}
?>
		</td>
	</tr>
	<tbody id="pay_system_tariff">
		<?php 
$actionFile = $request->get('ACTION_FILE') ? $request->get('ACTION_FILE') : $paySystem['ACTION_FILE'];
$tariffBlock = '';
$tariff = PaySystem\Manager::getTariff($actionFile, $paySystem['ID']);
if ($tariff) {
Пример #3
0
 static function testInstall()
 {
     var_dump(\Bitrix\Sale\BusinessValue::install('BASIC', null, array('PERSON_DOMAIN' => array(1 => BusinessValue::INDIVIDUAL_DOMAIN, 2 => BusinessValue::ENTITY_DOMAIN), 'GROUPS' => array('BASIC' => array('SORT' => 0)), 'CODES' => array('BASIC_COMMON' => array('GROUP' => 'BASIC', 'SORT' => 0, 'DOMAIN' => BusinessValue::COMMON_DOMAIN), 'BASIC_INDIVIDUAL' => array('GROUP' => 'BASIC', 'SORT' => 0, 'DOMAIN' => BusinessValue::INDIVIDUAL_DOMAIN), 'BASIC_ENTITY' => array('GROUP' => 'BASIC', 'SORT' => 0, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN)))));
     var_dump(\Bitrix\Sale\BusinessValue::install('OTHER', null, array('PERSON_DOMAIN' => array(1 => BusinessValue::INDIVIDUAL_DOMAIN, 2 => BusinessValue::ENTITY_DOMAIN), 'GROUPS' => array('OTHER' => array('SORT' => 1)), 'CODES' => array('OTHER_COMMON' => array('GROUP' => 'OTHER', 'SORT' => 0, 'DOMAIN' => BusinessValue::COMMON_DOMAIN, 'MAP' => array(BusinessValue::COMMON_PERSON_ID => array('VALUE', 'other common value'), 1 => array('VALUE', 'other individual value'), 2 => array('VALUE', 'other entity value'))), 'OTHER_COMMON_ALL' => array('GROUP' => 'OTHER', 'SORT' => 0, 'DOMAIN' => BusinessValue::COMMON_DOMAIN, 'MAP' => array(BusinessValue::COMMON_PERSON_ID => array('VALUE', 'other common all'))), 'OTHER_INDIVIDUAL' => array('GROUP' => 'OTHER', 'SORT' => 0, 'DOMAIN' => BusinessValue::INDIVIDUAL_DOMAIN, 'MAP' => array(1 => array('PROPERTY', 1))), 'OTHER_ENTITY' => array('GROUP' => 'OTHER', 'SORT' => 0, 'DOMAIN' => BusinessValue::ENTITY_DOMAIN, 'MAP' => array(2 => array('PROPERTY', 8)))))));
     var_dump(\Bitrix\Sale\BusinessValue::install('COMMON', null, array('PERSON_DOMAIN' => array(1 => BusinessValue::INDIVIDUAL_DOMAIN, 2 => BusinessValue::ENTITY_DOMAIN), 'GROUPS' => array('COMMON' => array('SORT' => 2)), 'CODES' => array('BASIC_COMMON' => array('GROUP' => 'COMMON', 'SORT' => 0, 'DOMAIN' => BusinessValue::COMMON_DOMAIN), 'OTHER_COMMON' => array('GROUP' => 'COMMON', 'SORT' => 0, 'DOMAIN' => BusinessValue::COMMON_DOMAIN), 'OTHER_COMMON_ALL' => array('GROUP' => 'COMMON', 'SORT' => 0, 'DOMAIN' => BusinessValue::COMMON_DOMAIN)))));
 }
Пример #4
0
				CSaleOrderPropsVariant::Add($val);
			}
		}

		// add business value mapping to property
		$businessValueCodes[key($businessValueCodes)]['MAP'] = array($prop['PERSON_TYPE_ID'] => array('PROPERTY', $id));
		next($businessValueCodes);
	}

	// Install Business Values

	if (version_compare($saleVersion, '15.0.0', '>='))
	{
		BusinessValue::install('ESHOP', null, array(
			'PERSON_DOMAIN' => $businessValuePersonDomain,
			'GROUPS'        => $businessValueGroups,
			'CODES'         => $businessValueCodes,
		));
	}

/*
	$propReplace = "";
	foreach($arGeneralInfo["properies"] as $key => $val)
	{
		if(IntVal($val["LOCATION"]["ID"]) > 0)
			$propReplace .= '"PROP_'.$key.'" => Array(0 => "'.$val["LOCATION"]["ID"].'"), ';
	}
	WizardServices::ReplaceMacrosRecursive(WIZARD_SITE_PATH."personal/order/", Array("PROPS" => $propReplace));
*/
	//1C export
	if($personType["fiz"] == "Y" && !$fizExist)
Пример #5
0
 public function getBusinessValue($mapping)
 {
     $value = null;
     if (is_array($mapping) && isset($mapping['PROVIDER_NAME'], $mapping['PROVIDER_FIELD'])) {
         switch ($mapping['PROVIDER_NAME']) {
             case 'SHIPMENT':
                 $value = $this->getField($mapping['PROVIDER_FIELD']);
                 break;
             case 'COMPANY':
                 if ($companyId = $this->getField('COMPANY_ID')) {
                     if (substr($mapping['PROVIDER_FIELD'], 0, 3) == 'UF_') {
                         global $USER_FIELD_MANAGER;
                         $value = $USER_FIELD_MANAGER->GetUserFieldValue(Internals\CompanyTable::getUfId(), $mapping['PROVIDER_FIELD'], $companyId) ?: null;
                     } elseif ($company = Internals\CompanyTable::getById($companyId)->fetch()) {
                         $value = $company[$mapping['PROVIDER_FIELD']];
                     }
                 }
                 break;
             default:
                 /** @var ShipmentCollection $collection */
                 $value = ($collection = $this->getCollection()) && ($order = $collection->getOrder()) ? $order->getBusinessValue($mapping) : BusinessValue::getValueFromMapping($mapping);
         }
     }
     return $value;
 }
    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 '';
    }
Пример #7
0
 /** @deprecated */
 public static function migrateToBusinessValues()
 {
     $allPersonTypes = BusinessValue::getPersonTypes(true);
     Bitrix\Main\Application::getConnection()->query('DELETE FROM b_sale_bizval_code_1C');
     $result = Bitrix\Main\Application::getConnection()->query('SELECT * FROM b_sale_export');
     while ($row = $result->fetch()) {
         if (!(($map1C = unserialize($row['VARS'])) && is_array($map1C))) {
             continue;
         }
         $personTypeId = $row['PERSON_TYPE_ID'];
         $domain = $map1C['IS_FIZ'] === 'Y' ? BusinessValue::INDIVIDUAL_DOMAIN : BusinessValue::ENTITY_DOMAIN;
         unset($map1C['IS_FIZ']);
         if (!isset($allPersonTypes[$personTypeId])) {
             self::logError($row['ID'], 'Undefined person type "' . $personTypeId . '"');
             continue;
         } elseif (isset($allPersonTypes[$personTypeId]['DOMAIN'])) {
             if ($allPersonTypes[$personTypeId]['DOMAIN'] !== $domain) {
                 self::logError($row['ID'], 'Person type "' . $personTypeId . '" domain is "' . $allPersonTypes[$personTypeId]['DOMAIN'] . '", but in 1C is "' . $domain . '"');
                 continue;
             }
         } else {
             $r = Bitrix\Sale\Internals\BusinessValuePersonDomainTable::add(array('PERSON_TYPE_ID' => $personTypeId, 'DOMAIN' => $domain));
             if ($r->isSuccess()) {
                 $allPersonTypes[$personTypeId]['DOMAIN'] = $domain;
                 BusinessValue::getPersonTypes(true, $allPersonTypes);
             } else {
                 self::logError($row['ID'], 'Unable to set person type "' . $personTypeId . '" domain', $r);
                 continue;
             }
         }
         self::setMap($personTypeId, $map1C, 'Migrate:' . $personTypeId . ':' . $row['ID']);
     }
 }
Пример #8
0
 /**
  * @param \Bitrix\Sale\Order $order
  * @param $arOrder
  * @param $agentParams
  * @param $bExportFromCrm
  * @param $bCrmModuleIncluded
  * @param $paySystems
  * @param $delivery
  * @param array $options
  *
  * @return array|void
  */
 function getSaleProperties(Bitrix\Sale\Order $order, $arOrder, $agentParams, $bExportFromCrm, $bCrmModuleIncluded, $paySystems, $delivery, array $options = array())
 {
     $providersInstance = self::getProvidersInstanceByOrder($order);
     $personTypeId = $order->getPersonTypeId();
     $personTypes = BusinessValue::getPersonTypes();
     if (!($personType = $personTypes[$personTypeId])) {
         self::logError($order->getId(), 'Undefined DOMAIN for person type id "' . $personTypeId . '"');
         return;
     }
     $systemCodes1C = array_flip(self::$systemCodes[$personType['DOMAIN']]);
     $arProp = array();
     $arProp["ORDER"] = $arOrder;
     if (IntVal($arOrder["USER_ID"]) > 0) {
         $dbUser = CUser::GetByID($arOrder["USER_ID"]);
         if ($arUser = $dbUser->Fetch()) {
             $arProp["USER"] = $arUser;
         }
     }
     if ($bExportFromCrm) {
         $arProp["CRM"] = array();
         $companyID = isset($arOrder["UF_COMPANY_ID"]) ? intval($arOrder["UF_COMPANY_ID"]) : 0;
         $contactID = isset($arOrder["UF_CONTACT_ID"]) ? intval($arOrder["UF_CONTACT_ID"]) : 0;
         if ($companyID > 0) {
             $arProp["CRM"]["CLIENT_ID"] = "CRMCO" . $companyID;
         } else {
             $arProp["CRM"]["CLIENT_ID"] = "CRMC" . $contactID;
         }
         $clientInfo = array("LOGIN" => "", "NAME" => "", "LAST_NAME" => "", "SECOND_NAME" => "");
         if ($bCrmModuleIncluded) {
             if ($companyID > 0) {
                 $arCompanyFilter = array('=ID' => $companyID);
                 $dbCompany = CCrmCompany::GetListEx(array(), $arCompanyFilter, false, array("nTopCount" => 1), array("TITLE"));
                 $arCompany = $dbCompany->Fetch();
                 unset($dbCompany, $arCompanyFilter);
                 if (is_array($arCompany)) {
                     if (isset($arCompany["TITLE"])) {
                         $clientInfo["NAME"] = $arCompany["TITLE"];
                     }
                 }
                 unset($arCompany);
             } else {
                 if ($contactID > 0) {
                     $arContactFilter = array('=ID' => $contactID);
                     $dbContact = CCrmContact::GetListEx(array(), $arContactFilter, false, array("nTopCount" => 1), array("NAME", "LAST_NAME", "SECOND_NAME"));
                     $arContact = $dbContact->Fetch();
                     unset($dbContact, $arContactFilter);
                     if (is_array($arContact)) {
                         if (isset($arContact["NAME"])) {
                             $clientInfo["NAME"] = $arContact["NAME"];
                         }
                         if (isset($arContact["LAST_NAME"])) {
                             $clientInfo["LAST_NAME"] = $arContact["LAST_NAME"];
                         }
                         if (isset($arContact["SECOND_NAME"])) {
                             $clientInfo["SECOND_NAME"] = $arContact["SECOND_NAME"];
                         }
                     }
                     unset($arContact);
                 }
             }
         }
         $arProp["CRM"]["CLIENT"] = $clientInfo;
         unset($clientInfo);
     }
     if (IntVal($arOrder["PAY_SYSTEM_ID"]) > 0) {
         $arProp["ORDER"]["PAY_SYSTEM_NAME"] = $paySystems[$arOrder["PAY_SYSTEM_ID"]];
     }
     if (strlen($arOrder["DELIVERY_ID"]) > 0) {
         $arProp["ORDER"]["DELIVERY_NAME"] = $delivery[$arOrder["DELIVERY_ID"]];
     }
     $dbOrderPropVals = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $arOrder["ID"]), false, false, array("ID", "CODE", "VALUE", "ORDER_PROPS_ID", "PROP_TYPE"));
     $locationStreetPropertyValue = '';
     while ($arOrderPropVals = $dbOrderPropVals->Fetch()) {
         if ($arOrderPropVals["PROP_TYPE"] == "CHECKBOX") {
             if ($arOrderPropVals["VALUE"] == "Y") {
                 $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = "true";
             } else {
                 $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = "false";
             }
         } elseif ($arOrderPropVals["PROP_TYPE"] == "TEXT" || $arOrderPropVals["PROP_TYPE"] == "TEXTAREA") {
             $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = $arOrderPropVals["VALUE"];
         } elseif ($arOrderPropVals["PROP_TYPE"] == "SELECT" || $arOrderPropVals["PROP_TYPE"] == "RADIO") {
             $arVal = CSaleOrderPropsVariant::GetByValue($arOrderPropVals["ORDER_PROPS_ID"], $arOrderPropVals["VALUE"]);
             $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = $arVal["NAME"];
         } elseif ($arOrderPropVals["PROP_TYPE"] == "MULTISELECT") {
             $curVal = explode(",", $arOrderPropVals["VALUE"]);
             foreach ($curVal as $vm) {
                 $arVal = CSaleOrderPropsVariant::GetByValue($arOrderPropVals["ORDER_PROPS_ID"], $vm);
                 $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] .= ", " . $arVal["NAME"];
             }
             $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = substr($arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]], 2);
         } elseif ($arOrderPropVals["PROP_TYPE"] == "LOCATION") {
             $arVal = CSaleLocation::GetByID($arOrderPropVals["VALUE"], LANGUAGE_ID);
             if (CSaleLocation::isLocationProEnabled()) {
                 if (intval($arVal['ID'])) {
                     try {
                         $res = \Bitrix\Sale\Location\LocationTable::getPathToNode($arVal['ID'], array('select' => array('LNAME' => 'NAME.NAME', 'TYPE_ID'), 'filter' => array('=NAME.LANGUAGE_ID' => LANGUAGE_ID)));
                         $types = \Bitrix\Sale\Location\Admin\TypeHelper::getTypeCodeIdMapCached();
                         $path = array();
                         while ($item = $res->fetch()) {
                             // copy street to STREET property
                             if ($types['ID2CODE'][$item['TYPE_ID']] == 'STREET') {
                                 $locationStreetPropertyValue = $item['LNAME'];
                             }
                             $path[] = $item['LNAME'];
                         }
                         $locationString = implode(' - ', $path);
                     } catch (\Bitrix\Main\SystemException $e) {
                         $locationString = '';
                     }
                 } else {
                     $locationString = '';
                 }
             } else {
                 $locationString = $arVal["COUNTRY_NAME"] . (strlen($arVal["COUNTRY_NAME"]) <= 0 || strlen($arVal["REGION_NAME"]) <= 0 ? "" : " - ") . $arVal["REGION_NAME"] . (strlen($arVal["COUNTRY_NAME"]) <= 0 || strlen($arVal["CITY_NAME"]) <= 0 ? "" : " - ") . $arVal["CITY_NAME"];
             }
             $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = $locationString;
             $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"] . "_CITY"] = $arVal["CITY_NAME"];
             $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"] . "_COUNTRY"] = $arVal["COUNTRY_NAME"];
             $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"] . "_REGION"] = $arVal["REGION_NAME"];
         } else {
             $arProp["PROPERTY"][$arOrderPropVals["ORDER_PROPS_ID"]] = $arOrderPropVals["VALUE"];
         }
     }
     foreach ($agentParams as $k => $v) {
         if (strpos($k, "REKV_") !== false) {
             //params
             if (!is_array($v)) {
                 $agent["REKV"][$k] = $v;
             } else {
                 if (strlen($v["TYPE"]) <= 0) {
                     $agent["REKV"][$k] = $v["VALUE"];
                 } else {
                     switch ($v["TYPE"]) {
                         case 'CRM':
                             $agent["REKV"][$k] = $arProp[$v["TYPE"]][$v["VALUE"]];
                             //value
                             break;
                         default:
                             if (!($codeKey = $systemCodes1C[$k]) && substr($k, 0, 5) === 'REKV_' && ($codeIndex = substr($k, 5)) !== '' && ($codeKey = BusinessValueConsumer1C::getRekvCodeKey($order->getPersonTypeId(), $codeIndex)) && ($providerInstance = $providersInstance[$order->getId()][$v["TYPE"]]) && is_set($providerInstance)) {
                                 $agent["REKV"][$k] = Bitrix\Sale\BusinessValue::getValueFromProvider($providerInstance, $codeKey, BusinessValueConsumer1C::CONSUMER_KEY);
                             }
                     }
                 }
             }
         } else {
             if (!is_array($v)) {
                 $agent[$k] = $v;
             } else {
                 if (strlen($v["TYPE"]) <= 0) {
                     $agent[$k] = $v["VALUE"];
                 } else {
                     switch ($v["TYPE"]) {
                         case 'CRM':
                             $agent[$k] = $arProp[$v["TYPE"]][$v["VALUE"]];
                             break;
                         default:
                             if (($codeKey = $systemCodes1C[$k]) && ($providerInstance = $providersInstance[$order->getId()][$v["TYPE"]]) && is_set($providerInstance)) {
                                 $agent[$k] = Bitrix\Sale\BusinessValue::getValueFromProvider($providerInstance, $codeKey, BusinessValueConsumer1C::CONSUMER_KEY);
                             }
                     }
                 }
                 if ($k == 'STREET' && strlen($locationStreetPropertyValue)) {
                     $agent[$k] = $locationStreetPropertyValue . (strlen($agent[$k]) ? ', ' : '') . $agent[$k];
                 }
             }
         }
     }
     return array('agent' => $agent, 'arProp' => $arProp);
 }