commit
8c360e512a
4
.env.dist
Normal file
4
.env.dist
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
DB_BITRIX_HOST=""
|
||||||
|
DB_BITRIX_LOGIN=""
|
||||||
|
DB_BITRIX_PASS=""
|
||||||
|
DB_BITRIX_NAME=""
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -7,5 +7,8 @@
|
|||||||
.idea/*
|
.idea/*
|
||||||
/.idea
|
/.idea
|
||||||
/.idea/*
|
/.idea/*
|
||||||
.travis.yml
|
|
||||||
|
|
||||||
|
|
||||||
|
/vendor/
|
||||||
|
.env
|
||||||
|
.phpunit.result.cache
|
||||||
|
25
.travis.yml
Normal file
25
.travis.yml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
language: php
|
||||||
|
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
php:
|
||||||
|
- 7.1
|
||||||
|
- 7.2
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- DB_BITRIX_HOST=localhost
|
||||||
|
- DB_BITRIX_LOGIN=root
|
||||||
|
- DB_BITRIX_PASS=root
|
||||||
|
- DB_BITRIX_NAME=bitrix
|
||||||
|
- BITRIX_PATH=$TRAVIS_BUILD_DIR/bitrix
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
# Change MySQL root password
|
||||||
|
- echo "USE mysql;\nUPDATE user SET password=PASSWORD('root') WHERE user='root';\nFLUSH PRIVILEGES;\n" | mysql -u root
|
||||||
|
|
||||||
|
- composer install
|
||||||
|
- bash tests/bin/before_script.sh
|
||||||
|
|
||||||
|
script:
|
||||||
|
- make test
|
5
Makefile
Normal file
5
Makefile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
test: prepare_module
|
||||||
|
@php -d short_open_tag=On vendor/bin/phpunit -c phpunit.xml.dist
|
||||||
|
|
||||||
|
prepare_module:
|
||||||
|
@composer pre-module-install
|
@ -1,3 +1,4 @@
|
|||||||
|
[![Build Status](https://img.shields.io/travis/retailcrm/bitrix-module/master.svg?style=flat-square)](https://travis-ci.org/retailcrm/bitrix-module)
|
||||||
[![GitHub release](https://img.shields.io/github/release/retailcrm/bitrix-module.svg?style=flat-square)](https://github.com/retailcrm/bitrix-module/releases)
|
[![GitHub release](https://img.shields.io/github/release/retailcrm/bitrix-module.svg?style=flat-square)](https://github.com/retailcrm/bitrix-module/releases)
|
||||||
[![PHP version](https://img.shields.io/badge/PHP->=5.3-blue.svg?style=flat-square)](https://php.net/)
|
[![PHP version](https://img.shields.io/badge/PHP->=5.3-blue.svg?style=flat-square)](https://php.net/)
|
||||||
|
|
||||||
|
21
composer.json
Normal file
21
composer.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "retailcrm/bitrix-module",
|
||||||
|
"scripts": {
|
||||||
|
"pre-module-install": "cp -R intaro.retailcrm $BITRIX_PATH/bitrix/modules"
|
||||||
|
},
|
||||||
|
"description": "Integration module for Bitrix & RetailCRM",
|
||||||
|
"type": "bitrix-module",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "RetailDriver LLC",
|
||||||
|
"email": "integration@retailcrm.ru"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"ext-json": "*"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^7",
|
||||||
|
"vlucas/phpdotenv": "^3.3"
|
||||||
|
}
|
||||||
|
}
|
1591
composer.lock
generated
Normal file
1591
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,17 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RetailCrmCollector
|
||||||
|
*/
|
||||||
class RetailCrmCollector
|
class RetailCrmCollector
|
||||||
{
|
{
|
||||||
public static $MODULE_ID = 'intaro.retailcrm';
|
public static $MODULE_ID = 'intaro.retailcrm';
|
||||||
public static $CRM_COLL_KEY = 'coll_key';
|
public static $CRM_COLL_KEY = 'coll_key';
|
||||||
public static $CRM_COLL = 'collector';
|
public static $CRM_COLL = 'collector';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add Daemon Collector script
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function add()
|
public static function add()
|
||||||
{
|
{
|
||||||
$keys = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_COLL_KEY, 0));
|
$keys = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_COLL_KEY, 0));
|
||||||
$collector = COption::GetOptionString(self::$MODULE_ID, self::$CRM_COLL, 0);
|
$collector = COption::GetOptionString(self::$MODULE_ID, self::$CRM_COLL, 0);
|
||||||
|
|
||||||
if ($collector === 'Y' && !empty($keys[SITE_ID]) && ADMIN_SECTION !== true) {
|
if ($collector === 'Y' && !empty($keys[SITE_ID]) && ADMIN_SECTION !== true) {
|
||||||
global $APPLICATION;
|
|
||||||
global $USER;
|
global $USER;
|
||||||
|
|
||||||
$params = array();
|
$params = array();
|
||||||
@ -24,7 +32,9 @@ class RetailCrmCollector
|
|||||||
_rc('create', '" . $keys[SITE_ID] . "', " . json_encode((object) $params) . ");
|
_rc('create', '" . $keys[SITE_ID] . "', " . json_encode((object) $params) . ");
|
||||||
_rc('send', 'pageView');
|
_rc('send', 'pageView');
|
||||||
</script>";
|
</script>";
|
||||||
$APPLICATION->AddHeadString($str, true);
|
\Bitrix\Main\Page\Asset::getInstance()->addString($str, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* RCrmEvent
|
* Class RetailCrmEvent
|
||||||
*/
|
*/
|
||||||
use \Bitrix\Main\Event;
|
|
||||||
|
|
||||||
class RetailCrmEvent
|
class RetailCrmEvent
|
||||||
{
|
{
|
||||||
protected static $MODULE_ID = 'intaro.retailcrm';
|
protected static $MODULE_ID = 'intaro.retailcrm';
|
||||||
@ -23,29 +21,28 @@ class RetailCrmEvent
|
|||||||
protected static $CRM_SITES_LIST = 'sites_list';
|
protected static $CRM_SITES_LIST = 'sites_list';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OnAfterUserUpdate
|
* @param $arFields
|
||||||
*
|
*
|
||||||
* @param mixed $arFields - User arFields
|
* @return bool
|
||||||
*
|
* @throws InvalidArgumentException
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
function OnAfterUserUpdate($arFields)
|
function OnAfterUserUpdate($arFields)
|
||||||
{
|
{
|
||||||
if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) {
|
if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$arFields['RESULT']) {
|
if (!$arFields['RESULT']) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
|
$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_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
|
||||||
$api = new RetailCrm\ApiClient($api_host, $api_key);
|
|
||||||
|
|
||||||
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
||||||
|
|
||||||
|
$api = new RetailCrm\ApiClient($api_host, $api_key);
|
||||||
$resultOrder = RetailCrmUser::customerEdit($arFields, $api, $optionsSitesList);
|
$resultOrder = RetailCrmUser::customerEdit($arFields, $api, $optionsSitesList);
|
||||||
|
|
||||||
if (!$resultOrder) {
|
if (!$resultOrder) {
|
||||||
RCrmActions::eventLog('RetailCrmEvent::OnAfterUserUpdate', 'RetailCrmUser::customerEdit', 'error update customer');
|
RCrmActions::eventLog('RetailCrmEvent::OnAfterUserUpdate', 'RetailCrmUser::customerEdit', 'error update customer');
|
||||||
}
|
}
|
||||||
@ -84,126 +81,130 @@ class RetailCrmEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* orderSave
|
* @param $event
|
||||||
*
|
|
||||||
* @param object $event - Order object
|
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
function orderSave($event)
|
function orderSave($event)
|
||||||
{
|
{
|
||||||
if ($GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] !== false && $GLOBALS['RETAIL_CRM_HISTORY'] !== true && $GLOBALS['RETAILCRM_ORDER_DELETE'] !== true) {
|
if ($GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] === false
|
||||||
if (!CModule::IncludeModule('iblock')) {
|
&& $GLOBALS['RETAIL_CRM_HISTORY'] === true
|
||||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'iblock', 'module not found');
|
&& $GLOBALS['RETAILCRM_ORDER_DELETE'] === true
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
if (!CModule::IncludeModule('iblock')) {
|
||||||
}
|
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'iblock', 'module not found');
|
||||||
|
|
||||||
if (!CModule::IncludeModule("sale")) {
|
return false;
|
||||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'sale', 'module not found');
|
}
|
||||||
|
|
||||||
return true;
|
if (!CModule::IncludeModule("sale")) {
|
||||||
}
|
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'sale', 'module not found');
|
||||||
|
|
||||||
if (!CModule::IncludeModule("catalog")) {
|
return false;
|
||||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'catalog', 'module not found');
|
}
|
||||||
|
|
||||||
return true;
|
if (!CModule::IncludeModule("catalog")) {
|
||||||
}
|
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'catalog', 'module not found');
|
||||||
|
|
||||||
//exists getParameter("ENTITY")
|
return false;
|
||||||
if (method_exists($event, 'getId')) {
|
}
|
||||||
$obOrder = $event;
|
|
||||||
} elseif (method_exists($event, 'getParameter')) {
|
//exists getParameter("ENTITY")
|
||||||
$obOrder = $event->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 false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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
|
||||||
|
));
|
||||||
|
|
||||||
|
//many sites?
|
||||||
|
if ($optionsSitesList) {
|
||||||
|
if (array_key_exists($arOrder['LID'], $optionsSitesList) && $optionsSitesList[$arOrder['LID']] !== null) {
|
||||||
|
$site = $optionsSitesList[$arOrder['LID']];
|
||||||
} else {
|
} else {
|
||||||
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'events', 'event error');
|
return false;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
} elseif (!$optionsSitesList) {
|
||||||
|
$site = null;
|
||||||
|
}
|
||||||
|
|
||||||
$arOrder = RetailCrmOrder::orderObjToArr($obOrder);
|
//new order?
|
||||||
|
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arOrder['ID'], $site);
|
||||||
|
if (isset($orderCrm['order'])) {
|
||||||
|
$methodApi = 'ordersEdit';
|
||||||
|
$arParams['crmOrder'] = $orderCrm['order'];
|
||||||
|
} else {
|
||||||
|
$methodApi = 'ordersCreate';
|
||||||
|
}
|
||||||
|
|
||||||
//api
|
//user
|
||||||
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
|
$userCrm = RCrmActions::apiMethod($api, 'customersGet', __METHOD__, $arOrder['USER_ID'], $site);
|
||||||
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
|
if (!isset($userCrm['customer'])) {
|
||||||
$api = new RetailCrm\ApiClient($api_host, $api_key);
|
$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');
|
||||||
|
|
||||||
//params
|
return false;
|
||||||
$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
|
|
||||||
));
|
|
||||||
|
|
||||||
//many sites?
|
|
||||||
if ($optionsSitesList) {
|
|
||||||
if (array_key_exists($arOrder['LID'], $optionsSitesList) && $optionsSitesList[$arOrder['LID']] !== null) {
|
|
||||||
$site = $optionsSitesList[$arOrder['LID']];
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} elseif (!$optionsSitesList) {
|
|
||||||
$site = null;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//new order?
|
//order
|
||||||
$orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arOrder['ID'], $site);
|
$resultOrder = RetailCrmOrder::orderSend($arOrder, $api, $arParams, true, $site, $methodApi);
|
||||||
if (isset($orderCrm['order'])) {
|
if (!$resultOrder) {
|
||||||
$methodApi = 'ordersEdit';
|
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'RetailCrmOrder::orderSend', 'error during creating order');
|
||||||
$arParams['crmOrder'] = $orderCrm['order'];
|
|
||||||
} else {
|
|
||||||
$methodApi = 'ordersCreate';
|
|
||||||
}
|
|
||||||
|
|
||||||
//user
|
return false;
|
||||||
$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 true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* paymentSave
|
* @param \Bitrix\Sale\Payment $event
|
||||||
*
|
*
|
||||||
* @param \Bitrix\Sale\Payment $event - Payment object
|
* @throws InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function paymentSave($event)
|
function paymentSave($event)
|
||||||
{
|
{
|
||||||
@ -216,7 +217,7 @@ class RetailCrmEvent
|
|||||||
|| $apiVersion != 'v5'
|
|| $apiVersion != 'v5'
|
||||||
|| $order->isNew()
|
|| $order->isNew()
|
||||||
) {
|
) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
$optionsSitesList = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
||||||
@ -237,7 +238,7 @@ class RetailCrmEvent
|
|||||||
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
|
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
|
||||||
$site = $optionsSitesList[$arPayment['LID']];
|
$site = $optionsSitesList[$arPayment['LID']];
|
||||||
} else {
|
} else {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
} elseif (!$optionsSitesList) {
|
} elseif (!$optionsSitesList) {
|
||||||
$site = null;
|
$site = null;
|
||||||
@ -288,7 +289,7 @@ class RetailCrmEvent
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.');
|
RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.');
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists($arPayment['ID'], $paymentsExternalIds)) {
|
if (!array_key_exists($arPayment['ID'], $paymentsExternalIds)) {
|
||||||
@ -299,12 +300,14 @@ class RetailCrmEvent
|
|||||||
RCrmActions::apiMethod($api, 'ordersPaymentDelete', __METHOD__, $paymentsExternalIds[$arPayment['ID']]['id']);
|
RCrmActions::apiMethod($api, 'ordersPaymentDelete', __METHOD__, $paymentsExternalIds[$arPayment['ID']]['id']);
|
||||||
RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site);
|
RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* paymentDelete
|
* @param \Bitrix\Sale\Payment $event
|
||||||
*
|
*
|
||||||
* @param object $event - Payment object
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
function paymentDelete($event)
|
function paymentDelete($event)
|
||||||
{
|
{
|
||||||
|
18
phpunit.xml.dist
Normal file
18
phpunit.xml.dist
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit
|
||||||
|
bootstrap="tests/phpunit/bootstrap.php"
|
||||||
|
backupGlobals="false"
|
||||||
|
colors="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
verbose="true"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnFailure="false"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Retailcrm Bitrix module Test Suite">
|
||||||
|
<directory suffix=".php">tests/phpunit</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
21
tests/bin/before_script.sh
Executable file
21
tests/bin/before_script.sh
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ -d $TRAVIS_BUILD_DIR ]; then
|
||||||
|
BITRIX_PATH="$TRAVIS_BUILD_DIR/bitrix"
|
||||||
|
fi
|
||||||
|
|
||||||
|
download() {
|
||||||
|
wget http://download.retailcrm.pro/modules/bitrix/bitrix.tar.gz
|
||||||
|
|
||||||
|
mkdir $BITRIX_PATH
|
||||||
|
tar -xf $TRAVIS_BUILD_DIR/bitrix.tar.gz -C $BITRIX_PATH
|
||||||
|
rm $TRAVIS_BUILD_DIR/bitrix.tar.gz
|
||||||
|
}
|
||||||
|
|
||||||
|
create_db() {
|
||||||
|
mysqladmin create $DB_BITRIX_NAME --user="$DB_BITRIX_LOGIN" --password="$DB_BITRIX_PASS"
|
||||||
|
mysql --user="$DB_BITRIX_LOGIN" --password="$DB_BITRIX_PASS" $DB_BITRIX_NAME < $BITRIX_PATH/dump.sql
|
||||||
|
}
|
||||||
|
|
||||||
|
download
|
||||||
|
create_db
|
33
tests/phpunit/bootstrap.php
Normal file
33
tests/phpunit/bootstrap.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PHP version 7.0
|
||||||
|
*
|
||||||
|
* @category Integration
|
||||||
|
* @author RetailCRM <integration@retailcrm.ru>
|
||||||
|
* @license http://retailcrm.ru Proprietary
|
||||||
|
* @link http://retailcrm.ru
|
||||||
|
* @see http://help.retailcrm.ru
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (file_exists(__DIR__ . '/../../.env')) {
|
||||||
|
$dotenv = Dotenv\Dotenv::create(__DIR__ . '/../../');
|
||||||
|
$dotenv->load();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getenv('TRAVIS_BUILD_DIR')) {
|
||||||
|
$_SERVER['DOCUMENT_ROOT'] = getenv('TRAVIS_BUILD_DIR') . '/bitrix';
|
||||||
|
} else {
|
||||||
|
$_SERVER['DOCUMENT_ROOT'] = getenv('BITRIX_PATH');
|
||||||
|
}
|
||||||
|
|
||||||
|
define('NOT_CHECK_PERMISSIONS', true);
|
||||||
|
define('NO_AGENT_CHECK', true);
|
||||||
|
|
||||||
|
require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php');
|
||||||
|
|
||||||
|
global $USER;
|
||||||
|
$USER->Authorize(1);
|
||||||
|
|
||||||
|
if (!CModule::IncludeModule('intaro.retailcrm')) {
|
||||||
|
RegisterModule('intaro.retailcrm');
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class RetailCrmCollectorTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
const TEST_KEY = 'RC-XXXXXXXXXX-X';
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
COption::SetOptionString(
|
||||||
|
RetailCrmCollector::$MODULE_ID,
|
||||||
|
RetailCrmCollector::$CRM_COLL_KEY,
|
||||||
|
serialize([SITE_ID => self::TEST_KEY])
|
||||||
|
);
|
||||||
|
|
||||||
|
COption::SetOptionString(
|
||||||
|
RetailCrmCollector::$MODULE_ID,
|
||||||
|
RetailCrmCollector::$CRM_COLL,
|
||||||
|
'Y'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAdd()
|
||||||
|
{
|
||||||
|
RetailCrmCollector::add();
|
||||||
|
$strings = \Bitrix\Main\Page\Asset::getInstance()->getStrings();
|
||||||
|
|
||||||
|
$this->assertContains(self::TEST_KEY, $strings);
|
||||||
|
$this->assertContains('customerId', $strings);
|
||||||
|
}
|
||||||
|
}
|
240
tests/phpunit/classes/general/events/RetailCrmEventTest.php
Normal file
240
tests/phpunit/classes/general/events/RetailCrmEventTest.php
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RetailCrmEventTest
|
||||||
|
*/
|
||||||
|
class RetailCrmEventTest extends PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var RetailCrmEvent
|
||||||
|
*/
|
||||||
|
private $retailcrmEvent;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
||||||
|
CModule::IncludeModule('intaro.retailcrm');
|
||||||
|
|
||||||
|
$this->retailcrmEvent = new RetailCrmEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $history
|
||||||
|
* @param $emptyData
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||||
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @dataProvider userUpdateDataProvider
|
||||||
|
*/
|
||||||
|
public function testOnAfterUserUpdate($history, $emptyData)
|
||||||
|
{
|
||||||
|
$arFields = [
|
||||||
|
'ID' => 1
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($history === true) {
|
||||||
|
$GLOBALS['RETAIL_CRM_HISTORY'] = $history;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($emptyData === true) {
|
||||||
|
$arFields['RESULT'] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->retailcrmEvent->OnAfterUserUpdate($arFields);
|
||||||
|
|
||||||
|
$this->assertEquals(false, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $history
|
||||||
|
* @param $v5
|
||||||
|
* @param $new
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
* @throws \PHPUnit\Framework\Exception
|
||||||
|
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||||
|
* @throws \PHPUnit\Framework\MockObject\RuntimeException
|
||||||
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @dataProvider paymentSaveDataProvider
|
||||||
|
*/
|
||||||
|
public function testPaymentSave($history, $v5, $new)
|
||||||
|
{
|
||||||
|
$event = $this->createMock(\Bitrix\Sale\Payment::class);
|
||||||
|
|
||||||
|
$order = $this->createMock(\Bitrix\Sale\Order::class);
|
||||||
|
$order->expects($this->any())
|
||||||
|
->method('isNew')
|
||||||
|
->willReturn($new);
|
||||||
|
|
||||||
|
$paymentCollection = $this->createMock(\Bitrix\Sale\PaymentCollection::class);
|
||||||
|
$paymentCollection->expects($this->any())
|
||||||
|
->method('getOrder')
|
||||||
|
->willReturn($order);
|
||||||
|
|
||||||
|
$event->method('getCollection')->willReturn($paymentCollection);
|
||||||
|
|
||||||
|
if ($history === true) {
|
||||||
|
$GLOBALS['RETAIL_CRM_HISTORY'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($v5 === false) {
|
||||||
|
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->retailcrmEvent->paymentSave($event);
|
||||||
|
|
||||||
|
$this->assertEquals(false, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $history
|
||||||
|
* @param $v5
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
* @throws \PHPUnit\Framework\Exception
|
||||||
|
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||||
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @dataProvider paymentDeleteDataProvider
|
||||||
|
*/
|
||||||
|
public function testPaymentDelete($history, $v5)
|
||||||
|
{
|
||||||
|
$event = $this->createMock(\Bitrix\Sale\Payment::class);
|
||||||
|
|
||||||
|
if ($history === true) {
|
||||||
|
$GLOBALS['RETAIL_CRM_HISTORY'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($v5 === false) {
|
||||||
|
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v4');
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->retailcrmEvent->paymentDelete($event);
|
||||||
|
|
||||||
|
$this->assertEquals(false, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
* @throws \PHPUnit\Framework\Exception
|
||||||
|
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||||
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testOrderSave()
|
||||||
|
{
|
||||||
|
$GLOBALS['RETAIL_CRM_HISTORY'] = true;
|
||||||
|
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = false;
|
||||||
|
$GLOBALS['RETAILCRM_ORDER_DELETE'] = true;
|
||||||
|
|
||||||
|
$event = $this->createMock(\Bitrix\Main\Event::class);
|
||||||
|
|
||||||
|
$result = $this->retailcrmEvent->orderSave($event);
|
||||||
|
|
||||||
|
$this->assertEquals(false, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
* @throws \PHPUnit\Framework\Exception
|
||||||
|
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||||
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testOrderDelete()
|
||||||
|
{
|
||||||
|
$event = $this->createMock(\Bitrix\Main\Event::class);
|
||||||
|
|
||||||
|
$result = $this->retailcrmEvent->OrderDelete($event);
|
||||||
|
|
||||||
|
$this->assertEquals(null, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||||
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testOnUpdateOrder()
|
||||||
|
{
|
||||||
|
$arFields = [];
|
||||||
|
|
||||||
|
$result = $this->retailcrmEvent->OnUpdateOrder(1, $arFields);
|
||||||
|
|
||||||
|
$this->assertEquals(null, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function userUpdateDataProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'history' => true,
|
||||||
|
'emptyData' => false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'history' => false,
|
||||||
|
'emptyData' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function paymentSaveDataProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'history' => true,
|
||||||
|
'v5' => true,
|
||||||
|
'new' => false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'history' => false,
|
||||||
|
'v5' => false,
|
||||||
|
'new' => false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'history' => false,
|
||||||
|
'v5' => true,
|
||||||
|
'new' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function paymentDeleteDataProvider()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'history' => true,
|
||||||
|
'v5' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'history' => false,
|
||||||
|
'v5' => false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'history' => false,
|
||||||
|
'v5' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
$GLOBALS['RETAIL_CRM_HISTORY'] = false;
|
||||||
|
$GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = true;
|
||||||
|
$GLOBALS['RETAILCRM_ORDER_DELETE'] = false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user