1
0
mirror of synced 2024-11-22 13:26:10 +03:00

merge new version

This commit is contained in:
Alex Lushpai 2016-09-15 17:12:13 +03:00
commit 6de40139e1
62 changed files with 6158 additions and 4227 deletions

View File

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

View File

@ -1,561 +0,0 @@
<?php
if (file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/retailcrm/ICMLLoader.php")){
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/retailcrm/ICMLLoader.php");
}
else{
global $MESS;
IncludeModuleLangFile(__FILE__);
class ICMLLoader {
public $profileID;
public $iblocks;
public $filename;
public $serverName;
public $propertiesSKU;
public $propertiesUnitSKU;
public $propertiesProduct;
public $propertiesUnitProduct;
public $application;
public $encoding = 'utf-8';
public $encodingDefault = 'utf-8';
public $loadPurchasePrice = false;
protected $fp;
protected $mainSection = 1000000;
protected $pageSize = 500;
protected $offerPageSize = 50;
protected $isLogged = false;
protected $logFile = '/bitrix/catalog_export/i_crm_load_log.txt';
protected $fpLog;
protected $MODULE_ID = 'intaro.intarocrm';
protected $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
protected $measurement = array (
'mm' => 1, // 1 mm = 1 mm
'cm' => 10, // 1 cm = 10 mm
'm' => 1000,
'mg' => 0.001, // 0.001 g = 1 mg
'g' => 1,
'kg' => 1000,
);
protected $measurementLink = array (
'mm' => 'mm',
'cm' => 'mm',
'm' => 'mm',
'mg' => 'g',
'g' => 'g',
'kg' => 'g',
);
public function Load()
{
global $USER;
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();
$this->encodingDefault = $defaultSite["CHARSET"];
$this->PrepareSettings();
$this->fp = $this->PrepareFile($this->filename. '.tmp');
if ($this->isLogged) {
$this->fpLog = $this->PrepareFile($this->logFile);
$this->WriteLog("Start Loading");
}
$this->PreWriteCatalog();
$categories = $this->GetCategories();
$this->WriteCategories($categories);
$this->PreWriteOffers();
$this->BuildOffers($categories);
$this->PostWriteOffers();
$this->PostWriteCatalog();
if ($this->isLogged) {
$this->WriteLog("Loading was ended successfully (peek memory usage: " . memory_get_peak_usage() . ")");
}
$this->CloseFile($this->fp);
$this->CloseFile($this->fpLog);
unlink($_SERVER["DOCUMENT_ROOT"] . $this->filename);
rename($_SERVER["DOCUMENT_ROOT"] . $this->filename. '.tmp', $_SERVER["DOCUMENT_ROOT"] . $this->filename);
return true;
}
protected function PrepareSettings()
{
foreach ($this->propertiesSKU as $iblock => $arr) {
foreach ($arr as $id => $sku) {
$this->propertiesSKU[$iblock][$id] = strtoupper($sku);
}
}
foreach ($this->propertiesProduct as $iblock => $arr) {
foreach ($arr as $id => $prod) {
$this->propertiesProduct[$iblock][$id] = strtoupper($prod);
}
}
}
protected function PrepareValue($text)
{
$newText = $this->application->ConvertCharset($text, $this->encodingDefault, $this->encoding);
$newText = strip_tags($newText);
$newText = str_replace("&", "&#x26;", $newText);
return $newText;
}
protected function PrepareFile($filename)
{
$fullFilename = $_SERVER["DOCUMENT_ROOT"] . $filename;
CheckDirPath($fullFilename);
if ($fp = @fopen($fullFilename, "w"))
return $fp;
else
return false;
}
protected function PreWriteCatalog()
{
@fwrite($this->fp, "<yml_catalog date=\"" . $this->PrepareValue(Date("Y-m-d H:i:s")) . "\">\n
<shop>\n
<name>" . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</name>\n
<company>" . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</company>\n"
);
}
protected function WriteCategories($categories)
{
$stringCategories = "";
@fwrite($this->fp, "<categories>\n");
foreach ($categories as $category) {
$stringCategories .= $this->BuildCategory($category);
}
@fwrite($this->fp, $stringCategories);
@fwrite($this->fp, "</categories>\n");
}
protected function PreWriteOffers()
{
@fwrite($this->fp, "<offers>\n");
}
protected function PostWriteOffers()
{
@fwrite($this->fp, "</offers>\n");
}
protected function WriteOffers($offers)
{
@fwrite($this->fp, $offers);
}
protected function WriteLog($text)
{
if ($this->isLogged)
@fwrite($this->fpLog, Date("Y:m:d H:i:s") . ": " . $text . "\n");
}
protected function PostWriteCatalog()
{
@fwrite($this->fp, "</shop>\n
</yml_catalog>\n");
}
protected function CloseFile($fp)
{
@fclose($fp);
}
protected function GetCategories()
{
$categories = array();
foreach ($this->iblocks as $id)
{
$filter = array("IBLOCK_ID" => $id);
$dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
$hasCategories = false;
while ($arRes = $dbRes->Fetch()) {
$categories[$arRes['ID']] = $arRes;
$hasCategories = true;
}
if (!$hasCategories) {
$iblock = CIBlock::GetByID($id)->Fetch();
$arRes = Array();
$arRes['ID'] = $this->mainSection + $id;
$arRes['IBLOCK_SECTION_ID'] = 0;
$arRes['NAME'] = sprintf(GetMessage('ROOT_CATEGORY_FOR_CATALOG'), $iblock['NAME']);
$categories[$arRes['ID']] = $arRes;
}
}
return $categories;
}
protected function BuildCategory($arCategory)
{
return "
<category id=\"" . $this->PrepareValue($arCategory["ID"]) . "\""
. ( intval($arCategory["IBLOCK_SECTION_ID"] ) > 0 ?
" parentId=\"" . $this->PrepareValue($arCategory["IBLOCK_SECTION_ID"]) . "\""
:"")
. ">"
. $this->PrepareValue($arCategory["NAME"])
. "</category>\n";
}
protected function BuildOffers(&$allCategories)
{
$basePriceId = COption::GetOptionString(
$this->MODULE_ID,
$this->CRM_CATALOG_BASE_PRICE . (is_null($this->profileID) === false ? '_' . $this->profileID : ''),
1
);
foreach ($this->iblocks as $key => $id)
{
// Get Info by infoblocks
$iblock['IBLOCK_DB'] = CIBlock::GetByID($id)->Fetch();
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($id);
$arSelect = Array (
"ID",
"LID",
"IBLOCK_ID",
"IBLOCK_SECTION_ID",
"ACTIVE",
"ACTIVE_FROM",
"ACTIVE_TO",
"NAME",
"DETAIL_PICTURE",
"DETAIL_TEXT",
"DETAIL_PICTURE",
"LANG_DIR",
"DETAIL_PAGE_URL",
"CATALOG_GROUP_" . $basePriceId
);
// Set selected properties
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
if ($this->propertiesProduct[$id][$key] != "") {
$arSelect[] = "PROPERTY_" . $propProduct;
$arSelect[] = "PROPERTY_" . $propProduct . ".NAME";
}
}
$arSelectOffer = Array (
'ID',
'ACTIVE',
"NAME",
"DETAIL_TEXT",
"DETAIL_PAGE_URL",
"DETAIL_PICTURE",
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'],
"CATALOG_GROUP_" . $basePriceId
);
// Set selected properties
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
if ($this->propertiesSKU[$id][$key] != "") {
$arSelectOffer[] = "PROPERTY_" . $propSKU;
$arSelectOffer[] = "PROPERTY_" . $propSKU . ".NAME";
}
}
// Set filter
$filter = array(
"IBLOCK_ID" => $id
);
$order = array("id");
$arNavStatParams = Array(
"iNumPage" => 1,
"nPageSize" => $this->pageSize,
);
// Cycle page to page
do {
// Get products on this page
$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();
while ($product = $dbResProducts->GetNext()) {
// Compile products to array
$products[$product['ID']] = $product;
$products[$product['ID']]['offers'] = array();
$detailPicture = intval($product["DETAIL_PICTURE"]);
$previewPicture = intval($product["PREVIEW_PICTURE"]);
if ($detailPicture > 0 || $previewPicture > 0)
{
$picture = $detailPicture;
if ($picture <= 0) {
$picture = $previewPicture;
}
// Link pictureID and productID
$pictures[$picture] = $product['ID'];
}
}
unset($product);
unset($detailPicture, $previewPicture, $picture);
$pictureIDs = array_keys($pictures);
// Get pathes of pictures
$dbFiles = CFile::GetList(Array(), Array("@ID" => implode(',', $pictureIDs)));
while($file = $dbFiles->GetNext()) {
// Link picture to product
$products[$pictures[$file['ID']]]['PICTURE'] = ($_SERVER["HTTPS"] == 'on' ? "https://" : "http://") .
$this->serverName .
'/upload/' . $file['SUBDIR'] .
'/' . $file['FILE_NAME'] ;
}
unset($pictures);
if (!empty($iblockOffer['IBLOCK_ID'])) {
$arFilterOffer = array(
'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => array_keys($products),
);
// Get all offers for products on this page
$dbResOffers = CIBlockElement::GetList(
array(),
$arFilterOffer,
false,
array('nTopCount' => $this->pageSize * $this->offerPageSize),
$arSelectOffer
);
while ($offer = $dbResOffers->GetNext()) {
// Link offers to products
$products[$offer['PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] . '_VALUE']]['offers'][$offer['ID']] = $offer;
}
unset($offer, $dbResOffers);
}
$stringOffers = "";
foreach ($products as $product) {
// Get properties of product
$resPropertiesProduct = Array();
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
$resPropertiesProduct[$key] = "";
if ($propProduct != "") {
if (isset($product["PROPERTY_" . $propProduct . "_NAME"])){
$resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_NAME"];
}
elseif (isset($product["PROPERTY_" . $propProduct . "_VALUE"])){
$resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_VALUE"];
}
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]];
}
}
}
// Get categories of product
$categories = Array();
$dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true);
while ($arResCategory = $dbResCategories->Fetch()) {
$categories[$arResCategory["ID"]] = array(
'ID' => $arResCategory["ID"],
'NAME' => $arResCategory["NAME"],
);
}
if (count($categories) == 0) {
$catId = $this->mainSection + $id;
$categories[$catId] = $allCategories[$catId];
}
$existOffer = false;
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"];
$offer['PRODUCT_NAME'] = $product["NAME"];
$offer['PRODUCT_ACTIVE'] = $product["ACTIVE"];
$offer['PRICE'] = $offer['CATALOG_PRICE_' . $basePriceId];
$offer['PURCHASE_PRICE'] = $offer['CATALOG_PURCHASING_PRICE'];
$offer['QUANTITY'] = $offer["CATALOG_QUANTITY"];
// Get properties of product
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
if ($propSKU != "") {
if (isset ($offer["PROPERTY_" . $propSKU . "_NAME"])){
$offer['_PROP_' . $key] = $offer["PROPERTY_" . $propSKU . "_NAME"];
}
elseif (isset($offer["PROPERTY_" . $propSKU . "_VALUE"])){
$offer['_PROP_' . $key] = $offer["PROPERTY_" . $propSKU . "_VALUE"];
}
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])){
$offer['_PROP_' . $key] = $propProduct;
}
}
$stringOffers .= $this->BuildOffer($offer, $categories, $iblock, $allCategories);
$existOffer = true;
}
}
if (!$existOffer) {
$product['PRODUCT_ID'] = $product["ID"];
$product['PRODUCT_NAME'] = $product["NAME"];
$product['PRODUCT_ACTIVE'] = $product["ACTIVE"];
$product['PRICE'] = $product['CATALOG_PRICE_' . $basePriceId];
$product['PURCHASE_PRICE'] = $product['CATALOG_PURCHASING_PRICE'];
$product['QUANTITY'] = $product["CATALOG_QUANTITY"];
foreach ($resPropertiesProduct as $key => $propProduct) {
if ($this->propertiesProduct[$id][$key] != "" || $this->propertiesProduct[$id][str_replace("_UNIT", "", $key)] != "") {
$product['_PROP_' . $key] = $propProduct;
}
}
$stringOffers .= $this->BuildOffer($product, $categories, $iblock, $allCategories);
}
}
unset($products);
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'] = $dbResProductsIds->NavPageNomer + 1;
}
while ($dbResProductsIds->NavPageNomer < $dbResProductsIds->NavPageCount);
}
}
protected function BuildOffer($arOffer, $categories, $iblock, &$allCategories)
{
$offer = "";
$offer .= "<offer id=\"" .$this->PrepareValue($arOffer["ID"]) . "\" ".
"productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ".
"quantity=\"" . $this->PrepareValue(DoubleVal($arOffer['QUANTITY'])) . "\">\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) {
$category = $allCategories[$keys[0]];
$path = $category['CODE'];
if(intval($category["IBLOCK_SECTION_ID"] ) != 0) {
while (true) {
$category = $allCategories[$category['IBLOCK_SECTION_ID']];
$path = $category['CODE'] . '/' . $path;
if(intval($category["IBLOCK_SECTION_ID"] ) == 0)
break;
}
}
}
$arOffer['DETAIL_PAGE_URL'] = str_replace("#SECTION_PATH#", $path, $arOffer['DETAIL_PAGE_URL']);
}
$offer .= "<picture>" . $this->PrepareValue($arOffer["PICTURE"]) . "</picture>\n";
$offer .= "<url>" . ($_SERVER["HTTPS"] == 'on' ? "https://" : "http://") . $this->serverName . $this->PrepareValue($arOffer['DETAIL_PAGE_URL']) . "</url>\n";
$offer .= "<price>" . $this->PrepareValue($arOffer['PRICE']) . "</price>\n";
if ($arOffer['PURCHASE_PRICE'] && $this->loadPurchasePrice) {
$offer .= "<purchasePrice>" . $this->PrepareValue($arOffer['PURCHASE_PRICE']) . "</purchasePrice>\n";
}
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";
$offer .= "<productName>" . $this->PrepareValue($arOffer["PRODUCT_NAME"]) . "</productName>\n";
foreach ($this->propertiesProduct[$iblock['IBLOCK_DB']['ID']] as $key => $propProduct) {
if ($propProduct != "" && $arOffer['_PROP_' . $key] != null) {
if ($key === "manufacturer"){
$offer .= "<vendor>" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</vendor>\n";
}
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"){
$offer .= "<vendor>" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</vendor>\n";
}
else{
$offer .= '<param name="' . $key . '"' . (isset($arOffer['_PROP_' . $key . "_UNIT"]) ? ' unit="' . $arOffer['_PROP_' . $key . "_UNIT"] . '"' : "") . ">" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</param>\n";
}
}
}
$offer.= "</offer>\n";
return $offer;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,689 +0,0 @@
<?php
namespace RetailCrm;
use RetailCrm\Response\ApiResponse;
use RetailCrm\Exception\CurlException;
/**
* retailCRM API client class
*/
class RestApi
{
const VERSION = 'v3';
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
protected $client;
protected $url;
protected $defaultParameters;
protected $generatedAt;
/**
* Site code
*/
protected $siteCode;
/**
* Client creating
*
* @param string $url - url сайта
* @param string $apiKey - ключ API
* @param string $site - символьный код сайта
* @return mixed
*/
public function __construct($url, $apiKey, $site = null)
{
if ('/' != substr($url, strlen($url) - 1, 1)) {
$url .= '/';
}
$url = $url . 'api/' . self::VERSION;
if (false === stripos($url, 'https://')) {
throw new \InvalidArgumentException('API schema requires HTTPS protocol');
}
$this->url = $url;
$this->defaultParameters = array('apiKey' => $apiKey);
$this->siteCode = $site;
}
/* Методы для работы с заказами */
/**
* Получение заказа по id
*
* @param string $id - идентификатор заказа
* @param string $by - поиск заказа по id или externalId
* @param string $site - символьный код сайта
* @return ApiResponse - информация о заказе
*/
public function ordersGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
return $this->makeRequest("/orders/$id", self::METHOD_GET, $this->fillSite($site, array(
'by' => $by
)));
}
/**
* Создание заказа
*
* @param array $order - информация о заказе
* @param string $site - символьный код сайта
* @return ApiResponse
*/
public function ordersCreate($order, $site = null)
{
if (!sizeof($order)) {
throw new \InvalidArgumentException('Parameter `order` must contains a data');
}
return $this->makeRequest("/orders/create", self::METHOD_POST, $this->fillSite($site, array(
'order' => json_encode($order)
)));
}
/**
* Изменение заказа
*
* @param array $order - информация о заказе
* @param string $by - изменение заказа по id или externalId
* @param string $site - символьный код сайта
* @return ApiResponse
*/
public function orderEdit($order, $by = 'externalId', $site = null)
{
if (!sizeof($order)) {
throw new \InvalidArgumentException('Parameter `order` must contains a data');
}
$this->checkIdParameter($by);
if (!isset($order[$by])) {
throw new \InvalidArgumentException(sprintf('Order array must contain the "%s" parameter.', $by));
}
return $this->makeRequest(
"/orders/" . $order[$by] . "/edit",
self::METHOD_POST,
$this->fillSite($site, array(
'order' => json_encode($order),
'by' => $by,
))
);
}
/**
* Пакетная загрузка заказов
*
* @param array $orders - массив заказов
* @param string $site - символьный код сайта
* @return ApiResponse
*/
public function orderUpload($orders, $site = null)
{
if (!sizeof($orders)) {
throw new \InvalidArgumentException('Parameter `orders` must contains array of the orders');
}
return $this->makeRequest("/orders/upload", self::METHOD_POST, $this->fillSite($site, array(
'orders' => json_encode($orders),
)));
}
/**
* Обновление externalId у заказов с переданными id
*
* @param array $order - массив, содержащий id и externalId заказа
* @return ApiResponse
*/
public function orderFixExternalIds($order)
{
if (!sizeof($order)) {
throw new \InvalidArgumentException('Method parameter must contains at least one IDs pair');
}
return $this->makeRequest("/orders/fix-external-ids", self::METHOD_POST, array(
'orders' => json_encode($order),
));
}
/**
* Получение последних измененных заказов
*
* @param \DateTime|string|int $startDate - начальная дата и время выборки (Y-m-d H:i:s)
* @param \DateTime|string|int $endDate - конечная дата и время выборки (Y-m-d H:i:s)
* @param int $limit - ограничение на размер выборки
* @param int $offset - сдвиг
* @param bool $skipMyChanges
* @return ApiResponse
*/
public function orderHistory(
$startDate = null,
$endDate = null,
$limit = 100,
$offset = 0,
$skipMyChanges = true
) {
$parameters = array();
if ($startDate) {
$parameters['startDate'] = $this->ensureDateTime($startDate);
}
if ($endDate) {
$parameters['endDate'] = $this->ensureDateTime($endDate);
}
if ($limit) {
$parameters['limit'] = (int) $limit;
}
if ($offset) {
$parameters['offset'] = (int) $offset;
}
if ($skipMyChanges) {
$parameters['skipMyChanges'] = (bool) $skipMyChanges;
}
return $this->makeRequest('/orders/history', self::METHOD_GET, $parameters);
}
/* Методы для работы с клиентами */
/**
* Получение клиента по id
*
* @param string $id - идентификатор
* @param string $by - поиск заказа по id или externalId
* @param string $site - символьный код сайта
* @return array - информация о клиенте
*/
public function customerGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
return $this->makeRequest("/customers/$id", self::METHOD_GET, $this->fillSite($site, array(
'by' => $by
)));
}
/**
* Получение списка клиентов в соответсвии с запросом
*
* @param array $filter - фильтры
* @param int $page - страница
* @param int $limit - ограничение на размер выборки
* @return ApiResponse
*/
public function customersList(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
if (sizeof($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
return $this->makeRequest('/customers', self::METHOD_GET, $parameters);
}
/**
* Создание клиента
*
* @param array $customer - информация о клиенте
* @param string $site - символьный код сайта
* @return ApiResponse
*/
public function customersCreate(array $customer, $site = null)
{
if (!sizeof($customer)) {
throw new \InvalidArgumentException('Parameter `customer` must contains a data');
}
return $this->makeRequest("/customers/create", self::METHOD_POST, $this->fillSite($site, array(
'customer' => json_encode($customer)
)));
}
/**
* Редактирование клиента
*
* @param array $customer - информация о клиенте
* @param string $by - изменение клиента по id или externalId
* @param string $site - символьный код сайта
* @return ApiResponse
*/
public function customerEdit($customer, $by = 'externalId', $site = null)
{
if (!sizeof($customer)) {
throw new \InvalidArgumentException('Parameter `customer` must contains a data');
}
$this->checkIdParameter($by);
if (!isset($customer[$by])) {
throw new \InvalidArgumentException(sprintf('Customer array must contain the "%s" parameter.', $by));
}
return $this->makeRequest(
"/customers/" . $customer[$by] . "/edit",
self::METHOD_POST,
$this->fillSite($site, array(
'customer' => json_encode($customer),
'by' => $by,
)
));
}
/**
* Пакетная загрузка клиентов
*
* @param array $customers - массив клиентов
* @param string $site - символьный код сайта
* @return ApiResponse
*/
public function customerUpload($customers, $site = null)
{
if (!sizeof($customers)) {
throw new \InvalidArgumentException('Parameter `customers` must contains array of the customers');
}
return $this->makeRequest("/customers/upload", self::METHOD_POST, $this->fillSite($site, array(
'customers' => json_encode($customers),
)));
}
/**
* Обновление externalId у клиентов с переданными id
*
* @param array $customers - массив, содержащий id и externalId заказа
* @return array
*/
public function customerFixExternalIds($customers)
{
if (!sizeof($customers)) {
throw new \InvalidArgumentException('Method parameter must contains at least one IDs pair');
}
return $this->makeRequest("/customers/fix-external-ids", self::METHOD_POST, array(
'customers' => json_encode($customers),
));
}
/* Методы для работы со справочниками */
/**
* Получение списка типов доставки
*
* @return ApiResponse
*/
public function deliveryTypesList()
{
return $this->makeRequest('/reference/delivery-types', self::METHOD_GET);
}
/**
* Редактирование типа доставки
*
* @param array $delivery - информация о типе доставки
* @return ApiResponse
*/
public function deliveryTypeEdit($delivery)
{
if (!isset($delivery['code'])) {
throw new \InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->makeRequest(
'/reference/delivery-types/' . $delivery['code'] . '/edit',
self::METHOD_POST,
array(
'deliveryType' => json_encode($delivery)
)
);
}
/**
* Получение списка служб доставки
*
* @return ApiResponse
*/
public function deliveryServicesList()
{
return $this->makeRequest('/reference/delivery-services', self::METHOD_GET);
}
/**
* Редактирование службы доставки
*
* @param array $delivery - информация о типе доставки
* @return ApiResponse
*/
public function deliveryServiceEdit($delivery)
{
if (!isset($delivery['code'])) {
throw new \InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->makeRequest(
'/reference/delivery-services/' . $delivery['code'] . '/edit',
self::METHOD_POST,
array(
'deliveryService' => json_encode($delivery)
)
);
}
/**
* Получение списка типов оплаты
*
* @return ApiResponse
*/
public function paymentTypesList()
{
return $this->makeRequest('/reference/payment-types', self::METHOD_GET);
}
/**
* Редактирование типа оплаты
*
* @param array $paymentType - информация о типе оплаты
* @return ApiResponse
*/
public function paymentTypesEdit($paymentType)
{
if (!isset($paymentType['code'])) {
throw new \InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->makeRequest(
'/reference/payment-types/' . $paymentType['code'] . '/edit',
self::METHOD_POST,
array(
'paymentType' => json_encode($paymentType)
)
);
}
/**
* Получение списка статусов оплаты
*
* @return ApiResponse
*/
public function paymentStatusesList()
{
return $this->makeRequest('/reference/payment-statuses', self::METHOD_GET);
}
/**
* Редактирование статуса оплаты
*
* @param array $paymentStatus - информация о статусе оплаты
* @return ApiResponse
*/
public function paymentStatusesEdit($paymentStatus)
{
if (!isset($paymentStatus['code'])) {
throw new \InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->makeRequest(
'/reference/payment-statuses/' . $paymentStatus['code'] . '/edit',
self::METHOD_POST,
array(
'paymentStatus' => json_encode($paymentStatus)
)
);
}
/**
* Получение списка типов заказа
*
* @return ApiResponse
*/
public function orderTypesList()
{
return $this->makeRequest('/reference/order-types', self::METHOD_GET);
}
/**
* Редактирование типа заказа
*
* @param array $orderType - информация о типе заказа
* @return ApiResponse
*/
public function orderTypesEdit($orderType)
{
if (!isset($orderType['code'])) {
throw new \InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->makeRequest(
'/reference/order-types/' . $orderType['code'] . '/edit',
self::METHOD_POST,
array(
'orderType' => json_encode($orderType)
)
);
}
/**
* Получение списка способов оформления заказа
*
* @return ApiResponse
*/
public function orderMethodsList()
{
return $this->makeRequest('/reference/order-methods', self::METHOD_GET);
}
/**
* Редактирование способа оформления заказа
*
* @param array $orderMethod - информация о способе оформления заказа
* @return ApiResponse
*/
public function orderMethodsEdit($orderMethod)
{
if (!isset($orderMethod['code'])) {
throw new \InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->makeRequest(
'/reference/order-methods/' . $orderMethod['code'] . '/edit',
self::METHOD_POST,
array(
'orderMethod' => json_encode($orderMethod)
)
);
}
/**
* Получение списка статусов заказа
*
* @return ApiResponse
*/
public function orderStatusesList()
{
return $this->makeRequest('/reference/statuses', self::METHOD_GET);
}
/**
* Получение списка сайтов
*
* @return ApiResponse
*/
public function sitesList()
{
return $this->makeRequest('/reference/sites', self::METHOD_GET);
}
/**
* Редактирование статуса заказа
*
* @param array $status - информация о статусе заказа
* @return ApiResponse
*/
public function orderStatusEdit($status)
{
if (!isset($status['code'])) {
throw new \InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->makeRequest(
'/reference/statuses/' . $status['code'] . '/edit',
self::METHOD_POST,
array(
'status' => json_encode($status)
)
);
}
/**
* Получение списка групп статусов заказа
*
* @return ApiResponse
*/
public function orderStatusGroupsList()
{
return $this->makeRequest('/reference/status-groups', self::METHOD_GET);
}
/**
* Обновление статистики
*
* @return ApiResponse
*/
public function statisticUpdate()
{
return $this->makeRequest('/statistic/update', self::METHOD_GET);
}
/**
* @return \DateTime
*/
public function getGeneratedAt()
{
return $this->generatedAt;
}
protected function ensureDateTime($value)
{
if ($value instanceof \DateTime) {
return $value->format('Y-m-d H:i:s');
} elseif (is_int($value)) {
return date('Y-m-d H:i:s', $value);
}
return $value;
}
/**
* Check ID parameter
*
* @param string $by
* @return bool
*/
protected function checkIdParameter($by)
{
$allowedForBy = array('externalId', 'id');
if (!in_array($by, $allowedForBy)) {
throw new \InvalidArgumentException(sprintf(
'Value "%s" for parameter "by" is not valid. Allowed values are %s.',
$by,
implode(', ', $allowedForBy)
));
}
return true;
}
/**
* Fill params by site value
*
* @param string $site
* @param array $params
* @return array
*/
protected function fillSite($site, array $params)
{
if ($site) {
$params['site'] = $site;
} elseif ($this->siteCode) {
$params['site'] = $this->siteCode;
}
return $params;
}
/**
* Make HTTP request
*
* @param string $path
* @param string $method (default: 'GET')
* @param array $parameters (default: array())
* @param int $timeout
* @return ApiResponse
*/
public function makeRequest($path, $method, $parameters = array(), $timeout = 30)
{
$allowedMethods = array(self::METHOD_GET, self::METHOD_POST);
if (!in_array($method, $allowedMethods)) {
throw new \InvalidArgumentException(sprintf(
'Method "%s" is not valid. Allowed methods are %s',
$method,
implode(', ', $allowedMethods)
));
}
$parameters = array_merge($this->defaultParameters, $parameters);
$path = $this->url . $path;
if (self::METHOD_GET === $method && sizeof($parameters)) {
$path .= '?' . http_build_query($parameters);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout); // times out after 30s
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
if (self::METHOD_POST === $method) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
}
$responseBody = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$errno = curl_errno($ch);
$error = curl_error($ch);
curl_close($ch);
if ($errno) {
throw new CurlException($error, $errno);
}
$result = json_decode($responseBody, true);
if (isset($result['generatedAt'])) {
$this->generatedAt = new \DateTime($result['generatedAt']);
unset($result['generatedAt']);
}
return new ApiResponse($statusCode, $responseBody);
}
}

View File

@ -1,340 +0,0 @@
<?php
/**
* OrderEvent
*/
class ICrmOrderEvent {
protected static $MODULE_ID = 'intaro.intarocrm';
protected static $CRM_API_HOST_OPTION = 'api_host';
protected static $CRM_API_KEY_OPTION = 'api_key';
protected static $CRM_ORDER_TYPES_ARR = 'order_types_arr';
protected static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
protected static $CRM_PAYMENT_TYPES = 'pay_types_arr';
protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
protected static $CRM_ORDER_LAST_ID = 'order_last_id';
protected static $CRM_ORDER_PROPS = 'order_props';
protected static $CRM_LEGAL_DETAILS = 'legal_details';
protected static $CRM_CUSTOM_FIELDS = 'custom_fields';
protected static $CRM_CONTRAGENT_TYPE = 'contragent_type';
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
protected static $CRM_SITES_LIST = 'sites_list';
/**
* onBeforeOrderAdd
*
* @param mixed $arFields - Order arFields
*/
function onBeforeOrderAdd($arFields = array()) {
$GLOBALS['INTARO_CRM_ORDER_ADD'] = true;
return;
}
/**
* OnSaleBeforeReserveOrder
*
* @param mixed $arFields - Order arFields
*/
function OnSaleBeforeReserveOrder($arFields = array()) {
$GLOBALS['INTARO_CRM_ORDER_RESERVE'] = true;
return;
}
/**
* OnSaleReserveOrder
*
* @param mixed $arFields - Order arFields
*/
function OnSaleReserveOrder($arFields = array()) {
if(isset($GLOBALS['INTARO_CRM_ORDER_RESERVE']) && $GLOBALS['INTARO_CRM_ORDER_RESERVE'])
unset($GLOBALS['INTARO_CRM_ORDER_RESERVE']);
return;
}
/**
* onUpdateOrder
*
* @param mixed $ID - Order id
* @param mixed $arFields - Order arFields
*/
function onUpdateOrder($ID, $arFields) {
if(isset($GLOBALS['INTARO_CRM_ORDER_ADD']) && $GLOBALS['INTARO_CRM_ORDER_ADD'])
return;
if(isset($GLOBALS['INTARO_CRM_ORDER_RESERVE']) && $GLOBALS['INTARO_CRM_ORDER_RESERVE'])
return;
if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY'])
return;
if(isset($arFields['LOCKED_BY']) && $arFields['LOCKED_BY'])
return;
if(isset($arFields['CANCELED']))
return;
self::writeDataOnOrderCreate($ID, $arFields);
}
/**
* onSendOrderMail
* in: sale.order.ajax, sale.order.full
*
* @param mixed $ID - Order id
* @param mixed $eventName - Event type
* @param mixed $arFields - Order arFields for sending template
*/
function onSendOrderMail($ID, &$eventName, &$arFields) {
if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY'])
return;
if(self::writeDataOnOrderCreate($ID))
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, $ID);
else {
$failedIds = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, 0));
if(!$failedIds)
$failedIds = array();
$failedIds[] = $ID;
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, serialize($failedIds));
}
}
/**
* writeDataOnOrderCreate via api
*
* @param $ID - Order Id
* @param array $arFields
* @return boolean
*/
function writeDataOnOrderCreate($ID, $arFields) {
if (!CModule::IncludeModule('iblock')) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'iblock', 'module not found');
return true;
}
if (!CModule::IncludeModule("sale")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'sale', 'module not found');
return true;
}
if (!CModule::IncludeModule("catalog")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'catalog', 'module not found');
return true;
}
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = false;
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
//saved cat params
$optionsOrderTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0));
$optionsDelivTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 0));
$optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
$optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0));
$optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0));
$optionsContragentType = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CONTRAGENT_TYPE, 0));
$optionsCustomFields = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CUSTOM_FIELDS, 0));
$api = new RetailCrm\RestApi($api_host, $api_key);
$arParams = ICrmOrderActions::clearArr(array(
'optionsOrderTypes' => $optionsOrderTypes,
'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes,
'optionsPayStatuses' => $optionsPayStatuses,
'optionsPayment' => $optionsPayment,
'optionsOrderProps' => $optionsOrderProps,
'optionsLegalDetails' => $optionsLegalDetails,
'optionsContragentType' => $optionsContragentType,
'optionsSitesList' => $optionsSitesList,
'optionsCustomFields' => $optionsCustomFields
));
$arOrder = CSaleOrder::GetById($ID);
if (is_array($arFields) && !empty($arFields)) {
$arFieldsNew = array(
'USER_ID' => $arOrder['USER_ID'],
'ID' => $ID,
'PERSON_TYPE_ID' => $arOrder['PERSON_TYPE_ID'],
'CANCELED' => $arOrder['CANCELED'],
'STATUS_ID' => $arOrder['STATUS_ID'],
'DATE_INSERT' => $arOrder['DATE_INSERT'],
'LID' => $arOrder['LID']
);
$arFieldsNew = array_merge($arFieldsNew, $arFields);
$arOrder = $arFieldsNew;
}
if(count($optionsSitesList)>1){
$result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true, $optionsSitesList[$arOrder['LID']]);
}
else{
$result = ICrmOrderActions::orderCreate($arOrder, $api, $arParams, true);
}
if(!$result) {
ICrmOrderActions::eventLog('ICrmOrderEvent::writeDataOnOrderCreate', 'ICrmOrderActions::orderCreate', 'error during creating order');
return false;
}
return true;
}
/**
*
* @param type $ID -- orderId
* @param type $cancel -- Y / N - cancel order status
* @param type $reason -- cancel reason
* @return boolean
*/
function onSaleCancelOrder($ID, $cancel, $reason) {
if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY'])
return;
if(!$ID || !$cancel)
return true;
if (!CModule::IncludeModule('iblock')) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'iblock', 'module not found');
return true;
}
if (!CModule::IncludeModule("sale")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'sale', 'module not found');
return true;
}
if (!CModule::IncludeModule("catalog")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSaleCancelOrder', 'catalog', 'module not found');
return true;
}
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
//saved cat params
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
$api = new RetailCrm\RestApi($api_host, $api_key);
$order = array();
if($cancel == 'Y') {
$order = array(
'externalId' => (int) $ID,
'status' => $optionsPayStatuses[$cancel.$cancel],
'statusComment' => ICrmOrderActions::toJSON($reason)
);
} else if($cancel == 'N') {
$arOrder = CSaleOrder::GetById((int) $ID);
$order = array(
'externalId' => (int) $ID,
'status' => $optionsPayStatuses[$arOrder['STATUS_ID']],
'managerComment' => $arOrder['COMMENTS']
);
}
$log = new Logger();
$log->write($order, 'order');
try {
$api->orderEdit($order);
} catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'ICrmOrderEvent::onSaleCancelOrder', 'RetailCrm\RestApi::orderEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
return true;
}
/**
*
* @param type $ID -- orderId
* @param type $payed -- Y / N - pay order status
* @return boolean
*/
function onSalePayOrder($ID, $payed) {
if(isset($GLOBALS['INTARO_CRM_FROM_HISTORY']) && $GLOBALS['INTARO_CRM_FROM_HISTORY'])
return;
if(!$ID || !$payed || ($payed != 'Y'))
return true;
if (!CModule::IncludeModule('iblock')) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'iblock', 'module not found');
return true;
}
if (!CModule::IncludeModule("sale")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'sale', 'module not found');
return true;
}
if (!CModule::IncludeModule("catalog")) {
//handle err
ICrmOrderActions::eventLog('ICrmOrderEvent::onSalePayOrder', 'catalog', 'module not found');
return true;
}
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
//saved cat params
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
$api = new RetailCrm\RestApi($api_host, $api_key);
$order = array(
'externalId' => (int) $ID,
'paymentStatus' => $optionsPayment[$payed]
);
$log = new Logger();
$log->write($order, 'order');
try {
$api->orderEdit($order);
} catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'ICrmOrderEvent::onSalePayOrder', 'RetailCrm\RestApi::orderEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
return true;
}
/**
*
* @param type $ID -- orderId
* @param type $value -- ACCOUNT_NUMBER
* @return boolean
*/
function onBeforeOrderAccountNumberSet($ID, $value) {
if(isset($GLOBALS['ICRM_ACCOUNT_NUMBER']) && $GLOBALS['ICRM_ACCOUNT_NUMBER'])
return $GLOBALS['ICRM_ACCOUNT_NUMBER'];
return false;
}
}

