diff --git a/.travis.yml b/.travis.yml index c98c779..94acbfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ language: php sudo: false php: - - 7.0 - 7.1 + - 7.2 env: global: @@ -39,4 +39,4 @@ deploy: on: php: 7.1 branch: master - condition: "$DEPLOY = true" \ No newline at end of file + condition: "$DEPLOY = false" \ No newline at end of file diff --git a/RoboFile.php b/RoboFile.php index 6be3b39..d8b74cf 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -73,9 +73,12 @@ class RoboFile extends \Robo\Tasks $this->taskDeleteDir('www')->run(); $this->taskFileSystemStack() ->mirror('vendor/opencart/opencart/upload', 'www') - ->copy('vendor/beyondit/opencart-test-suite/src/upload/system/config/test-config.php','www/system/config/test-config.php') - ->copy('vendor/beyondit/opencart-test-suite/src/upload/catalog/controller/startup/test_startup.php','www/catalog/controller/startup/test_startup.php') + ->copy('tests/test-config.php', 'www/system/config/test-config.php') + ->copy('vendor/beyondit/opencart-test-suite/src/upload/system/library/session/test.php', 'www/system/library/session/test.php') + ->copy('vendor/beyondit/opencart-test-suite/src/upload/admin/controller/startup/test_startup.php','www/admin/controller/startup/test_startup.php') ->chmod('www', 0777, 0000, true) + ->rename('www/config-dist.php', 'www/config.php') + ->rename('www/admin/config-dist.php', 'www/admin/config.php') ->run(); // Create new database, drop if exists already @@ -97,7 +100,9 @@ class RoboFile extends \Robo\Tasks $install->run(); $this->taskDeleteDir('www/install')->run(); - $this->restoreSampleData($conn); + if (isset($conn)) { + $this->restoreSampleData($conn); + } $conn = null; } diff --git a/VERSION b/VERSION index ef538c2..826cf5d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.2 +3.1.0-alpha1 \ No newline at end of file diff --git a/composer.json b/composer.json index b541a38..9387249 100644 --- a/composer.json +++ b/composer.json @@ -9,11 +9,12 @@ "email": "integration@retailcrm.ru" } ], + "version": "3.1.0-alpha1", "require-dev": { - "opencart/opencart" : "2.3.0.2", + "opencart/opencart" : "3.1.0.0_a1", "vlucas/phpdotenv": "~1.1.0", - "phpunit/phpunit" : "~4.0", - "beyondit/opencart-test-suite": "~2.3.0", + "phpunit/phpunit" : "^6", + "beyondit/opencart-test-suite": "~3.0", "consolidation/robo": "~1", "henrikbjorn/lurker": "^1.2" }, @@ -25,9 +26,11 @@ "opencart-dir" : "www" }, "scripts" : { + "test-library": "bin/phpunit --testsuite library-tests --colors=always", "test-admin": "bin/phpunit --testsuite admin-tests --colors=always", "test-catalog": "bin/phpunit --testsuite catalog-tests --colors=always", "test": [ + "@test-library", "@test-admin", "@test-catalog" ], diff --git a/composer.lock b/composer.lock index 4f6742b..85f9e4f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "d99f618b88f08898e6a4fef93d970c82", - "content-hash": "ca0e4df35c14fb6adac2eb994bcf9e44", + "hash": "e86a9a9221ff5785b6015d1645dd9f51", + "content-hash": "89e86d741ab7fffaceca710d5fb4a35f", "packages": [], "packages-dev": [ { @@ -53,35 +53,32 @@ }, { "name": "beyondit/opencart-test-suite", - "version": "2.3.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/beyondit/opencart-test-suite.git", - "reference": "066f980fcef884409e606302bf028d04157d83b2" + "reference": "a56a41d0e620206faaed8e80df7a3e7fdf4c4f3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/beyondit/opencart-test-suite/zipball/066f980fcef884409e606302bf028d04157d83b2", - "reference": "066f980fcef884409e606302bf028d04157d83b2", + "url": "https://api.github.com/repos/beyondit/opencart-test-suite/zipball/a56a41d0e620206faaed8e80df7a3e7fdf4c4f3b", + "reference": "a56a41d0e620206faaed8e80df7a3e7fdf4c4f3b", "shasum": "" }, "require": { - "beyondit/opencart-extension-installer": "~2.3.0", - "phpunit/phpunit": "4.*" + "beyondit/opencart-extension-installer": "*", + "php": ">=5.4", + "phpunit/phpunit": "^6.2" }, "require-dev": { - "consolidation/robo": "^1.0", - "opencart/opencart": "2.3.0.2", - "phpunit/phpunit": "4.*", - "vlucas/phpdotenv": "~1.1.0" + "consolidation/robo": "^1.1", + "opencart/opencart": "3.0.2.0", + "squizlabs/php_codesniffer": "^3.0", + "vlucas/phpdotenv": "^2.4" }, "type": "opencart-extension", "extra": { - "src-dir": "src/upload", - "mappings": [ - "system/config/test-config.php", - "catalog/controller/startup/test_startup.php" - ] + "src-dir": "src/upload" }, "autoload": { "files": [ @@ -101,7 +98,11 @@ } ], "description": "Testing Suite for OpenCart Development", - "time": "2016-12-02 10:08:16" + "keywords": [ + "opencart", + "phpunit" + ], + "time": "2017-07-21 16:25:52" }, { "name": "braintree/braintree_php", @@ -189,16 +190,16 @@ }, { "name": "consolidation/annotated-command", - "version": "2.8.4", + "version": "2.9.1", "source": { "type": "git", "url": "https://github.com/consolidation/annotated-command.git", - "reference": "651541a0b68318a2a202bda558a676e5ad92223c" + "reference": "4bdbb8fa149e1cc1511bd77b0bc4729fd66bccac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/consolidation/annotated-command/zipball/651541a0b68318a2a202bda558a676e5ad92223c", - "reference": "651541a0b68318a2a202bda558a676e5ad92223c", + "url": "https://api.github.com/repos/consolidation/annotated-command/zipball/4bdbb8fa149e1cc1511bd77b0bc4729fd66bccac", + "reference": "4bdbb8fa149e1cc1511bd77b0bc4729fd66bccac", "shasum": "" }, "require": { @@ -237,20 +238,20 @@ } ], "description": "Initialize Symfony Console commands from annotated command class methods.", - "time": "2018-05-25 18:04:25" + "time": "2018-09-19 17:47:18" }, { "name": "consolidation/config", - "version": "1.0.11", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/consolidation/config.git", - "reference": "ede41d946078e97e7a9513aadc3352f1c26817af" + "reference": "c9fc25e9088a708637e18a256321addc0670e578" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/consolidation/config/zipball/ede41d946078e97e7a9513aadc3352f1c26817af", - "reference": "ede41d946078e97e7a9513aadc3352f1c26817af", + "url": "https://api.github.com/repos/consolidation/config/zipball/c9fc25e9088a708637e18a256321addc0670e578", + "reference": "c9fc25e9088a708637e18a256321addc0670e578", "shasum": "" }, "require": { @@ -260,7 +261,7 @@ }, "require-dev": { "g1a/composer-test-scenarios": "^1", - "phpunit/phpunit": "^4", + "phpunit/phpunit": "^5", "satooshi/php-coveralls": "^1.0", "squizlabs/php_codesniffer": "2.*", "symfony/console": "^2.5|^3|^4", @@ -291,7 +292,7 @@ } ], "description": "Provide configuration services for a commandline tool.", - "time": "2018-05-27 01:17:02" + "time": "2018-08-07 22:57:00" }, { "name": "consolidation/log", @@ -399,16 +400,16 @@ }, { "name": "consolidation/robo", - "version": "1.3.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/consolidation/Robo.git", - "reference": "ac563abfadf7cb7314b4e152f2b5033a6c255f6f" + "reference": "31f2d2562c4e1dcde70f2659eefd59aa9c7f5b2d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/consolidation/Robo/zipball/ac563abfadf7cb7314b4e152f2b5033a6c255f6f", - "reference": "ac563abfadf7cb7314b4e152f2b5033a6c255f6f", + "url": "https://api.github.com/repos/consolidation/Robo/zipball/31f2d2562c4e1dcde70f2659eefd59aa9c7f5b2d", + "reference": "31f2d2562c4e1dcde70f2659eefd59aa9c7f5b2d", "shasum": "" }, "require": { @@ -416,6 +417,8 @@ "consolidation/config": "^1.0.10", "consolidation/log": "~1", "consolidation/output-formatters": "^3.1.13", + "consolidation/self-update": "^1", + "g1a/composer-test-scenarios": "^2", "grasmash/yaml-expander": "^1.3", "league/container": "^2.2", "php": ">=5.5.0", @@ -432,7 +435,6 @@ "codeception/aspect-mock": "^1|^2.1.1", "codeception/base": "^2.3.7", "codeception/verify": "^0.3.2", - "g1a/composer-test-scenarios": "^2", "goaop/framework": "~2.1.2", "goaop/parser-reflection": "^1.1.0", "natxet/cssmin": "3.0.4", @@ -475,7 +477,57 @@ } ], "description": "Modern task runner", - "time": "2018-05-27 01:42:53" + "time": "2018-08-17 18:44:18" + }, + { + "name": "consolidation/self-update", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/consolidation/self-update.git", + "reference": "de33822f907e0beb0ffad24cf4b1b4fae5ada318" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/consolidation/self-update/zipball/de33822f907e0beb0ffad24cf4b1b4fae5ada318", + "reference": "de33822f907e0beb0ffad24cf4b1b4fae5ada318", + "shasum": "" + }, + "require": { + "php": ">=5.5.0", + "symfony/console": "^2.8|^3|^4", + "symfony/filesystem": "^2.5|^3|^4" + }, + "bin": [ + "scripts/release" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "SelfUpdate\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Greg Anderson", + "email": "greg.1.anderson@greenknowe.org" + }, + { + "name": "Alexander Menk", + "email": "menk@mestrona.net" + } + ], + "description": "Provides a self:update command for Symfony Console applications.", + "time": "2018-08-24 17:01:46" }, { "name": "container-interop/container-interop", @@ -614,32 +666,32 @@ }, { "name": "doctrine/instantiator", - "version": "1.0.5", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", "shasum": "" }, "require": { - "php": ">=5.3,<8.0-DEV" + "php": "^7.1" }, "require-dev": { "athletic/athletic": "~0.1.8", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" + "phpunit/phpunit": "^6.2.3", + "squizlabs/php_codesniffer": "^3.0.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -664,7 +716,40 @@ "constructor", "instantiate" ], - "time": "2015-06-14 21:17:01" + "time": "2017-07-22 11:58:36" + }, + { + "name": "g1a/composer-test-scenarios", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/g1a/composer-test-scenarios.git", + "reference": "a166fd15191aceab89f30c097e694b7cf3db4880" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/g1a/composer-test-scenarios/zipball/a166fd15191aceab89f30c097e694b7cf3db4880", + "reference": "a166fd15191aceab89f30c097e694b7cf3db4880", + "shasum": "" + }, + "bin": [ + "scripts/create-scenario", + "scripts/dependency-licenses", + "scripts/install-scenario" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Greg Anderson", + "email": "greg.1.anderson@greenknowe.org" + } + ], + "description": "Useful scripts for testing multiple sets of Composer dependencies.", + "time": "2018-08-08 23:37:23" }, { "name": "grasmash/expander", @@ -763,16 +848,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "5.3.2", + "version": "5.3.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "f9acb4761844317e626a32259205bec1f1bc60d2" + "reference": "93bbdb30d59be6cd9839495306c65f2907370eb9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f9acb4761844317e626a32259205bec1f1bc60d2", - "reference": "f9acb4761844317e626a32259205bec1f1bc60d2", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/93bbdb30d59be6cd9839495306c65f2907370eb9", + "reference": "93bbdb30d59be6cd9839495306c65f2907370eb9", "shasum": "" }, "require": { @@ -812,7 +897,7 @@ "rest", "web service" ], - "time": "2018-01-15 07:18:01" + "time": "2018-07-31 13:33:10" }, { "name": "guzzlehttp/log-subscriber", @@ -920,16 +1005,16 @@ }, { "name": "guzzlehttp/ringphp", - "version": "1.1.0", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/guzzle/RingPHP.git", - "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b" + "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", - "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", + "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/5e2a174052995663dd68e6b5ad838afd47dd615b", + "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b", "shasum": "" }, "require": { @@ -967,7 +1052,7 @@ } ], "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.", - "time": "2015-05-20 03:37:09" + "time": "2018-07-31 13:22:33" }, { "name": "guzzlehttp/streams", @@ -1128,38 +1213,37 @@ }, { "name": "leafo/scssphp", - "version": "v0.0.12", + "version": "v0.7.5", "source": { "type": "git", "url": "https://github.com/leafo/scssphp.git", - "reference": "ff76df3e45af45e808f3fcd516a2cb5cbc77f45e" + "reference": "8b538d828bbb75276974605c4a1a435e939da74e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/leafo/scssphp/zipball/ff76df3e45af45e808f3fcd516a2cb5cbc77f45e", - "reference": "ff76df3e45af45e808f3fcd516a2cb5cbc77f45e", + "url": "https://api.github.com/repos/leafo/scssphp/zipball/8b538d828bbb75276974605c4a1a435e939da74e", + "reference": "8b538d828bbb75276974605c4a1a435e939da74e", "shasum": "" }, "require": { - "php": ">=5.2.0" + "php": ">=5.4.0" }, "require-dev": { - "php": ">=5.3.0", - "phpunit/phpunit": "3.7.*" + "phpunit/phpunit": "~4.6", + "squizlabs/php_codesniffer": "~2.5" }, "bin": [ - "pscss" + "bin/pscss" ], "type": "library", "autoload": { - "classmap": [ - "scss.inc.php" - ] + "psr-4": { + "Leafo\\ScssPhp\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT", - "GPL-3.0" + "MIT" ], "authors": [ { @@ -1169,8 +1253,15 @@ } ], "description": "scssphp is a compiler for SCSS written in PHP.", - "homepage": "http://leafo.net/scssphp/", - "time": "2014-07-07 01:51:39" + "homepage": "http://leafo.github.io/scssphp/", + "keywords": [ + "css", + "less", + "sass", + "scss", + "stylesheet" + ], + "time": "2018-02-09 02:04:21" }, { "name": "league/container", @@ -1238,17 +1329,65 @@ "time": "2017-05-10 09:20:27" }, { - "name": "opencart/opencart", - "version": "2.3.0.2", + "name": "myclabs/deep-copy", + "version": "1.8.1", "source": { "type": "git", - "url": "https://github.com/opencart/opencart.git", - "reference": "85e0f35ae96197e0aa92a4aedd3aad76eebd2961" + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opencart/opencart/zipball/85e0f35ae96197e0aa92a4aedd3aad76eebd2961", - "reference": "85e0f35ae96197e0aa92a4aedd3aad76eebd2961", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2018-06-11 23:09:50" + }, + { + "name": "opencart/opencart", + "version": "3.1.0.0_a1", + "source": { + "type": "git", + "url": "https://github.com/opencart/opencart.git", + "reference": "d572831caca12926b32652a4f354cd196a5b719d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/opencart/opencart/zipball/d572831caca12926b32652a4f354cd196a5b719d", + "reference": "d572831caca12926b32652a4f354cd196a5b719d", "shasum": "" }, "require": { @@ -1256,23 +1395,127 @@ "cardinity/cardinity-sdk-php": "^1.0", "divido/divido-php": ">=1.1.1", "klarna/kco_rest": "^2.2", - "leafo/scssphp": "0.0.12", - "php": ">=5.4.0" + "leafo/scssphp": "0.7.5", + "php": ">=7.1.0", + "twig/twig": "^2.4.8", + "zoujingli/wechat-php-sdk": ">=1.3.10" }, "type": "project", "notification-url": "https://packagist.org/downloads/", "license": [ - "GPL-3.0+" + "GPL-3.0-or-later" ], "description": "OpenCart", - "homepage": "http://www.opencart.com", + "homepage": "https://www.opencart.com/", "keywords": [ "ecommerce", "framework", "opencart", "opensource" ], - "time": "2016-08-01 13:43:14" + "time": "2018-07-24 17:33:42" + }, + { + "name": "phar-io/manifest", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/2df402786ab5368a0169091f61a7c1e0eb6852d0", + "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^1.0.1", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2017-03-05 18:14:27" + }, + { + "name": "phar-io/version", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2017-03-05 17:38:23" }, { "name": "phpdocumentor/reflection-common", @@ -1428,16 +1671,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.6", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712" + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712", - "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", "shasum": "" }, "require": { @@ -1449,12 +1692,12 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.8.x-dev" } }, "autoload": { @@ -1487,43 +1730,44 @@ "spy", "stub" ], - "time": "2018-04-18 13:57:24" + "time": "2018-08-05 17:53:17" }, { "name": "phpunit/php-code-coverage", - "version": "2.2.4", + "version": "5.3.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" + "reference": "c89677919c5dd6d3b3852f230a663118762218ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c89677919c5dd6d3b3852f230a663118762218ac", + "reference": "c89677919c5dd6d3b3852f230a663118762218ac", "shasum": "" }, "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "^1.3.2", - "sebastian/version": "~1.0" + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^7.0", + "phpunit/php-file-iterator": "^1.4.2", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^2.0.1", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^3.0", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" }, "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4" + "phpunit/phpunit": "^6.0" }, "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.2.1", - "ext-xmlwriter": "*" + "ext-xdebug": "^2.5.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2.x-dev" + "dev-master": "5.3.x-dev" } }, "autoload": { @@ -1538,7 +1782,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1549,7 +1793,7 @@ "testing", "xunit" ], - "time": "2015-10-06 15:47:00" + "time": "2018-04-06 15:36:58" }, { "name": "phpunit/php-file-iterator", @@ -1690,29 +1934,29 @@ }, { "name": "phpunit/php-token-stream", - "version": "1.4.12", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16" + "reference": "791198a2c6254db10131eecfe8c06670700904db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16", - "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", + "reference": "791198a2c6254db10131eecfe8c06670700904db", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=5.3.3" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^6.2.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -1735,45 +1979,57 @@ "keywords": [ "tokenizer" ], - "time": "2017-12-04 08:55:13" + "time": "2017-11-27 05:48:46" }, { "name": "phpunit/phpunit", - "version": "4.8.36", + "version": "6.5.13", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "46023de9a91eec7dfb06cc56cb4e260017298517" + "reference": "0973426fb012359b2f18d3bd1e90ef1172839693" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46023de9a91eec7dfb06cc56cb4e260017298517", - "reference": "46023de9a91eec7dfb06cc56cb4e260017298517", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0973426fb012359b2f18d3bd1e90ef1172839693", + "reference": "0973426fb012359b2f18d3bd1e90ef1172839693", "shasum": "" }, "require": { "ext-dom": "*", "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "~2.1", - "phpunit/php-file-iterator": "~1.4", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.2.2", - "sebastian/diff": "~1.2", - "sebastian/environment": "~1.3", - "sebastian/exporter": "~1.2", - "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", - "symfony/yaml": "~2.1|~3.0" + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "^1.6.1", + "phar-io/manifest": "^1.0.1", + "phar-io/version": "^1.0", + "php": "^7.0", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^5.3", + "phpunit/php-file-iterator": "^1.4.3", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^1.0.9", + "phpunit/phpunit-mock-objects": "^5.0.9", + "sebastian/comparator": "^2.1", + "sebastian/diff": "^2.0", + "sebastian/environment": "^3.1", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^2.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^1.0", + "sebastian/version": "^2.0.1" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2", + "phpunit/dbunit": "<3.0" + }, + "require-dev": { + "ext-pdo": "*" }, "suggest": { - "phpunit/php-invoker": "~1.1" + "ext-xdebug": "*", + "phpunit/php-invoker": "^1.1" }, "bin": [ "phpunit" @@ -1781,7 +2037,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.8.x-dev" + "dev-master": "6.5.x-dev" } }, "autoload": { @@ -1807,30 +2063,33 @@ "testing", "xunit" ], - "time": "2017-06-21 08:07:12" + "time": "2018-09-08 15:10:43" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.8", + "version": "5.0.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/cd1cf05c553ecfec36b170070573e540b67d3f1f", + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.2", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2", - "sebastian/exporter": "~1.2" + "doctrine/instantiator": "^1.0.5", + "php": "^7.0", + "phpunit/php-text-template": "^1.2.1", + "sebastian/exporter": "^3.1" + }, + "conflict": { + "phpunit/phpunit": "<6.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^6.5.11" }, "suggest": { "ext-soap": "*" @@ -1838,7 +2097,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3.x-dev" + "dev-master": "5.0.x-dev" } }, "autoload": { @@ -1853,7 +2112,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1863,7 +2122,7 @@ "mock", "xunit" ], - "time": "2015-10-02 06:51:40" + "time": "2018-08-09 05:50:03" }, { "name": "psr/container", @@ -1963,16 +2222,16 @@ }, { "name": "react/promise", - "version": "v2.6.0", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/reactphp/promise.git", - "reference": "5e60e5596a5422287f9d2205f405bef2ae0cef4b" + "reference": "f4edc2581617431aea50430749db55cc3fc031b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/5e60e5596a5422287f9d2205f405bef2ae0cef4b", - "reference": "5e60e5596a5422287f9d2205f405bef2ae0cef4b", + "url": "https://api.github.com/repos/reactphp/promise/zipball/f4edc2581617431aea50430749db55cc3fc031b3", + "reference": "f4edc2581617431aea50430749db55cc3fc031b3", "shasum": "" }, "require": { @@ -2005,34 +2264,79 @@ "promise", "promises" ], - "time": "2018-06-11 11:05:43" + "time": "2018-06-13 15:59:06" }, { - "name": "sebastian/comparator", - "version": "1.2.4", + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2 || ~2.0" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^5.7 || ^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "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-04 06:30:41" + }, + { + "name": "sebastian/comparator", + "version": "2.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", + "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/diff": "^2.0 || ^3.0", + "sebastian/exporter": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" } }, "autoload": { @@ -2063,38 +2367,38 @@ } ], "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", + "homepage": "https://github.com/sebastianbergmann/comparator", "keywords": [ "comparator", "compare", "equality" ], - "time": "2017-01-29 09:50:25" + "time": "2018-02-01 13:46:46" }, { "name": "sebastian/diff", - "version": "1.4.3", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" + "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", + "reference": "347c1d8b49c5c3ee30c7040ea6fc446790e6bddd", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpunit/phpunit": "^6.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -2121,32 +2425,32 @@ "keywords": [ "diff" ], - "time": "2017-05-22 07:24:03" + "time": "2017-08-03 08:09:46" }, { "name": "sebastian/environment", - "version": "1.3.8", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/cd0871b3975fb7fc44d11314fd1ee20925fce4f5", + "reference": "cd0871b3975fb7fc44d11314fd1ee20925fce4f5", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.0" + "phpunit/phpunit": "^6.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "3.1.x-dev" } }, "autoload": { @@ -2171,34 +2475,34 @@ "environment", "hhvm" ], - "time": "2016-08-18 05:49:44" + "time": "2017-07-01 08:51:00" }, { "name": "sebastian/exporter", - "version": "1.2.2", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/recursion-context": "~1.0" + "php": "^7.0", + "sebastian/recursion-context": "^3.0" }, "require-dev": { "ext-mbstring": "*", - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "3.1.x-dev" } }, "autoload": { @@ -2238,27 +2542,27 @@ "export", "exporter" ], - "time": "2016-06-17 09:04:28" + "time": "2017-04-03 13:19:02" }, { "name": "sebastian/global-state", - "version": "1.1.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^6.0" }, "suggest": { "ext-uopz": "*" @@ -2266,7 +2570,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -2289,32 +2593,124 @@ "keywords": [ "global state" ], - "time": "2015-10-12 03:26:01" + "time": "2017-04-27 15:39:26" }, { - "name": "sebastian/recursion-context", - "version": "1.0.5", + "name": "sebastian/object-enumerator", + "version": "3.0.3", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7" + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/b19cc3298482a335a95f3016d2f8a6950f0fbcd7", - "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-08-03 12:35:26" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29 09:07:27" + }, + { + "name": "sebastian/recursion-context", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" } }, "autoload": { @@ -2342,23 +2738,73 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-10-03 07:41:43" + "time": "2017-03-03 06:23:57" }, { - "name": "sebastian/version", - "version": "1.0.6", + "name": "sebastian/resource-operations", + "version": "1.0.0", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", "shasum": "" }, + "require": { + "php": ">=5.6.0" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28 20:34:47" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -2377,20 +2823,20 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-06-21 13:59:46" + "time": "2016-10-03 07:35:21" }, { "name": "symfony/config", - "version": "v3.4.11", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "73e055cf2e6467715f187724a0347ea32079967c" + "reference": "7b08223b7f6abd859651c56bcabf900d1627d085" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/73e055cf2e6467715f187724a0347ea32079967c", - "reference": "73e055cf2e6467715f187724a0347ea32079967c", + "url": "https://api.github.com/repos/symfony/config/zipball/7b08223b7f6abd859651c56bcabf900d1627d085", + "reference": "7b08223b7f6abd859651c56bcabf900d1627d085", "shasum": "" }, "require": { @@ -2441,25 +2887,24 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2018-05-14 16:49:53" + "time": "2018-07-26 11:19:56" }, { "name": "symfony/console", - "version": "v3.4.11", + "version": "v4.1.4", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "36f83f642443c46f3cf751d4d2ee5d047d757a27" + "reference": "ca80b8ced97cf07390078b29773dc384c39eee1f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/36f83f642443c46f3cf751d4d2ee5d047d757a27", - "reference": "36f83f642443c46f3cf751d4d2ee5d047d757a27", + "url": "https://api.github.com/repos/symfony/console/zipball/ca80b8ced97cf07390078b29773dc384c39eee1f", + "reference": "ca80b8ced97cf07390078b29773dc384c39eee1f", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8", - "symfony/debug": "~2.8|~3.0|~4.0", + "php": "^7.1.3", "symfony/polyfill-mbstring": "~1.0" }, "conflict": { @@ -2468,11 +2913,11 @@ }, "require-dev": { "psr/log": "~1.0", - "symfony/config": "~3.3|~4.0", + "symfony/config": "~3.4|~4.0", "symfony/dependency-injection": "~3.4|~4.0", - "symfony/event-dispatcher": "~2.8|~3.0|~4.0", + "symfony/event-dispatcher": "~3.4|~4.0", "symfony/lock": "~3.4|~4.0", - "symfony/process": "~3.3|~4.0" + "symfony/process": "~3.4|~4.0" }, "suggest": { "psr/log-implementation": "For using the console logger", @@ -2483,7 +2928,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -2510,76 +2955,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-05-16 08:49:21" - }, - { - "name": "symfony/debug", - "version": "v3.4.11", - "source": { - "type": "git", - "url": "https://github.com/symfony/debug.git", - "reference": "b28fd73fefbac341f673f5efd707d539d6a19f68" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/b28fd73fefbac341f673f5efd707d539d6a19f68", - "reference": "b28fd73fefbac341f673f5efd707d539d6a19f68", - "shasum": "" - }, - "require": { - "php": "^5.5.9|>=7.0.8", - "psr/log": "~1.0" - }, - "conflict": { - "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" - }, - "require-dev": { - "symfony/http-kernel": "~2.8|~3.0|~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Debug\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Debug Component", - "homepage": "https://symfony.com", - "time": "2018-05-16 14:03:39" + "time": "2018-07-26 11:24:31" }, { "name": "symfony/event-dispatcher", - "version": "v3.4.11", + "version": "v3.4.15", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "fdd5abcebd1061ec647089c6c41a07ed60af09f8" + "reference": "b2e1f19280c09a42dc64c0b72b80fe44dd6e88fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/fdd5abcebd1061ec647089c6c41a07ed60af09f8", - "reference": "fdd5abcebd1061ec647089c6c41a07ed60af09f8", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b2e1f19280c09a42dc64c0b72b80fe44dd6e88fb", + "reference": "b2e1f19280c09a42dc64c0b72b80fe44dd6e88fb", "shasum": "" }, "require": { @@ -2629,30 +3018,30 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2018-04-06 07:35:25" + "time": "2018-07-26 09:06:28" }, { "name": "symfony/filesystem", - "version": "v3.4.11", + "version": "v4.1.4", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "8e03ca3fa52a0f56b87506f38cf7bd3f9442b3a0" + "reference": "c0f5f62db218fa72195b8b8700e4b9b9cf52eb5e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/8e03ca3fa52a0f56b87506f38cf7bd3f9442b3a0", - "reference": "8e03ca3fa52a0f56b87506f38cf7bd3f9442b3a0", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/c0f5f62db218fa72195b8b8700e4b9b9cf52eb5e", + "reference": "c0f5f62db218fa72195b8b8700e4b9b9cf52eb5e", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8", + "php": "^7.1.3", "symfony/polyfill-ctype": "~1.8" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -2679,29 +3068,29 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2018-05-16 08:49:21" + "time": "2018-08-18 16:52:46" }, { "name": "symfony/finder", - "version": "v3.4.11", + "version": "v4.1.4", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "472a92f3df8b247b49ae364275fb32943b9656c6" + "reference": "e162f1df3102d0b7472805a5a9d5db9fcf0a8068" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/472a92f3df8b247b49ae364275fb32943b9656c6", - "reference": "472a92f3df8b247b49ae364275fb32943b9656c6", + "url": "https://api.github.com/repos/symfony/finder/zipball/e162f1df3102d0b7472805a5a9d5db9fcf0a8068", + "reference": "e162f1df3102d0b7472805a5a9d5db9fcf0a8068", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8" + "php": "^7.1.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -2728,29 +3117,32 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2018-05-16 08:49:21" + "time": "2018-07-26 11:24:31" }, { "name": "symfony/polyfill-ctype", - "version": "v1.8.0", + "version": "v1.9.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", - "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "suggest": { + "ext-ctype": "For best performance" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -2783,20 +3175,20 @@ "polyfill", "portable" ], - "time": "2018-04-30 19:57:29" + "time": "2018-08-06 14:22:27" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.8.0", + "version": "v1.9.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "3296adf6a6454a050679cde90f95350ad604b171" + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", - "reference": "3296adf6a6454a050679cde90f95350ad604b171", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", "shasum": "" }, "require": { @@ -2808,7 +3200,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -2842,29 +3234,29 @@ "portable", "shim" ], - "time": "2018-04-26 10:06:28" + "time": "2018-08-06 14:22:27" }, { "name": "symfony/process", - "version": "v3.4.11", + "version": "v4.1.4", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "4cbf2db9abcb01486a21b7a059e03a62fae63187" + "reference": "86cdb930a6a855b0ab35fb60c1504cb36184f843" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/4cbf2db9abcb01486a21b7a059e03a62fae63187", - "reference": "4cbf2db9abcb01486a21b7a059e03a62fae63187", + "url": "https://api.github.com/repos/symfony/process/zipball/86cdb930a6a855b0ab35fb60c1504cb36184f843", + "reference": "86cdb930a6a855b0ab35fb60c1504cb36184f843", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8" + "php": "^7.1.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -2891,7 +3283,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2018-05-16 08:49:21" + "time": "2018-08-03 11:13:38" }, { "name": "symfony/translation", @@ -2959,16 +3351,16 @@ }, { "name": "symfony/validator", - "version": "v2.8.41", + "version": "v2.8.45", "source": { "type": "git", "url": "https://github.com/symfony/validator.git", - "reference": "96bbfd5534d2e07ba45255bad27ee90d3bc121a3" + "reference": "131ae089fb441c3bed5cda4335404b5f289f7003" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/validator/zipball/96bbfd5534d2e07ba45255bad27ee90d3bc121a3", - "reference": "96bbfd5534d2e07ba45255bad27ee90d3bc121a3", + "url": "https://api.github.com/repos/symfony/validator/zipball/131ae089fb441c3bed5cda4335404b5f289f7003", + "reference": "131ae089fb441c3bed5cda4335404b5f289f7003", "shasum": "" }, "require": { @@ -3029,24 +3421,24 @@ ], "description": "Symfony Validator Component", "homepage": "https://symfony.com", - "time": "2018-05-07 06:57:27" + "time": "2018-08-05 14:25:16" }, { "name": "symfony/yaml", - "version": "v3.4.11", + "version": "v4.1.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "c5010cc1692ce1fa328b1fb666961eb3d4a85bb0" + "reference": "b832cc289608b6d305f62149df91529a2ab3c314" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/c5010cc1692ce1fa328b1fb666961eb3d4a85bb0", - "reference": "c5010cc1692ce1fa328b1fb666961eb3d4a85bb0", + "url": "https://api.github.com/repos/symfony/yaml/zipball/b832cc289608b6d305f62149df91529a2ab3c314", + "reference": "b832cc289608b6d305f62149df91529a2ab3c314", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8", + "php": "^7.1.3", "symfony/polyfill-ctype": "~1.8" }, "conflict": { @@ -3061,7 +3453,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.4-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -3088,7 +3480,114 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-05-03 23:18:14" + "time": "2018-08-18 16:52:46" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2017-04-07 12:08:54" + }, + { + "name": "twig/twig", + "version": "v2.5.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "6a5f676b77a90823c2d4eaf76137b771adf31323" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/6a5f676b77a90823c2d4eaf76137b771adf31323", + "reference": "6a5f676b77a90823c2d4eaf76137b771adf31323", + "shasum": "" + }, + "require": { + "php": "^7.0", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "psr/container": "^1.0", + "symfony/debug": "^2.7", + "symfony/phpunit-bridge": "^3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-0": { + "Twig_": "lib/" + }, + "psr-4": { + "Twig\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + }, + { + "name": "Twig Team", + "homepage": "https://twig.symfony.com/contributors", + "role": "Contributors" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "https://twig.symfony.com", + "keywords": [ + "templating" + ], + "time": "2018-07-13 07:18:09" }, { "name": "vlucas/phpdotenv", @@ -3185,11 +3684,47 @@ "validate" ], "time": "2018-01-29 19:49:41" + }, + { + "name": "zoujingli/wechat-php-sdk", + "version": "v1.3.16", + "source": { + "type": "git", + "url": "https://github.com/zoujingli/wechat-php-sdk.git", + "reference": "81bea8a9756dbf06b44dea29a1bb7925b8fea01b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zoujingli/wechat-php-sdk/zipball/81bea8a9756dbf06b44dea29a1bb7925b8fea01b", + "reference": "81bea8a9756dbf06b44dea29a1bb7925b8fea01b", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "project", + "autoload": { + "psr-4": { + "Wechat\\": "./Wechat" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WeChat development of SDK", + "homepage": "http://www.kancloud.cn/zoujingli/wechat-php-sdk", + "keywords": [ + "wechat-php-sdk" + ], + "time": "2018-07-10 08:48:24" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "opencart/opencart": 15 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 90272e8..2f79810 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,7 +6,7 @@ convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" - processIsolation="false" + processIsolation="true" stopOnFailure="false" syntaxCheck="false"> @@ -16,8 +16,13 @@ ./tests/admin/ + + ./tests/library/ + + + \ No newline at end of file diff --git a/src/upload/admin/controller/cron/icml.php b/src/upload/admin/controller/cron/icml.php new file mode 100644 index 0000000..7c0b745 --- /dev/null +++ b/src/upload/admin/controller/cron/icml.php @@ -0,0 +1,7 @@ +load->controller('extension/module/retailcrm/icml'); + } +} diff --git a/src/upload/admin/controller/extension/module/retailcrm.php b/src/upload/admin/controller/extension/module/retailcrm.php index 8a11213..e72bcd3 100644 --- a/src/upload/admin/controller/extension/module/retailcrm.php +++ b/src/upload/admin/controller/extension/module/retailcrm.php @@ -9,19 +9,7 @@ * @license https://opensource.org/licenses/MIT MIT License * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 */ -class ControllerExtensionModuleRetailcrm extends Controller -{ - private $_error = array(); - protected $log, $statuses, $payments, $deliveryTypes, $retailcrmApiClient, $moduleTitle, $tokenTitle; - public $children, $template; - - public function __construct($registry) - { - parent::__construct($registry); - $this->load->library('retailcrm/retailcrm'); - $this->moduleTitle = $this->retailcrm->getModuleTitle(); - $this->tokenTitle = $this->retailcrm->getTokenTitle(); - } +class ControllerExtensionModuleRetailcrm extends Controller { /** * Install method @@ -33,13 +21,14 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->load->model('setting/setting'); $this->model_setting_setting->editSetting( - $this->moduleTitle, + \Retailcrm\Retailcrm::MODULE, array( - $this->moduleTitle . '_status' => 1, - $this->moduleTitle . '_country' => array($this->config->get('config_country_id')) + \Retailcrm\Retailcrm::MODULE . '_status' => 1, + \Retailcrm\Retailcrm::MODULE . '_country' => array($this->config->get('config_country_id')) ) ); + $this->addCronJobs(); $this->addEvents(); } @@ -53,10 +42,11 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->uninstall_collector(); $this->load->model('setting/setting'); $this->model_setting_setting->editSetting( - $this->moduleTitle, - array($this->moduleTitle . '_status' => 0) + \Retailcrm\Retailcrm::MODULE, + array(\Retailcrm\Retailcrm::MODULE . '_status' => 0) ); $this->model_setting_setting->deleteSetting('retailcrm_history'); + $this->deleteCronJobs(); $this->deleteEvents(); } @@ -66,12 +56,14 @@ class ControllerExtensionModuleRetailcrm extends Controller * @return void */ public function install_collector() - { - $collector = $this->getCollectorTitle(); - $this->loadModels(); + { $this->load->model('setting/setting'); - $this->{'model_' . $this->modelExtension}->install('analytics', 'daemon_collector'); - $this->model_setting_setting->editSetting($collector, array($collector . '_status' => 1)); + $this->load->model('setting/extension'); + $this->model_setting_extension->install('analytics', 'daemon_collector'); + $this->model_setting_setting->editSetting( + 'analytics_daemon_collector', + array('analytics_daemon_collector_status' => 1) + ); } /** @@ -80,12 +72,14 @@ class ControllerExtensionModuleRetailcrm extends Controller * @return void */ public function uninstall_collector() - { - $collector = $this->getCollectorTitle(); - $this->loadModels(); + { $this->load->model('setting/setting'); - $this->model_setting_setting->editSetting($collector, array($collector . '_status' => 0)); - $this->{'model_' . $this->modelExtension}->uninstall('analytics', 'daemon_collector'); + $this->load->model('setting/extension'); + $this->model_setting_setting->editSetting( + 'analytics_daemon_collector', + array('analytics_daemon_collector_status' => 0) + ); + $this->model_setting_extension->uninstall('analytics', 'daemon_collector'); } /** @@ -95,7 +89,9 @@ class ControllerExtensionModuleRetailcrm extends Controller */ public function index() { - $this->loadModels(); + $this->load->library('retailcrm/retailcrm'); + $this->load->model('setting/extension'); + $this->load->model('setting/event'); $this->load->model('localisation/country'); $this->load->model('setting/setting'); $this->load->model('extension/retailcrm/references'); @@ -103,8 +99,9 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->document->setTitle($this->language->get('heading_title')); $this->document->addStyle('/admin/view/stylesheet/retailcrm.css'); - $collector = $this->getCollectorTitle(); $history_setting = $this->model_setting_setting->getSetting('retailcrm_history'); + $retailcrm_api_client = $this->retailcrm->getApiClient(); + $opencart_api_client = $this->retailcrm->getOcApiClient($this->registry); if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { if ($this->checkEvents() === false) { @@ -112,81 +109,49 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->addEvents(); } - $analytics = $this->{'model_' . $this->modelExtension}->getInstalled('analytics'); + $analytics = $this->model_setting_extension->getInstalled('analytics'); - if ($this->request->post[$this->moduleTitle . '_collector_active'] == 1 - && !in_array($collector, $analytics) + if ($this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector_active'] == 1 + && !in_array('analytics_daemon_collector', $analytics) ) { $this->install_collector(); - } elseif ($this->request->post[$this->moduleTitle . '_collector_active'] == 0 - && in_array($collector, $analytics) + } elseif ($this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector_active'] == 0 + && in_array('analytics_daemon_collector', $analytics) ) { $this->uninstall_collector(); } - if (parse_url($this->request->post[$this->moduleTitle . '_url'])) { - $crm_url = parse_url($this->request->post[$this->moduleTitle . '_url'], PHP_URL_HOST); - $this->request->post[$this->moduleTitle . '_url'] = 'https://' . $crm_url; + if (parse_url($this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'])) { + $crm_url = parse_url($this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'], PHP_URL_HOST); + $this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'] = 'https://' . $crm_url; } - if (isset($this->request->post[$this->moduleTitle . '_custom_field_active']) - && $this->request->post[$this->moduleTitle . '_custom_field_active'] == 0 + if (isset($this->request->post[\Retailcrm\Retailcrm::MODULE . '_custom_field_active']) + && $this->request->post[\Retailcrm\Retailcrm::MODULE . '_custom_field_active'] == 0 ) { - unset($this->request->post[$this->moduleTitle . '_custom_field']); + unset($this->request->post[\Retailcrm\Retailcrm::MODULE . '_custom_field']); } $this->model_setting_setting->editSetting( - $this->moduleTitle, + \Retailcrm\Retailcrm::MODULE, $this->request->post ); - if ($this->request->post[$this->moduleTitle . '_apiversion'] != 'v3') { - if (!isset($history_setting['retailcrm_history_orders']) && !isset($history_setting['retailcrm_history_customers'])) { - $api = $this->retailcrm->getApiClient( - $this->request->post[$this->moduleTitle . '_url'], - $this->request->post[$this->moduleTitle . '_apikey'], - $this->request->post[$this->moduleTitle . '_apiversion'] - ); + if (!isset($history_setting['retailcrm_history_orders']) + && !isset($history_setting['retailcrm_history_customers']) + ) { + $api = $this->retailcrm->getApiClient( + $this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'], + $this->request->post[\Retailcrm\Retailcrm::MODULE . '_apikey'], + $this->request->post[\Retailcrm\Retailcrm::MODULE . '_apiversion'] + ); - $ordersHistory = $api->ordersHistory(); - - if ($ordersHistory->isSuccessful() && !empty($ordersHistory['history'])) { - $ordersHistory = $api->ordersHistory(array(), $ordersHistory['pagination']['totalPageCount']); - - if ($ordersHistory->isSuccessful()) { - $ordersHistoryArr = $ordersHistory['history']; - $lastChangeOrders = end($ordersHistoryArr); - $sinceIdOrders = $lastChangeOrders['id']; - $generatedAt = $ordersHistory['generatedAt']; - } - } - - $customersHistory = $api->customersHistory(); - - if ($customersHistory->isSuccessful() && !empty($customersHistory['history'])) { - $customersHistory = $api->customersHistory(array(), $customersHistory['pagination']['totalPageCount']); - - if ($customersHistory->isSuccessful()) { - $customersHistoryArr = $customersHistory['history']; - $lastChangeCustomers = end($customersHistoryArr); - $sinceIdCustomers = $lastChangeCustomers['id']; - } - } - - $this->model_setting_setting->editSetting( - 'retailcrm_history', - array( - 'retailcrm_history_orders' => isset($sinceIdOrders) ? $sinceIdOrders : 1, - 'retailcrm_history_customers' => isset($sinceIdCustomers) ? $sinceIdCustomers : 1, - 'retailcrm_history_datetime' => isset($generatedAt) ? $generatedAt : date('Y-m-d H:i:s') - ) - ); - } + $this->getHistory($api); } $this->session->data['success'] = $this->language->get('text_success'); $redirect = $this->url->link( - 'extension/module/retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], + 'extension/module/retailcrm', 'user_token=' . $this->session->data['user_token'], 'SSL' ); @@ -251,51 +216,39 @@ class ControllerExtensionModuleRetailcrm extends Controller 'special_price_settings', 'special_price', 'order_number', - 'text_order_number' + 'text_order_number', + 'debug', + 'text_debug' ); - $_data = &$data; - foreach ($text_strings as $text) { $_data[$text] = $this->language->get($text); } $_data['retailcrm_errors'] = array(); $_data['saved_settings'] = $this->model_setting_setting - ->getSetting($this->moduleTitle); + ->getSetting(\Retailcrm\Retailcrm::MODULE); - $url = isset($_data['saved_settings'][$this->moduleTitle . '_url']) - ? $_data['saved_settings'][$this->moduleTitle . '_url'] + $url = isset($_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_url']) + ? $_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_url'] : null; - $key = isset($_data['saved_settings'][$this->moduleTitle . '_apikey']) - ? $_data['saved_settings'][$this->moduleTitle . '_apikey'] - : null; - $apiVersion = isset($_data['saved_settings'][$this->moduleTitle . '_apiversion']) - ? $_data['saved_settings'][$this->moduleTitle . '_apiversion'] + $key = isset($_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey']) + ? $_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey'] : null; if (!empty($url) && !empty($key)) { - $_data['delivery'] = $this->model_extension_retailcrm_references - ->getDeliveryTypes(); + ->getDeliveryTypes($opencart_api_client ,$retailcrm_api_client); $_data['statuses'] = $this->model_extension_retailcrm_references - ->getOrderStatuses(); + ->getOrderStatuses($retailcrm_api_client); $_data['payments'] = $this->model_extension_retailcrm_references - ->getPaymentTypes(); - - if ($apiVersion == 'v5') { - $_data['customFields'] = $this->model_extension_retailcrm_references - ->getCustomFields(); - } - - if ($apiVersion != 'v3') { - $_data['priceTypes'] = $this->model_extension_retailcrm_references - ->getPriceTypes(); - } + ->getPaymentTypes($retailcrm_api_client); + $_data['customFields'] = $this->model_extension_retailcrm_references + ->getCustomFields($retailcrm_api_client); } $config_data = array( - $this->moduleTitle . '_status' + \Retailcrm\Retailcrm::MODULE . '_status' ); foreach ($config_data as $conf) { @@ -318,7 +271,7 @@ class ControllerExtensionModuleRetailcrm extends Controller 'text' => $this->language->get('text_home'), 'href' => $this->url->link( 'common/dashboard', - $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL' + 'user_token' . '=' . $this->session->data['user_token'], 'SSL' ), 'separator' => false ); @@ -327,7 +280,7 @@ class ControllerExtensionModuleRetailcrm extends Controller 'text' => $this->language->get('text_module'), 'href' => $this->url->link( 'extension/extension', - $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL' + 'user_token' . '=' . $this->session->data['user_token'], 'SSL' ), 'separator' => ' :: ' ); @@ -336,19 +289,19 @@ class ControllerExtensionModuleRetailcrm extends Controller 'text' => $this->language->get('retailcrm_title'), 'href' => $this->url->link( 'extension/module/retailcrm', - $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL' + 'user_token' . '=' . $this->session->data['user_token'], 'SSL' ), 'separator' => ' :: ' ); $_data['action'] = $this->url->link( 'extension/module/retailcrm', - $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL' + 'user_token' . '=' . $this->session->data['user_token'], 'SSL' ); $_data['cancel'] = $this->url->link( - version_compare(VERSION, '3.0', '<') ? 'extension/extension' : 'marketplace/extension', - $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], 'SSL' + 'marketplace/extension', + 'user_token' . '=' . $this->session->data['user_token'], 'SSL' ); $_data['modules'] = array(); @@ -361,13 +314,12 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->load->model('design/layout'); $_data['layouts'] = $this->model_design_layout->getLayouts(); - $_data['header'] = $this->load->controller('common/header'); $_data['column_left'] = $this->load->controller('common/column_left'); $_data['footer'] = $this->load->controller('common/footer'); $_data['countries'] = $this->model_localisation_country->getCountries(); $_data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; - $_data[$this->tokenTitle] = $this->request->get[$this->tokenTitle]; + $_data['user_token'] = $this->request->get['user_token']; if(file_exists(DIR_SYSTEM . '/cron/export_done')) { $_data['export_file'] = false; @@ -382,11 +334,15 @@ class ControllerExtensionModuleRetailcrm extends Controller ); $_data['collectorFields'] = $collectorFields; - $_data['api_versions'] = array('v3', 'v4', 'v5'); - $_data['default_apiversion'] = 'v4'; + $_data['api_versions'] = array('v5'); + $_data['default_apiversion'] = 'v5'; - $retailcrmLog = file_exists(DIR_SYSTEM . 'storage/logs/retailcrm.log') ? DIR_SYSTEM . 'storage/logs/retailcrm.log' : false; - $ocApiLog = file_exists(DIR_SYSTEM . 'storage/logs/opencartapi.log') ? DIR_SYSTEM . 'storage/logs/opencartapi.log' : false; + $retailcrmLog = file_exists(DIR_SYSTEM . 'storage/logs/retailcrm.log') + ? DIR_SYSTEM . 'storage/logs/retailcrm.log' + : false; + $ocApiLog = file_exists(DIR_SYSTEM . 'storage/logs/opencartapi.log') + ? DIR_SYSTEM . 'storage/logs/opencartapi.log' + : false; if ($this->checkLogFile($retailcrmLog) !== false) { $_data['logs']['retailcrm_log'] = $this->checkLogFile($retailcrmLog); @@ -400,8 +356,8 @@ class ControllerExtensionModuleRetailcrm extends Controller $_data['logs']['oc_error'] = $this->language->get('text_error_log'); } - $_data['clear_retailcrm'] = $this->url->link('extension/module/retailcrm/clear_retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], true); - $_data['clear_opencart'] = $this->url->link('extension/module/retailcrm/clear_opencart', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], true); + $_data['clear_retailcrm'] = $this->url->link('extension/module/retailcrm/clear_retailcrm', 'user_token' . '=' . $this->session->data['user_token'], true); + $_data['clear_opencart'] = $this->url->link('extension/module/retailcrm/clear_opencart', 'user_token' . '=' . $this->session->data['user_token'], true); $_data['button_clear'] = $this->language->get('button_clear'); $this->response->setOutput( @@ -417,25 +373,14 @@ class ControllerExtensionModuleRetailcrm extends Controller */ public function history() { - $this->load->model('setting/setting'); - $settings = $this->model_setting_setting->getSetting($this->moduleTitle); + $this->load->library('retailcrm/retailcrm'); - if ($settings[$this->moduleTitle . '_apiversion'] == 'v3') { - if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/history/v3.php')) { - $this->load->model('extension/retailcrm/custom/history/v3'); - $this->model_extension_retailcrm_custom_history_v3->request($this->retailcrm->getApiClient()); - } else { - $this->load->model('extension/retailcrm/history/v3'); - $this->model_extension_retailcrm_history_v3->request($this->retailcrm->getApiClient()); - } + if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/history.php')) { + $this->load->model('extension/retailcrm/custom/history'); + $this->model_extension_retailcrm_custom_history->request($this->retailcrm->getApiClient()); } else { - if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/history/v4-5.php')) { - $this->load->model('extension/retailcrm/custom/history/v4-5'); - $this->model_extension_retailcrm_custom_history_v4_5->request($this->retailcrm->getApiClient()); - } else { - $this->load->model('extension/retailcrm/history/v4_5'); - $this->model_extension_retailcrm_history_v4_5->request($this->retailcrm->getApiClient()); - } + $this->load->model('extension/retailcrm/history'); + $this->model_extension_retailcrm_history->request($this->retailcrm->getApiClient()); } } @@ -446,6 +391,8 @@ class ControllerExtensionModuleRetailcrm extends Controller */ public function icml() { + $this->load->library('retailcrm/retailcrm'); + if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/icml.php')) { $this->load->model('extension/retailcrm/custom/icml'); $this->model_extension_retailcrm_custom_icml->generateICML(); @@ -463,8 +410,8 @@ class ControllerExtensionModuleRetailcrm extends Controller * * @return void */ - public function customer_edit($route, $customer) - { + public function customerEdit($route, $customer) + { $this->load->model('localisation/country'); $this->load->model('localisation/zone'); $this->load->model('customer/customer'); @@ -487,7 +434,7 @@ class ControllerExtensionModuleRetailcrm extends Controller 'postcode' => $address['postcode'], 'iso_code_2' => $country['iso_code_2'], 'zone' => $zone['name'] - ); + ); } $this->load->model('extension/retailcrm/customer'); @@ -504,23 +451,18 @@ class ControllerExtensionModuleRetailcrm extends Controller $order_id = isset($this->request->get['order_id']) ? $this->request->get['order_id'] : ''; $this->load->model('sale/order'); - $data = $this->model_sale_order->getOrder($order_id); - $data['products'] = $this->model_sale_order->getOrderProducts($order_id); - $data['totals'] = $this->model_sale_order->getOrderTotals($order_id); + $order = $this->model_sale_order->getOrder($order_id); + $order['products'] = $this->model_sale_order->getOrderProducts($order_id); + $order['totals'] = $this->model_sale_order->getOrderTotals($order_id); - foreach ($data['products'] as $key => $product) { - $data['products'][$key]['option'] = $this->model_sale_order->getOrderOptions($product['order_id'], $product['order_product_id']); + foreach ($order['products'] as $key => $product) { + $order['products'][$key]['option'] = $this->model_sale_order->getOrderOptions($product['order_id'], $product['order_product_id']); } - if (!isset($data['fromApi'])) { - $this->load->model('setting/setting'); - $status = $this->model_setting_setting->getSetting($this->moduleTitle); - $data['order_status'] = $status[$this->moduleTitle . '_status'][$data['order_status_id']]; - - $this->load->model('extension/retailcrm/order'); - $this->model_extension_retailcrm_order->uploadOrder($data, $this->retailcrm->getApiClient()); - $response = ModelExtensionRetailcrmOrder::getLastResponse(); - } + $this->load->library('retailcrm/retailcrm'); + $retailcrm_order = $this->retailcrm->createObject(\Retailcrm\Order::class); + $retailcrm_order->prepare($order); + $response = $retailcrm_order->create($this->retailcrm->getApiClient()); if (!$response->isSuccessful()) { if (isset($response['errors'])) { @@ -556,14 +498,17 @@ class ControllerExtensionModuleRetailcrm extends Controller public function export() { $this->load->model('customer/customer'); - $this->load->model('extension/retailcrm/customer'); - $this->load->model('extension/retailcrm/order'); $this->load->model('sale/order'); + $this->load->library('retailcrm/retailcrm'); + + $retailcrm_api_client = $this->retailcrm->getApiClient(); + $retailcrm_customer = $this->retailcrm->createObject(\Retailcrm\Customer::class); + $retailcrm_order = $this->retailcrm->createObject(\Retailcrm\Order::class); $customers = $this->model_customer_customer->getCustomers(); - $this->model_extension_retailcrm_customer->uploadToCrm($customers, $this->retailcrm->getApiClient()); - $orders = $this->model_sale_order->getOrders(); + $retailcrm_customer->upload($retailcrm_api_client, $customers, 'customers'); + $orders = $this->model_sale_order->getOrders(); $fullOrders = array(); foreach ($orders as $order) { @@ -572,15 +517,14 @@ class ControllerExtensionModuleRetailcrm extends Controller $fullOrder['totals'] = $this->model_sale_order->getOrderTotals($order['order_id']); $fullOrder['products'] = $this->model_sale_order->getOrderProducts($order['order_id']); - foreach($fullOrder['products'] as $key => $product) { + foreach ($fullOrder['products'] as $key => $product) { $fullOrder['products'][$key]['option'] = $this->model_sale_order->getOrderOptions($product['order_id'], $product['order_product_id']); } $fullOrders[] = $fullOrder; } - $this->model_extension_retailcrm_order->uploadToCrm($fullOrders, $this->retailcrm->getApiClient()); - fopen(DIR_SYSTEM . '/cron/export_done', "x"); + $retailcrm_order->upload($retailcrm_api_client, $fullOrders); } /** @@ -591,14 +535,23 @@ class ControllerExtensionModuleRetailcrm extends Controller public function prices() { $this->load->model('catalog/product'); + $this->load->library('retailcrm/retailcrm'); $products = $this->model_catalog_product->getProducts(); if (file_exists(DIR_APPLICATION . 'model/extension/retailcrm/custom/prices.php')) { $this->load->model('extension/retailcrm/custom/prices'); - $this->model_extension_retailcrm_custom_prices->uploadPrices($products, $this->retailcrm->getApiClient()); + $this->model_extension_retailcrm_custom_prices->uploadPrices( + $products, + $this->retailcrm->getApiClient(), + $this->retailcrm + ); } else { $this->load->model('extension/retailcrm/prices'); - $this->model_extension_retailcrm_prices->uploadPrices($products, $this->retailcrm->getApiClient()); + $this->model_extension_retailcrm_prices->uploadPrices( + $products, + $this->retailcrm->getApiClient(), + $this->retailcrm + ); } } @@ -610,22 +563,20 @@ class ControllerExtensionModuleRetailcrm extends Controller private function validate() { $versionsMap = array( - 'v3' => '3.0', - 'v4' => '4.0', 'v5' => '5.0' ); - if (!empty($this->request->post[$this->moduleTitle . '_url']) && !empty($this->request->post[$this->moduleTitle . '_apikey'])) { + if (!empty($this->request->post[\Retailcrm\Retailcrm::MODULE . '_url']) && !empty($this->request->post[\Retailcrm\Retailcrm::MODULE . '_apikey'])) { $apiClient = $this->retailcrm->getApiClient( - $this->request->post[$this->moduleTitle . '_url'], - $this->request->post[$this->moduleTitle . '_apikey'] + $this->request->post[\Retailcrm\Retailcrm::MODULE . '_url'], + $this->request->post[\Retailcrm\Retailcrm::MODULE . '_apikey'] ); } - $response = $apiClient->apiVersions(); + $response = isset($apiClient) ? $apiClient->apiVersions() : false; if ($response && $response->isSuccessful()) { - if (!in_array($versionsMap[$this->request->post[$this->moduleTitle . '_apiversion']], $response['versions'])) { + if (!in_array($versionsMap[$this->request->post[\Retailcrm\Retailcrm::MODULE . '_apiversion']], $response['versions'])) { $this->_error['warning'] = $this->language->get('text_error_api'); } } else { @@ -636,9 +587,9 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->_error['warning'] = $this->language->get('error_permission'); } - if (isset($this->request->post[$this->moduleTitle . '_collector']['custom']) && - $this->request->post[$this->moduleTitle . '_collector']['custom_form'] == 1) { - $customField = $this->request->post[$this->moduleTitle . '_collector']['custom']; + if (isset($this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector']['custom']) && + $this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector']['custom_form'] == 1) { + $customField = $this->request->post[\Retailcrm\Retailcrm::MODULE . '_collector']['custom']; if (empty($customField['name']) && empty($customField['email']) && empty($customField['phone'])) { $this->_error['fields'] = $this->language->get('text_error_collector_fields'); @@ -654,7 +605,7 @@ class ControllerExtensionModuleRetailcrm extends Controller /** * Clear retailcrm log file - * + * * @return void */ public function clear_retailcrm() @@ -667,12 +618,18 @@ class ControllerExtensionModuleRetailcrm extends Controller fclose($handle); } - $this->response->redirect($this->url->link('extension/module/retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], true)); + $this->response->redirect( + $this->url->link( + 'extension/module/retailcrm', + 'user_token' . '=' . $this->session->data['user_token'], + true + ) + ); } /** * Clear opencart API log file - * + * * @return void */ public function clear_opencart() @@ -685,54 +642,18 @@ class ControllerExtensionModuleRetailcrm extends Controller fclose($handle); } - $this->response->redirect($this->url->link('extension/module/retailcrm', $this->tokenTitle . '=' . $this->session->data[$this->tokenTitle], true)); - } - - /** - * Method for load models - * - * @return void - */ - private function loadModels() - { - if (version_compare(VERSION, '3.0', '<')) { - $this->load->model('extension/event'); - $this->load->model('extension/extension'); - // $this->load->model('extension/module'); - - $this->modelEvent = 'extension_event'; - $this->modelExtension = 'extension_extension'; - // $this->modelModule = 'extension_module'; - } else { - $this->load->model('setting/event'); - $this->load->model('setting/extension'); - // $this->load->model('setting/module'); - - $this->modelEvent = 'setting_event'; - $this->modelExtension = 'setting_extension'; - // $this->modelModule = 'setting_module'; - } - } - - /** - * Get collector module name - * - * @return string - */ - private function getCollectorTitle() - { - if (version_compare(VERSION, '3.0', '<')) { - $title = 'daemon_collector'; - } else { - $title = 'analytics_daemon_collector'; - } - - return $title; + $this->response->redirect( + $this->url->link( + 'extension/module/retailcrm', + 'user_token' . '=' . $this->session->data['user_token'], + true + ) + ); } /** * Check file size - * + * * @return string */ private function checkLogFile($file) @@ -754,67 +675,65 @@ class ControllerExtensionModuleRetailcrm extends Controller /** * Add events to db - * + * * @return void */ private function addEvents() { - $this->loadModels(); - - $this->{'model_' . $this->modelEvent} + $this->model_setting_event ->addEvent( - $this->moduleTitle, + \Retailcrm\Retailcrm::MODULE, 'catalog/model/checkout/order/addOrder/after', - 'extension/module/retailcrm/order_create' + 'extension/module/retailcrm/orderCreate' ); - $this->{'model_' . $this->modelEvent} + $this->model_setting_event ->addEvent( - $this->moduleTitle, - 'catalog/model/checkout/order/addOrderHistory/after', - 'extension/module/retailcrm/order_edit' + \Retailcrm\Retailcrm::MODULE, + 'catalog/model/checkout/order/editOrder/after', + 'extension/module/retailcrm/orderEdit' ); - $this->{'model_' . $this->modelEvent} + $this->model_setting_event ->addEvent( - $this->moduleTitle, + \Retailcrm\Retailcrm::MODULE, 'catalog/model/account/customer/addCustomer/after', - 'extension/module/retailcrm/customer_create' + 'extension/module/retailcrm/customerCreate' ); - $this->{'model_' . $this->modelEvent} + $this->model_setting_event ->addEvent( - $this->moduleTitle, + \Retailcrm\Retailcrm::MODULE, 'catalog/model/account/customer/editCustomer/after', - 'extension/module/retailcrm/customer_edit' + 'extension/module/retailcrm/customerEdit' ); - $this->{'model_' . $this->modelEvent} + $this->model_setting_event ->addEvent( - $this->moduleTitle, + \Retailcrm\Retailcrm::MODULE, 'catalog/model/account/address/editAddress/after', - 'extension/module/retailcrm/customer_edit' + 'extension/module/retailcrm/customerEdit' ); - $this->{'model_' . $this->modelEvent} + $this->model_setting_event ->addEvent( - $this->moduleTitle, + \Retailcrm\Retailcrm::MODULE, 'admin/model/customer/customer/editCustomer/after', - 'extension/module/retailcrm/customer_edit' + 'extension/module/retailcrm/customerEdit' ); } /** * Check events in db - * + * * @return boolean */ private function checkEvents() { - $events = $this->{'model_' . $this->modelEvent}->getEvent( - $this->moduleTitle, + $events = $this->model_setting_event->getEvent( + \Retailcrm\Retailcrm::MODULE, 'catalog/model/checkout/order/addOrder/after', - 'extension/module/retailcrm/order_create' + 'extension/module/retailcrm/orderCreate' ); if (!empty($events)) { @@ -826,17 +745,72 @@ class ControllerExtensionModuleRetailcrm extends Controller /** * Delete events from db - * + * * @return void */ private function deleteEvents() { - $this->loadModels(); + $this->model_setting_event->deleteEventByCode(\Retailcrm\Retailcrm::MODULE); + } - if (version_compare(VERSION, '3.0', '<')) { - $this->{'model_' . $this->modelEvent}->deleteEvent($this->moduleTitle); - } else { - $this->{'model_' . $this->modelEvent}->deleteEventByCode($this->moduleTitle); + /** + * Getting history for first setting save + * + * @param $apiClient + * + * @return void + */ + private function getHistory($apiClient) + { + $ordersHistoryBegin = $apiClient->ordersHistory(); + + if ($ordersHistoryBegin->isSuccessful() && !empty($ordersHistoryBegin['history'])) { + $ordersHistoryEnd = $apiClient->ordersHistory(array(), + $ordersHistoryBegin['pagination']['totalPageCount'] + ); + + if ($ordersHistoryEnd->isSuccessful()) { + $ordersHistoryArr = $ordersHistoryEnd['history']; + $lastChangeOrders = end($ordersHistoryArr); + $sinceIdOrders = $lastChangeOrders['id']; + $generatedAt = $ordersHistoryEnd['generatedAt']; + } } + + $customersHistoryBegin = $apiClient->customersHistory(); + + if ($customersHistoryBegin->isSuccessful() && !empty($customersHistoryBegin['history'])) { + $customersHistoryEnd = $apiClient->customersHistory( + array(), + $customersHistoryBegin['pagination']['totalPageCount'] + ); + + if ($customersHistoryEnd->isSuccessful()) { + $customersHistoryArr = $customersHistoryEnd['history']; + $lastChangeCustomers = end($customersHistoryArr); + $sinceIdCustomers = $lastChangeCustomers['id']; + } + } + + $this->model_setting_setting->editSetting( + 'retailcrm_history', + array( + 'retailcrm_history_orders' => isset($sinceIdOrders) ? $sinceIdOrders : 1, + 'retailcrm_history_customers' => isset($sinceIdCustomers) ? $sinceIdCustomers : 1, + 'retailcrm_history_datetime' => isset($generatedAt) ? $generatedAt : date('Y-m-d H:i:s') + ) + ); + } + + private function addCronJobs() { + $this->load->model('setting/cron'); + $this->model_setting_cron->addCron('icml', 'day', 'cron/icml', 1); + $this->model_setting_cron->addCron('prices', 'day', 'cron/icml', 0); + } + + private function deleteCronJobs() { + $this->load->model('setting/cron'); + $this->model_setting_cron->deleteCronByCode('icml'); + $this->model_setting_cron->deleteCronByCode('prices'); } } diff --git a/src/upload/admin/language/en-gb/extension/module/retailcrm.php b/src/upload/admin/language/en-gb/extension/module/retailcrm.php index 35d0ba7..597e11b 100644 --- a/src/upload/admin/language/en-gb/extension/module/retailcrm.php +++ b/src/upload/admin/language/en-gb/extension/module/retailcrm.php @@ -26,6 +26,7 @@ $_['collector_site_key'] = 'Site key'; $_['special_price_settings'] = 'Setting of uploading promotion price'; $_['special_price'] = 'Price type to which the promotion price will be uploaded'; + $_['text_success_export'] = 'Orders and customers are uploaded successfully'; $_['text_success_export_order'] = 'Order is uploaded successfully'; $_['text_button_export'] = 'Upload all orders and customers'; @@ -69,6 +70,9 @@ $_['retailcrm_missing_status'] = 'Status of lost orders'; $_['order_number'] = 'Order number'; $_['text_order_number'] = 'Upload the order number to retailCRM'; +$_['debug'] = 'Debug mode'; +$_['text_debug'] = 'Enable debug mode'; + $_['column_total'] = 'Total'; $_['product_summ'] = 'Sum'; diff --git a/src/upload/admin/language/ru-ru/extension/module/retailcrm.php b/src/upload/admin/language/ru-ru/extension/module/retailcrm.php index cbfd9ee..8556707 100644 --- a/src/upload/admin/language/ru-ru/extension/module/retailcrm.php +++ b/src/upload/admin/language/ru-ru/extension/module/retailcrm.php @@ -24,7 +24,7 @@ $_['retailcrm_url'] = 'Адрес RetailCRM'; $_['retailcrm_apikey'] = 'Api ключ RetailCRM'; $_['collector_site_key'] = 'Ключ сайта'; $_['special_price_settings'] = 'Настройка выгрузки акционной цены'; -$_['special_price'] = 'Тип цены, в который будет выгружаться цена по акции'; +$_['special_price'] = 'Тип цены, в который будет выгружаться цена по акции'; $_['text_success_export'] = 'Заказы и клиенты успешно выгружены'; $_['text_success_export_order'] = 'Заказ успешно выгружен'; @@ -56,7 +56,7 @@ $_['text_error_cf_opencart'] = 'Отсутствуют пользовате $_['text_error_cf_retailcrm'] = 'Отсутствуют пользовательские поля в RetailCRM'; $_['text_error_save'] = 'Ошибка сохранения настроек'; $_['text_error_log'] = 'Размер лога более 2MB'; -$_['text_error_delivery'] = 'Не найдены типы доставки'; +$_['text_error_delivery'] = 'Не найдены типы доставки'; $_['text_confirm_log'] = 'Вы уверены, что хотите очистить лог?'; $_['retailcrm_dict_delivery'] = 'Способы доставки'; @@ -69,6 +69,9 @@ $_['retailcrm_missing_status'] = 'Статус пропавших заказо $_['order_number'] = 'Номер заказа'; $_['text_order_number'] = 'Передавать номер заказа в retailCRM'; +$_['debug'] = 'Debug режим'; +$_['text_debug'] = 'Включить подробное логирование'; + $_['column_total'] = 'Итого'; $_['product_summ'] = 'Сумма'; diff --git a/src/upload/admin/model/extension/retailcrm/customer.php b/src/upload/admin/model/extension/retailcrm/customer.php deleted file mode 100644 index 1702e9a..0000000 --- a/src/upload/admin/model/extension/retailcrm/customer.php +++ /dev/null @@ -1,137 +0,0 @@ -load->model('setting/setting'); - $this->load->library('retailcrm/retailcrm'); - - $this->moduleTitle = $this->retailcrm->getModuleTitle(); - $this->settings = $this->model_setting_setting->getSetting($this->moduleTitle); - } - - /** - * Upload customers - * - * @param array $customers - * @param \RetailcrmProxy $retailcrmApiClient - * - * @return mixed - */ - public function uploadToCrm($customers, $retailcrmApiClient) - { - if ($retailcrmApiClient === false || empty($customers)) { - return false; - } - - $customersToCrm = array(); - - foreach($customers as $customer) { - $customersToCrm[] = $this->process($customer); - } - - $chunkedCustomers = array_chunk($customersToCrm, 50); - - foreach($chunkedCustomers as $customersPart) { - $retailcrmApiClient->customersUpload($customersPart); - } - - return $chunkedCustomers; - } - - /** - * Edit customer - * - * @param array $customer - * @param \RetailcrmProxy $retailcrmApiClient - * - * @return mixed - */ - public function changeInCrm($customer, $retailcrmApiClient) - { - if ($retailcrmApiClient === false || empty($customer)) { - return false; - } - - $customerToCrm = $this->process($customer); - - $retailcrmApiClient->customersEdit($customerToCrm); - - return $customerToCrm; - } - - /** - * Create customer - * - * @param array $customer - * @param \RetailcrmProxy $retailcrmApiClient - * - * @return mixed - */ - public function sendToCrm($customer, $retailcrmApiClient) - { - if ($retailcrmApiClient === false || empty($customer)) { - return false; - } - - $customerToCrm = $this->process($customer); - - $retailcrmApiClient->customersCreate($customerToCrm); - - return $customerToCrm; - } - - /** - * Process customer - * - * @param array $customer - * - * @return array $customerToCrm - */ - private function process($customer) - { - $customerToCrm = array( - 'externalId' => $customer['customer_id'], - 'firstName' => $customer['firstname'], - 'lastName' => $customer['lastname'], - 'email' => $customer['email'], - 'phones' => array( - array( - 'number' => $customer['telephone'] - ) - ), - 'createdAt' => $customer['date_added'] - ); - - if (isset($customer['address'])) { - $customerToCrm['address'] = array( - 'index' => $customer['address']['postcode'], - 'countryIso' => $customer['address']['iso_code_2'], - 'region' => $customer['address']['zone'], - 'city' => $customer['address']['city'], - 'text' => $customer['address']['address_1'] . ' ' . $customer['address']['address_2'] - ); - } - - if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $customer['custom_field']) { - $customFields = json_decode($customer['custom_field']); - - foreach ($customFields as $key => $value) { - if (isset($this->settings[$this->moduleTitle . '_custom_field']['c_' . $key])) { - $customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['c_' . $key]] = $value; - } - } - - if (isset($customFieldsToCrm)) { - $customerToCrm['customFields'] = $customFieldsToCrm; - } - } - - return $customerToCrm; - } -} diff --git a/src/upload/admin/model/extension/retailcrm/history.php b/src/upload/admin/model/extension/retailcrm/history.php index 7a46524..bd353b6 100644 --- a/src/upload/admin/model/extension/retailcrm/history.php +++ b/src/upload/admin/model/extension/retailcrm/history.php @@ -1,194 +1,825 @@ db->query("INSERT INTO `" . DB_PREFIX . "order` SET store_id = '" . (int)$order['store_id'] . "', store_name = '" . $order['store_name'] . "', customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(isset($order['custom_field']) ? json_encode($order['custom_field']) : '') . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', affiliate_id = '" . (int)$order['affiliate_id'] . "', language_id = '" . (int)$order['language_id'] . "', currency_id = '" . (int)$order['currency_id'] . "', currency_code = '" . $this->db->escape($order['currency_code']) . "', currency_value = '" . (float)$order['currency_value'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_added = NOW(), date_modified = NOW()"); - - $order_id = $this->db->getLastId(); - - // Products - if (isset($order['order_product']) && $order['order_product']) { - $this->addOrderProducts($order_id, $order['order_product']); - } - - // Totals - if (isset($order['order_total'])) { - $this->addOrderTotals($order_id, $order['order_total']); - } - - return $order_id; + parent::__construct($registry); + $this->load->library('retailcrm/retailcrm'); + $this->opencartApiClient = $this->retailcrm->getOcApiClient($registry); } /** - * Edit order in OC - * - * @param int $order_id - * @param array $order - * - * @return void + * Getting changes from RetailCRM + * @param \RetailcrmProxy $retailcrmApiClient + * + * @return boolean */ - public function editOrder($order_id, $order) + public function request($retailcrmApiClient) { - $this->db->query("UPDATE `" . DB_PREFIX . "order` SET customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(json_encode($order['custom_field'])) . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($order['payment_address_2']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'"); + $this->load->library('retailcrm/retailcrm'); + $this->load->model('setting/setting'); + $this->load->model('setting/store'); + $this->load->model('user/api'); + $this->load->model('sale/order'); + $this->load->model('customer/customer'); + $this->load->model('extension/retailcrm/references'); + $this->load->model('catalog/product'); + $this->load->model('catalog/option'); + $this->load->model('localisation/zone'); - $this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'"); + $this->load->language('extension/module/retailcrm'); - // Products - if (isset($order['order_product']) && $order['order_product']) { - $this->addOrderProducts($order_id, $order['order_product']); + $settings = $this->model_setting_setting->getSetting(\Retailcrm\Retailcrm::MODULE); + $history = $this->model_setting_setting->getSetting('retailcrm_history'); + $settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST); + + $url = isset($settings[\Retailcrm\Retailcrm::MODULE . '_url']) ? $settings[\Retailcrm\Retailcrm::MODULE . '_url'] : null; + $key = isset($settings[\Retailcrm\Retailcrm::MODULE . '_apikey']) ? $settings[\Retailcrm\Retailcrm::MODULE . '_apikey'] : null; + + if (empty($url) || empty($key)) { + $this->log->addNotice('You need to configure retailcrm module first.'); + return false; } - // Totals - $this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'"); + $sinceIdOrders = $history['retailcrm_history_orders'] ? $history['retailcrm_history_orders'] : null; + $sinceIdCustomers = $history['retailcrm_history_customers'] ? $history['retailcrm_history_customers'] : null; - if (isset($order['order_total'])) { - $this->addOrderTotals($order_id, $order['order_total']); + $packsOrders = $retailcrmApiClient->ordersHistory(array( + 'sinceId' => $sinceIdOrders ? $sinceIdOrders : 0 + ), 1, 100); + $packsCustomers = $retailcrmApiClient->customersHistory(array( + 'sinceId' => $sinceIdCustomers ? $sinceIdCustomers : 0 + ), 1, 100); + + if(!$packsOrders->isSuccessful() && count($packsOrders->history) <= 0 && !$packsCustomers->isSuccessful() && count($packsCustomers->history) <= 0) { + return false; } - } - /** - * Add order products - * - * @param int $order_id - * @param array $products - * - * @return void - */ - public function addOrderProducts($order_id, $products) - { - foreach ($products as $product) { - $this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', quantity = '" . (int)$product['quantity'] . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', reward = '" . (float)$product['reward'] . "'"); + $generatedAt = $packsOrders['generatedAt']; + $orders = RetailcrmHistoryHelper::assemblyOrder($packsOrders->history); + $customers = RetailcrmHistoryHelper::assemblyCustomer($packsCustomers->history); - $order_product_id = $this->db->getLastId(); + $ordersHistory = $packsOrders->history; + $customersHistory = $packsCustomers->history; - foreach ($product['option'] as $option) { - $this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_id = '" . (int)$option['product_option_id'] . "', product_option_value_id = '" . (int)$option['product_option_value_id'] . "', name = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', `type` = '" . $this->db->escape($option['type']) . "'"); + $lastChangeOrders = $ordersHistory ? end($ordersHistory) : null; + $lastChangeCustomers = $customersHistory ? end($customersHistory) : null; + + if ($lastChangeOrders !== null) { + $sinceIdOrders = $lastChangeOrders['id']; + } + + if ($lastChangeCustomers !== null) { + $sinceIdCustomers = $lastChangeCustomers['id']; + } + + $this->settings = $settings; + $this->totalTitle = $this->totalTitles(); + $this->subtotalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'sub_total'); + $this->totalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'total'); + $this->shippingSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'shipping'); + + $this->delivery = array_flip($settings[\Retailcrm\Retailcrm::MODULE . '_delivery']); + $this->payment = array_flip($settings[\Retailcrm\Retailcrm::MODULE . '_payment']); + $this->status = array_flip($settings[\Retailcrm\Retailcrm::MODULE . '_status']); + $this->delivery_default = $settings[\Retailcrm\Retailcrm::MODULE . '_default_shipping']; + $this->payment_default = $settings[\Retailcrm\Retailcrm::MODULE . '_default_payment']; + $this->ocPayment = $this->model_extension_retailcrm_references + ->getOpercartPaymentTypes(); + + $this->ocDelivery = $this->model_extension_retailcrm_references + ->getOpercartDeliveryTypes($this->opencartApiClient); + + $this->zones = $this->model_localisation_zone->getZones(); + + if (isset($settings[\Retailcrm\Retailcrm::MODULE . '_custom_field'])) { + $this->customFieldSetting = array_flip($settings[\Retailcrm\Retailcrm::MODULE . '_custom_field']); + } + + $updatedOrders = array(); + $newOrders = array(); + + foreach ($orders as $order) { + + if (isset($order['deleted'])) { + continue; + } + + if (isset($order['externalId'])) { + $updatedOrders[] = $order['id']; + } else { + $newOrders[] = $order['id']; } } + + unset($orders); + + $updateCustomers = array(); + + foreach ($customers as $customer) { + + if (isset($customer['deleted'])) { + continue; + } + + if (isset($customer['externalId'])) { + $updateCustomers[] = $customer['id']; + } + } + + unset($customers); + + if (!empty($updateCustomers)) { + $customers = $retailcrmApiClient->customersList($filter = array('ids' => $updateCustomers)); + if ($customers) { + $this->updateCustomers($customers['customers']); + } + } + + if (!empty($newOrders)) { + $orders = $retailcrmApiClient->ordersList($filter = array('ids' => $newOrders)); + if ($orders) { + $this->createResult = $this->createOrders($orders['orders']); + } + } + + if (!empty($updatedOrders)) { + $orders = $retailcrmApiClient->ordersList($filter = array('ids' => $updatedOrders)); + if ($orders) { + $this->updateOrders($orders['orders']); + } + } + + $this->model_setting_setting->editSetting( + 'retailcrm_history', + array( + 'retailcrm_history_orders' => $sinceIdOrders, + 'retailcrm_history_customers' => $sinceIdCustomers, + 'retailcrm_history_datetime' => $generatedAt + ) + ); + + if (!empty($this->createResult['customers'])) { + $retailcrmApiClient->customersFixExternalIds($this->createResult['customers']); + } + + if (!empty($this->createResult['orders'])) { + $retailcrmApiClient->ordersFixExternalIds($this->createResult['orders']); + } + + return true; } /** - * Add order totals - * - * @param int $order_id - * @param array $totals - * + * Update orders from history + * + * @param array $orders + * * @return void */ - public function addOrderTotals($order_id, $totals) + protected function updateOrders($orders) { - foreach ($totals as $total) { - $this->db->query("INSERT INTO " . DB_PREFIX . "order_total SET order_id = '" . (int)$order_id . "', code = '" . $this->db->escape($total['code']) . "', title = '" . $this->db->escape($total['title']) . "', `value` = '" . (float)$total['value'] . "', sort_order = '" . (int)$total['sort_order'] . "'"); + foreach ($orders as $order) { + $ocOrder = $this->model_sale_order->getOrder($order['externalId']); + + if (isset($order['payments']) && $order['payments']) { + foreach ($order['payments'] as $orderPayment) { + if (isset($orderPayment['externalId'])) { + $payment = $orderPayment; + } + } + + if (!isset($payment) && count($order['payments']) == 1) { + $payment = end($order['payments']); + } + } elseif (isset($order['paymentType'])) { + $payment['type'] = $order['paymentType']; + } + + $data = array(); + + $mail = isset($order['email']) ? $order['email'] : $order['customer']['email']; + $phone = isset($order['phone']) ? $order['phone'] : ''; + + if (!$phone) { + $data['telephone'] = $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : '80000000000'; + } else { + $data['telephone'] = $phone; + } + + if (isset($order['customer']['externalId']) && $order['customer']['externalId']) { + $customer = $this->model_customer_customer->getCustomer($order['customer']['externalId']); + } + + $data['customer'] = $order['firstName']; + $data['customer_id'] = (isset($customer)) ? $customer['customer_id'] : 0; + $data['customer_group_id'] = (isset($customer)) ? $customer['customer_group_id'] : 1; + $data['firstname'] = $order['firstName']; + $data['lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName']; + $data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru'; + $data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : ''; + $data['payment_address'] = '0'; + $data['payment_firstname'] = $order['firstName']; + $data['payment_lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName']; + $data['payment_address_1'] = isset($order['customer']['address']) ? $order['customer']['address']['text'] : ''; + $data['payment_address_2'] = ''; + $data['payment_city'] = !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city']; + $data['payment_postcode'] = !empty( $order['customer']['address']['index'] ) ? $order['customer']['address']['index'] : $order['delivery']['address']['index']; + + $shippingZone = ''; + + if (is_int($order['delivery']['address']['region'])) { + $shippingZone = $order['delivery']['address']['region']; + } else { + $shippingZone = $this->getZoneByName($order['delivery']['address']['region']); + + if ($shippingZone) { + $shipping_zone_id = $shippingZone['zone_id']; + } else { + $shipping_zone_id = 0; + } + } + + if (isset($order['customer']['address']['region'])) { + $paymentZone = $this->getZoneByName($order['customer']['address']['region']); + + if ($paymentZone) { + $payment_zone_id = $paymentZone['zone_id']; + } else { + $payment_zone_id = 0; + } + } + + if (isset($order['countryIso']) && !empty($order['countryIso'])) { + $shippingCountry = $this->getCountryByIsoCode($order['countryIso']); + } + + if (isset($order['customer']['address']['countryIso']) && !empty($order['customer']['address']['countryIso'])) { + $paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); + } else { + $paymentCountry = $this->getCountryByIsoCode($order['countryIso']); + } + + $delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null; + $data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : $ocOrder['payment_country_id']; + $data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : $ocOrder['payment_country']; + $data['payment_zone_id'] = $payment_zone_id ? $payment_zone_id : $ocOrder['payment_zone_id']; + $data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : $ocOrder['payment_zone']; + $data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : $ocOrder['shipping_country_id']; + $data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : $ocOrder['shipping_country']; + $data['shipping_zone_id'] = $shipping_zone_id ? $shipping_zone_id : $ocOrder['shipping_zone_id']; + $data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $ocOrder['shipping_zone']; + $data['shipping_address'] = '0'; + $data['shipping_firstname'] = $order['firstName']; + $data['shipping_lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName']; + $data['shipping_address_1'] = $order['delivery']['address']['text']; + $data['shipping_address_2'] = ''; + $data['shipping_company'] = ''; + $data['shipping_company_id'] = ''; + $data['shipping_city'] = $order['delivery']['address']['city']; + $data['shipping_postcode'] = $order['delivery']['address']['index']; + + if ($delivery !== null) { + if (isset($this->settings[\Retailcrm\Retailcrm::MODULE . '_delivery'][$ocOrder['shipping_code']]) + && isset($this->delivery[$delivery]) + ) { + $data['shipping'] = $this->delivery[$delivery]; + + $shipping = explode('.', $data['shipping']); + $shippingModule = $shipping[0]; + + if (isset($this->ocDelivery[$shippingModule][$data['shipping']]['title'])) { + $data['shipping_method'] = $this->ocDelivery[$shippingModule][$data['shipping']]['title']; + } else { + $data['shipping_method'] = $this->ocDelivery[$shippingModule]['title']; + } + + $data['shipping_code'] = $data['shipping']; + } elseif (!isset($this->settings[\Retailcrm\Retailcrm::MODULE . '_delivery'][$ocOrder['shipping_code']]) + ) { + $data['shipping_method'] = $ocOrder['shipping_method']; + $data['shipping_code'] = $ocOrder['shipping_code']; + } + } else { + if (!isset($this->settings[$ocOrder['shipping_code']]) + || !isset($this->delivery[$delivery]) + ) { + $data['shipping_method'] = $ocOrder['shipping_method']; + $data['shipping_code'] = $ocOrder['shipping_code']; + } + } + + if (isset($payment)) { + $data['payment'] = $this->payment[$payment['type']]; + $data['payment_method'] = isset($this->ocPayment[$data['payment']]) ? $this->ocPayment[$data['payment']] : $ocOrder['payment_method']; + $data['payment_code'] = isset($this->payment[$payment['type']]) ? $this->payment[$payment['type']] : $ocOrder['payment_code']; + } else { + $data['payment_method'] = $ocOrder['payment_method']; + $data['payment_code'] = $ocOrder['payment_code']; + } + + // this data will not retrive from crm for now + $data['tax'] = ''; + $data['tax_id'] = ''; + $data['product'] = ''; + $data['product_id'] = ''; + $data['reward'] = ''; + $data['affiliate'] = ''; + $data['affiliate_id'] = ''; + $data['payment_tax_id'] = ''; + $data['order_product_id'] = ''; + $data['payment_company'] = ''; + $data['payment_company_id'] = ''; + $data['company'] = ''; + $data['company_id'] = ''; + + $data['order_product'] = array(); + + $discount = false; + + foreach ($order['items'] as $item) { + $productId = $item['offer']['externalId']; + $options = array(); + + if (isset($item['discountTotal']) && $item['discountTotal'] > 0) { + $discount = true; + } + + if (mb_strpos($item['offer']['externalId'], '#') > 1) { + $offer = explode('#', $item['offer']['externalId']); + $productId = $offer[0]; + $optionsFromCRM = explode('_', $offer[1]); + + foreach ($optionsFromCRM as $optionFromCRM) { + $optionData = explode('-', $optionFromCRM); + $productOptionId = $optionData[0]; + $optionValueId = $optionData[1]; + + $productOptions = $this->model_catalog_product->getProductOptions($productId); + + foreach($productOptions as $productOption) { + if($productOptionId == $productOption['product_option_id']) { + foreach($productOption['product_option_value'] as $productOptionValue) { + if($productOptionValue['option_value_id'] == $optionValueId) { + $options[] = array( + 'product_option_id' => $productOptionId, + 'product_option_value_id' => $productOptionValue['product_option_value_id'], + 'value' => $this->getOptionValue($productOptionValue['option_value_id'], 'name'), + 'type' => $productOption['type'], + 'name' => $productOption['name'], + ); + } + } + } + } + } + } + + $product = $this->model_catalog_product->getProduct($productId); + $rewards = $this->model_catalog_product->getProductRewards($productId); + + $data['order_product'][] = array( + 'name' => $product['name'], + 'model' => $product['model'], + 'price' => $item['initialPrice'], + 'total' => (float)($item['initialPrice'] * $item['quantity']), + 'product_id' => $productId, + 'quantity' => $item['quantity'], + 'option' => $options, + 'reward' => $rewards[$data['customer_group_id']]['points'] * $item['quantity'] + ); + } + + if (isset($this->customFieldSetting) && $order['customFields']) { + foreach ($order['customFields'] as $code => $value) { + if (array_key_exists($code, $this->customFieldSetting)) { + $fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]); + $customFields[$fieldCode] = $value; + } + } + + $data['custom_field'] = isset($customFields) ? $customFields : ''; + } else { + $data['custom_field'] = $ocOrder['custom_field']; + } + + $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0; + + $data['total'] = $order['totalSumm']; + $data['order_total'] = array( + array( + 'order_total_id' => '', + 'code' => 'sub_total', + 'title' => $this->language->get('product_summ'), + 'value' => $order['summ'], + 'text' => $order['summ'], + 'sort_order' => $this->subtotalSettings['sub_total_sort_order'] + ), + array( + 'order_total_id' => '', + 'code' => 'shipping', + 'title' => $data['shipping_method'], + 'value' => $deliveryCost, + 'text' => $deliveryCost, + 'sort_order' => $this->shippingSettings[$this->totalTitle . 'shipping_sort_order'] + ), + array( + 'order_total_id' => '', + 'code' => 'total', + 'title' => $this->language->get('column_total'), + 'value' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost, + 'text' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost, + 'sort_order' => $this->totalSettings[$this->totalTitle . 'total_sort_order'] + ) + ); + + if ((isset($order['discount']) + && $order['discount'] > 0) + || $discount + ) { + $orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']); + foreach ($orderTotals as $orderTotal) { + if ($orderTotal['code'] == 'coupon' + || $orderTotal['code'] == 'reward' + ) { + $data['order_total'][] = $orderTotal; + } + } + } + + $data['fromApi'] = true; + + if (array_key_exists($order['status'], $this->status)) { + $data['order_status_id'] = $this->status[$order['status']]; + } else { + $tmpOrder = $this->model_sale_order->getOrder($order['externalId']); + $data['order_status_id'] = $tmpOrder['order_status_id']; + } + + $this->editOrder($order['externalId'], $data); + $this->opencartApiClient->addHistory($order['externalId'], $data['order_status_id']); } } /** - * Get total titles - * - * @return string $title - */ - protected function totalTitles() - { - if (version_compare(VERSION, '3.0', '<')) { - $title = ''; - } else { - $title = 'total_'; - } - - return $title; - } - - /** - * Get country by iso code 2 - * - * @param string $isoCode - * + * Create orders from history + * + * @param array $orders + * * @return array */ - public function getCountryByIsoCode($isoCode) + protected function createOrders($orders) { - $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE iso_code_2 = '" . $isoCode . "'"); - - return $query->row; - } + $customersIdsFix = array(); + $ordersIdsFix = array(); - /** - * Get zone by name - * - * @param string $name - * - * @return array - */ - public function getZoneByName($name) - { - $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE name = '" . $name . "'"); + foreach ($orders as $order) { + $store = $this->config->get('config_store_id'); - return $query->row; - } + if (isset($order['payments']) && $order['payments']) { + $payment = end($order['payments']); + } elseif (isset($order['paymentType'])) { + $payment['type'] = $order['paymentType']; + } - /** - * Get currency - * - * @param string $code - * @param string $field (default = '') - * - * @return mixed array | string - */ - public function getCurrencyByCode($code, $field = '') - { - $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "currency` WHERE code = '" . $code . "'"); + $customer_id = (!empty($order['customer']['externalId'])) + ? $order['customer']['externalId'] + : 0; - if (!$field) { - return $query->row; + $data = array(); + + if ($customer_id == 0) { + if (isset($order['customer']['address']['countryIso'])) { + $customerCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); + } else { + $customerCountry = $this->getCountryByIsoCode($order['delivery']['address']['countryIso']); + } + + if (isset($order['customer']['address']['region'])) { + $customerZone = $this->getZoneByName($order['customer']['address']['region']); + } else { + $customerZone = $this->getZoneByName($order['delivery']['address']['region']); + } + + $cData = array( + 'store_id' => 0, + 'customer_group_id' => '1', + 'firstname' => isset($order['patronymic']) ? $order['firstName'] . ' ' . $order['patronymic'] : $order['firstName'], + 'lastname' => (!empty($order['customer']['lastName'])) ? $order['customer']['lastName'] : ' ', + 'email' => $order['customer']['email'], + 'telephone' => $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : ' ', + 'fax' => '', + 'newsletter' => 0, + 'password' => 'tmppass', + 'status' => 1, + 'approved' => 1, + 'safe' => 0, + 'affiliate' => '', + 'address' => array( + array( + 'firstname' => isset($order['patronymic']) ? $order['firstName'] . ' ' . $order['patronymic'] : $order['firstName'], + 'lastname' => (!empty($order['customer']['lastName'])) ? $order['customer']['lastName'] : ' ', + 'address_1' => $order['customer']['address']['text'], + 'address_2' => ' ', + 'city' => !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city'], + 'postcode' => isset($order['customer']['address']['index']) ? $order['customer']['address']['index'] : $order['delivery']['address']['index'], + 'tax_id' => '1', + 'company' => '', + 'company_id' => '', + 'zone_id' => $customerZone ? $customerZone['zone_id'] : 0, + 'country_id' => $customerCountry ? $customerCountry['country_id'] : 0, + 'default' => '1' + ) + ), + ); + + $customer_id = $this->model_customer_customer->addCustomer($cData); + + $customersIdsFix[] = array('id' => $order['customer']['id'], 'externalId' => (int)$customer_id); + } + + $mail = isset($order['email']) ? $order['email'] : $order['customer']['email']; + $phone = isset($order['phone']) ? $order['phone'] : ''; + + if (!$phone) { + $data['telephone'] = $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : '80000000000'; + } else { + $data['telephone'] = $phone; + } + + $data['currency_code'] = $this->config->get('config_currency'); + $data['currency_value'] = $this->getCurrencyByCode($data['currency_code'], 'value'); + $data['currency_id'] = $this->getCurrencyByCode($data['currency_code'], 'currency_id'); + $data['language_id'] = $this->getLanguageByCode($this->config->get('config_language'), 'language_id'); + $data['store_id'] = $store == null ? 0 : $store; + $data['store_name'] = $this->config->get('config_name'); + $data['customer'] = $order['firstName']; + $data['customer_id'] = $customer_id; + $data['customer_group_id'] = 1; + $data['firstname'] = $order['firstName']; + $data['lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName']; + $data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru'; + $data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : ''; + $data['fax'] = ''; + $data['payment_address'] = '0'; + $data['payment_firstname'] = $order['firstName']; + $data['payment_lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName']; + $data['payment_address_1'] = $order['customer']['address']['text']; + $data['payment_address_2'] = ''; + $data['payment_company'] = ''; + $data['payment_company_id'] = ''; + $data['payment_city'] = !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city']; + $data['payment_postcode'] = !empty($order['customer']['address']['index']) ? $order['customer']['address']['index'] : $order['delivery']['address']['index']; + + $shippingZone = ''; + + if (!empty($order['delivery']['address']['region']) && is_int($order['delivery']['address']['region'])) { + $shippingZone = $order['delivery']['address']['region']; + } else { + $shippingZone = $this->getZoneByName($order['delivery']['address']['region']); + + if ($shippingZone) { + $shipping_zone_id = $shippingZone['zone_id']; + } else { + $shipping_zone_id = 0; + } + } + + if (isset($order['customer']['address']['region'])) { + $paymentZone = $this->getZoneByName($order['customer']['address']['region']); + + if ($paymentZone) { + $payment_zone_id = $paymentZone['zone_id']; + } else { + $payment_zone_id = 0; + } + } + + if (isset($order['countryIso'])) { + $shippingCountry = $this->getCountryByIsoCode($order['countryIso']); + } + + if (isset($order['customer']['address']['countryIso'])) { + $paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); + } + + $delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null; + $data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0; + $data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : ''; + $data['payment_zone_id'] = $payment_zone_id; + $data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : ''; + $data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : 0; + $data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : ''; + $data['shipping_zone_id'] = $shipping_zone_id; + $data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $data['payment_zone']; + $data['shipping_address'] = '0'; + $data['shipping_firstname'] = $order['firstName']; + $data['shipping_lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName']; + $data['shipping_address_1'] = $order['delivery']['address']['text']; + $data['shipping_address_2'] = ''; + $data['shipping_company'] = ''; + $data['shipping_company_id'] = ''; + $data['shipping_city'] = $order['delivery']['address']['city']; + $data['shipping_postcode'] = $order['delivery']['address']['index']; + $data['shipping'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; + $data['shipping_code'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; + + $shipping = explode('.', $data['shipping']); + $shippingModule = $shipping[0]; + + if (isset($this->ocDelivery[$shippingModule][$data['shipping']]['title'])) { + $data['shipping_method'] = $this->ocDelivery[$shippingModule][$data['shipping']]['title']; + } else { + $data['shipping_method'] = $this->ocDelivery[$shippingModule]['title']; + } + + if (isset($payment)) { + $data['payment'] = $this->payment[$payment['type']]; + $data['payment_method'] = $this->ocPayment[$data['payment']]; + $data['payment_code'] = $this->payment[$payment['type']]; + } else { + $data['payment'] = $this->payment_default; + $data['payment_method'] = $this->ocPayment[$data['payment']]; + $data['payment_code'] = $this->payment_default; + } + + // this data will not retrive from crm for now + $data['tax'] = ''; + $data['tax_id'] = ''; + $data['product'] = ''; + $data['product_id'] = ''; + $data['reward'] = ''; + $data['affiliate'] = ''; + $data['affiliate_id'] = 0; + $data['payment_tax_id'] = ''; + $data['order_product_id'] = ''; + $data['payment_company'] = ''; + $data['payment_company_id'] = ''; + $data['company'] = ''; + $data['company_id'] = ''; + + $data['order_product'] = array(); + + foreach ($order['items'] as $item) { + $productId = $item['offer']['externalId']; + $options = array(); + + if(mb_strpos($item['offer']['externalId'], '#') > 1) { + $offer = explode('#', $item['offer']['externalId']); + $productId = $offer[0]; + $optionsFromCRM = explode('_', $offer[1]); + + foreach ($optionsFromCRM as $optionFromCRM) { + $optionData = explode('-', $optionFromCRM); + $productOptionId = $optionData[0]; + $optionValueId = $optionData[1]; + + $productOptions = $this->model_catalog_product->getProductOptions($productId); + + foreach($productOptions as $productOption) { + if($productOptionId == $productOption['product_option_id']) { + foreach($productOption['product_option_value'] as $productOptionValue) { + if($productOptionValue['option_value_id'] == $optionValueId) { + $options[] = array( + 'product_option_id' => $productOptionId, + 'product_option_value_id' => $productOptionValue['product_option_value_id'], + 'value' => $this->getOptionValue($productOptionValue['option_value_id'], 'name'), + 'type' => $productOption['type'], + 'name' => $productOption['name'], + ); + } + } + } + } + } + } + + $product = $this->model_catalog_product->getProduct($productId); + $rewards = $this->model_catalog_product->getProductRewards($productId); + + $data['order_product'][] = array( + 'name' => $product['name'], + 'model' => $product['model'], + 'price' => $item['initialPrice'], + 'total' => (float)($item['initialPrice'] * $item['quantity']), + 'product_id' => $productId, + 'quantity' => $item['quantity'], + 'option' => $options, + 'reward' => $rewards[$data['customer_group_id']]['points'] * $item['quantity'] + ); + } + + if (isset($this->customFieldSetting) && $order['customFields']) { + foreach ($order['customFields'] as $code => $value) { + if (array_key_exists($code, $this->customFieldSetting)) { + $fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]); + $customFields[$fieldCode] = $value; + } + } + + $data['custom_field'] = isset($customFields) ? $customFields : ''; + } + + $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0; + + $data['total'] = $order['totalSumm']; + $data['order_total'] = array( + array( + 'order_total_id' => '', + 'code' => 'sub_total', + 'title' => $this->language->get('product_summ'), + 'value' => $order['summ'], + 'text' => $order['summ'], + 'sort_order' => $this->subtotalSettings['sub_total_sort_order'] + ), + array( + 'order_total_id' => '', + 'code' => 'shipping', + 'title' => $data['shipping_method'], + 'value' => $deliveryCost, + 'text' => $deliveryCost, + 'sort_order' => $this->shippingSettings[$this->totalTitle . 'shipping_sort_order'] + ), + array( + 'order_total_id' => '', + 'code' => 'total', + 'title' => $this->language->get('column_total'), + 'value' => !empty($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost, + 'text' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost, + 'sort_order' => $this->totalSettings[$this->totalTitle . 'total_sort_order'] + ) + ); + + $data['fromApi'] = true; + $data['order_status_id'] = 1; + + $order_id = $this->addOrder($data); + + $ordersIdsFix[] = array('id' => $order['id'], 'externalId' => (int) $order_id); } - return $query->row[$field]; + return array('customers' => $customersIdsFix, 'orders' => $ordersIdsFix); } - /** - * Get language - * - * @param string $code - * @param string $field (default = '') - * - * @return mixed array | string - */ - public function getLanguageByCode($code, $field = '') + protected function updateCustomers($customers) { - $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE code = '" . $code . "'"); + foreach ($customers as $customer) { + $customer_id = $customer['externalId']; + $customerData = $this->model_customer_customer->getCustomer($customer_id); + $customerData['password'] = false; - if (!$field) { - return $query->row; + $customerData['firstname'] = $customer['firstName']; + $customerData['lastname'] = isset($customer['lastName']) ? $customer['lastName'] : ''; + $customerData['email'] = $customer['email']; + $customerData['telephone'] = $customer['phones'] ? $customer['phones'][0]['number'] : ''; + + $customerAddress = $this->model_customer_customer->getAddress($customerData['address_id']); + + if (isset($customer['address']['countryIso'])) { + $customerCountry = $this->getCountryByIsoCode($customer['address']['countryIso']); + } + + if (isset($customer['address']['region'])) { + $customerZone = $this->getZoneByName($customer['address']['region']); + } + + $customerAddress['firstname'] = isset($customer['patronymic']) ? $customer['firstName'] . ' ' . $customer['patronymic'] : $customer['firstName']; + $customerAddress['lastname'] = isset($customer['lastName']) ? $customer['lastName'] : ''; + $customerAddress['address_1'] = $customer['address']['text']; + $customerAddress['city'] = $customer['address']['city']; + $customerAddress['postcode'] = isset($customer['address']['index']) ? $customer['address']['index'] : ''; + + if (isset($customerCountry)) { + $customerAddress['country_id'] = $customerCountry['country_id']; + } + + if (isset($customerZone) && isset($customerZone['zone_id'])) { + $customerAddress['zone_id'] = $customerZone['zone_id']; + } + + $customerData['address'] = array($customerAddress); + + if (isset($this->customFieldSetting) && $customer['customFields']) { + foreach ($customer['customFields'] as $code => $value) { + if (array_key_exists($code, $this->customFieldSetting)) { + $fieldCode = str_replace('c_', '', $this->customFieldSetting[$code]); + $customFields[$fieldCode] = $value; + } + } + + $customerData['custom_field'] = isset($customFields) ? $customFields : ''; + } + + $this->model_customer_customer->editCustomer($customer_id, $customerData); } - - return $query->row[$field]; - } - - /** - * Get product option value - * - * @param int $option_value_id - * @param string $field - * - * @return mixed array | string - */ - public function getOptionValue($option_value_id, $field = '') - { - $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value_description` WHERE option_value_id = '" . $option_value_id . "'"); - - if (!$field) { - return $query->row; - } - - return $query->row[$field]; } } diff --git a/src/upload/admin/model/extension/retailcrm/history/v3.php b/src/upload/admin/model/extension/retailcrm/history/v3.php deleted file mode 100644 index 25fadb0..0000000 --- a/src/upload/admin/model/extension/retailcrm/history/v3.php +++ /dev/null @@ -1,117 +0,0 @@ -retailcrm->getModuleTitle(); - $this->load->model('setting/setting'); - $this->load->model('setting/store'); - $this->load->model('user/api'); - $this->load->model('sale/order'); - $this->load->model('customer/customer'); - $this->load->model('extension/retailcrm/references'); - $this->load->model('catalog/product'); - $this->load->model('catalog/option'); - $this->load->model('localisation/zone'); - - $this->load->language('extension/module/retailcrm'); - - $settings = $this->model_setting_setting->getSetting($moduleTitle); - $history = $this->model_setting_setting->getSetting('retailcrm_history'); - $settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST); - - $url = isset($settings[$moduleTitle . '_url']) ? $settings[$moduleTitle . '_url'] : null; - $key = isset($settings[$moduleTitle . '_apikey']) ? $settings[$moduleTitle . '_apikey'] : null; - - if (empty($url) || empty($key)) { - $this->log->addNotice('You need to configure retailcrm module first.'); - return false; - } - - $lastRun = !empty($history['retailcrm_history_datetime']) - ? new DateTime($history['retailcrm_history_datetime']) - : new DateTime(date('Y-m-d H:i:s', strtotime('-1 days', strtotime(date('Y-m-d H:i:s'))))); - - $packsOrders = $retailcrmApiClient->ordersHistory($lastRun); - - if(!$packsOrders->isSuccessful() && count($packsOrders['orders']) <= 0) { - return false; - } - - $generatedAt = $packsOrders['generatedAt']; - - $this->totalTitle = $this->totalTitles(); - $this->subtotalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'sub_total'); - $this->totalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'total'); - $this->shippingSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'shipping'); - $this->delivery = array_flip($settings[$moduleTitle . '_delivery']); - $this->payment = array_flip($settings[$moduleTitle . '_payment']); - $this->status = array_flip($settings[$moduleTitle . '_status']); - $this->payment_default = $settings[$moduleTitle . '_default_payment']; - $this->delivery_default = $settings[$moduleTitle . '_default_shipping']; - $this->ocPayment = $this->model_extension_retailcrm_references - ->getOpercartPaymentTypes(); - - $this->ocDelivery = $this->model_extension_retailcrm_references - ->getOpercartDeliveryTypes(); - - $this->zones = $this->model_localisation_zone->getZones(); - - $updatedOrders = array(); - $newOrders = array(); - $orders = $packsOrders['orders']; - - foreach ($orders as $order) { - - if (isset($order['deleted'])) { - continue; - } - - if (isset($order['externalId'])) { - $updatedOrders[] = $order['id']; - } else { - $newOrders[] = $order['id']; - } - } - - unset($orders); - - if (!empty($newOrders)) { - $orders = $retailcrmApiClient->ordersList($filter = array('ids' => $newOrders)); - if ($orders) { - $this->createResult = $this->createOrders($orders['orders']); - } - } - - if (!empty($updatedOrders)) { - $orders = $retailcrmApiClient->ordersList($filter = array('ids' => $updatedOrders)); - if ($orders) { - $this->updateOrders($orders['orders']); - } - } - - $this->model_setting_setting->editSetting('retailcrm_history', array('retailcrm_history_datetime' => $generatedAt)); - - if (!empty($this->createResult['customers'])) { - $retailcrmApiClient->customersFixExternalIds($this->createResult['customers']); - } - - if (!empty($this->createResult['orders'])) { - $retailcrmApiClient->ordersFixExternalIds($this->createResult['orders']); - } - - return true; - } -} diff --git a/src/upload/admin/model/extension/retailcrm/history/v4_5.php b/src/upload/admin/model/extension/retailcrm/history/v4_5.php deleted file mode 100644 index 8d82b3f..0000000 --- a/src/upload/admin/model/extension/retailcrm/history/v4_5.php +++ /dev/null @@ -1,827 +0,0 @@ -load->library('retailcrm/retailcrm'); - $this->moduleTitle = $this->retailcrm->getModuleTitle(); - $this->opencartApiClient = $this->retailcrm->getOcApiClient($registry); - } - - /** - * Getting changes from RetailCRM - * @param \RetailcrmProxy $retailcrmApiClient - * - * @return boolean - */ - public function request($retailcrmApiClient) - { - $this->load->library('retailcrm/retailcrm'); - $this->load->model('setting/setting'); - $this->load->model('setting/store'); - $this->load->model('user/api'); - $this->load->model('sale/order'); - $this->load->model('customer/customer'); - $this->load->model('extension/retailcrm/references'); - $this->load->model('catalog/product'); - $this->load->model('catalog/option'); - $this->load->model('localisation/zone'); - - $this->load->language('extension/module/retailcrm'); - - $settings = $this->model_setting_setting->getSetting($this->moduleTitle); - $history = $this->model_setting_setting->getSetting('retailcrm_history'); - $settings['domain'] = parse_url(HTTP_SERVER, PHP_URL_HOST); - - $url = isset($settings[$this->moduleTitle . '_url']) ? $settings[$this->moduleTitle . '_url'] : null; - $key = isset($settings[$this->moduleTitle . '_apikey']) ? $settings[$this->moduleTitle . '_apikey'] : null; - - if (empty($url) || empty($key)) { - $this->log->addNotice('You need to configure retailcrm module first.'); - return false; - } - - $sinceIdOrders = $history['retailcrm_history_orders'] ? $history['retailcrm_history_orders'] : null; - $sinceIdCustomers = $history['retailcrm_history_customers'] ? $history['retailcrm_history_customers'] : null; - - $packsOrders = $retailcrmApiClient->ordersHistory(array( - 'sinceId' => $sinceIdOrders ? $sinceIdOrders : 0 - ), 1, 100); - $packsCustomers = $retailcrmApiClient->customersHistory(array( - 'sinceId' => $sinceIdCustomers ? $sinceIdCustomers : 0 - ), 1, 100); - - if(!$packsOrders->isSuccessful() && count($packsOrders->history) <= 0 && !$packsCustomers->isSuccessful() && count($packsCustomers->history) <= 0) { - return false; - } - - $generatedAt = $packsOrders['generatedAt']; - $orders = RetailcrmHistoryHelper::assemblyOrder($packsOrders->history); - $customers = RetailcrmHistoryHelper::assemblyCustomer($packsCustomers->history); - - $ordersHistory = $packsOrders->history; - $customersHistory = $packsCustomers->history; - - $lastChangeOrders = $ordersHistory ? end($ordersHistory) : null; - $lastChangeCustomers = $customersHistory ? end($customersHistory) : null; - - if ($lastChangeOrders !== null) { - $sinceIdOrders = $lastChangeOrders['id']; - } - - if ($lastChangeCustomers !== null) { - $sinceIdCustomers = $lastChangeCustomers['id']; - } - - $this->settings = $settings; - $this->totalTitle = $this->totalTitles(); - $this->subtotalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'sub_total'); - $this->totalSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'total'); - $this->shippingSettings = $this->model_setting_setting->getSetting($this->totalTitle . 'shipping'); - - $this->delivery = array_flip($settings[$this->moduleTitle . '_delivery']); - $this->payment = array_flip($settings[$this->moduleTitle . '_payment']); - $this->status = array_flip($settings[$this->moduleTitle . '_status']); - $this->delivery_default = $settings[$this->moduleTitle . '_default_shipping']; - $this->payment_default = $settings[$this->moduleTitle . '_default_payment']; - $this->ocPayment = $this->model_extension_retailcrm_references - ->getOpercartPaymentTypes(); - - $this->ocDelivery = $this->model_extension_retailcrm_references - ->getOpercartDeliveryTypes(); - - $this->zones = $this->model_localisation_zone->getZones(); - - if (isset($settings[$this->moduleTitle . '_custom_field'])) { - $this->customFieldSetting = array_flip($settings[$this->moduleTitle . '_custom_field']); - } - - $updatedOrders = array(); - $newOrders = array(); - - foreach ($orders as $order) { - - if (isset($order['deleted'])) { - continue; - } - - if (isset($order['externalId'])) { - $updatedOrders[] = $order['id']; - } else { - $newOrders[] = $order['id']; - } - } - - unset($orders); - - $updateCustomers = array(); - - foreach ($customers as $customer) { - - if (isset($customer['deleted'])) { - continue; - } - - if (isset($customer['externalId'])) { - $updateCustomers[] = $customer['id']; - } - } - - unset($customers); - - if (!empty($updateCustomers)) { - $customers = $retailcrmApiClient->customersList($filter = array('ids' => $updateCustomers)); - if ($customers) { - $this->updateCustomers($customers['customers']); - } - } - - if (!empty($newOrders)) { - $orders = $retailcrmApiClient->ordersList($filter = array('ids' => $newOrders)); - if ($orders) { - $this->createResult = $this->createOrders($orders['orders']); - } - } - - if (!empty($updatedOrders)) { - $orders = $retailcrmApiClient->ordersList($filter = array('ids' => $updatedOrders)); - if ($orders) { - $this->updateOrders($orders['orders']); - } - } - - $this->model_setting_setting->editSetting( - 'retailcrm_history', - array( - 'retailcrm_history_orders' => $sinceIdOrders, - 'retailcrm_history_customers' => $sinceIdCustomers, - 'retailcrm_history_datetime' => $generatedAt - ) - ); - - if (!empty($this->createResult['customers'])) { - $retailcrmApiClient->customersFixExternalIds($this->createResult['customers']); - } - - if (!empty($this->createResult['orders'])) { - $retailcrmApiClient->ordersFixExternalIds($this->createResult['orders']); - } - - return true; - } - - /** - * Update orders from history - * - * @param array $orders - * - * @return void - */ - protected function updateOrders($orders) - { - foreach ($orders as $order) { - $ocOrder = $this->model_sale_order->getOrder($order['externalId']); - - if (isset($order['payments']) && $order['payments']) { - foreach ($order['payments'] as $orderPayment) { - if (isset($orderPayment['externalId'])) { - $payment = $orderPayment; - } - } - - if (!isset($payment) && count($order['payments']) == 1) { - $payment = end($order['payments']); - } - } elseif (isset($order['paymentType'])) { - $payment['type'] = $order['paymentType']; - } - - $data = array(); - - $mail = isset($order['email']) ? $order['email'] : $order['customer']['email']; - $phone = isset($order['phone']) ? $order['phone'] : ''; - - if (!$phone) { - $data['telephone'] = $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : '80000000000'; - } else { - $data['telephone'] = $phone; - } - - if (isset($order['customer']['externalId']) && $order['customer']['externalId']) { - $customer = $this->model_customer_customer->getCustomer($order['customer']['externalId']); - } - - $data['customer'] = $order['firstName']; - $data['customer_id'] = (isset($customer)) ? $customer['customer_id'] : 0; - $data['customer_group_id'] = (isset($customer)) ? $customer['customer_group_id'] : 1; - $data['firstname'] = $order['firstName']; - $data['lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName']; - $data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru'; - $data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : ''; - $data['payment_address'] = '0'; - $data['payment_firstname'] = $order['firstName']; - $data['payment_lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName']; - $data['payment_address_1'] = isset($order['customer']['address']) ? $order['customer']['address']['text'] : ''; - $data['payment_address_2'] = ''; - $data['payment_city'] = !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city']; - $data['payment_postcode'] = !empty( $order['customer']['address']['index'] ) ? $order['customer']['address']['index'] : $order['delivery']['address']['index']; - - $shippingZone = ''; - - if (is_int($order['delivery']['address']['region'])) { - $shippingZone = $order['delivery']['address']['region']; - } else { - $shippingZone = $this->getZoneByName($order['delivery']['address']['region']); - - if ($shippingZone) { - $shipping_zone_id = $shippingZone['zone_id']; - } else { - $shipping_zone_id = 0; - } - } - - if (isset($order['customer']['address']['region'])) { - $paymentZone = $this->getZoneByName($order['customer']['address']['region']); - - if ($paymentZone) { - $payment_zone_id = $paymentZone['zone_id']; - } else { - $payment_zone_id = 0; - } - } - - if (isset($order['countryIso']) && !empty($order['countryIso'])) { - $shippingCountry = $this->getCountryByIsoCode($order['countryIso']); - } - - if (isset($order['customer']['address']['countryIso']) && !empty($order['customer']['address']['countryIso'])) { - $paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); - } else { - $paymentCountry = $this->getCountryByIsoCode($order['countryIso']); - } - - $delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null; - $data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : $ocOrder['payment_country_id']; - $data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : $ocOrder['payment_country']; - $data['payment_zone_id'] = $payment_zone_id ? $payment_zone_id : $ocOrder['payment_zone_id']; - $data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : $ocOrder['payment_zone']; - $data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : $ocOrder['shipping_country_id']; - $data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : $ocOrder['shipping_country']; - $data['shipping_zone_id'] = $shipping_zone_id ? $shipping_zone_id : $ocOrder['shipping_zone_id']; - $data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $ocOrder['shipping_zone']; - $data['shipping_address'] = '0'; - $data['shipping_firstname'] = $order['firstName']; - $data['shipping_lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName']; - $data['shipping_address_1'] = $order['delivery']['address']['text']; - $data['shipping_address_2'] = ''; - $data['shipping_company'] = ''; - $data['shipping_company_id'] = ''; - $data['shipping_city'] = $order['delivery']['address']['city']; - $data['shipping_postcode'] = $order['delivery']['address']['index']; - - if ($delivery !== null) { - if (isset($this->settings[$this->moduleTitle . '_delivery'][$ocOrder['shipping_code']]) - && isset($this->delivery[$delivery]) - ) { - $data['shipping'] = $this->delivery[$delivery]; - - $shipping = explode('.', $data['shipping']); - $shippingModule = $shipping[0]; - - if (isset($this->ocDelivery[$shippingModule][$data['shipping']]['title'])) { - $data['shipping_method'] = $this->ocDelivery[$shippingModule][$data['shipping']]['title']; - } else { - $data['shipping_method'] = $this->ocDelivery[$shippingModule]['title']; - } - - $data['shipping_code'] = $data['shipping']; - } elseif (!isset($this->settings[$this->moduleTitle . '_delivery'][$ocOrder['shipping_code']]) - ) { - $data['shipping_method'] = $ocOrder['shipping_method']; - $data['shipping_code'] = $ocOrder['shipping_code']; - } - } else { - if (!isset($this->settings[$ocOrder['shipping_code']]) - || !isset($this->delivery[$delivery]) - ) { - $data['shipping_method'] = $ocOrder['shipping_method']; - $data['shipping_code'] = $ocOrder['shipping_code']; - } - } - - if (isset($payment)) { - $data['payment'] = $this->payment[$payment['type']]; - $data['payment_method'] = isset($this->ocPayment[$data['payment']]) ? $this->ocPayment[$data['payment']] : $ocOrder['payment_method']; - $data['payment_code'] = isset($this->payment[$payment['type']]) ? $this->payment[$payment['type']] : $ocOrder['payment_code']; - } else { - $data['payment_method'] = $ocOrder['payment_method']; - $data['payment_code'] = $ocOrder['payment_code']; - } - - // this data will not retrive from crm for now - $data['tax'] = ''; - $data['tax_id'] = ''; - $data['product'] = ''; - $data['product_id'] = ''; - $data['reward'] = ''; - $data['affiliate'] = ''; - $data['affiliate_id'] = ''; - $data['payment_tax_id'] = ''; - $data['order_product_id'] = ''; - $data['payment_company'] = ''; - $data['payment_company_id'] = ''; - $data['company'] = ''; - $data['company_id'] = ''; - - $data['order_product'] = array(); - - $discount = false; - - foreach ($order['items'] as $item) { - $productId = $item['offer']['externalId']; - $options = array(); - - if (isset($item['discountTotal']) && $item['discountTotal'] > 0) { - $discount = true; - } - - if (mb_strpos($item['offer']['externalId'], '#') > 1) { - $offer = explode('#', $item['offer']['externalId']); - $productId = $offer[0]; - $optionsFromCRM = explode('_', $offer[1]); - - foreach ($optionsFromCRM as $optionFromCRM) { - $optionData = explode('-', $optionFromCRM); - $productOptionId = $optionData[0]; - $optionValueId = $optionData[1]; - - $productOptions = $this->model_catalog_product->getProductOptions($productId); - - foreach($productOptions as $productOption) { - if($productOptionId == $productOption['product_option_id']) { - foreach($productOption['product_option_value'] as $productOptionValue) { - if($productOptionValue['option_value_id'] == $optionValueId) { - $options[] = array( - 'product_option_id' => $productOptionId, - 'product_option_value_id' => $productOptionValue['product_option_value_id'], - 'value' => $this->getOptionValue($productOptionValue['option_value_id'], 'name'), - 'type' => $productOption['type'], - 'name' => $productOption['name'], - ); - } - } - } - } - } - } - - $product = $this->model_catalog_product->getProduct($productId); - $rewards = $this->model_catalog_product->getProductRewards($productId); - - $data['order_product'][] = array( - 'name' => $product['name'], - 'model' => $product['model'], - 'price' => $item['initialPrice'], - 'total' => (float)($item['initialPrice'] * $item['quantity']), - 'product_id' => $productId, - 'quantity' => $item['quantity'], - 'option' => $options, - 'reward' => $rewards[$data['customer_group_id']]['points'] * $item['quantity'] - ); - } - - if (isset($this->customFieldSetting) && $order['customFields']) { - foreach ($order['customFields'] as $code => $value) { - if (array_key_exists($code, $this->customFieldSetting)) { - $fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]); - $customFields[$fieldCode] = $value; - } - } - - $data['custom_field'] = isset($customFields) ? $customFields : ''; - } else { - $data['custom_field'] = $ocOrder['custom_field']; - } - - $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0; - - $data['total'] = $order['totalSumm']; - $data['order_total'] = array( - array( - 'order_total_id' => '', - 'code' => 'sub_total', - 'title' => $this->language->get('product_summ'), - 'value' => $order['summ'], - 'text' => $order['summ'], - 'sort_order' => $this->subtotalSettings['sub_total_sort_order'] - ), - array( - 'order_total_id' => '', - 'code' => 'shipping', - 'title' => $data['shipping_method'], - 'value' => $deliveryCost, - 'text' => $deliveryCost, - 'sort_order' => $this->shippingSettings[$this->totalTitle . 'shipping_sort_order'] - ), - array( - 'order_total_id' => '', - 'code' => 'total', - 'title' => $this->language->get('column_total'), - 'value' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost, - 'text' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost, - 'sort_order' => $this->totalSettings[$this->totalTitle . 'total_sort_order'] - ) - ); - - if ((isset($order['discount']) - && $order['discount'] > 0) - || $discount - ) { - $orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']); - foreach ($orderTotals as $orderTotal) { - if ($orderTotal['code'] == 'coupon' - || $orderTotal['code'] == 'reward' - ) { - $data['order_total'][] = $orderTotal; - } - } - } - - $data['fromApi'] = true; - - if (array_key_exists($order['status'], $this->status)) { - $data['order_status_id'] = $this->status[$order['status']]; - } else { - $tmpOrder = $this->model_sale_order->getOrder($order['externalId']); - $data['order_status_id'] = $tmpOrder['order_status_id']; - } - - $this->editOrder($order['externalId'], $data); - $this->opencartApiClient->addHistory($order['externalId'], $data['order_status_id']); - } - } - - /** - * Create orders from history - * - * @param array $orders - * - * @return array - */ - protected function createOrders($orders) - { - $customersIdsFix = array(); - $ordersIdsFix = array(); - - foreach ($orders as $order) { - $store = $this->config->get('config_store_id'); - - if (isset($order['payments']) && $order['payments']) { - $payment = end($order['payments']); - } elseif (isset($order['paymentType'])) { - $payment['type'] = $order['paymentType']; - } - - $customer_id = (!empty($order['customer']['externalId'])) - ? $order['customer']['externalId'] - : 0; - - $data = array(); - - if ($customer_id == 0) { - if (isset($order['customer']['address']['countryIso'])) { - $customerCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); - } else { - $customerCountry = $this->getCountryByIsoCode($order['delivery']['address']['countryIso']); - } - - if (isset($order['customer']['address']['region'])) { - $customerZone = $this->getZoneByName($order['customer']['address']['region']); - } else { - $customerZone = $this->getZoneByName($order['delivery']['address']['region']); - } - - $cData = array( - 'store_id' => 0, - 'customer_group_id' => '1', - 'firstname' => isset($order['patronymic']) ? $order['firstName'] . ' ' . $order['patronymic'] : $order['firstName'], - 'lastname' => (!empty($order['customer']['lastName'])) ? $order['customer']['lastName'] : ' ', - 'email' => $order['customer']['email'], - 'telephone' => $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : ' ', - 'fax' => '', - 'newsletter' => 0, - 'password' => 'tmppass', - 'status' => 1, - 'approved' => 1, - 'safe' => 0, - 'affiliate' => '', - 'address' => array( - array( - 'firstname' => isset($order['patronymic']) ? $order['firstName'] . ' ' . $order['patronymic'] : $order['firstName'], - 'lastname' => (!empty($order['customer']['lastName'])) ? $order['customer']['lastName'] : ' ', - 'address_1' => $order['customer']['address']['text'], - 'address_2' => ' ', - 'city' => !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city'], - 'postcode' => isset($order['customer']['address']['index']) ? $order['customer']['address']['index'] : $order['delivery']['address']['index'], - 'tax_id' => '1', - 'company' => '', - 'company_id' => '', - 'zone_id' => $customerZone ? $customerZone['zone_id'] : 0, - 'country_id' => $customerCountry ? $customerCountry['country_id'] : 0, - 'default' => '1' - ) - ), - ); - - $customer_id = $this->model_customer_customer->addCustomer($cData); - - $customersIdsFix[] = array('id' => $order['customer']['id'], 'externalId' => (int)$customer_id); - } - - $mail = isset($order['email']) ? $order['email'] : $order['customer']['email']; - $phone = isset($order['phone']) ? $order['phone'] : ''; - - if (!$phone) { - $data['telephone'] = $order['customer']['phones'] ? $order['customer']['phones'][0]['number'] : '80000000000'; - } else { - $data['telephone'] = $phone; - } - - $data['currency_code'] = $this->config->get('config_currency'); - $data['currency_value'] = $this->getCurrencyByCode($data['currency_code'], 'value'); - $data['currency_id'] = $this->getCurrencyByCode($data['currency_code'], 'currency_id'); - $data['language_id'] = $this->getLanguageByCode($this->config->get('config_language'), 'language_id'); - $data['store_id'] = $store == null ? 0 : $store; - $data['store_name'] = $this->config->get('config_name'); - $data['customer'] = $order['firstName']; - $data['customer_id'] = $customer_id; - $data['customer_group_id'] = 1; - $data['firstname'] = $order['firstName']; - $data['lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName']; - $data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru'; - $data['comment'] = !empty($order['customerComment']) ? $order['customerComment'] : ''; - $data['fax'] = ''; - $data['payment_address'] = '0'; - $data['payment_firstname'] = $order['firstName']; - $data['payment_lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName']; - $data['payment_address_1'] = $order['customer']['address']['text']; - $data['payment_address_2'] = ''; - $data['payment_company'] = ''; - $data['payment_company_id'] = ''; - $data['payment_city'] = !empty($order['customer']['address']['city']) ? $order['customer']['address']['city'] : $order['delivery']['address']['city']; - $data['payment_postcode'] = !empty($order['customer']['address']['index']) ? $order['customer']['address']['index'] : $order['delivery']['address']['index']; - - $shippingZone = ''; - - if (!empty($order['delivery']['address']['region']) && is_int($order['delivery']['address']['region'])) { - $shippingZone = $order['delivery']['address']['region']; - } else { - $shippingZone = $this->getZoneByName($order['delivery']['address']['region']); - - if ($shippingZone) { - $shipping_zone_id = $shippingZone['zone_id']; - } else { - $shipping_zone_id = 0; - } - } - - if (isset($order['customer']['address']['region'])) { - $paymentZone = $this->getZoneByName($order['customer']['address']['region']); - - if ($paymentZone) { - $payment_zone_id = $paymentZone['zone_id']; - } else { - $payment_zone_id = 0; - } - } - - if (isset($order['countryIso'])) { - $shippingCountry = $this->getCountryByIsoCode($order['countryIso']); - } - - if (isset($order['customer']['address']['countryIso'])) { - $paymentCountry = $this->getCountryByIsoCode($order['customer']['address']['countryIso']); - } - - $delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : null; - $data['payment_country_id'] = $paymentCountry ? $paymentCountry['country_id'] : 0; - $data['payment_country'] = isset($paymentCountry) ? $paymentCountry['name'] : ''; - $data['payment_zone_id'] = $payment_zone_id; - $data['payment_zone'] = isset($order['customer']['address']['region']) ? $order['customer']['address']['region'] : ''; - $data['shipping_country_id'] = isset($shippingCountry) ? $shippingCountry['country_id'] : 0; - $data['shipping_country'] = isset($shippingCountry) ? $shippingCountry['name'] : ''; - $data['shipping_zone_id'] = $shipping_zone_id; - $data['shipping_zone'] = $shippingZone ? $shippingZone['name'] : $data['payment_zone']; - $data['shipping_address'] = '0'; - $data['shipping_firstname'] = $order['firstName']; - $data['shipping_lastname'] = (isset($order['lastName'])) ? $order['lastName'] : $order['firstName']; - $data['shipping_address_1'] = $order['delivery']['address']['text']; - $data['shipping_address_2'] = ''; - $data['shipping_company'] = ''; - $data['shipping_company_id'] = ''; - $data['shipping_city'] = $order['delivery']['address']['city']; - $data['shipping_postcode'] = $order['delivery']['address']['index']; - $data['shipping'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; - $data['shipping_code'] = $delivery != null ? $this->delivery[$delivery] : $this->delivery_default; - - $shipping = explode('.', $data['shipping']); - $shippingModule = $shipping[0]; - - if (isset($this->ocDelivery[$shippingModule][$data['shipping']]['title'])) { - $data['shipping_method'] = $this->ocDelivery[$shippingModule][$data['shipping']]['title']; - } else { - $data['shipping_method'] = $this->ocDelivery[$shippingModule]['title']; - } - - if (isset($payment)) { - $data['payment'] = $this->payment[$payment['type']]; - $data['payment_method'] = $this->ocPayment[$data['payment']]; - $data['payment_code'] = $this->payment[$payment['type']]; - } else { - $data['payment'] = $this->payment_default; - $data['payment_method'] = $this->ocPayment[$data['payment']]; - $data['payment_code'] = $this->payment_default; - } - - // this data will not retrive from crm for now - $data['tax'] = ''; - $data['tax_id'] = ''; - $data['product'] = ''; - $data['product_id'] = ''; - $data['reward'] = ''; - $data['affiliate'] = ''; - $data['affiliate_id'] = 0; - $data['payment_tax_id'] = ''; - $data['order_product_id'] = ''; - $data['payment_company'] = ''; - $data['payment_company_id'] = ''; - $data['company'] = ''; - $data['company_id'] = ''; - - $data['order_product'] = array(); - - foreach ($order['items'] as $item) { - $productId = $item['offer']['externalId']; - $options = array(); - - if(mb_strpos($item['offer']['externalId'], '#') > 1) { - $offer = explode('#', $item['offer']['externalId']); - $productId = $offer[0]; - $optionsFromCRM = explode('_', $offer[1]); - - foreach ($optionsFromCRM as $optionFromCRM) { - $optionData = explode('-', $optionFromCRM); - $productOptionId = $optionData[0]; - $optionValueId = $optionData[1]; - - $productOptions = $this->model_catalog_product->getProductOptions($productId); - - foreach($productOptions as $productOption) { - if($productOptionId == $productOption['product_option_id']) { - foreach($productOption['product_option_value'] as $productOptionValue) { - if($productOptionValue['option_value_id'] == $optionValueId) { - $options[] = array( - 'product_option_id' => $productOptionId, - 'product_option_value_id' => $productOptionValue['product_option_value_id'], - 'value' => $this->getOptionValue($productOptionValue['option_value_id'], 'name'), - 'type' => $productOption['type'], - 'name' => $productOption['name'], - ); - } - } - } - } - } - } - - $product = $this->model_catalog_product->getProduct($productId); - $rewards = $this->model_catalog_product->getProductRewards($productId); - - $data['order_product'][] = array( - 'name' => $product['name'], - 'model' => $product['model'], - 'price' => $item['initialPrice'], - 'total' => (float)($item['initialPrice'] * $item['quantity']), - 'product_id' => $productId, - 'quantity' => $item['quantity'], - 'option' => $options, - 'reward' => $rewards[$data['customer_group_id']]['points'] * $item['quantity'] - ); - } - - if (isset($this->customFieldSetting) && $order['customFields']) { - foreach ($order['customFields'] as $code => $value) { - if (array_key_exists($code, $this->customFieldSetting)) { - $fieldCode = str_replace('o_', '', $this->customFieldSetting[$code]); - $customFields[$fieldCode] = $value; - } - } - - $data['custom_field'] = isset($customFields) ? $customFields : ''; - } - - $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0; - - $data['total'] = $order['totalSumm']; - $data['order_total'] = array( - array( - 'order_total_id' => '', - 'code' => 'sub_total', - 'title' => $this->language->get('product_summ'), - 'value' => $order['summ'], - 'text' => $order['summ'], - 'sort_order' => $this->subtotalSettings['sub_total_sort_order'] - ), - array( - 'order_total_id' => '', - 'code' => 'shipping', - 'title' => $data['shipping_method'], - 'value' => $deliveryCost, - 'text' => $deliveryCost, - 'sort_order' => $this->shippingSettings[$this->totalTitle . 'shipping_sort_order'] - ), - array( - 'order_total_id' => '', - 'code' => 'total', - 'title' => $this->language->get('column_total'), - 'value' => !empty($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost, - 'text' => isset($order['totalSumm']) ? $order['totalSumm'] : $order['summ'] + $deliveryCost, - 'sort_order' => $this->totalSettings[$this->totalTitle . 'total_sort_order'] - ) - ); - - $data['fromApi'] = true; - $data['order_status_id'] = 1; - - $order_id = $this->addOrder($data); - - $ordersIdsFix[] = array('id' => $order['id'], 'externalId' => (int) $order_id); - } - - return array('customers' => $customersIdsFix, 'orders' => $ordersIdsFix); - } - - protected function updateCustomers($customers) - { - foreach ($customers as $customer) { - $customer_id = $customer['externalId']; - $customerData = $this->model_customer_customer->getCustomer($customer_id); - $customerData['password'] = false; - - $customerData['firstname'] = $customer['firstName']; - $customerData['lastname'] = isset($customer['lastName']) ? $customer['lastName'] : ''; - $customerData['email'] = $customer['email']; - $customerData['telephone'] = $customer['phones'] ? $customer['phones'][0]['number'] : ''; - - $customerAddress = $this->model_customer_customer->getAddress($customerData['address_id']); - - if (isset($customer['address']['countryIso'])) { - $customerCountry = $this->getCountryByIsoCode($customer['address']['countryIso']); - } - - if (isset($customer['address']['region'])) { - $customerZone = $this->getZoneByName($customer['address']['region']); - } - - $customerAddress['firstname'] = isset($customer['patronymic']) ? $customer['firstName'] . ' ' . $customer['patronymic'] : $customer['firstName']; - $customerAddress['lastname'] = isset($customer['lastName']) ? $customer['lastName'] : ''; - $customerAddress['address_1'] = $customer['address']['text']; - $customerAddress['city'] = $customer['address']['city']; - $customerAddress['postcode'] = isset($customer['address']['index']) ? $customer['address']['index'] : ''; - - if (isset($customerCountry)) { - $customerAddress['country_id'] = $customerCountry['country_id']; - } - - if (isset($customerZone) && isset($customerZone['zone_id'])) { - $customerAddress['zone_id'] = $customerZone['zone_id']; - } - - $customerData['address'] = array($customerAddress); - - if (isset($this->customFieldSetting) && $customer['customFields']) { - foreach ($customer['customFields'] as $code => $value) { - if (array_key_exists($code, $this->customFieldSetting)) { - $fieldCode = str_replace('c_', '', $this->customFieldSetting[$code]); - $customFields[$fieldCode] = $value; - } - } - - $customerData['custom_field'] = isset($customFields) ? $customFields : ''; - } - - $this->model_customer_customer->editCustomer($customer_id, $customerData); - } - } -} diff --git a/src/upload/admin/model/extension/retailcrm/icml.php b/src/upload/admin/model/extension/retailcrm/icml.php index d0afb5c..3efd10d 100644 --- a/src/upload/admin/model/extension/retailcrm/icml.php +++ b/src/upload/admin/model/extension/retailcrm/icml.php @@ -15,7 +15,7 @@ class ModelExtensionRetailcrmIcml extends Model /** * Constructor - * + * * @param Registry $registry */ public function __construct($registry) @@ -267,7 +267,7 @@ class ModelExtensionRetailcrmIcml extends Model private function generateImage($image) { $this->load->model('tool/image'); - + $currentTheme = $this->config->get('config_theme'); $width = $this->config->get($currentTheme . '_image_related_width') ? $this->config->get($currentTheme . '_image_related_width') : 200; $height = $this->config->get($currentTheme . '_image_related_height') ? $this->config->get($currentTheme . '_image_related_height') : 200; diff --git a/src/upload/admin/model/extension/retailcrm/order.php b/src/upload/admin/model/extension/retailcrm/order.php index b870b97..7b1135f 100644 --- a/src/upload/admin/model/extension/retailcrm/order.php +++ b/src/upload/admin/model/extension/retailcrm/order.php @@ -1,305 +1,188 @@ load->model('setting/setting'); - $this->load->library('retailcrm/retailcrm'); - - $this->moduleTitle = $this->retailcrm->getModuleTitle(); - $this->settings = $this->model_setting_setting->getSetting($this->moduleTitle); - } - +class ModelExtensionRetailcrmOrder extends Model +{ /** - * Upload orders to CRM + * Create order in OC * - * @param array $orders - * @param \RetailcrmProxy $retailcrmApiClient + * @param array $order * - * @return mixed + * @return int $order_id */ - public function uploadToCrm($orders, $retailcrmApiClient) + public function addOrder($order) { - if ($retailcrmApiClient === false) { - return false; + $this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET store_id = '" . (int)$order['store_id'] . "', store_name = '" . $order['store_name'] . "', customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(isset($order['custom_field']) ? json_encode($order['custom_field']) : '') . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', affiliate_id = '" . (int)$order['affiliate_id'] . "', language_id = '" . (int)$order['language_id'] . "', currency_id = '" . (int)$order['currency_id'] . "', currency_code = '" . $this->db->escape($order['currency_code']) . "', currency_value = '" . (float)$order['currency_value'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_added = NOW(), date_modified = NOW()"); + + $order_id = $this->db->getLastId(); + + // Products + if (isset($order['order_product']) && $order['order_product']) { + $this->addOrderProducts($order_id, $order['order_product']); } - $ordersToCrm = array(); - - foreach ($orders as $order) { - $ordersToCrm[] = $this->process($order); + // Totals + if (isset($order['order_total'])) { + $this->addOrderTotals($order_id, $order['order_total']); } - $chunkedOrders = array_chunk($ordersToCrm, 50); - - foreach($chunkedOrders as $ordersPart) { - $retailcrmApiClient->ordersUpload($ordersPart); - } - - return $chunkedOrders; + return $order_id; } /** - * Send one order by id - * - * @param array $order_data - * @param \RetailcrmProxy $retailcrmApiClient + * Edit order in OC * - * @return mixed + * @param int $order_id + * @param array $order + * + * @return void */ - public function uploadOrder($order_data, $retailcrmApiClient) + public function editOrder($order_id, $order) { - if ($retailcrmApiClient === false) { - return false; + $this->db->query("UPDATE `" . DB_PREFIX . "order` SET customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(json_encode($order['custom_field'])) . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($order['payment_address_2']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'"); + + $this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'"); + + // Products + if (isset($order['order_product']) && $order['order_product']) { + $this->addOrderProducts($order_id, $order['order_product']); } - if (isset($this->request->post['fromApi'])) { - return false; + // Totals + $this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'"); + + if (isset($order['order_total'])) { + $this->addOrderTotals($order_id, $order['order_total']); } - - $order = $this->process($order_data); - - if (isset($order['customer']['externalId'])) { - $this->load->model('extension/retailcrm/customer'); - $this->load->model('customer/customer'); - $customer = $this->model_customer_customer->getCustomer($order['customer']['externalId']); - $this->model_extension_retailcrm_customer->sendToCrm($customer, $retailcrmApiClient); - } else { - $customers = $retailcrmApiClient->customersList( - array( - 'name' => $order_data['telephone'], - 'email' => $order_data['email'] - ), - 1, - 100 - ); - - if ($customers) { - foreach ($customers['customers'] as $customer) { - $order['customer']['id'] = $customer['id']; - } - } - - unset($customers); - } - - self::$lastRepsonse = $retailcrmApiClient->ordersCreate($order); - - return $order; } /** - * Process order - * - * @param array $order_data - * - * @return array $order + * Add order products + * + * @param int $order_id + * @param array $products + * + * @return void */ - private function process($order_data) { - $order = array(); + public function addOrderProducts($order_id, $products) + { + foreach ($products as $product) { + $this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', quantity = '" . (int)$product['quantity'] . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', reward = '" . (float)$product['reward'] . "'"); - $this->load->model('catalog/product'); + $order_product_id = $this->db->getLastId(); - if (!empty($order_data['payment_code']) && isset($this->settings[$this->moduleTitle . '_payment'][$order_data['payment_code']])) { - $payment_code = $this->settings[$this->moduleTitle . '_payment'][$order_data['payment_code']]; - } else { - $payment_code = ''; - } - - if (!empty($order_data['shipping_code'])) { - $shippingCode = explode('.', $order_data['shipping_code']); - $shippingModule = $shippingCode[0]; - - if (isset($this->settings[$this->moduleTitle . '_delivery'][$order_data['shipping_code']])) { - $delivery_code = $this->settings[$this->moduleTitle . '_delivery'][$order_data['shipping_code']]; - } elseif (isset($this->settings[$this->moduleTitle . '_delivery'][$shippingModule])) { - $delivery_code = $this->settings[$this->moduleTitle . '_delivery'][$shippingModule]; + foreach ($product['option'] as $option) { + $this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_id = '" . (int)$option['product_option_id'] . "', product_option_value_id = '" . (int)$option['product_option_value_id'] . "', name = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', `type` = '" . $this->db->escape($option['type']) . "'"); } } - - if (!isset($delivery_code) && isset($shippingModule)) { - if (isset($this->settings[$this->moduleTitle . '_delivery']) - && $this->settings[$this->moduleTitle . '_delivery'] - ) { - $deliveries = array_keys($this->settings[$this->moduleTitle . '_delivery']); - $shipping_code = ''; - - array_walk($deliveries, function($item, $key) use ($shippingModule, &$shipping_code) { - if (strripos($item, $shippingModule) !== false) { - $shipping_code = $item; - } - }); - - $delivery_code = $this->settings[$this->moduleTitle . '_delivery'][$shipping_code]; - } - } - - if (!empty($order_data['payment_iso_code_2'])) { - $order['countryIso'] = $order_data['payment_iso_code_2']; - } - - if (isset($this->settings[$this->moduleTitle . '_order_number']) - && $this->settings[$this->moduleTitle . '_order_number'] == 1 - ) { - $order['number'] = $order_data['order_id']; - } - - $order['externalId'] = $order_data['order_id']; - $order['firstName'] = $order_data['firstname']; - $order['lastName'] = $order_data['lastname']; - $order['phone'] = $order_data['telephone']; - $order['customerComment'] = $order_data['comment']; - - if (!empty($order_data['email'])) { - $order['email'] = $order_data['email']; - } - - if ($order_data['customer_id']) { - $order['customer']['externalId'] = $order_data['customer_id']; - } - - $deliveryCost = 0; - $orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ; - - foreach ($orderTotals as $totals) { - if ($totals['code'] == 'shipping') { - $deliveryCost = $totals['value']; - } - } - - $order['createdAt'] = $order_data['date_added']; - - if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v5') { - $order['paymentType'] = $payment_code; - } - - $country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ; - - $order['delivery'] = array( - 'code' => isset($delivery_code) ? $delivery_code : '', - 'cost' => $deliveryCost, - 'address' => array( - 'countryIso' => $order_data['shipping_iso_code_2'], - 'index' => $order_data['shipping_postcode'], - 'city' => $order_data['shipping_city'], - 'region' => $order_data['shipping_zone'], - 'text' => implode(', ', array( - $order_data['shipping_postcode'], - $country, - $order_data['shipping_city'], - $order_data['shipping_address_1'], - $order_data['shipping_address_2'] - )) - ) - ); - - $orderProducts = isset($order_data['products']) ? $order_data['products'] : $order_data['order_product']; - $offerOptions = array('select', 'radio'); - - foreach ($orderProducts as $product) { - $offerId = ''; - - if (!empty($product['option'])) { - $options = array(); - - $productOptions = $this->model_catalog_product->getProductOptions($product['product_id']); - - foreach ($product['option'] as $option) { - if ($option['type'] == 'checkbox') { - $properties[] = array( - 'code' => $option['product_option_value_id'], - 'name' => $option['name'], - 'value' => $option['value'] - ); - } - - if (!in_array($option['type'], $offerOptions)) continue; - foreach($productOptions as $productOption) { - if($productOption['product_option_id'] = $option['product_option_id']) { - foreach($productOption['product_option_value'] as $productOptionValue) { - if($productOptionValue['product_option_value_id'] == $option['product_option_value_id']) { - $options[$option['product_option_id']] = $productOptionValue['option_value_id']; - } - } - } - } - } - - ksort($options); - - $offerId = array(); - foreach($options as $optionKey => $optionValue) { - $offerId[] = $optionKey.'-'.$optionValue; - } - $offerId = implode('_', $offerId); - } - - if ($this->settings[$this->moduleTitle . '_apiversion'] != 'v3') { - $item = array( - 'offer' => array( - 'externalId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id'] - ), - 'productName' => $product['name'], - 'initialPrice' => $product['price'], - 'quantity' => $product['quantity'], - ); - } else { - $item = array( - 'productName' => $product['name'], - 'initialPrice' => $product['price'], - 'quantity' => $product['quantity'], - 'productId' => !empty($offerId) ? $product['product_id'].'#'.$offerId : $product['product_id'] - ); - } - - if (isset($properties)) $item['properties'] = $properties; - $order['items'][] = $item; - } - - if (isset($order_data['order_status_id']) && $order_data['order_status_id'] > 0) { - $order['status'] = $this->settings[$this->moduleTitle . '_status'][$order_data['order_status_id']]; - } - - if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v5') { - if ($payment_code) { - $payment = array( - 'externalId' => $order_data['order_id'], - 'type' => $payment_code - ); - - $order['payments'][] = $payment; - } - } - - if (isset($this->settings[$this->moduleTitle . '_custom_field']) && $order_data['custom_field']) { - $customFields = json_decode($order_data['custom_field']); - - foreach ($customFields as $key => $value) { - if (isset($this->settings[$this->moduleTitle . '_custom_field']['o_' . $key])) { - $customFieldsToCrm[$this->settings[$this->moduleTitle . '_custom_field']['o_' . $key]] = $value; - } - } - - if (isset($customFieldsToCrm)) { - $order['customFields'] = $customFieldsToCrm; - } - } - - return $order; } /** - * @return mixed + * Add order totals + * + * @param int $order_id + * @param array $totals + * + * @return void */ - public static function getLastResponse() + public function addOrderTotals($order_id, $totals) { - return self::$lastRepsonse; + foreach ($totals as $total) { + $this->db->query("INSERT INTO " . DB_PREFIX . "order_total SET order_id = '" . (int)$order_id . "', code = '" . $this->db->escape($total['code']) . "', title = '" . $this->db->escape($total['title']) . "', `value` = '" . (float)$total['value'] . "', sort_order = '" . (int)$total['sort_order'] . "'"); + } + } + + /** + * Get total titles + * + * @return string $title + */ + protected function totalTitles() + { + return 'total_'; + } + + /** + * Get country by iso code 2 + * + * @param string $isoCode + * + * @return array + */ + public function getCountryByIsoCode($isoCode) + { + $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE iso_code_2 = '" . $isoCode . "'"); + + return $query->row; + } + + /** + * Get zone by name + * + * @param string $name + * + * @return array + */ + public function getZoneByName($name) + { + $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE name = '" . $name . "'"); + + return $query->row; + } + + /** + * Get currency + * + * @param string $code + * @param string $field (default = '') + * + * @return mixed array | string + */ + public function getCurrencyByCode($code, $field = '') + { + $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "currency` WHERE code = '" . $code . "'"); + + if (!$field) { + return $query->row; + } + + return $query->row[$field]; + } + + /** + * Get language + * + * @param string $code + * @param string $field (default = '') + * + * @return mixed array | string + */ + public function getLanguageByCode($code, $field = '') + { + $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE code = '" . $code . "'"); + + if (!$field) { + return $query->row; + } + + return $query->row[$field]; + } + + /** + * Get product option value + * + * @param int $option_value_id + * @param string $field + * + * @return mixed array | string + */ + public function getOptionValue($option_value_id, $field = '') + { + $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value_description` WHERE option_value_id = '" . $option_value_id . "'"); + + if (!$field) { + return $query->row; + } + + return $query->row[$field]; } } diff --git a/src/upload/admin/model/extension/retailcrm/prices.php b/src/upload/admin/model/extension/retailcrm/prices.php index 5c6c303..c784184 100644 --- a/src/upload/admin/model/extension/retailcrm/prices.php +++ b/src/upload/admin/model/extension/retailcrm/prices.php @@ -3,45 +3,34 @@ class ModelExtensionRetailcrmPrices extends Model { protected $settings; - protected $moduleTitle; + private $options; private $optionValues; /** - * Constructor - * - * @param Registry $registry + * Upload prices to CRM + * + * @param array $products + * @param \RetailcrmProxy $retailcrm_api_client + * @param \Retailcrm\Retailcrm $retailcrm + * + * @return mixed bool | array */ - public function __construct($registry) + public function uploadPrices($products, $retailcrm_api_client, $retailcrm) { - parent::__construct($registry); - $this->load->library('retailcrm/retailcrm'); $this->load->model('catalog/option'); $this->load->model('setting/setting'); - $this->moduleTitle = $this->retailcrm->getModuleTitle(); - $this->settings = $this->model_setting_setting->getSetting($this->moduleTitle); - } + $prices = $this->getPrices($products, $retailcrm_api_client, $retailcrm); - /** - * Upload prices to CRM - * - * @param array $products - * @param \RetailcrmProxy $retailcrmApiClient - * @return mixed bool | array - */ - public function uploadPrices($products, $retailcrmApiClient) - { - $prices = $this->getPrices($products, $retailcrmApiClient); - - if ($retailcrmApiClient === false || !$prices) { + if ($retailcrm_api_client === false || !$prices) { return false; } $pricesUpload = array_chunk($prices, 250); foreach ($pricesUpload as $priceUpload) { - $retailcrmApiClient->storePricesUpload($priceUpload); + $retailcrm_api_client->storePricesUpload($priceUpload); } return $pricesUpload; @@ -49,18 +38,21 @@ class ModelExtensionRetailcrmPrices extends Model /** * Get prices - * + * * @param array $products - * + * @param \RetailcrmProxy $retailcrm_api_client + * @param \Retailcrm\Retailcrm $retailcrm * @return mixed */ - protected function getPrices($products, $retailcrmApiClient) + protected function getPrices($products, $retailcrm_api_client, $retailcrm) { - $prices = array(); - $site = $this->getSite($retailcrmApiClient); + $settings = $this->model_setting_setting->getSetting(\retailcrm\Retailcrm::MODULE); - if (!isset($this->settings[$this->moduleTitle . '_special']) - || $this->settings[$this->moduleTitle . '_apiversion'] == 'v3' + $prices = array(); + $site = $this->getSite($retailcrm_api_client); + + if (!isset($settings[\Retailcrm\Retailcrm::MODULE . '_special']) + || $settings[\Retailcrm\Retailcrm::MODULE . '_apiversion'] == 'v3' ) { return false; } @@ -80,7 +72,7 @@ class ModelExtensionRetailcrmPrices extends Model } } - $offers = $this->retailcrm->getOffers($product); + $offers = $retailcrm->getOffers($product); foreach ($offers as $optionsString => $optionsValues) { $optionsString = explode('_', $optionsString); @@ -115,7 +107,7 @@ class ModelExtensionRetailcrmPrices extends Model 'site' => $site, 'prices' => array( array( - 'code' => $this->settings[$this->moduleTitle . '_special'], + 'code' => $settings[\Retailcrm\Retailcrm::MODULE . '_special'], 'price' => $productPrice + $optionsValues['price'] ) ) @@ -128,9 +120,9 @@ class ModelExtensionRetailcrmPrices extends Model /** * Get actual special - * + * * @param array $specials - * + * * @return float $productPrice */ private function getSpecialPrice($specials) @@ -157,10 +149,10 @@ class ModelExtensionRetailcrmPrices extends Model /** * Get data option - * + * * @param int $optionId * @param int $optionValueId - * + * * @return array */ private function getOptionData($optionId, $optionValueId) { @@ -191,9 +183,9 @@ class ModelExtensionRetailcrmPrices extends Model * * @return mixed boolean | string */ - private function getSite($retailcrmApiClient) + private function getSite($retailcrm_api_client) { - $response = $retailcrmApiClient->sitesList(); + $response = $retailcrm_api_client->sitesList(); if ($response && $response->isSuccessful()) { $sites = $response->sites; diff --git a/src/upload/admin/model/extension/retailcrm/products.php b/src/upload/admin/model/extension/retailcrm/products.php new file mode 100644 index 0000000..d179650 --- /dev/null +++ b/src/upload/admin/model/extension/retailcrm/products.php @@ -0,0 +1,9 @@ +load->model('catalog/product_option'); + + return $this->model_catalog_product_option->getProductOptionsByProductId($product_id); + } +} diff --git a/src/upload/admin/model/extension/retailcrm/references.php b/src/upload/admin/model/extension/retailcrm/references.php index 722c499..4aeef5a 100644 --- a/src/upload/admin/model/extension/retailcrm/references.php +++ b/src/upload/admin/model/extension/retailcrm/references.php @@ -1,93 +1,72 @@ load->model('setting/setting'); - $this->load->library('retailcrm/retailcrm'); - - $this->moduleTitle = $this->retailcrm->getModuleTitle(); - $this->settings = $this->model_setting_setting->getSetting($this->moduleTitle); - $this->retailcrmApiClient = $this->retailcrm->getApiClient(); - } +class ModelExtensionRetailcrmReferences extends Model { /** * Get opencart delivery methods - * + * * @return array */ - public function getOpercartDeliveryTypes() + public function getOpercartDeliveryTypes($opencart_api_client) { - $this->opencartApiClient = $this->retailcrm->getOcApiClient($this->registry); - - return $this->opencartApiClient->getDeliveryTypes(); + return $opencart_api_client->getDeliveryTypes(); } /** * Get all delivery types - * + * * @return array */ - public function getDeliveryTypes() + public function getDeliveryTypes($opencart_api_client, $retailcrm_api_client) { - $this->load->model('setting/store'); - return array( - 'opencart' => $this->getOpercartDeliveryTypes(), - 'retailcrm' => $this->getApiDeliveryTypes() + 'opencart' => $this->getOpercartDeliveryTypes($opencart_api_client), + 'retailcrm' => $this->getApiDeliveryTypes($retailcrm_api_client) ); } /** * Get all statuses - * + * * @return array */ - public function getOrderStatuses() + public function getOrderStatuses($retailcrm_api_client) { return array( 'opencart' => $this->getOpercartOrderStatuses(), - 'retailcrm' => $this->getApiOrderStatuses() + 'retailcrm' => $this->getApiOrderStatuses($retailcrm_api_client) ); } /** * Get all payment types - * + * * @return array */ - public function getPaymentTypes() + public function getPaymentTypes($retailcrm_api_client) { return array( 'opencart' => $this->getOpercartPaymentTypes(), - 'retailcrm' => $this->getApiPaymentTypes() + 'retailcrm' => $this->getApiPaymentTypes($retailcrm_api_client) ); } /** * Get all custom fields - * + * * @return array */ - public function getCustomFields() + public function getCustomFields($retailcrm_api_client) { return array( 'opencart' => $this->getOpencartCustomFields(), - 'retailcrm' => $this->getApiCustomFields() + 'retailcrm' => $this->getApiCustomFields($retailcrm_api_client) ); } /** * Get opencart order statuses - * + * * @return array */ public function getOpercartOrderStatuses() @@ -100,7 +79,7 @@ class ModelExtensionRetailcrmReferences extends Model /** * Get opencart payment types - * + * * @return array */ public function getOpercartPaymentTypes() @@ -113,7 +92,7 @@ class ModelExtensionRetailcrmReferences extends Model $extension = basename($file, '.php'); $this->load->language('extension/payment/' . $extension); - + if (version_compare(VERSION, '3.0', '<')) { $configStatus = $extension . '_status'; } else { @@ -133,80 +112,80 @@ class ModelExtensionRetailcrmReferences extends Model /** * Get opencart custom fields - * + * * @return array */ public function getOpencartCustomFields() { $this->load->model('customer/custom_field'); - + return $this->model_customer_custom_field->getCustomFields(); } /** * Get RetailCRM delivery types - * + * * @return array */ - public function getApiDeliveryTypes() + public function getApiDeliveryTypes($retailcrm_api_client) { - $response = $this->retailcrmApiClient->deliveryTypesList(); + $response = $retailcrm_api_client->deliveryTypesList(); return (!$response->isSuccessful()) ? array() : $response->deliveryTypes; } /** * Get RetailCRM order statuses - * + * * @return array */ - public function getApiOrderStatuses() + public function getApiOrderStatuses($retailcrm_api_client) { - $response = $this->retailcrmApiClient->statusesList(); + $response = $retailcrm_api_client->statusesList(); return (!$response->isSuccessful()) ? array() : $response->statuses; } /** * Get RetailCRM payment types - * + * * @return array */ - public function getApiPaymentTypes() + public function getApiPaymentTypes($retailcrm_api_client) { - $response = $this->retailcrmApiClient->paymentTypesList(); + $response = $retailcrm_api_client->paymentTypesList(); return (!$response->isSuccessful()) ? array() : $response->paymentTypes; } /** * Get RetailCRM custom fields - * + * * @return array */ - public function getApiCustomFields() + public function getApiCustomFields($retailcrm_api_client) { - $customers = $this->retailcrmApiClient->customFieldsList(array('entity' => 'customer')); - $orders = $this->retailcrmApiClient->customFieldsList(array('entity' => 'order')); + $customers = $retailcrm_api_client->customFieldsList(array('entity' => 'customer')); + $orders = $retailcrm_api_client->customFieldsList(array('entity' => 'order')); - $customFieldsCustomers = (!$customers->isSuccessful()) ? array() : $customers->customFields; - $customFieldsOrders = (!$orders->isSuccessful()) ? array() : $orders->customFields; + $custom_fields_customers = (!$customers->isSuccessful()) ? array() : $customers->customFields; + $custom_fields_orders = (!$orders->isSuccessful()) ? array() : $orders->customFields; - if (!$customFieldsCustomers && !$customFieldsOrders) { + if (!$custom_fields_customers && !$custom_fields_orders) { return array(); } - - return array('customers' => $customFieldsCustomers, 'orders' => $customFieldsOrders); + + return array('customers' => $custom_fields_customers, 'orders' => $custom_fields_orders); } /** * Get RetailCRM price types - * + * * @return array */ - public function getPriceTypes() + public function getPriceTypes($retailcrm_api_client) { - $response = $this->retailcrmApiClient->priceTypesList(); + $response = $retailcrm_api_client->priceTypesList(); return (!$response->isSuccessful()) ? array() : $response->priceTypes; } diff --git a/src/upload/admin/view/stylesheet/retailcrm.css b/src/upload/admin/view/stylesheet/retailcrm.css index fba27ff..34a1123 100644 --- a/src/upload/admin/view/stylesheet/retailcrm.css +++ b/src/upload/admin/view/stylesheet/retailcrm.css @@ -1,5 +1,5 @@ .retailcrm_unit {margin-bottom: 10px;} -.retailcrm_unit input {width: 30%;} +.retailcrm_unit input {width: 60%;} .checkbox input{width: auto;} .retailcrm_unit input[type=checkbox] {width: 13px;} .retailcrm_unit select {max-width: 500px;} \ No newline at end of file diff --git a/src/upload/admin/view/template/extension/module/retailcrm.tpl b/src/upload/admin/view/template/extension/module/retailcrm.tpl deleted file mode 100644 index 5adffdf..0000000 --- a/src/upload/admin/view/template/extension/module/retailcrm.tpl +++ /dev/null @@ -1,600 +0,0 @@ - -
- -
- -
- - -
- - - - -
-
-
- -
-
- -
- -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
- -
- -
-
- -
- -
- -
-
-
-
- - - -
- - -
- -
- -
-
-
- -
-
- -
-
-
-
-
- -
- -
- -
- -
-
-
- -
- -
- -
- - -
-
-
-
-
-
- -
- -
-
- - -
-
- - $val): ?> -
-
- -
-
- -
-
- -
- - -
- - -
- -
-
-
-
- -
- - -
-
- -
-
- -
-
- -
-
-
- -
- $value): ?> -
-
- -
-
- -
-
- -
-
-
- -
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-
- -
-
-
-
-
-
-
- -
-
-
- -
-
-
-
-
- - -
-
-
- -
- -
- - -
-
-
- -
- -
-
-
- -
- - -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- - -
-
- $label) : ?> -
- -
-
-
- -
-
- /> - -
-
-
-
- -
-
- -
-
- - -
- -
- - -
-
-
- -
-
- -
-
- -
- -
- -
-
- -
-
-
-
- -
-
- -
-
- -
- -
- -
-
- -
-
-
- -
- - -
- -
- - -
- -
- - -
- -
-
- -
-
- Retailcrm API error log -
- -
- -
-
- -
-
- -
- -
- -
-
- Opencart API error log -
- -
- -
-
- -
-
- -
- -
- -
-
-
-
-
-
-
-
- - - diff --git a/src/upload/admin/view/template/extension/module/retailcrm.twig b/src/upload/admin/view/template/extension/module/retailcrm.twig index 25062be..75561c4 100644 --- a/src/upload/admin/view/template/extension/module/retailcrm.twig +++ b/src/upload/admin/view/template/extension/module/retailcrm.twig @@ -2,19 +2,19 @@
@@ -35,14 +35,14 @@
@@ -50,8 +50,8 @@
{{ retailcrm_base_settings }} -
- +
+
-
- +
+
-
- +
+
@@ -75,10 +75,10 @@
{{ retailcrm_countries_settings }} -
- +
+
-
+
{% for country in countries %}