diff --git a/CHANGELOG.md b/CHANGELOG.md index a9652650..3c03408e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2021-11-12 v.6.0.0 +* Добавлена поддержка программы лояльности + ## 2021-10-15 v.5.8.4 * Исправление некорректной генерации каталога при повторных запусках генерации diff --git a/bin/build b/bin/build index 949fefae..4631ec6f 100644 --- a/bin/build +++ b/bin/build @@ -29,7 +29,8 @@ echo "Update version and date in the file \"version.php\"" for i in `find ./"$version" -type f -name '*.*'`; do encoding=`file -b --mime-encoding "$i"` - if [ "$encoding" != "iso-8859-1" ] && [ "$encoding" != "binary" ]; then + if [ "$encoding" != "iso-8859-1" ] && [ "$encoding" != "us-ascii" ] && [ "$encoding" != "binary" ]; then + echo "$i: converting from $encoding to cp1251" result=$(iconv -f $encoding -t "cp1251" $i -o $i.cp1251 2>&1 > /dev/null) if [ ! -z "$result" ]; then echo "Errors in file $i" diff --git a/bin/build-release b/bin/build-release index 46f17bc7..7c8af5cb 100644 --- a/bin/build-release +++ b/bin/build-release @@ -24,9 +24,7 @@ if (!$handle) { $modifiedFiles = []; while (($buffer = fgets($handle)) !== false) { - $file = explode("\t", trim($buffer)); - $modifiedFile = new ModifiedFile($file[1], $file[0]{0}); - $modifiedFiles[] = $modifiedFile; + $modifiedFiles[] = new ModifiedFile($buffer); } try { diff --git a/composer.json b/composer.json index 52b2760c..991265a3 100755 --- a/composer.json +++ b/composer.json @@ -5,6 +5,7 @@ "tests": "php vendor/bin/phpunit -c phpunit.xml.dist --whitelist=$BITRIX_PATH/bitrix/modules/intaro.retailcrm" }, "description": "Integration module for Bitrix & RetailCRM", + "license": "MIT", "type": "bitrix-module", "authors": [ { @@ -15,6 +16,7 @@ "require": { "ext-json": "*", "ext-mbstring": "*", + "ext-tokenizer": "*", "ext-xmlwriter": "*" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 66b54f40..3120278b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,41 +4,36 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "72c54dce7daa3cd6c40577578128091a", + "content-hash": "a51135dfd806a9758965d7dd91cb8b2a", "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.3.0", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "ae466f726242e637cebdd526a7d991b9433bacf1" + "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1", - "reference": "ae466f726242e637cebdd526a7d991b9433bacf1", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b", + "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^6.0", + "doctrine/coding-standard": "^8.0", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.13", - "phpstan/phpstan-phpunit": "^0.11", - "phpstan/phpstan-shim": "^0.11", - "phpunit/phpunit": "^7.0" + "phpbench/phpbench": "^0.13 || 1.0.0-alpha2", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" @@ -52,7 +47,7 @@ { "name": "Marco Pivetta", "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" + "homepage": "https://ocramius.github.io/" } ], "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", @@ -61,20 +56,38 @@ "constructor", "instantiate" ], - "time": "2019-10-21T16:45:58+00:00" + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.4.0" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", + "type": "tidelift" + } + ], + "time": "2020-11-10T18:47:58+00:00" }, { "name": "fzaninotto/faker", - "version": "v1.9.1", + "version": "v1.9.2", "source": { "type": "git", "url": "https://github.com/fzaninotto/Faker.git", - "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f" + "reference": "848d8125239d7dbf8ab25cb7f054f1a630e68c2e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/fc10d778e4b84d5bd315dad194661e091d307c6f", - "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/848d8125239d7dbf8ab25cb7f054f1a630e68c2e", + "reference": "848d8125239d7dbf8ab25cb7f054f1a630e68c2e", "shasum": "" }, "require": { @@ -111,7 +124,12 @@ "faker", "fixtures" ], - "time": "2019-12-12T13:22:17+00:00" + "support": { + "issues": "https://github.com/fzaninotto/Faker/issues", + "source": "https://github.com/fzaninotto/Faker/tree/v1.9.2" + }, + "abandoned": true, + "time": "2020-12-11T09:56:16+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -158,6 +176,10 @@ "keywords": [ "test" ], + "support": { + "issues": "https://github.com/hamcrest/hamcrest-php/issues", + "source": "https://github.com/hamcrest/hamcrest-php/tree/v2.0.1" + }, "time": "2020-07-09T08:09:16+00:00" }, { @@ -223,24 +245,28 @@ "test double", "testing" ], + "support": { + "issues": "https://github.com/mockery/mockery/issues", + "source": "https://github.com/mockery/mockery/tree/1.3.3" + }, "time": "2020-08-11T18:10:21+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.9.5", + "version": "1.10.2", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef" + "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/b2c28789e80a97badd14145fda39b545d83ca3ef", - "reference": "b2c28789e80a97badd14145fda39b545d83ca3ef", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220", + "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1 || ^8.0" }, "replace": { "myclabs/deep-copy": "self.version" @@ -271,7 +297,17 @@ "object", "object graph" ], - "time": "2020-01-17T21:11:47+00:00" + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2020-11-13T09:40:50+00:00" }, { "name": "phar-io/manifest", @@ -326,6 +362,10 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/master" + }, "time": "2018-07-08T19:23:20+00:00" }, { @@ -373,28 +413,29 @@ } ], "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/master" + }, "time": "2018-07-08T19:19:57+00:00" }, { "name": "phpdocumentor/reflection-common", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" + "reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/6568f4687e5b41b054365f9ae03fcb1ed5f2069b", + "reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b", "shasum": "" }, "require": { "php": ">=7.1" }, - "require-dev": { - "phpunit/phpunit": "~6" - }, "type": "library", "extra": { "branch-alias": { @@ -425,7 +466,11 @@ "reflection", "static analysis" ], - "time": "2018-08-07T13:53:10+00:00" + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/master" + }, + "time": "2020-04-27T09:25:28+00:00" }, { "name": "phpdocumentor/reflection-docblock", @@ -477,6 +522,10 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/release/4.x" + }, "time": "2019-12-28T18:55:12+00:00" }, { @@ -524,28 +573,32 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "support": { + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/0.7.2" + }, "time": "2019-08-22T18:11:29+00:00" }, { "name": "phpoption/phpoption", - "version": "1.7.2", + "version": "1.7.5", "source": { "type": "git", "url": "https://github.com/schmittjoh/php-option.git", - "reference": "77f7c4d2e65413aff5b5a8cc8b3caf7a28d81959" + "reference": "994ecccd8f3283ecf5ac33254543eb0ac946d525" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/77f7c4d2e65413aff5b5a8cc8b3caf7a28d81959", - "reference": "77f7c4d2e65413aff5b5a8cc8b3caf7a28d81959", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/994ecccd8f3283ecf5ac33254543eb0ac946d525", + "reference": "994ecccd8f3283ecf5ac33254543eb0ac946d525", "shasum": "" }, "require": { - "php": "^5.5.9 || ^7.0" + "php": "^5.5.9 || ^7.0 || ^8.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.3", - "phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0" + "bamarni/composer-bin-plugin": "^1.4.1", + "phpunit/phpunit": "^4.8.35 || ^5.7.27 || ^6.5.6 || ^7.0 || ^8.0 || ^9.0" }, "type": "library", "extra": { @@ -579,7 +632,21 @@ "php", "type" ], - "time": "2019-12-15T19:35:24+00:00" + "support": { + "issues": "https://github.com/schmittjoh/php-option/issues", + "source": "https://github.com/schmittjoh/php-option/tree/1.7.5" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption", + "type": "tidelift" + } + ], + "time": "2020-07-20T17:29:33+00:00" }, { "name": "phpspec/prophecy", @@ -642,6 +709,10 @@ "spy", "stub" ], + "support": { + "issues": "https://github.com/phpspec/prophecy/issues", + "source": "https://github.com/phpspec/prophecy/tree/v1.10.3" + }, "time": "2020-03-05T15:02:03+00:00" }, { @@ -705,27 +776,31 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/master" + }, "time": "2018-10-31T16:06:48+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "2.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "050bedf145a257b1ff02746c31894800e5122946" + "reference": "4b49fb70f067272b659ef0174ff9ca40fdaa6357" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", - "reference": "050bedf145a257b1ff02746c31894800e5122946", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/4b49fb70f067272b659ef0174ff9ca40fdaa6357", + "reference": "4b49fb70f067272b659ef0174ff9ca40fdaa6357", "shasum": "" }, "require": { - "php": "^7.1" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^7.1" + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { @@ -755,7 +830,17 @@ "filesystem", "iterator" ], - "time": "2018-09-13T20:33:42+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T08:25:21+00:00" }, { "name": "phpunit/php-text-template", @@ -796,27 +881,31 @@ "keywords": [ "template" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/1.2.1" + }, "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", - "version": "2.1.2", + "version": "2.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e" + "reference": "2454ae1765516d20c4ffe103d85a58a9a3bd5662" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/1038454804406b0b5f5f520358e78c1c2f71501e", - "reference": "1038454804406b0b5f5f520358e78c1c2f71501e", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/2454ae1765516d20c4ffe103d85a58a9a3bd5662", + "reference": "2454ae1765516d20c4ffe103d85a58a9a3bd5662", "shasum": "" }, "require": { - "php": "^7.1" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { @@ -845,25 +934,35 @@ "keywords": [ "timer" ], - "time": "2019-06-07T04:22:29+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/2.1.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T08:20:02+00:00" }, { "name": "phpunit/php-token-stream", - "version": "3.1.1", + "version": "3.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff" + "reference": "472b687829041c24b25f475e14c2f38a09edf1c2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/995192df77f63a59e47f025390d2d1fdf8f425ff", - "reference": "995192df77f63a59e47f025390d2d1fdf8f425ff", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/472b687829041c24b25f475e14c2f38a09edf1c2", + "reference": "472b687829041c24b25f475e14c2f38a09edf1c2", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": "^7.1" + "php": ">=7.1" }, "require-dev": { "phpunit/phpunit": "^7.0" @@ -894,7 +993,18 @@ "keywords": [ "tokenizer" ], - "time": "2019-09-17T06:23:10+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", + "source": "https://github.com/sebastianbergmann/php-token-stream/tree/3.1.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "abandoned": true, + "time": "2020-11-30T08:38:46+00:00" }, { "name": "phpunit/phpunit", @@ -978,27 +1088,31 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "source": "https://github.com/sebastianbergmann/phpunit/tree/7.5.20" + }, "time": "2020-01-08T08:45:45+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/1de8cd5c010cb153fcd68b8d0f64606f523f7619", + "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { @@ -1023,29 +1137,39 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/1.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T08:15:22+00:00" }, { "name": "sebastian/comparator", - "version": "3.0.2", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" + "reference": "1071dfcef776a57013124ff35e1fc41ccd294758" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", - "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1071dfcef776a57013124ff35e1fc41ccd294758", + "reference": "1071dfcef776a57013124ff35e1fc41ccd294758", "shasum": "" }, "require": { - "php": "^7.1", + "php": ">=7.1", "sebastian/diff": "^3.0", "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^7.1" + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { @@ -1063,6 +1187,10 @@ "BSD-3-Clause" ], "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -1074,10 +1202,6 @@ { "name": "Bernhard Schussek", "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" } ], "description": "Provides the functionality to compare PHP values for equality", @@ -1087,24 +1211,34 @@ "compare", "equality" ], - "time": "2018-07-12T15:12:46+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/3.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T08:04:30+00:00" }, { "name": "sebastian/diff", - "version": "3.0.2", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" + "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", - "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/14f72dd46eaf2f2293cbe79c93cc0bc43161a211", + "reference": "14f72dd46eaf2f2293cbe79c93cc0bc43161a211", "shasum": "" }, "require": { - "php": "^7.1" + "php": ">=7.1" }, "require-dev": { "phpunit/phpunit": "^7.5 || ^8.0", @@ -1126,13 +1260,13 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" } ], "description": "Diff implementation", @@ -1143,24 +1277,34 @@ "unidiff", "unified diff" ], - "time": "2019-02-04T06:01:07+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/3.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:59:04+00:00" }, { "name": "sebastian/environment", - "version": "4.2.3", + "version": "4.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368" + "reference": "d47bbbad83711771f167c72d4e3f25f7fcc1f8b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/464c90d7bdf5ad4e8a6aea15c091fec0603d4368", - "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/d47bbbad83711771f167c72d4e3f25f7fcc1f8b0", + "reference": "d47bbbad83711771f167c72d4e3f25f7fcc1f8b0", "shasum": "" }, "require": { - "php": "^7.1" + "php": ">=7.1" }, "require-dev": { "phpunit/phpunit": "^7.5" @@ -1196,24 +1340,34 @@ "environment", "hhvm" ], - "time": "2019-11-20T08:46:58+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/4.2.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:53:42+00:00" }, { "name": "sebastian/exporter", - "version": "3.1.2", + "version": "3.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" + "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/6b853149eab67d4da22291d36f5b0631c0fd856e", + "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e", "shasum": "" }, "require": { - "php": "^7.0", + "php": ">=7.0", "sebastian/recursion-context": "^3.0" }, "require-dev": { @@ -1263,7 +1417,17 @@ "export", "exporter" ], - "time": "2019-09-14T09:02:43+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/3.1.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:47:53+00:00" }, { "name": "sebastian/global-state", @@ -1314,24 +1478,28 @@ "keywords": [ "global state" ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/2.0.0" + }, "time": "2017-04-27T15:39:26+00:00" }, { "name": "sebastian/object-enumerator", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", + "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", "shasum": "" }, "require": { - "php": "^7.0", + "php": ">=7.0", "sebastian/object-reflector": "^1.1.1", "sebastian/recursion-context": "^3.0" }, @@ -1361,24 +1529,34 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-08-03T12:35:26+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/3.0.4" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:40:27+00:00" }, { "name": "sebastian/object-reflector", - "version": "1.1.1", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "773f97c67f28de00d397be301821b06708fca0be" + "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", - "reference": "773f97c67f28de00d397be301821b06708fca0be", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", + "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", "shasum": "" }, "require": { - "php": "^7.0" + "php": ">=7.0" }, "require-dev": { "phpunit/phpunit": "^6.0" @@ -1406,24 +1584,34 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "time": "2017-03-29T09:07:27+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/1.1.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:37:18+00:00" }, { "name": "sebastian/recursion-context", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/367dcba38d6e1977be014dc4b22f47a484dac7fb", + "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb", "shasum": "" }, "require": { - "php": "^7.0" + "php": ">=7.0" }, "require-dev": { "phpunit/phpunit": "^6.0" @@ -1444,14 +1632,14 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, { "name": "Adam Harvey", "email": "aharvey@php.net" @@ -1459,24 +1647,34 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2017-03-03T06:23:57+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/3.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:34:24+00:00" }, { "name": "sebastian/resource-operations", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" + "reference": "31d35ca87926450c44eae7e2611d45a7a65ea8b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", - "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/31d35ca87926450c44eae7e2611d45a7a65ea8b3", + "reference": "31d35ca87926450c44eae7e2611d45a7a65ea8b3", "shasum": "" }, "require": { - "php": "^7.1" + "php": ">=7.1" }, "type": "library", "extra": { @@ -1501,7 +1699,17 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2018-10-04T04:07:39+00:00" + "support": { + "issues": "https://github.com/sebastianbergmann/resource-operations/issues", + "source": "https://github.com/sebastianbergmann/resource-operations/tree/2.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:30:19+00:00" }, { "name": "sebastian/version", @@ -1544,24 +1752,28 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/master" + }, "time": "2016-10-03T07:35:21+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.14.0", + "version": "v1.22.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38" + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", - "reference": "fbdeaec0df06cf3d51c93de80c7eb76e271f5a38", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=7.1" }, "suggest": { "ext-ctype": "For best performance" @@ -1569,7 +1781,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.14-dev" + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -1602,7 +1818,24 @@ "polyfill", "portable" ], - "time": "2020-01-13T11:15:53+00:00" + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-07T16:49:33+00:00" }, { "name": "theseer/tokenizer", @@ -1642,33 +1875,39 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/master" + }, "time": "2019-06-13T22:48:21+00:00" }, { "name": "vlucas/phpdotenv", - "version": "v3.6.1", + "version": "v3.6.7", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "8f7961f7b9deb3b432452c18093cf16f88205902" + "reference": "2065beda6cbe75e2603686907b2e45f6f3a5ad82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/8f7961f7b9deb3b432452c18093cf16f88205902", - "reference": "8f7961f7b9deb3b432452c18093cf16f88205902", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/2065beda6cbe75e2603686907b2e45f6f3a5ad82", + "reference": "2065beda6cbe75e2603686907b2e45f6f3a5ad82", "shasum": "" }, "require": { - "php": "^5.4 || ^7.0", - "phpoption/phpoption": "^1.5", - "symfony/polyfill-ctype": "^1.9" + "php": "^5.4 || ^7.0 || ^8.0", + "phpoption/phpoption": "^1.5.2", + "symfony/polyfill-ctype": "^1.17" }, "require-dev": { "ext-filter": "*", - "phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0" + "ext-pcre": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7.27 || ^6.5.6 || ^7.0" }, "suggest": { - "ext-filter": "Required to use the boolean validator." + "ext-filter": "Required to use the boolean validator.", + "ext-pcre": "Required to use most of the library." }, "type": "library", "extra": { @@ -1703,28 +1942,43 @@ "env", "environment" ], - "time": "2020-03-12T13:44:00+00:00" + "support": { + "issues": "https://github.com/vlucas/phpdotenv/issues", + "source": "https://github.com/vlucas/phpdotenv/tree/v3.6.7" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", + "type": "tidelift" + } + ], + "time": "2020-07-14T19:04:52+00:00" }, { "name": "webmozart/assert", - "version": "1.7.0", + "version": "1.9.1", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "aed98a490f9a8f78468232db345ab9cf606cf598" + "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/aed98a490f9a8f78468232db345ab9cf606cf598", - "reference": "aed98a490f9a8f78468232db345ab9cf606cf598", + "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", + "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0", + "php": "^5.3.3 || ^7.0 || ^8.0", "symfony/polyfill-ctype": "^1.8" }, "conflict": { - "vimeo/psalm": "<3.6.0" + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<3.9.1" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" @@ -1751,7 +2005,11 @@ "check", "validate" ], - "time": "2020-02-14T12:15:55+00:00" + "support": { + "issues": "https://github.com/webmozart/assert/issues", + "source": "https://github.com/webmozart/assert/tree/master" + }, + "time": "2020-07-08T17:02:28+00:00" } ], "aliases": [], @@ -1762,6 +2020,7 @@ "platform": { "ext-json": "*", "ext-mbstring": "*", + "ext-tokenizer": "*", "ext-xmlwriter": "*" }, "platform-dev": [], diff --git a/helpers/release/ModifiedFile.php b/helpers/release/ModifiedFile.php index 6885950e..1c91fb94 100644 --- a/helpers/release/ModifiedFile.php +++ b/helpers/release/ModifiedFile.php @@ -29,18 +29,34 @@ class ModifiedFile /** @var string */ protected $filename; + /** @var string */ + protected $oldFilename; + /** @var string */ protected $modificator; + /** @var int */ + protected $percent; + /** * ModifiedFile constructor. - * @param string $filename - * @param string $modificator + * @param string $source */ - public function __construct($filename, $modificator = self::Modified) + public function __construct($source) { - $this->filename = $filename; - $this->modificator = $modificator; + $params = explode("\t", trim($source)); + + $this->filename = $params[1]; + $this->modificator = $params[0][0]; + + if (strlen($params[0]) > 1) { + $this->percent = (int) substr($params[0], 1); + } + + if (count($params) >= 3) { + $this->filename = $params[2]; + $this->oldFilename = $params[1]; + } } /** @@ -90,4 +106,20 @@ class ModifiedFile { return $this->filename; } + + /** + * @return string + */ + public function getOldFilename() + { + return $this->oldFilename; + } + + /** + * @return int + */ + public function getPercent() + { + return $this->percent; + } } diff --git a/intaro.retailcrm/RetailcrmClasspathBuilder.php b/intaro.retailcrm/RetailcrmClasspathBuilder.php new file mode 100644 index 00000000..117611db --- /dev/null +++ b/intaro.retailcrm/RetailcrmClasspathBuilder.php @@ -0,0 +1,307 @@ +/bitrix/php_interface/retailcrm + * + * Array format: + * [ + * 'class path with namespace' => 'file name' + * ] + */ + protected static $customizableClasses = [ + 'RestNormalizer' => 'RestNormalizer.php', + 'Logger' => 'Logger.php', + 'RetailCrm\ApiClient' => 'ApiClient_v5.php', + 'RetailCrm\Http\Client' => 'Client.php', + 'RCrmActions' => 'RCrmActions.php', + 'RetailCrmUser' => 'RetailCrmUser.php', + 'RetailCrmICML' => 'RetailCrmICML.php', + 'RetailCrmInventories' => 'RetailCrmInventories.php', + 'RetailCrmPrices' => 'RetailCrmPrices.php', + 'RetailCrmCollector' => 'RetailCrmCollector.php', + 'RetailCrmUa' => 'RetailCrmUa.php', + 'RetailCrmEvent' => 'RetailCrmEvent.php', + 'RetailCrmCorporateClient' => 'RetailCrmCorporateClient.php' + ]; + + /** + * These classes can be customized, in which case they would be replaced with files from + * directory /bitrix/php_interface/retailcrm + * Customized versions have fixed name, and original versions name depends on API version + * + * Array format: + * [ + * 'class path with namespace' => ['customized file name', 'original file name with %s for API version'] + * ] + */ + protected static $versionedClasses = [ + 'RetailCrm\ApiClient' => ['ApiClient.php', 'ApiClient_%s.php'], + 'RetailCrmOrder' => ['RetailCrmOrder.php', 'RetailCrmOrder_%s.php'], + 'RetailCrmHistory' => ['RetailCrmHistory.php', 'RetailCrmHistory_%s.php'] + ]; + + /** + * These classes will be ignored while loading from original files + */ + protected static $ignoredClasses = [ + 'ApiClient_v4.php', + 'ApiClient_v5.php', + 'RetailCrmOrder_v4.php', + 'RetailCrmOrder_v5.php', + 'RetailCrmHistory_v4.php', + 'RetailCrmHistory_v5.php', + ]; + + /** + * These namespaces are hardcoded. + */ + protected static $hardcodedNamespaces = [ + 'RetailCrm\Response\ApiResponse' => 'ApiResponse.php', + 'RetailCrm\Exception\InvalidJsonException' => 'InvalidJsonException.php', + 'RetailCrm\Exception\CurlException' => 'CurlException.php' + ]; + + protected function buildCustomizableClasspath() + { + foreach (static::$customizableClasses as $className => $fileName) { + $customizedFile = $this->documentRoot . '/bitrix/php_interface/retailcrm/' . $fileName; + + if (file_exists($customizedFile)) { + $this->result[$className] = $customizedFile; + } else { + $this->notIncluded[$className] = $fileName; + } + } + } + + protected function buildVersionedClasspath() + { + foreach (static::$versionedClasses as $className => $fileNames) { + $customizedFile = $this->documentRoot . '/bitrix/php_interface/retailcrm/' . $fileNames[0]; + + if (file_exists($customizedFile)) { + $this->result[$className] = $customizedFile; + } else { + $this->notIncluded[$className] = sprintf($fileNames[1], $this->version); + } + } + } + + /** + * Traverse through directories, build include paths + * @return $this + */ + public function build(): self + { + $directory = new RecursiveDirectoryIterator( + $this->getSearchPath(), + RecursiveDirectoryIterator::SKIP_DOTS + ); + $fileIterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::LEAVES_ONLY); + + $this->buildCustomizableClasspath(); + $this->buildVersionedClasspath(); + $notIncludedClasses = array_flip($this->notIncluded); + $hardcodedNamespaces = array_flip(static::$hardcodedNamespaces); + + /** @var \SplFileObject $file */ + foreach ($fileIterator as $file) { + $fileNameWithoutExt = str_ireplace('.' . $this->fileExt, '', $file->getFilename()); + + if ($file->getExtension() !== $this->fileExt) { + continue; + } + + if (in_array($file->getFilename(), static::$customizableClasses) + || in_array($file->getFilename(), static::$ignoredClasses) + ) { + if (in_array($file->getFilename(), $this->notIncluded)) { + $this->result[$notIncludedClasses[$file->getFilename()]] = $this->getImportPath($file->getPathname()); + } + + continue; + } + + if (in_array($file->getFilename(), static::$hardcodedNamespaces)) { + $this->result[$hardcodedNamespaces[$file->getFilename()]] = $this->getImportPath($file->getPathname()); + } else { + $this->result[$this->getImportClass($fileNameWithoutExt, $file->getPath())] = $this->getImportPath($file->getPathname()); + } + } + + return $this; + } + + /** + * Sets the $fileExt property + * + * @param string $fileExt The file extension used for class files. Default is "php". + * + * @return \RetailcrmClasspathBuilder + */ + public function setFileExt($fileExt) + { + $this->fileExt = $fileExt; + return $this; + } + + /** + * @param string $documentRoot + * + * @return RetailcrmClasspathBuilder + */ + public function setDocumentRoot(string $documentRoot): RetailcrmClasspathBuilder + { + $this->documentRoot = $documentRoot; + return $this; + } + + /** + * Sets the $path property + * + * @param string $path Top path to load files + * + * @return \RetailcrmClasspathBuilder + */ + public function setPath(string $path) + { + $this->path = $path; + return $this; + } + + /** + * @param mixed $disableNamespaces + * + * @return RetailcrmClasspathBuilder + */ + public function setDisableNamespaces($disableNamespaces) + { + $this->disableNamespaces = $disableNamespaces; + return $this; + } + + /** + * @param string $moduleId + * + * @return RetailcrmClasspathBuilder + */ + public function setModuleId(string $moduleId): RetailcrmClasspathBuilder + { + $this->moduleId = $moduleId; + return $this; + } + + /** + * @param string $version + * + * @return RetailcrmClasspathBuilder + */ + public function setVersion(string $version): RetailcrmClasspathBuilder + { + $this->version = $version; + return $this; + } + + /** + * @return array + */ + public function getResult(): array + { + return $this->result; + } + + /** + * @return string + */ + protected function getSearchPath(): string + { + return __DIR__ . DIRECTORY_SEPARATOR . $this->path; + } + + /** + * @param string $filePath + * + * @return string + */ + protected function getImportPath(string $filePath): string + { + return (string) str_ireplace(implode(DIRECTORY_SEPARATOR, [ + $this->documentRoot, + 'bitrix', + 'modules', + $this->moduleId + ]) . DIRECTORY_SEPARATOR, '', $filePath); + } + + /** + * @param string $fileNameWithoutExt + * @param string $filePath + * + * @return string + */ + protected function getImportClass(string $fileNameWithoutExt, string $filePath): string + { + if ($this->disableNamespaces) { + return $fileNameWithoutExt; + } + + $importClass = str_ireplace($this->getSearchPath(), '', $filePath). '\\' . $fileNameWithoutExt; + + if (strlen($importClass) > 0 && $importClass[0] === '/') { + $importClass = '\\' . substr($importClass, 1); + } + + return (string) str_replace(DIRECTORY_SEPARATOR, '\\', $importClass); + } +} diff --git a/intaro.retailcrm/classes/general/ApiClient_v4.php b/intaro.retailcrm/classes/general/ApiClient_v4.php index 8fb2d8dc..27492edb 100644 --- a/intaro.retailcrm/classes/general/ApiClient_v4.php +++ b/intaro.retailcrm/classes/general/ApiClient_v4.php @@ -1814,7 +1814,18 @@ class ApiClient { $this->siteCode = $site; } - + + /** + * @return \RetailCrm\Response\ApiResponse + */ + public function getCredentials(): ApiResponse + { + return $this->client->makeRequest( + '/credentials', + Client::METHOD_GET + ); + } + /** * Check ID parameter * diff --git a/intaro.retailcrm/classes/general/ApiClient_v5.php b/intaro.retailcrm/classes/general/ApiClient_v5.php index ae58d925..0cf6afd6 100644 --- a/intaro.retailcrm/classes/general/ApiClient_v5.php +++ b/intaro.retailcrm/classes/general/ApiClient_v5.php @@ -29,6 +29,7 @@ class ApiClient const VERSION = 'v5'; protected $client; + protected $unversionedClient; /** * Site code @@ -50,10 +51,13 @@ class ApiClient $url .= '/'; } - $url = $url . 'api/' . self::VERSION; + $versionedUrl = $url . 'api/' . self::VERSION; + $unversionedUrl = $url . 'api'; - $this->client = new Client($url, array('apiKey' => $apiKey)); + $this->client = new Client($versionedUrl, array('apiKey' => $apiKey)); $this->siteCode = $site; + + $this->unversionedClient = new Client($unversionedUrl, ['apiKey' => $apiKey]); } /** @@ -240,11 +244,11 @@ class ApiClient return $this->client->makeRequest( '/customers-corporate/fix-external-ids', Client::METHOD_POST, - array('customerCorporate' => json_encode($ids)) + array('customersCorporate' => json_encode($ids)) ); } - /* + /** * Upload array of the customers corporate * * @param array $customers array of customers @@ -608,20 +612,15 @@ class ApiClient /** * Create corporate customer address * - * @param string $id corporate customer identifier - * @param array $address (default: array()) - * @param string $by (default: 'externalId') - * @param string $site (default: null) - * - * @throws \InvalidArgumentException - * @throws \RetailCrm\Exception\CurlException - * @throws \RetailCrm\Exception\InvalidJsonException + * @param string $id corporate customer identifier + * @param array $address (default: array()) + * @param string $by (default: 'externalId') + * @param null $site (default: null) * * @return \RetailCrm\Response\ApiResponse */ - public function customersCorporateAddressesCreate($id, array $address = [], $by = 'externalId', $site = null) + public function customersCorporateAddressesCreate($id, array $address = [], $by = 'externalId', $site = null): ApiResponse { - /* @noinspection PhpUndefinedMethodInspection */ return $this->client->makeRequest( "/customers-corporate/$id/addresses/create", Client::METHOD_POST, @@ -830,7 +829,7 @@ class ApiClient * * @return ApiResponse */ - public function ordersCreate(array $order, $site = null) + public function ordersCreate(array $order, $site = null): ApiResponse { if (!count($order)) { throw new InvalidArgumentException( @@ -841,7 +840,7 @@ class ApiClient return $this->client->makeRequest( '/orders/create', Client::METHOD_POST, - $this->fillSite($site, array('order' => json_encode($order))) + $this->fillSite($site, ['order' => json_encode($order)]) ); } @@ -966,7 +965,7 @@ class ApiClient * * @return ApiResponse */ - public function ordersEdit(array $order, $by = 'externalId', $site = null) + public function ordersEdit(array $order, $by = 'externalId', $site = null): ApiResponse { if (!count($order)) { throw new InvalidArgumentException( @@ -987,7 +986,7 @@ class ApiClient Client::METHOD_POST, $this->fillSite( $site, - array('order' => json_encode($order), 'by' => $by) + ['order' => json_encode($order), 'by' => $by] ) ); } @@ -2932,4 +2931,186 @@ class ApiClient return $params; } + + /** + * @param array $request + * @param int $checkId + * @return \RetailCrm\Response\ApiResponse + */ + public function checkStatusPlVerification(array $request, int $checkId): ApiResponse + { + return $this->client->makeRequest( + "/verification/sms/$checkId/status", + Client::METHOD_GET, + $request + ); + } + + /** + * @param array $request + * @return \RetailCrm\Response\ApiResponse + */ + public function loyaltyOrderApply(array $request): ApiResponse + { + return $this->client->makeRequest( + "/orders/loyalty/apply", + Client::METHOD_POST, + [ + 'site' => $request['site'], + 'order' => json_encode($request['order']), + 'bonuses' => $request['bonuses'], + ] + ); + } + + /** + * @param array $request + * @return \RetailCrm\Response\ApiResponse + */ + public function loyaltyOrderCalculate(array $request): ApiResponse + { + return $this->client->makeRequest( + "/loyalty/calculate", + Client::METHOD_POST, + [ + 'site' => json_encode($request['site']), + 'order' => json_encode($request['order']), + 'bonuses' => $request['bonuses'] + ] + ); + } + + /** + * @return \RetailCrm\Response\ApiResponse + */ + public function getCredentials(): ApiResponse + { + return $this->unversionedClient->makeRequest( + "/credentials", + Client::METHOD_GET + ); + } + + /** + * @param array $request + * @return \RetailCrm\Response\ApiResponse + */ + public function createLoyaltyAccount(array $request): ApiResponse + { + return $this->client->makeRequest( + "/loyalty/account/create", + Client::METHOD_POST, + [ + 'loyaltyAccount' => json_encode($request['loyaltyAccount']), + 'site' => $request['site'], + ] + ); + } + + /** + * @param int $loyaltyId + * @return \RetailCrm\Response\ApiResponse + */ + public function activateLoyaltyAccount(int $loyaltyId): ApiResponse + { + return $this->client->makeRequest( + "/loyalty/account/".$loyaltyId."/activate", + Client::METHOD_POST + ); + } + + /** + * @param array $request + * @return \RetailCrm\Response\ApiResponse + */ + public function sendVerificationCode(array $request): ApiResponse + { + return $this->client->makeRequest( + "/verification/sms/confirm", + Client::METHOD_POST, + [ + 'verification'=> json_encode($request['verification']) + ] + ); + } + + /** + * @param array $request + * @return \RetailCrm\Response\ApiResponse + */ + public function getLoyaltyAccounts(array $request): ApiResponse + { + return $this->client->makeRequest( + "/loyalty/accounts", + Client::METHOD_GET, + $request + ); + } + + /** + * @param int $loyaltyId + * @return \RetailCrm\Response\ApiResponse + */ + public function getLoyaltyLoyalty(int $loyaltyId): ApiResponse + { + return $this->client->makeRequest( + '/loyalty/loyalties/' . $loyaltyId, + Client::METHOD_GET + ); + } + + /** + * @return \RetailCrm\Response\ApiResponse + */ + public function getLoyaltyLoyalties(): ApiResponse + { + return $this->client->makeRequest( + '/loyalty/loyalties', + Client::METHOD_GET + ); + } + + /** + * @param array $request + * @param int $accountId + * + * @return \RetailCrm\Response\ApiResponse + */ + public function editLoyaltyAccount(array $request, int $accountId): ApiResponse + { + return $this->client->makeRequest( + '/loyalty/account/' . $accountId . '/edit', + Client::METHOD_POST, + [ + 'loyaltyAccount'=> json_encode($request['loyaltyAccount']), + 'id' => $request['id'] + ] + ); + } + + /** + * @param array $request + * @return \RetailCrm\Response\ApiResponse + */ + protected function confirmLpVerificationBySMS(array $request): ApiResponse + { + return $this->client->makeRequest( + '/verification/sms/confirm', + Client::METHOD_POST, + $request + ); + } + + /** + * @param array $request + * @return \RetailCrm\Response\ApiResponse + */ + public function sendSmsForLpVerification(array $request): ApiResponse + { + return $this->client->makeRequest( + '/verification/sms/send', + Client::METHOD_POST, + $request + ); + } } diff --git a/intaro.retailcrm/classes/general/Logger.php b/intaro.retailcrm/classes/general/Logger.php index 6db51421..f8febc7b 100644 --- a/intaro.retailcrm/classes/general/Logger.php +++ b/intaro.retailcrm/classes/general/Logger.php @@ -25,8 +25,8 @@ class Logger public static function getInstance($logPath = '/bitrix/modules/intaro.retailcrm/log', $files = 3) { if (empty(self::$instance) - || self::$instance instanceof Logger - && (self::$instance->logPath != $logPath || self::$instance->files != $files) + || (self::$instance instanceof self + && (self::$instance->logPath !== $logPath || self::$instance->files !== $files)) ) { self::$instance = new Logger($logPath, $files); } @@ -40,12 +40,12 @@ class Logger * @param string $logPath * @param int $files */ - private function __construct($logPath = '/bitrix/modules/intaro.retailcrm/log', $files = 3) + public function __construct($logPath = '/bitrix/modules/intaro.retailcrm/log', $files = 3) { $this->logPath = $logPath; $this->files = $files; } - + public function write($dump, $file = 'info') { $rsSites = CSite::GetList($by, $sort, array('DEF' => 'Y')); @@ -53,19 +53,19 @@ class Logger 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'; + $file = $ar['ABS_DOC_ROOT'] . $this->logPath . '/' . $file . '.log'; $data['TIME'] = date('Y-m-d H:i:s'); $data['DATA'] = $dump; $f = fopen($file, "a+"); fwrite($f, print_r($data, true)); - fclose($f); + fclose($f); // if filesize more than 5 Mb rotate it if (filesize($file) > 5242880) { $this->rotate($file); - } + } } private function rotate($file) @@ -105,5 +105,4 @@ class Logger { file_put_contents($file, ''); } - } diff --git a/intaro.retailcrm/classes/general/RCrmActions.php b/intaro.retailcrm/classes/general/RCrmActions.php index 2c5f3230..183f4753 100644 --- a/intaro.retailcrm/classes/general/RCrmActions.php +++ b/intaro.retailcrm/classes/general/RCrmActions.php @@ -1,5 +1,6 @@ 'Y']); - + while ($ar = $rsSites->Fetch()) { $arSites[] = $ar; } @@ -183,13 +188,13 @@ class RCrmActions public static function eventLog($auditType, $itemId, $description) { - CEventLog::Add(array( + CEventLog::Add([ 'SEVERITY' => 'SECURITY', 'AUDIT_TYPE_ID' => $auditType, 'MODULE_ID' => self::$MODULE_ID, 'ITEM_ID' => $itemId, 'DESCRIPTION' => $description, - )); + ]); } /** @@ -202,7 +207,7 @@ class RCrmActions { 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); } @@ -237,23 +242,14 @@ class RCrmActions * working with nested arrs * * @param array $arr + * * @return array */ - public static function clearArr($arr) + public static function clearArr(array $arr): array { - 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; + /** @var \Intaro\RetailCrm\Service\Utils $utils */ + $utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class); + return $utils->clearArray($arr); } /** @@ -261,13 +257,12 @@ class RCrmActions * @param array|bool|\SplFixedArray|string $str in SITE_CHARSET * * @return array|bool|\SplFixedArray|string $str in utf-8 - * @global $APPLICATION */ public static function toJSON($str) { - global $APPLICATION; - - return $APPLICATION->ConvertCharset($str, SITE_CHARSET, 'utf-8'); + /** @var \Intaro\RetailCrm\Service\Utils $utils */ + $utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class); + return $utils->toUTF8($str); } /** @@ -275,13 +270,12 @@ class RCrmActions * @param string|array|\SplFixedArray $str in utf-8 * * @return array|bool|\SplFixedArray|string $str in SITE_CHARSET - * @global $APPLICATION */ public static function fromJSON($str) { - global $APPLICATION; - - return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); + /** @var \Intaro\RetailCrm\Service\Utils $utils */ + $utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class); + return $utils->fromUTF8($str); } /** diff --git a/intaro.retailcrm/classes/general/Response/ApiResponse.php b/intaro.retailcrm/classes/general/Response/ApiResponse.php index 28855326..24a262bd 100644 --- a/intaro.retailcrm/classes/general/Response/ApiResponse.php +++ b/intaro.retailcrm/classes/general/Response/ApiResponse.php @@ -172,4 +172,12 @@ class ApiResponse implements \ArrayAccess return $this->response[$offset]; } + + /** + * @return array + */ + public function getResponseBody() + { + return $this->response; + } } diff --git a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php index 34823b70..971ffbc3 100644 --- a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php +++ b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php @@ -9,8 +9,12 @@ * @package RetailCRM */ +use Intaro\RetailCrm\Component\ConfigProvider; + IncludeModuleLangFile(__FILE__); +require_once __DIR__ . '/../../lib/component/configprovider.php'; + /** * PHP version 5.3 * @@ -19,840 +23,6 @@ IncludeModuleLangFile(__FILE__); * @category RetailCRM * @package RetailCRM */ -class RetailcrmConfigProvider +class RetailcrmConfigProvider extends ConfigProvider { - /** @var bool|null|string */ - private static $apiUrl; - - /** @var bool|null|string */ - private static $apiKey; - - /** @var bool|null|string */ - private static $catalogBasePrice; - - /** @var bool|null|string */ - private static $currency; - - /** @var bool|null|string */ - private static $orderDimensions; - - /** @var bool|null|string */ - private static $corporateClientName; - - /** @var bool|null|string */ - private static $corporateClientAddress; - - /** @var bool|null|string */ - private static $corporateClient; - - /** @var bool|null|string $shipmentDeducted */ - private static $shipmentDeducted; - - /** @var array $sitesList */ - private static $sitesList; - - /** @var array $sitesListCorporate */ - private static $sitesListCorporate; - - /** @var bool|null|string $orderNumbers */ - private static $orderNumbers; - - /** @var array $orderTypes */ - private static $orderTypes; - - /** @var array $deliveryTypes */ - private static $deliveryTypes; - - /** @var array $paymentTypes */ - private static $paymentTypes; - - /** @var array $integrationPayment */ - private static $integrationPayment; - - /** @var array $paymentStatuses */ - private static $paymentStatuses; - - /** @var array $payment */ - private static $payment; - - /** @var array $orderProps */ - private static $orderProps; - - /** @var array $legalDetails */ - private static $legalDetails; - - /** @var array $contragentTypes */ - private static $contragentTypes; - - /** @var array $cancellableOrderPaymentStatuses */ - private static $cancellableOrderPaymentStatuses; - - /** @var array $customFields */ - private static $customFields; - - /** @var array $infoblocksInventories */ - private static $infoblocksInventories; - - /** @var array $stores */ - private static $stores; - - /** @var array $shops */ - private static $shops; - - /** - * @return bool|string|null - */ - public static function getApiUrl() - { - if (self::isEmptyNotZero(static::$apiUrl)) { - static::$apiUrl = static::getOption(RetailcrmConstants::CRM_API_HOST_OPTION); - } - - return static::$apiUrl; - } - - /** - * @return bool|string|null - */ - public static function getApiKey() - { - if (self::isEmptyNotZero(static::$apiKey)) { - static::$apiKey = static::getOption(RetailcrmConstants::CRM_API_KEY_OPTION); - } - - return static::$apiKey; - } - - /** - * getCorporateClientName - * - * @return bool|string|null - */ - public static function getCorporateClientName() - { - if (self::isEmptyNotZero(static::$corporateClientName)) { - static::$corporateClientName = static::getUnserializedOption(RetailcrmConstants::CRM_CORP_NAME); - } - - return static::$corporateClientName; - } - - /** - * getCorporateClientAddress - * - * @return bool|string|null - */ - public static function getCorporateClientAddress() - { - if (self::isEmptyNotZero(static::$corporateClientAddress)) { - static::$corporateClientAddress = static::getUnserializedOption(RetailcrmConstants::CRM_CORP_ADDRESS); - } - - return static::$corporateClientAddress; - } - - /** - * getCorporateClient - * - * @return bool|string|null - */ - public static function getCorporateClientStatus() - { - if (self::isEmptyNotZero(static::$corporateClient)) { - static::$corporateClient = static::getOption(RetailcrmConstants::CRM_CC); - } - - return static::$corporateClient; - } - - /** - * getSitesList - * - * @return array - */ - public static function getSitesList() - { - if (self::isEmptyNotZero(static::$sitesList)) { - static::$sitesList = static::getUnserializedOption(RetailcrmConstants::CRM_SITES_LIST); - } - - return static::$sitesList; - } - - /** - * getSitesListCorporate - * - * @return array - */ - public static function getSitesListCorporate() - { - if (self::isEmptyNotZero(static::$sitesListCorporate)) { - static::$sitesListCorporate = static::getUnserializedOption( - RetailcrmConstants::CRM_SITES_LIST_CORPORATE - ); - } - - return static::$sitesListCorporate; - } - - /** - * isOnlineConsultantEnabled - * - * @return bool - */ - public static function isOnlineConsultantEnabled() - { - return static::getOption(RetailcrmConstants::CRM_ONLINE_CONSULTANT) === 'Y'; - } - - /** - * getOnlineConsultantScript - * - * @return string - */ - public static function getOnlineConsultantScript() - { - return trim(static::getOption(RetailcrmConstants::CRM_ONLINE_CONSULTANT_SCRIPT, "")); - } - - /** - * setOnlineConsultant - * - * @param string $value - */ - public static function setOnlineConsultant($value) - { - static::setOption(RetailcrmConstants::CRM_ONLINE_CONSULTANT, $value); - } - - /** - * @return bool|string|null - */ - public static function getCrmPurchasePrice() - { - return static::getOption(RetailcrmConstants::CRM_PURCHASE_PRICE_NULL); - } - - public static function getProtocol() - { - return static::getOption(RetailcrmConstants::PROTOCOL); - } - - /** - * @return string - */ - public static function getSiteName(): string - { - $siteName = COption::GetOptionString('main', 'site_name'); - - if (!$siteName) { - return ''; - } - - return $siteName; - } - - /** - * @return mixed - */ - public static function getUsersMap() - { - return static::getUnserializedOption(RetailcrmConstants::CRM_USERS_MAP); - } - - /** - * @param array|null $userMap - * - * @return bool - */ - public static function setUsersMap(?array $userMap): bool - { - return static::setOption(RetailcrmConstants::CRM_USERS_MAP, serialize($userMap)); - } - - /** - * @param $profileId - * - * @return false|string|null - */ - public static function getCrmBasePrice($profileId) - { - return self::getOption(RetailcrmConstants::CRM_CATALOG_BASE_PRICE . '_' . $profileId, 1); - } - - public static function setProfileBasePrice($profileId, $priceTypes): void - { - self::setOption( - RetailcrmConstants::CRM_CATALOG_BASE_PRICE . '_' . $profileId, - htmlspecialchars(trim($priceTypes)) - ); - } - - /** - * @return string - */ - public static function getDefaultIcmlPath(): string - { - return (COption::GetOptionString( - 'catalog', - 'export_default_path', - '/bitrix/catalog_export/')) - . 'retailcrm.xml'; - } - - /** - * setOnlineConsultantScript - * - * @param string $value - */ - public function setOnlineConsultantScript($value) - { - static::setOption(RetailcrmConstants::CRM_ONLINE_CONSULTANT_SCRIPT, $value); - } - - - /** - * getOrderTypes - * - * @return array - */ - public static function getOrderTypes() - { - if (self::isEmptyNotZero(static::$orderTypes)) { - static::$orderTypes = static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_TYPES_ARR); - } - - return static::$orderTypes; - } - - /** - * setOrderTypes - * - * @param array $orderTypesArr - */ - public static function setOrderTypes($orderTypesArr) - { - static::setOption(RetailcrmConstants::CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr))); - } - - /** - * getDeliveryTypes - * - * @return array - */ - public static function getDeliveryTypes() - { - if (self::isEmptyNotZero(static::$deliveryTypes)) { - static::$deliveryTypes = static::getUnserializedOption(RetailcrmConstants::CRM_DELIVERY_TYPES_ARR); - } - - return static::$deliveryTypes; - } - - /** - * setDeliveryTypes - * - * @param array $deliveryTypesArr - */ - public static function setDeliveryTypes($deliveryTypesArr) - { - static::setOption(RetailcrmConstants::CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr))); - } - - /** - * getPaymentTypes - * - * @return array - */ - public static function getPaymentTypes() - { - if (self::isEmptyNotZero(static::$paymentTypes)) { - static::$paymentTypes = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_TYPES); - } - - return static::$paymentTypes; - } - - /** - * getIntegrationPaymentTypes - * - * @return array - */ - public static function getIntegrationPaymentTypes(): array - { - if (self::isEmptyNotZero(static::$integrationPayment)) { - $option = static::getUnserializedOption(RetailcrmConstants::CRM_INTEGRATION_PAYMENT); - static::$integrationPayment = is_array($option) ? $option : []; - } - - return static::$integrationPayment; - } - - /** - * setIntegrationPaymentTypes - * @param $integrationPayment - */ - public static function setIntegrationPaymentTypes($integrationPayment) - { - static::setOption(RetailcrmConstants::CRM_INTEGRATION_PAYMENT, serialize(RCrmActions::clearArr($integrationPayment))); - } - - /** - * setIntegrationDelivery - * @param $deliveryIntegrationCode - */ - public static function setIntegrationDelivery($deliveryIntegrationCode) - { - static::setOption(RetailcrmConstants::CRM_INTEGRATION_DELIVERY, serialize(RCrmActions::clearArr($deliveryIntegrationCode))); - } - - /** - * setPaymentTypes - * - * @param array $paymentTypesArr - */ - public static function setPaymentTypes($paymentTypesArr) - { - static::setOption(RetailcrmConstants::CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr))); - } - - /** - * getPaymentStatuses - * - * @return array - */ - public static function getPaymentStatuses() - { - if (self::isEmptyNotZero(static::$paymentStatuses)) { - static::$paymentStatuses = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT_STATUSES); - } - - return static::$paymentStatuses; - } - - /** - * getPaymentStatuses - * - * @param array $paymentStatusesArr - */ - public static function setPaymentStatuses($paymentStatusesArr) - { - static::setOption(RetailcrmConstants::CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr($paymentStatusesArr))); - } - - /** - * getPayment - * - * @return array - */ - public static function getPayment() - { - if (self::isEmptyNotZero(static::$payment)) { - static::$payment = static::getUnserializedOption(RetailcrmConstants::CRM_PAYMENT); - } - - return static::$payment; - } - - /** - * getOrderProps - * - * @return array - */ - public static function getOrderProps() - { - if (self::isEmptyNotZero(static::$orderProps)) { - static::$orderProps = static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_PROPS); - } - - return static::$orderProps; - } - - /** - * getLegalDetails - * - * @return array - */ - public static function getLegalDetails() - { - if (self::isEmptyNotZero(static::$legalDetails)) { - static::$legalDetails = static::getUnserializedOption(RetailcrmConstants::CRM_LEGAL_DETAILS); - } - - return static::$legalDetails; - } - - /** - * getContragentTypes - * - * @return array - */ - public static function getContragentTypes() - { - if (self::isEmptyNotZero(static::$contragentTypes)) { - static::$contragentTypes = static::getUnserializedOption(RetailcrmConstants::CRM_CONTRAGENT_TYPE); - } - - return static::$contragentTypes; - } - - /** - * setContragentTypes - * - * @param array $contragentTypeArr - */ - public static function setContragentTypes($contragentTypeArr) - { - static::setOption(RetailcrmConstants::CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr))); - } - - /** - * getCustomFields - * - * @return array - */ - public static function getCustomFields() - { - if (self::isEmptyNotZero(static::$customFields)) { - static::$customFields = static::getUnserializedOption(RetailcrmConstants::CRM_CUSTOM_FIELDS); - } - - return static::$customFields; - } - - /** - * getCancellableOrderPaymentStatuses - * - * @return array - */ - public static function getCancellableOrderPaymentStatuses() - { - if (self::isEmptyNotZero(static::$cancellableOrderPaymentStatuses)) { - static::$cancellableOrderPaymentStatuses = static::getUnserializedOption( - RetailcrmConstants::CRM_CANCEL_ORDER - ); - } - - return static::$cancellableOrderPaymentStatuses; - } - - /** - * getLastOrderId - * - * @return bool|string|null - */ - public static function getLastOrderId() - { - return static::getOption(RetailcrmConstants::CRM_ORDER_LAST_ID); - } - - /** - * getSendPaymentAmount - * - * @return bool|string|null - */ - public static function getSendPaymentAmount() - { - return static::getOption(RetailcrmConstants::SEND_PAYMENT_AMOUNT); - } - - /** - * setSendPaymentAmount - * - * @param string $value - */ - public static function setSendPaymentAmount($value) - { - static::setOption(RetailcrmConstants::SEND_PAYMENT_AMOUNT, $value); - } - - /** - * Returns true if payment amount should be sent from CMS to RetailCRM. - * - * @return bool|string|null - */ - public static function shouldSendPaymentAmount() - { - return static::getSendPaymentAmount() === 'Y'; - } - - /** - * setLastOrderId - * - * @param $id - */ - public static function setLastOrderId($id) - { - static::setOption(RetailcrmConstants::CRM_ORDER_LAST_ID, $id); - } - - /** - * getFailedOrdersIds - * - * @return array - */ - public static function getFailedOrdersIds() - { - return static::getUnserializedOption(RetailcrmConstants::CRM_ORDER_FAILED_IDS); - } - - /** - * setFailedOrdersIds - * - * @param $ids - */ - public static function setFailedOrdersIds($ids) - { - static::setOption(RetailcrmConstants::CRM_ORDER_FAILED_IDS, serialize($ids)); - } - - /** - * getOrderNumbers - * - * @return bool|string|null - */ - public static function getOrderNumbers() - { - if (self::isEmptyNotZero(self::$orderNumbers)) { - self::$orderNumbers = static::getOption(RetailcrmConstants::CRM_ORDER_NUMBERS); - } - - return self::$orderNumbers; - } - - /** - * getOrderHistoryDate - * - * @return bool|string|null - */ - public static function getOrderHistoryDate() - { - return static::getOption(RetailcrmConstants::CRM_ORDER_HISTORY_DATE); - } - - /** - * Returns customers history since ID - * - * @return int - */ - public static function getCustomersHistorySinceId() - { - return (int) static::getOption(RetailcrmConstants::CRM_CUSTOMERS_HISTORY_SINCE_ID); - } - - /** - * Sets new customers history since ID - * - * @param int $sinceId - */ - public static function setCustomersHistorySinceId($sinceId) - { - static::setOption(RetailcrmConstants::CRM_CUSTOMERS_HISTORY_SINCE_ID, $sinceId); - } - - /** - * getCatalogBasePrice - * - * @return bool|string|null - */ - public static function getCatalogBasePrice() - { - if (self::isEmptyNotZero(static::$catalogBasePrice)) { - static::$catalogBasePrice = static::getOption(RetailcrmConstants::CRM_CATALOG_BASE_PRICE); - } - - return static::$catalogBasePrice; - } - - /** - * @param $profileId - * - * @return false|string|null - */ - public static function getCatalogBasePriceByProfile($profileId) - { - return COption::GetOptionString( - RetailcrmConstants::MODULE_ID, - RetailcrmConstants::CRM_CATALOG_BASE_PRICE . '_' . $profileId, - 0 - ); - } - - - /** - * getOrderDimensions - * - * @return bool|string|null - */ - public static function getOrderDimensions() - { - if (self::isEmptyNotZero(static::$orderDimensions)) { - static::$orderDimensions = static::getOption(RetailcrmConstants::CRM_ORDER_DIMENSIONS, 'N'); - } - - return static::$orderDimensions; - } - - /** - * getCurrency - * - * @return bool|string|null - */ - public static function getCurrency() - { - if (self::isEmptyNotZero(static::$currency)) { - static::$currency = static::getOption(RetailcrmConstants::CRM_CURRENCY); - } - - return static::$currency; - } - - /** - * Returns currency from settings. If it's not set - returns Bitrix base currency. - * - * @return bool|string|null - */ - public static function getCurrencyOrDefault() - { - return self::getCurrency() ? self::getCurrency() : \Bitrix\Currency\CurrencyManager::getBaseCurrency(); - } - - /** - * getInfoblocksInventories - * - * @return array - */ - public static function getInfoblocksInventories() - { - if (self::isEmptyNotZero(static::$infoblocksInventories)) { - static::$infoblocksInventories = static::getUnserializedOption( - RetailcrmConstants::CRM_IBLOCKS_INVENTORIES - ); - } - - return static::$infoblocksInventories; - } - - /** - * getStores - * - * @return array - */ - public static function getStores() - { - if (self::isEmptyNotZero(static::$stores)) { - static::$stores = static::getUnserializedOption(RetailcrmConstants::CRM_STORES); - } - - return static::$stores; - } - - /** - * getShops - * - * @return array - */ - public static function getShops() - { - if (self::isEmptyNotZero(static::$shops)) { - static::$shops = static::getUnserializedOption(RetailcrmConstants::CRM_SHOPS); - } - - return static::$shops; - } - - /** - * getShipmentDeducted - * - * @return bool|string|null - */ - public static function getShipmentDeducted() - { - if (self::isEmptyNotZero(static::$shipmentDeducted)) { - static::$shipmentDeducted = static::getOption(RetailcrmConstants::CRM_SHIPMENT_DEDUCTED); - } - - return static::$shipmentDeducted; - } - - /** - * isPhoneRequired - * - * @return bool|string|null - */ - public static function isPhoneRequired() - { - return COption::GetOptionString("main", "new_user_phone_required") === 'Y'; - } - - /** - * Return integration_delivery option - * - * @return mixed - */ - public static function getCrmIntegrationDelivery() - { - return static::getUnserializedOption(RetailcrmConstants::CRM_INTEGRATION_DELIVERY); - } - - /** - * Wraps Bitrix COption::GetOptionString(...) - * - * @param string $option - * @param int|string $def - * - * @return bool|string|null - */ - private static function getOption($option, $def = 0) - { - return COption::GetOptionString( - RetailcrmConstants::MODULE_ID, - $option, - $def - ); - } - - /** - * setOption - * - * @param $name - * @param string $value - * @param bool $desc - * @param string $site - */ - private static function setOption($name, string $value = '', bool $desc = false, string $site = ''): bool - { - return COption::SetOptionString( - RetailcrmConstants::MODULE_ID, - $name, - $value, - $desc, - $site - ); - } - - /** - * Wraps Bitrix unserialize(COption::GetOptionString(...)) - * - * @param string $option - * @param int|string $def - * - * @return mixed - */ - private static function getUnserializedOption($option, $def = 0) - { - return unserialize(static::getOption($option, $def)); - } - - /** - * Returns true if value is empty and not zero (0 - digit) - * - * @param mixed $value - * - * @return bool - */ - private static function isEmptyNotZero($value) - { - return empty($value) && $value !== 0; - } } diff --git a/intaro.retailcrm/classes/general/RetailcrmConstants.php b/intaro.retailcrm/classes/general/RetailcrmConstants.php index 576888c7..0a354c43 100644 --- a/intaro.retailcrm/classes/general/RetailcrmConstants.php +++ b/intaro.retailcrm/classes/general/RetailcrmConstants.php @@ -9,8 +9,12 @@ * @package RetailCRM */ +use Intaro\RetailCrm\Component\Constants; + IncludeModuleLangFile(__FILE__); +require_once __DIR__ . '/../../lib/component/constants.php'; + /** * PHP version 5.3 * @@ -19,63 +23,6 @@ IncludeModuleLangFile(__FILE__); * @category RetailCRM * @package RetailCRM */ -class RetailcrmConstants +class RetailcrmConstants extends Constants { - public const MODULE_ID = 'intaro.retailcrm'; - public const CRM_API_HOST_OPTION = 'api_host'; - public const CRM_API_KEY_OPTION = 'api_key'; - public const CRM_ORDER_TYPES_ARR = 'order_types_arr'; - public const CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr'; - public const CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr'; - public const CRM_PAYMENT_TYPES = 'pay_types_arr'; - public const CRM_INTEGRATION_PAYMENT = 'integration_payment'; - public const CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; - public const CRM_PAYMENT = 'payment_arr'; //order payment Y/N - public const CRM_ORDER_LAST_ID = 'order_last_id'; - public const CRM_ORDER_SITES = 'sites_ids'; - public const CRM_ORDER_DISCHARGE = 'order_discharge'; - public const CRM_SITES_LIST = 'sites_list'; - public const CRM_ORDER_PROPS = 'order_props'; - public const CRM_LEGAL_DETAILS = 'legal_details'; - public const CRM_CUSTOM_FIELDS = 'custom_fields'; - public const CRM_CONTRAGENT_TYPE = 'contragent_type'; - public const CRM_SITES_LIST_CORPORATE = 'shops-corporate'; - public const CRM_ORDER_NUMBERS = 'order_numbers'; - public const CRM_CANCEL_ORDER = 'cansel_order'; - public const CRM_INVENTORIES_UPLOAD = 'inventories_upload'; - public const CRM_STORES = 'stores'; - public const CRM_SHOPS = 'shops'; - public const CRM_IBLOCKS_INVENTORIES = 'iblocks_inventories'; - public const CRM_PRICES_UPLOAD = 'prices_upload'; - public const CRM_PRICES = 'prices'; - public const CRM_PRICE_SHOPS = 'price_shops'; - public const CRM_IBLOCKS_PRICES = 'iblock_prices'; - public const CRM_COLLECTOR = 'collector'; - public const CRM_COLL_KEY = 'coll_key'; - public const CRM_UA = 'ua'; - public const CRM_UA_KEYS = 'ua_keys'; - public const CRM_DISCOUNT_ROUND = 'discount_round'; - public const CRM_CC = 'cc'; - public const CRM_CORP_SHOPS = 'shops-corporate'; - public const CRM_CORP_NAME = 'nickName-corporate'; - public const CRM_CORP_ADDRESS = 'adres-corporate'; - public const CRM_API_VERSION = 'api_version'; - public const CRM_CURRENCY = 'currency'; - public const CRM_ADDRESS_OPTIONS = 'address_options'; - public const CRM_DIMENSIONS = 'order_dimensions'; - public const PROTOCOL = 'protocol'; - public const CRM_ORDER_FAILED_IDS = 'order_failed_ids'; - public const CRM_CUSTOMERS_HISTORY_SINCE_ID = 'customer_history'; - public const CRM_ORDER_HISTORY_DATE = 'order_history_date'; - public const CRM_CATALOG_BASE_PRICE = 'catalog_base_price'; - public const CRM_ORDER_DIMENSIONS = 'order_dimensions'; - public const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED'; - public const CRM_INTEGRATION_DELIVERY = 'integration_delivery'; - public const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted'; - public const SEND_PAYMENT_AMOUNT = 'send_payment_amount'; - public const CRM_ONLINE_CONSULTANT = 'online_consultant'; - public const CRM_ONLINE_CONSULTANT_SCRIPT = 'online_consultant_script'; - public const CRM_PURCHASE_PRICE_NULL = 'purchasePrice_null'; - public const CRM_USERS_MAP = 'crm_users_map'; - public const BITRIX_USER_ID_PREFIX = 'bitrixUserId-'; } diff --git a/intaro.retailcrm/classes/general/RetailcrmDependencyLoader.php b/intaro.retailcrm/classes/general/RetailcrmDependencyLoader.php index 5f85c977..b184dad1 100644 --- a/intaro.retailcrm/classes/general/RetailcrmDependencyLoader.php +++ b/intaro.retailcrm/classes/general/RetailcrmDependencyLoader.php @@ -11,6 +11,8 @@ IncludeModuleLangFile(__FILE__); +require_once __DIR__ . '/../../lib/component/dependencyloader.php'; + /** * PHP version 5.3 * @@ -19,80 +21,6 @@ IncludeModuleLangFile(__FILE__); * @category RetailCRM * @package RetailCRM */ -class RetailcrmDependencyLoader +class RetailcrmDependencyLoader extends \Intaro\RetailCrm\Component\DependencyLoader { - /** @var int */ - const LEGACY_LOADER = 0; - - /** @var int */ - const D7_LOADER = 1; - - /** @var int $loader */ - private static $loader = self::D7_LOADER; - - /** - * Loads dependencies - * - * @return bool - */ - public static function loadDependencies() - { - foreach (self::getDependencies() as $dependency) { - if (self::LEGACY_LOADER == self::$loader) { - if (!CModule::IncludeModule($dependency)) { - RCrmActions::eventLog( - __CLASS__ . '::' . __METHOD__, - $dependency, - 'module not found' - ); - - return false; - } - } else { - try { - if (!\Bitrix\Main\Loader::includeModule($dependency)) { - RCrmActions::eventLog( - __CLASS__ . '::' . __METHOD__, - $dependency, - 'module not found' - ); - - return false; - } - } catch (\Bitrix\Main\LoaderException $exception) { - RCrmActions::eventLog( - __CLASS__ . '::' . __METHOD__, - $dependency, - sprintf('error while trying to load module: %s', $exception->getMessage()) - ); - - return false; - } - } - } - - return true; - } - - /** - * Set loader mode. Use RetailcrmDependencyLoader::LEGACY_LOADER or RetailcrmDependencyLoader::D7_LOADER - * - * @param $loader - */ - public static function setLoader($loader) - { - if (in_array($loader, array(self::LEGACY_LOADER, self::D7_LOADER))) { - self::$loader = $loader; - } - } - - /** - * Returns array of required modules names - * - * @return array - */ - public static function getDependencies() - { - return array("iblock", "sale", "catalog"); - } } diff --git a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php index c91df52b..563d2adf 100644 --- a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php +++ b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php @@ -3,22 +3,36 @@ use Bitrix\Main\Context\Culture; use Intaro\RetailCrm\Service\ManagerService; use Bitrix\Sale\Payment; -use RetailCrm\ApiClient; +use Bitrix\Catalog\Model\Event; +use Bitrix\Main\UserTable; +use Bitrix\Sale\Order; +use Intaro\RetailCrm\Component\ConfigProvider; +use Intaro\RetailCrm\Model\Api\Response\OrdersCreateResponse; +use Intaro\RetailCrm\Model\Api\Response\OrdersEditResponse; /** * Class RetailCrmEvent */ class RetailCrmEvent { - protected static $MODULE_ID = 'intaro.retailcrm'; - protected static $CRM_API_HOST_OPTION = 'api_host'; + 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_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_CUSTOM_FIELDS = 'custom_fields'; - protected static $CRM_CONTRAGENT_TYPE = 'contragent_type'; - protected static $CRM_SITES_LIST = 'sites_list'; + 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'; + 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'; + protected static $CRM_CC = 'cc'; + protected static $CRM_CORP_NAME = 'nickName-corporate'; + protected static $CRM_CORP_ADRES = 'adres-corporate'; /** * @param $arFields @@ -31,22 +45,22 @@ class RetailCrmEvent if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) { return false; } - + if (!$arFields['RESULT']) { return false; } - + $optionsSitesList = RetailcrmConfigProvider::getSitesList(); $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); $resultOrder = RetailCrmUser::customerEdit($arFields, $api, $optionsSitesList); - + if (!$resultOrder) { RCrmActions::eventLog('RetailCrmEvent::OnAfterUserUpdate', 'RetailCrmUser::customerEdit', 'error update customer'); } - + return true; } - + /** * onUpdateOrder * @@ -59,19 +73,19 @@ class RetailCrmEvent $GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = false; return; } - + $GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] = true; - + if (($arFields['CANCELED'] === 'Y') && (sizeof($arFields['BASKET_ITEMS']) == 0) && (sizeof($arFields['ORDER_PROP']) == 0) ) { $GLOBALS['ORDER_DELETE_USER_ADMIN'] = true; } - + return; } - + /** * orderDelete * @@ -80,67 +94,28 @@ class RetailCrmEvent public function orderDelete($event) { $GLOBALS['RETAILCRM_ORDER_DELETE'] = true; - + return; } - + /** * @param $event * - * @return bool + * @return array|bool|OrdersCreateResponse|OrdersEditResponse|null + * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ObjectPropertyException * @throws \Bitrix\Main\SystemException - * @throws \Bitrix\Main\ArgumentException + * @throws \Exception */ - public function orderSave($event) + public static function orderSave($event) { - if (true == $GLOBALS['ORDER_DELETE_USER_ADMIN']) { - return false; - } - - if ($GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] === false - && $GLOBALS['RETAILCRM_ORDER_DELETE'] === true - ) { - return false; - } - - if ($GLOBALS['RETAIL_CRM_HISTORY'] === true) { - return false; - } - - if (!CModule::IncludeModule('iblock')) { - RCrmActions::eventLog('RetailCrmEvent::orderSave', 'iblock', 'module not found'); - - return false; - } - - if (!CModule::IncludeModule('sale')) { - RCrmActions::eventLog('RetailCrmEvent::orderSave', 'sale', 'module not found'); - - return false; - } - - if (!CModule::IncludeModule('catalog')) { - RCrmActions::eventLog('RetailCrmEvent::orderSave', 'catalog', 'module not found'); - - return false; - } - - //exists 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; + if (!static::checkConfig()) { + return null; } - $arOrder = RetailCrmOrder::orderObjToArr($obOrder); - + $arOrder = static::getOrderArray($event); $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); - + //params $optionsOrderTypes = RetailcrmConfigProvider::getOrderTypes(); $optionsDelivTypes = RetailcrmConfigProvider::getDeliveryTypes(); @@ -152,10 +127,9 @@ class RetailCrmEvent $optionsLegalDetails = RetailcrmConfigProvider::getLegalDetails(); $optionsContragentType = RetailcrmConfigProvider::getContragentTypes(); $optionsCustomFields = RetailcrmConfigProvider::getCustomFields(); - + //corp cliente swich $optionCorpClient = RetailcrmConfigProvider::getCorporateClientStatus(); - $arParams = RCrmActions::clearArr([ 'optionsOrderTypes' => $optionsOrderTypes, 'optionsDelivTypes' => $optionsDelivTypes, @@ -168,32 +142,35 @@ class RetailCrmEvent '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 false; + return null; } } elseif (!$optionsSitesList) { $site = null; } - + //new order? $orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arOrder['ID'], $site); + if (isset($orderCrm['order'])) { $methodApi = 'ordersEdit'; $arParams['crmOrder'] = $orderCrm['order']; } else { $methodApi = 'ordersCreate'; } - + $orderCompany = null; - if ('Y' === $optionCorpClient) { - if (true === RetailCrmCorporateClient::isCorpTookExternalId((string) $arOrder['USER_ID'], $api)) { - RetailCrmCorporateClient::setPrefixForExternalId((string) $arOrder['USER_ID'], $api); - } + + if ( + ('Y' === $optionCorpClient) + && true === RetailCrmCorporateClient::isCorpTookExternalId((string)$arOrder['USER_ID'], $api) + ) { + RetailCrmCorporateClient::setPrefixForExternalId((string) $arOrder['USER_ID'], $api); } //TODO эта управляющая конструкция по функционалу дублирует RetailCrmOrder::createCustomerForOrder. @@ -207,34 +184,34 @@ class RetailCrmEvent $userCorp = []; $corpName = RetailcrmConfigProvider::getCorporateClientName(); $corpAddress = RetailcrmConfigProvider::getCorporateClientAddress(); - + foreach ($arOrder['PROPS']['properties'] as $prop) { if ($prop['CODE'] === $corpName) { $nickName = $prop['VALUE'][0]; } - + if ($prop['CODE'] === $corpAddress) { $address = $prop['VALUE'][0]; } - + if (!empty($optionsLegalDetails) && $search = array_search($prop['CODE'], $optionsLegalDetails[$arOrder['PERSON_TYPE_ID']]) ) { $contragent[$search] = $prop['VALUE'][0];//legal order data } } - + if (!empty($contragentType)) { $contragent['contragentType'] = $contragentType; } - + $customersCorporate = false; $response = $api->customersCorporateList(['companyName' => $nickName]); - + if ($response && $response->getStatusCode() == 200) { $customersCorporate = $response['customersCorporate']; $singleCorp = reset($customersCorporate); - + if (!empty($singleCorp)) { $userCorp['customerCorporate'] = $singleCorp; $companiesResponse = $api->customersCorporateCompanies( @@ -245,7 +222,7 @@ class RetailCrmEvent 'id', $site ); - + if ($companiesResponse && $companiesResponse->isSuccessful()) { $orderCompany = array_reduce( $companiesResponse['companies'], @@ -253,7 +230,7 @@ class RetailCrmEvent if (is_array($item) && $item['name'] === $nickName) { $carry = $item; } - + return $carry; }, null @@ -266,35 +243,35 @@ class RetailCrmEvent 'ApiClient::customersCorporateList', 'error during fetching corporate customers' ); - - return false; + + return null; } - + //user $userCrm = RCrmActions::apiMethod($api, 'customersGet', __METHOD__, $arOrder['USER_ID'], $site); - + if (!isset($userCrm['customer'])) { - $arUser = Bitrix\Main\UserTable::getById($arOrder['USER_ID'])->fetch(); - + $arUser = UserTable::getById($arOrder['USER_ID'])->fetch(); + if (!empty($address)) { $arUser['PERSONAL_STREET'] = $address; } - + $resultUser = RetailCrmUser::customerSend($arUser, $api, 'individual', true, $site); - + if (!$resultUser) { RCrmActions::eventLog( __CLASS__ . '::' . __METHOD__, 'RetailCrmUser::customerSend', 'error during creating customer' ); - - return false; + + return null; } - + $userCrm = ['customer' => ['externalId' => $arOrder['USER_ID']]]; } - + if (!isset($userCorp['customerCorporate'])) { $resultUserCorp = RetailCrmCorporateClient::clientSend( $arOrder, @@ -304,23 +281,23 @@ class RetailCrmEvent false, $site ); - + Logger::getInstance()->write($resultUserCorp, 'resultUserCorp'); - + if (!$resultUserCorp) { RCrmActions::eventLog('RetailCrmEvent::orderSave', 'RetailCrmCorporateClient::clientSend', 'error during creating client'); - - return false; + + return null; } - + $arParams['customerCorporate'] = $resultUserCorp; $arParams['orderCompany'] = $resultUserCorp['mainCompany'] ?? null; - + $customerCorporateAddress = []; $customerCorporateCompany = []; $addressResult = null; $companyResult = null; - + if (!empty($address)) { //TODO address builder add $customerCorporateAddress = [ @@ -328,24 +305,24 @@ class RetailCrmEvent 'isMain' => true, 'text' => $address, ]; - + $addressResult = $api->customersCorporateAddressesCreate($resultUserCorp['id'], $customerCorporateAddress, 'id', $site); } - + $customerCorporateCompany = [ 'name' => $nickName, 'isMain' => true, 'contragent' => $contragent, ]; - + if (!empty($addressResult)) { $customerCorporateCompany['address'] = [ 'id' => $addressResult['id'], ]; } - + $companyResult = $api->customersCorporateCompaniesCreate($resultUserCorp['id'], $customerCorporateCompany, 'id', $site); - + $customerCorporateContact = [ 'isMain' => true, 'customer' => [ @@ -353,26 +330,26 @@ class RetailCrmEvent 'site' => $site, ], ]; - + if (!empty($companyResult)) { $orderCompany = [ 'id' => $companyResult['id'], ]; - + $customerCorporateContact['companies'] = [ [ 'company' => $orderCompany, ], ]; } - + $api->customersCorporateContactsCreate( $resultUserCorp['id'], $customerCorporateContact, 'id', $site ); - + $arParams['orderCompany'] = array_merge( $customerCorporateCompany, ['id' => $companyResult['id']] @@ -385,44 +362,61 @@ class RetailCrmEvent $api, $site = null ); - + $arParams['customerCorporate'] = $userCorp['customerCorporate']; - + if (!empty($orderCompany)) { $arParams['orderCompany'] = $orderCompany; } } - + $arParams['contactExId'] = $userCrm['customer']['externalId']; } else { //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); + $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 false; - } + RCrmActions::eventLog( + 'RetailCrmEvent::orderSave', + 'RetailCrmUser::customerSend', + 'error during creating customer' + ); + + return null; + }http://localhost/personal/cart/ } } + if (isset($arOrder['RESPONSIBLE_ID']) && !empty($arOrder['RESPONSIBLE_ID'])) { $managerService = ManagerService::getInstance(); $arParams['managerId'] = $managerService->getManagerCrmId($arOrder['RESPONSIBLE_ID']); } //order $resultOrder = RetailCrmOrder::orderSend($arOrder, $api, $arParams, true, $site, $methodApi); - + if (!$resultOrder) { - RCrmActions::eventLog('RetailCrmEvent::orderSave', 'RetailCrmOrder::orderSend', 'error during creating order'); - - return false; + RCrmActions::eventLog( + 'RetailCrmEvent::orderSave', + 'RetailCrmOrder::orderSend', + 'error during creating order' + ); + + return null; } - - return true; + + return $resultOrder; } - + /** * @param \Bitrix\Sale\Payment $event * @@ -433,22 +427,22 @@ class RetailCrmEvent public function paymentSave(Payment $event) { $apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0); - + /** @var \Bitrix\Sale\Order $order */ $order = $event->getCollection()->getOrder(); - + if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) || $apiVersion !== 'v5' || $order->isNew() ) { return false; } - - $optionsSitesList = RetailcrmConfigProvider::getSitesList(); + + $optionsSitesList = RetailcrmConfigProvider::getSitesList(); $optionsPaymentTypes = RetailcrmConfigProvider::getPaymentTypes(); $optionsPayStatuses = RetailcrmConfigProvider::getPayment(); $integrationPaymentTypes = RetailcrmConfigProvider::getIntegrationPaymentTypes(); - + $arPayment = [ 'ID' => $event->getId(), 'ORDER_ID' => $event->getField('ORDER_ID'), @@ -458,7 +452,7 @@ class RetailCrmEvent 'LID' => $order->getSiteId(), 'DATE_PAID' => $event->getField('DATE_PAID'), ]; - + if ($optionsSitesList) { if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) { $site = $optionsSitesList[$arPayment['LID']]; @@ -468,14 +462,14 @@ class RetailCrmEvent } elseif (!$optionsSitesList) { $site = null; } - + $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); $orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arPayment['ORDER_ID'], $site); - + if (isset($orderCrm['order'])) { $payments = $orderCrm['order']['payments']; } - + if ($payments) { foreach ($payments as $payment) { if (isset($payment['externalId'])) { @@ -488,16 +482,16 @@ class RetailCrmEvent } } } - + if (!empty($arPayment['PAY_SYSTEM_ID']) && isset($optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']])) { $paymentToCrm = [ 'type' => $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']], ]; - + if (!empty($arPayment['ID'])) { $paymentToCrm['externalId'] = RCrmActions::generatePaymentExternalId($arPayment['ID']); } - + $isIntegrationPayment = RetailCrmService::isIntegrationPayment($arPayment['PAY_SYSTEM_ID'] ?? null); @@ -509,15 +503,15 @@ class RetailCrmEvent $paymentToCrm['paidAt'] = $arPayment['DATE_PAID']; } } - + if (!empty($optionsPayStatuses[$arPayment['PAID']]) && !$isIntegrationPayment) { $paymentToCrm['status'] = $optionsPayStatuses[$arPayment['PAID']]; } - + if (!empty($arPayment['ORDER_ID'])) { $paymentToCrm['order']['externalId'] = $arPayment['ORDER_ID']; } - + if (RetailcrmConfigProvider::shouldSendPaymentAmount()) { $paymentToCrm['amount'] = $arPayment['SUM']; } @@ -525,9 +519,9 @@ class RetailCrmEvent RCrmActions::eventLog('RetailCrmEvent::paymentSave', 'payments', 'OrderID = ' . $arPayment['ID'] . '. Payment not found.'); return false; } - + $arPaymentExtId = RCrmActions::generatePaymentExternalId($arPayment['ID']); - + if (array_key_exists($arPaymentExtId, $paymentsExternalIds)) { $paymentData = $paymentsExternalIds[$arPaymentExtId]; } elseif (array_key_exists($arPayment['ID'], $paymentsExternalIds)) { @@ -535,7 +529,7 @@ class RetailCrmEvent } else { $paymentData = []; } - + if (empty($paymentData)) { RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site); } elseif ($paymentData['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { @@ -547,7 +541,7 @@ class RetailCrmEvent ); return false; } - + $paymentToCrm['externalId'] = $paymentData['externalId']; RCrmActions::apiMethod($api, 'paymentEditByExternalId', __METHOD__, $paymentToCrm, $site); } elseif ($paymentData['type'] != $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) { @@ -559,10 +553,10 @@ class RetailCrmEvent ); RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $paymentToCrm, $site); } - + return true; } - + /** * @param \Bitrix\Sale\Payment $event * @@ -571,22 +565,22 @@ class RetailCrmEvent public function paymentDelete(Payment $event): void { $apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0); - + if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) - || $apiVersion != 'v5' + || $apiVersion !== 'v5' || !$event->getId() ) { return; } - + $optionsSitesList = RetailcrmConfigProvider::getSitesList(); - + $arPayment = [ 'ID' => $event->getId(), 'ORDER_ID' => $event->getField('ORDER_ID'), 'LID' => $event->getCollection()->getOrder()->getSiteId(), ]; - + if ($optionsSitesList) { if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) { $site = $optionsSitesList[$arPayment['LID']]; @@ -596,12 +590,10 @@ class RetailCrmEvent } elseif (!$optionsSitesList) { $site = null; } - - $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 ApiClient($api_host, $api_key); + + $api = new RetailCrm\ApiClient(ConfigProvider::getApiUrl(), ConfigProvider::getApiKey()); $orderCrm = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $arPayment['ORDER_ID'], $site); - + if (isset($orderCrm['order']['payments']) && $orderCrm['order']['payments']) { foreach ($orderCrm['order']['payments'] as $payment) { if (isset($payment['externalId']) @@ -613,4 +605,50 @@ class RetailCrmEvent } } } + + /** + * @return bool + */ + private static function checkConfig(): bool + { + if (true == $GLOBALS['ORDER_DELETE_USER_ADMIN']) { + return false; + } + + if ($GLOBALS['RETAILCRM_ORDER_OLD_EVENT'] === false + && $GLOBALS['RETAILCRM_ORDER_DELETE'] === true + ) { + return false; + } + + if ($GLOBALS['RETAIL_CRM_HISTORY'] === true) { + return false; + } + + if (!RetailcrmDependencyLoader::loadDependencies()) { + return false; + } + + return true; + } + + /** + * @param \Bitrix\Sale\Order|\Bitrix\Main\Event $event + * + * @throws \Bitrix\Main\SystemException + */ + private static function getOrderArray($event): ?array + { + if ($event instanceof Order) { + $obOrder = $event; + } elseif ($event instanceof Event) { + $obOrder = $event->getParameter('ENTITY'); + } else { + RCrmActions::eventLog('RetailCrmEvent::orderSave', 'events', 'event error'); + + return null; + } + + return RetailCrmOrder::orderObjToArr($obOrder); + } } diff --git a/intaro.retailcrm/classes/general/history/FastOrderHistory.php b/intaro.retailcrm/classes/general/history/FastOrderHistory.php index 1149acf2..be2b095d 100644 --- a/intaro.retailcrm/classes/general/history/FastOrderHistory.php +++ b/intaro.retailcrm/classes/general/history/FastOrderHistory.php @@ -4,7 +4,7 @@ require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_be $GLOBALS['APPLICATION']->RestartBuffer(); $moduleId = 'intaro.retailcrm'; $historyTime = 'history_time'; -$idOrderCRM = (int)$_REQUEST['idOrderCRM']; +$idOrderCRM = (int) $_REQUEST['idOrderCRM']; if (CModule::IncludeModule($moduleId) && $idOrderCRM && $idOrderCRM > 0) { $timeBd = COption::GetOptionString($moduleId, $historyTime, 0); diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v4.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v4.php index 800301d5..ab2b754c 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v4.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v4.php @@ -9,7 +9,7 @@ class RetailCrmHistory 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_PAYMENT = 'payment_arr'; public static $CRM_ORDER_LAST_ID = 'order_last_id'; public static $CRM_SITES_LIST = 'sites_list'; public static $CRM_ORDER_PROPS = 'order_props'; @@ -751,7 +751,7 @@ class RetailCrmHistory if (file_exists($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/objects.xml')) { $objects = simplexml_load_file($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/objects.xml'); foreach ($objects->fields->field as $object) { - $fields[(string)$object["group"]][(string)$object["id"]] = (string)$object; + $fields[(string) $object["group"]][(string) $object["id"]] = (string) $object; } } $customers = array(); @@ -804,7 +804,7 @@ class RetailCrmHistory if (file_exists($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/objects.xml')) { $objects = simplexml_load_file($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/objects.xml'); foreach ($objects->fields->field as $object) { - $fields[(string)$object["group"]][(string)$object["id"]] = (string)$object; + $fields[(string) $object["group"]][(string) $object["id"]] = (string) $object; } } $orders = array(); diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index 19a90222..e932b031 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -2,7 +2,10 @@ use Bitrix\Main\ArgumentException; use Bitrix\Main\ArgumentNullException; +use Bitrix\Main\ArgumentOutOfRangeException; use Bitrix\Main\Context; +use Bitrix\Main\NotSupportedException; +use Bitrix\Main\SystemException; use Bitrix\Sale\Basket; use Bitrix\Sale\Delivery\Services\EmptyDeliveryService; use Bitrix\Sale\Delivery\Services\Manager; @@ -11,7 +14,11 @@ use Bitrix\Sale\Internals\PaymentTable; use Bitrix\Sale\Location\Search\Finder; use Bitrix\Sale\Order; use Bitrix\Sale\OrderUserProperties; +use Bitrix\Sale\Payment; use Intaro\RetailCrm\Service\ManagerService; +use Intaro\RetailCrm\Component\ConfigProvider; +use Intaro\RetailCrm\Component\Constants; +use Intaro\RetailCrm\Component\Handlers\EventsHandlers; IncludeModuleLangFile(__FILE__); class RetailCrmHistory @@ -532,7 +539,7 @@ class RetailCrmHistory continue; } - + $site = self::getSite($order['site']); if (null === $site) { @@ -1229,7 +1236,7 @@ class RetailCrmHistory return false; } - + /** * @param string $shopCode * @@ -1238,18 +1245,18 @@ class RetailCrmHistory public static function getSite(string $shopCode): ?string { $optionsSitesList = RetailcrmConfigProvider::getSitesList(); - + if ($optionsSitesList) { $searchResult = array_search($shopCode, $optionsSitesList, true); - + return is_string($searchResult) ? $searchResult : null; } - + $defaultSite = CSite::GetDefSite(); - + return is_string($defaultSite) ? $defaultSite : null; } - + /** * @param $array * @param $value @@ -1493,7 +1500,7 @@ class RetailCrmHistory return $orders; } - + /** * Filters out history by these terms: * - Changes from current API key will be added only if CMS changes are more actual than history. @@ -1512,7 +1519,7 @@ class RetailCrmHistory $history = []; $organizedHistory = []; $notOurChanges = []; - + foreach ($historyEntries as $entry) { if (!isset($entry[$recordType]['externalId'])) { if ($entry['source'] == 'api' @@ -1522,23 +1529,23 @@ class RetailCrmHistory ) { continue; } - + $history[] = $entry; - + continue; } - + $externalId = $entry[$recordType]['externalId']; $field = $entry['field']; - + if (!isset($organizedHistory[$externalId])) { $organizedHistory[$externalId] = []; } - + if (!isset($notOurChanges[$externalId])) { $notOurChanges[$externalId] = []; } - + if ($entry['source'] == 'api' && isset($entry['apiKey']['current']) && $entry['apiKey']['current'] == true @@ -1553,38 +1560,42 @@ class RetailCrmHistory $notOurChanges[$externalId][$field] = true; } } - + unset($notOurChanges); - + foreach ($organizedHistory as $historyChunk) { $history = array_merge($history, $historyChunk); } - + return $history; } - + /** * Update shipment in order * - * @param order object - * @param options delivery types - * @param order from crm + * @param \Bitrix\Sale\Order $bitrixOrder + * @param array $optionsDelivTypes + * @param array $crmOrder * - * @return void + * @return bool|null + * @throws \Bitrix\Main\ArgumentException + * @throws \Bitrix\Main\ArgumentNullException + * @throws \Bitrix\Main\ObjectNotFoundException + * @throws \Bitrix\Main\SystemException */ - public static function deliveryUpdate(Bitrix\Sale\Order $order, $optionsDelivTypes, $orderCrm) + public static function deliveryUpdate(Bitrix\Sale\Order $bitrixOrder, $optionsDelivTypes, $crmOrder) { - if (!$order instanceof Bitrix\Sale\Order) { + if (!$bitrixOrder instanceof Bitrix\Sale\Order) { return false; } - if ($order->getId()) { + if ($bitrixOrder->getId()) { $update = true; } else { $update = false; } - $crmCode = $orderCrm['delivery']['code'] ?? false; + $crmCode = $crmOrder['delivery']['code'] ?? false; $noDeliveryId = EmptyDeliveryService::getEmptyDeliveryServiceId(); if ($crmCode === false || !isset($optionsDelivTypes[$crmCode])) { @@ -1592,9 +1603,9 @@ class RetailCrmHistory } else { $deliveryId = $optionsDelivTypes[$crmCode]; - if (isset($orderCrm['delivery']['service']['code'])) { + if (isset($crmOrder['delivery']['service']['code'])) { $deliveryCode = Manager::getCodeById($deliveryId); - $serviceCode = $orderCrm['delivery']['service']['code']; + $serviceCode = $crmOrder['delivery']['service']['code']; $service = Manager::getService($deliveryId); if (is_object($service)) { @@ -1608,7 +1619,7 @@ class RetailCrmHistory if ($deliveryCode) { try { $deliveryService = Manager::getObjectByCode($deliveryCode . ':' . $serviceCode); - } catch (Bitrix\Main\SystemException $systemException) { + } catch (SystemException $systemException) { RCrmActions::eventLog('RetailCrmHistory::deliveryEdit', '\Bitrix\Sale\Delivery\Services\Manager::getObjectByCode', $systemException->getMessage()); } @@ -1620,31 +1631,33 @@ class RetailCrmHistory } $delivery = Manager::getObjectById($deliveryId); - $shipmentColl = $order->getShipmentCollection(); + $shipmentColl = $bitrixOrder->getShipmentCollection(); if ($delivery) { if (!$update) { $shipment = $shipmentColl->createItem($delivery); $shipment->setFields(array( - 'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'], - 'CURRENCY' => $order->getCurrency(), - 'DELIVERY_NAME' => $delivery->getName(), + 'BASE_PRICE_DELIVERY' => $crmOrder['delivery']['cost'], + 'CURRENCY' => $bitrixOrder->getCurrency(), + 'DELIVERY_NAME' => $delivery->getName(), 'CUSTOM_PRICE_DELIVERY' => 'Y' )); } else { foreach ($shipmentColl as $shipment) { if (!$shipment->isSystem()) { $shipment->setFields(array( - 'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'], - 'CURRENCY' => $order->getCurrency(), - 'DELIVERY_ID' => $deliveryId, - 'DELIVERY_NAME' => $delivery->getName(), + 'BASE_PRICE_DELIVERY' => $crmOrder['delivery']['cost'], + 'CURRENCY' => $bitrixOrder->getCurrency(), + 'DELIVERY_ID' => $deliveryId, + 'DELIVERY_NAME' => $delivery->getName(), 'CUSTOM_PRICE_DELIVERY' => 'Y' )); } } } } + + return true; } /** @@ -1703,11 +1716,11 @@ class RetailCrmHistory if (!$shipment->isSystem()) { try { $shipment->tryUnreserve(); - } catch (Main\ArgumentOutOfRangeException $ArgumentOutOfRangeException) { + } catch (ArgumentOutOfRangeException $ArgumentOutOfRangeException) { RCrmActions::eventLog('RetailCrmHistory::unreserveShipment', '\Bitrix\Sale\Shipment::tryUnreserve()', $ArgumentOutOfRangeException->getMessage()); return false; - } catch (Main\NotSupportedException $NotSupportedException) { + } catch (NotSupportedException $NotSupportedException) { RCrmActions::eventLog('RetailCrmHistory::unreserveShipment', '\Bitrix\Sale\Shipment::tryUnreserve()', $NotSupportedException->getMessage()); return false; @@ -1748,7 +1761,7 @@ class RetailCrmHistory $nowPaymentId = RCrmActions::getFromPaymentExternalId($paymentCrm['externalId']); $nowPayment = $paymentsList[$nowPaymentId]; //update data - if ($nowPayment instanceof \Bitrix\Sale\Payment) { + if ($nowPayment instanceof Payment) { $nowPayment->setField('SUM', $paymentCrm['amount']); if ($optionsPayTypes[$paymentCrm['type']] != $nowPayment->getField('PAY_SYSTEM_ID')) { $nowPayment->setField('PAY_SYSTEM_ID', $optionsPayTypes[$paymentCrm['type']]); diff --git a/intaro.retailcrm/classes/general/history/RetailUser.php b/intaro.retailcrm/classes/general/history/RetailUser.php index 6dc119d9..07df4bd1 100644 --- a/intaro.retailcrm/classes/general/history/RetailUser.php +++ b/intaro.retailcrm/classes/general/history/RetailUser.php @@ -14,30 +14,29 @@ class RetailUser extends CUser if ($arUser = $rsUser->Fetch()) { return $arUser['ID']; - } else { - $retailUser = new CUser; - - $userPassword = uniqid(); - - $arFields = [ - "NAME" => 'retailcrm', - "LAST_NAME" => 'retailcrm', - "EMAIL" => 'retailcrm@retailcrm.com', - "LOGIN" => 'retailcrm', - "LID" => "ru", - "ACTIVE" => "Y", - "GROUP_ID" => [2], - "PASSWORD" => $userPassword, - "CONFIRM_PASSWORD" => $userPassword, - ]; - - $id = $retailUser->Add($arFields); - - if (!$id) { - return null; - } else { - return $id; - } } + + $retailUser = new CUser; + $userPassword = uniqid(); + + $arFields = [ + 'NAME' => 'retailcrm', + 'LAST_NAME' => 'retailcrm', + 'EMAIL' => 'retailcrm@retailcrm.com', + 'LOGIN' => 'retailcrm', + 'LID' => 'ru', + 'ACTIVE' => 'Y', + 'GROUP_ID' => [2], + 'PASSWORD' => $userPassword, + 'CONFIRM_PASSWORD' => $userPassword, + ]; + + $id = $retailUser->Add($arFields); + + if (!$id) { + return null; + } + + return $id; } } diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v4.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v4.php index bbd48711..08feda80 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v4.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v4.php @@ -9,7 +9,7 @@ class RetailCrmOrder 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_PAYMENT = 'payment_arr'; public static $CRM_ORDER_LAST_ID = 'order_last_id'; public static $CRM_SITES_LIST = 'sites_list'; public static $CRM_ORDER_PROPS = 'order_props'; diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index ad6ef492..08db5ac2 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -8,9 +8,14 @@ use Bitrix\Sale\Internals\Fields; use Bitrix\Sale\Internals\OrderTable; use Bitrix\Sale\Location\LocationTable; use Bitrix\Sale\Order; +use Intaro\RetailCrm\Component\Factory\ClientFactory; +use Intaro\RetailCrm\Component\ServiceLocator; +use Intaro\RetailCrm\Service\LoyaltyService; use RetailCrm\ApiClient; use Intaro\RetailCrm\Service\ManagerService; +use Intaro\RetailCrm\Service\LoyaltyAccountService; use RetailCrm\Response\ApiResponse; +use Intaro\RetailCrm\Component\ConfigProvider; IncludeModuleLangFile(__FILE__); @@ -29,7 +34,7 @@ class RetailCrmOrder * @param null $site * @param string $methodApi * - * @return boolean|array + * @return array|false|\Intaro\RetailCrm\Model\Api\Response\OrdersCreateResponse|\Intaro\RetailCrm\Model\Api\Response\OrdersEditResponse|null * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ObjectPropertyException * @throws \Bitrix\Main\SystemException @@ -43,12 +48,12 @@ class RetailCrmOrder string $methodApi = 'ordersEdit' ) { if (!$api || empty($arParams)) { // add cond to check $arParams - return false; + return null; } if (empty($arOrder)) { RCrmActions::eventLog('RetailCrmOrder::orderSend', 'empty($arFields)', 'incorrect order'); - return false; + return null; } $dimensionsSetting = RetailcrmConfigProvider::getOrderDimensions(); @@ -161,7 +166,7 @@ class RetailCrmOrder //deliverys if (array_key_exists($arOrder['DELIVERYS'][0]['id'], $arParams['optionsDelivTypes'])) { $order['delivery']['code'] = $arParams['optionsDelivTypes'][$arOrder['DELIVERYS'][0]['id']]; - + if (isset($arOrder['DELIVERYS'][0]['service']) && $arOrder['DELIVERYS'][0]['service'] != '') { $order['delivery']['service']['code'] = $arOrder['DELIVERYS'][0]['service']; } @@ -176,7 +181,7 @@ class RetailCrmOrder $response = RCrmActions::apiMethod($api, 'ordersGet', __METHOD__, $order['externalId']); if (isset($response['order'])) { foreach ($response['order']['items'] as $k => $item) { - $externalId = $k ."_". $item['offer']['externalId']; + $externalId = $k .'_'. $item['offer']['externalId']; $orderItems[$externalId] = $item; } } @@ -192,7 +197,7 @@ class RetailCrmOrder $itemId = $orderItems[$externalId]['id']; $key = array_search('bitrix', array_column($externalIds, 'code')); - + if ($externalIds[$key]['code'] === 'bitrix') { $externalIds[$key] = [ 'code' => 'bitrix', @@ -203,13 +208,31 @@ class RetailCrmOrder 'code' => 'bitrix', 'value' => $externalId, ]; - } + } + + $keyBasketId = array_search('bitrixBasketId', array_column($externalIds, 'code')); + + if ($externalIds[$keyBasketId]['code'] === 'bitrixBasketId') { + $externalIds[$keyBasketId] = [ + 'code' => 'bitrixBasketId', + 'value' => $product['ID'], + ]; + } else { + $externalIds[] = [ + 'code' => 'bitrixBasketId', + 'value' => $product['ID'], + ]; + } } else { //create $externalIds = [ [ 'code' => 'bitrix', 'value' => $externalId, - ] + ], + [ + 'code' => 'bitrixBasketId', + 'value' => $product['ID'], + ], ]; } @@ -228,7 +251,7 @@ class RetailCrmOrder } $catalogProduct = CCatalogProduct::GetByID($product['PRODUCT_ID']); - + if (is_null($catalogProduct['PURCHASING_PRICE']) === false) { if ($catalogProduct['PURCHASING_CURRENCY'] && $currency != $catalogProduct['PURCHASING_CURRENCY']) { $purchasePrice = CCurrencyRates::ConvertCurrency( @@ -243,9 +266,25 @@ class RetailCrmOrder $item['purchasePrice'] = $purchasePrice; } + $discount = (double) $product['DISCOUNT_PRICE']; + $dpItem = $product['BASE_PRICE'] - $product['PRICE']; + + if ( $dpItem > 0 && $discount <= 0) { + $discount = $dpItem; + } + $item['discountManualPercent'] = 0; - - if ($product['BASE_PRICE'] >= $product['PRICE']) { + $item['initialPrice'] = (double) $product['BASE_PRICE']; + + if ( + $product['BASE_PRICE'] >= $product['PRICE'] + && $methodApi === 'ordersEdit' + && ConfigProvider::getLoyaltyProgramStatus() === 'Y' + ) { + /** @var LoyaltyService $service */ + $service = ServiceLocator::get(LoyaltyService::class); + $item['discountManualAmount'] = $service->getInitialDiscount((int) $externalId) ?? $discount; + } elseif ($product['BASE_PRICE'] >= $product['PRICE']) { $item['discountManualAmount'] = self::getDiscountManualAmount($product); $item['initialPrice'] = (double) $product['BASE_PRICE']; } else { @@ -276,7 +315,7 @@ class RetailCrmOrder //payments $payments = []; - + foreach ($arOrder['PAYMENTS'] as $payment) { $isIntegrationPayment = RetailCrmService::isIntegrationPayment($payment['PAY_SYSTEM_ID'] ?? null); @@ -340,8 +379,21 @@ class RetailCrmOrder Logger::getInstance()->write($order, 'orderSend'); - if ($send && !RCrmActions::apiMethod($api, $methodApi, __METHOD__, $order, $site)) { - return false; + if (ConfigProvider::getLoyaltyProgramStatus() === 'Y' && LoyaltyAccountService::getLoyaltyPersonalStatus()) { + $order['privilegeType'] = 'loyalty_level'; + } + + /** @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter $client */ + $client = ClientFactory::createClientAdapter(); + + if ($send) { + if ($methodApi === 'ordersCreate') { + return $client->createOrder($order, $site); + } + + if ($methodApi === 'ordersEdit') { + return $client->editOrder($order, $site); + } } return $order; @@ -354,7 +406,7 @@ class RetailCrmOrder * @param bool $failed -- flag to export failed orders * @param array|null $orderList * - * @return boolean + * @return bool * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ArgumentNullException * @throws \Bitrix\Main\ObjectPropertyException @@ -381,7 +433,7 @@ class RetailCrmOrder $orderIds = $orderList; } else { $dbOrder = OrderTable::GetList([ - 'order' => ["ID" => "ASC"], + 'order' => ['ID' => 'ASC'], 'filter' => ['>ID' => $lastUpOrderId], 'limit' => $pSize, 'select' => ['ID'], @@ -433,7 +485,6 @@ class RetailCrmOrder $arCustomer = []; $arCustomerCorporate = []; $order = self::orderObjToArr($bitrixOrder); - $user = UserTable::getById($order['USER_ID'])->fetch(); $site = self::getCrmShopCodeByLid($order['LID'], $arParams['optionsSitesList']); if (null === $site && count($arParams['optionsSitesList']) > 0) { @@ -474,7 +525,7 @@ class RetailCrmOrder return false; } - if ('Y' == RetailcrmConfigProvider::getCorporateClientStatus()) { + if ('Y' === RetailcrmConfigProvider::getCorporateClientStatus()) { $cachedCorporateIds = []; foreach ($ordersPack as $lid => $lidOrdersList) { @@ -497,7 +548,7 @@ class RetailCrmOrder if ($failed == true && $failedIds !== false && count($failedIds) > 0) { RetailcrmConfigProvider::setFailedOrdersIds(array_diff($failedIds, $recOrders)); - } elseif ($lastUpOrderId < max($recOrders) && $orderList === false) { + } elseif (count($orderList) === 0 && $lastUpOrderId < max($recOrders)) { RetailcrmConfigProvider::setLastOrderId(max($recOrders)); } } @@ -709,7 +760,7 @@ class RetailCrmOrder foreach ($pack as $key => $itemLoad) { $site = self::getCrmShopCodeByLid($key, $optionsSitesList); - + if (null === $site && count($optionsSitesList) > 0) { continue; } @@ -839,14 +890,14 @@ class RetailCrmOrder $sumDifference = $product->get('BASE_PRICE') - $product->get('PRICE'); return $sumDifference > 0 ? $sumDifference : 0.0; } - + $discount = (double) $product->get('DISCOUNT_PRICE'); $dpItem = $product->get('BASE_PRICE') - $product->get('PRICE'); - + if ($dpItem > 0 && $discount <= 0) { return $dpItem; } - + return $discount; } } diff --git a/intaro.retailcrm/classes/general/services/RetailCrmService.php b/intaro.retailcrm/classes/general/services/RetailCrmService.php index 22f8d973..9a4a87e3 100644 --- a/intaro.retailcrm/classes/general/services/RetailCrmService.php +++ b/intaro.retailcrm/classes/general/services/RetailCrmService.php @@ -12,8 +12,7 @@ class RetailCrmService */ public static function unsetIntegrationDeliveryFields(array $order): array { - $integrationDelivery = RetailcrmConfigProvider::getCrmIntegrationDelivery(); - + $integrationDelivery = RetailcrmConfigProvider::getCrmIntegrationDelivery(); if (isset($order['delivery']['code'])) { $deliveryCode = $order['delivery']['code']; diff --git a/intaro.retailcrm/classes/general/user/RetailCrmUser.php b/intaro.retailcrm/classes/general/user/RetailCrmUser.php index 00dee6d6..61019bdf 100644 --- a/intaro.retailcrm/classes/general/user/RetailCrmUser.php +++ b/intaro.retailcrm/classes/general/user/RetailCrmUser.php @@ -61,7 +61,7 @@ class RetailCrmUser return $customer; } - public static function customerEdit($arFields, $api, $optionsSitesList = array()): bool + public static function customerEdit($arFields, $api, $optionsSitesList = array()) : bool { if (empty($arFields)) { RCrmActions::eventLog('RetailCrmUser::customerEdit', 'empty($arFields)', 'incorrect customer'); diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index f937918a..864624db 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Исправление некорректной генерации каталога при повторных запусках генерации +- Добавлена поддержка программы лояльности diff --git a/intaro.retailcrm/export/export_setup.php b/intaro.retailcrm/export/export_setup.php index d0eea8cd..02579e8b 100644 --- a/intaro.retailcrm/export/export_setup.php +++ b/intaro.retailcrm/export/export_setup.php @@ -357,7 +357,7 @@ if ($STEP === 1) { $arIBlock['OLD_PROPERTY_SKU_SELECT'], $propertyKey ); - + echo $isSelected ? ' selected' : ''; ?> > @@ -377,7 +377,7 @@ if ($STEP === 1) {