View File

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

View File

@ -1,435 +0,0 @@
<?
$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

@ -1,4 +0,0 @@
- Исправлена ошибка, связанная с версионностью PHP в History.
- Добавлена выгрузка закупочной цены вместе с заказом
- Добавлены индивидуальные настройки для профилей выгрузки
- Исправлены мелкие ошибки

View File

@ -1,15 +0,0 @@
<?php
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',
'ICMLLoader' => 'classes/general/ICMLLoader.php',
'ICrmOrderEvent' => 'classes/general/events/ICrmOrderEvent.php',
'RetailCrm\Exception\InvalidJsonException' => 'classes/general/Exception/InvalidJsonException.php',
'RetailCrm\Exception\CurlException' => 'classes/general/Exception/CurlException.php',
)
);

View File

@ -1,3 +0,0 @@
<?
//<title>retailCRM</title>
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/export/export_run.php");

View File

@ -1,3 +0,0 @@
<?
//<title>retailCRM</title>
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/export/export_setup.php");

View File

@ -1,6 +0,0 @@
<?
$arModuleVersion = array(
"VERSION" => "1.1.1",
"VERSION_DATE" => "2015-03-19 14:56:00"
);

View File

@ -1,2 +0,0 @@
<?php
$MESS["PRODUCT_CANCEL"] = "Товар в статусе отмены";

View File

