Skip to content

Commit

Permalink
v.2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostrainman committed Oct 4, 2016
1 parent 53c1117 commit 02828f4
Show file tree
Hide file tree
Showing 19 changed files with 578 additions and 567 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 2016-10-04 v.2.0.3
* fix состава отгрузки

## 2016-10-04 v.2.0.2
* Исправлены ошибки

## 2016-10-03 v.2.0.1
* Исправлены ошибки

## 2016-09-12 v.2.0.0
* API V4
* Переход на ядро d7
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Bitrix module
=============

Bitrix module for interaction with [retailCRM](http://www.retailcrm.ru) through [REST API](http://retailcrm.ru/docs/Разработчики).
Bitrix module for interaction with [retailCRM](http://www.retailcrm.ru) through [REST API](http://www.retailcrm.ru/docs/Developers/Index).

Module allows:

* Exchange the orders with retailCRM
* Configure relations between dictionaries of retailCRM and Bitrix (statuses, payments, delivery types and etc)
* Generate [ICML](http://docs.retailcrm.ru/index.php?n=Разработчики.ФорматICML) (Intaro Markup Language) for catalog loading by retailCRM
* Generate [ICML](http://www.retailcrm.ru/docs/Developers/ICML) (Intaro Markup Language) for catalog loading by retailCRM

Installation
-------------

You should install module through [Bitrix.Marketplace](http://marketplace.1c-bitrix.ru/solutions/intaro.intarocrm/).
You should install module through [Bitrix.Marketplace](http://marketplace.1c-bitrix.ru/solutions/intaro.retailcrm/).
5 changes: 2 additions & 3 deletions intaro.retailcrm/classes/general/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public function write($dump, $file = 'info')
{
$rsSites = CSite::GetList($by, $sort, array('DEF' => 'Y'));
$ar = $rsSites->Fetch();
if (!is_dir($ar['ABS_DOC_ROOT'] . $this->logPath . '/'))
{
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';
Expand All @@ -24,7 +23,7 @@ public function write($dump, $file = 'info')
$data['DATA'] = $dump;

$f = fopen($file, "a+");
fwrite($f, print_r($data,true));
fwrite($f, print_r($data, true));
fclose($f);

// if filesize more than 5 Mb rotate it
Expand Down
66 changes: 39 additions & 27 deletions intaro.retailcrm/classes/general/RCrmActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ class RCrmActions

const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';

public static function SitesList(){
public static function SitesList()
{
$arSites = array();
$rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y'));
while ($ar = $rsSites->Fetch()){
while ($ar = $rsSites->Fetch()) {
$arSites[] = $ar;
}

return $arSites;
}

public static function OrderTypesList($arSites){
public static function OrderTypesList($arSites)
{
$orderTypesList = array();
foreach($arSites as $site){
foreach ($arSites as $site) {
$personTypes = \Bitrix\Sale\PersonType::load($site['LID']);
$bitrixOrderTypesList = array();
foreach($personTypes as $personType){
if(!array_key_exists($personType['ID'], $orderTypesList)){
foreach ($personTypes as $personType) {
if (!array_key_exists($personType['ID'], $orderTypesList)) {
$bitrixOrderTypesList[$personType['ID']] = $personType;
}
asort($bitrixOrderTypesList);
Expand All @@ -34,49 +36,52 @@ public static function OrderTypesList($arSites){
return $orderTypesList;
}

public static function DeliveryList(){
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){
foreach ($arDeliveryServiceAll as $arDeliveryService) {
if ($arDeliveryService['PARENT_ID'] == '0' && $arDeliveryService['ID'] != $noOrderId) {
$bitrixDeliveryTypesList[] = $arDeliveryService;
}
}

return $bitrixDeliveryTypesList;
}

public static function PaymentList(){
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())
{
while ($payment = $dbPaymentAll->fetch()) {
$bitrixPaymentTypesList[] = $payment;
}

return $bitrixPaymentTypesList;
}

public static function StatusesList(){
public static function StatusesList()
{
$bitrixPaymentStatusesList = array();
$arStatusesAll = \Bitrix\Sale\OrderStatus::getAllStatusesNames();
foreach($arStatusesAll as $key => $arStatus){
foreach ($arStatusesAll as $key => $arStatus) {
$bitrixPaymentStatusesList[$key] = array('ID' => $key, 'NAME' => $arStatus);
}

return $bitrixPaymentStatusesList;
}

public static function OrderPropsList(){
public static function OrderPropsList()
{
$bitrixPropsList = array();
$arPropsAll = \Bitrix\Sale\Internals\OrderPropsTable::getList(array(
'select' => array('*')
));
while ($prop = $arPropsAll->Fetch()){
while ($prop = $arPropsAll->Fetch()) {
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
}

Expand All @@ -87,8 +92,8 @@ public static function OrderPropsList(){
* w+ event in bitrix log
*/

public static function eventLog($auditType, $itemId, $description) {

public static function eventLog($auditType, $itemId, $description)
{
CEventLog::Add(array(
"SEVERITY" => "SECURITY",
"AUDIT_TYPE_ID" => $auditType,
Expand All @@ -105,7 +110,8 @@ public static function eventLog($auditType, $itemId, $description) {
* @return self name
*/

public static function uploadOrdersAgent() {
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)) {
Expand All @@ -122,8 +128,9 @@ public static function uploadOrdersAgent() {
* @return self name
*/

public static function orderAgent() {
if(COption::GetOptionString('main', 'agents_use_crontab', 'N') != 'N') {
public static function orderAgent()
{
if (COption::GetOptionString('main', 'agents_use_crontab', 'N') != 'N') {
define('NO_AGENT_CHECK', true);
}

Expand All @@ -141,7 +148,8 @@ public static function orderAgent() {
* @param array $arr
* @return array
*/
public static function clearArr($arr) {
public static function clearArr($arr)
{
if (is_array($arr) === false) {
return $arr;
}
Expand All @@ -163,7 +171,8 @@ public static function clearArr($arr) {
* @param $str in SITE_CHARSET
* @return $str in utf-8
*/
public static function toJSON($str) {
public static function toJSON($str)
{
global $APPLICATION;

return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8');
Expand All @@ -175,13 +184,15 @@ public static function toJSON($str) {
* @param $str in utf-8
* @return $str in SITE_CHARSET
*/
public static function fromJSON($str) {
public static function fromJSON($str)
{
global $APPLICATION;

return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET);
}

public static function explodeFIO($fio) {
public static function explodeFIO($fio)
{
$newFio = empty($fio) ? false : explode(" ", $fio, 3);
$result = array();
switch (count($newFio)) {
Expand Down Expand Up @@ -210,8 +221,9 @@ public static function explodeFIO($fio) {
return $result;
}

public static function apiMethod($api, $methodApi, $method, $params, $site = null) {
switch($methodApi){
public static function apiMethod($api, $methodApi, $method, $params, $site = null)
{
switch ($methodApi) {
case 'ordersGet':
case 'ordersEdit':
case 'customersGet':
Expand Down
23 changes: 2 additions & 21 deletions intaro.retailcrm/classes/general/RestNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@ final public function __construct()
$this->server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot();
}

/**
* Installation file validation
* @param string $file The path to the file validation
* @return void
* @access public
* @final
*/
// 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
* @param string $file The path to the file validation
Expand Down Expand Up @@ -117,10 +99,9 @@ final private function formatting($data, $skip = false)
$formatted = array();

foreach ($data as $code => $value) {

if (isset($this->validation[ $code ]) && $this->validation[ $code ]['type'] == 'skip') {
$formatted[ $code ] = $value;
}elseif (isset($this->validation[ $code ]) && is_array($value) === false) {
} elseif (isset($this->validation[ $code ]) && is_array($value) === false) {
$formatted[ $code ] = $this->setFormat($value, $this->validation[ $code ]);
} elseif (is_array($value)) {
$formatted[ $code ] = $this->formatting($value, true);
Expand Down Expand Up @@ -208,7 +189,7 @@ final private function setString($data, $validation)
} elseif (isset($validation['min']) && mb_strlen($data) < $validation['min']) {
$pad = isset($validation['pad']) && mb_strlen($validation['pad']) == 1 ? $validation['pad'] : ' ';
$data .= str_repeat($pad, $validation['min'] - mb_strlen($data));
}elseif (isset($validation['max']) && mb_strlen($data) > $validation['max']) {
} elseif (isset($validation['max']) && mb_strlen($data) > $validation['max']) {
$data = mb_substr($data, 0, $validation['max']);
}

Expand Down
Loading

0 comments on commit 02828f4

Please sign in to comment.