1
0
mirror of synced 2025-01-19 17:31:43 +03:00

Merge pull request #9 from ghostrainman/master

v.1.1.3
This commit is contained in:
Alex Lushpai 2015-11-10 10:45:45 +03:00
commit 2380ce6108
15 changed files with 813 additions and 117 deletions

View File

@ -1,3 +1,11 @@
## 2015-11-09 v.1.1.3
* Добавлено логгирование в файл для приходящей из црм и уходящей в црм информации
* Изменен механизм добавления товара в заказ
* Возможность добавить товар в заказ, который есть в црм, но нет на сайте
* Изменил логику выбора товаров для выгрузки в xml
* Появилась возможность перевести History на триггер
* Исправлены ошибки
## 2015-05-18 v.1.1.2
* Добавлена возможность изменять файлы основных классов(ICMLLoader и ICrmOrderActions) и экспорт каталога без потери обновлений
* Исправлены мелкие ошибки

View File

@ -54,9 +54,10 @@ else{
public function Load()
{
global $USER;
if(!isset($_SESSION["SESS_AUTH"]["USER_ID"]) || !$_SESSION["SESS_AUTH"]["USER_ID"])
if(!isset($_SESSION["SESS_AUTH"]["USER_ID"]) || !$_SESSION["SESS_AUTH"]["USER_ID"]){
$USER = new CUser;
}
$this->isLogged = true;
$defaultSite = CSite::GetList($by="def", $order="desc", Array())->Fetch();
@ -282,8 +283,7 @@ else{
// Set filter
$filter = array(
"IBLOCK_ID" => $id,
"INCLUDE_SUBSECTIONS" => "Y",
"IBLOCK_ID" => $id
);
$order = array("id");
$arNavStatParams = Array(
@ -294,7 +294,18 @@ else{
// Cycle page to page
do {
// Get products on this page
$dbResProducts = CIBlockElement::GetList($order, $filter, false, $arNavStatParams, $arSelect);
$elems = array();
$dbResProductsIds = CIBlockElement::GetList($order, $filter, false, $arNavStatParams, array('ID'));
while($obIds = $dbResProductsIds->Fetch())
{
$elems[] = $obIds['ID'];
}
$arfilter = array(
"IBLOCK_ID" => $id,
"ID" => $elems
);
$dbResProducts = CIBlockElement::GetList($order, $arfilter, false, false, $arSelect);
$pictures = array();
$products = array();
@ -366,14 +377,15 @@ else{
$resPropertiesProduct[$key] = "";
if ($propProduct != "") {
if (isset($product["PROPERTY_" . $propProduct . "_NAME"]))
if (isset($product["PROPERTY_" . $propProduct . "_NAME"])){
$resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_NAME"];
elseif (isset($product["PROPERTY_" . $propProduct . "_VALUE"]))
}
elseif (isset($product["PROPERTY_" . $propProduct . "_VALUE"])){
$resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_VALUE"];
elseif (isset($product[$propProduct]))
}
elseif (isset($product[$propProduct])){
$resPropertiesProduct[$key] = $product[$propProduct];
}
if (array_key_exists($key, $this->propertiesUnitProduct[$id])) {
$resPropertiesProduct[$key] *= $this->measurement[$this->propertiesUnitProduct[$id][$key]];
$resPropertiesProduct[$key . "_UNIT"] = $this->measurementLink[$this->propertiesUnitProduct[$id][$key]];
@ -391,7 +403,6 @@ else{
);
}
if (count($categories) == 0) {
$catId = $this->mainSection + $id;
$categories[$catId] = $allCategories[$catId];
}
@ -401,8 +412,6 @@ else{
if (!empty($iblockOffer['IBLOCK_ID'])) {
foreach ($product['offers'] as $offer) {
$offer['PRODUCT_ID'] = $product["ID"];
$offer['DETAIL_PAGE_URL'] = $product["DETAIL_PAGE_URL"];
$offer['PICTURE'] = $product["PICTURE"];
@ -413,29 +422,28 @@ else{
$offer['QUANTITY'] = $offer["CATALOG_QUANTITY"];
// Get properties of product
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
if ($propSKU != "") {
if (isset ($offer["PROPERTY_" . $propSKU . "_NAME"]))
if (isset ($offer["PROPERTY_" . $propSKU . "_NAME"])){
$offer['_PROP_' . $key] = $offer["PROPERTY_" . $propSKU . "_NAME"];
elseif (isset($offer["PROPERTY_" . $propSKU . "_VALUE"]))
}
elseif (isset($offer["PROPERTY_" . $propSKU . "_VALUE"])){
$offer['_PROP_' . $key] = $offer["PROPERTY_" . $propSKU . "_VALUE"];
elseif (isset($offer[$propSKU]))
}
elseif (isset($offer[$propSKU])){
$offer['_PROP_' . $key] = $offer[$propSKU];
}
if (array_key_exists($key, $this->propertiesUnitSKU[$id])) {
$offer['_PROP_' . $key] *= $this->measurement[$this->propertiesUnitSKU[$id][$key]];
$offer['_PROP_' . $key . "_UNIT"] = $this->measurementLink[$this->propertiesUnitSKU[$id][$key]];
}
}
}
foreach ($resPropertiesProduct as $key => $propProduct) {
if ($this->propertiesProduct[$id][$key] != "" && !isset($offer[$key]))
if ($this->propertiesProduct[$id][$key] != "" && !isset($offer[$key])){
$offer['_PROP_' . $key] = $propProduct;
}
}
$stringOffers .= $this->BuildOffer($offer, $categories, $iblock, $allCategories);
@ -463,16 +471,17 @@ else{
}
unset($products);
if ($this->isLogged)
if ($this->isLogged){
$this->WriteLog(($this->pageSize * $arNavStatParams['iNumPage']) . " product(s) has been loaded from " . $id . " IB (memory usage: " . memory_get_usage() . ")");
}
if ($stringOffers != "") {
$this->WriteOffers($stringOffers);
$stringOffers = "";
}
$arNavStatParams['iNumPage'] = $dbResProducts->NavPageNomer + 1;
$arNavStatParams['iNumPage'] = $dbResProductsIds->NavPageNomer + 1;
}
while ($dbResProducts->NavPageNomer < $dbResProducts->NavPageCount);
while ($dbResProductsIds->NavPageNomer < $dbResProductsIds->NavPageCount);
}
}
@ -484,9 +493,10 @@ else{
"productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ".
"quantity=\"" . $this->PrepareValue(DoubleVal($arOffer['QUANTITY'])) . "\">\n";
if ($arOffer['PRODUCT_ACTIVE'] == "N")
if ($arOffer['PRODUCT_ACTIVE'] == "N"){
$offer .= "<productActivity>" . $this->PrepareValue($arOffer['PRODUCT_ACTIVE']) . "</productActivity>\n";
}
$keys = array_keys($categories);
if (strpos($arOffer['DETAIL_PAGE_URL'], "#SECTION_PATH#") !== false) {
if (count($categories) != 0) {
@ -514,9 +524,10 @@ else{
if ($arOffer['PURCHASE_PRICE'] && $this->loadPurchasePrice) {
$offer .= "<purchasePrice>" . $this->PrepareValue($arOffer['PURCHASE_PRICE']) . "</purchasePrice>\n";
}
foreach ($categories as $category)
foreach ($categories as $category){
$offer .= "<categoryId>" . $category['ID'] . "</categoryId>\n";
}
$offer .= "<name>" . $this->PrepareValue($arOffer["NAME"]) . "</name>\n";
$offer .= "<xmlId>" . $this->PrepareValue($arOffer["EXTERNAL_ID"]) . "</xmlId>\n";
@ -524,18 +535,22 @@ else{
foreach ($this->propertiesProduct[$iblock['IBLOCK_DB']['ID']] as $key => $propProduct) {
if ($propProduct != "" && $arOffer['_PROP_' . $key] != null) {
if ($key === "manufacturer")
if ($key === "manufacturer"){
$offer .= "<vendor>" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</vendor>\n";
else
}
else{
$offer .= '<param name="' . $key . '"' . (isset($arOffer['_PROP_' . $key . "_UNIT"]) ? ' unit="' . $arOffer['_PROP_' . $key . "_UNIT"] . '"' : "") . ">" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</param>\n";
}
}
}
foreach ($this->propertiesSKU[$iblock['IBLOCK_DB']['ID']] as $key => $propProduct) {
if ($propProduct != "" && $arOffer['_PROP_' . $key] != null) {
if ($key === "manufacturer")
if ($key === "manufacturer"){
$offer .= "<vendor>" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</vendor>\n";
else
}
else{
$offer .= '<param name="' . $key . '"' . (isset($arOffer['_PROP_' . $key . "_UNIT"]) ? ' unit="' . $arOffer['_PROP_' . $key . "_UNIT"] . '"' : "") . ">" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</param>\n";
}
}
}

View File

@ -22,7 +22,8 @@ else{
protected static $CRM_CONTRAGENT_TYPE = 'contragent_type';
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
protected static $CRM_ORDER_HISTORY_DATE = 'order_history_date';
protected static $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
/**
@ -168,7 +169,7 @@ else{
}
$normalizer = new RestNormalizer();
$normalizer->setValidation(__DIR__ . '/config/retailcrm.json');
$normalizer->setValidation($_SERVER["DOCUMENT_ROOT"].'/bitrix/modules/intaro.intarocrm/classes/general/config/retailcrm.json');
$customer = array();
@ -309,7 +310,11 @@ else{
array_key_exists($arFields['LID'], $arParams['optionsSitesList'])) {
$site = $arParams['optionsSitesList'][$arFields['LID']];
}
$log = new Logger();
$log->write($customer, 'customer');
$log->write($order, 'order');
if($send) {
if (!self::apiMethod($api, 'customerEdit', __METHOD__, $customer, $site)) {
return false;
@ -403,7 +408,10 @@ else{
}
$orderHistory = isset($orderHistory['orders']) ? $orderHistory['orders'] : array();
$log = new Logger();
$log->write($orderHistory, 'history');
$dateFinish = $api->getGeneratedAt();
if (is_null($dateFinish) || $dateFinish == false) {
$dateFinish = new \DateTime();
@ -442,7 +450,7 @@ else{
$registerNewUser = true;
if (!isset($order['customer']['email'])) {
if (!isset($order['customer']['email']) || $order['customer']['email'] == '') {
$login = $order['customer']['email'] = uniqid('user_' . time()) . '@crm.com';
} else {
$dbUser = CUser::GetList(($by = 'ID'), ($sort = 'ASC'), array('=EMAIL' => $order['email']));
@ -621,95 +629,234 @@ else{
foreach($order['items'] as $item) {
if(isset($item['deleted']) && $item['deleted']) {
if ($p = CSaleBasket::GetList(array(), array('ORDER_ID' => $order['externalId'], 'PRODUCT_ID' => $item['id']))->Fetch()) {
CSaleBasket::Delete($p['ID']);
if(!CSaleBasket::Delete($p['ID'])){
self::eventLog('ICrmOrderActions::orderHistory', 'CSaleBasket::Delete', 'Error element delete');
}
}
else{
$prp = CSaleBasket::GetPropsList(array(), array("ORDER_ID" => $order['externalId'], "CODE" => 'ID', "VALUE" => $item['id']))->Fetch();
if(!CSaleBasket::Delete($prp['BASKET_ID'])){
self::eventLog('ICrmOrderActions::orderHistory', 'CSaleBasket::Delete', 'Error castom element delete');
}
}
continue;
}
if (isset($item['offer']) === false && isset($item['offer']['externalId']) === false) {
continue;
}
$res = CIBlockElement::GetByID($item['offer']['externalId'])->Fetch();
$p = CSaleBasket::GetList(array(),array('ORDER_ID' => $order['externalId'], 'PRODUCT_ID' => $item['offer']['externalId']))->Fetch();
if($res){
$p = CSaleBasket::GetList(array(),array('ORDER_ID' => $order['externalId'], 'PRODUCT_ID' => $item['offer']['externalId']))->Fetch();
if ($p == false) {
$p = CIBlockElement::GetByID($item['offer']['externalId'])->Fetch();
$iblock = CIBlock::GetByID($p['IBLOCK_ID'])->Fetch();
$p['CATALOG_XML_ID'] = $iblock['XML_ID'];
$p['PRODUCT_XML_ID'] = $p['XML_ID'];
unset($p['XML_ID']);
} elseif ($propResult = CSaleBasket::GetPropsList(array(''),array('BASKET_ID' => $p['ID']))) {
while ($r = $propResult->Fetch()) {
$p['PROPS'][] = $r;
if ($p == false) {
$p = CIBlockElement::GetByID($item['offer']['externalId'])->GetNext();
$iblock = CIBlock::GetByID($p['IBLOCK_ID'])->Fetch();
$p['CATALOG_XML_ID'] = $iblock['XML_ID'];
$p['PRODUCT_XML_ID'] = $p['XML_ID'];
unset($p['XML_ID']);
} elseif ($propResult = CSaleBasket::GetPropsList(array(''),array('BASKET_ID' => $p['ID']))) {
while ($r = $propResult->Fetch()) {
unset($r['ID']);
unset($r['BASKET_ID']);
$p['PROPS'][] = $r;
}
}
}
$arProduct = array();
$arProduct = array();
if (isset($item['created']) && $item['created'] == true) {
$productPrice = GetCatalogProductPrice($item['offer']['externalId'], COption::GetOptionString(self::$MODULE_ID, self::$CRM_CATALOG_BASE_PRICE, 0));
$arProduct = array(
'FUSER_ID' => $userId,
'ORDER_ID' => $order['externalId'],
'QUANTITY' => $item['quantity'],
'CURRENCY' => $productPrice['CURRENCY'],
'LID' => $LID,
'PRODUCT_ID' => $item['offer']['externalId'],
'PRODUCT_PRICE_ID' => $p['PRODUCT_PRICE_ID'],
'WEIGHT' => $p['WEIGHT'],
'DELAY' => $p['DELAY'],
'CAN_BUY' => $p['CAN_BUY'],
'MODULE' => $p['MODULE'],
'NOTES' => $item['comment'] ?: $p['NOTES'],
'PRODUCT_PROVIDER_CLASS' => $p['PRODUCT_PROVIDER_CLASS'],
'DETAIL_PAGE_URL' => $p['DETAIL_PAGE_URL'],
'CATALOG_XML_ID' => $p['CATALOG_XML_ID'],
'PRODUCT_XML_ID' => $p['PRODUCT_XML_ID'],
'CUSTOM_PRICE' => 'Y'
);
}
if (isset($item['isCanceled']) == false) {
if (isset($item['initialPrice']) && $item['initialPrice']) {
$arProduct['PRICE'] = (double) $item['initialPrice'];
}
if (isset($item['discount'])) {
$arProduct['DISCOUNT_PRICE'] = $item['discount'];
}
if (isset($item['discountPercent'])) {
$arProduct['DISCOUNT_VALUE'] = $item['discountPercent'];
$newPrice = round($arProduct['PRICE'] / 100 * (100 - $arProduct['DISCOUNT_VALUE']), 2);
$arProduct['DISCOUNT_PRICE'] = $arProduct['DISCOUNT_PRICE'] + $arProduct['PRICE'] - $newPrice;
}
if(isset($item['discount']) || isset($item['discountPercent'])) {
$arProduct['PRICE'] -= $arProduct['DISCOUNT_PRICE'];
}
if (isset($item['offer']['name']) && $item['offer']['name']) {
$arProduct['NAME'] = self::fromJSON($item['offer']['name']);
}
$arProduct = self::updateCancelProp($arProduct, 0);
} elseif (isset($item['isCanceled'])) {
$arProduct['PRICE'] = 0;
$arProduct = self::updateCancelProp($arProduct, 1);
}
if (isset($item['created']) && $item['created'] == true) {
$productPrice = GetCatalogProductPrice($item['offer']['externalId'], 1);
$arProduct = array(
'FUSER_ID' => $userId,
'ORDER_ID' => $order['externalId'],
'QUANTITY' => $item['quantity'],
'CURRENCY' => $productPrice['CURRENCY'],
'LID' => $LID,
'PRODUCT_ID' => $item['offer']['externalId'],
'PRODUCT_PRICE_ID' => $p['PRODUCT_PRICE_ID'],
'WEIGHT' => $p['WEIGHT'],
'DELAY' => $p['DELAY'],
'CAN_BUY' => $p['CAN_BUY'],
'MODULE' => $p['MODULE'],
'NOTES' => $item['comment'] ?: $p['NOTES'],
'PRODUCT_PROVIDER_CLASS' => $p['PRODUCT_PROVIDER_CLASS'],
'DETAIL_PAGE_URL' => $p['DETAIL_PAGE_URL'],
'CATALOG_XML_ID' => $p['CATALOG_XML_ID'],
'PRODUCT_XML_ID' => $p['PRODUCT_XML_ID'],
'CUSTOM_PRICE' => 'Y'
);
}
if (isset($item['created']) && $item['created'] == true) {
if(!Add2BasketByProductID($item['offer']['externalId'], $item['quantity'], $arProduct, $p['PROPS'])){
self::eventLog('ICrmOrderActions::orderHistory', 'Add2BasketByProductID', 'Error element add');
}
continue;
}
if (isset($item['isCanceled']) == false) {
if (isset($item['initialPrice']) && $item['initialPrice']) {
$arProduct['PRICE'] = (double) $item['initialPrice'];
if (count($p['PROPS']) > 0) {
$arProduct['PROPS'] = $p['PROPS'];
}
if (isset($item['discount'])) {
$arProduct['DISCOUNT_PRICE'] = $item['discount'];
}
if (isset($item['discountPercent'])) {
$arProduct['DISCOUNT_VALUE'] = $item['discountPercent'];
$newPrice = round($arProduct['PRICE'] / 100 * (100 - $arProduct['DISCOUNT_VALUE']), 2);
$arProduct['DISCOUNT_PRICE'] = $arProduct['DISCOUNT_PRICE'] + $arProduct['PRICE'] - $newPrice;
}
if(isset($item['discount']) || isset($item['discountPercent'])) {
$arProduct['PRICE'] -= $arProduct['DISCOUNT_PRICE'];
if (isset($item['quantity']) && $item['quantity']) {
$arProduct['QUANTITY'] = $item['quantity'];
}
if (isset($item['offer']['name']) && $item['offer']['name']) {
$arProduct['NAME'] = self::fromJSON($item['offer']['name']);
}
$arProduct = self::updateCancelProp($arProduct, 0);
} elseif (isset($item['isCanceled'])) {
$arProduct['PRICE'] = 0;
$arProduct = self::updateCancelProp($arProduct, 1);
}
if (isset($item['created']) && $item['created'] == true) {
CSaleBasket::Add($arProduct);
continue;
if(!CSaleBasket::Update($p['ID'], $arProduct)){
self::eventLog('ICrmOrderActions::orderHistory', 'CSaleBasket::Update', 'Error element update');
}
CSaleBasket::DeleteAll($userId);
}
else{
$arProduct = array();
if (isset($item['created']) && $item['created'] == true) {
$arProduct = array(
'FUSER_ID' => $userId,
'ORDER_ID' => $order['externalId'],
'LID' => $LID,
'NOTES' => $item['comment'],
);
}
if (isset($item['isCanceled']) == false) {
if (isset($item['initialPrice']) && $item['initialPrice']) {
$arProduct['PRICE'] = (double) $item['initialPrice'];
}
if (isset($item['discount'])) {
$arProduct['DISCOUNT_PRICE'] = $item['discount'];
}
if (isset($item['discountPercent'])) {
$arProduct['DISCOUNT_VALUE'] = $item['discountPercent'];
$newPrice = round($arProduct['PRICE'] / 100 * (100 - $arProduct['DISCOUNT_VALUE']), 2);
$arProduct['DISCOUNT_PRICE'] = $arProduct['DISCOUNT_PRICE'] + $arProduct['PRICE'] - $newPrice;
}
if(isset($item['discount']) || isset($item['discountPercent'])) {
$arProduct['PRICE'] -= $arProduct['DISCOUNT_PRICE'];
}
if (isset($item['offer']['name']) && $item['offer']['name']) {
$arProduct['NAME'] = self::fromJSON($item['offer']['name']);
}
$arProduct = self::updateCancelProp($arProduct, 0);
} elseif (isset($item['isCanceled'])) {
$arProduct['PRICE'] = 0;
$arProduct = self::updateCancelProp($arProduct, 1);
}
if (isset($item['quantity']) && $item['quantity']) {
$arProduct['QUANTITY'] = $item['quantity'];
}
if (isset($item['offer']['name']) && $item['offer']['name']) {
$arProduct['NAME'] = self::fromJSON($item['offer']['name']);
}
if (isset($item['created']) && $item['created'] == true) {
$iBlocks = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CATALOG_IBLOCKS, 0));
$iBlock = array_shift($iBlocks);
$newSection = new CIBlockSection;
$newSectionFields = Array(
"ACTIVE" => 'N',
"IBLOCK_ID" => $iBlock,
"NAME" => 'RetailCRM',
"CODE" => 'RetailCRM',
);
$resSection = $newSection->Add($newSectionFields);
if(!$resSection){
self::eventLog('ICrmOrderActions::orderHistory', 'CIBlockSection::Add', 'Error castom section add');
continue;
}
if (count($p['PROPS']) > 0) {
$arProduct['PROPS'] = $p['PROPS'];
}
if (isset($item['quantity']) && $item['quantity']) {
$arProduct['QUANTITY'] = $item['quantity'];
}
if (isset($item['offer']['name']) && $item['offer']['name']) {
$arProduct['NAME'] = self::fromJSON($item['offer']['name']);
}
$arLoadProductArray = Array(
"IBLOCK_SECTION_ID" => $resSection,
"IBLOCK_ID" => $iBlock,
"NAME" => $item['offer']['name'] ? $item['offer']['name'] : 'RetailCrmElement',
"CODE" => 'RetailCrmElement',
"ACTIVE" => 'Y'
);
$el = new CIBlockElement;
$PRODUCT_ID = $el->Add($arLoadProductArray, false, false, true);
if(!$PRODUCT_ID){
self::eventLog('ICrmOrderActions::orderHistory', 'CIBlockElement::Add', 'Error castom element add');
continue;
}
CSaleBasket::Update($p['ID'], $arProduct);
CSaleBasket::DeleteAll($userId);
if(!CCatalogProduct::Add(array("ID" => $PRODUCT_ID))){
self::eventLog('ICrmOrderActions::orderHistory', 'CCatalogProduct::Add', 'Error product add');
continue;
}
$arFields = Array(
"PRODUCT_ID" => $PRODUCT_ID,
"CATALOG_GROUP_ID" => COption::GetOptionString(self::$MODULE_ID, self::$CRM_CATALOG_BASE_PRICE, 0),
"PRICE" => $item['initialPrice'] ? $item['initialPrice'] : 1,
"CURRENCY" => CCurrency::GetBaseCurrency(),
);
if(!CPrice::Add($arFields)){
self::eventLog('ICrmOrderActions::orderHistory', 'CPrice::Add', 'Error price add');
continue;
}
$Params = array(
array(
'NAME' => 'id',
'CODE' => 'ID',
'VALUE' => $item['offer']['externalId']
)
);
if(!Add2BasketByProductID($PRODUCT_ID, $item['quantity'], $arProduct, $Params)){
self::eventLog('ICrmOrderActions::orderHistory', 'Add2BasketByProductID', 'Error add to basket');
continue;
}
if(!CIBlockSection::Delete($resSection)){
self::eventLog('ICrmOrderActions::orderHistory', 'CIBlockSection::Delete', 'Error delete section');
continue;
}
continue;
}
$prp = CSaleBasket::GetPropsList(array(), array("ORDER_ID" => $order['externalId'], "CODE" => 'ID', "VALUE" => $item['offer']['externalId']))->Fetch();
CSaleBasket::Update($prp['BASKET_ID'], $arProduct);
}
}
if (isset($order['delivery']) === false || isset($order['delivery']['cost']) === false) {

View File

@ -0,0 +1,68 @@
<?php
class Logger
{
private $logPath;
private $files;
public function __construct($logPath = '/bitrix/modules/intaro.intarocrm/classes/general/log', $files = 3)
{
$this->logPath = $logPath;
$this->files = $files;
}
public function write($dump, $file = 'info')
{
$file = $_SERVER["DOCUMENT_ROOT"] . $this->logPath . '/' . $file . '.log';
// message prefix with current time
$data['TIME'] = date('Y-m-d H:i:s');
$data['DATA'] = $dump;
//write log
$f = fopen($file, "a+");
fwrite($f, print_r($data,true));
fclose($f);
// if filesize more than 5 Mb rotate it
if (filesize($file) > 5242880) {
$this->rotate($file);
}
}
private function rotate($file)
{
$path = pathinfo($file);
$rotate = implode('', array(
$path['dirname'],
'/',
$path['filename'],
date('YmdHis'),
'.',
$path['extension']
));
copy($file, $rotate);
$this->clean($file);
$files = glob($path['dirname'] . '/' . "*" . $path['filename'] . ".log");
if (0 === $this->files) {
return;
}
if (count($files) > $this->files) {
natsort($files);
foreach (array_slice($files, $this->files) as $log) {
if (is_writable($log)) {
unlink($log);
}
}
}
}
private function clean($file)
{
file_put_contents($file, '');
}
}

View File

@ -172,7 +172,7 @@ class RestNormalizer
$formatted[ $code ] = $this->formatting($value, true);
}
if ($formatted[ $code ] === null || $formatted[ $code ] == '' || count($formatted[ $code ]) < 1) {
if ($formatted[ $code ] === null || $formatted[ $code ] === '' || count($formatted[ $code ]) < 1) {
if ($this->clear === true) {
unset($formatted[ $code ]);
}

View File

@ -272,6 +272,9 @@
"managerId": {
"type": "int"
},
"deliveryTime": {
"type": "string"
},
"paymentType": {
"type": "string"
},
@ -293,7 +296,7 @@
"quantity": {
"type": "double",
"default": 1,
"min": 1,
"min": 0,
"decimals": 1
},
"properties": {

View File

@ -250,7 +250,10 @@ class ICrmOrderEvent {
'managerComment' => $arOrder['COMMENTS']
);
}
$log = new Logger();
$log->write($order, 'order');
try {
$api->orderEdit($order);
} catch (\RetailCrm\Exception\CurlException $e) {
@ -307,7 +310,8 @@ class ICrmOrderEvent {
'paymentStatus' => $optionsPayment[$payed]
);
$api->orderEdit($order);
$log = new Logger();
$log->write($order, 'order');
try {
$api->orderEdit($order);

View File

@ -0,0 +1,2 @@
Satisfy Any
Allow from all

View File

@ -0,0 +1,435 @@
<?
$idOrderCRM = (int) $_REQUEST['idOrderCRM'];
if($idOrderCRM && $idOrderCRM > 0){
require_once($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');
if (!CModule::IncludeModule("iblock")) {
ICrmOrderActions::eventLog('ICrmOrderActions::orderHistory', 'iblock', 'module not found');
return false;
}
if (!CModule::IncludeModule("sale")) {
ICrmOrderActions::eventLog('ICrmOrderActions::orderHistory', 'sale', 'module not found');
return false;
}
if (!CModule::IncludeModule("catalog")) {
ICrmOrderActions::eventLog('ICrmOrderActions::orderHistory', 'catalog', 'module not found');
return false;
}
if (!CModule::IncludeModule("intaro.intarocrm")) {
ICrmOrderActions::eventLog('ICrmOrderActions::orderHistory', 'intaro.intarocrm', 'module not found');
return false;
}
global $USER;
if (is_object($USER) == false) {
$USER = new RetailUser;
}
$api_host = COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_API_KEY_OPTION, 0);
$optionsOrderTypes = array_flip(unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_ORDER_TYPES_ARR, 0)));
$optionsDelivTypes = array_flip(unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_DELIVERY_TYPES_ARR, 0)));
$optionsPayTypes = array_flip(unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_PAYMENT_TYPES, 0)));
$optionsPayStatuses = array_flip(unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_PAYMENT_STATUSES, 0))); // --statuses
$optionsPayment = array_flip(unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_PAYMENT, 0)));
$optionsOrderProps = unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_ORDER_PROPS, 0));
$optionsLegalDetails = unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_LEGAL_DETAILS, 0));
$optionsContragentType = unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_CONTRAGENT_TYPE, 0));
$optionsSitesList = unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_SITES_LIST, 0));
$optionsCustomFields = unserialize(COption::GetOptionString(ICrmOrderActions::$MODULE_ID, ICrmOrderActions::$CRM_CUSTOM_FIELDS, 0));
foreach ($optionsOrderProps as $code => $value) {
if (isset($optionsLegalDetails[$code])) {
$optionsOrderProps[$code] = array_merge($optionsOrderProps[$code], $optionsLegalDetails[$code]);
}
if (isset($optionsCustomFields[$code])) {
$optionsOrderProps[$code] = array_merge($optionsOrderProps[$code], $optionsCustomFields[$code]);
}
$optionsOrderProps[$code]['location'] = 'LOCATION';
if (array_search('CITY', $optionsOrderProps[$code]) == false) {
$optionsOrderProps[$code]['city'] = 'CITY';
}
if (array_search('ZIP', $optionsOrderProps[$code]) == false) {
$optionsOrderProps[$code]['index'] = 'ZIP';
}
}
$api = new RetailCrm\RestApi($api_host, $api_key);
$order = $api->orderGet($idOrderCRM, $by = 'id');
$log = new Logger();
$log->write($order, 'order');
$defaultOrderType = 1;
$dbOrderTypesList = CSalePersonType::GetList(array(), array("ACTIVE" => "Y"));
if ($arOrderTypesList = $dbOrderTypesList->Fetch()) {
$defaultOrderType = $arOrderTypesList['ID'];
}
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = true;
if (function_exists('intarocrm_order_pre_persist')) {
$order = intarocrm_order_pre_persist($order);
}
if (!isset($order['externalId'])) {
// custom orderType function
if (function_exists('intarocrm_set_order_type')) {
$orderType = intarocrm_set_order_type($order);
if ($orderType) {
$optionsOrderTypes[$order['orderType']] = $orderType;
} else {
$optionsOrderTypes[$order['orderType']] = $defaultOrderType;
}
}
// we dont need new orders without any customers (can check only for externalId)
if (!isset($order['customer']['externalId'])) {
if (!isset($order['customer']['id'])) {
die();
}
$registerNewUser = true;
if (!isset($order['customer']['email']) && $order['customer']['email'] != '') {
$login = $order['customer']['email'] = uniqid('user_' . time()) . '@crm.com';
} else {
$dbUser = CUser::GetList(($by = 'ID'), ($sort = 'ASC'), array('=EMAIL' => $order['email']));
switch ($dbUser->SelectedRowsCount()) {
case 0:
$login = $order['customer']['email'];
break;
case 1:
$arUser = $dbUser->Fetch();
$registeredUserID = $arUser['ID'];
$registerNewUser = false;
break;
default:
$login = uniqid('user_' . time()) . '@crm.com';
break;
}
}
if ($registerNewUser === true) {
$userPassword = uniqid();
$newUser = new CUser;
$arFields = array(
"NAME" => ICrmOrderActions::fromJSON($order['customer']['firstName']),
"LAST_NAME" => ICrmOrderActions::fromJSON($order['customer']['lastName']),
"EMAIL" => $order['customer']['email'],
"LOGIN" => $login,
"LID" => "ru",
"ACTIVE" => "Y",
"PASSWORD" => $userPassword,
"CONFIRM_PASSWORD" => $userPassword
);
$registeredUserID = $newUser->Add($arFields);
if ($registeredUserID === false) {
ICrmOrderActions::eventLog('ICrmOrderActions::orderHistory', 'CUser::Register', 'Error register user');
die();
}
try {
$api->customerFixExternalIds(array(array('id' => $order['customer']['id'], 'externalId' => $registeredUserID)));
} catch (\IntaroCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'ICrmOrderActions::orderHistory', 'RetailCrm\RestApi::customerFixExternalIds::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
die();
}
}
$order['customer']['externalId'] = $registeredUserID;
}
// new order
$newOrderFields = array(
'LID' => CSite::GetDefSite(),
'PERSON_TYPE_ID' => isset($optionsOrderTypes[$order['orderType']]) ? $optionsOrderTypes[$order['orderType']] : $defaultOrderType,
'PAYED' => 'N',
'CANCELED' => 'N',
'STATUS_ID' => 'N',
'PRICE' => 0,
'CURRENCY' => CCurrency::GetBaseCurrency(),
'USER_ID' => $order['customer']['externalId'],
'PAY_SYSTEM_ID' => 0,
'PRICE_DELIVERY' => 0,
'DELIVERY_ID' => 0,
'DISCOUNT_VALUE' => 0,
'USER_DESCRIPTION' => ''
);
if(count($optionsSitesList) > 1 && $lid = array_search($order['site'], $optionsSitesList)){
$newOrderFields['LID'] = $lid;
}
$externalId = CSaleOrder::Add($newOrderFields);
if (!isset($order['externalId'])) {
try {
$api->orderFixExternalIds(array(array('id' => $order['id'], 'externalId' => $externalId)));
} catch (\IntaroCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'ICrmOrderActions::orderHistory', 'RetailCrm\RestApi::orderFixExternalIds::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
die();
}
}
$order['externalId'] = $externalId;
}
if (isset($order['externalId']) && $order['externalId']) {
// custom orderType function
if (function_exists('intarocrm_set_order_type')) {
$orderType = intarocrm_set_order_type($order);
if ($orderType) {
$optionsOrderTypes[$order['orderType']] = $orderType;
} else {
$optionsOrderTypes[$order['orderType']] = $defaultOrderType;
}
}
$arFields = CSaleOrder::GetById($order['externalId']);
// incorrect order
if ($arFields === false || empty($arFields)) {
die();
}
$LID = $arFields['LID'];
$userId = $arFields['USER_ID'];
if(isset($order['customer']['externalId']) && !is_null($order['customer']['externalId'])) {
$userId = $order['customer']['externalId'];
}
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
$arUpdateProps = array();
while ($ar = $rsOrderProps->Fetch()) {
$prop = CSaleOrderProps::GetByID($ar['ORDER_PROPS_ID']);
$arUpdateProps[ $ar['CODE'] ] = array('ID' => $ar['ID'], 'TYPE' => $prop['TYPE'], 'VALUE' => $ar['VALUE']);
}
$order['fio'] = trim(
implode(
' ',
array(
isset($order['lastName']) ? $order['lastName'] : '',
isset($order['firstName']) ? $order['firstName'] : '',
isset($order['patronymic']) ? $order['patronymic'] : '',
)
)
);
if (isset($order['delivery']['address']['city'])) {
$order['location'] = $order['delivery']['address']['city'];
}
if (isset($order['orderType']) && isset($optionsOrderTypes[ $order['orderType'] ])) {
if (isset($optionsOrderProps[$arFields['PERSON_TYPE_ID']])) {
foreach ($optionsOrderProps[$arFields['PERSON_TYPE_ID']] as $code => $value) {
if (in_array($code, array_keys($order)) === false && isset($optionsOrderProps[$optionsOrderTypes[$order['orderType']]][$code])) {
$order[ $code ] = $arUpdateProps[$optionsOrderProps[$arFields['PERSON_TYPE_ID']][$code]]['VALUE'];
}
}
}
//update ordertype
CSaleOrder::Update($order['externalId'], array('PERSON_TYPE_ID' => $optionsOrderTypes[ $order['orderType'] ]));
$arProp = CSaleOrderProps::GetList(array(), array('PERSON_TYPE_ID' => $optionsOrderTypes[ $order['orderType'] ]));
$typeParam = array();
while ($ar = $arProp->Fetch()) {
$typeParam[ $ar['CODE'] ] = $ar['CODE'];
}
foreach (array_diff_key($arUpdateProps, $typeParam) as $code => $param) {
if (isset($arUpdateProps[$code])) {
CSaleOrderPropsValue::Delete($param['ID']);
}
}
$arFields['PERSON_TYPE_ID'] = $optionsOrderTypes[ $order['orderType'] ];
}
array_walk_recursive(
ICrmOrderActions::clearArr($order),
'ICrmOrderActions::recursiveUpdate',
array(
'update' => $arUpdateProps,
'type' => $arFields['PERSON_TYPE_ID'],
'options' => $optionsOrderProps,
'orderId' => $order['externalId']
)
);
//выбираем товары по текущему заказу с сайта
$bItms = array();
$p = CSaleBasket::GetList(array(), array('ORDER_ID' => $order['externalId']));
while($bItm = $p->Fetch()){
$bItms[$bItm['PRODUCT_ID']] = $bItm;
}
//перебираем хистори
$CrmItms = array();
foreach($order['items'] as $item) {
$CrmItms[] = $item['id'];
//если такой товар есть
if(in_array($item['offer']['externalId'], $bItms)){
if ((int) $item['quantity'] != (int) $bItms[$item['offer']['externalId']]['QUANTITY']) {
$arProduct['QUANTITY'] = $item['quantity'];
$g = CSaleBasket::Update($bItms[$item['offer']['externalId']]['ID'], $arProduct);
//резерв
$ar_res = CCatalogProduct::GetByID($item['offer']['externalId']);
$arFields = array(
'QUANTITY' => (int)$ar_res['QUANTITY'] + (int)$bItms[$item['offer']['externalId']]['QUANTITY'] - (int) $item['quantity'],
'QUANTITY_RESERVED' => (int)$ar_res['QUANTITY_RESERVED'] - (int)$bItms[$item['offer']['externalId']]['QUANTITY'] + (int) $item['quantity'],
);
$d = CCatalogProduct::Update($item['offer']['externalId'], $arFields);
}
}//если нет, добавляем
else{
$p = CIBlockElement::GetByID($item['offer']['externalId'])->Fetch();
$iblock = CIBlock::GetByID($p['IBLOCK_ID'])->Fetch();
$p['CATALOG_XML_ID'] = $iblock['XML_ID'];
$p['PRODUCT_XML_ID'] = $p['XML_ID'];
$arProduct = array(
'FUSER_ID' => $userId,
'ORDER_ID' => $order['externalId'],
'QUANTITY' => $item['quantity'],
'CURRENCY' => CCurrency::GetBaseCurrency(),
'LID' => $LID,
'PRODUCT_ID' => $item['offer']['externalId'],
'PRODUCT_PRICE_ID' => $p['PRODUCT_PRICE_ID'],
'WEIGHT' => $p['WEIGHT'],
'DELAY' => $p['DELAY'],
'CAN_BUY' => $p['CAN_BUY'],
'MODULE' => $p['MODULE'],
'NOTES' => $item['comment'] ?: $p['NOTES'],
'PRODUCT_PROVIDER_CLASS' => $p['PRODUCT_PROVIDER_CLASS'],
'DETAIL_PAGE_URL' => $p['DETAIL_PAGE_URL'],
'CATALOG_XML_ID' => $p['CATALOG_XML_ID'],
'PRODUCT_XML_ID' => $p['PRODUCT_XML_ID'],
'CUSTOM_PRICE' => 'Y'
);
if (isset($item['initialPrice']) && $item['initialPrice']) {
$arProduct['PRICE'] = (double) $item['initialPrice'];
}
if (isset($item['discount'])) {
$arProduct['DISCOUNT_PRICE'] = $item['discount'];
}
if (isset($item['discountPercent'])) {
$arProduct['DISCOUNT_VALUE'] = $item['discountPercent'];
$newPrice = round($arProduct['PRICE'] / 100 * (100 - $arProduct['DISCOUNT_VALUE']), 2);
$arProduct['DISCOUNT_PRICE'] = $arProduct['DISCOUNT_PRICE'] + $arProduct['PRICE'] - $newPrice;
}
if(isset($item['discount']) || isset($item['discountPercent'])) {
$arProduct['PRICE'] -= $arProduct['DISCOUNT_PRICE'];
}
if (isset($item['offer']['name']) && $item['offer']['name']) {
$arProduct['NAME'] = ICrmOrderActions::fromJSON($item['offer']['name']);
}
$op = CSaleBasket::Add($arProduct);
//резерв
$ar_res = CCatalogProduct::GetByID($item['offer']['externalId']);
$arFields = array(
'QUANTITY' => (int)$ar_res['QUANTITY'] - (int)$item['quantity'],
'QUANTITY_RESERVED' => (int)$ar_res['QUANTITY_RESERVED'] + (int)$item['quantity'],
);
$d = CCatalogProduct::Update($item['offer']['externalId'], $arFields);
}
}
//удаляем лишние товары
foreach($bItms as $bItm){
if(!in_array($bItm['PRODUCT_ID'], $CrmItms)){
CSaleBasket::Delete($bItm['ID']);
//удаляем товары из резерва
$ar_res = CCatalogProduct::GetByID($bItm['PRODUCT_ID']);
$arFields = array(
'QUANTITY' => (int)$ar_res['QUANTITY'] + (int)$bItm['QUANTITY'],
'QUANTITY_RESERVED' => (int)$ar_res['QUANTITY_RESERVED'] - (int)$bItm['QUANTITY'],
);
$d = CCatalogProduct::Update($bItm['PRODUCT_ID'], $arFields);
}
}
if (isset($order['delivery']) === false || isset($order['delivery']['cost']) === false) {
$order['delivery']['cost'] = $arFields['PRICE_DELIVERY'];
}
if (isset($order['summ']) === false || $order['summ'] <= 0) {
$order['summ'] = $arFields['PRICE'] - $arFields['PRICE_DELIVERY'];
}
$wasCanaceled = $arFields['CANCELED'] == 'Y' ? true : false;
if (isset($optionsDelivTypes[$order['delivery']['code']])) {
$resultDeliveryTypeId = $optionsDelivTypes[$order['delivery']['code']];
} else {
$resultDeliveryTypeId = isset($order['delivery']['service']) && isset($order['delivery']['service']['code']) ?
reset(explode(":", $arFields['DELIVERY_ID'], 1)) :
$arFields['DELIVERY_ID'];
}
if(isset($order['delivery']['service']) && isset($order['delivery']['service']['code'])) {
$deliveryHandler = reset(CSaleDeliveryHandler::GetBySID($resultDeliveryTypeId)->arResult);
if (count($deliveryHandler) > 0 && array_key_exists($order['delivery']['service']['code'], $deliveryHandler['PROFILES'])) {
$resultDeliveryTypeId = $resultDeliveryTypeId . ':' . $order['delivery']['service']['code'];
}
}
// orderUpdate
$arFields = ICrmOrderActions::clearArr(array(
'PRICE_DELIVERY' => $order['delivery']['cost'],
'PRICE' => $order['summ'] + (double) $order['delivery']['cost'],
'DATE_MARKED' => $order['markDatetime'],
'USER_ID' => $userId,
'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']],
'DELIVERY_ID' => $resultDeliveryTypeId,
'STATUS_ID' => $optionsPayStatuses[$order['status']],
'REASON_CANCELED' => ICrmOrderActions::fromJSON($order['statusComment']),
'USER_DESCRIPTION' => ICrmOrderActions::fromJSON($order['customerComment']),
'COMMENTS' => ICrmOrderActions::fromJSON($order['managerComment'])
));
if (isset($order['discount'])) {
$arFields['DISCOUNT_VALUE'] = $order['discount'];
$arFields['PRICE'] -= $order['discount'];
}
if(!empty($arFields)) {
CSaleOrder::Update($order['externalId'], $arFields);
}
if(isset($order['status']) && $order['status']) {
if(isset($optionsPayStatuses[$order['status']]) && $optionsPayStatuses[$order['status']]) {
// set STATUS_ID
CSaleOrder::StatusOrder($order['externalId'], $optionsPayStatuses[$order['status']]);
if($wasCanaceled && $optionsPayStatuses[ $order['status'] ] != 'YY') {
CSaleOrder::CancelOrder($order['externalId'], "N", $order['statusComment']);
} elseif ($optionsPayStatuses[ $order['status'] ] == 'YY') {
CSaleOrder::CancelOrder($order['externalId'], "Y", $order['statusComment']);
}
}
}
// set PAYED
if(isset($order['paymentStatus']) && $order['paymentStatus'] && $optionsPayment[$order['paymentStatus']]) {
CSaleOrder::PayOrder($order['externalId'], $optionsPayment[$order['paymentStatus']]);
}
if(function_exists('intarocrm_order_post_persist')) {
intarocrm_order_post_persist($order);
}
}
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = false;
}
?>

View File

@ -136,7 +136,7 @@ else{
$iblockFieldsName = Array(
"weight" => Array("code" => "catalog_size" , "name" => GetMessage("SELECT_WEIGHT_PROPERTY_NAME"), 'unit' => 'mass'),
"weight" => Array("code" => "catalog_weight" , "name" => GetMessage("SELECT_WEIGHT_PROPERTY_NAME"), 'unit' => 'mass'),
"length" => Array("code" => "catalog_length" , "name" => GetMessage("SELECT_LENGTH_PROPERTY_NAME"), 'unit' => 'length'),
"width" => Array("code" => "catalog_width" , "name" => GetMessage("SELECT_WIDTH_PROPERTY_NAME"), 'unit' => 'length'),
"height" => Array("code" => "catalog_height" , "name" => GetMessage("SELECT_HEIGHT_PROPERTY_NAME"), 'unit' => 'length'),
@ -696,6 +696,7 @@ else{
elseif ($STEP==2)
{
COption::SetOptionString($MODULE_ID, $CRM_CATALOG_BASE_PRICE . '_' . $_REQUEST['PROFILE_ID'], htmlspecialchars(trim($_POST['price-types'])));
COption::SetOptionString($MODULE_ID, 'catalog_base_iblocks', serialize($IBLOCK_EXPORT));
$FINITE = true;
}
}

View File

@ -3,6 +3,7 @@ CModule::AddAutoloadClasses(
'intaro.intarocrm', // module name
array (
'RestNormalizer' => 'classes/general/RestNormalizer.php',
'Logger' => 'classes/general/Logger.php',
'RetailCrm\RestApi' => 'classes/general/RestApi.php',
'RetailCrm\Response\ApiResponse' => 'classes/general/Response/ApiResponse.php',
'ICrmOrderActions' => 'classes/general/ICrmOrderActions.php',

View File

@ -40,6 +40,7 @@ class intaro_intarocrm extends CModule {
var $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
var $CRM_ORDER_HISTORY_DATE = 'order_history_date';
var $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
var $CRM_CATALOG_IBLOCKS = 'catalog_base_iblocks';
var $INSTALL_PATH;
function intaro_intarocrm() {
@ -188,7 +189,7 @@ class intaro_intarocrm extends CModule {
$this->INTARO_CRM_API = new RetailCrm\RestApi($api_host, $api_key);
//api key ok and sites list
try {
$arResult['sitesList'] = $this->INTARO_CRM_API->sitesList()->sites;
$arResult['sitesList'] = $APPLICATION->ConvertCharsetArray($this->INTARO_CRM_API->sitesList()->sites, 'utf-8', SITE_CHARSET);
} catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'intaro.crm/install/index.php', 'RetailCrm\RestApi::sitesList',
@ -376,7 +377,7 @@ class intaro_intarocrm extends CModule {
$paymentStatusesArr['YY'] = htmlspecialchars(trim($_POST['payment-status-YY']));
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
do {
$arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList;
$arResult['bitrixPaymentStatusesList'][$arPaymentStatusesList['ID']] = $arPaymentStatusesList;
$paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']]));
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
}
@ -686,7 +687,7 @@ class intaro_intarocrm extends CModule {
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
do {
$arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList;
$arResult['bitrixPaymentStatusesList'][$arPaymentStatusesList['ID']] = $arPaymentStatusesList;
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
}
@ -1165,6 +1166,7 @@ class intaro_intarocrm extends CModule {
RegisterModuleDependences("sale", "OnSaleReserveOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleReserveOrder");
COption::SetOptionString($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE, htmlspecialchars(trim($_POST['price-types'])));
COption::SetOptionString($this->MODULE_ID, $this->CRM_CATALOG_IBLOCKS, $iblocks);
$this->CopyFiles();
if (isset($_POST['LOAD_NOW'])) {
@ -1343,6 +1345,7 @@ class intaro_intarocrm extends CModule {
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_HISTORY_DATE);
COption::RemoveOption($this->MODULE_ID, $this->CRM_CATALOG_BASE_PRICE);
COption::RemoveOption($this->MODULE_ID, $this->CRM_CATALOG_IBLOCKS);
UnRegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder");
UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder");

View File

@ -34,6 +34,7 @@
<td width="50%" class="adm-detail-content-cell-l"><?php echo $site['NAME'] . ' (' . $site['LID'] . ')'; ?></td>
<td width="50%" class="adm-detail-content-cell-r">
<select class="typeselect" name="sites-id-<?php echo $site['LID']?>">
<option value=""></option>
<?php foreach ($arResult['sitesList'] as $sitesList): ?>
<option value="<?php echo $sitesList['code'] ?>"><?php echo $sitesList['name']?></option>
<?php endforeach; ?>

View File

@ -64,4 +64,5 @@ $MESS ['MESS_1'] = 'Произошла ошибка при выгрузке од
$MESS ['MESS_2'] = 'Произошла ошибка сервера, обратитесь в Интаро Софт.';
$MESS ['ORDER_TYPES_LIST_CUSTOM'] = 'Внимание! Используется не стандартное соответвие типов заказов.';
$MESS ['ORDER_UPL_START'] = 'Начать выгрузку';

View File

@ -426,7 +426,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$arResult['paymentStatusesList'] = $api->paymentStatusesList()->paymentStatuses; // --statuses
$arResult['paymentList'] = $api->orderStatusesList()->statuses;
$arResult['paymentGroupList'] = $api->orderStatusGroupsList()->statusGroups; // -- statuses groups
$arResult['sitesList'] = $api->sitesList()->sites;
$arResult['sitesList'] = $APPLICATION->ConvertCharsetArray($api->sitesList()->sites, 'utf-8', SITE_CHARSET);
} catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'intaro.crm/options.php', 'RetailCrm\RestApi::*List::CurlException',
@ -435,6 +435,10 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode()));
}
catch (InvalidArgumentException $e) {
$badKey = true;
echo CAdminMessage::ShowMessage(GetMessage('ERR_403'));
}
//bitrix orderTypesList -- personTypes
$dbOrderTypesList = CSalePersonType::GetList(
@ -525,7 +529,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
do {
$arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList;
$arResult['bitrixPaymentStatusesList'][$arPaymentStatusesList['ID']] = $arPaymentStatusesList;
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
}
$arResult['bitrixPaymentStatusesList'][] = array(
@ -681,6 +685,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
<td width="50%" class="adm-detail-content-cell-l"><?php echo $site['NAME'] . ' (' . $site['LID'] . ')'; ?></td>
<td width="50%" class="adm-detail-content-cell-r">
<select class="typeselect" name="sites-id-<?php echo $site['LID']?>">
<option value=""></option>
<?php foreach ($arResult['sitesList'] as $sitesList): ?>
<option value="<?php echo $sitesList['code'] ?>" <?php if($sitesList['code'] == $optionsSitesList[$site['LID']]) echo 'selected="selected"'; ?>><?php echo $sitesList['name']?></option>
<?php endforeach; ?>
@ -689,6 +694,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</tr>
<?php endforeach; ?>
<?php endif;?>
<?php if(!$badKey):?>
<?php $tabControl->BeginNextTab(); ?>
<input type="hidden" name="tab" value="catalog">
<tr align="center">
@ -928,6 +934,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</b>
</td>
</tr>
<?php endif;?>
<?php $tabControl->Buttons(); ?>
<input type="hidden" name="Update" value="Y" />
<input type="submit" title="<?php echo GetMessage('ICRM_OPTIONS_SUBMIT_TITLE'); ?>" value="<?php echo GetMessage('ICRM_OPTIONS_SUBMIT_VALUE'); ?>" name="btn-update" class="adm-btn-save" />
@ -1093,7 +1100,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
<br />
<div class="order-upload-button">
<div align="left">
<input type="submit" name="start" value="Начать выгрузку" class="adm-btn-save">
<input type="submit" name="start" value="<?php echo GetMessage('ORDER_UPL_START'); ?>" class="adm-btn-save">
</div>
</div>
</div>