@ -1,5 +0,0 @@
<?php
if (!CModule::IncludeModule("main")) return;
DeleteDirFilesEx('/retailcrm');
DeleteDirFilesEx('/bitrix/modules/intaro.intarocrm/classes/general/agent.php');
DeleteDirFilesEx('/bitrix/modules/intaro.intarocrm/classes/general/Exception/ApiException.php');

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,160 @@
<?php
/**
* PHP version 5.3
*
* HTTP client
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/
namespace RetailCrm\Http;
use RetailCrm\Exception\CurlException;
use RetailCrm\Exception\InvalidJsonException;
use RetailCrm\Response\ApiResponse;
/**
* PHP version 5.3
*
* HTTP client
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/
class Client
{
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
protected $url;
protected $defaultParameters;
protected $retry;
/**
* Client constructor.
*
* @param string $url api url
* @param array $defaultParameters array of parameters
*
* @throws \InvalidArgumentException
*/
public function __construct($url, array $defaultParameters = array())
{
if (false === stripos($url, 'https://')) {
throw new \InvalidArgumentException(
'API schema requires HTTPS protocol'
);
}
$this->url = $url;
$this->defaultParameters = $defaultParameters;
$this->retry = 0;
$this->curlErrors = array(
CURLE_COULDNT_RESOLVE_PROXY,
CURLE_COULDNT_RESOLVE_HOST,
CURLE_COULDNT_CONNECT,
CURLE_OPERATION_TIMEOUTED,
CURLE_HTTP_POST_ERROR,
CURLE_SSL_CONNECT_ERROR,
CURLE_SEND_ERROR,
CURLE_RECV_ERROR
);
}
/**
* Make HTTP request
*
* @param string $path request url
* @param string $method (default: 'GET')
* @param array $parameters (default: array())
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
* @throws \InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
*
* @return ApiResponse
*/
public function makeRequest(
$path,
$method,
array $parameters = array()
) {
$allowedMethods = array(self::METHOD_GET, self::METHOD_POST);
if (!in_array($method, $allowedMethods, false)) {
throw new \InvalidArgumentException(
sprintf(
'Method "%s" is not valid. Allowed methods are %s',
$method,
implode(', ', $allowedMethods)
)
);
}
$parameters = array_merge($this->defaultParameters, $parameters);
$url = $this->url . $path;
if (self::METHOD_GET === $method && count($parameters)) {
$url .= '?' . http_build_query($parameters, '', '&');
}
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, $url);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlHandler, CURLOPT_FAILONERROR, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, 30);
curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, 30);
if (self::METHOD_POST === $method) {
curl_setopt($curlHandler, CURLOPT_POST, true);
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $parameters);
}
$responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
$errno = curl_errno($curlHandler);
$error = curl_error($curlHandler);
curl_close($curlHandler);
if ($errno
&& in_array($errno, $this->curlErrors, false)
&& $this->retry < 3
) {
$errno = null;
$error = null;
++$this->retry;
$this->makeRequest($path, $method, $parameters);
}
if ($errno) {
throw new CurlException($error, $errno);
}
return new ApiResponse($statusCode, $responseBody);
}
/**
* Retry connect
*
* @return int
*/
public function getRetry()
{
return $this->retry;
}
}

View File

@ -4,7 +4,7 @@ class Logger
private $logPath;
private $files;
public function __construct($logPath = '/bitrix/modules/intaro.intarocrm/classes/general/log', $files = 3)
public function __construct($logPath = '/bitrix/modules/intaro.retailcrm/log', $files = 3)
{
$this->logPath = $logPath;
$this->files = $files;
@ -12,13 +12,17 @@ class Logger
public function write($dump, $file = 'info')
{
$file = $_SERVER["DOCUMENT_ROOT"] . $this->logPath . '/' . $file . '.log';
// message prefix with current time
$rsSites = CSite::GetList($by, $sort, array('DEF' => 'Y'));
$ar = $rsSites->Fetch();
if (!is_dir($ar['ABS_DOC_ROOT'] . $this->logPath . '/'))
{
mkdir($ar['ABS_DOC_ROOT'] . $this->logPath . '/');
}
$file = $ar['ABS_DOC_ROOT'] . $this->logPath . '/' . $file . '.log';
$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);
@ -36,7 +40,8 @@ class Logger
$path['dirname'],
'/',
$path['filename'],
date('YmdHis'),
'_',
date('Y-m-d_H:i:s'),
'.',
$path['extension']
));
@ -44,7 +49,7 @@ class Logger
copy($file, $rotate);
$this->clean($file);
$files = glob($path['dirname'] . '/' . "*" . $path['filename'] . ".log");
$files = glob($path['dirname'] . '/' . $path['filename'] . "*" . ".log");
if (0 === $this->files) {
return;
@ -52,6 +57,7 @@ class Logger
if (count($files) > $this->files) {
natsort($files);
$files = array_reverse($files);
foreach (array_slice($files, $this->files) as $log) {
if (is_writable($log)) {
unlink($log);

View File

@ -0,0 +1,259 @@
<?php
IncludeModuleLangFile(__FILE__);
class RCrmActions
{
public static $MODULE_ID = 'intaro.retailcrm';
public static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
public static function SitesList(){
$arSites = array();
$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
while ($ar = $rsSites->Fetch()){
$arSites[] = $ar;
}
return $arSites;
}
public static function OrderTypesList($arSites){
$orderTypesList = array();
foreach($arSites as $site){
$personTypes = \Bitrix\Sale\PersonType::load($site['LID']);
$bitrixOrderTypesList = array();
foreach($personTypes as $personType){
if(!array_key_exists($personType['ID'], $orderTypesList)){
$bitrixOrderTypesList[$personType['ID']] = $personType;
}
asort($bitrixOrderTypesList);
}
$orderTypesList = $orderTypesList + $bitrixOrderTypesList;
}
return $orderTypesList;
}
public static function DeliveryList(){
$bitrixDeliveryTypesList = array();
$arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
$noOrderId = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId();
foreach($arDeliveryServiceAll as $arDeliveryService){
if($arDeliveryService['PARENT_ID'] == '0' && $arDeliveryService['ID'] != $noOrderId){
$bitrixDeliveryTypesList[] = $arDeliveryService;
}
}
return $bitrixDeliveryTypesList;
}
public static function PaymentList(){
$bitrixPaymentTypesList = array();
$dbPaymentAll = \Bitrix\Sale\PaySystem\Manager::getList(array(
'select' => array('ID', 'NAME'),
'filter' => array('ACTIVE' => 'Y')
));
while($payment = $dbPaymentAll->fetch())
{
$bitrixPaymentTypesList[] = $payment;
}
return $bitrixPaymentTypesList;
}
public static function StatusesList(){
$bitrixPaymentStatusesList = array();
$arStatusesAll = \Bitrix\Sale\OrderStatus::getAllStatusesNames();
foreach($arStatusesAll as $key => $arStatus){
$bitrixPaymentStatusesList[$key] = array('ID' => $key, 'NAME' => $arStatus);
}
return $bitrixPaymentStatusesList;
}
public static function OrderPropsList(){
$bitrixPropsList = array();
$arPropsAll = \Bitrix\Sale\Internals\OrderPropsTable::getList(array(
'select' => array('*')
));
while ($prop = $arPropsAll->Fetch()){
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
}
return $bitrixPropsList;
}
/**
*
* w+ event in bitrix log
*/
public static function eventLog($auditType, $itemId, $description) {
CEventLog::Add(array(
"SEVERITY" => "SECURITY",
"AUDIT_TYPE_ID" => $auditType,
"MODULE_ID" => self::$MODULE_ID,
"ITEM_ID" => $itemId,
"DESCRIPTION" => $description,
));
}
/**
*
* Agent function
*
* @return self name
*/
public static function uploadOrdersAgent() {
RetailCrmOrder::uploadOrders();
$failedIds = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, 0));
if (is_array($failedIds) && !empty($failedIds)) {
RetailCrmOrder::uploadOrders(50, true);
}
return 'RCrmActions::uploadOrdersAgent();';
}
/**
*
* Agent function
*
* @return self name
*/
public static function orderAgent() {
if(COption::GetOptionString('main', 'agents_use_crontab', 'N') != 'N') {
define('NO_AGENT_CHECK', true);
}
RetailCrmHistory::customerHistory();
RetailCrmHistory::orderHistory();
self::uploadOrdersAgent();
return 'RCrmActions::orderAgent();';
}
/**
* removes all empty fields from arrays
* working with nested arrs
*
* @param array $arr
* @return array
*/
public static function clearArr($arr) {
if (is_array($arr) === false) {
return $arr;
}
$result = array();
foreach ($arr as $index => $node ) {
$result[ $index ] = is_array($node) === true ? self::clearArr($node) : trim($node);
if ($result[ $index ] == '' || $result[ $index ] === null || count($result[ $index ]) < 1) {
unset($result[ $index ]);
}
}
return $result;
}
/**
*
* @global $APPLICATION
* @param $str in SITE_CHARSET
* @return $str in utf-8
*/
public static function toJSON($str) {
global $APPLICATION;
return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8');
}
/**
*
* @global $APPLICATION
* @param $str in utf-8
* @return $str in SITE_CHARSET
*/
public static function fromJSON($str) {
global $APPLICATION;
return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET);
}
public static function explodeFIO($fio) {
$newFio = empty($fio) ? false : explode(" ", $fio, 3);
$result = array();
switch (count($newFio)) {
default:
case 0:
$result['firstName'] = $fio;
break;
case 1:
$result['firstName'] = $newFio[0];
break;
case 2:
$result = array(
'lastName' => $newFio[0],
'firstName' => $newFio[1]
);
break;
case 3:
$result = array(
'lastName' => $newFio[0],
'firstName' => $newFio[1],
'patronymic' => $newFio[2]
);
break;
}
return $result;
}
public static function apiMethod($api, $methodApi, $method, $params, $site = null) {
switch($methodApi){
case 'ordersGet':
case 'ordersEdit':
case 'customersGet':
case 'customersEdit':
try {
$result = $api->$methodApi($params, 'externalId', $site);
} catch (\RetailCrm\Exception\CurlException $e) {
self::eventLog(
__CLASS__.'::'.$method, 'RetailCrm\ApiClient::'.$methodApi.'::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
return false;
} catch (InvalidArgumentException $e) {
self::eventLog(
__CLASS__.'::'.$method, 'RetailCrm\ApiClient::'.$methodApi.'::InvalidArgumentException',
$e->getCode() . ': ' . $e->getMessage()
);
return false;
}
return $result;
default:
try {
$result = $api->$methodApi($params, $site);
} catch (\RetailCrm\Exception\CurlException $e) {
self::eventLog(
__CLASS__.'::'.$method, 'RetailCrm\ApiClient::'.$methodApi.'::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
return false;
} catch (InvalidArgumentException $e) {
self::eventLog(
__CLASS__.'::'.$method, 'RetailCrm\ApiClient::'.$methodApi.'::InvalidArgumentException',
$e->getCode() . ': ' . $e->getMessage()
);
return false;
}
return $result;
}
}
}

View File

@ -1,11 +1,31 @@
<?php
/**
* PHP version 5.3
*
* Response from retailCRM API
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/
namespace RetailCrm\Response;
use RetailCrm\Exception\InvalidJsonException;
/**
* PHP version 5.3
*
* Response from retailCRM API
*
* @category RetailCrm
* @package RetailCrm
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion3
*/
class ApiResponse implements \ArrayAccess
{
@ -15,6 +35,14 @@ class ApiResponse implements \ArrayAccess
// response assoc array
protected $response;
/**
* ApiResponse constructor.
*
* @param int $statusCode HTTP status code
* @param mixed $responseBody HTTP body
*
* @throws InvalidJsonException
*/
public function __construct($statusCode, $responseBody = null)
{
$this->statusCode = (int) $statusCode;
@ -56,7 +84,11 @@ class ApiResponse implements \ArrayAccess
/**
* Allow to access for the property throw class method
*
* @param string $name
* @param string $name method name
* @param mixed $arguments method parameters
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function __call($name, $arguments)
@ -74,7 +106,10 @@ class ApiResponse implements \ArrayAccess
/**
* Allow to access for the property throw object property
*
* @param string $name
* @param string $name property name
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function __get($name)
@ -87,8 +122,13 @@ class ApiResponse implements \ArrayAccess
}
/**
* @param mixed $offset
* @param mixed $value
* Offset set
*
* @param mixed $offset offset
* @param mixed $value value
*
* @throws \BadMethodCallException
* @return void
*/
public function offsetSet($offset, $value)
{
@ -96,7 +136,12 @@ class ApiResponse implements \ArrayAccess
}
/**
* @param mixed $offset
* Offset unset
*
* @param mixed $offset offset
*
* @throws \BadMethodCallException
* @return void
*/
public function offsetUnset($offset)
{
@ -104,7 +149,10 @@ class ApiResponse implements \ArrayAccess
}
/**
* @param mixed $offset
* Check offset
*
* @param mixed $offset offset
*
* @return bool
*/
public function offsetExists($offset)
@ -113,7 +161,12 @@ class ApiResponse implements \ArrayAccess
}
/**
* @param mixed $offset
* Get offset
*
* @param mixed $offset offset
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function offsetGet($offset)

View File

@ -0,0 +1,746 @@
<?php //
//
//namespace RetailCrm;
//
//use RetailCrm\Response\ApiResponse;
//use RetailCrm\Exception\CurlException;
//
///**
// * retailCRM API client class
// */
//class RestApi
//{
// const VERSION = 'v3';
// const METHOD_GET = 'GET';
// const METHOD_POST = 'POST';
//
// protected $client;
// protected $url;
// protected $defaultParameters;
// protected $generatedAt;
//
// /**
// * Site code
// */
// protected $siteCode;
//
// /**
// * Client creating
// *
// * @param string $url - url сайта
// * @param string $apiKey - ключ API
// * @param string $site - символьный код сайта
// * @return mixed
// */
// public function __construct($url, $apiKey, $site = null)
// {
// if ('/' != substr($url, strlen($url) - 1, 1)) {
// $url .= '/';
// }
//
// $url = $url . 'api/' . self::VERSION;
//
// if (false === stripos($url, 'https://')) {
// throw new \InvalidArgumentException('API schema requires HTTPS protocol');
// }
//
// $this->url = $url;
// $this->defaultParameters = array('apiKey' => $apiKey);
// $this->siteCode = $site;
// }
//
// /* Методы для работы с заказами */
// /**
// * Получение заказа по id
// *
// * @param string $id - идентификатор заказа
// * @param string $by - поиск заказа по id или externalId
// * @param string $site - символьный код сайта
// * @return ApiResponse - информация о заказе
// */
// public function ordersGet($id, $by = 'externalId', $site = null)
// {
// $this->checkIdParameter($by);
//
// return $this->makeRequest("/orders/$id", self::METHOD_GET, $this->fillSite($site, array(
// 'by' => $by
// )));
// }
//
// /**
// * Получение списка заказов, удовлетворяющих заданному фильтру
// *
// * @param array $filter - фильтры
// * @param int $page - страница
// * @param int $limit - ограничение на размер выборки
// * @return ApiResponse - информация о заказах
// */
// public function ordersList(array $filter = array(), $page = null, $limit = null)
// {
// $parameters = array();
// if (sizeof($filter)) {
// $parameters['filter'] = $filter;
// }
// if (null !== $page) {
// $parameters['page'] = (int) $page;
// }
// if (null !== $limit) {
// $parameters['limit'] = (int) $limit;
// }
// return $this->makeRequest('/orders', self::METHOD_GET, $parameters);
// }
//
// /**
// * Создание заказа
// *
// * @param array $order - информация о заказе
// * @param string $site - символьный код сайта
// * @return ApiResponse
// */
// public function ordersCreate($order, $site = null)
// {
// if (!sizeof($order)) {
// throw new \InvalidArgumentException('Parameter `order` must contains a data');
// }
//
// return $this->makeRequest("/orders/create", self::METHOD_POST, $this->fillSite($site, array(
// 'order' => json_encode($order)
// )));
// }
//
// /**
// * Изменение заказа
// *
// * @param array $order - информация о заказе
// * @param string $by - изменение заказа по id или externalId
// * @param string $site - символьный код сайта
// * @return ApiResponse
// */
// public function orderEdit($order, $by = 'externalId', $site = null)
// {
// if (!sizeof($order)) {
// throw new \InvalidArgumentException('Parameter `order` must contains a data');
// }
//
// $this->checkIdParameter($by);
//
// if (!isset($order[$by])) {
// throw new \InvalidArgumentException(sprintf('Order array must contain the "%s" parameter.', $by));
// }
//
// return $this->makeRequest(
// "/orders/" . $order[$by] . "/edit",
// self::METHOD_POST,
// $this->fillSite($site, array(
// 'order' => json_encode($order),
// 'by' => $by,
// ))
// );
// }
//
// /**
// * Пакетная загрузка заказов
// *
// * @param array $orders - массив заказов
// * @param string $site - символьный код сайта
// * @return ApiResponse
// */
// public function orderUpload($orders, $site = null)
// {
// if (!sizeof($orders)) {
// throw new \InvalidArgumentException('Parameter `orders` must contains array of the orders');
// }
//
// return $this->makeRequest("/orders/upload", self::METHOD_POST, $this->fillSite($site, array(
// 'orders' => json_encode($orders),
// )));
// }
//
// /**
// * Обновление externalId у заказов с переданными id
// *
// * @param array $order - массив, содержащий id и externalId заказа
// * @return ApiResponse
// */
// public function orderFixExternalIds($order)
// {
// if (!sizeof($order)) {
// throw new \InvalidArgumentException('Method parameter must contains at least one IDs pair');
// }
//
// return $this->makeRequest("/orders/fix-external-ids", self::METHOD_POST, array(
// 'orders' => json_encode($order),
// ));
// }
//
// /**
// * Получение последних измененных заказов
// *
// * @param \DateTime|string|int $startDate - начальная дата и время выборки (Y-m-d H:i:s)
// * @param \DateTime|string|int $endDate - конечная дата и время выборки (Y-m-d H:i:s)
// * @param int $limit - ограничение на размер выборки
// * @param int $offset - сдвиг
// * @param bool $skipMyChanges
// * @return ApiResponse
// */
// public function orderHistory(
// $startDate = null,
// $endDate = null,
// $limit = 100,
// $offset = 0,
// $skipMyChanges = true
// ) {
// $parameters = array();
//
// if ($startDate) {
// $parameters['startDate'] = $this->ensureDateTime($startDate);
// }
// if ($endDate) {
// $parameters['endDate'] = $this->ensureDateTime($endDate);
// }
// if ($limit) {
// $parameters['limit'] = (int) $limit;
// }
// if ($offset) {
// $parameters['offset'] = (int) $offset;
// }
// if ($skipMyChanges) {
// $parameters['skipMyChanges'] = (bool) $skipMyChanges;
// }
//
// return $this->makeRequest('/orders/history', self::METHOD_GET, $parameters);
// }
//
// /* Методы для работы с клиентами */
// /**
// * Получение клиента по id
// *
// * @param string $id - идентификатор
// * @param string $by - поиск заказа по id или externalId
// * @param string $site - символьный код сайта
// * @return array - информация о клиенте
// */
// public function customerGet($id, $by = 'externalId', $site = null)
// {
// $this->checkIdParameter($by);
//
// return $this->makeRequest("/customers/$id", self::METHOD_GET, $this->fillSite($site, array(
// 'by' => $by
// )));
// }
//
// /**
// * Получение списка клиентов в соответсвии с запросом
// *
// * @param array $filter - фильтры
// * @param int $page - страница
// * @param int $limit - ограничение на размер выборки
// * @return ApiResponse
// */
// public function customersList(array $filter = array(), $page = null, $limit = null)
// {
// $parameters = array();
//
// if (sizeof($filter)) {
// $parameters['filter'] = $filter;
// }
//
// if (null !== $page) {
// $parameters['page'] = (int) $page;
// }
//
// if (null !== $limit) {
// $parameters['limit'] = (int) $limit;
// }
//
// return $this->makeRequest('/customers', self::METHOD_GET, $parameters);
// }
//
// /**
// * Создание клиента
// *
// * @param array $customer - информация о клиенте
// * @param string $site - символьный код сайта
// * @return ApiResponse
// */
// public function customersCreate(array $customer, $site = null)
// {
// if (!sizeof($customer)) {
// throw new \InvalidArgumentException('Parameter `customer` must contains a data');
// }
//
// return $this->makeRequest("/customers/create", self::METHOD_POST, $this->fillSite($site, array(
// 'customer' => json_encode($customer)
// )));
// }
//
// /**
// * Редактирование клиента
// *
// * @param array $customer - информация о клиенте
// * @param string $by - изменение клиента по id или externalId
// * @param string $site - символьный код сайта
// * @return ApiResponse
// */
// public function customerEdit($customer, $by = 'externalId', $site = null)
// {
// if (!sizeof($customer)) {
// throw new \InvalidArgumentException('Parameter `customer` must contains a data');
// }
//
// $this->checkIdParameter($by);
//
// if (!isset($customer[$by])) {
// throw new \InvalidArgumentException(sprintf('Customer array must contain the "%s" parameter.', $by));
// }
//
// return $this->makeRequest(
// "/customers/" . $customer[$by] . "/edit",
// self::METHOD_POST,
// $this->fillSite($site, array(
// 'customer' => json_encode($customer),
// 'by' => $by,
// )
// ));
// }
//
// /**
// * Пакетная загрузка клиентов
// *
// * @param array $customers - массив клиентов
// * @param string $site - символьный код сайта
// * @return ApiResponse
// */
// public function customerUpload($customers, $site = null)
// {
// if (!sizeof($customers)) {
// throw new \InvalidArgumentException('Parameter `customers` must contains array of the customers');
// }
//
// return $this->makeRequest("/customers/upload", self::METHOD_POST, $this->fillSite($site, array(
// 'customers' => json_encode($customers),
// )));
// }
//
// /**
// * Обновление externalId у клиентов с переданными id
// *
// * @param array $customers - массив, содержащий id и externalId заказа
// * @return array
// */
// public function customerFixExternalIds($customers)
// {
// if (!sizeof($customers)) {
// throw new \InvalidArgumentException('Method parameter must contains at least one IDs pair');
// }
//
// return $this->makeRequest("/customers/fix-external-ids", self::METHOD_POST, array(
// 'customers' => json_encode($customers),
// ));
// }
//
// /* Методы для работы со справочниками */
//
// /**
// * Получение списка типов доставки
// *
// * @return ApiResponse
// */
// public function deliveryTypesList()
// {
// return $this->makeRequest('/reference/delivery-types', self::METHOD_GET);
// }
//
// /**
// * Редактирование типа доставки
// *
// * @param array $delivery - информация о типе доставки
// * @return ApiResponse
// */
// public function deliveryTypeEdit($delivery)
// {
// if (!isset($delivery['code'])) {
// throw new \InvalidArgumentException('Data must contain "code" parameter.');
// }
//
// return $this->makeRequest(
// '/reference/delivery-types/' . $delivery['code'] . '/edit',
// self::METHOD_POST,
// array(
// 'deliveryType' => json_encode($delivery)
// )
// );
// }
//
// /**
// * Получение списка служб доставки
// *
// * @return ApiResponse
// */
// public function deliveryServicesList()
// {
// return $this->makeRequest('/reference/delivery-services', self::METHOD_GET);
// }
//
// /**
// * Редактирование службы доставки
// *
// * @param array $delivery - информация о типе доставки
// * @return ApiResponse
// */
// public function deliveryServiceEdit($delivery)
// {
// if (!isset($delivery['code'])) {
// throw new \InvalidArgumentException('Data must contain "code" parameter.');
// }
//
// return $this->makeRequest(
// '/reference/delivery-services/' . $delivery['code'] . '/edit',
// self::METHOD_POST,
// array(
// 'deliveryService' => json_encode($delivery)
// )
// );
// }
//
//
// /**
// * Получение списка типов оплаты
// *
// * @return ApiResponse
// */
// public function paymentTypesList()
// {
// return $this->makeRequest('/reference/payment-types', self::METHOD_GET);
// }
//
// /**
// * Редактирование типа оплаты
// *
// * @param array $paymentType - информация о типе оплаты
// * @return ApiResponse
// */
// public function paymentTypesEdit($paymentType)
// {
// if (!isset($paymentType['code'])) {
// throw new \InvalidArgumentException('Data must contain "code" parameter.');
// }
//
// return $this->makeRequest(
// '/reference/payment-types/' . $paymentType['code'] . '/edit',
// self::METHOD_POST,
// array(
// 'paymentType' => json_encode($paymentType)
// )
// );
// }
//
//
// /**
// * Получение списка статусов оплаты
// *
// * @return ApiResponse
// */
// public function paymentStatusesList()
// {
// return $this->makeRequest('/reference/payment-statuses', self::METHOD_GET);
// }
//
// /**
// * Редактирование статуса оплаты
// *
// * @param array $paymentStatus - информация о статусе оплаты
// * @return ApiResponse
// */
// public function paymentStatusesEdit($paymentStatus)
// {
// if (!isset($paymentStatus['code'])) {
// throw new \InvalidArgumentException('Data must contain "code" parameter.');
// }
//
// return $this->makeRequest(
// '/reference/payment-statuses/' . $paymentStatus['code'] . '/edit',
// self::METHOD_POST,
// array(
// 'paymentStatus' => json_encode($paymentStatus)
// )
// );
// }
//
//
// /**
// * Получение списка типов заказа
// *
// * @return ApiResponse
// */
// public function orderTypesList()
// {
// return $this->makeRequest('/reference/order-types', self::METHOD_GET);
// }
//
// /**
// * Редактирование типа заказа
// *
// * @param array $orderType - информация о типе заказа
// * @return ApiResponse
// */
// public function orderTypesEdit($orderType)
// {
// if (!isset($orderType['code'])) {
// throw new \InvalidArgumentException('Data must contain "code" parameter.');
// }
//
// return $this->makeRequest(
// '/reference/order-types/' . $orderType['code'] . '/edit',
// self::METHOD_POST,
// array(
// 'orderType' => json_encode($orderType)
// )
// );
// }
//
//
// /**
// * Получение списка способов оформления заказа
// *
// * @return ApiResponse
// */
// public function orderMethodsList()
// {
// return $this->makeRequest('/reference/order-methods', self::METHOD_GET);
// }
//
// /**
// * Редактирование способа оформления заказа
// *
// * @param array $orderMethod - информация о способе оформления заказа
// * @return ApiResponse
// */
// public function orderMethodsEdit($orderMethod)
// {
// if (!isset($orderMethod['code'])) {
// throw new \InvalidArgumentException('Data must contain "code" parameter.');
// }
//
// return $this->makeRequest(
// '/reference/order-methods/' . $orderMethod['code'] . '/edit',
// self::METHOD_POST,
// array(
// 'orderMethod' => json_encode($orderMethod)
// )
// );
// }
//
// /**
// * Получение списка статусов заказа
// *
// * @return ApiResponse
// */
// public function orderStatusesList()
// {
// return $this->makeRequest('/reference/statuses', self::METHOD_GET);
// }
//
// /**
// * Получение списка сайтов
// *
// * @return ApiResponse
// */
// public function sitesList()
// {
// return $this->makeRequest('/reference/sites', self::METHOD_GET);
// }
//
// /**
// * Редактирование статуса заказа
// *
// * @param array $status - информация о статусе заказа
// * @return ApiResponse
// */
// public function orderStatusEdit($status)
// {
// if (!isset($status['code'])) {
// throw new \InvalidArgumentException('Data must contain "code" parameter.');
// }
//
// return $this->makeRequest(
// '/reference/statuses/' . $status['code'] . '/edit',
// self::METHOD_POST,
// array(
// 'status' => json_encode($status)
// )
// );
// }
//
//
// /**
// * Получение списка групп статусов заказа
// *
// * @return ApiResponse
// */
// public function orderStatusGroupsList()
// {
// return $this->makeRequest('/reference/status-groups', self::METHOD_GET);
// }
//
// /**
// * Обновление статистики
// *
// * @return ApiResponse
// */
// public function statisticUpdate()
// {
// return $this->makeRequest('/statistic/update', self::METHOD_GET);
// }
//
// /**
// * Обновление остатков
// *
// * @return ApiResponse
// */
// public function storeUpload($data, $site)
// {
// if (!sizeof($data)) {
// throw new \InvalidArgumentException('Parameter `site` must contains array of the customers');
// }
//
// return $this->makeRequest('/store/inventories/upload', self::METHOD_POST, $this->fillSite($site, array('offers' => json_encode($data))));
// }
//
// /**
// * Редактирование сведений о складе
// *
// * @return ApiResponse
// */
// public function storesEdit($data)
// {
// if (!isset($data['code'])) {
// throw new \InvalidArgumentException('Data must contain "code" parameter.');
// }
//
// return $this->makeRequest(
// '/reference/stores/' . $data['code'] . '/edit',
// self::METHOD_POST,
// array(
// 'store' => json_encode($data)
// )
// );
// }
//
// /**
// * @return \DateTime
// */
// public function getGeneratedAt()
// {
// return $this->generatedAt;
// }
//
// protected function ensureDateTime($value)
// {
// if ($value instanceof \DateTime) {
// return $value->format('Y-m-d H:i:s');
// } elseif (is_int($value)) {
// return date('Y-m-d H:i:s', $value);
// }
//
// return $value;
// }
//
// /**
// * Check ID parameter
// *
// * @param string $by
// * @return bool
// */
// protected function checkIdParameter($by)
// {
// $allowedForBy = array('externalId', 'id');
// if (!in_array($by, $allowedForBy)) {
// throw new \InvalidArgumentException(sprintf(
// 'Value "%s" for parameter "by" is not valid. Allowed values are %s.',
// $by,
// implode(', ', $allowedForBy)
// ));
// }
// return true;
// }
//
// /**
// * Fill params by site value
// *
// * @param string $site
// * @param array $params
// * @return array
// */
// protected function fillSite($site, array $params)
// {
// if ($site) {
// $params['site'] = $site;
// } elseif ($this->siteCode) {
// $params['site'] = $this->siteCode;
// }
//
// return $params;
// }
//
// /**
// * Make HTTP request
// *
// * @param string $path
// * @param string $method (default: 'GET')
// * @param array $parameters (default: array())
// * @param int $timeout
// * @return ApiResponse
// */
// public function makeRequest($path, $method, $parameters = array(), $timeout = 30)
// {
// $allowedMethods = array(self::METHOD_GET, self::METHOD_POST);
// if (!in_array($method, $allowedMethods)) {
// throw new \InvalidArgumentException(sprintf(
// 'Method "%s" is not valid. Allowed methods are %s',
// $method,
// implode(', ', $allowedMethods)
// ));
// }
//
// $parameters = array_merge($this->defaultParameters, $parameters);
//
// $path = $this->url . $path;
// if (self::METHOD_GET === $method && sizeof($parameters)) {
// $path .= '?' . http_build_query($parameters);
// }
//
// $ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, $path);
// curl_setopt($ch, CURLOPT_FAILONERROR, false);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
// curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout); // times out after 30s
// // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
//
// if (self::METHOD_POST === $method) {
// curl_setopt($ch, CURLOPT_POST, true);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
// }
//
// $responseBody = curl_exec($ch);
// $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//
// $errno = curl_errno($ch);
// $error = curl_error($ch);
// curl_close($ch);
//
// if ($errno) {
// throw new CurlException($error, $errno);
// }
//
// $result = json_decode($responseBody, true);
//
// if (isset($result['generatedAt'])) {
// $this->generatedAt = new \DateTime($result['generatedAt']);
// unset($result['generatedAt']);
// }
//
// return new ApiResponse($statusCode, $responseBody);
// }
//}

View File

@ -1,45 +1,4 @@
<?php
/**
* RestNormalizer
*
* Copyright (c) 2015, Dmitry Mamontov <d.slonyara@gmail.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Dmitry Mamontov nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package restnormalizer
* @author Dmitry Mamontov <d.slonyara@gmail.com>
* @copyright 2015 Dmitry Mamontov <d.slonyara@gmail.com>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @since File available since Release 1.0.0
*/
/**
* RestNormalizer - The main class
@ -54,26 +13,10 @@
class RestNormalizer
{
/**
* Cleanup of null values
* @var boolean
* @access public
*/
public $clear = true;
/**
* Sorted file validation
* @var array
* @access private
*/
private $validation = array();
/**
* File validation
* @var array
* @access private
*/
private $originalValidation = array();
private $originalValidation = array();
private $server;
/**
* Class constructor
@ -86,6 +29,7 @@ class RestNormalizer
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
date_default_timezone_set(@date_default_timezone_get());
}
$this->server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot();
}
/**
@ -95,15 +39,16 @@ class RestNormalizer
* @access public
* @final
*/
final public function setValidation($file)
{
if (is_null($file) || is_file($file) === false
|| json_decode(file_get_contents($file)) === null
|| $this->parseConfig($file) === false) {
ICrmOrderActions::eventLog('RestNormalizer', 'intaro.intarocrm', 'Incorrect file normalize.');
return false;
}
}
// final public function setValidation($file = false)
// {
// if ($file === false || is_null($file) || is_file($file) === false) {
// $file = $this->server . '/bitrix/modules/intaro.intarocrm/classes/general/config/retailcrm.json';
// }
// if (json_decode(file_get_contents($file)) === null || $this->parseConfig($file) === false) {
// ICrmOrderActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect file normalize.');
// return false;
// }
// }
/**
* Parsing the file validation
@ -130,8 +75,17 @@ class RestNormalizer
* @access public
* @final
*/
final public function normalize($data, $key = false)
final public function normalize($data, $key = false, $file = '/bitrix/modules/intaro.retailcrm/classes/general/config/retailcrm.json')
{
$server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot();
$file = $server . $file;
if (is_null($file) || is_file($file) === false
|| json_decode(file_get_contents($file)) === null
|| $this->parseConfig($file) === false) {
ICrmOrderActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect file normalize.');
return false;
}
if (is_string($data)) {
$data = json_decode($data, true);
}
@ -143,7 +97,7 @@ class RestNormalizer
}
if (!is_array($data) || count($data) < 1) {
ICrmOrderActions::eventLog('RestNormalizer', 'intaro.intarocrm', 'Incorrect data array.');
ICrmOrderActions::eventLog('RestNormalizer', 'intaro.retailcrm', 'Incorrect data array.');
return false;
}
@ -188,7 +142,7 @@ class RestNormalizer
if ($skip === false) {
foreach ($this->validation as $code => $valid) {
if (isset($valid['required']) && $valid['required'] === true && isset($formatted[ $code ]) === false) {
ICrmOrderActions::eventLog('RestNormalizer', 'intaro.intarocrm', "NOT VALID: $code");
ICrmOrderActions::eventLog('RestNormalizer', 'intaro.retailcrm', "NOT VALID: $code");
}
}

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<options>
<fields>
<field id="id" group="customer">id</field>
<field id="first_name" group="customer">firstName</field>
<field id="last_name" group="customer">lastName</field>
<field id="patronymic" group="customer">patronymic</field>
<field id="email" group="customer">email</field>
<field id="birthday" group="customer">birthday</field>
<field id="phones" group="customer">phones</field>
<field id="manager" group="customer">manager</field>
<field id="commentary" group="customer">commentary</field>
<field id="external_id" group="customer">externalId</field>
<field id="cumulative_discount" group="customer">cumulativeDiscount</field>
<field id="personal_discount" group="customer">personalDiscount</field>
<field id="discount_card_number" group="customer">discountCardNumber</field>
<field id="address.index" group="customerAddress">index</field>
<field id="address.country" group="customerAddress">countryIso</field>
<field id="address.region" group="customerAddress">region</field>
<field id="address.city" group="customerAddress">city</field>
<field id="address.street" group="customerAddress">street</field>
<field id="address.building" group="customerAddress">building</field>
<field id="address.house" group="customerAddress">house</field>
<field id="address.block" group="customerAddress">block</field>
<field id="address.flat" group="customerAddress">flat</field>
<field id="address.floor" group="customerAddress">floor</field>
<field id="address.intercom_code" group="customerAddress">intercomCode</field>
<field id="address.metro" group="customerAddress">metro</field>
<field id="address.notes" group="customerAddress">notes</field>
<field id="contragent.contragent_type" group="customerContragent">contragentType</field>
<field id="contragent.legal_name" group="customerContragent">legalName</field>
<field id="contragent.legal_address" group="customerContragent">legalAddress</field>
<field id="contragent.certificate_number" group="customerContragent">certificateNumber</field>
<field id="contragent.certificate_date" group="customerContragent">certificateDate</field>
<field id="contragent.bank" group="customerContragent">bank</field>
<field id="contragent.bank_address" group="customerContragent">bankAddress</field>
<field id="contragent.corr_account" group="customerContragent">corrAccount</field>
<field id="contragent.bank_account" group="customerContragent">bankAccount</field>
<field id="id" group="order">id</field>
<field id="created_at" group="order">createdAt</field>
<field id="order_type" group="order">orderType</field>
<field id="order_method" group="order">orderMethod</field>
<field id="site" group="order">site</field>
<field id="status" group="order">status</field>
<field id="status_comment" group="order">statusComment</field>
<field id="manager" group="order">manager</field>
<field id="first_name" group="order">firstName</field>
<field id="last_name" group="order">lastName</field>
<field id="patronymic" group="order">patronymic</field>
<field id="phone" group="order">phone</field>
<field id="additional_phone" group="order">additionalPhone</field>
<field id="email" group="order">email</field>
<field id="payment_type" group="order">paymentType</field>
<field id="payment_status" group="order">paymentStatus</field>
<field id="discount" group="order">discount</field>
<field id="discount_percent" group="order">discountPercent</field>
<field id="prepay_sum" group="order">prepaySum</field>
<field id="customer_comment" group="order">customerComment</field>
<field id="manager_comment" group="order">managerComment</field>
<field id="shipment_store" group="order">shipmentStore</field>
<field id="shipment_date" group="order">shipmentDate</field>
<field id="shipped" group="order">shipped</field>
<!--<field id="order_product" group="order">item</field>-->
<field id="order_product.id" group="item">id</field>
<field id="order_product.initial_price" group="item">initialPrice</field>
<field id="order_product.discount" group="item">discount</field>
<field id="order_product.discount_percent" group="item">discountPercent</field>
<field id="order_product.quantity" group="item">quantity</field>
<field id="order_product.status" group="item">status</field>
<field id="delivery_type" group="delivery">code</field>
<field id="delivery_service" group="delivery">service</field>
<field id="delivery_date" group="delivery">date</field>
<field id="delivery_time" group="delivery">time</field>
<field id="delivery_cost" group="delivery">cost</field>
<field id="delivery_net_cost" group="delivery">netCost</field>
<field id="delivery_address.country" group="orderAddress">country</field>
<field id="delivery_address.index" group="orderAddress">index</field>
<field id="delivery_address.region" group="orderAddress">region</field>
<field id="delivery_address.city" group="orderAddress">city</field>
<field id="delivery_address.street" group="orderAddress">street</field>
<field id="delivery_address.building" group="orderAddress">building</field>
<field id="delivery_address.house" group="orderAddress">house</field>
<field id="delivery_address.block" group="orderAddress">block</field>
<field id="delivery_address.flat" group="orderAddress">flat</field>
<field id="delivery_address.floor" group="orderAddress">floor</field>
<field id="delivery_address.intercom_code" group="orderAddress">intercomCode</field>
<field id="delivery_address.metro" group="orderAddress">metro</field>
<field id="delivery_address.notes" group="orderAddress">notes</field>
<field id="integration_delivery_data.status" group="integrationDelivery">status</field>
<field id="integration_delivery_data.track_number" group="integrationDelivery">trackNumber</field>
<field id="integration_delivery_data.courier" group="integrationDelivery">courier</field>
</fields>
</options>

View File

@ -13,7 +13,7 @@
<field id="city">Город</field>
<field id="index">Индекс</field>
<field id="street">Улица</field>
<field id="building">Строение</field>
<field id="building">Номер дома</field>
<field id="flat">Квартира</field>
<field id="intercomcode">Домофон</field>
<field id="floor">Этаж</field>

View File

@ -377,6 +377,9 @@
},
"text": {
"type": "string"
},
"shipmentStore": {
"type": "string"
}
}
}

View File

@ -0,0 +1,216 @@
<?php
/**
* RCrmEvent
*/
class RetailCrmEvent {
protected static $MODULE_ID = 'intaro.retailcrm';
protected static $CRM_API_HOST_OPTION = 'api_host';
protected static $CRM_API_KEY_OPTION = 'api_key';
protected static $CRM_ORDER_TYPES_ARR = 'order_types_arr';
protected static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
protected static $CRM_PAYMENT_TYPES = 'pay_types_arr';
protected static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
protected static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
protected static $CRM_ORDER_LAST_ID = 'order_last_id';
protected static $CRM_ORDER_PROPS = 'order_props';
protected static $CRM_LEGAL_DETAILS = 'legal_details';
protected static $CRM_CUSTOM_FIELDS = 'custom_fields';
protected static $CRM_CONTRAGENT_TYPE = 'contragent_type';
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
protected static $CRM_SITES_LIST = 'sites_list';
/**
* OnAfterUserUpdate
*
* @param mixed $arFields - User arFields
*/
function OnAfterUserUpdate($arFields) {
if(isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']){
return;
}
if(!$arFields['RESULT']){
return;
}
$customer = array(
'externalId' => $arFields['ID'],
'firstName' => $arFields['NAME'],
'lastName' => $arFields['LAST_NAME'],
'patronymic' => $arFields['SECOND_NAME'],
'email' => $arFields['EMAIL']
);
if(isset($arFields['PERSONAL_PHONE'])){
$customer['phones'][]['number'] = $arFields['PERSONAL_PHONE'];
}
if(isset($arFields['WORK_PHONE'])){
$customer['phones'][]['number'] = $arFields['WORK_PHONE'];
}
if (function_exists('retailcrmBeforeCustomerSend')) {
$newResCustomer = intarocrm_before_customer_send($customer);
if (is_array($newResCustomer) && !empty($newResCustomer)) {
$customer = $newResCustomer;
}
}
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
$api = new RetailCrm\ApiClient($api_host, $api_key);
//ищем юзера по id и др. данным.
//апдейтим если находим
}
/**
* onBeforeOrderAdd
*
* @param mixed $arFields - User arFields
*/
function onBeforeOrderAdd($arFields = array()) {
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = false;
return;
}
/**
* OnOrderSave
*
* @param mixed $ID - Order id
* @param mixed $arFields - Order arFields
*/
function OnOrderSave($ID, $arFields, $arOrder, $isNew) {
$GLOBALS['RETAILCRM_EVENT_OLD'] = true;
return;
}
/**
* onUpdateOrder
*
* @param mixed $ID - Order id
* @param mixed $arFields - Order arFields
*/
function onUpdateOrder($ID, $arFields) {
if(isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']){
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = false;
return;
}
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = true;
return;
}
/**
* orderDelete
*
* @param object $event - Order object
*/
function orderDelete($event){
$GLOBALS['RETAILCRM_ORDER_DELETE'] = true;
return;
}
/**
* orderSave
*
* @param object $event - Order object
*/
function orderSave($event){
if($GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] !== false && $GLOBALS['RETAIL_CRM_HISTORY'] !== true && $GLOBALS['RETAILCRM_ORDER_DELETE'] !== true){
if (!CModule::IncludeModule('iblock')) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'iblock', 'module not found');
return true;
}
if (!CModule::IncludeModule("sale")) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'sale', 'module not found');
return true;
}
if (!CModule::IncludeModule("catalog")) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'catalog', 'module not found');
return true;
}
//проверка на существование getParameter("ENTITY")
if(method_exists($event, 'getId')){
$obOrder = $event;
}
elseif(method_exists($event, 'getParameter')){
$obOrder = $event->getParameter("ENTITY");
}
else{
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'events', 'event error');
return true;
}
$arOrder = RetailCrmOrder::orderObjToArr($obOrder);
//api
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
$api = new RetailCrm\ApiClient($api_host, $api_key);
//params
$optionsOrderTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0));
$optionsDelivTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 0));
$optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
$optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0));
$optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0));
$optionsContragentType = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CONTRAGENT_TYPE, 0));
$optionsCustomFields = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CUSTOM_FIELDS, 0));
$arParams = RCrmActions::clearArr(array(
'optionsOrderTypes' => $optionsOrderTypes,
'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes,
'optionsPayStatuses' => $optionsPayStatuses,
'optionsPayment' => $optionsPayment,
'optionsOrderProps' => $optionsOrderProps,
'optionsLegalDetails' => $optionsLegalDetails,
'optionsContragentType' => $optionsContragentType,
'optionsSitesList' => $optionsSitesList,
'optionsCustomFields' => $optionsCustomFields
));
//многосайтовость
$site = count($optionsSitesList)>1 ? $optionsSitesList[$arOrder['LID']] : null;
//проверка на новый заказ
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arOrder['ID'], $site);
if(isset($orderCrm['order'])){
$methodApi = 'ordersEdit';
}
else{
$methodApi = 'ordersCreate';
}
//user
$userCrm = RCrmActions::apiMethod($api, 'customersGet', __METHOD__, $arOrder['USER_ID'], $site);
if(!isset($userCrm['customer'])){
$arUser = Bitrix\Main\UserTable::getById($arOrder['USER_ID'])->fetch();
$resultUser = RetailCrmUser::customerSend($arUser, $api, $optionsContragentType[$arOrder['PERSON_TYPE_ID']], true, $site);
if(!$resultUser) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'RetailCrmUser::customerSend', 'error during creating customer');
return true;
}
}
//order
$resultOrder = RetailCrmOrder::orderSend($arOrder, $api, $arParams, true, $site, $methodApi);
if(!$resultOrder) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'RetailCrmOrder::orderSend', 'error during creating order');
return true;
}
return true;
}
return;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,561 @@
<?php
IncludeModuleLangFile(__FILE__);
class RetailCrmICML
{
public $profileID;
public $iblocks;
public $filename;
public $serverName;
public $propertiesSKU;
public $propertiesUnitSKU;
public $propertiesProduct;
public $propertiesUnitProduct;
public $application;
public $encoding = 'utf-8';
public $encodingDefault = 'utf-8';
public $loadPurchasePrice = false;
protected $fp;
protected $mainSection = 1000000;
protected $pageSize = 500;
protected $offerPageSize = 50;
protected $protocol;
protected $isLogged = false;
protected $logFile = '/bitrix/catalog_export/i_crm_load_log.txt';
protected $fpLog;
protected $MODULE_ID = 'intaro.retailcrm';
protected $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
protected $measurement = array (
'mm' => 1, // 1 mm = 1 mm
'cm' => 10, // 1 cm = 10 mm
'm' => 1000,
'mg' => 0.001, // 0.001 g = 1 mg
'g' => 1,
'kg' => 1000,
);
protected $measurementLink = array (
'mm' => 'mm',
'cm' => 'mm',
'm' => 'mm',
'mg' => 'g',
'g' => 'g',
'kg' => 'g',
);
public function Load()
{
global $USER;
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('DEF' => 'Y'))->Fetch();
$this->encodingDefault = $defaultSite["CHARSET"];
$url = 'https://' . $this->serverName;
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, $url);
$responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
curl_close($curlHandler);
if($statusCode == 200){
$this->protocol = 'https://';
}
else{
$this->protocol = 'http://';
}
$this->PrepareSettings();
$this->fp = $this->PrepareFile($this->filename. '.tmp');
if ($this->isLogged) {
$this->fpLog = $this->PrepareFile($this->logFile);
$this->WriteLog("Start Loading");
}
$this->PreWriteCatalog();
$categories = $this->GetCategories();
$this->WriteCategories($categories);
$this->PreWriteOffers();
$this->BuildOffers($categories);
$this->PostWriteOffers();
$this->PostWriteCatalog();
if ($this->isLogged) {
$this->WriteLog("Loading was ended successfully (peek memory usage: " . memory_get_peak_usage() . ")");
}
$this->CloseFile($this->fp);
$this->CloseFile($this->fpLog);
unlink($defaultSite['ABS_DOC_ROOT'] . $this->filename);
rename($defaultSite['ABS_DOC_ROOT'] . $this->filename. '.tmp', $defaultSite['ABS_DOC_ROOT'] . $this->filename);
return true;
}
protected function PrepareSettings()
{
foreach ($this->propertiesSKU as $iblock => $arr) {
foreach ($arr as $id => $sku) {
$this->propertiesSKU[$iblock][$id] = strtoupper($sku);
}
}
foreach ($this->propertiesProduct as $iblock => $arr) {
foreach ($arr as $id => $prod) {
$this->propertiesProduct[$iblock][$id] = strtoupper($prod);
}
}
}
protected function PrepareValue($text)
{
$newText = $this->application->ConvertCharset($text, $this->encodingDefault, $this->encoding);
$newText = strip_tags($newText);
$newText = str_replace("&", "&#x26;", $newText);
return $newText;
}
protected function PrepareFile($filename)
{
$fullFilename = $_SERVER["DOCUMENT_ROOT"] . $filename;
CheckDirPath($fullFilename);
if ($fp = @fopen($fullFilename, "w"))
return $fp;
else
return false;
}
protected function PreWriteCatalog()
{
@fwrite($this->fp, "<yml_catalog date=\"" . $this->PrepareValue(Date("Y-m-d H:i:s")) . "\">\n
<shop>\n
<name>" . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</name>\n
<company>" . $this->PrepareValue(COption::GetOptionString("main", "site_name", ""))."</company>\n"
);
}
protected function WriteCategories($categories)
{
$stringCategories = "";
@fwrite($this->fp, "<categories>\n");
foreach ($categories as $category) {
$stringCategories .= $this->BuildCategory($category);
}
@fwrite($this->fp, $stringCategories);
@fwrite($this->fp, "</categories>\n");
}
protected function PreWriteOffers()
{
@fwrite($this->fp, "<offers>\n");
}
protected function PostWriteOffers()
{
@fwrite($this->fp, "</offers>\n");
}
protected function WriteOffers($offers)
{
@fwrite($this->fp, $offers);
}
protected function WriteLog($text)
{
if ($this->isLogged)
@fwrite($this->fpLog, Date("Y:m:d H:i:s") . ": " . $text . "\n");
}
protected function PostWriteCatalog()
{
@fwrite($this->fp, "</shop>\n
</yml_catalog>\n");
}
protected function CloseFile($fp)
{
@fclose($fp);
}
protected function GetCategories()
{
$categories = array();
foreach ($this->iblocks as $id)
{
$filter = array("IBLOCK_ID" => $id);
$dbRes = CIBlockSection::GetList(array("left_margin" => "asc"), $filter);
$hasCategories = false;
while ($arRes = $dbRes->Fetch()) {
$categories[$arRes['ID']] = $arRes;
$hasCategories = true;
}
if (!$hasCategories) {
$iblock = CIBlock::GetByID($id)->Fetch();
$arRes = Array();
$arRes['ID'] = $this->mainSection + $id;
$arRes['IBLOCK_SECTION_ID'] = 0;
$arRes['NAME'] = sprintf(GetMessage('ROOT_CATEGORY_FOR_CATALOG'), $iblock['NAME']);
$categories[$arRes['ID']] = $arRes;
}
}
return $categories;
}
protected function BuildCategory($arCategory)
{
return "
<category id=\"" . $this->PrepareValue($arCategory["ID"]) . "\""
. ( intval($arCategory["IBLOCK_SECTION_ID"] ) > 0 ?
" parentId=\"" . $this->PrepareValue($arCategory["IBLOCK_SECTION_ID"]) . "\""
:"")
. ">"
. $this->PrepareValue($arCategory["NAME"])
. "</category>\n";
}
protected function BuildOffers(&$allCategories)
{
$basePriceId = COption::GetOptionString(
$this->MODULE_ID,
$this->CRM_CATALOG_BASE_PRICE . (is_null($this->profileID) === false ? '_' . $this->profileID : ''),
1
);
foreach ($this->iblocks as $key => $id)
{
// Get Info by infoblocks
$iblock['IBLOCK_DB'] = CIBlock::GetByID($id)->Fetch();
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($id);
$arSelect = Array (
"ID",
"LID",
"IBLOCK_ID",
"IBLOCK_SECTION_ID",
"ACTIVE",
"NAME",
"DETAIL_PICTURE",
"PREVIEW_PICTURE",
"DETAIL_PAGE_URL",
"CATALOG_GROUP_" . $basePriceId
);
// Set selected properties
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
if ($this->propertiesProduct[$id][$key] != "") {
$arSelect[] = "PROPERTY_" . $propProduct;
$arSelect[] = "PROPERTY_" . $propProduct . ".NAME";
}
}
$arSelectOffer = Array (
'ID',
'ACTIVE',
"NAME",
"DETAIL_PAGE_URL",
"DETAIL_PICTURE",
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'],
"CATALOG_GROUP_" . $basePriceId
);
// Set selected properties
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
if ($this->propertiesSKU[$id][$key] != "") {
$arSelectOffer[] = "PROPERTY_" . $propSKU;
$arSelectOffer[] = "PROPERTY_" . $propSKU . ".NAME";
}
}
// Set filter
$filter = array(
"IBLOCK_ID" => $id
);
$order = array("id");
$arNavStatParams = Array(
"iNumPage" => 1,
"nPageSize" => $this->pageSize,
);
// Cycle page to page
do {
// Get products on this page
$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();
while ($product = $dbResProducts->GetNext()) {
// Compile products to array
$products[$product['ID']] = $product;
$products[$product['ID']]['offers'] = array();
$detailPicture = intval($product["DETAIL_PICTURE"]);
$previewPicture = intval($product["PREVIEW_PICTURE"]);
if ($detailPicture > 0 || $previewPicture > 0)
{
$picture = $detailPicture;
if ($picture <= 0) {
$picture = $previewPicture;
}
// Link pictureID and productID
$pictures[$picture] = $product['ID'];
}
}
unset($product);
unset($detailPicture, $previewPicture, $picture);
$pictureIDs = array_keys($pictures);
// Get pathes of pictures
$dbFiles = CFile::GetList(Array(), Array("@ID" => implode(',', $pictureIDs)));
while($file = $dbFiles->GetNext()) {
// Link picture to product
$products[$pictures[$file['ID']]]['PICTURE'] = $this->protocol .
$this->serverName .
'/upload/' . $file['SUBDIR'] .
'/' . $file['FILE_NAME'] ;
}
unset($pictures);
if (!empty($iblockOffer['IBLOCK_ID'])) {
$arFilterOffer = array(
'IBLOCK_ID' => $iblockOffer['IBLOCK_ID'],
'PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] => array_keys($products),
);
// Get all offers for products on this page
$dbResOffers = CIBlockElement::GetList(
array(),
$arFilterOffer,
false,
array('nTopCount' => $this->pageSize * $this->offerPageSize),
$arSelectOffer
);
while ($offer = $dbResOffers->GetNext()) {
// Link offers to products
$products[$offer['PROPERTY_' . $iblockOffer['SKU_PROPERTY_ID'] . '_VALUE']]['offers'][$offer['ID']] = $offer;
}
unset($offer, $dbResOffers);
}
$stringOffers = "";
foreach ($products as $product) {
// Get properties of product
$resPropertiesProduct = Array();
foreach ($this->propertiesProduct[$id] as $key => $propProduct) {
$resPropertiesProduct[$key] = "";
if ($propProduct != "") {
if (isset($product["PROPERTY_" . $propProduct . "_NAME"])){
$resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_NAME"];
}
elseif (isset($product["PROPERTY_" . $propProduct . "_VALUE"])){
$resPropertiesProduct[$key] = $product["PROPERTY_" . $propProduct . "_VALUE"];
}
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]];
}
}
}
// Get categories of product
$categories = Array();
$dbResCategories = CIBlockElement::GetElementGroups($product['ID'], true);
while ($arResCategory = $dbResCategories->Fetch()) {
$categories[$arResCategory["ID"]] = array(
'ID' => $arResCategory["ID"],
'NAME' => $arResCategory["NAME"],
);
}
if (count($categories) == 0) {
$catId = $this->mainSection + $id;
$categories[$catId] = $allCategories[$catId];
}
$existOffer = false;
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"];
$offer['PRODUCT_NAME'] = $product["NAME"];
$offer['PRODUCT_ACTIVE'] = $offer["ACTIVE"];
$offer['PRICE'] = $offer['CATALOG_PRICE_' . $basePriceId];
$offer['PURCHASE_PRICE'] = $offer['CATALOG_PURCHASING_PRICE'];
$offer['QUANTITY'] = $offer["CATALOG_QUANTITY"];
// Get properties of product
foreach ($this->propertiesSKU[$id] as $key => $propSKU) {
if ($propSKU != "") {
if (isset ($offer["PROPERTY_" . $propSKU . "_NAME"])){
$offer['_PROP_' . $key] = $offer["PROPERTY_" . $propSKU . "_NAME"];
}
elseif (isset($offer["PROPERTY_" . $propSKU . "_VALUE"])){
$offer['_PROP_' . $key] = $offer["PROPERTY_" . $propSKU . "_VALUE"];
}
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])){
$offer['_PROP_' . $key] = $propProduct;
}
}
$stringOffers .= $this->BuildOffer($offer, $categories, $iblock, $allCategories);
$existOffer = true;
}
}
if (!$existOffer) {
$product['PRODUCT_ID'] = $product["ID"];
$product['PRODUCT_NAME'] = $product["NAME"];
$product['PRODUCT_ACTIVE'] = $product["ACTIVE"];
$product['PRICE'] = $product['CATALOG_PRICE_' . $basePriceId];
$product['PURCHASE_PRICE'] = $product['CATALOG_PURCHASING_PRICE'];
$product['QUANTITY'] = $product["CATALOG_QUANTITY"];
foreach ($resPropertiesProduct as $key => $propProduct) {
if ($this->propertiesProduct[$id][$key] != "" || $this->propertiesProduct[$id][str_replace("_UNIT", "", $key)] != "") {
$product['_PROP_' . $key] = $propProduct;
}
}
$stringOffers .= $this->BuildOffer($product, $categories, $iblock, $allCategories);
}
}
unset($products);
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'] = $dbResProductsIds->NavPageNomer + 1;
}
while ($dbResProductsIds->NavPageNomer < $dbResProductsIds->NavPageCount);
}
}
protected function BuildOffer($arOffer, $categories, $iblock, &$allCategories)
{
$offer = "";
$offer .= "<offer id=\"" .$this->PrepareValue($arOffer["ID"]) . "\" ".
"productId=\"" . $this->PrepareValue($arOffer["PRODUCT_ID"]) . "\" ".
"quantity=\"" . $this->PrepareValue(DoubleVal($arOffer['QUANTITY'])) . "\">\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) {
$category = $allCategories[$keys[0]];
$path = $category['CODE'];
if(intval($category["IBLOCK_SECTION_ID"] ) != 0) {
while (true) {
$category = $allCategories[$category['IBLOCK_SECTION_ID']];
$path = $category['CODE'] . '/' . $path;
if(intval($category["IBLOCK_SECTION_ID"] ) == 0)
break;
}
}
}
$arOffer['DETAIL_PAGE_URL'] = str_replace("#SECTION_PATH#", $path, $arOffer['DETAIL_PAGE_URL']);
}
$offer .= "<picture>" . $this->PrepareValue($arOffer["PICTURE"]) . "</picture>\n";
$offer .= "<url>" . $this->protocol . $this->serverName . $this->PrepareValue($arOffer['DETAIL_PAGE_URL']) . "</url>\n";
$offer .= "<price>" . $this->PrepareValue($arOffer['PRICE']) . "</price>\n";
if ($arOffer['PURCHASE_PRICE'] && $this->loadPurchasePrice) {
$offer .= "<purchasePrice>" . $this->PrepareValue($arOffer['PURCHASE_PRICE']) . "</purchasePrice>\n";
}
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";
$offer .= "<productName>" . $this->PrepareValue($arOffer["PRODUCT_NAME"]) . "</productName>\n";
foreach ($this->propertiesProduct[$iblock['IBLOCK_DB']['ID']] as $key => $propProduct) {
if ($propProduct != "" && $arOffer['_PROP_' . $key] != null) {
if ($key === "manufacturer"){
$offer .= "<vendor>" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</vendor>\n";
}
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"){
$offer .= "<vendor>" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</vendor>\n";
}
else{
$offer .= '<param name="' . $key . '"' . (isset($arOffer['_PROP_' . $key . "_UNIT"]) ? ' unit="' . $arOffer['_PROP_' . $key . "_UNIT"] . '"' : "") . ">" . $this->PrepareValue($arOffer['_PROP_' . $key]) . "</param>\n";
}
}
}
$offer.= "</offer>\n";
return $offer;
}
}

View File

@ -0,0 +1,328 @@
<?php
IncludeModuleLangFile(__FILE__);
class RetailCrmOrder
{
public static $MODULE_ID = 'intaro.retailcrm';
public static $CRM_API_HOST_OPTION = 'api_host';
public static $CRM_API_KEY_OPTION = 'api_key';
public static $CRM_ORDER_TYPES_ARR = 'order_types_arr';
public static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
public static $CRM_PAYMENT_TYPES = 'pay_types_arr';
public static $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
public static $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
public static $CRM_ORDER_LAST_ID = 'order_last_id';
public static $CRM_SITES_LIST = 'sites_list';
public static $CRM_ORDER_PROPS = 'order_props';
public static $CRM_LEGAL_DETAILS = 'legal_details';
public static $CRM_CUSTOM_FIELDS = 'custom_fields';
public static $CRM_CONTRAGENT_TYPE = 'contragent_type';
public static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
public static $CRM_ORDER_HISTORY_DATE = 'order_history_date';
public static $CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
public static $CRM_ORDER_NUMBERS = 'order_numbers';
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
/**
*
* Creates order or returns order for mass upload
*
* @param array $arFields
* @param $api
* @param $arParams
* @param $send
* @return boolean
* @return array - array('order' = $order, 'customer' => $customer)
*/
public static function orderSend($arFields, $api, $arParams, $send = false, $site = null, $methodApi = 'ordersEdit') {
if(!$api || empty($arParams)) { // add cond to check $arParams
return false;
}
if (empty($arFields)) {
RCrmActions::eventLog('RetailCrmOrder::orderSend', 'empty($arFields)', 'incorrect order');
return false;
}
$order = array(
'number' => $arFields['NUMBER'],
'externalId' => $arFields['ID'],
'createdAt' => new \DateTime($arFields['DATE_INSERT']),
'customer' => array('externalId' => $arFields['USER_ID']),
'paymentType' => isset($arParams['optionsPayTypes'][$arFields['PAYMENTS'][0]]) ?
$arParams['optionsPayTypes'][$arFields['PAYMENTS'][0]] : '',
'paymentStatus' => isset($arParams['optionsPayment'][$arFields['PAYED']]) ?
$arParams['optionsPayment'][$arFields['PAYED']] : '',
'orderType' => isset($arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']]) ?
$arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']] : '',
'status' => isset($arParams['optionsPayStatuses'][$arFields['STATUS_ID']]) ?
$arParams['optionsPayStatuses'][$arFields['STATUS_ID']] : '',
//'statusComment' => $arFields['REASON_CANCELED'],
'customerComment' => $arFields['USER_DESCRIPTION'],
'managerComment' => $arFields['COMMENTS'],
'delivery' => array(
'cost' => $arFields['PRICE_DELIVERY']
),
);
if(isset($_COOKIE['_rc']) && $_COOKIE['_rc'] != ''){
$order['customer']['browserId'] = $_COOKIE['_rc'];
}
$order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arFields['PERSON_TYPE_ID']];
//свойства
foreach($arFields['PROPS']['properties'] as $prop){
if ($search = array_search($prop['CODE'], $arParams['optionsLegalDetails'][$arFields['PERSON_TYPE_ID']])) {
$order['contragent'][$search] = $prop['VALUE'][0];//юр данные заказа
} elseif ($search = array_search($prop['CODE'], $arParams['optionsCustomFields'][$arFields['PERSON_TYPE_ID']])) {
$order['customFields'][$search] = $prop['VALUE'][0];//кастомные свойства
} elseif ($search = array_search($prop['CODE'], $arParams['optionsOrderProps'][$arFields['PERSON_TYPE_ID']])) {//остальное
if (in_array($search, array('fio', 'phone', 'email'))) {//фио, телефон, почта
if ($search == 'fio') {
$order = array_merge($order, RCrmActions::explodeFIO($prop['VALUE'][0]));//добавляем поля фио
} else {
$order[$search] = $prop['VALUE'][0];//телефон и почта
}
} else {//остальное - адрес
if ($prop['TYPE'] == 'LOCATION') {
$arLoc = \Bitrix\Sale\Location\LocationTable::getByCode($prop['VALUE'][0])->fetch();
$location = \Bitrix\Sale\Location\Name\LocationTable::getList(array(
'filter' => array('=LOCATION_ID' => $arLoc['CITY_ID'], 'LANGUAGE_ID'=>'ru')
))->fetch();
$prop['VALUE'][0] = $location['NAME'];
}
$order['delivery']['address'][$search] = $prop['VALUE'][0];
}
}
}
//доставки
if (array_key_exists($arFields['DELIVERYS'][0]['id'], $arParams['optionsDelivTypes'])) {
$order['delivery']['code'] = $arParams['optionsDelivTypes'][$arFields['DELIVERYS'][0]['id']];
if (isset($arFields['DELIVERYS'][0]['service'])) {
$order['delivery']['service'] = $arFields['DELIVERYS'][0]['service'];
}
}
//корзина
foreach($arFields['BASKET'] as $product){
$item = array(
'quantity' => $product['QUANTITY'],
'offer' => array('externalId' => $product['PRODUCT_ID'],
'xmlId' => $product['PRODUCT_XML_ID']
),
'productName' => $product['NAME']
);
$pp = CCatalogProduct::GetByID($product['PRODUCT_ID']);
if (is_null($pp['PURCHASING_PRICE']) == false) {
$item['purchasePrice'] = $pp['PURCHASING_PRICE'];
}
$item['discount'] = (double) $product['DISCOUNT_PRICE'];
$item['discountPercent'] = 0;
$item['initialPrice'] = (double) $product['PRICE'] + (double) $product['DISCOUNT_PRICE'];
$order['items'][] = $item;
}
//отправка
if (function_exists('retailCrmBeforeOrderSend')) {
$newResOrder = retailCrmBeforeOrderSend($order);
if (is_array($newResOrder) && !empty($newResOrder)) {
$order = $newResOrder;
}
}
$normalizer = new RestNormalizer();
$order = $normalizer->normalize($order, 'orders');
if (isset($arParams['optionsSitesList']) && is_array($arParams['optionsSitesList']) &&
array_key_exists($arFields['LID'], $arParams['optionsSitesList'])) {
$site = $arParams['optionsSitesList'][$arFields['LID']];
}
$log = new Logger();
$log->write($order, 'order');
if($send) {
if (!RCrmActions::apiMethod($api, $methodApi, __METHOD__, $order, $site)) {
return false;
}
}
return $order;
}
/**
* Mass order uploading, without repeating; always returns true, but writes error log
* @param $pSize
* @param $failed -- flag to export failed orders
* @return boolean
*/
public static function uploadOrders($pSize = 50, $failed = false, $orderList = false) {
if (!CModule::IncludeModule("iblock")) {
RCrmActions::eventLog('RetailCrmOrder::uploadOrders', 'iblock', 'module not found');
return true;
}
if (!CModule::IncludeModule("sale")) {
RCrmActions::eventLog('RetailCrmOrder::uploadOrders', 'sale', 'module not found');
return true;
}
if (!CModule::IncludeModule("catalog")) {
RCrmActions::eventLog('RetailCrmOrder::uploadOrders', 'catalog', 'module not found');
return true;
}
$resOrders = array();
$resCustomers = array();
$orderIds = array();
$lastUpOrderId = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, 0);
$failedIds = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, 0));
if ($failed == true && $failedIds !== false && count($failedIds) > 0) {
$orderIds = $failedIds;
} elseif ($orderList !== false && count($orderList) > 0) {
$orderIds = $orderList;
} else {
$dbOrder = \Bitrix\Sale\Order::GetList(array(
'order' => array("ID" => "ASC"),
'filter' => array('>ID' => $lastUpOrderId),
'limit' => $pSize,
'select' => array('ID')
));
while($arOrder = $dbOrder->fetch()){
$orderIds[] = $arOrder['ID'];
}
}
if (count($orderIds)<=0) {
return false;
}
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
$optionsOrderTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_TYPES_ARR, 0));
$optionsDelivTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_DELIVERY_TYPES_ARR, 0));
$optionsPayTypes = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0));
$optionsPayStatuses = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_STATUSES, 0)); // --statuses
$optionsPayment = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0));
$optionsOrderProps = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_PROPS, 0));
$optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0));
$optionsContragentType = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CONTRAGENT_TYPE, 0));
$optionsCustomFields = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CUSTOM_FIELDS, 0));
$api = new RetailCrm\ApiClient($api_host, $api_key);
$arParams = array(
'optionsOrderTypes' => $optionsOrderTypes,
'optionsDelivTypes' => $optionsDelivTypes,
'optionsPayTypes' => $optionsPayTypes,
'optionsPayStatuses' => $optionsPayStatuses,
'optionsPayment' => $optionsPayment,
'optionsOrderProps' => $optionsOrderProps,
'optionsLegalDetails' => $optionsLegalDetails,
'optionsContragentType' => $optionsContragentType,
'optionsSitesList' => $optionsSitesList,
'optionsCustomFields' => $optionsCustomFields,
);
$recOrders = array();
foreach($orderIds as $orderId){
$id = \Bitrix\Sale\Order::load($orderId);
if(!$id){
continue;
}
$order = self::orderObjToArr($id);
$user = Bitrix\Main\UserTable::getById($order['USER_ID'])->fetch();
$site = count($optionsSitesList) > 1 ? $optionsSitesList[$order['LID']] : null;
$arCustomers = RetailCrmUser::customerSend($user, $api, $optionsContragentType[$order['PERSON_TYPE_ID']], false, $site);
$arOrders = self::orderSend($order, $api, $arParams, false, $site);
if (!$arCustomers || !$arOrders){
continue;
}
$resCustomers[$order['LID']][] = $arCustomers;
$resOrders[$order['LID']][] = $arOrders;
$recOrders[] = $orderId;
}
if(count($resOrders) > 0){
foreach($resCustomers as $key => $customerLoad){
$site = count($optionsSitesList) > 1 ? $optionsSitesList[$key] : null;
if (RCrmActions::apiMethod($api, 'customersUpload', __METHOD__, $customerLoad, $site) === false) {
return false;
}
if (count($optionsSitesList) > 1) {
time_nanosleep(0, 250000000);
}
}
foreach($resOrders as $key => $orderLoad){
$site = count($optionsSitesList) > 1 ? $optionsSitesList[$key] : null;
if (RCrmActions::apiMethod($api, 'ordersUpload', __METHOD__, $orderLoad, $site) === false) {
return false;
}
if (count($optionsSitesList) > 1) {
time_nanosleep(0, 250000000);
}
}
if ($failed == true && $failedIds !== false && count($failedIds) > 0) {
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_FAILED_IDS, serialize(array_diff($failedIds, $recOrders)));
} elseif ($lastUpOrderId < max($recOrders) && $orderList === false) {
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_LAST_ID, max($recOrders));
}
}
return true;
}
public static function orderObjToArr($obOrder){
$arOrder = array(
'ID' => $obOrder->getId(),
'NUMBER' => $obOrder->getField('ACCOUNT_NUMBER'),
'LID' => $obOrder->getSiteId(),
'DATE_INSERT' => $obOrder->getDateInsert(),
'STATUS_ID' => $obOrder->getField('STATUS_ID'),
'USER_ID' => $obOrder->getUserId(),
'PERSON_TYPE_ID' => $obOrder->getPersonTypeId(),
'CURRENCY' => $obOrder->getCurrency(),
'PAYMENTS' => $obOrder->getPaymentSystemId(),
'PAYED' => $obOrder->isPaid(),
'DELIVERYS' => array(),
'PRICE_DELIVERY' => $obOrder->getDeliveryPrice(),
'PROPS' => $obOrder->getPropertyCollection()->getArray(),
'DISCOUNTS' => $obOrder->getDiscount()->getApplyResult(),
'BASKET' => array(),
'USER_DESCRIPTION' => $obOrder->getField('USER_DESCRIPTION'),
'COMMENTS' => $obOrder->getField('COMMENTS'),
);
$shipmentList = $obOrder->getShipmentCollection();
foreach($shipmentList as $shipmentData){
if($shipmentData->getDeliveryId()){
$delivery = \Bitrix\Sale\Delivery\Services\Manager::getById($shipmentData->getDeliveryId());
if($delivery['PARENT_ID']){
$servise = explode(':', $delivery['CODE']);
$shipment = array('id' => $delivery['PARENT_ID'], 'service' => $servise[1]);
}
else{
$shipment = array('id' => $delivery['ID']);
}
$arOrder['DELIVERYS'][] = $shipment;
}
}
$basketItems = $obOrder->getBasket();
foreach($basketItems as $item){
$arOrder['BASKET'][] = $item->getFields();
}
return $arOrder;
}
}

View File

@ -0,0 +1,54 @@
<?php
IncludeModuleLangFile(__FILE__);
class RetailCrmUser
{
public static function customerSend($arFields, $api, $contragentType, $send = false, $site = null){//только на создание
if(!$api || empty($contragentType)) { // add cond to check $arParams
return false;
}
if (empty($arFields)) {
RCrmActions::eventLog('ICrmOrderActions::orderCreate', 'empty($arFields)', 'incorrect customer');
return false;
}
$customer = array(
'externalId' => $arFields['ID'],
'firstName' => $arFields['NAME'],
'lastName' => $arFields['LAST_NAME'],
'patronymic' => $arFields['SECOND_NAME'],
'createdAt' => new \DateTime($arFields['DATE_REGISTER']),
'contragentType' => $contragentType
);
if(isset($arFields['PERSONAL_PHONE'])){
$customer['phones'][]['number'] = $arFields['PERSONAL_PHONE'];
}
if(isset($arUser['WORK_PHONE'])){
$customer['phones'][]['number'] = $arFields['WORK_PHONE'];
}
if(isset($_COOKIE['_rc']) && $_COOKIE['_rc'] != ''){
$customer['browserId'] = $_COOKIE['_rc'];
}
if (function_exists('retailCrmBeforeCustomerSend')) {
$newResCustomer = retailCrmBeforeCustomerSend($customer);
if (is_array($newResCustomer) && !empty($newResCustomer)) {
$customer = $newResCustomer;
}
}
$normalizer = new RestNormalizer();
$customer = $normalizer->normalize($customer, 'customers');
$log = new Logger();
$log->write($customer, 'customer');
if($send) {
if (!RCrmActions::apiMethod($api, 'customersCreate', __METHOD__, $customer, $site)) {
return false;
}
}
return $customer;
}
}

View File

@ -0,0 +1,2 @@
- Переход на новое API Битрикса
- Переход на API црм v4

View File

@ -11,13 +11,13 @@ else{
return;
if (!CModule::IncludeModule("catalog"))
return;
if (!CModule::IncludeModule("intaro.intarocrm"))
if (!CModule::IncludeModule("intaro.retailcrm"))
return;
$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
while ($ar = $rsSites->Fetch()){
if($ar['DEF'] == 'Y'){
$SERVER_NAME = $ar['SERVER_NAME'];//разделить потом с учетом многосайтовости
$SERVER_NAME = $ar['SERVER_NAME'];
}
}
@ -72,7 +72,7 @@ else{
}
}
$loader = new ICMLLoader();
$loader = new RetailCrmICML();
$loader->profileID = $PROFILE_ID;
$loader->iblocks = $IBLOCK_EXPORT;
$loader->propertiesSKU = $IBLOCK_PROPERTY_SKU;

View File

@ -16,9 +16,9 @@ else{
if(!check_bitrix_sessid()) return;
__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/icml_export_setup.php"));
__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.retailcrm/lang/", "/icml_export_setup.php"));
$MODULE_ID = 'intaro.intarocrm';
$MODULE_ID = 'intaro.retailcrm';
$CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
$basePriceId = COption::GetOptionString($MODULE_ID, $CRM_CATALOG_BASE_PRICE . '_' . $_REQUEST['PROFILE_ID'], 1);
@ -554,7 +554,7 @@ else{
'catalog',
'export_default_path',
'/bitrix/catalog_export/'))
.'intarocrm'/* .mt_rand(0, 999999) */.'.xml'
.'retailcrm'/* .mt_rand(0, 999999) */.'.xml'
); ?>" size="50">
<br>
<br>

View File

@ -0,0 +1,21 @@
<?php
$server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot();
CModule::AddAutoloadClasses(
'intaro.retailcrm', // module name
array (
'RestNormalizer' => file_exists($server . '/bitrix/php_interface/retailcrm/RestNormalizer.php') ? $server . '/bitrix/php_interface/retailcrm/RestNormalizer.php' : 'classes/general/RestNormalizer.php',
'Logger' => file_exists($server . '/bitrix/php_interface/retailcrm/Logger.php') ? $server . '/bitrix/php_interface/retailcrm/Logger.php' : 'classes/general/Logger.php',
'RetailCrm\ApiClient' => file_exists($server . '/bitrix/php_interface/retailcrm/ApiClient.php') ? $server . '/bitrix/php_interface/retailcrm/ApiClient.php' : 'classes/general/ApiClient.php',
'RetailCrm\Http\Client' => file_exists($server . '/bitrix/php_interface/retailcrm/Client.php') ? $server . '/bitrix/php_interface/retailcrm/Client.php' : 'classes/general/Http/Client.php',
'RCrmActions' => file_exists($server . '/bitrix/php_interface/retailcrm/RCrmActions.php') ? $server . '/bitrix/php_interface/retailcrm/RCrmActions.php' : 'classes/general/RCrmActions.php',
'RetailCrmUser' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmUser.php') ? $server . '/bitrix/php_interface/retailcrm/RetailCrmUser.php' : 'classes/general/user/RetailCrmUser.php',
'RetailCrmOrder' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmOrder.php') ? $server . '/bitrix/php_interface/retailcrm/RetailCrmOrder.php' : 'classes/general/order/RetailCrmOrder.php',
'RetailCrmHistory' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmHistory.php') ? $server . '/bitrix/php_interface/retailcrm/RetailCrmHistory.php' : 'classes/general/history/RetailCrmHistory.php',
'RetailCrmICML' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmICML.php') ? $server . '/bitrix/php_interface/retailcrm/RetailCrmICML.php' : 'classes/general/icml/RetailCrmICML.php',
'RetailCrmEvent' => file_exists($server . '/bitrix/php_interface/retailcrm/RetailCrmEvent.php') ? $server . '/bitrix/php_interface/retailcrm/RetailCrmEvent.php' : 'classes/general/events/RetailCrmEvent.php',
'RetailCrm\Response\ApiResponse' => 'classes/general/Response/ApiResponse.php',
'RetailCrm\Exception\InvalidJsonException' => 'classes/general/Exception/InvalidJsonException.php',
'RetailCrm\Exception\CurlException' => 'classes/general/Exception/CurlException.php',
)
);

View File

@ -0,0 +1,3 @@
<?
//<title>retailCRM</title>
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.retailcrm/export/export_run.php");

View File

@ -0,0 +1,3 @@
<?
//<title>retailCRM</title>
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.retailcrm/export/export_setup.php");

View File

@ -9,7 +9,7 @@
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST">
<?php echo bitrix_sessid_post(); ?>
<input type="hidden" name="lang" value="<?php echo LANGUAGE_ID ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="11">
@ -31,11 +31,11 @@
</tr>
<tr>
<td width="50%" class="adm-detail-content-cell-l"><?php echo GetMessage('ICRM_API_HOST'); ?></td>
<td width="50%" class="adm-detail-content-cell-r"><input type="text" id="api_host" name="api_host" value=""></td>
<td width="50%" class="adm-detail-content-cell-r"><input type="text" id="api_host" name="api_host" value="<?php if(isset($arResult['API_HOST'])) echo $arResult['API_HOST'];?>"></td>
</tr>
<tr>
<td width="50%" class="adm-detail-content-cell-l"><?php echo GetMessage('ICRM_API_KEY'); ?></td>
<td width="50%" class="adm-detail-content-cell-r"><input type="text" id="api_key" name="api_key" value=""></td>
<td width="50%" class="adm-detail-content-cell-r"><input type="text" id="api_key" name="api_key" value="<?php if(isset($arResult['API_KEY'])) echo $arResult['API_KEY'];?>"></td>
</tr>
</tbody>
</table>

View File

@ -9,7 +9,7 @@
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST">
<?php echo bitrix_sessid_post(); ?>
<input type="hidden" name="lang" value="<?php echo LANGUAGE_ID ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="2">
@ -36,7 +36,7 @@
<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>
<option value="<?php echo $sitesList['code'] ?>" <?php if(isset($arResult['SITES_LIST'][$site['LID']]) && $arResult['SITES_LIST'][$site['LID']] == $sitesList['code']) echo 'selected'; ?>><?php echo $sitesList['name']?></option>
<?php endforeach; ?>
</select>
</td>

View File

@ -1,7 +1,7 @@
<?php
IncludeModuleLangFile(__FILE__);
$MODULE_ID = 'intaro.intarocrm';
$MODULE_ID = 'intaro.retailcrm';
$CRM_API_HOST_OPTION = 'api_host';
$api_host = COption::GetOptionString($MODULE_ID, $CRM_API_HOST_OPTION, 0);
@ -11,33 +11,58 @@ $arResult['bitrixPaymentList'][0]['ID'] = 'Y';
$arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N');
$arResult['bitrixPaymentList'][1]['ID'] = 'N';
$defaultOrderTypes = array (
1 => 'eshop-individual',
2 => 'eshop-legal'
);
if(isset($arResult['ORDER_TYPES'])){
$defaultOrderTypes = $arResult['ORDER_TYPES'];
}
else{
$defaultOrderTypes = array (
1 => 'eshop-individual',
2 => 'eshop-legal'
);
}
$defaultDelivTypes = array (
1 => 'courier',
2 => 'self-delivery'
);
if(isset($arResult['DELIVERY_TYPES'])){
$defaultDelivTypes = $arResult['DELIVERY_TYPES'];
}
else{
$defaultDelivTypes = array (
1 => 'courier',
2 => 'self-delivery'
);
}
$defaultPayTypes = array (
1 => 'cash',
5 => 'bank-transfer',
6 => 'bank-transfer'
);
if(isset($arResult['PAYMENT_TYPES'])){
$defaultPayTypes = $arResult['PAYMENT_TYPES'];
}
else{
$defaultPayTypes = array (
1 => 'cash',
4 => 'e-money',
5 => 'bank-card',
9 => 'bank-transfer'
);
}
$defaultPayStatuses = array (
'N' => 'new',
'P' => 'approval',
'F' => 'complete',
'Y' => 'cancel-other'
);
if(isset($arResult['PAYMENT_STATUSES'])){
$defaultPayStatuses = $arResult['PAYMENT_STATUSES'];
}
else{
$defaultPayStatuses = array (
'N' => 'new',
'P' => 'prepayed',
'F' => 'complete',
);
}
$defaultPayment = array(
'Y' => 'paid',
'N' => 'not-paid'
);
if(isset($arResult['PAYMENT'])){
$defaultPayment = $arResult['PAYMENT'];
}
else{
$defaultPayment = array(
'Y' => 'paid',
'N' => 'not-paid'
);
}
?>
@ -106,18 +131,18 @@ $defaultPayment = array(
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST">
<?php echo bitrix_sessid_post(); ?>
<input type="hidden" name="lang" value="<?php echo LANGUAGE_ID ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="3">
<table class="adm-detail-content-table edit-table" id="edit1_edit_table">
<tbody>
<tr class="heading">
<!--<tr class="heading">
<td colspan="2" style="position:relative;">
<b><?php echo GetMessage('STEP_NAME'); ?></b>
<input type="submit" name="update" value="<?php echo GetMessage('UPDATE_CATS'); ?>" class="adm-btn-save">
</td>
</tr>
</tr>-->
<tr align="center">
<td colspan="2"><b><?php echo GetMessage('INFO_1'); ?></b></td>
</tr>
@ -180,27 +205,47 @@ $defaultPayment = array(
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('PAYMENT_STATUS_LIST'); ?></b></td>
</tr>
<?php foreach($arResult['bitrixPaymentStatusesList'] as $bitrixPaymentStatus): ?>
<tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPaymentStatus['ID']; ?>">
<?php echo $bitrixPaymentStatus['NAME']; ?>
<td width="50%"></td>
<td width="50%">
<table width="100%">
<tr>
<td width="50%"></td>
<td width="50%"><?php echo GetMessage('CANCELED'); ?></td>
</tr>
</table>
</td>
</tr>
<?php foreach($arResult['bitrixStatusesList'] as $bitrixStatus): ?>
<tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixStatus['ID']; ?>">
<?php echo $bitrixStatus['NAME']; ?>
</td>
<td width="50%" class="adm-detail-content-cell-r">
<select name="payment-status-<?php echo $bitrixPaymentStatus['ID']; ?>" class="typeselect">
<option value="" selected=""></option>
<?php foreach($arResult['paymentGroupList'] as $orderStatusGroup): if(!empty($orderStatusGroup['statuses'])) : ?>
<optgroup label="<?php echo $APPLICATION->ConvertCharset($orderStatusGroup['name'], 'utf-8', SITE_CHARSET); ?>">
<?php foreach($orderStatusGroup['statuses'] as $payment): ?>
<?php if(isset($arResult['paymentList'][$payment])): ?>
<option value="<?php echo $arResult['paymentList'][$payment]['code']; ?>"
<?php if ($defaultPayStatuses[$bitrixPaymentStatus['ID']] == $arResult['paymentList'][$payment]['code']) echo 'selected'; ?>>
<?php echo $APPLICATION->ConvertCharset($arResult['paymentList'][$payment]['name'], 'utf-8', SITE_CHARSET); ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</optgroup>
<?php endif; endforeach; ?>
</select>
<table width="100%">
<tr>
<td width="70%">
<select name="payment-status-<?php echo $bitrixStatus['ID']; ?>" class="typeselect">
<option value="" selected=""></option>
<?php foreach($arResult['paymentGroupList'] as $orderStatusGroup): if(!empty($orderStatusGroup['statuses'])) : ?>
<optgroup label="<?php echo $APPLICATION->ConvertCharset($orderStatusGroup['name'], 'utf-8', SITE_CHARSET); ?>">
<?php foreach($orderStatusGroup['statuses'] as $payment): ?>
<?php if(isset($arResult['paymentList'][$payment])): ?>
<option value="<?php echo $arResult['paymentList'][$payment]['code']; ?>"
<?php if ($defaultPayStatuses[$bitrixStatus['ID']] == $arResult['paymentList'][$payment]['code']) echo 'selected'; ?>>
<?php echo $APPLICATION->ConvertCharset($arResult['paymentList'][$payment]['name'], 'utf-8', SITE_CHARSET); ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</optgroup>
<?php endif; endforeach; ?>
</select>
</td>
<td width="30%">
<input name="order-cansel-<?php echo $bitrixStatus['ID']; ?>" value="Y" type="checkbox" />
</td>
</tr>
</table>
</td>
</tr>
<?php endforeach; ?>

View File

@ -3,22 +3,28 @@ if (!check_bitrix_sessid())
return;
IncludeModuleLangFile(__FILE__);
$defaultOrderProps = array(
1 => array(
'fio' => 'FIO',
'index' => 'ZIP',
'text' => 'ADDRESS',
'phone' => 'PHONE',
'email' => 'EMAIL'
),
2 => array(
'fio' => 'FIO',
'index' => 'ZIP',
'text' => 'ADDRESS',
'phone' => 'PHONE',
'email' => 'EMAIL'
)
);
if(isset($arResult['ORDER_PROPS'])){
$defaultOrderProps = $arResult['ORDER_PROPS'];
}
else{
$defaultOrderProps = array(
1 => array(
'fio' => 'FIO',
'index' => 'ZIP',
'text' => 'ADDRESS',
'phone' => 'PHONE',
'email' => 'EMAIL'
),
2 => array(
'fio' => 'CONTACT_PERSON',
'index' => 'ZIP',
'text' => 'ADDRESS',
'phone' => 'PHONE',
'email' => 'EMAIL'
)
);
}
echo"<pre>";var_export($arResult);echo"</pre>";
?>
<script type="text/javascript" src="/bitrix/js/main/jquery/jquery-1.7.min.js"></script>
<script type="text/javascript">
@ -55,7 +61,7 @@ $defaultOrderProps = array(
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST">
<?php echo bitrix_sessid_post(); ?>
<input type="hidden" name="lang" value="<?php echo LANGUAGE_ID ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="4">
<input type="hidden" name="continue" value="3">
@ -82,7 +88,7 @@ $defaultOrderProps = array(
<td width="50%" class="adm-detail-content-cell-r">
<select name="contragent-type-<?php echo $bitrixOrderType['ID']; ?>" class="typeselect">
<?php foreach ($arResult['contragentType'] as $contragentType): ?>
<option value="<?php echo $contragentType["ID"]; ?>" <?php if ($optionsContragentType[$bitrixOrderType['ID']] == $contragentType['ID']) echo 'selected'; ?>>
<option value="<?php echo $contragentType["ID"]; ?>" <?php if (isset($arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']]) && $arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']] == $contragentType["ID"]) echo 'selected'; ?>>
<?php echo $contragentType["NAME"]; ?>
</option>
<?php endforeach; ?>
@ -136,14 +142,14 @@ $defaultOrderProps = array(
<select name="custom-fields-<?=$customFields['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect">
<option value=""></option>
<?foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp):?>
<option value="<?=$arProp['CODE']?>" <?php if ($optionsCustomFields[$bitrixOrderType['ID']][$customFields['ID']] == $arProp['CODE']) echo 'selected'; ?>>
<option value="<?=$arProp['CODE']?>" <?php if (isset($arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']]) && $arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']] == $arProp['CODE']) echo 'selected'; ?>>
<?=$arProp['NAME']; ?>
</option>
<?endforeach;?>
</select>
</td>
</tr>
<?endforeach;?>
<?endforeach;?>
<?endif;?>
<tr class="heading legal-detail-title-<?php echo $bitrixOrderType['ID'];?>" style="display:none">
@ -163,7 +169,7 @@ $defaultOrderProps = array(
<select name="legal-detail-<?php echo $legalDetails['ID'] . '-' . $bitrixOrderType['ID']; ?>" class="typeselect">
<option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>" <?php if ($optionsLegalDetails[$bitrixOrderType['ID']][$legalDetails['ID']] == $arProp['CODE']) echo 'selected'; ?>>
<option value="<?php echo $arProp['CODE']; ?>" <?php if (isset($arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']]) && $arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']] == $arProp['CODE']) echo 'selected'; ?>>
<?php echo $arProp['NAME']; ?>
</option>
<?php endforeach; ?>

View File

@ -167,7 +167,7 @@ IncludeModuleLangFile(__FILE__);
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST">
<?php echo bitrix_sessid_post(); ?>
<input type="hidden" name="lang" value="<?php echo LANGUAGE_ID ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="5">
<input type="hidden" name="continue" value="4">

View File

@ -2,7 +2,7 @@
if(!check_bitrix_sessid()) return;
IncludeModuleLangFile(__FILE__);
__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/icml_export_setup.php"));
__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.retailcrm/lang/", "/icml_export_setup.php"));
?>
<h3><?=GetMessage("EXPORT_CATALOGS_INFO");?></h3>
<?php
@ -460,7 +460,7 @@ if (!empty($oldValues)) {
'catalog',
'export_default_path',
'/bitrix/catalog_export/'))
.'intarocrm'/* .mt_rand(0, 999999) */.'.xml'
.'retailcrm'/* .mt_rand(0, 999999) */.'.xml'
); ?>" size="50">
<br>
@ -590,7 +590,7 @@ if (!empty($oldValues)) {
<?=bitrix_sessid_post();?>
<input type="hidden" name="lang" value="<?php echo LANG; ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="6">
<input type="hidden" name="continue" value="5">

View File

@ -5,7 +5,7 @@ echo GetMessage("INTAROCRM_INFO"); ?>
<form action="<?php echo $APPLICATION->GetCurPage(); ?>">
<input type="hidden" name="lang" value="<?php echo LANG; ?>">
<input type="hidden" name="id" value="intaro.intarocrm">
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="submit" name="" value="<?php echo GetMessage("MOD_BACK"); ?>">
<form>

View File

@ -0,0 +1,6 @@
<?
$arModuleVersion = array(
"VERSION" => "2.0.0",
"VERSION_DATE" => "2016-09-12 12:00:00"
);

View File

@ -1,5 +1,5 @@
<?php
$MESS ['INTARO_MODULE_NAME'] = 'retailCRM';
$MESS ['RETAIL_MODULE_NAME'] = 'retailCRM';
$MESS ['MODULE_DESCRIPTION'] = 'Модуль интеграции с retailCRM - специализированной CRM для e-commerce';
$MESS ['MODULE_PARTNER_NAME'] = 'Интаро Софт';
$MESS ['MODULE_PARTNER_URI'] = 'http://www.retailcrm.ru';
@ -9,10 +9,11 @@ $MESS ['CANCELED'] = 'Флаг «Отменен»';
$MESS ['ERR_SALE'] = 'Отсутствует модуль sale! Дальнейшая установка невозможна.';
$MESS ['ERR_IBLOCK'] = 'Отсутствует модуль iblock! Дальнейшая установка невозможна.';
$MESS ['ERR_CATALOG'] = 'Отсутствует модуль catalog! Дальнейшая установка невозможна.';
$MESS ['INTAROCRM_CURL_ERR'] = 'Для работы модуля интеграции с retailCRM требуется PHP-расширение CURL.';
$MESS ['RETAILCRM_CURL_ERR'] = 'Для работы модуля интеграции с retailCRM требуется PHP-расширение CURL.';
$MESS ['ERR_ARTICLE_IBLOCK'] = 'Не установлены артикулы';
$MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона в настройках php.';
$MESS ['SALE_VERSION_ERR'] = 'Версия модуля \'Интернет-магазин\' должна быть выше 16.';
/*
$MESS ['ORDER_PROPS'] = 'Настройки соответствия полей заказа retailCRM свойствам заказа 1С-Битрикс';
$MESS ['FIO'] = 'Ф.И.О.';
$MESS ['ZIP'] = 'Индекс';
@ -30,4 +31,4 @@ $MESS ['FLOOR'] = 'Этаж';
$MESS ['BLOCK'] = 'Подъезд';
$MESS ['HOUSE'] = 'Строение / корпус';
$MESS ['ADDRESS_SHORT'] = 'Краткий адрес';
$MESS ['ADDRESS_FULL'] = 'Детальный адрес';
$MESS ['ADDRESS_FULL'] = 'Детальный адрес';*/

View File

@ -9,7 +9,7 @@ $MESS ['ERR_6'] = 'Возможно неверно введен адрес retai
$MESS ['ERR_403'] = 'Неверный apiKey.';
$MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.';
$MESS ['ERR_FIELDS_API_HOST'] = 'Неверно заполнены поля.';
$MESS ['URL_NOT_FOUND'] = 'В настройках одного или нескольких сайтов не заполнено поле "URL сервера".';
//$MESS ['URL_NOT_FOUND'] = 'В настройках одного или нескольких сайтов не заполнено поле "URL сервера".';
$MESS ['INFO_1'] = 'Введите адрес экземпляра retailCRM (например, https://demo.retailcrm.ru) и API-ключ.';
$MESS ['INFO_2'] = 'API-ключ можно сгенерировать при регистрации магазина в retailCRM (Администрирование > Интеграция).';
$MESS ['INFO_3'] = 'Код сайта в 1С-Битрикс должен совпадать с кодом сайта в retailCRM (Администрирование > Магазины).';

View File

@ -9,7 +9,7 @@ $MESS ['ORDER_TYPES_LIST'] = 'Типы заказа';
$MESS ['PAYMENT_LIST'] = 'Оплата';
$MESS ['PAYMENT_Y'] = 'Оплачен';
$MESS ['PAYMENT_N'] = 'Не оплачен';
$MESS ['CANCELED'] = 'Флаг «Отменен»';
$MESS ['CANCELED'] = 'Является флагом «Отменен»';
$MESS ['INFO_1'] = 'Задайте соответствие между справочниками 1C-Битрикс и справочниками retailCRM.';
$MESS ['INFO_2'] = 'В случае, если вы не нашли подходящих значений в справочниках retailCRM, вы можете внести их в разделе';
$MESS ['URL_1'] = 'Администрирование';

View File

@ -29,7 +29,7 @@ $MESS ['ERR_404'] = 'Возможно не верно введен адрес CR
$MESS ['ERR_403'] = 'Неверный apiKey.';
$MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.';
$MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.';
$MESS ['CANCELED'] = 'Флаг «Отменен»';
$MESS ['CANCELED'] = 'Является флагом «Отменен»';
$MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками retailCRM.';
$MESS ['ICRM_OPTIONS_ORDER_DISCHARGE_TAB'] = 'Режим выгрузки заказов';
@ -66,3 +66,6 @@ $MESS ['MESS_2'] = 'Произошла ошибка сервера, обрати
$MESS ['ORDER_TYPES_LIST_CUSTOM'] = 'Внимание! Используется не стандартное соответвие типов заказов.';
$MESS ['ORDER_UPL_START'] = 'Начать выгрузку';
$MESS ['OTHER_OPTIONS'] = 'Прочие настройки';
$MESS ['ORDERS_OPTIONS'] = 'Настройки заказов';
$MESS ['ORDER_NUMBERS'] = 'Транслировать номера заказов созданных в црм в магазин';

View File

@ -1,6 +1,6 @@
<?php
IncludeModuleLangFile(__FILE__);
$mid = 'intaro.intarocrm';
$mid = 'intaro.retailcrm';
$uri = $APPLICATION->GetCurPage() . '?mid=' . htmlspecialchars($mid) . '&lang=' . LANGUAGE_ID;
$CRM_API_HOST_OPTION = 'api_host';
@ -19,9 +19,10 @@ $CRM_LEGAL_DETAILS = 'legal_details';
$CRM_CUSTOM_FIELDS = 'custom_fields';
$CRM_CONTRAGENT_TYPE = 'contragent_type';
$CRM_SITES_LIST= 'sites_list';
$CRM_ORDER_NUMBERS = 'order_numbers';
$CRM_CANSEL_ORDER = 'cansel_order';
if(!CModule::IncludeModule('intaro.intarocrm')
|| !CModule::IncludeModule('sale'))
if(!CModule::IncludeModule('intaro.retailcrm') || !CModule::IncludeModule('sale'))
return;
$_GET['errc'] = htmlspecialchars(trim($_GET['errc']));
@ -32,8 +33,8 @@ if($_GET['ok'] && $_GET['ok'] == 'Y') echo CAdminMessage::ShowNote(GetMessage('I
$arResult = array();
if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.intarocrm/classes/general/config/options.xml')) {
$options = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.intarocrm/classes/general/config/options.xml');
if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml')) {
$options = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml');
foreach($options->contragents->contragent as $contragent)
{
@ -61,29 +62,19 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.intarocrm/cl
unset($type);
}
}
//else error
$arResult['arSites'] = array();
$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
while ($ar = $rsSites->Fetch()){
$arResult['arSites'][] = $ar;
}
$arResult['arSites'] = RCrmActions::SitesList();
//ajax update deliveryServices
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) {
$result = array();
$api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0);
$api = new RetailCrm\RestApi($api_host, $api_key);
$api = new RetailCrm\ApiClient($api_host, $api_key);
try {
$api->paymentStatusesList();
} catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'intaro.crm/options.php', 'RetailCrm\RestApi::paymentStatusesList::CurlException',
RCrmActions::eventLog(
'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::paymentStatusesList::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
@ -93,45 +84,28 @@ if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_RE
}
$optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0));
$arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
// bitrix deliveryServicesList
$dbDeliveryServicesList = CSaleDeliveryHandler::GetList(
array(
'SORT' => 'ASC',
'NAME' => 'ASC'
),
array(
'ACTIVE' => 'Y',
'SITE_ID' => $arResult['arSites'][0]['LID']
)
);
if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) {
do {
if(!$optionsDelivTypes[$arDeliveryServicesList['SID']]) {
ICrmOrderActions::eventLog('options.php', 'No delivery type relations established', $arDeliveryServicesList['SID'] . ':' . $id);
continue;
}
foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) {
// send to crm
try {
$api->deliveryServiceEdit(ICrmOrderActions::clearArr(array(
'code' => $arDeliveryServicesList['SID'] . '-' . $id,
'name' => ICrmOrderActions::toJSON($profile['TITLE']),
'deliveryType' => $arDeliveryServicesList['SID']
)));
} catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'intaro.crm/options.php', 'RetailCrm\RestApi::deliveryServiceEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
foreach($optionsDelivTypes as $key => $deliveryType){
foreach($arDeliveryServiceAll as $deliveryService){
if($deliveryService['PARENT_ID'] != 0 && $deliveryService['PARENT_ID'] == $key){
$srv = explode(':', $deliveryService['CODE']);
if(count($srv) == 2){
try {
$api->deliveryServicesEdit(RCrmActions::clearArr(array(
'code' => $srv[1],
'name' => RCrmActions::toJSON($deliveryService['NAME']),
'deliveryType' => $deliveryType
)));
} catch (\RetailCrm\Exception\CurlException $e) {
RCrmActions::eventLog(
'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::deliveryServiceEdit::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
}
}
}
} while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch());
}
}
$APPLICATION->RestartBuffer();
@ -162,7 +136,7 @@ if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQ
$splitedOrders = array_chunk($orders, $countStep);
$stepOrders = $splitedOrders[$step];
ICrmOrderActions::uploadOrders($countStep, false, $stepOrders);
RetailCrmOrder::uploadOrders($countStep, false, $stepOrders);
$percent = round((($step * $countStep + count($stepOrders)) * 100 / count($orders)), 1);
$step++;
@ -179,7 +153,7 @@ if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQ
$orders[] = $i + $step * $countStep;
}
ICrmOrderActions::uploadOrders($countStep, false, $orders);
RetailCrmOrder::uploadOrders($countStep, false, $orders);
$step++;
$countLeft = (int) CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $step * $countStep), array());
@ -210,12 +184,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
}
if($api_host && $api_key) {
$api = new RetailCrm\RestApi($api_host, $api_key);
$api = new RetailCrm\ApiClient($api_host, $api_key);
try {
$api->paymentStatusesList();
} catch (\RetailCrm\Exception\CurlException $e) {
ICrmOrderActions::eventLog(
'intaro.crm/options.php', 'RetailCrm\RestApi::paymentStatusesList::CurlException',
RCrmActions::eventLog(
'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::paymentStatusesList::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
@ -226,110 +200,42 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
COption::SetOptionString($mid, 'api_host', $api_host);
COption::SetOptionString($mid, 'api_key', $api_key);
}
//bitrix orderTypesList -- personTypes
$dbOrderTypesList = CSalePersonType::GetList(
array(
"SORT" => "ASC",
"NAME" => "ASC"
),
array(
"ACTIVE" => "Y",
),
false,
false,
array()
);
//form order types ids arr
$orderTypesArr = array();
$orderTypesList = array();
if ($arOrderTypesList = $dbOrderTypesList->Fetch()) {
do {
$orderTypesArr[$arOrderTypesList['ID']] = $_POST['order-type-' . $arOrderTypesList['ID']];
$orderTypesList[] = $arOrderTypesList;
} while ($arOrderTypesList = $dbOrderTypesList->Fetch());
}
$orderTypesList = RCrmActions::OrderTypesList($arResult['arSites']);
//bitrix deliveryTypesList
$dbDeliveryTypesList = CSaleDelivery::GetList(
array(
"SORT" => "ASC",
"NAME" => "ASC"
),
array(
"ACTIVE" => "Y",
),
false,
false,
array()
);
$orderTypesArr = array();
foreach($orderTypesList as $orderType){
$orderTypesArr[$orderType['ID']] = htmlspecialchars(trim($_POST['order-type-' . $orderType['ID']]));
}
//form delivery types ids arr
$arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList();
$deliveryTypesArr = array();
if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) {
do {
$deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']]));
} while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch());
foreach($arResult['bitrixDeliveryTypesList'] as $delivery){
$deliveryTypesArr[$delivery['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $delivery['ID']]));
}
//bitrix deliveryServicesList
$dbDeliveryServicesList = CSaleDeliveryHandler::GetList(
array(
'SORT' => 'ASC',
'NAME' => 'ASC'
),
array(
'ACTIVE' => 'Y',
'SITE_ID' => $arResult['arSites'][0]['LID']
)
);
//form delivery services ids arr
if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) {
do {
//auto delivery types
$deliveryTypesArr[$arDeliveryServicesList['SID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryServicesList['SID']]));
} while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch());
}
//bitrix paymentTypesList
$dbPaymentTypesList = CSalePaySystem::GetList(
array(
"SORT" => "ASC",
"NAME" => "ASC"
),
array(
"ACTIVE" => "Y"
)
);
//form payment types ids arr
$paymentTypesArr = array();
if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) {
do {
$paymentTypesArr[$arPaymentTypesList['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $arPaymentTypesList['ID']]));
} while ($arPaymentTypesList = $dbPaymentTypesList->Fetch());
}
//bitrix paymentStatusesList
$dbPaymentStatusesList = CSaleStatus::GetList(
array(
"SORT" => "ASC",
"NAME" => "ASC"
),
array(
"LID" => "ru", //ru
"ACTIVE" => "Y"
)
);
$arResult['bitrixPaymentTypesList'] = RCrmActions::PaymentList();
$paymentTypesArr = array();
foreach($arResult['bitrixPaymentTypesList'] as $payment){
$paymentTypesArr[$payment['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $payment['ID']]));
}
//form payment statuses ids arr
$paymentStatusesArr['YY'] = htmlspecialchars(trim($_POST['payment-status-YY']));
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
do {
$paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']]));
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
$arResult['bitrixStatusesList'] = RCrmActions::StatusesList();
$paymentStatusesArr = array();
$canselOrderArr = array();
//$paymentStatusesArr['YY'] = htmlspecialchars(trim($_POST['payment-status-YY']));
foreach($arResult['bitrixStatusesList'] as $status){
$paymentStatusesArr[$status['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $status['ID']]));
if(trim($_POST['order-cansel-' . $status['ID']]) == 'Y'){
$canselOrderArr[] = $status['ID'];
}
}
//form payment ids arr
@ -344,7 +250,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
// 1 - event
$orderDischarge = 0;
$orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge']));
///////////тут дописать\\\\\\\\\\\\\\\
if (($orderDischarge != $previousDischarge) && ($orderDischarge == 0)) {
// remove depenedencies
UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail");
@ -396,18 +302,22 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
foreach ($orderTypesList as $orderType) {
$contragentTypeArr[$orderType['ID']] = htmlspecialchars(trim($_POST['contragent-type-' . $orderType['ID']]));
}
//order numbers
$orderNumbers = htmlspecialchars(trim($_POST['order-numbers'])) ? htmlspecialchars(trim($_POST['order-numbers'])) : 'N';
COption::SetOptionString($mid, $CRM_SITES_LIST, serialize(ICrmOrderActions::clearArr($siteListArr)));
COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize(ICrmOrderActions::clearArr($orderTypesArr)));
COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize(ICrmOrderActions::clearArr($deliveryTypesArr)));
COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize(ICrmOrderActions::clearArr($paymentTypesArr)));
COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize(ICrmOrderActions::clearArr($paymentStatusesArr)));
COption::SetOptionString($mid, $CRM_PAYMENT, serialize(ICrmOrderActions::clearArr($paymentArr)));
COption::SetOptionString($mid, $CRM_SITES_LIST, serialize(RCrmActions::clearArr($siteListArr)));
COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr)));
COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr)));
COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr)));
COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr($paymentStatusesArr)));
COption::SetOptionString($mid, $CRM_PAYMENT, serialize(RCrmActions::clearArr($paymentArr)));
COption::SetOptionString($mid, $CRM_ORDER_DISCHARGE, $orderDischarge);
COption::SetOptionString($mid, $CRM_ORDER_PROPS, serialize(ICrmOrderActions::clearArr($orderPropsArr)));
COption::SetOptionString($mid, $CRM_CONTRAGENT_TYPE, serialize(ICrmOrderActions::clearArr($contragentTypeArr)));
COption::SetOptionString($mid, $CRM_LEGAL_DETAILS, serialize(ICrmOrderActions::clearArr($legalDetailsArr)));
COption::SetOptionString($mid, $CRM_CUSTOM_FIELDS, serialize(ICrmOrderActions::clearArr($customFieldsArr)));
COption::SetOptionString($mid, $CRM_ORDER_PROPS, serialize(RCrmActions::clearArr($orderPropsArr)));
COption::SetOptionString($mid, $CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr)));
COption::SetOptionString($mid, $CRM_LEGAL_DETAILS, serialize(RCrmActions::clearArr($legalDetailsArr)));
COption::SetOptionString($mid, $CRM_CUSTOM_FIELDS, serialize(RCrmActions::clearArr($customFieldsArr)));
COption::SetOptionString($mid, $CRM_ORDER_NUMBERS, $orderNumbers);
COption::SetOptionString($mid, $CRM_CANSEL_ORDER, serialize(RCrmActions::clearArr($canselOrderArr)));
$uri .= '&ok=Y';
LocalRedirect($uri);
@ -415,7 +325,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0);
$api = new RetailCrm\RestApi($api_host, $api_key);
$api = new RetailCrm\ApiClient($api_host, $api_key);
//prepare crm lists
try {
@ -424,118 +334,36 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$arResult['deliveryServicesList'] = $api->deliveryServicesList()->deliveryServices;
$arResult['paymentTypesList'] = $api->paymentTypesList()->paymentTypes;
$arResult['paymentStatusesList'] = $api->paymentStatusesList()->paymentStatuses; // --statuses
$arResult['paymentList'] = $api->orderStatusesList()->statuses;
$arResult['paymentGroupList'] = $api->orderStatusGroupsList()->statusGroups; // -- statuses groups
$arResult['paymentList'] = $api->statusesList()->statuses;
$arResult['paymentGroupList'] = $api->statusGroupsList()->statusGroups; // -- statuses groups
$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',
RCrmActions::eventLog(
'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException',
$e->getCode() . ': ' . $e->getMessage()
);
echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode()));
}
catch (InvalidArgumentException $e) {
} catch (InvalidArgumentException $e) {
$badKey = true;
echo CAdminMessage::ShowMessage(GetMessage('ERR_403'));
}
//bitrix orderTypesList -- personTypes
$dbOrderTypesList = CSalePersonType::GetList(
array(
"SORT" => "ASC",
"NAME" => "ASC"
),
array(
"ACTIVE" => "Y",
),
false,
false,
array()
);
if ($arOrderTypesList = $dbOrderTypesList->Fetch()) {
do {
$arResult['bitrixOrderTypesList'][] = $arOrderTypesList;
} while ($arOrderTypesList = $dbOrderTypesList->Fetch());
}
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
//bitrix deliveryTypesList
$dbDeliveryTypesList = CSaleDelivery::GetList(
array(
"SORT" => "ASC",
"NAME" => "ASC"
),
array(
"ACTIVE" => "Y",
),
false,
false,
array()
);
if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) {
do {
$arResult['bitrixDeliveryTypesList'][] = $arDeliveryTypesList;
} while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch());
}
// bitrix deliveryServicesList
$dbDeliveryServicesList = CSaleDeliveryHandler::GetList(
array(
'SORT' => 'ASC',
'NAME' => 'ASC'
),
array(
'ACTIVE' => 'Y',
'SITE_ID' => $arResult['arSites'][0]['LID']
)
);
if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) {
do {
$arResult['bitrixDeliveryTypesList'][] = array('ID' => $arDeliveryServicesList['SID'], 'NAME' => $arDeliveryServicesList['NAME']);
} while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch());
}
$arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList();
//bitrix paymentTypesList
$dbPaymentTypesList = CSalePaySystem::GetList(
array(
"SORT" => "ASC",
"NAME" => "ASC"
),
array(
"ACTIVE" => "Y"
)
);
if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) {
do {
$arResult['bitrixPaymentTypesList'][] = $arPaymentTypesList;
} while ($arPaymentTypesList = $dbPaymentTypesList->Fetch());
}
//bitrix paymentStatusesList
$dbPaymentStatusesList = CSaleStatus::GetList(
array(
"SORT" => "ASC",
"NAME" => "ASC"
),
array(
"LID" => "ru", //ru
"ACTIVE" => "Y"
)
);
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
do {
$arResult['bitrixPaymentStatusesList'][$arPaymentStatusesList['ID']] = $arPaymentStatusesList;
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
}
$arResult['bitrixPaymentStatusesList'][] = array(
$arResult['bitrixPaymentTypesList'] = RCrmActions::PaymentList();
//bitrix statusesList
$arResult['bitrixPaymentStatusesList'] = RCrmActions::StatusesList();
/*$arResult['bitrixPaymentStatusesList'][] = array(
'ID' => 'YY',
'NAME' => GetMessage('CANCELED')
);
);*/
//bitrix pyament Y/N
$arResult['bitrixPaymentList'][0]['NAME'] = GetMessage('PAYMENT_Y');
@ -543,10 +371,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N');
$arResult['bitrixPaymentList'][1]['ID'] = 'N';
$dbProp = CSaleOrderProps::GetList(array(), array());
while ($arProp = $dbProp->GetNext()) {
$arResult['arProp'][$arProp['PERSON_TYPE_ID']][] = $arProp;
}
//bitrix orderPropsList
$arResult['arProp'] = RCrmActions::OrderPropsList();
//saved cat params
$optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0));
@ -560,8 +386,10 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
$optionsContragentType = unserialize(COption::GetOptionString($mid, $CRM_CONTRAGENT_TYPE, 0));
$optionsLegalDetails = unserialize(COption::GetOptionString($mid, $CRM_LEGAL_DETAILS, 0));
$optionsCustomFields = unserialize(COption::GetOptionString($mid, $CRM_CUSTOM_FIELDS, 0));
$optionsOrderNumbers = COption::GetOptionString($mid, $CRM_ORDER_NUMBERS, 0);
$canselOrderArr = unserialize(COption::GetOptionString($mid, $CRM_CANSEL_ORDER, 0));
$isCustomOrderType = function_exists('intarocrm_set_order_type') || function_exists('intarocrm_get_order_type');
//$isCustomOrderType = function_exists('intarocrm_set_order_type') || function_exists('intarocrm_get_order_type');
$aTabs = array(
array(
@ -584,7 +412,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
),
array(
"DIV" => "edit4",
"TAB" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_TAB'),
"TAB" => GetMessage('OTHER_OPTIONS'),
"ICON" => '',
"TITLE" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_CAPTION')
)
@ -748,26 +576,46 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('PAYMENT_STATUS_LIST'); ?></b></td>
</tr>
<tr>
<td width="50%"></td>
<td width="50%">
<table width="100%">
<tr>
<td width="50%"></td>
<td width="50%"><?php echo GetMessage('CANCELED'); ?></td>
</tr>
</table>
</td>
</tr>
<?php foreach($arResult['bitrixPaymentStatusesList'] as $bitrixPaymentStatus): ?>
<tr>
<td width="50%" class="adm-detail-content-cell-l" name="<?php echo $bitrixPaymentStatus['ID']; ?>">
<?php echo $bitrixPaymentStatus['NAME']; ?>
</td>
<td width="50%" class="adm-detail-content-cell-r">
<select name="payment-status-<?php echo $bitrixPaymentStatus['ID']; ?>" class="typeselect">
<option value=""></option>
<?php foreach($arResult['paymentGroupList'] as $orderStatusGroup): if(!empty($orderStatusGroup['statuses'])) : ?>
<optgroup label="<?php echo $APPLICATION->ConvertCharset($orderStatusGroup['name'], 'utf-8', SITE_CHARSET); ?>">
<?php foreach($orderStatusGroup['statuses'] as $payment): ?>
<?php if(isset($arResult['paymentList'][$payment])): ?>
<option value="<?php echo $arResult['paymentList'][$payment]['code']; ?>" <?php if ($optionsPayStatuses[$bitrixPaymentStatus['ID']] == $arResult['paymentList'][$payment]['code']) echo 'selected'; ?>>
<?php echo $APPLICATION->ConvertCharset($arResult['paymentList'][$payment]['name'], 'utf-8', SITE_CHARSET); ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</optgroup>
<?php endif; endforeach; ?>
</select>
<table width="100%">
<tr>
<td width="70%">
<select name="payment-status-<?php echo $bitrixPaymentStatus['ID']; ?>" class="typeselect">
<option value=""></option>
<?php foreach($arResult['paymentGroupList'] as $orderStatusGroup): if(!empty($orderStatusGroup['statuses'])) : ?>
<optgroup label="<?php echo $APPLICATION->ConvertCharset($orderStatusGroup['name'], 'utf-8', SITE_CHARSET); ?>">
<?php foreach($orderStatusGroup['statuses'] as $payment): ?>
<?php if(isset($arResult['paymentList'][$payment])): ?>
<option value="<?php echo $arResult['paymentList'][$payment]['code']; ?>" <?php if ($optionsPayStatuses[$bitrixPaymentStatus['ID']] == $arResult['paymentList'][$payment]['code']) echo 'selected'; ?>>
<?php echo $APPLICATION->ConvertCharset($arResult['paymentList'][$payment]['name'], 'utf-8', SITE_CHARSET); ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</optgroup>
<?php endif; endforeach; ?>
</select>
</td>
<td width="30%">
<input name="order-cansel-<?php echo $bitrixPaymentStatus['ID']; ?>" <?php if(in_array($bitrixPaymentStatus['ID'], $canselOrderArr)) echo "checked";?> value="Y" type="checkbox" />
</td>
</tr>
</table>
</td>
</tr>
<?php endforeach; ?>
@ -934,6 +782,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</b>
</td>
</tr>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('ORDERS_OPTIONS'); ?></b></td>
</tr>
<tr class="heading">
<td colspan="2">
<b>
<label><input class="addr" type="checkbox" name="order-numbers" value="Y" <?php if($optionsOrderNumbers == 'Y') echo "checked"; ?>> <?php echo GetMessage('ORDER_NUMBERS'); ?></label>
</b>
</td>
</tr>
<?php endif;?>
<?php $tabControl->Buttons(); ?>
<input type="hidden" name="Update" value="Y" />