mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-02 19:33:14 +03:00
Add CS Fixer
This commit is contained in:
parent
c927b29378
commit
f9a730208a
12
.github/workflows/lint.yml
vendored
Normal file
12
.github/workflows/lint.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
on: [push, pull_request]
|
||||||
|
name: Main
|
||||||
|
jobs:
|
||||||
|
php-cs-fixer:
|
||||||
|
name: PHP-CS-Fixer
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: PHP-CS-Fixer
|
||||||
|
uses: docker://oskarstark/php-cs-fixer-ga
|
||||||
|
with:
|
||||||
|
args: --config=.php-cs-fixer.php --dry-run --using-cache=no -v --diff
|
76
.php-cs-fixer.php
Normal file
76
.php-cs-fixer.php
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
ini_set('memory_limit','256M');
|
||||||
|
|
||||||
|
$finder = PhpCsFixer\Finder::create()->in([
|
||||||
|
__DIR__.'/retailcrm',
|
||||||
|
__DIR__.'/tests',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return (new PhpCsFixer\Config())
|
||||||
|
->setRiskyAllowed(true)
|
||||||
|
->setRules([
|
||||||
|
'@Symfony' => true,
|
||||||
|
'@Symfony:risky' => true,
|
||||||
|
'psr_autoloading' => false,
|
||||||
|
'array_indentation' => true,
|
||||||
|
'cast_spaces' => [
|
||||||
|
'space' => 'single',
|
||||||
|
],
|
||||||
|
'yoda_style' => [
|
||||||
|
'equal' => true,
|
||||||
|
'identical' => true,
|
||||||
|
'less_and_greater' => true
|
||||||
|
],
|
||||||
|
|
||||||
|
'date_time_immutable' => true,
|
||||||
|
'combine_consecutive_issets' => true,
|
||||||
|
'concat_space' => [
|
||||||
|
'spacing' => 'one',
|
||||||
|
],
|
||||||
|
'error_suppression' => [
|
||||||
|
'mute_deprecation_error' => false,
|
||||||
|
'noise_remaining_usages' => false,
|
||||||
|
'noise_remaining_usages_exclude' => [],
|
||||||
|
],
|
||||||
|
'function_to_constant' => false,
|
||||||
|
'method_chaining_indentation' => true,
|
||||||
|
'no_alias_functions' => false,
|
||||||
|
'no_superfluous_phpdoc_tags' => false,
|
||||||
|
'non_printable_character' => [
|
||||||
|
'use_escape_sequences_in_strings' => true,
|
||||||
|
],
|
||||||
|
'phpdoc_align' => [
|
||||||
|
'align' => 'left',
|
||||||
|
],
|
||||||
|
'phpdoc_summary' => false,
|
||||||
|
'protected_to_private' => false,
|
||||||
|
'self_accessor' => false,
|
||||||
|
'single_line_throw' => false,
|
||||||
|
'no_alias_language_construct_call' => false,
|
||||||
|
'visibility_required' => false,
|
||||||
|
'ordered_imports' => true,
|
||||||
|
'global_namespace_import' => [
|
||||||
|
'import_classes' => false,
|
||||||
|
'import_constants' => false,
|
||||||
|
'import_functions' => false,
|
||||||
|
],
|
||||||
|
'native_constant_invocation' => false,
|
||||||
|
'native_function_invocation' => false,
|
||||||
|
'modernize_types_casting' => true,
|
||||||
|
'is_null' => true,
|
||||||
|
'operator_linebreak' => [
|
||||||
|
'only_booleans' => true,
|
||||||
|
'position' => 'beginning',
|
||||||
|
],
|
||||||
|
'ternary_to_null_coalescing' => false,
|
||||||
|
'array_syntax' => [
|
||||||
|
'syntax' => 'short',
|
||||||
|
],
|
||||||
|
'phpdoc_annotation_without_dot' => false,
|
||||||
|
'logical_operators' => true,
|
||||||
|
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
|
||||||
|
'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
|
||||||
|
|
||||||
|
])
|
||||||
|
->setFinder($finder);
|
4
Makefile
4
Makefile
@ -52,6 +52,10 @@ else
|
|||||||
&& bash travis-scripts/install-prestashop.sh
|
&& bash travis-scripts/install-prestashop.sh
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
lint:
|
||||||
|
php-cs-fixer fix --config=$(ROOT_DIR)/.php-cs-fixer.php -v
|
||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
ifeq ($(COMPOSERV1),1)
|
ifeq ($(COMPOSERV1),1)
|
||||||
cd $(PRESTASHOP_DIR) \
|
cd $(PRESTASHOP_DIR) \
|
||||||
|
@ -43,9 +43,7 @@
|
|||||||
* where this class resides. Additional options can be provided to control the naming
|
* where this class resides. Additional options can be provided to control the naming
|
||||||
* convention of the class files.
|
* convention of the class files.
|
||||||
*
|
*
|
||||||
* @package Autoloader
|
|
||||||
* @license http://opensource.org/licenses/MIT MIT License
|
* @license http://opensource.org/licenses/MIT MIT License
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class RetailcrmAutoloader
|
class RetailcrmAutoloader
|
||||||
{
|
{
|
||||||
@ -56,13 +54,11 @@ class RetailcrmAutoloader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The top level directory where recursion will begin.
|
* The top level directory where recursion will begin.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
protected static $pathTop;
|
protected static $pathTop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The top level directory where recursion for custom classes will begin.
|
* The top level directory where recursion for custom classes will begin.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
protected static $pathTopCustom;
|
protected static $pathTopCustom;
|
||||||
|
|
||||||
@ -142,7 +138,7 @@ class RetailcrmAutoloader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RetailcrmAutoloader::setPath(realpath(dirname(__FILE__)));
|
RetailcrmAutoloader::setPath(realpath(__DIR__));
|
||||||
RetailcrmAutoloader::setPathCustom(realpath(_PS_MODULE_DIR_ . '/retailcrm/custom'));
|
RetailcrmAutoloader::setPathCustom(realpath(_PS_MODULE_DIR_ . '/retailcrm/custom'));
|
||||||
RetailcrmAutoloader::setFileExt('.php');
|
RetailcrmAutoloader::setFileExt('.php');
|
||||||
spl_autoload_register('RetailcrmAutoloader::loader');
|
spl_autoload_register('RetailcrmAutoloader::loader');
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(ticks = 1);
|
declare(ticks=1);
|
||||||
|
|
||||||
if (!isset($_SERVER['REQUEST_METHOD'])) {
|
if (!isset($_SERVER['REQUEST_METHOD'])) {
|
||||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
@ -46,7 +46,7 @@ if (!isset($_SERVER['REMOTE_ADDR'])) {
|
|||||||
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';
|
$_SERVER['REMOTE_ADDR'] = '0.0.0.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once dirname(__FILE__) . '/lib/RetailcrmCli.php';
|
require_once __DIR__ . '/lib/RetailcrmCli.php';
|
||||||
|
|
||||||
function retailcrmCliInterruptHandler($signo)
|
function retailcrmCliInterruptHandler($signo)
|
||||||
{
|
{
|
||||||
@ -59,9 +59,9 @@ function retailcrmCliInterruptHandler($signo)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (php_sapi_name() == 'cli') {
|
if ('cli' == php_sapi_name()) {
|
||||||
$cli = new RetailcrmCli(__FILE__);
|
$cli = new RetailcrmCli(__FILE__);
|
||||||
$cli->execute('retailcrmCliInterruptHandler');
|
$cli->execute('retailcrmCliInterruptHandler');
|
||||||
} else {
|
} else {
|
||||||
include_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'index.php';
|
include_once __DIR__ . DIRECTORY_SEPARATOR . 'index.php';
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class RetailcrmConsultantModuleFrontController extends ModuleFrontController
|
class RetailcrmConsultantModuleFrontController extends ModuleFrontController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -80,7 +79,8 @@ class RetailcrmConsultantModuleFrontController extends ModuleFrontController
|
|||||||
$rcctExtractor = new RetailcrmCachedSettingExtractor();
|
$rcctExtractor = new RetailcrmCachedSettingExtractor();
|
||||||
$rcct = $rcctExtractor
|
$rcct = $rcctExtractor
|
||||||
->setCachedAndConfigKey(RetailCRM::CONSULTANT_RCCT)
|
->setCachedAndConfigKey(RetailCRM::CONSULTANT_RCCT)
|
||||||
->getData();
|
->getData()
|
||||||
|
;
|
||||||
|
|
||||||
if (empty($rcct)) {
|
if (empty($rcct)) {
|
||||||
$script = trim(Configuration::get(RetailCRM::CONSULTANT_SCRIPT));
|
$script = trim(Configuration::get(RetailCRM::CONSULTANT_SCRIPT));
|
||||||
@ -95,6 +95,6 @@ class RetailcrmConsultantModuleFrontController extends ModuleFrontController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array('rcct' => empty($rcct) ? '' : $rcct);
|
return ['rcct' => empty($rcct) ? '' : $rcct];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class RetailcrmDaemonCollectorModuleFrontController extends ModuleFrontController
|
class RetailcrmDaemonCollectorModuleFrontController extends ModuleFrontController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -83,7 +82,7 @@ class RetailcrmDaemonCollectorModuleFrontController extends ModuleFrontControlle
|
|||||||
$siteKey = Configuration::get(RetailCRM::COLLECTOR_KEY);
|
$siteKey = Configuration::get(RetailCRM::COLLECTOR_KEY);
|
||||||
$collectorConfigured = $isActive && $siteKey;
|
$collectorConfigured = $isActive && $siteKey;
|
||||||
|
|
||||||
$params = array('siteKey' => !$collectorConfigured ? '' : $siteKey);
|
$params = ['siteKey' => !$collectorConfigured ? '' : $siteKey];
|
||||||
|
|
||||||
if ($collectorConfigured && !empty($this->context->customer) && $this->context->customer->id) {
|
if ($collectorConfigured && !empty($this->context->customer) && $this->context->customer->id) {
|
||||||
$params['customerId'] = $this->context->customer->id;
|
$params['customerId'] = $this->context->customer->id;
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class RetailcrmJobsModuleFrontController extends ModuleFrontController
|
class RetailcrmJobsModuleFrontController extends ModuleFrontController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -81,6 +80,6 @@ class RetailcrmJobsModuleFrontController extends ModuleFrontController
|
|||||||
RetailcrmTools::startJobManager();
|
RetailcrmTools::startJobManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
return array('success' => true);
|
return ['success' => true];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -47,6 +47,6 @@ abstract class RetailcrmAbstractBuilder
|
|||||||
*/
|
*/
|
||||||
protected function arrayValue($key, $default = '--')
|
protected function arrayValue($key, $default = '--')
|
||||||
{
|
{
|
||||||
return isset($this->dataCrm[$key]) && !empty($this->dataCrm[$key]) ? $this->dataCrm[$key] : $default;
|
return isset($this->dataCrm[$key]) && !empty($this->dataCrm[$key]) ? $this->dataCrm[$key] : $default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
abstract class RetailcrmAbstractDataBuilder
|
abstract class RetailcrmAbstractDataBuilder
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var mixed $data Any data type (depends on the builder)
|
* @var mixed Any data type (depends on the builder)
|
||||||
*/
|
*/
|
||||||
protected $data;
|
protected $data;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ abstract class RetailcrmAbstractDataBuilder
|
|||||||
return RetailcrmTools::clearArray((array) $this->data);
|
return RetailcrmTools::clearArray((array) $this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,7 +52,6 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
*/
|
*/
|
||||||
const MODE_ORDER_DELIVERY = 2;
|
const MODE_ORDER_DELIVERY = 2;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Divider for order delivery addressline1 and addressline 2
|
* Divider for order delivery addressline1 and addressline 2
|
||||||
*/
|
*/
|
||||||
@ -91,6 +90,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
public function setAddress($address)
|
public function setAddress($address)
|
||||||
{
|
{
|
||||||
$this->address = $address;
|
$this->address = $address;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +102,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
public function setIsMain($isMain)
|
public function setIsMain($isMain)
|
||||||
{
|
{
|
||||||
$this->isMain = $isMain;
|
$this->isMain = $isMain;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +114,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
public function setMode($mode)
|
public function setMode($mode)
|
||||||
{
|
{
|
||||||
$this->mode = $mode;
|
$this->mode = $mode;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +126,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
public function setWithExternalId($withExternalId)
|
public function setWithExternalId($withExternalId)
|
||||||
{
|
{
|
||||||
$this->withExternalId = $withExternalId;
|
$this->withExternalId = $withExternalId;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +138,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
public function setExternalIdSuffix($externalIdSuffix)
|
public function setExternalIdSuffix($externalIdSuffix)
|
||||||
{
|
{
|
||||||
$this->externalIdSuffix = $externalIdSuffix;
|
$this->externalIdSuffix = $externalIdSuffix;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +150,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
public function setAddressId($addressId)
|
public function setAddressId($addressId)
|
||||||
{
|
{
|
||||||
$this->address = new Address($addressId);
|
$this->address = new Address($addressId);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +163,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
{
|
{
|
||||||
parent::reset();
|
parent::reset();
|
||||||
|
|
||||||
$this->data = array();
|
$this->data = [];
|
||||||
$this->address = null;
|
$this->address = null;
|
||||||
$this->mode = static::MODE_CUSTOMER;
|
$this->mode = static::MODE_CUSTOMER;
|
||||||
$this->isMain = false;
|
$this->isMain = false;
|
||||||
@ -188,17 +193,17 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
$this->buildOrderNames();
|
$this->buildOrderNames();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new \InvalidArgumentException("Incorrect builder mode");
|
throw new \InvalidArgumentException('Incorrect builder mode');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->data = RetailcrmTools::filter(
|
$this->data = RetailcrmTools::filter(
|
||||||
'RetailcrmFilterProcessAddress',
|
'RetailcrmFilterProcessAddress',
|
||||||
$this->data,
|
$this->data,
|
||||||
array(
|
[
|
||||||
'address' => $this->address,
|
'address' => $this->address,
|
||||||
'mode' => $this->mode
|
'mode' => $this->mode,
|
||||||
));
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -226,7 +231,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -246,7 +251,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_filter(array(
|
return array_filter([
|
||||||
'index' => $this->address->postcode,
|
'index' => $this->address->postcode,
|
||||||
'city' => $this->address->city,
|
'city' => $this->address->city,
|
||||||
'countryIso' => Country::getIsoById($this->address->id_country),
|
'countryIso' => Country::getIsoById($this->address->id_country),
|
||||||
@ -256,8 +261,8 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
$this->address->address2,
|
$this->address->address2,
|
||||||
])),
|
])),
|
||||||
'notes' => $this->address->other,
|
'notes' => $this->address->other,
|
||||||
'region' => $state
|
'region' => $state,
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -266,11 +271,11 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
|
|||||||
private function buildCustomerPhones()
|
private function buildCustomerPhones()
|
||||||
{
|
{
|
||||||
if (!empty($this->address->phone_mobile)) {
|
if (!empty($this->address->phone_mobile)) {
|
||||||
$this->data['customer']['phones'][] = array('number'=> $this->address->phone_mobile);
|
$this->data['customer']['phones'][] = ['number' => $this->address->phone_mobile];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->address->phone)) {
|
if (!empty($this->address->phone)) {
|
||||||
$this->data['customer']['phones'][] = array('number'=> $this->address->phone);
|
$this->data['customer']['phones'][] = ['number' => $this->address->phone];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,4 +67,3 @@ interface RetailcrmBuilderInterface
|
|||||||
*/
|
*/
|
||||||
public function reset();
|
public function reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ class RetailcrmCachedSettingExtractor extends RetailcrmAbstractDataBuilder
|
|||||||
public function setCachedKey($cachedKey)
|
public function setCachedKey($cachedKey)
|
||||||
{
|
{
|
||||||
$this->cachedKey = $cachedKey;
|
$this->cachedKey = $cachedKey;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +75,7 @@ class RetailcrmCachedSettingExtractor extends RetailcrmAbstractDataBuilder
|
|||||||
public function setConfigKey($configKey)
|
public function setConfigKey($configKey)
|
||||||
{
|
{
|
||||||
$this->configKey = $configKey;
|
$this->configKey = $configKey;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +88,7 @@ class RetailcrmCachedSettingExtractor extends RetailcrmAbstractDataBuilder
|
|||||||
{
|
{
|
||||||
$this->setCachedKey($key);
|
$this->setCachedKey($key);
|
||||||
$this->setConfigKey($key);
|
$this->setConfigKey($key);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ class RetailcrmCartUploader
|
|||||||
*/
|
*/
|
||||||
public static function setSyncDelay($time)
|
public static function setSyncDelay($time)
|
||||||
{
|
{
|
||||||
if (is_numeric($time) && $time > 0) {
|
if (is_numeric($time) && 0 < $time) {
|
||||||
static::$syncDelay = (int)$time;
|
static::$syncDelay = (int) $time;
|
||||||
} else {
|
} else {
|
||||||
static::$syncDelay = 0;
|
static::$syncDelay = 0;
|
||||||
}
|
}
|
||||||
@ -101,12 +101,12 @@ class RetailcrmCartUploader
|
|||||||
public static function init()
|
public static function init()
|
||||||
{
|
{
|
||||||
static::$api = null;
|
static::$api = null;
|
||||||
static::$cartsIds = array();
|
static::$cartsIds = [];
|
||||||
static::$paymentTypes = array();
|
static::$paymentTypes = [];
|
||||||
static::$syncDelay = 0;
|
static::$syncDelay = 0;
|
||||||
static::$allowedUpdateInterval = 86400;
|
static::$allowedUpdateInterval = 86400;
|
||||||
static::$syncStatus = '';
|
static::$syncStatus = '';
|
||||||
static::$now = new \DateTime();
|
static::$now = new \DateTimeImmutable();
|
||||||
static::$context = Context::getContext();
|
static::$context = Context::getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class RetailcrmCartUploader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($cart->date_upd)) {
|
if (!empty($cart->date_upd)) {
|
||||||
$cartLastUpdateDate = \DateTime::createFromFormat('Y-m-d H:i:s', $cart->date_upd);
|
$cartLastUpdateDate = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $cart->date_upd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!static::isAbandonedCartShouldBeUpdated(
|
if (!static::isAbandonedCartShouldBeUpdated(
|
||||||
@ -160,7 +160,7 @@ class RetailcrmCartUploader
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (static::$api->ordersCreate($order) !== false) {
|
if (false !== static::$api->ordersCreate($order)) {
|
||||||
$cart->date_upd = date('Y-m-d H:i:s');
|
$cart->date_upd = date('Y-m-d H:i:s');
|
||||||
$cart->save();
|
$cart->save();
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ class RetailcrmCartUploader
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (static::$api->ordersEdit($order) !== false) {
|
if (false !== static::$api->ordersEdit($order)) {
|
||||||
static::registerAbandonedCartSync($cart->id);
|
static::registerAbandonedCartSync($cart->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,15 +219,15 @@ class RetailcrmCartUploader
|
|||||||
try {
|
try {
|
||||||
$currentCartTotal = $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
|
$currentCartTotal = $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);
|
||||||
|
|
||||||
if ($currentCartTotal == 0) {
|
if (0 == $currentCartTotal) {
|
||||||
$shouldBeUploaded = false;
|
$shouldBeUploaded = false;
|
||||||
}
|
}
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
RetailcrmLogger::writeCaller(
|
RetailcrmLogger::writeCaller(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
sprintf("Failure while trying to get cart total (cart id=%d)", $cart->id)
|
sprintf('Failure while trying to get cart total (cart id=%d)', $cart->id)
|
||||||
);
|
);
|
||||||
RetailcrmLogger::writeCaller(__METHOD__, "Error message and stacktrace will be printed below");
|
RetailcrmLogger::writeCaller(__METHOD__, 'Error message and stacktrace will be printed below');
|
||||||
RetailcrmLogger::writeCaller(__METHOD__, $exception->getMessage());
|
RetailcrmLogger::writeCaller(__METHOD__, $exception->getMessage());
|
||||||
RetailcrmLogger::writeNoCaller($exception->getTraceAsString());
|
RetailcrmLogger::writeNoCaller($exception->getTraceAsString());
|
||||||
|
|
||||||
@ -236,15 +236,15 @@ class RetailcrmCartUploader
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Don't upload empty cartsIds.
|
// Don't upload empty cartsIds.
|
||||||
if (count($cart->getProducts(true)) == 0 || !$shouldBeUploaded) {
|
if (0 == count($cart->getProducts(true)) || !$shouldBeUploaded) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
RetailcrmLogger::writeCaller(
|
RetailcrmLogger::writeCaller(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
sprintf("Failure while trying to get cart products (cart id=%d)", $cart->id)
|
sprintf('Failure while trying to get cart products (cart id=%d)', $cart->id)
|
||||||
);
|
);
|
||||||
RetailcrmLogger::writeCaller(__METHOD__, "Error message and stacktrace will be printed below");
|
RetailcrmLogger::writeCaller(__METHOD__, 'Error message and stacktrace will be printed below');
|
||||||
RetailcrmLogger::writeCaller(__METHOD__, $exception->getMessage());
|
RetailcrmLogger::writeCaller(__METHOD__, $exception->getMessage());
|
||||||
RetailcrmLogger::writeNoCaller($exception->getTraceAsString());
|
RetailcrmLogger::writeNoCaller($exception->getTraceAsString());
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ class RetailcrmCartUploader
|
|||||||
*/
|
*/
|
||||||
private static function buildCartOrder($cart, $cartExternalId)
|
private static function buildCartOrder($cart, $cartExternalId)
|
||||||
{
|
{
|
||||||
$order = array();
|
$order = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$order = RetailcrmOrderBuilder::buildCrmOrderFromCart(
|
$order = RetailcrmOrderBuilder::buildCrmOrderFromCart(
|
||||||
@ -318,7 +318,7 @@ class RetailcrmCartUploader
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return \DateTime::createFromFormat('Y-m-d H:i:s', $when);
|
return \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $when);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,12 +326,12 @@ class RetailcrmCartUploader
|
|||||||
*/
|
*/
|
||||||
private static function loadAbandonedCartsIds()
|
private static function loadAbandonedCartsIds()
|
||||||
{
|
{
|
||||||
$sql = 'SELECT c.id_cart, c.date_upd
|
$sql = 'SELECT c.id_cart, c.date_upd
|
||||||
FROM ' . _DB_PREFIX_ . 'cart AS c
|
FROM ' . _DB_PREFIX_ . 'cart AS c
|
||||||
LEFT JOIN ' . _DB_PREFIX_ . 'customer cus
|
LEFT JOIN ' . _DB_PREFIX_ . 'customer cus
|
||||||
ON
|
ON
|
||||||
c.id_customer = cus.id_customer
|
c.id_customer = cus.id_customer
|
||||||
WHERE c.id_customer != 0
|
WHERE c.id_customer != 0
|
||||||
AND cus.is_guest = 0
|
AND cus.is_guest = 0
|
||||||
' . Shop::addSqlRestriction(false, 'c') . '
|
' . Shop::addSqlRestriction(false, 'c') . '
|
||||||
AND TIME_TO_SEC(TIMEDIFF(\'' . pSQL(static::$now->format('Y-m-d H:i:s'))
|
AND TIME_TO_SEC(TIMEDIFF(\'' . pSQL(static::$now->format('Y-m-d H:i:s'))
|
||||||
@ -359,7 +359,7 @@ class RetailcrmCartUploader
|
|||||||
ob_clean();
|
ob_clean();
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
|
||||||
if (is_null($lastUploadDate) || is_null($lastUpdatedDate)) {
|
if (null === $lastUploadDate || null === $lastUpdatedDate) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,8 +374,8 @@ class RetailcrmCartUploader
|
|||||||
private static function validateState()
|
private static function validateState()
|
||||||
{
|
{
|
||||||
if (empty(static::$syncStatus)
|
if (empty(static::$syncStatus)
|
||||||
|| (count(static::$paymentTypes) < 1)
|
|| (1 > count(static::$paymentTypes))
|
||||||
|| is_null(static::$now)
|
|| null === static::$now
|
||||||
|| !static::$api
|
|| !static::$api
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
*/
|
*/
|
||||||
class RetailcrmCatalog
|
class RetailcrmCatalog
|
||||||
{
|
{
|
||||||
|
|
||||||
public $default_lang;
|
public $default_lang;
|
||||||
public $default_currency;
|
public $default_currency;
|
||||||
public $default_country;
|
public $default_country;
|
||||||
@ -49,11 +48,11 @@ class RetailcrmCatalog
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
$this->default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
||||||
$this->default_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT');
|
$this->default_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
|
||||||
$this->default_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
|
$this->default_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
|
||||||
|
|
||||||
$this->protocol = (Configuration::get('PS_SSL_ENABLED')) ? "https://" : "http://";
|
$this->protocol = (Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
|
||||||
$this->version = substr(_PS_VERSION_, 0, 3);
|
$this->version = substr(_PS_VERSION_, 0, 3);
|
||||||
$this->link = new Link();
|
$this->link = new Link();
|
||||||
$this->home_category = Configuration::get('PS_HOME_CATEGORY');
|
$this->home_category = Configuration::get('PS_HOME_CATEGORY');
|
||||||
@ -61,13 +60,13 @@ class RetailcrmCatalog
|
|||||||
|
|
||||||
public function getData()
|
public function getData()
|
||||||
{
|
{
|
||||||
return array($this->getCategories(), $this->getOffers());
|
return [$this->getCategories(), $this->getOffers()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCategories()
|
public function getCategories()
|
||||||
{
|
{
|
||||||
$categories = array();
|
$categories = [];
|
||||||
$categoriesIds = array();
|
$categoriesIds = [];
|
||||||
|
|
||||||
$types = Category::getCategories($this->default_lang, true, false);
|
$types = Category::getCategories($this->default_lang, true, false);
|
||||||
|
|
||||||
@ -76,19 +75,18 @@ class RetailcrmCatalog
|
|||||||
? $category['id'] : $category['id_category'];
|
? $category['id'] : $category['id_category'];
|
||||||
|
|
||||||
if (!self::isCategoryActive(new Category($categoryId))) {
|
if (!self::isCategoryActive(new Category($categoryId))) {
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$picture = $this->link->getCatImageLink($category['link_rewrite'], $categoryId, 'category_default');
|
$picture = $this->link->getCatImageLink($category['link_rewrite'], $categoryId, 'category_default');
|
||||||
|
|
||||||
$categoriesIds[] = $categoryId;
|
$categoriesIds[] = $categoryId;
|
||||||
$categories[] = array(
|
$categories[] = [
|
||||||
'id' => $categoryId,
|
'id' => $categoryId,
|
||||||
'parentId' => self::getParentCategoryId($categoryId, $category['id_parent']),
|
'parentId' => self::getParentCategoryId($categoryId, $category['id_parent']),
|
||||||
'name' => htmlspecialchars($category['name']),
|
'name' => htmlspecialchars($category['name']),
|
||||||
'picture' => $picture ? $this->protocol . $picture : ''
|
'picture' => $picture ? $this->protocol . $picture : '',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($categories as $key => $innerCategory) {
|
foreach ($categories as $key => $innerCategory) {
|
||||||
@ -136,7 +134,7 @@ class RetailcrmCatalog
|
|||||||
$start = 0;
|
$start = 0;
|
||||||
$count = self::getProductsCount($id_lang);
|
$count = self::getProductsCount($id_lang);
|
||||||
|
|
||||||
if ($count > 0)
|
if (0 < $count) {
|
||||||
do {
|
do {
|
||||||
$products = Product::getProducts($id_lang, $start, $limit, 'name', 'asc');
|
$products = Product::getProducts($id_lang, $start, $limit, 'name', 'asc');
|
||||||
|
|
||||||
@ -160,9 +158,9 @@ class RetailcrmCatalog
|
|||||||
if (empty($categoriesLeft)) {
|
if (empty($categoriesLeft)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$productsCount++;
|
++$productsCount;
|
||||||
|
|
||||||
if ($this->version == "1.3") {
|
if ('1.3' == $this->version) {
|
||||||
$available_for_order = $product['active'] && $product['quantity'];
|
$available_for_order = $product['active'] && $product['quantity'];
|
||||||
} else {
|
} else {
|
||||||
$available_for_order = $product['active'] && $product['available_for_order'];
|
$available_for_order = $product['active'] && $product['available_for_order'];
|
||||||
@ -194,7 +192,7 @@ class RetailcrmCatalog
|
|||||||
}
|
}
|
||||||
|
|
||||||
$weight = round($product['weight'], 2);
|
$weight = round($product['weight'], 2);
|
||||||
if ($weight === 0.0) {
|
if (0.0 === $weight) {
|
||||||
$weight = null;
|
$weight = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,8 +200,8 @@ class RetailcrmCatalog
|
|||||||
$height = round($product['height'], 3);
|
$height = round($product['height'], 3);
|
||||||
$depth = round($product['depth'], 3);
|
$depth = round($product['depth'], 3);
|
||||||
|
|
||||||
if ($width !== 0.0 && $height !== 0.0) {
|
if (0.0 !== $width && 0.0 !== $height) {
|
||||||
$dimensions = implode('/', array($depth, $width, $height));
|
$dimensions = implode('/', [$depth, $width, $height]);
|
||||||
} else {
|
} else {
|
||||||
$dimensions = null;
|
$dimensions = null;
|
||||||
}
|
}
|
||||||
@ -211,7 +209,7 @@ class RetailcrmCatalog
|
|||||||
$offers = Product::getProductAttributesIds($product['id_product']);
|
$offers = Product::getProductAttributesIds($product['id_product']);
|
||||||
|
|
||||||
if (!empty($offers)) {
|
if (!empty($offers)) {
|
||||||
$offersCount+= count($offers);
|
$offersCount += count($offers);
|
||||||
$productForCombination = new Product($product['id_product']);
|
$productForCombination = new Product($product['id_product']);
|
||||||
|
|
||||||
foreach ($offers as $offer) {
|
foreach ($offers as $offer) {
|
||||||
@ -238,10 +236,10 @@ class RetailcrmCatalog
|
|||||||
$pictures[] = $picture;
|
$pictures[] = $picture;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->version == "1.3") {
|
if ('1.3' == $this->version) {
|
||||||
$quantity = $product['quantity'];
|
$quantity = $product['quantity'];
|
||||||
} else {
|
} else {
|
||||||
$quantity = (int)StockAvailable::getQuantityAvailableByProduct($product['id_product'], $offer['id_product_attribute']);
|
$quantity = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product'], $offer['id_product_attribute']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$offerCombination = new Combination($offer['id_product_attribute']);
|
$offerCombination = new Combination($offer['id_product_attribute']);
|
||||||
@ -251,9 +249,9 @@ class RetailcrmCatalog
|
|||||||
: round($offerCombination->price, 2);
|
: round($offerCombination->price, 2);
|
||||||
|
|
||||||
$offerPrice = round($offerCombinationPrice, 2) + $price;
|
$offerPrice = round($offerCombinationPrice, 2) + $price;
|
||||||
$offerPrice = $offerPrice > 0 ? $offerPrice : $price;
|
$offerPrice = 0 < $offerPrice ? $offerPrice : $price;
|
||||||
|
|
||||||
if ($offerCombination->wholesale_price > 0) {
|
if (0 < $offerCombination->wholesale_price) {
|
||||||
$offerPurchasePrice = round($offerCombination->wholesale_price, 2);
|
$offerPurchasePrice = round($offerCombination->wholesale_price, 2);
|
||||||
} else {
|
} else {
|
||||||
$offerPurchasePrice = $purchasePrice;
|
$offerPurchasePrice = $purchasePrice;
|
||||||
@ -274,7 +272,7 @@ class RetailcrmCatalog
|
|||||||
'categoryId' => $categoriesLeft,
|
'categoryId' => $categoriesLeft,
|
||||||
'picture' => $pictures,
|
'picture' => $pictures,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'quantity' => $quantity > 0 ? $quantity : 0,
|
'quantity' => 0 < $quantity ? $quantity : 0,
|
||||||
'purchasePrice' => $offerPurchasePrice,
|
'purchasePrice' => $offerPurchasePrice,
|
||||||
'price' => round($offerPrice, 2),
|
'price' => round($offerPrice, 2),
|
||||||
'vendor' => $vendor,
|
'vendor' => $vendor,
|
||||||
@ -300,20 +298,20 @@ class RetailcrmCatalog
|
|||||||
$item,
|
$item,
|
||||||
[
|
[
|
||||||
'product' => $product,
|
'product' => $product,
|
||||||
'offer' => $offer
|
'offer' => $offer,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$offersCount++;
|
++$offersCount;
|
||||||
|
|
||||||
$covers = Image::getImages($id_lang, $product['id_product'], null);
|
$covers = Image::getImages($id_lang, $product['id_product'], null);
|
||||||
$pictures = $this->getPictures($covers, $product);
|
$pictures = $this->getPictures($covers, $product);
|
||||||
|
|
||||||
if ($this->version == "1.3") {
|
if ('1.3' == $this->version) {
|
||||||
$quantity = $product['quantity'];
|
$quantity = $product['quantity'];
|
||||||
} else {
|
} else {
|
||||||
$quantity = (int)StockAvailable::getQuantityAvailableByProduct($product['id_product']);
|
$quantity = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = [
|
$item = [
|
||||||
@ -325,7 +323,7 @@ class RetailcrmCatalog
|
|||||||
'categoryId' => $categoriesLeft,
|
'categoryId' => $categoriesLeft,
|
||||||
'picture' => $pictures,
|
'picture' => $pictures,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'quantity' => $quantity > 0 ? $quantity : 0,
|
'quantity' => 0 < $quantity ? $quantity : 0,
|
||||||
'purchasePrice' => round($purchasePrice, 2),
|
'purchasePrice' => round($purchasePrice, 2),
|
||||||
'price' => $price,
|
'price' => $price,
|
||||||
'vendor' => $vendor,
|
'vendor' => $vendor,
|
||||||
@ -339,14 +337,15 @@ class RetailcrmCatalog
|
|||||||
'RetailcrmFilterProcessOffer',
|
'RetailcrmFilterProcessOffer',
|
||||||
$item,
|
$item,
|
||||||
[
|
[
|
||||||
'product' => $product
|
'product' => $product,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$start += $limit;
|
$start += $limit;
|
||||||
} while ($start < $count && count($products) > 0);
|
} while ($start < $count && 0 < count($products));
|
||||||
|
}
|
||||||
|
|
||||||
RetailcrmCatalogHelper::setIcmlFileInfo($productsCount, $offersCount);
|
RetailcrmCatalogHelper::setIcmlFileInfo($productsCount, $offersCount);
|
||||||
}
|
}
|
||||||
@ -357,27 +356,26 @@ class RetailcrmCatalog
|
|||||||
foreach ($covers as $cover) {
|
foreach ($covers as $cover) {
|
||||||
$picture = $this->protocol . $this->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $cover['id_image'], 'large_default');
|
$picture = $this->protocol . $this->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $cover['id_image'], 'large_default');
|
||||||
|
|
||||||
if ($offers === false && $cover['cover']) {
|
if (false === $offers && $cover['cover']) {
|
||||||
array_unshift($pictures, $picture);
|
array_unshift($pictures, $picture);
|
||||||
} else {
|
} else {
|
||||||
$pictures[] = $picture;
|
$pictures[] = $picture;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pictures;
|
return $pictures;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getProductsCount(
|
private static function getProductsCount(
|
||||||
$id_lang,
|
$id_lang,
|
||||||
Context $context = null
|
Context $context = null
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
if (!$context) {
|
if (!$context) {
|
||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
$front = true;
|
$front = true;
|
||||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) {
|
if (!in_array($context->controller->controller_type, ['front', 'modulefront'])) {
|
||||||
$front = false;
|
$front = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,10 +383,10 @@ class RetailcrmCatalog
|
|||||||
FROM `' . _DB_PREFIX_ . 'product` p
|
FROM `' . _DB_PREFIX_ . 'product` p
|
||||||
' . Shop::addSqlAssociation('product', 'p') . '
|
' . Shop::addSqlAssociation('product', 'p') . '
|
||||||
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` ' . Shop::addSqlRestrictionOnLang('pl') . ')
|
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` ' . Shop::addSqlRestrictionOnLang('pl') . ')
|
||||||
WHERE pl.`id_lang` = ' . (int)$id_lang .
|
WHERE pl.`id_lang` = ' . (int) $id_lang .
|
||||||
($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '');
|
($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '');
|
||||||
|
|
||||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -452,5 +450,4 @@ class RetailcrmCatalog
|
|||||||
|
|
||||||
return $parentId;
|
return $parentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,14 +44,14 @@ class RetailcrmCatalogHelper
|
|||||||
{
|
{
|
||||||
$date = null;
|
$date = null;
|
||||||
$filePath = self::getIcmlFilePath();
|
$filePath = self::getIcmlFilePath();
|
||||||
if (!file_exists($filePath) || ($fileHandler = fopen($filePath, 'rb')) === false) {
|
if (!file_exists($filePath) || ($fileHandler = fopen($filePath, 'r')) === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($line = fgets($fileHandler)) {
|
while ($line = fgets($fileHandler)) {
|
||||||
if (strpos($line, 'yml_catalog date=') !== false) {
|
if (false !== strpos($line, 'yml_catalog date=')) {
|
||||||
preg_match_all('/date="([\d\- :]+)"/', $line, $matches);
|
preg_match_all('/date="([\d\- :]+)"/', $line, $matches);
|
||||||
if (count($matches) == 2) {
|
if (2 == count($matches)) {
|
||||||
$date = $matches[1][0];
|
$date = $matches[1][0];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -60,7 +60,7 @@ class RetailcrmCatalogHelper
|
|||||||
|
|
||||||
fclose($fileHandler);
|
fclose($fileHandler);
|
||||||
|
|
||||||
return DateTime::createFromFormat('Y-m-d H:i:s', $date);
|
return DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getIcmlFileLink()
|
public static function getIcmlFileLink()
|
||||||
@ -89,37 +89,37 @@ class RetailcrmCatalogHelper
|
|||||||
|
|
||||||
public static function getIcmlFileInfo()
|
public static function getIcmlFileInfo()
|
||||||
{
|
{
|
||||||
$icmlInfo = json_decode((string)Configuration::get(self::ICML_INFO_NAME), true);
|
$icmlInfo = json_decode((string) Configuration::get(self::ICML_INFO_NAME), true);
|
||||||
|
|
||||||
if ($icmlInfo === null || json_last_error() !== JSON_ERROR_NONE) {
|
if (null === $icmlInfo || JSON_ERROR_NONE !== json_last_error()) {
|
||||||
$icmlInfo = array();
|
$icmlInfo = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastGenerated = self::getIcmlFileDate();
|
$lastGenerated = self::getIcmlFileDate();
|
||||||
|
|
||||||
if ($lastGenerated === false) {
|
if (false === $lastGenerated) {
|
||||||
return $icmlInfo;
|
return $icmlInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
$icmlInfo['lastGenerated'] = $lastGenerated;
|
$icmlInfo['lastGenerated'] = $lastGenerated;
|
||||||
$now = new DateTime();
|
$now = new DateTimeImmutable();
|
||||||
/** @var DateInterval $diff */
|
/** @var DateInterval $diff */
|
||||||
$diff = $lastGenerated->diff($now);
|
$diff = $lastGenerated->diff($now);
|
||||||
|
|
||||||
$icmlInfo['lastGeneratedDiff'] = array(
|
$icmlInfo['lastGeneratedDiff'] = [
|
||||||
'days' => $diff->days,
|
'days' => $diff->days,
|
||||||
'hours' => $diff->h,
|
'hours' => $diff->h,
|
||||||
'minutes' => $diff->i
|
'minutes' => $diff->i,
|
||||||
);
|
];
|
||||||
|
|
||||||
$icmlInfo['isOutdated'] = (
|
$icmlInfo['isOutdated'] = (
|
||||||
$icmlInfo['lastGeneratedDiff']['days'] > 0
|
0 < $icmlInfo['lastGeneratedDiff']['days']
|
||||||
|| $icmlInfo['lastGeneratedDiff']['hours'] > 4
|
|| 4 < $icmlInfo['lastGeneratedDiff']['hours']
|
||||||
);
|
);
|
||||||
|
|
||||||
$api = RetailcrmTools::getApiClient();
|
$api = RetailcrmTools::getApiClient();
|
||||||
|
|
||||||
if ($api !== null) {
|
if (null !== $api) {
|
||||||
$reference = new RetailcrmReferences($api);
|
$reference = new RetailcrmReferences($api);
|
||||||
|
|
||||||
$site = $reference->getSite();
|
$site = $reference->getSite();
|
||||||
@ -134,7 +134,7 @@ class RetailcrmCatalogHelper
|
|||||||
|
|
||||||
public static function getIcmlFileInfoMultistore()
|
public static function getIcmlFileInfoMultistore()
|
||||||
{
|
{
|
||||||
return RetailcrmContextSwitcher::runInContext(array(self::class, 'getIcmlFileInfo'));
|
return RetailcrmContextSwitcher::runInContext([self::class, 'getIcmlFileInfo']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,10 +143,10 @@ class RetailcrmCatalogHelper
|
|||||||
*/
|
*/
|
||||||
public static function setIcmlFileInfo($productsCount, $offersCount)
|
public static function setIcmlFileInfo($productsCount, $offersCount)
|
||||||
{
|
{
|
||||||
$icmlInfo = array(
|
$icmlInfo = [
|
||||||
'productsCount' => $productsCount,
|
'productsCount' => $productsCount,
|
||||||
'offersCount' => $offersCount
|
'offersCount' => $offersCount,
|
||||||
);
|
];
|
||||||
Configuration::updateValue(self::ICML_INFO_NAME, (string)json_encode($icmlInfo));
|
Configuration::updateValue(self::ICML_INFO_NAME, (string) json_encode($icmlInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,13 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
|
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
|
||||||
date_default_timezone_set(@date_default_timezone_get());
|
date_default_timezone_set(@date_default_timezone_get());
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/../../../config/config.inc.php');
|
require_once __DIR__ . '/../../../config/config.inc.php';
|
||||||
require_once(dirname(__FILE__) . '/../../../init.php');
|
require_once __DIR__ . '/../../../init.php';
|
||||||
require_once(dirname(__FILE__) . '/../bootstrap.php');
|
require_once __DIR__ . '/../bootstrap.php';
|
||||||
|
|
||||||
if (!defined('_PS_VERSION_')) {
|
if (!defined('_PS_VERSION_')) {
|
||||||
exit;
|
exit;
|
||||||
@ -53,7 +52,8 @@ if (!defined('_PS_VERSION_')) {
|
|||||||
*
|
*
|
||||||
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
||||||
* @license GPL
|
* @license GPL
|
||||||
* @link https://retailcrm.ru
|
*
|
||||||
|
* @see https://retailcrm.ru
|
||||||
*/
|
*/
|
||||||
class RetailcrmCli
|
class RetailcrmCli
|
||||||
{
|
{
|
||||||
@ -98,16 +98,16 @@ class RetailcrmCli
|
|||||||
RetailcrmLogger::output('WARNING: cannot handle signals properly, force stop can cause problems!');
|
RetailcrmLogger::output('WARNING: cannot handle signals properly, force stop can cause problems!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$shortopts = "j:s:";
|
$shortopts = 'j:s:';
|
||||||
$longopts = array(
|
$longopts = [
|
||||||
"job:",
|
'job:',
|
||||||
"shop:",
|
'shop:',
|
||||||
"set-web-jobs:",
|
'set-web-jobs:',
|
||||||
"query-web-jobs",
|
'query-web-jobs',
|
||||||
"run-jobs",
|
'run-jobs',
|
||||||
"reset-job-manager",
|
'reset-job-manager',
|
||||||
"reset-all"
|
'reset-all',
|
||||||
);
|
];
|
||||||
|
|
||||||
$options = getopt($shortopts, $longopts);
|
$options = getopt($shortopts, $longopts);
|
||||||
$jobName = isset($options['j']) ? $options['j'] : (isset($options['job']) ? $options['job'] : null);
|
$jobName = isset($options['j']) ? $options['j'] : (isset($options['job']) ? $options['job'] : null);
|
||||||
@ -148,7 +148,7 @@ class RetailcrmCli
|
|||||||
*/
|
*/
|
||||||
private function setCleanupOnShutdown()
|
private function setCleanupOnShutdown()
|
||||||
{
|
{
|
||||||
RetailcrmJobManager::setCustomShutdownHandler(array($this, 'cleanupOnShutdown'));
|
RetailcrmJobManager::setCustomShutdownHandler([$this, 'cleanupOnShutdown']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,7 +184,7 @@ class RetailcrmCli
|
|||||||
* Prints error details
|
* Prints error details
|
||||||
*
|
*
|
||||||
* @param \Exception $exception
|
* @param \Exception $exception
|
||||||
* @param string $header
|
* @param string $header
|
||||||
*/
|
*/
|
||||||
private function printStack($exception, $header = 'Error while executing a job: ')
|
private function printStack($exception, $header = 'Error while executing a job: ')
|
||||||
{
|
{
|
||||||
@ -216,19 +216,19 @@ class RetailcrmCli
|
|||||||
RetailcrmLogger::output(sprintf('> php %s --query-web-jobs - Check web jobs status', $this->cliPath));
|
RetailcrmLogger::output(sprintf('> php %s --query-web-jobs - Check web jobs status', $this->cliPath));
|
||||||
RetailcrmLogger::output();
|
RetailcrmLogger::output();
|
||||||
RetailcrmLogger::output(
|
RetailcrmLogger::output(
|
||||||
"NOTICE: If you have MultiShop feature enabled, you can additionally " .
|
'NOTICE: If you have MultiShop feature enabled, you can additionally ' .
|
||||||
"specify shop id when manually running job: "
|
'specify shop id when manually running job: '
|
||||||
);
|
);
|
||||||
RetailcrmLogger::output("At default jobs are running for all active shops alternately.");
|
RetailcrmLogger::output('At default jobs are running for all active shops alternately.');
|
||||||
RetailcrmLogger::output();
|
RetailcrmLogger::output();
|
||||||
RetailcrmLogger::output(sprintf('> php %s -j <job name> -s <shop id> - Runs provided job for specified shop', $this->cliPath));
|
RetailcrmLogger::output(sprintf('> php %s -j <job name> -s <shop id> - Runs provided job for specified shop', $this->cliPath));
|
||||||
RetailcrmLogger::output(sprintf('> php %s --job <job name> --shop <shop id> - Runs provided job for specified shop', $this->cliPath));
|
RetailcrmLogger::output(sprintf('> php %s --job <job name> --shop <shop id> - Runs provided job for specified shop', $this->cliPath));
|
||||||
RetailcrmLogger::output();
|
RetailcrmLogger::output();
|
||||||
RetailcrmLogger::output(
|
RetailcrmLogger::output(
|
||||||
"WARNING: Commands below are dangerous and should be used only when " .
|
'WARNING: Commands below are dangerous and should be used only when ' .
|
||||||
"job manager or cli doesn't work properly."
|
"job manager or cli doesn't work properly."
|
||||||
);
|
);
|
||||||
RetailcrmLogger::output("Use them at your own risk.");
|
RetailcrmLogger::output('Use them at your own risk.');
|
||||||
RetailcrmLogger::output();
|
RetailcrmLogger::output();
|
||||||
RetailcrmLogger::output(sprintf(
|
RetailcrmLogger::output(sprintf(
|
||||||
'> php %s --reset-job-manager - Will reset job manager internal timers & current job name',
|
'> php %s --reset-job-manager - Will reset job manager internal timers & current job name',
|
||||||
@ -245,12 +245,13 @@ class RetailcrmCli
|
|||||||
* Sets new web jobs state
|
* Sets new web jobs state
|
||||||
*
|
*
|
||||||
* @param bool $state
|
* @param bool $state
|
||||||
* @param $shopId
|
* @param $shopId
|
||||||
*/
|
*/
|
||||||
private function setWebJobs($state, $shopId = null)
|
private function setWebJobs($state, $shopId = null)
|
||||||
{
|
{
|
||||||
if ($shopId === null) {
|
if (null === $shopId) {
|
||||||
RetailcrmLogger::output('You must specify shop id');
|
RetailcrmLogger::output('You must specify shop id');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,8 +270,9 @@ class RetailcrmCli
|
|||||||
*/
|
*/
|
||||||
private function queryWebJobs($shopId = null)
|
private function queryWebJobs($shopId = null)
|
||||||
{
|
{
|
||||||
if ($shopId === null) {
|
if (null === $shopId) {
|
||||||
RetailcrmLogger::output('You must specify shop id');
|
RetailcrmLogger::output('You must specify shop id');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,7 +354,7 @@ class RetailcrmCli
|
|||||||
*/
|
*/
|
||||||
public static function clearCurrentJob($job)
|
public static function clearCurrentJob($job)
|
||||||
{
|
{
|
||||||
if (is_null($job) || self::getCurrentJob() == $job) {
|
if (null === $job || self::getCurrentJob() == $job) {
|
||||||
return Configuration::deleteByName(self::CURRENT_TASK_CLI);
|
return Configuration::deleteByName(self::CURRENT_TASK_CLI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +386,7 @@ class RetailcrmCli
|
|||||||
*/
|
*/
|
||||||
private function getAllowedJobs()
|
private function getAllowedJobs()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'RetailcrmAbandonedCartsEvent',
|
'RetailcrmAbandonedCartsEvent',
|
||||||
'RetailcrmIcmlEvent',
|
'RetailcrmIcmlEvent',
|
||||||
'RetailcrmIcmlUpdateUrlEvent',
|
'RetailcrmIcmlUpdateUrlEvent',
|
||||||
@ -392,7 +394,7 @@ class RetailcrmCli
|
|||||||
'RetailcrmInventoriesEvent',
|
'RetailcrmInventoriesEvent',
|
||||||
'RetailcrmExportEvent',
|
'RetailcrmExportEvent',
|
||||||
'RetailcrmUpdateSinceIdEvent',
|
'RetailcrmUpdateSinceIdEvent',
|
||||||
'RetailcrmClearLogsEvent'
|
'RetailcrmClearLogsEvent',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ class RetailcrmConsultantRcctExtractor extends RetailcrmAbstractDataBuilder
|
|||||||
{
|
{
|
||||||
$this->consultantScript = $consultantScript;
|
$this->consultantScript = $consultantScript;
|
||||||
$this->data = '';
|
$this->data = '';
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,16 +52,17 @@ class RetailcrmContextSwitcher
|
|||||||
*
|
*
|
||||||
* @param callable $callback
|
* @param callable $callback
|
||||||
* @param array $arguments Arguments that will be passed to callback function
|
* @param array $arguments Arguments that will be passed to callback function
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function runInContext($callback, $arguments = array())
|
public static function runInContext($callback, $arguments = [])
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = [];
|
||||||
self::storeContext();
|
self::storeContext();
|
||||||
|
|
||||||
foreach (self::getShops() as $shop) {
|
foreach (self::getShops() as $shop) {
|
||||||
self::setShopContext(intval($shop['id_shop']));
|
self::setShopContext((int) ($shop['id_shop']));
|
||||||
$result[intval($shop['id_shop'])] = call_user_func_array($callback, $arguments);
|
$result[(int) ($shop['id_shop'])] = call_user_func_array($callback, $arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
self::restoreContext();
|
self::restoreContext();
|
||||||
@ -98,7 +99,6 @@ class RetailcrmContextSwitcher
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Change shop in the context
|
* Change shop in the context
|
||||||
*
|
*
|
||||||
* @param $id_shop
|
* @param $id_shop
|
||||||
@ -120,10 +120,10 @@ class RetailcrmContextSwitcher
|
|||||||
{
|
{
|
||||||
$idShop = Shop::getContextShopID();
|
$idShop = Shop::getContextShopID();
|
||||||
|
|
||||||
if (Shop::isFeatureActive() && $idShop === null) {
|
if (Shop::isFeatureActive() && null === $idShop) {
|
||||||
return Shop::getShops(true, Shop::getContextShopGroupID(true));
|
return Shop::getShops(true, Shop::getContextShopGroupID(true));
|
||||||
} else {
|
} else {
|
||||||
return array(Shop::getShop($idShop));
|
return [Shop::getShop($idShop)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,32 +38,32 @@
|
|||||||
class RetailcrmCorporateCustomerBuilder extends RetailcrmAbstractBuilder implements RetailcrmBuilderInterface
|
class RetailcrmCorporateCustomerBuilder extends RetailcrmAbstractBuilder implements RetailcrmBuilderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Customer|CustomerCore $corporateCustomer Corporate customer
|
* @var Customer|CustomerCore Corporate customer
|
||||||
*/
|
*/
|
||||||
private $corporateCustomer;
|
private $corporateCustomer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var RetailcrmBuilderInterface $customerBuilder Customer builder
|
* @var RetailcrmBuilderInterface Customer builder
|
||||||
*/
|
*/
|
||||||
private $customerBuilder;
|
private $customerBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $dataCrm customerHistory
|
* @var array customerHistory
|
||||||
*/
|
*/
|
||||||
protected $dataCrm;
|
protected $dataCrm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $companyName
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $companyName;
|
private $companyName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $companyInn
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $companyInn;
|
protected $companyInn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Address|AddressCore $corporateAddress
|
* @var Address|AddressCore
|
||||||
*/
|
*/
|
||||||
private $corporateAddress;
|
private $corporateAddress;
|
||||||
|
|
||||||
@ -77,51 +77,61 @@ class RetailcrmCorporateCustomerBuilder extends RetailcrmAbstractBuilder impleme
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RetailcrmBuilderInterface $customerBuilder
|
* @param RetailcrmBuilderInterface $customerBuilder
|
||||||
|
*
|
||||||
* @return RetailcrmCorporateCustomerBuilder
|
* @return RetailcrmCorporateCustomerBuilder
|
||||||
*/
|
*/
|
||||||
public function setCustomerBuilder($customerBuilder)
|
public function setCustomerBuilder($customerBuilder)
|
||||||
{
|
{
|
||||||
$this->customerBuilder = $customerBuilder;
|
$this->customerBuilder = $customerBuilder;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Customer $corporateCustomer Corporate customer
|
* @param Customer $corporateCustomer Corporate customer
|
||||||
|
*
|
||||||
* @return RetailcrmCorporateCustomerBuilder
|
* @return RetailcrmCorporateCustomerBuilder
|
||||||
*/
|
*/
|
||||||
public function setCustomer($corporateCustomer)
|
public function setCustomer($corporateCustomer)
|
||||||
{
|
{
|
||||||
$this->corporateCustomer = $corporateCustomer;
|
$this->corporateCustomer = $corporateCustomer;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $companyName
|
* @param string $companyName
|
||||||
|
*
|
||||||
* @return RetailcrmCorporateCustomerBuilder
|
* @return RetailcrmCorporateCustomerBuilder
|
||||||
*/
|
*/
|
||||||
public function setCompanyName($companyName)
|
public function setCompanyName($companyName)
|
||||||
{
|
{
|
||||||
$this->companyName = $companyName;
|
$this->companyName = $companyName;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $companyInn
|
* @param string $companyInn
|
||||||
|
*
|
||||||
* @return RetailcrmCorporateCustomerBuilder
|
* @return RetailcrmCorporateCustomerBuilder
|
||||||
*/
|
*/
|
||||||
public function setCompanyInn($companyInn)
|
public function setCompanyInn($companyInn)
|
||||||
{
|
{
|
||||||
$this->companyInn = $companyInn;
|
$this->companyInn = $companyInn;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Address|AddressCore $corporateAddress
|
* @param Address|AddressCore $corporateAddress
|
||||||
|
*
|
||||||
* @return RetailcrmCorporateCustomerBuilder
|
* @return RetailcrmCorporateCustomerBuilder
|
||||||
*/
|
*/
|
||||||
public function setCorporateAddress($corporateAddress)
|
public function setCorporateAddress($corporateAddress)
|
||||||
{
|
{
|
||||||
$this->corporateAddress = $corporateAddress;
|
$this->corporateAddress = $corporateAddress;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +139,7 @@ class RetailcrmCorporateCustomerBuilder extends RetailcrmAbstractBuilder impleme
|
|||||||
* Set data in address, name and inn company corporate customer
|
* Set data in address, name and inn company corporate customer
|
||||||
*
|
*
|
||||||
* @param array $dataCrm
|
* @param array $dataCrm
|
||||||
|
*
|
||||||
* @return RetailcrmCorporateCustomerBuilder
|
* @return RetailcrmCorporateCustomerBuilder
|
||||||
*/
|
*/
|
||||||
public function extractCompanyDataFromOrder($dataCrm)
|
public function extractCompanyDataFromOrder($dataCrm)
|
||||||
@ -145,6 +156,7 @@ class RetailcrmCorporateCustomerBuilder extends RetailcrmAbstractBuilder impleme
|
|||||||
public function setDataCrm($dataCrm)
|
public function setDataCrm($dataCrm)
|
||||||
{
|
{
|
||||||
$this->dataCrm = $dataCrm;
|
$this->dataCrm = $dataCrm;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,15 +200,14 @@ class RetailcrmCorporateCustomerBuilder extends RetailcrmAbstractBuilder impleme
|
|||||||
$this->buildCustomer();
|
$this->buildCustomer();
|
||||||
|
|
||||||
if (!empty($this->corporateAddress)) {
|
if (!empty($this->corporateAddress)) {
|
||||||
|
if (empty($this->corporateAddress->alias) || 'default' == $this->corporateAddress->alias) {
|
||||||
if (empty($this->corporateAddress->alias) || $this->corporateAddress->alias == 'default') {
|
|
||||||
$this->corporateAddress->alias = '--';
|
$this->corporateAddress->alias = '--';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->corporateAddress->vat_number = !empty($this->companyInn) ? $this->companyInn : '';
|
$this->corporateAddress->vat_number = !empty($this->companyInn) ? $this->companyInn : '';
|
||||||
$this->corporateAddress->company = !empty($this->companyName) ? $this->companyName : '';
|
$this->corporateAddress->company = !empty($this->companyName) ? $this->companyName : '';
|
||||||
|
|
||||||
if (!empty($this->companyName) && (empty($this->corporateCustomer->firstname) || $this->corporateCustomer->firstname == '--')) {
|
if (!empty($this->companyName) && (empty($this->corporateCustomer->firstname) || '--' == $this->corporateCustomer->firstname)) {
|
||||||
$this->corporateCustomer->firstname = $this->companyName;
|
$this->corporateCustomer->firstname = $this->companyName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,18 +215,17 @@ class RetailcrmCorporateCustomerBuilder extends RetailcrmAbstractBuilder impleme
|
|||||||
$this->corporateCustomer = RetailcrmTools::filter(
|
$this->corporateCustomer = RetailcrmTools::filter(
|
||||||
'RetailcrmFilterSaveCorporateCustomer',
|
'RetailcrmFilterSaveCorporateCustomer',
|
||||||
$this->corporateCustomer,
|
$this->corporateCustomer,
|
||||||
array(
|
[
|
||||||
'dataCrm' => $this->dataCrm,
|
'dataCrm' => $this->dataCrm,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$this->corporateAddress = RetailcrmTools::filter(
|
$this->corporateAddress = RetailcrmTools::filter(
|
||||||
'RetailcrmFilterSaveCorporateCustomerAddress',
|
'RetailcrmFilterSaveCorporateCustomerAddress',
|
||||||
$this->corporateAddress,
|
$this->corporateAddress,
|
||||||
array(
|
[
|
||||||
'dataCrm' => $this->dataCrm,
|
'dataCrm' => $this->dataCrm,
|
||||||
));
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,32 +44,32 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
private $customerAddress;
|
private $customerAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $dataCrm
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $dataCrm;
|
private $dataCrm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int $idCustomer
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $idCustomer;
|
private $idCustomer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $firstName
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $firstName;
|
private $firstName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $lastName
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $lastName;
|
private $lastName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $phone
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $phone;
|
private $phone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $alias
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $alias;
|
private $alias;
|
||||||
|
|
||||||
@ -83,6 +83,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Address|AddressCore $customerAddress
|
* @param Address|AddressCore $customerAddress
|
||||||
|
*
|
||||||
* @return RetailcrmCustomerAddressBuilder
|
* @return RetailcrmCustomerAddressBuilder
|
||||||
*/
|
*/
|
||||||
public function setCustomerAddress($customerAddress)
|
public function setCustomerAddress($customerAddress)
|
||||||
@ -101,6 +102,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $idCustomer
|
* @param int $idCustomer
|
||||||
|
*
|
||||||
* @return RetailcrmCustomerAddressBuilder
|
* @return RetailcrmCustomerAddressBuilder
|
||||||
*/
|
*/
|
||||||
public function setIdCustomer($idCustomer)
|
public function setIdCustomer($idCustomer)
|
||||||
@ -112,6 +114,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $alias
|
* @param string $alias
|
||||||
|
*
|
||||||
* @return RetailcrmCustomerAddressBuilder
|
* @return RetailcrmCustomerAddressBuilder
|
||||||
*/
|
*/
|
||||||
public function setAlias($alias)
|
public function setAlias($alias)
|
||||||
@ -123,6 +126,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $firstName
|
* @param string $firstName
|
||||||
|
*
|
||||||
* @return RetailcrmCustomerAddressBuilder
|
* @return RetailcrmCustomerAddressBuilder
|
||||||
*/
|
*/
|
||||||
public function setFirstName($firstName)
|
public function setFirstName($firstName)
|
||||||
@ -134,6 +138,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $lastName
|
* @param string $lastName
|
||||||
|
*
|
||||||
* @return RetailcrmCustomerAddressBuilder
|
* @return RetailcrmCustomerAddressBuilder
|
||||||
*/
|
*/
|
||||||
public function setLastName($lastName)
|
public function setLastName($lastName)
|
||||||
@ -145,6 +150,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $phone
|
* @param string $phone
|
||||||
|
*
|
||||||
* @return RetailcrmCustomerAddressBuilder
|
* @return RetailcrmCustomerAddressBuilder
|
||||||
*/
|
*/
|
||||||
public function setPhone($phone)
|
public function setPhone($phone)
|
||||||
@ -160,7 +166,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
return $this->customerAddress;
|
return $this->customerAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset()
|
public function reset()
|
||||||
@ -211,9 +217,9 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
$this->customerAddress = RetailcrmTools::filter(
|
$this->customerAddress = RetailcrmTools::filter(
|
||||||
'RetailcrmFilterSaveCustomerAddress',
|
'RetailcrmFilterSaveCustomerAddress',
|
||||||
$this->customerAddress,
|
$this->customerAddress,
|
||||||
array(
|
[
|
||||||
'dataCrm' => $this->dataCrm
|
'dataCrm' => $this->dataCrm,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -225,7 +231,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
throw new InvalidArgumentException("Property $field not exist in the object");
|
throw new InvalidArgumentException("Property $field not exist in the object");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value !== null) {
|
if (null !== $value) {
|
||||||
$this->customerAddress->$field = $value;
|
$this->customerAddress->$field = $value;
|
||||||
} else {
|
} else {
|
||||||
$this->customerAddress->$field = $default;
|
$this->customerAddress->$field = $default;
|
||||||
@ -243,7 +249,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
|
|||||||
$addressLine = explode(RetailcrmAddressBuilder::ADDRESS_LINE_DIVIDER, $text, 2);
|
$addressLine = explode(RetailcrmAddressBuilder::ADDRESS_LINE_DIVIDER, $text, 2);
|
||||||
|
|
||||||
$this->setAddressField('address1', $addressLine[0], '--');
|
$this->setAddressField('address1', $addressLine[0], '--');
|
||||||
if (count($addressLine) == 1) {
|
if (1 == count($addressLine)) {
|
||||||
$this->setAddressField('address2', '');
|
$this->setAddressField('address2', '');
|
||||||
} else {
|
} else {
|
||||||
$this->setAddressField('address2', $addressLine[1], '');
|
$this->setAddressField('address2', $addressLine[1], '');
|
||||||
|
@ -37,16 +37,16 @@
|
|||||||
*/
|
*/
|
||||||
class RetailcrmCustomerBuilder extends RetailcrmAbstractBuilder implements RetailcrmBuilderInterface
|
class RetailcrmCustomerBuilder extends RetailcrmAbstractBuilder implements RetailcrmBuilderInterface
|
||||||
{
|
{
|
||||||
/** @var Customer|CustomerCore $customer Customer */
|
/** @var Customer|CustomerCore Customer */
|
||||||
private $customer;
|
private $customer;
|
||||||
|
|
||||||
/** @var Address|AddressCore|null $customerAddress Address */
|
/** @var Address|AddressCore|null Address */
|
||||||
private $customerAddress;
|
private $customerAddress;
|
||||||
|
|
||||||
/** @var array $dataCrm customerHistory */
|
/** @var array customerHistory */
|
||||||
protected $dataCrm;
|
protected $dataCrm;
|
||||||
|
|
||||||
/** @var RetailcrmBuilderInterface $addressBuilder Address builder */
|
/** @var RetailcrmBuilderInterface Address builder */
|
||||||
private $addressBuilder;
|
private $addressBuilder;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
@ -55,28 +55,33 @@ class RetailcrmCustomerBuilder extends RetailcrmAbstractBuilder implements Retai
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Customer|CustomerCore $customer
|
* @param Customer|CustomerCore $customer
|
||||||
|
*
|
||||||
* @return RetailcrmCustomerBuilder
|
* @return RetailcrmCustomerBuilder
|
||||||
*/
|
*/
|
||||||
public function setCustomer($customer)
|
public function setCustomer($customer)
|
||||||
{
|
{
|
||||||
$this->customer = $customer;
|
$this->customer = $customer;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RetailcrmBuilderInterface $addressBuilder
|
* @param RetailcrmBuilderInterface $addressBuilder
|
||||||
|
*
|
||||||
* @return RetailcrmCustomerBuilder
|
* @return RetailcrmCustomerBuilder
|
||||||
*/
|
*/
|
||||||
public function setAddressBuilder($addressBuilder)
|
public function setAddressBuilder($addressBuilder)
|
||||||
{
|
{
|
||||||
$this->addressBuilder = $addressBuilder;
|
$this->addressBuilder = $addressBuilder;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDataCrm($dataCrm)
|
public function setDataCrm($dataCrm)
|
||||||
{
|
{
|
||||||
$this->dataCrm = $dataCrm;
|
$this->dataCrm = $dataCrm;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +116,8 @@ class RetailcrmCustomerBuilder extends RetailcrmAbstractBuilder implements Retai
|
|||||||
->setLastName($this->arrayValue('lastName'))
|
->setLastName($this->arrayValue('lastName'))
|
||||||
->setPhone(isset($this->dataCrm['phones'][0]['number']) && !empty($this->dataCrm['phones'][0]['number'])
|
->setPhone(isset($this->dataCrm['phones'][0]['number']) && !empty($this->dataCrm['phones'][0]['number'])
|
||||||
? $this->dataCrm['phones'][0]['number'] : '')
|
? $this->dataCrm['phones'][0]['number'] : '')
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$this->customerAddress = $this->addressBuilder->getData();
|
$this->customerAddress = $this->addressBuilder->getData();
|
||||||
} else {
|
} else {
|
||||||
@ -128,7 +134,7 @@ class RetailcrmCustomerBuilder extends RetailcrmAbstractBuilder implements Retai
|
|||||||
$this->customer->firstname = $this->arrayValue('firstName');
|
$this->customer->firstname = $this->arrayValue('firstName');
|
||||||
$this->customer->lastname = $this->arrayValue('lastName');
|
$this->customer->lastname = $this->arrayValue('lastName');
|
||||||
|
|
||||||
if (isset($this->dataCrm['subscribed']) && $this->dataCrm['subscribed'] == false) {
|
if (isset($this->dataCrm['subscribed']) && false == $this->dataCrm['subscribed']) {
|
||||||
$this->customer->newsletter = false;
|
$this->customer->newsletter = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +145,7 @@ class RetailcrmCustomerBuilder extends RetailcrmAbstractBuilder implements Retai
|
|||||||
$this->customer->birthday = $this->arrayValue('birthday', '');
|
$this->customer->birthday = $this->arrayValue('birthday', '');
|
||||||
|
|
||||||
if (isset($this->dataCrm['sex'])) {
|
if (isset($this->dataCrm['sex'])) {
|
||||||
$this->customer->id_gender = $this->dataCrm['sex'] == 'male' ? 1 : 2;
|
$this->customer->id_gender = 'male' == $this->dataCrm['sex'] ? 1 : 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->buildAddress();
|
$this->buildAddress();
|
||||||
@ -150,18 +156,17 @@ class RetailcrmCustomerBuilder extends RetailcrmAbstractBuilder implements Retai
|
|||||||
$this->customer->email = RetailcrmTools::createPlaceholderEmail($this->arrayValue('firstName', microtime()));
|
$this->customer->email = RetailcrmTools::createPlaceholderEmail($this->arrayValue('firstName', microtime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($this->customer->passwd )) {
|
if (empty($this->customer->passwd)) {
|
||||||
$this->customer->passwd = Tools::substr(str_shuffle(Tools::strtolower(sha1(rand() . time()))), 0, 5);
|
$this->customer->passwd = Tools::substr(str_shuffle(Tools::strtolower(sha1(rand() . time()))), 0, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->customer = RetailcrmTools::filter(
|
$this->customer = RetailcrmTools::filter(
|
||||||
'RetailcrmFilterSaveCustomer',
|
'RetailcrmFilterSaveCustomer',
|
||||||
$this->customer,
|
$this->customer,
|
||||||
array(
|
[
|
||||||
'dataCrm' => $this->dataCrm,
|
'dataCrm' => $this->dataCrm,
|
||||||
));
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,10 +37,10 @@
|
|||||||
*/
|
*/
|
||||||
class RetailcrmCustomerBuilderResult
|
class RetailcrmCustomerBuilderResult
|
||||||
{
|
{
|
||||||
/** @var Customer|CustomerCore $customer */
|
/** @var Customer|CustomerCore */
|
||||||
private $customer;
|
private $customer;
|
||||||
|
|
||||||
/**@var Address|AddressCore|null $customerAddress */
|
/** @var Address|AddressCore|null */
|
||||||
private $customerAddress;
|
private $customerAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,4 +71,3 @@ class RetailcrmCustomerBuilderResult
|
|||||||
return $this->customerAddress;
|
return $this->customerAddress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,16 +38,16 @@
|
|||||||
class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \RetailcrmCustomerSwitcherState $data
|
* @var \RetailcrmCustomerSwitcherState
|
||||||
*/
|
*/
|
||||||
private $data;
|
private $data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \RetailcrmCustomerSwitcherResult|null $result
|
* @var \RetailcrmCustomerSwitcherResult|null
|
||||||
*/
|
*/
|
||||||
private $result;
|
private $result;
|
||||||
|
|
||||||
/** @var bool $isContact */
|
/** @var bool */
|
||||||
private $isContact;
|
private $isContact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,10 +75,10 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
if (!empty($newCustomer)) {
|
if (!empty($newCustomer)) {
|
||||||
RetailcrmLogger::writeDebugArray(
|
RetailcrmLogger::writeDebugArray(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array(
|
[
|
||||||
'Changing to individual customer for order',
|
'Changing to individual customer for order',
|
||||||
$this->data->getOrder()->id
|
$this->data->getOrder()->id,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
$this->isContact = false;
|
$this->isContact = false;
|
||||||
$this->processChangeToRegular($this->data->getOrder(), $newCustomer);
|
$this->processChangeToRegular($this->data->getOrder(), $newCustomer);
|
||||||
@ -90,10 +90,10 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
if (!empty($newContact)) {
|
if (!empty($newContact)) {
|
||||||
RetailcrmLogger::writeDebugArray(
|
RetailcrmLogger::writeDebugArray(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array(
|
[
|
||||||
'Changing to contact person customer for order',
|
'Changing to contact person customer for order',
|
||||||
$this->data->getOrder()->id
|
$this->data->getOrder()->id,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
$this->isContact = true;
|
$this->isContact = true;
|
||||||
$this->processChangeToRegular($this->data->getOrder(), $newContact);
|
$this->processChangeToRegular($this->data->getOrder(), $newContact);
|
||||||
@ -124,7 +124,7 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
* Change order customer to regular one
|
* Change order customer to regular one
|
||||||
*
|
*
|
||||||
* @param \Order $order
|
* @param \Order $order
|
||||||
* @param array $newCustomer
|
* @param array $newCustomer
|
||||||
*/
|
*/
|
||||||
protected function processChangeToRegular($order, $newCustomer)
|
protected function processChangeToRegular($order, $newCustomer)
|
||||||
{
|
{
|
||||||
@ -141,12 +141,12 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
|
|
||||||
RetailcrmLogger::writeDebugArray(
|
RetailcrmLogger::writeDebugArray(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array(
|
[
|
||||||
'Switching in order',
|
'Switching in order',
|
||||||
$order->id,
|
$order->id,
|
||||||
'to',
|
'to',
|
||||||
$newCustomer
|
$newCustomer,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($newCustomer['externalId'])) {
|
if (isset($newCustomer['externalId'])) {
|
||||||
@ -175,10 +175,10 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
$customer = $result->getCustomer();
|
$customer = $result->getCustomer();
|
||||||
$address = $this->getCustomerAddress($customer, $result->getCustomerAddress());
|
$address = $this->getCustomerAddress($customer, $result->getCustomerAddress());
|
||||||
|
|
||||||
RetailcrmLogger::writeDebugArray(__METHOD__, array('Result:', array(
|
RetailcrmLogger::writeDebugArray(__METHOD__, ['Result:', [
|
||||||
'customer' => RetailcrmTools::dumpEntity($customer),
|
'customer' => RetailcrmTools::dumpEntity($customer),
|
||||||
'address' => RetailcrmTools::dumpEntity($address)
|
'address' => RetailcrmTools::dumpEntity($address),
|
||||||
)));
|
]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->result = new RetailcrmCustomerSwitcherResult($customer, $address, $order);
|
$this->result = new RetailcrmCustomerSwitcherResult($customer, $address, $order);
|
||||||
@ -223,7 +223,8 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
->setPhone($billingPhone)
|
->setPhone($billingPhone)
|
||||||
->setAlias('--')
|
->setAlias('--')
|
||||||
->build()
|
->build()
|
||||||
->getData();
|
->getData()
|
||||||
|
;
|
||||||
$address->company = $this->data->getNewCompanyName();
|
$address->company = $this->data->getNewCompanyName();
|
||||||
RetailcrmTools::assignAddressIdsByFields($customer, $address);
|
RetailcrmTools::assignAddressIdsByFields($customer, $address);
|
||||||
}
|
}
|
||||||
@ -277,6 +278,7 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
{
|
{
|
||||||
$this->data = new RetailcrmCustomerSwitcherState();
|
$this->data = new RetailcrmCustomerSwitcherState();
|
||||||
$this->result = null;
|
$this->result = null;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,6 +312,7 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,20 +338,20 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
private function debugLogState()
|
private function debugLogState()
|
||||||
{
|
{
|
||||||
if (RetailcrmTools::isDebug()) {
|
if (RetailcrmTools::isDebug()) {
|
||||||
RetailcrmLogger::writeDebugArray(__METHOD__, array('state', array(
|
RetailcrmLogger::writeDebugArray(__METHOD__, ['state', [
|
||||||
'newCustomer' => $this->data->getNewCustomer(),
|
'newCustomer' => $this->data->getNewCustomer(),
|
||||||
'newContact' => $this->data->getNewContact(),
|
'newContact' => $this->data->getNewContact(),
|
||||||
'newCompanyName' => $this->data->getNewCompanyName(),
|
'newCompanyName' => $this->data->getNewCompanyName(),
|
||||||
'companyAddress' => $this->data->getCompanyAddress(),
|
'companyAddress' => $this->data->getCompanyAddress(),
|
||||||
'order' => RetailcrmTools::dumpEntity($this->data->getOrder()),
|
'order' => RetailcrmTools::dumpEntity($this->data->getOrder()),
|
||||||
)));
|
]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns placeholder address if customer hasn't one; returns address without any changes otherwise.
|
* Returns placeholder address if customer hasn't one; returns address without any changes otherwise.
|
||||||
*
|
*
|
||||||
* @param \Customer|\CustomerCore $customer
|
* @param \Customer|\CustomerCore $customer
|
||||||
* @param Address|\AddressCore|null $address
|
* @param Address|\AddressCore|null $address
|
||||||
*
|
*
|
||||||
* @return \Address|\AddressCore|array|mixed
|
* @return \Address|\AddressCore|array|mixed
|
||||||
@ -370,7 +373,7 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
* Process address fields for existing customer.
|
* Process address fields for existing customer.
|
||||||
*
|
*
|
||||||
* @param Customer|\CustomerCore $customer
|
* @param Customer|\CustomerCore $customer
|
||||||
* @param Address|\AddressCore $address
|
* @param Address|\AddressCore $address
|
||||||
*/
|
*/
|
||||||
private function processCustomerAddress($customer, $address)
|
private function processCustomerAddress($customer, $address)
|
||||||
{
|
{
|
||||||
@ -378,7 +381,7 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
$newCompany = $this->data->getNewCompanyName();
|
$newCompany = $this->data->getNewCompanyName();
|
||||||
RetailcrmLogger::writeDebug(__METHOD__, 'Processing address for a contact person');
|
RetailcrmLogger::writeDebug(__METHOD__, 'Processing address for a contact person');
|
||||||
|
|
||||||
if ($address->alias == '' || $address->alias == 'default') {
|
if ('' == $address->alias || 'default' == $address->alias) {
|
||||||
$address->alias = '--';
|
$address->alias = '--';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,20 +414,22 @@ class RetailcrmCustomerSwitcher implements RetailcrmBuilderInterface
|
|||||||
* Builds placeholder address for customer if he doesn't have address.
|
* Builds placeholder address for customer if he doesn't have address.
|
||||||
*
|
*
|
||||||
* @param \Customer $customer
|
* @param \Customer $customer
|
||||||
* @param string $alias
|
* @param string $alias
|
||||||
*
|
*
|
||||||
* @return \Address|\AddressCore|array|mixed
|
* @return \Address|\AddressCore|array|mixed
|
||||||
*/
|
*/
|
||||||
private function createPlaceholderAddress($customer, $alias = 'default')
|
private function createPlaceholderAddress($customer, $alias = 'default')
|
||||||
{
|
{
|
||||||
$addressBuilder = new RetailcrmCustomerAddressBuilder();
|
$addressBuilder = new RetailcrmCustomerAddressBuilder();
|
||||||
|
|
||||||
return $addressBuilder
|
return $addressBuilder
|
||||||
->setIdCustomer($customer->id)
|
->setIdCustomer($customer->id)
|
||||||
->setFirstName($customer->firstname)
|
->setFirstName($customer->firstname)
|
||||||
->setLastName($customer->lastname)
|
->setLastName($customer->lastname)
|
||||||
->setAlias($alias)
|
->setAlias($alias)
|
||||||
->build()
|
->build()
|
||||||
->getData();
|
->getData()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,12 +49,12 @@ class RetailcrmExport
|
|||||||
static $api;
|
static $api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var int
|
||||||
*/
|
*/
|
||||||
static $ordersOffset;
|
static $ordersOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var int
|
||||||
*/
|
*/
|
||||||
static $customersOffset;
|
static $customersOffset;
|
||||||
|
|
||||||
@ -75,12 +75,12 @@ class RetailcrmExport
|
|||||||
*/
|
*/
|
||||||
public static function getOrdersCount()
|
public static function getOrdersCount()
|
||||||
{
|
{
|
||||||
$sql = 'SELECT count(o.id_order)
|
$sql = 'SELECT count(o.id_order)
|
||||||
FROM `' . _DB_PREFIX_ . 'orders` o
|
FROM `' . _DB_PREFIX_ . 'orders` o
|
||||||
WHERE 1
|
WHERE 1
|
||||||
' . Shop::addSqlRestriction(false, 'o');
|
' . Shop::addSqlRestriction(false, 'o');
|
||||||
|
|
||||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,36 +90,39 @@ class RetailcrmExport
|
|||||||
* @param int|null $count Sets the count of orders to get from database
|
* @param int|null $count Sets the count of orders to get from database
|
||||||
*
|
*
|
||||||
* @return Generator
|
* @return Generator
|
||||||
|
*
|
||||||
* @throws PrestaShopDatabaseException
|
* @throws PrestaShopDatabaseException
|
||||||
*/
|
*/
|
||||||
public static function getOrdersIds($start = 0, $count = null)
|
public static function getOrdersIds($start = 0, $count = null)
|
||||||
{
|
{
|
||||||
if (is_null($count)) {
|
if (null === $count) {
|
||||||
$to = static::getOrdersCount();
|
$to = static::getOrdersCount();
|
||||||
$count = $to - $start;
|
$count = $to - $start;
|
||||||
} else {
|
} else {
|
||||||
$to = $start + $count;
|
$to = $start + $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($count > 0) {
|
if (0 < $count) {
|
||||||
$predefinedSql = 'SELECT o.`id_order`
|
$predefinedSql = 'SELECT o.`id_order`
|
||||||
FROM `' . _DB_PREFIX_ . 'orders` o
|
FROM `' . _DB_PREFIX_ . 'orders` o
|
||||||
WHERE 1
|
WHERE 1
|
||||||
' . Shop::addSqlRestriction(false, 'o') . '
|
' . Shop::addSqlRestriction(false, 'o') . '
|
||||||
ORDER BY o.`id_order` ASC';
|
ORDER BY o.`id_order` ASC';
|
||||||
|
|
||||||
while ($start < $to) {
|
while ($start < $to) {
|
||||||
$offset = ($start + static::$ordersOffset > $to) ? $to - $start : static::$ordersOffset;
|
$offset = ($start + static::$ordersOffset > $to) ? $to - $start : static::$ordersOffset;
|
||||||
if ($offset <= 0)
|
if (0 >= $offset) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$sql = $predefinedSql . '
|
$sql = $predefinedSql . '
|
||||||
LIMIT ' . (int)$start . ', ' . (int)$offset;
|
LIMIT ' . (int) $start . ', ' . (int) $offset;
|
||||||
|
|
||||||
$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||||
|
|
||||||
if (empty($orders))
|
if (empty($orders)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
yield $order;
|
yield $order;
|
||||||
@ -140,7 +143,7 @@ class RetailcrmExport
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$orders = array();
|
$orders = [];
|
||||||
$orderRecords = static::getOrdersIds($from, $count);
|
$orderRecords = static::getOrdersIds($from, $count);
|
||||||
$orderBuilder = new RetailcrmOrderBuilder();
|
$orderBuilder = new RetailcrmOrderBuilder();
|
||||||
$orderBuilder->defaultLangFromConfiguration()->setApi(static::$api);
|
$orderBuilder->defaultLangFromConfiguration()->setApi(static::$api);
|
||||||
@ -180,9 +183,9 @@ class RetailcrmExport
|
|||||||
|
|
||||||
time_nanosleep(0, 250000000);
|
time_nanosleep(0, 250000000);
|
||||||
|
|
||||||
if (count($orders) == 50) {
|
if (50 == count($orders)) {
|
||||||
static::$api->ordersUpload($orders);
|
static::$api->ordersUpload($orders);
|
||||||
$orders = array();
|
$orders = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +196,7 @@ class RetailcrmExport
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get total count of customers for context shop
|
* Get total count of customers for context shop
|
||||||
|
*
|
||||||
* @param bool $withOrders If set to <b>true</b>, then return total count of customers.
|
* @param bool $withOrders If set to <b>true</b>, then return total count of customers.
|
||||||
* If set to <b>false</b>, then return count of customers without orders
|
* If set to <b>false</b>, then return count of customers without orders
|
||||||
*
|
*
|
||||||
@ -200,7 +204,7 @@ class RetailcrmExport
|
|||||||
*/
|
*/
|
||||||
public static function getCustomersCount($withOrders = true)
|
public static function getCustomersCount($withOrders = true)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT count(c.id_customer)
|
$sql = 'SELECT count(c.id_customer)
|
||||||
FROM `' . _DB_PREFIX_ . 'customer` c
|
FROM `' . _DB_PREFIX_ . 'customer` c
|
||||||
WHERE 1
|
WHERE 1
|
||||||
' . Shop::addSqlRestriction(false, 'c');
|
' . Shop::addSqlRestriction(false, 'c');
|
||||||
@ -208,15 +212,15 @@ class RetailcrmExport
|
|||||||
if (!$withOrders) {
|
if (!$withOrders) {
|
||||||
$sql .= '
|
$sql .= '
|
||||||
AND c.id_customer not in (
|
AND c.id_customer not in (
|
||||||
select o.id_customer
|
select o.id_customer
|
||||||
from `' . _DB_PREFIX_ . 'orders` o
|
from `' . _DB_PREFIX_ . 'orders` o
|
||||||
WHERE 1
|
WHERE 1
|
||||||
' . Shop::addSqlRestriction(false, 'o') . '
|
' . Shop::addSqlRestriction(false, 'o') . '
|
||||||
group by o.id_customer
|
group by o.id_customer
|
||||||
)';
|
)';
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,18 +233,19 @@ class RetailcrmExport
|
|||||||
* @param bool $returnAddressId If set to <b>true</b>, then also return address id in <i>`id_address`</i>
|
* @param bool $returnAddressId If set to <b>true</b>, then also return address id in <i>`id_address`</i>
|
||||||
*
|
*
|
||||||
* @return Generator
|
* @return Generator
|
||||||
|
*
|
||||||
* @throws PrestaShopDatabaseException
|
* @throws PrestaShopDatabaseException
|
||||||
*/
|
*/
|
||||||
public static function getCustomersIds($start = 0, $count = null, $withOrders = true, $returnAddressId = true)
|
public static function getCustomersIds($start = 0, $count = null, $withOrders = true, $returnAddressId = true)
|
||||||
{
|
{
|
||||||
if (is_null($count)) {
|
if (null === $count) {
|
||||||
$to = static::getCustomersCount($withOrders);
|
$to = static::getCustomersCount($withOrders);
|
||||||
$count = $to - $start;
|
$count = $to - $start;
|
||||||
} else {
|
} else {
|
||||||
$to = $start + $count;
|
$to = $start + $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($count > 0) {
|
if (0 < $count) {
|
||||||
$predefinedSql = 'SELECT c.`id_customer`
|
$predefinedSql = 'SELECT c.`id_customer`
|
||||||
' . ($returnAddressId ? ', a.`id_address`' : '') . '
|
' . ($returnAddressId ? ', a.`id_address`' : '') . '
|
||||||
FROM `' . _DB_PREFIX_ . 'customer` c
|
FROM `' . _DB_PREFIX_ . 'customer` c
|
||||||
@ -274,27 +279,28 @@ class RetailcrmExport
|
|||||||
' . Shop::addSqlRestriction(false, 'c') .
|
' . Shop::addSqlRestriction(false, 'c') .
|
||||||
($withOrders ? '' : '
|
($withOrders ? '' : '
|
||||||
AND c.`id_customer` not in (
|
AND c.`id_customer` not in (
|
||||||
select o.`id_customer`
|
select o.`id_customer`
|
||||||
from `' . _DB_PREFIX_ . 'orders` o
|
from `' . _DB_PREFIX_ . 'orders` o
|
||||||
WHERE 1
|
WHERE 1
|
||||||
' . Shop::addSqlRestriction(false, 'o') . '
|
' . Shop::addSqlRestriction(false, 'o') . '
|
||||||
group by o.`id_customer`
|
group by o.`id_customer`
|
||||||
)') . '
|
)') . '
|
||||||
ORDER BY c.`id_customer` ASC';
|
ORDER BY c.`id_customer` ASC';
|
||||||
|
|
||||||
|
|
||||||
while ($start < $to) {
|
while ($start < $to) {
|
||||||
$offset = ($start + static::$customersOffset > $to) ? $to - $start : static::$customersOffset;
|
$offset = ($start + static::$customersOffset > $to) ? $to - $start : static::$customersOffset;
|
||||||
if ($offset <= 0)
|
if (0 >= $offset) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$sql = $predefinedSql . '
|
$sql = $predefinedSql . '
|
||||||
LIMIT ' . (int)$start . ', ' . (int)$offset;
|
LIMIT ' . (int) $start . ', ' . (int) $offset;
|
||||||
|
|
||||||
$customers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
$customers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||||
|
|
||||||
if (empty($customers))
|
if (empty($customers)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($customers as $customer) {
|
foreach ($customers as $customer) {
|
||||||
yield $customer;
|
yield $customer;
|
||||||
@ -315,7 +321,7 @@ class RetailcrmExport
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$customers = array();
|
$customers = [];
|
||||||
$customersRecords = RetailcrmExport::getCustomersIds($from, $count, false);
|
$customersRecords = RetailcrmExport::getCustomersIds($from, $count, false);
|
||||||
|
|
||||||
foreach ($customersRecords as $record) {
|
foreach ($customersRecords as $record) {
|
||||||
@ -332,9 +338,10 @@ class RetailcrmExport
|
|||||||
$address = $addressBuilder
|
$address = $addressBuilder
|
||||||
->setAddress($cmsAddress)
|
->setAddress($cmsAddress)
|
||||||
->build()
|
->build()
|
||||||
->getDataArray();
|
->getDataArray()
|
||||||
|
;
|
||||||
} else {
|
} else {
|
||||||
$address = array();
|
$address = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -345,9 +352,9 @@ class RetailcrmExport
|
|||||||
RetailcrmLogger::output($exception->getMessage());
|
RetailcrmLogger::output($exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($customers) == 50) {
|
if (50 == count($customers)) {
|
||||||
static::$api->customersUpload($customers);
|
static::$api->customersUpload($customers);
|
||||||
$customers = array();
|
$customers = [];
|
||||||
|
|
||||||
time_nanosleep(0, 250000000);
|
time_nanosleep(0, 250000000);
|
||||||
}
|
}
|
||||||
@ -360,9 +367,11 @@ class RetailcrmExport
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @param false $receiveOrderNumber
|
* @param false $receiveOrderNumber
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
* @throws PrestaShopObjectNotFoundExceptionCore
|
* @throws PrestaShopObjectNotFoundExceptionCore
|
||||||
* @throws PrestaShopDatabaseException
|
* @throws PrestaShopDatabaseException
|
||||||
* @throws PrestaShopException
|
* @throws PrestaShopException
|
||||||
@ -392,7 +401,8 @@ class RetailcrmExport
|
|||||||
->setApi(static::$api)
|
->setApi(static::$api)
|
||||||
->setCmsOrder($object)
|
->setCmsOrder($object)
|
||||||
->setCmsCustomer($customer)
|
->setCmsCustomer($customer)
|
||||||
->buildOrderWithPreparedCustomer();
|
->buildOrderWithPreparedCustomer()
|
||||||
|
;
|
||||||
|
|
||||||
if (empty($crmOrder)) {
|
if (empty($crmOrder)) {
|
||||||
return false;
|
return false;
|
||||||
@ -410,9 +420,9 @@ class RetailcrmExport
|
|||||||
$response = static::$api->ordersEdit($crmOrder);
|
$response = static::$api->ordersEdit($crmOrder);
|
||||||
|
|
||||||
if (empty($existingOrder['payments']) && !empty($crmOrder['payments'])) {
|
if (empty($existingOrder['payments']) && !empty($crmOrder['payments'])) {
|
||||||
$payment = array_merge(reset($crmOrder['payments']), array(
|
$payment = array_merge(reset($crmOrder['payments']), [
|
||||||
'order' => array('externalId' => $crmOrder['externalId'])
|
'order' => ['externalId' => $crmOrder['externalId']],
|
||||||
));
|
]);
|
||||||
static::$api->ordersPaymentCreate($payment);
|
static::$api->ordersPaymentCreate($payment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -427,9 +437,9 @@ class RetailcrmExport
|
|||||||
*/
|
*/
|
||||||
private static function validateState()
|
private static function validateState()
|
||||||
{
|
{
|
||||||
if (!static::$api ||
|
if (!static::$api
|
||||||
!static::$ordersOffset ||
|
|| !static::$ordersOffset
|
||||||
!static::$customersOffset
|
|| !static::$customersOffset
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,8 @@ interface RetailcrmFilterInterface
|
|||||||
/**
|
/**
|
||||||
* @param object|array|string $object
|
* @param object|array|string $object
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
|
*
|
||||||
* @return object|array|string
|
* @return object|array|string
|
||||||
*/
|
*/
|
||||||
public static function filter($object, array $parameters);
|
public static function filter($object, array $parameters);
|
||||||
}
|
}
|
||||||
|
@ -51,25 +51,26 @@ class RetailcrmHistory
|
|||||||
{
|
{
|
||||||
$lastSync = Configuration::get('RETAILCRM_LAST_CUSTOMERS_SYNC');
|
$lastSync = Configuration::get('RETAILCRM_LAST_CUSTOMERS_SYNC');
|
||||||
|
|
||||||
$customerFix = array();
|
$customerFix = [];
|
||||||
|
|
||||||
$filter = $lastSync === false
|
$filter = false === $lastSync
|
||||||
? array('startDate' => date('Y-m-d H:i:s', strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))))
|
? ['startDate' => date('Y-m-d H:i:s', strtotime('-1 days', strtotime(date('Y-m-d H:i:s'))))]
|
||||||
: array('sinceId' => $lastSync);
|
: ['sinceId' => $lastSync];
|
||||||
|
|
||||||
$request = new RetailcrmApiPaginatedRequest();
|
$request = new RetailcrmApiPaginatedRequest();
|
||||||
$historyChanges = array();
|
$historyChanges = [];
|
||||||
$history = $request
|
$history = $request
|
||||||
->setApi(self::$api)
|
->setApi(self::$api)
|
||||||
->setMethod('customersHistory')
|
->setMethod('customersHistory')
|
||||||
->setParams(array($filter, '{{page}}'))
|
->setParams([$filter, '{{page}}'])
|
||||||
->setDataKey('history')
|
->setDataKey('history')
|
||||||
->setLimit(100)
|
->setLimit(100)
|
||||||
->setPageLimit(50)
|
->setPageLimit(50)
|
||||||
->execute()
|
->execute()
|
||||||
->getData();
|
->getData()
|
||||||
|
;
|
||||||
|
|
||||||
if (count($history) > 0) {
|
if (0 < count($history)) {
|
||||||
$historyChanges = static::filterHistory($history, 'customer');
|
$historyChanges = static::filterHistory($history, 'customer');
|
||||||
$end = end($history);
|
$end = end($history);
|
||||||
Configuration::updateValue('RETAILCRM_LAST_CUSTOMERS_SYNC', $end['id']);
|
Configuration::updateValue('RETAILCRM_LAST_CUSTOMERS_SYNC', $end['id']);
|
||||||
@ -77,7 +78,7 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
if (count($historyChanges)) {
|
if (count($historyChanges)) {
|
||||||
$customersHistory = RetailcrmHistoryHelper::assemblyCustomer($historyChanges);
|
$customersHistory = RetailcrmHistoryHelper::assemblyCustomer($historyChanges);
|
||||||
RetailcrmLogger::writeDebugArray(__METHOD__, array('Assembled history:', $customersHistory));
|
RetailcrmLogger::writeDebugArray(__METHOD__, ['Assembled history:', $customersHistory]);
|
||||||
|
|
||||||
foreach ($customersHistory as $customerHistory) {
|
foreach ($customersHistory as $customerHistory) {
|
||||||
$customerHistory = RetailcrmTools::filter(
|
$customerHistory = RetailcrmTools::filter(
|
||||||
@ -111,43 +112,46 @@ class RetailcrmHistory
|
|||||||
$addressBuilder = new RetailcrmCustomerAddressBuilder();
|
$addressBuilder = new RetailcrmCustomerAddressBuilder();
|
||||||
|
|
||||||
$addressBuilder
|
$addressBuilder
|
||||||
->setCustomerAddress($customerAddress);
|
->setCustomerAddress($customerAddress)
|
||||||
|
;
|
||||||
|
|
||||||
$customerBuilder
|
$customerBuilder
|
||||||
->setCustomer($foundCustomer)
|
->setCustomer($foundCustomer)
|
||||||
->setAddressBuilder($addressBuilder)
|
->setAddressBuilder($addressBuilder)
|
||||||
->setDataCrm($customerData)
|
->setDataCrm($customerData)
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$customer = $customerBuilder->getData()->getCustomer();
|
$customer = $customerBuilder->getData()->getCustomer();
|
||||||
$address = $customerBuilder->getData()->getCustomerAddress();
|
$address = $customerBuilder->getData()->getCustomerAddress();
|
||||||
|
|
||||||
if (self::loadInCMS($customer, 'update') === false) {
|
if (false === self::loadInCMS($customer, 'update')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($address)) {
|
if (!empty($address)) {
|
||||||
RetailcrmTools::assignAddressIdsByFields($customer, $address);
|
RetailcrmTools::assignAddressIdsByFields($customer, $address);
|
||||||
|
|
||||||
if (self::loadInCMS($address, 'update') === false) {
|
if (false === self::loadInCMS($address, 'update')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$customerBuilder
|
$customerBuilder
|
||||||
->setDataCrm($customerHistory)
|
->setDataCrm($customerHistory)
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$customer = $customerBuilder->getData()->getCustomer();
|
$customer = $customerBuilder->getData()->getCustomer();
|
||||||
|
|
||||||
if (self::loadInCMS($customer, 'add') === false) {
|
if (false === self::loadInCMS($customer, 'add')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$customerFix[] = array(
|
$customerFix[] = [
|
||||||
'id' => $customerHistory['id'],
|
'id' => $customerHistory['id'],
|
||||||
'externalId' => $customer->id
|
'externalId' => $customer->id,
|
||||||
);
|
];
|
||||||
|
|
||||||
$customer->update();
|
$customer->update();
|
||||||
|
|
||||||
@ -156,7 +160,7 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
$address->id_customer = $customer->id;
|
$address->id_customer = $customer->id;
|
||||||
|
|
||||||
if (self::loadInCMS($address, 'add') === false) {
|
if (false === self::loadInCMS($address, 'add')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,6 +181,7 @@ class RetailcrmHistory
|
|||||||
* Get orders history
|
* Get orders history
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
*
|
||||||
* @throws \PrestaShopException
|
* @throws \PrestaShopException
|
||||||
* @throws \PrestaShopDatabaseException
|
* @throws \PrestaShopDatabaseException
|
||||||
*/
|
*/
|
||||||
@ -185,19 +190,19 @@ class RetailcrmHistory
|
|||||||
$lastSync = Configuration::get('RETAILCRM_LAST_ORDERS_SYNC');
|
$lastSync = Configuration::get('RETAILCRM_LAST_ORDERS_SYNC');
|
||||||
$lastDate = Configuration::get('RETAILCRM_LAST_SYNC');
|
$lastDate = Configuration::get('RETAILCRM_LAST_SYNC');
|
||||||
|
|
||||||
if ($lastSync === false && $lastDate === false) {
|
if (false === $lastSync && false === $lastDate) {
|
||||||
$filter = array(
|
$filter = [
|
||||||
'startDate' => date(
|
'startDate' => date(
|
||||||
'Y-m-d H:i:s',
|
'Y-m-d H:i:s',
|
||||||
strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))
|
strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))
|
||||||
)
|
),
|
||||||
);
|
];
|
||||||
} elseif ($lastSync === false && $lastDate !== false) {
|
} elseif (false === $lastSync && false !== $lastDate) {
|
||||||
$filter = array('startDate' => $lastDate);
|
$filter = ['startDate' => $lastDate];
|
||||||
} elseif ($lastSync !== false) {
|
} elseif (false !== $lastSync) {
|
||||||
$filter = array('sinceId' => $lastSync);
|
$filter = ['sinceId' => $lastSync];
|
||||||
} else {
|
} else {
|
||||||
$filter = array();
|
$filter = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$orderFix = [];
|
$orderFix = [];
|
||||||
@ -210,26 +215,27 @@ class RetailcrmHistory
|
|||||||
$history = $request
|
$history = $request
|
||||||
->setApi(self::$api)
|
->setApi(self::$api)
|
||||||
->setMethod('ordersHistory')
|
->setMethod('ordersHistory')
|
||||||
->setParams(array($filter, '{{page}}'))
|
->setParams([$filter, '{{page}}'])
|
||||||
->setDataKey('history')
|
->setDataKey('history')
|
||||||
->setLimit(100)
|
->setLimit(100)
|
||||||
->setPageLimit(50)
|
->setPageLimit(50)
|
||||||
->execute()
|
->execute()
|
||||||
->getData();
|
->getData()
|
||||||
|
;
|
||||||
|
|
||||||
if (count($history) > 0) {
|
if (0 < count($history)) {
|
||||||
$historyChanges = static::filterHistory($history, 'order');
|
$historyChanges = static::filterHistory($history, 'order');
|
||||||
$end = end($history);
|
$end = end($history);
|
||||||
Configuration::updateValue('RETAILCRM_LAST_ORDERS_SYNC', $end['id']);
|
Configuration::updateValue('RETAILCRM_LAST_ORDERS_SYNC', $end['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($historyChanges)) {
|
if (count($historyChanges)) {
|
||||||
$default_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT');
|
$default_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
|
||||||
$references = new RetailcrmReferences(self::$api);
|
$references = new RetailcrmReferences(self::$api);
|
||||||
$receiveOrderNumber = (bool)(Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING));
|
$receiveOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING));
|
||||||
$sendOrderNumber = (bool)(Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_SENDING));
|
$sendOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_SENDING));
|
||||||
$statuses = array_flip(array_filter(json_decode(Configuration::get('RETAILCRM_API_STATUS'), true)));
|
$statuses = array_flip(array_filter(json_decode(Configuration::get('RETAILCRM_API_STATUS'), true)));
|
||||||
$cartStatus = (string)(Configuration::get('RETAILCRM_API_SYNCHRONIZED_CART_STATUS'));
|
$cartStatus = (string) (Configuration::get('RETAILCRM_API_SYNCHRONIZED_CART_STATUS'));
|
||||||
$deliveries = array_flip(array_filter(json_decode(Configuration::get('RETAILCRM_API_DELIVERY'), true)));
|
$deliveries = array_flip(array_filter(json_decode(Configuration::get('RETAILCRM_API_DELIVERY'), true)));
|
||||||
$payments = array_flip(array_filter(json_decode(Configuration::get('RETAILCRM_API_PAYMENT'), true)));
|
$payments = array_flip(array_filter(json_decode(Configuration::get('RETAILCRM_API_PAYMENT'), true)));
|
||||||
$deliveryDefault = json_decode(Configuration::get('RETAILCRM_API_DELIVERY_DEFAULT'), true);
|
$deliveryDefault = json_decode(Configuration::get('RETAILCRM_API_DELIVERY_DEFAULT'), true);
|
||||||
@ -241,7 +247,7 @@ class RetailcrmHistory
|
|||||||
}
|
}
|
||||||
|
|
||||||
$orders = RetailcrmHistoryHelper::assemblyOrder($historyChanges);
|
$orders = RetailcrmHistoryHelper::assemblyOrder($historyChanges);
|
||||||
RetailcrmLogger::writeDebugArray(__METHOD__, array('Assembled history:', $orders));
|
RetailcrmLogger::writeDebugArray(__METHOD__, ['Assembled history:', $orders]);
|
||||||
|
|
||||||
foreach ($orders as $order_history) {
|
foreach ($orders as $order_history) {
|
||||||
$order_history = RetailcrmTools::filter(
|
$order_history = RetailcrmTools::filter(
|
||||||
@ -249,7 +255,7 @@ class RetailcrmHistory
|
|||||||
$order_history
|
$order_history
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($order_history['deleted']) && $order_history['deleted'] == true) {
|
if (isset($order_history['deleted']) && true == $order_history['deleted']) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$infoOrder = null;
|
$infoOrder = null;
|
||||||
@ -271,7 +277,7 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
// status
|
// status
|
||||||
$state = $order['status'];
|
$state = $order['status'];
|
||||||
if (array_key_exists($state, $statuses) && $statuses[$state] != '') {
|
if (array_key_exists($state, $statuses) && '' != $statuses[$state]) {
|
||||||
$orderStatus = $statuses[$state];
|
$orderStatus = $statuses[$state];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,12 +286,12 @@ class RetailcrmHistory
|
|||||||
$paymentId = null;
|
$paymentId = null;
|
||||||
$paymentType = null;
|
$paymentType = null;
|
||||||
if (isset($order['payments'])) {
|
if (isset($order['payments'])) {
|
||||||
if (count($order['payments']) === 1) {
|
if (1 === count($order['payments'])) {
|
||||||
$paymentCRM = end($order['payments']);
|
$paymentCRM = end($order['payments']);
|
||||||
$paymentTypeCRM = $paymentCRM['type'];
|
$paymentTypeCRM = $paymentCRM['type'];
|
||||||
} elseif (count($order['payments']) > 1) {
|
} elseif (1 < count($order['payments'])) {
|
||||||
foreach ($order['payments'] as $paymentCRM) {
|
foreach ($order['payments'] as $paymentCRM) {
|
||||||
if (isset($paymentCRM['status']) && $paymentCRM['status'] !== 'paid') {
|
if (isset($paymentCRM['status']) && 'paid' !== $paymentCRM['status']) {
|
||||||
$paymentTypeCRM = $paymentCRM['type'];
|
$paymentTypeCRM = $paymentCRM['type'];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -332,7 +338,7 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
// delivery
|
// delivery
|
||||||
$delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : false;
|
$delivery = isset($order['delivery']['code']) ? $order['delivery']['code'] : false;
|
||||||
if ($delivery && array_key_exists($delivery, $deliveries) && $deliveries[$delivery] != '') {
|
if ($delivery && array_key_exists($delivery, $deliveries) && '' != $deliveries[$delivery]) {
|
||||||
$deliveryType = $deliveries[$delivery];
|
$deliveryType = $deliveries[$delivery];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +361,7 @@ class RetailcrmHistory
|
|||||||
$customer = null;
|
$customer = null;
|
||||||
$customerId = null;
|
$customerId = null;
|
||||||
|
|
||||||
if ($order['customer']['type'] === 'customer_corporate'
|
if ('customer_corporate' === $order['customer']['type']
|
||||||
&& RetailcrmTools::isCorporateEnabled()
|
&& RetailcrmTools::isCorporateEnabled()
|
||||||
&& !empty($order['contact'])
|
&& !empty($order['contact'])
|
||||||
&& array_key_exists('externalId', $order['contact'])
|
&& array_key_exists('externalId', $order['contact'])
|
||||||
@ -366,7 +372,7 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
if (empty($customerId) && !empty($order['contact']['email'])) {
|
if (empty($customerId) && !empty($order['contact']['email'])) {
|
||||||
$customer = Customer::getCustomersByEmail($order['contact']['email']);
|
$customer = Customer::getCustomersByEmail($order['contact']['email']);
|
||||||
$customer = is_array($customer) ? reset($customer) : array();
|
$customer = is_array($customer) ? reset($customer) : [];
|
||||||
|
|
||||||
if (array_key_exists('id_customer', $customer)) {
|
if (array_key_exists('id_customer', $customer)) {
|
||||||
$customerId = $customer['id_customer'];
|
$customerId = $customer['id_customer'];
|
||||||
@ -381,14 +387,15 @@ class RetailcrmHistory
|
|||||||
$corporateCustomerBuilder = new RetailcrmCorporateCustomerBuilder();
|
$corporateCustomerBuilder = new RetailcrmCorporateCustomerBuilder();
|
||||||
$dataOrder = array_merge(
|
$dataOrder = array_merge(
|
||||||
$order['contact'],
|
$order['contact'],
|
||||||
array('address' => $order['company']['address'])
|
['address' => $order['company']['address']]
|
||||||
);
|
);
|
||||||
|
|
||||||
$corporateCustomerBuilder
|
$corporateCustomerBuilder
|
||||||
->setCustomer(new Customer($customerId))
|
->setCustomer(new Customer($customerId))
|
||||||
->setDataCrm($dataOrder)
|
->setDataCrm($dataOrder)
|
||||||
->extractCompanyDataFromOrder($order)
|
->extractCompanyDataFromOrder($order)
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$customer = $corporateCustomerBuilder->getData()->getCustomer();
|
$customer = $corporateCustomerBuilder->getData()->getCustomer();
|
||||||
$addressInvoice = $corporateCustomerBuilder->getData()->getCustomerAddress();
|
$addressInvoice = $corporateCustomerBuilder->getData()->getCustomerAddress();
|
||||||
@ -400,7 +407,8 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
$customerBuilder
|
$customerBuilder
|
||||||
->setDataCrm($order['customer'])
|
->setDataCrm($order['customer'])
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$customer = $customerBuilder->getData()->getCustomer();
|
$customer = $customerBuilder->getData()->getCustomer();
|
||||||
$addressInvoice = $customerBuilder->getData()->getCustomerAddress();
|
$addressInvoice = $customerBuilder->getData()->getCustomerAddress();
|
||||||
@ -410,7 +418,7 @@ class RetailcrmHistory
|
|||||||
$customer->id = self::getCustomerIdByEmail($customer->email);
|
$customer->id = self::getCustomerIdByEmail($customer->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::loadInCMS($customer, 'save') === false) {
|
if (false === self::loadInCMS($customer, 'save')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,7 +435,7 @@ class RetailcrmHistory
|
|||||||
$order['company']['address']['id'],
|
$order['company']['address']['id'],
|
||||||
array_merge(
|
array_merge(
|
||||||
$order['company']['address'],
|
$order['company']['address'],
|
||||||
array('externalId' => $addressInvoice->id)
|
['externalId' => $addressInvoice->id]
|
||||||
),
|
),
|
||||||
'id',
|
'id',
|
||||||
'id'
|
'id'
|
||||||
@ -449,7 +457,8 @@ class RetailcrmHistory
|
|||||||
->setLastName(isset($order['lastName']) ? $order['lastName'] : null)
|
->setLastName(isset($order['lastName']) ? $order['lastName'] : null)
|
||||||
->setPhone(isset($order['phone']) ? $order['phone'] : null)
|
->setPhone(isset($order['phone']) ? $order['phone'] : null)
|
||||||
->build()
|
->build()
|
||||||
->getData();
|
->getData()
|
||||||
|
;
|
||||||
|
|
||||||
if (RetailcrmTools::validateEntity($addressDelivery)) {
|
if (RetailcrmTools::validateEntity($addressDelivery)) {
|
||||||
RetailcrmTools::assignAddressIdsByFields($customer, $addressDelivery);
|
RetailcrmTools::assignAddressIdsByFields($customer, $addressDelivery);
|
||||||
@ -466,15 +475,15 @@ class RetailcrmHistory
|
|||||||
$cart->id_currency = $default_currency;
|
$cart->id_currency = $default_currency;
|
||||||
$cart->id_lang = self::$default_lang;
|
$cart->id_lang = self::$default_lang;
|
||||||
$cart->id_shop = Context::getContext()->shop->id;
|
$cart->id_shop = Context::getContext()->shop->id;
|
||||||
$cart->id_shop_group = intval(Context::getContext()->shop->id_shop_group);
|
$cart->id_shop_group = (int) (Context::getContext()->shop->id_shop_group);
|
||||||
$cart->id_customer = $customer->id;
|
$cart->id_customer = $customer->id;
|
||||||
$cart->id_address_delivery = isset($addressDelivery->id) ? (int)$addressDelivery->id : 0;
|
$cart->id_address_delivery = isset($addressDelivery->id) ? (int) $addressDelivery->id : 0;
|
||||||
$cart->id_address_invoice = isset($addressInvoice->id) ? (int)$addressInvoice->id : 0;
|
$cart->id_address_invoice = isset($addressInvoice->id) ? (int) $addressInvoice->id : 0;
|
||||||
$cart->id_carrier = (int)$deliveryType;
|
$cart->id_carrier = (int) $deliveryType;
|
||||||
|
|
||||||
self::loadInCMS($cart, 'add');
|
self::loadInCMS($cart, 'add');
|
||||||
|
|
||||||
$products = array();
|
$products = [];
|
||||||
if (!empty($order['items'])) {
|
if (!empty($order['items'])) {
|
||||||
foreach ($order['items'] as $item) {
|
foreach ($order['items'] as $item) {
|
||||||
if (RetailcrmOrderBuilder::isGiftItem($item)) {
|
if (RetailcrmOrderBuilder::isGiftItem($item)) {
|
||||||
@ -482,11 +491,11 @@ class RetailcrmHistory
|
|||||||
}
|
}
|
||||||
|
|
||||||
$productId = explode('#', $item['offer']['externalId']);
|
$productId = explode('#', $item['offer']['externalId']);
|
||||||
$product = array();
|
$product = [];
|
||||||
$product['id_product'] = (int)$productId[0];
|
$product['id_product'] = (int) $productId[0];
|
||||||
$product['id_product_attribute'] = !empty($productId[1]) ? $productId[1] : 0;
|
$product['id_product_attribute'] = !empty($productId[1]) ? $productId[1] : 0;
|
||||||
$product['quantity'] = $item['quantity'];
|
$product['quantity'] = $item['quantity'];
|
||||||
$product['id_address_delivery'] = isset($addressDelivery->id) ? (int)$addressDelivery->id : 0;
|
$product['id_address_delivery'] = isset($addressDelivery->id) ? (int) $addressDelivery->id : 0;
|
||||||
$products[] = $product;
|
$products[] = $product;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -500,18 +509,18 @@ class RetailcrmHistory
|
|||||||
*/
|
*/
|
||||||
$newOrder = new Order();
|
$newOrder = new Order();
|
||||||
$newOrder->id_shop = Context::getContext()->shop->id;
|
$newOrder->id_shop = Context::getContext()->shop->id;
|
||||||
$newOrder->id_shop_group = intval(Context::getContext()->shop->id_shop_group);
|
$newOrder->id_shop_group = (int) (Context::getContext()->shop->id_shop_group);
|
||||||
$newOrder->id_address_delivery = isset($addressDelivery->id) ? (int)$addressDelivery->id : 0;
|
$newOrder->id_address_delivery = isset($addressDelivery->id) ? (int) $addressDelivery->id : 0;
|
||||||
$newOrder->id_address_invoice = isset($addressInvoice->id) ? (int)$addressInvoice->id : 0;
|
$newOrder->id_address_invoice = isset($addressInvoice->id) ? (int) $addressInvoice->id : 0;
|
||||||
$newOrder->id_cart = (int)$cart->id;
|
$newOrder->id_cart = (int) $cart->id;
|
||||||
$newOrder->id_currency = $default_currency;
|
$newOrder->id_currency = $default_currency;
|
||||||
$newOrder->id_lang = self::$default_lang;
|
$newOrder->id_lang = self::$default_lang;
|
||||||
$newOrder->id_customer = (int)$customer->id;
|
$newOrder->id_customer = (int) $customer->id;
|
||||||
$orderNumber = $receiveOrderNumber ? $order['number'] : $newOrder->generateReference();
|
$orderNumber = $receiveOrderNumber ? $order['number'] : $newOrder->generateReference();
|
||||||
$newOrder->reference = $orderNumber;
|
$newOrder->reference = $orderNumber;
|
||||||
|
|
||||||
if (isset($deliveryType)) {
|
if (isset($deliveryType)) {
|
||||||
$newOrder->id_carrier = (int)$deliveryType;
|
$newOrder->id_carrier = (int) $deliveryType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($paymentType)) {
|
if (isset($paymentType)) {
|
||||||
@ -523,6 +532,7 @@ class RetailcrmHistory
|
|||||||
$totalPaid = $order['totalSumm'];
|
$totalPaid = $order['totalSumm'];
|
||||||
$orderTotalProducts = array_reduce($order['items'], function ($sum, $it) {
|
$orderTotalProducts = array_reduce($order['items'], function ($sum, $it) {
|
||||||
$sum += $it['initialPrice'] * $it['quantity'];
|
$sum += $it['initialPrice'] * $it['quantity'];
|
||||||
|
|
||||||
return $sum;
|
return $sum;
|
||||||
});
|
});
|
||||||
$deliveryCost = $order['delivery']['cost'];
|
$deliveryCost = $order['delivery']['cost'];
|
||||||
@ -537,8 +547,8 @@ class RetailcrmHistory
|
|||||||
$newOrder->total_paid_tax_excl = $totalPaid;
|
$newOrder->total_paid_tax_excl = $totalPaid;
|
||||||
$newOrder->total_paid_real = $totalPaid;
|
$newOrder->total_paid_real = $totalPaid;
|
||||||
|
|
||||||
$newOrder->total_products = (int)$orderTotalProducts;
|
$newOrder->total_products = (int) $orderTotalProducts;
|
||||||
$newOrder->total_products_wt = (int)$orderTotalProducts;
|
$newOrder->total_products_wt = (int) $orderTotalProducts;
|
||||||
|
|
||||||
$newOrder->total_shipping = $deliveryCost;
|
$newOrder->total_shipping = $deliveryCost;
|
||||||
$newOrder->total_shipping_tax_incl = $deliveryCost;
|
$newOrder->total_shipping_tax_incl = $deliveryCost;
|
||||||
@ -603,7 +613,7 @@ class RetailcrmHistory
|
|||||||
foreach ($order['payments'] as $payment) {
|
foreach ($order['payments'] as $payment) {
|
||||||
if (!isset($payment['externalId'])
|
if (!isset($payment['externalId'])
|
||||||
&& isset($payment['status'])
|
&& isset($payment['status'])
|
||||||
&& $payment['status'] === 'paid'
|
&& 'paid' === $payment['status']
|
||||||
) {
|
) {
|
||||||
$paymentTypeCRM = isset($payment['type']) ? $payment['type'] : null;
|
$paymentTypeCRM = isset($payment['type']) ? $payment['type'] : null;
|
||||||
$paymentType = null;
|
$paymentType = null;
|
||||||
@ -668,10 +678,10 @@ class RetailcrmHistory
|
|||||||
* Create order details
|
* Create order details
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$newItemsIds = array();
|
$newItemsIds = [];
|
||||||
if (!empty($order['items'])) {
|
if (!empty($order['items'])) {
|
||||||
foreach ($order['items'] as $item) {
|
foreach ($order['items'] as $item) {
|
||||||
$product = new Product((int)$item['offer']['externalId'], false, self::$default_lang);
|
$product = new Product((int) $item['offer']['externalId'], false, self::$default_lang);
|
||||||
$product_id = $item['offer']['externalId'];
|
$product_id = $item['offer']['externalId'];
|
||||||
$product_attribute_id = 0;
|
$product_attribute_id = 0;
|
||||||
|
|
||||||
@ -679,13 +689,13 @@ class RetailcrmHistory
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($item['offer']['externalId'], '#') !== false) {
|
if (false !== strpos($item['offer']['externalId'], '#')) {
|
||||||
$externalIds = explode('#', $item['offer']['externalId']);
|
$externalIds = explode('#', $item['offer']['externalId']);
|
||||||
$product_id = $externalIds[0];
|
$product_id = $externalIds[0];
|
||||||
$product_attribute_id = $externalIds[1];
|
$product_attribute_id = $externalIds[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($product_attribute_id != 0) {
|
if (0 != $product_attribute_id) {
|
||||||
$productName = htmlspecialchars(
|
$productName = htmlspecialchars(
|
||||||
strip_tags(Product::getProductName($product_id, $product_attribute_id))
|
strip_tags(Product::getProductName($product_id, $product_attribute_id))
|
||||||
);
|
);
|
||||||
@ -702,14 +712,14 @@ class RetailcrmHistory
|
|||||||
$orderDetail->id_order_invoice = $newOrder->invoice_number;
|
$orderDetail->id_order_invoice = $newOrder->invoice_number;
|
||||||
$orderDetail->id_shop = Context::getContext()->shop->id;
|
$orderDetail->id_shop = Context::getContext()->shop->id;
|
||||||
|
|
||||||
$orderDetail->product_id = (int)$product_id;
|
$orderDetail->product_id = (int) $product_id;
|
||||||
$orderDetail->product_attribute_id = (int)$product_attribute_id;
|
$orderDetail->product_attribute_id = (int) $product_attribute_id;
|
||||||
$orderDetail->product_reference = implode('', array('\'', $product->reference, '\''));
|
$orderDetail->product_reference = implode('', ['\'', $product->reference, '\'']);
|
||||||
|
|
||||||
$orderDetail->product_price = $productPrice;
|
$orderDetail->product_price = $productPrice;
|
||||||
$orderDetail->original_product_price = $productPrice;
|
$orderDetail->original_product_price = $productPrice;
|
||||||
$orderDetail->product_quantity = (int)$item['quantity'];
|
$orderDetail->product_quantity = (int) $item['quantity'];
|
||||||
$orderDetail->product_quantity_in_stock = (int)$item['quantity'];
|
$orderDetail->product_quantity_in_stock = (int) $item['quantity'];
|
||||||
|
|
||||||
$orderDetail->total_price_tax_incl = $productPrice * $orderDetail->product_quantity;
|
$orderDetail->total_price_tax_incl = $productPrice * $orderDetail->product_quantity;
|
||||||
$orderDetail->unit_price_tax_incl = $productPrice;
|
$orderDetail->unit_price_tax_incl = $productPrice;
|
||||||
@ -717,7 +727,6 @@ class RetailcrmHistory
|
|||||||
$orderDetail->id_warehouse = !empty($newOrder->id_warehouse) ? $newOrder->id_warehouse : 0;
|
$orderDetail->id_warehouse = !empty($newOrder->id_warehouse) ? $newOrder->id_warehouse : 0;
|
||||||
|
|
||||||
if (!$product->checkQty($orderDetail->product_quantity)) {
|
if (!$product->checkQty($orderDetail->product_quantity)) {
|
||||||
|
|
||||||
self::$api->ordersFixExternalIds([[
|
self::$api->ordersFixExternalIds([[
|
||||||
'id' => $order['id'],
|
'id' => $order['id'],
|
||||||
'externalId' => $newOrder->id,
|
'externalId' => $newOrder->id,
|
||||||
@ -746,26 +755,26 @@ class RetailcrmHistory
|
|||||||
}
|
}
|
||||||
|
|
||||||
// collect order ids for single fix request
|
// collect order ids for single fix request
|
||||||
$orderFix[] = array('id' => $order['id'], 'externalId' => $newOrder->id);
|
$orderFix[] = ['id' => $order['id'], 'externalId' => $newOrder->id];
|
||||||
|
|
||||||
// update order items ids in crm
|
// update order items ids in crm
|
||||||
$newItemsIdsByOrderId[$newOrder->id] = $newItemsIds;
|
$newItemsIdsByOrderId[$newOrder->id] = $newItemsIds;
|
||||||
|
|
||||||
// collect orders id and reference if option sendOrderNumber enabled
|
// collect orders id and reference if option sendOrderNumber enabled
|
||||||
if ($sendOrderNumber) {
|
if ($sendOrderNumber) {
|
||||||
$updateOrderIds[] = array(
|
$updateOrderIds[] = [
|
||||||
'externalId' => $newOrder->id,
|
'externalId' => $newOrder->id,
|
||||||
'number' => $newOrder->reference,
|
'number' => $newOrder->reference,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$order = $order_history;
|
$order = $order_history;
|
||||||
|
|
||||||
if (stripos($order['externalId'], 'pscart_') !== false) {
|
if (false !== stripos($order['externalId'], 'pscart_')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$orderToUpdate = new Order((int)$order['externalId']);
|
$orderToUpdate = new Order((int) $order['externalId']);
|
||||||
if (!Validate::isLoadedObject($orderToUpdate)) {
|
if (!Validate::isLoadedObject($orderToUpdate)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -773,9 +782,9 @@ class RetailcrmHistory
|
|||||||
$order = RetailcrmTools::filter(
|
$order = RetailcrmTools::filter(
|
||||||
'RetailcrmFilterOrdersHistoryUpdate',
|
'RetailcrmFilterOrdersHistoryUpdate',
|
||||||
$order,
|
$order,
|
||||||
array(
|
[
|
||||||
'orderToUpdate' => $orderToUpdate
|
'orderToUpdate' => $orderToUpdate,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
self::handleCustomerDataChange($orderToUpdate, $order);
|
self::handleCustomerDataChange($orderToUpdate, $order);
|
||||||
@ -839,13 +848,14 @@ class RetailcrmHistory
|
|||||||
->setPhone($orderPhone)
|
->setPhone($orderPhone)
|
||||||
->setAlias($orderAddress->alias)
|
->setAlias($orderAddress->alias)
|
||||||
->build()
|
->build()
|
||||||
->getData();
|
->getData()
|
||||||
|
;
|
||||||
|
|
||||||
if (RetailcrmTools::validateEntity($address, $orderToUpdate)) {
|
if (RetailcrmTools::validateEntity($address, $orderToUpdate)) {
|
||||||
$address->id = null;
|
$address->id = null;
|
||||||
RetailcrmTools::assignAddressIdsByFields(new Customer($orderToUpdate->id_customer), $address);
|
RetailcrmTools::assignAddressIdsByFields(new Customer($orderToUpdate->id_customer), $address);
|
||||||
|
|
||||||
if ($address->id === null) {
|
if (null === $address->id) {
|
||||||
// Modifying an address in order creates another address
|
// Modifying an address in order creates another address
|
||||||
// instead of changing the original one. This issue has been fixed in PS 1.7.7
|
// instead of changing the original one. This issue has been fixed in PS 1.7.7
|
||||||
if (version_compare(_PS_VERSION_, '1.7.7', '<')) {
|
if (version_compare(_PS_VERSION_, '1.7.7', '<')) {
|
||||||
@ -878,12 +888,12 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
(
|
(
|
||||||
$dtype !== null &&
|
null !== $dtype
|
||||||
isset($deliveries[$dtype])
|
&& isset($deliveries[$dtype])
|
||||||
&& $deliveries[$dtype] !== null
|
&& null !== $deliveries[$dtype]
|
||||||
&& $deliveries[$dtype] !== $orderToUpdate->id_carrier
|
&& $deliveries[$dtype] !== $orderToUpdate->id_carrier
|
||||||
)
|
)
|
||||||
|| $dcost !== null
|
|| null !== $dcost
|
||||||
) {
|
) {
|
||||||
if (property_exists($orderToUpdate, 'id_order_carrier')) {
|
if (property_exists($orderToUpdate, 'id_order_carrier')) {
|
||||||
$idOrderCarrier = $orderToUpdate->id_order_carrier;
|
$idOrderCarrier = $orderToUpdate->id_order_carrier;
|
||||||
@ -895,11 +905,11 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
$orderCarrier = new OrderCarrier($idOrderCarrier);
|
$orderCarrier = new OrderCarrier($idOrderCarrier);
|
||||||
|
|
||||||
if ($dtype != null) {
|
if (null != $dtype) {
|
||||||
$orderCarrier->id_carrier = $deliveries[$dtype];
|
$orderCarrier->id_carrier = $deliveries[$dtype];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dcost != null) {
|
if (null != $dcost) {
|
||||||
$orderCarrier->shipping_cost_tax_incl = $dcost;
|
$orderCarrier->shipping_cost_tax_incl = $dcost;
|
||||||
$orderCarrier->shipping_cost_tax_excl = $dcost;
|
$orderCarrier->shipping_cost_tax_excl = $dcost;
|
||||||
}
|
}
|
||||||
@ -910,14 +920,14 @@ class RetailcrmHistory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* check payment type
|
* check payment type
|
||||||
*/
|
*/
|
||||||
if (!empty($order['payments'])) {
|
if (!empty($order['payments'])) {
|
||||||
foreach ($order['payments'] as $payment) {
|
foreach ($order['payments'] as $payment) {
|
||||||
if (!isset($payment['externalId'])
|
if (!isset($payment['externalId'])
|
||||||
&& isset($payment['status'])
|
&& isset($payment['status'])
|
||||||
&& $payment['status'] === 'paid'
|
&& 'paid' === $payment['status']
|
||||||
) {
|
) {
|
||||||
$paymentTypeCRM = isset($payment['type']) ? $payment['type'] : null;
|
$paymentTypeCRM = isset($payment['type']) ? $payment['type'] : null;
|
||||||
$paymentType = null;
|
$paymentType = null;
|
||||||
@ -981,7 +991,7 @@ class RetailcrmHistory
|
|||||||
*/
|
*/
|
||||||
$id_order_detail = null;
|
$id_order_detail = null;
|
||||||
foreach ($order['items'] as $key => $item) {
|
foreach ($order['items'] as $key => $item) {
|
||||||
if (isset($item['delete']) && $item['delete'] == true) {
|
if (isset($item['delete']) && true == $item['delete']) {
|
||||||
if (RetailcrmOrderBuilder::isGiftItem($item)) {
|
if (RetailcrmOrderBuilder::isGiftItem($item)) {
|
||||||
$orderToUpdate->gift = false;
|
$orderToUpdate->gift = false;
|
||||||
}
|
}
|
||||||
@ -1025,11 +1035,11 @@ class RetailcrmHistory
|
|||||||
$product_attribute_id = $parsedExtId['product_attribute_id'];
|
$product_attribute_id = $parsedExtId['product_attribute_id'];
|
||||||
$isExistingItem = isset($item['create']) ? false : true;
|
$isExistingItem = isset($item['create']) ? false : true;
|
||||||
|
|
||||||
if ($isExistingItem &&
|
if ($isExistingItem
|
||||||
$product_id == $orderItem['product_id'] &&
|
&& $product_id == $orderItem['product_id']
|
||||||
$product_attribute_id == $orderItem['product_attribute_id']
|
&& $product_attribute_id == $orderItem['product_attribute_id']
|
||||||
) {
|
) {
|
||||||
$product = new Product((int)$product_id, false, self::$default_lang);
|
$product = new Product((int) $product_id, false, self::$default_lang);
|
||||||
|
|
||||||
$orderDetailId = !empty($parsedExtId['id_order_detail'])
|
$orderDetailId = !empty($parsedExtId['id_order_detail'])
|
||||||
? $parsedExtId['id_order_detail'] : $orderItem['id_order_detail'];
|
? $parsedExtId['id_order_detail'] : $orderItem['id_order_detail'];
|
||||||
@ -1050,7 +1060,7 @@ class RetailcrmHistory
|
|||||||
$orderDetail->product_quantity = $item['quantity'];
|
$orderDetail->product_quantity = $item['quantity'];
|
||||||
$orderDetail->product_quantity_in_stock = $item['quantity'];
|
$orderDetail->product_quantity_in_stock = $item['quantity'];
|
||||||
|
|
||||||
if ($deltaQuantity < 0 && !$product->checkQty(-1 * $deltaQuantity)) {
|
if (0 > $deltaQuantity && !$product->checkQty(-1 * $deltaQuantity)) {
|
||||||
$newStatus = self::setOutOfStockStatus(
|
$newStatus = self::setOutOfStockStatus(
|
||||||
$infoOrder,
|
$infoOrder,
|
||||||
$orderToUpdate,
|
$orderToUpdate,
|
||||||
@ -1084,7 +1094,7 @@ class RetailcrmHistory
|
|||||||
* Check new items
|
* Check new items
|
||||||
*/
|
*/
|
||||||
$isNewItemsExist = false;
|
$isNewItemsExist = false;
|
||||||
$newItemsIds = array();
|
$newItemsIds = [];
|
||||||
foreach ($order['items'] as $key => $newItem) {
|
foreach ($order['items'] as $key => $newItem) {
|
||||||
if (RetailcrmOrderBuilder::isGiftItem($newItem)) {
|
if (RetailcrmOrderBuilder::isGiftItem($newItem)) {
|
||||||
continue;
|
continue;
|
||||||
@ -1099,9 +1109,9 @@ class RetailcrmHistory
|
|||||||
$product_id = $parsedExtId['product_id'];
|
$product_id = $parsedExtId['product_id'];
|
||||||
$product_attribute_id = $parsedExtId['product_attribute_id'];
|
$product_attribute_id = $parsedExtId['product_attribute_id'];
|
||||||
|
|
||||||
$product = new Product((int)$product_id, false, self::$default_lang);
|
$product = new Product((int) $product_id, false, self::$default_lang);
|
||||||
|
|
||||||
if ($product_attribute_id != 0) {
|
if (0 != $product_attribute_id) {
|
||||||
$productName = htmlspecialchars(
|
$productName = htmlspecialchars(
|
||||||
strip_tags(Product::getProductName($product_id, $product_attribute_id))
|
strip_tags(Product::getProductName($product_id, $product_attribute_id))
|
||||||
);
|
);
|
||||||
@ -1121,14 +1131,14 @@ class RetailcrmHistory
|
|||||||
$orderDetail->id_order_invoice = $orderToUpdate->invoice_number;
|
$orderDetail->id_order_invoice = $orderToUpdate->invoice_number;
|
||||||
$orderDetail->id_shop = Context::getContext()->shop->id;
|
$orderDetail->id_shop = Context::getContext()->shop->id;
|
||||||
|
|
||||||
$orderDetail->product_id = (int)$product_id;
|
$orderDetail->product_id = (int) $product_id;
|
||||||
$orderDetail->product_attribute_id = (int)$product_attribute_id;
|
$orderDetail->product_attribute_id = (int) $product_attribute_id;
|
||||||
$orderDetail->product_reference = implode('', array('\'', $product->reference, '\''));
|
$orderDetail->product_reference = implode('', ['\'', $product->reference, '\'']);
|
||||||
|
|
||||||
$orderDetail->product_price = $productPrice;
|
$orderDetail->product_price = $productPrice;
|
||||||
$orderDetail->original_product_price = $productPrice;
|
$orderDetail->original_product_price = $productPrice;
|
||||||
$orderDetail->product_quantity = (int)$newItem['quantity'];
|
$orderDetail->product_quantity = (int) $newItem['quantity'];
|
||||||
$orderDetail->product_quantity_in_stock = (int)$newItem['quantity'];
|
$orderDetail->product_quantity_in_stock = (int) $newItem['quantity'];
|
||||||
|
|
||||||
$orderDetail->total_price_tax_incl = $productPrice * $orderDetail->product_quantity;
|
$orderDetail->total_price_tax_incl = $productPrice * $orderDetail->product_quantity;
|
||||||
$orderDetail->unit_price_tax_incl = $productPrice;
|
$orderDetail->unit_price_tax_incl = $productPrice;
|
||||||
@ -1177,6 +1187,7 @@ class RetailcrmHistory
|
|||||||
$totalPaid = $infoOrder['totalSumm'];
|
$totalPaid = $infoOrder['totalSumm'];
|
||||||
$orderTotalProducts = array_reduce($infoOrder['items'], function ($sum, $it) {
|
$orderTotalProducts = array_reduce($infoOrder['items'], function ($sum, $it) {
|
||||||
$sum += $it['initialPrice'] * $it['quantity'];
|
$sum += $it['initialPrice'] * $it['quantity'];
|
||||||
|
|
||||||
return $sum;
|
return $sum;
|
||||||
});
|
});
|
||||||
$deliveryCost = $infoOrder['delivery']['cost'];
|
$deliveryCost = $infoOrder['delivery']['cost'];
|
||||||
@ -1203,7 +1214,7 @@ class RetailcrmHistory
|
|||||||
self::loadInCMS($orderToUpdate, 'update');
|
self::loadInCMS($orderToUpdate, 'update');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* check status
|
* check status
|
||||||
*/
|
*/
|
||||||
if (!empty($order['status']) && !array_key_exists($orderToUpdate->id, $updateOrderStatuses)) {
|
if (!empty($order['status']) && !array_key_exists($orderToUpdate->id, $updateOrderStatuses)) {
|
||||||
@ -1242,10 +1253,10 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
// collect orders id and reference if option sendOrderNumber enabled
|
// collect orders id and reference if option sendOrderNumber enabled
|
||||||
if ($sendOrderNumber) {
|
if ($sendOrderNumber) {
|
||||||
$updateOrderIds[] = array(
|
$updateOrderIds[] = [
|
||||||
'externalId' => $orderToUpdate->id,
|
'externalId' => $orderToUpdate->id,
|
||||||
'number' => $orderToUpdate->reference,
|
'number' => $orderToUpdate->reference,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1292,10 +1303,10 @@ class RetailcrmHistory
|
|||||||
&& $crmOrderResponse->isSuccessful()
|
&& $crmOrderResponse->isSuccessful()
|
||||||
&& $crmOrderResponse->offsetExists('order')
|
&& $crmOrderResponse->offsetExists('order')
|
||||||
) {
|
) {
|
||||||
return (array)$crmOrderResponse['order'];
|
return (array) $crmOrderResponse['order'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1309,12 +1320,12 @@ class RetailcrmHistory
|
|||||||
{
|
{
|
||||||
RetailcrmLogger::writeDebugArray(
|
RetailcrmLogger::writeDebugArray(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array(
|
[
|
||||||
'Using this individual person data in order to set it into order,',
|
'Using this individual person data in order to set it into order,',
|
||||||
$data->getOrder()->id,
|
$data->getOrder()->id,
|
||||||
': ',
|
': ',
|
||||||
$crmCustomer
|
$crmCustomer,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($isContact) {
|
if ($isContact) {
|
||||||
@ -1343,13 +1354,13 @@ class RetailcrmHistory
|
|||||||
if (isset($crmOrder['fullPaidAt']) && !empty($crmOrder['fullPaidAt'])) {
|
if (isset($crmOrder['fullPaidAt']) && !empty($crmOrder['fullPaidAt'])) {
|
||||||
$stype = $statusArray['out_of_stock_paid'];
|
$stype = $statusArray['out_of_stock_paid'];
|
||||||
|
|
||||||
if ($stype == '') {
|
if ('' == $stype) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$stype = $statusArray['out_of_stock_not_paid'];
|
$stype = $statusArray['out_of_stock_not_paid'];
|
||||||
|
|
||||||
if ($stype == '') {
|
if ('' == $stype) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1390,12 +1401,12 @@ class RetailcrmHistory
|
|||||||
* @param \Order $order
|
* @param \Order $order
|
||||||
* @param array $historyOrder
|
* @param array $historyOrder
|
||||||
*
|
*
|
||||||
* @return bool True if customer change happened; false otherwise.
|
* @return bool true if customer change happened; false otherwise
|
||||||
*/
|
*/
|
||||||
private static function handleCustomerDataChange($order, $historyOrder)
|
private static function handleCustomerDataChange($order, $historyOrder)
|
||||||
{
|
{
|
||||||
$handled = false;
|
$handled = false;
|
||||||
$crmOrder = array();
|
$crmOrder = [];
|
||||||
$newCustomerId = null;
|
$newCustomerId = null;
|
||||||
$switcher = new RetailcrmCustomerSwitcher();
|
$switcher = new RetailcrmCustomerSwitcher();
|
||||||
$data = new RetailcrmCustomerSwitcherState();
|
$data = new RetailcrmCustomerSwitcherState();
|
||||||
@ -1429,7 +1440,7 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
if ($isChangedToRegular) {
|
if ($isChangedToRegular) {
|
||||||
self::prepareChangeToIndividual(
|
self::prepareChangeToIndividual(
|
||||||
RetailcrmTools::arrayValue($crmOrder, 'customer', array()),
|
RetailcrmTools::arrayValue($crmOrder, 'customer', []),
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1453,12 +1464,12 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
if (RetailcrmTools::isCrmOrderCorporate($crmOrder)) {
|
if (RetailcrmTools::isCrmOrderCorporate($crmOrder)) {
|
||||||
self::prepareChangeToIndividual(
|
self::prepareChangeToIndividual(
|
||||||
RetailcrmTools::arrayValue($crmOrder, 'contact', array()),
|
RetailcrmTools::arrayValue($crmOrder, 'contact', []),
|
||||||
$data,
|
$data,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$data->setNewCustomer(array());
|
$data->setNewCustomer([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1478,7 +1489,8 @@ class RetailcrmHistory
|
|||||||
try {
|
try {
|
||||||
$result = $switcher->setData($data)
|
$result = $switcher->setData($data)
|
||||||
->build()
|
->build()
|
||||||
->getResult();
|
->getResult()
|
||||||
|
;
|
||||||
$result->save();
|
$result->save();
|
||||||
$handled = true;
|
$handled = true;
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
@ -1517,10 +1529,10 @@ class RetailcrmHistory
|
|||||||
{
|
{
|
||||||
Db::getInstance()->execute('
|
Db::getInstance()->execute('
|
||||||
DELETE FROM ' . _DB_PREFIX_ . 'order_detail
|
DELETE FROM ' . _DB_PREFIX_ . 'order_detail
|
||||||
WHERE id_order = ' . pSQL((int)$order_id) . '
|
WHERE id_order = ' . pSQL((int) $order_id) . '
|
||||||
AND product_id = ' . pSQL((int)$product_id) . '
|
AND product_id = ' . pSQL((int) $product_id) . '
|
||||||
AND product_attribute_id = ' . pSQL((int)$product_attribute_id) . '
|
AND product_attribute_id = ' . pSQL((int) $product_attribute_id) . '
|
||||||
AND id_order_detail = ' . pSQL((int)$id_order_detail)
|
AND id_order_detail = ' . pSQL((int) $id_order_detail)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1537,7 +1549,7 @@ class RetailcrmHistory
|
|||||||
* @param \ObjectModel|\ObjectModelCore $object
|
* @param \ObjectModel|\ObjectModelCore $object
|
||||||
* @param string $action
|
* @param string $action
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private static function loadInCMS($object, $action)
|
private static function loadInCMS($object, $action)
|
||||||
{
|
{
|
||||||
@ -1569,7 +1581,7 @@ class RetailcrmHistory
|
|||||||
'loadInCMS',
|
'loadInCMS',
|
||||||
sprintf(
|
sprintf(
|
||||||
' > %s %s',
|
' > %s %s',
|
||||||
(string)$action,
|
(string) $action,
|
||||||
$e->getMessage()
|
$e->getMessage()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1596,16 +1608,16 @@ class RetailcrmHistory
|
|||||||
*/
|
*/
|
||||||
private static function filterHistory($historyEntries, $recordType)
|
private static function filterHistory($historyEntries, $recordType)
|
||||||
{
|
{
|
||||||
$history = array();
|
$history = [];
|
||||||
$organizedHistory = array();
|
$organizedHistory = [];
|
||||||
$notOurChanges = array();
|
$notOurChanges = [];
|
||||||
|
|
||||||
foreach ($historyEntries as $entry) {
|
foreach ($historyEntries as $entry) {
|
||||||
if (!isset($entry[$recordType]['externalId'])) {
|
if (!isset($entry[$recordType]['externalId'])) {
|
||||||
if ($entry['source'] == 'api'
|
if ('api' == $entry['source']
|
||||||
&& isset($change['apiKey']['current'])
|
&& isset($change['apiKey']['current'])
|
||||||
&& $entry['apiKey']['current'] == true
|
&& true == $entry['apiKey']['current']
|
||||||
&& $entry['field'] != 'externalId'
|
&& 'externalId' != $entry['field']
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
@ -1619,19 +1631,19 @@ class RetailcrmHistory
|
|||||||
$field = $entry['field'];
|
$field = $entry['field'];
|
||||||
|
|
||||||
if (!isset($organizedHistory[$externalId])) {
|
if (!isset($organizedHistory[$externalId])) {
|
||||||
$organizedHistory[$externalId] = array();
|
$organizedHistory[$externalId] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($notOurChanges[$externalId])) {
|
if (!isset($notOurChanges[$externalId])) {
|
||||||
$notOurChanges[$externalId] = array();
|
$notOurChanges[$externalId] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$entry['source'] == 'api'
|
'api' == $entry['source']
|
||||||
&& isset($entry['apiKey']['current'])
|
&& isset($entry['apiKey']['current'])
|
||||||
&& $entry['apiKey']['current'] == true
|
&& true == $entry['apiKey']['current']
|
||||||
) {
|
) {
|
||||||
if (isset($notOurChanges[$externalId][$field]) || $field == 'externalId' || $field == 'status') {
|
if (isset($notOurChanges[$externalId][$field]) || 'externalId' == $field || 'status' == $field) {
|
||||||
$organizedHistory[$externalId][] = $entry;
|
$organizedHistory[$externalId][] = $entry;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
@ -1663,7 +1675,7 @@ class RetailcrmHistory
|
|||||||
if (!empty($customerEmail)) {
|
if (!empty($customerEmail)) {
|
||||||
$item = Customer::getCustomersByEmail($customerEmail);
|
$item = Customer::getCustomersByEmail($customerEmail);
|
||||||
|
|
||||||
if (is_array($item) && count($item) > 0) {
|
if (is_array($item) && 0 < count($item)) {
|
||||||
$item = reset($item);
|
$item = reset($item);
|
||||||
|
|
||||||
return (int) $item['id_customer'];
|
return (int) $item['id_customer'];
|
||||||
@ -1686,7 +1698,7 @@ class RetailcrmHistory
|
|||||||
{
|
{
|
||||||
if (isset($item['externalIds'])) {
|
if (isset($item['externalIds'])) {
|
||||||
foreach ($item['externalIds'] as $externalId) {
|
foreach ($item['externalIds'] as $externalId) {
|
||||||
if ($externalId['code'] == 'prestashop') {
|
if ('prestashop' == $externalId['code']) {
|
||||||
return static::parseItemExternalIdString($externalId['value']);
|
return static::parseItemExternalIdString($externalId['value']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1707,23 +1719,23 @@ class RetailcrmHistory
|
|||||||
private static function parseItemExternalIdString($externalIdString)
|
private static function parseItemExternalIdString($externalIdString)
|
||||||
{
|
{
|
||||||
$parsed = explode('_', $externalIdString);
|
$parsed = explode('_', $externalIdString);
|
||||||
$data = array(
|
$data = [
|
||||||
'product_id' => 0,
|
'product_id' => 0,
|
||||||
'product_attribute_id' => 0,
|
'product_attribute_id' => 0,
|
||||||
'id_order_detail' => 0
|
'id_order_detail' => 0,
|
||||||
);
|
];
|
||||||
|
|
||||||
if (count($parsed) > 0) {
|
if (0 < count($parsed)) {
|
||||||
$productIdParsed = explode('#', $parsed[0]);
|
$productIdParsed = explode('#', $parsed[0]);
|
||||||
|
|
||||||
if (count($productIdParsed) == 2) {
|
if (2 == count($productIdParsed)) {
|
||||||
$data['product_id'] = $productIdParsed[0];
|
$data['product_id'] = $productIdParsed[0];
|
||||||
$data['product_attribute_id'] = $productIdParsed[1];
|
$data['product_attribute_id'] = $productIdParsed[1];
|
||||||
} elseif (count($productIdParsed) == 1) {
|
} elseif (1 == count($productIdParsed)) {
|
||||||
$data['product_id'] = $parsed[0];
|
$data['product_id'] = $parsed[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($parsed) == 2) {
|
if (2 == count($parsed)) {
|
||||||
$data['id_order_detail'] = $parsed[1];
|
$data['id_order_detail'] = $parsed[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1755,10 +1767,10 @@ class RetailcrmHistory
|
|||||||
*/
|
*/
|
||||||
private static function removeEdgeQuotes($str)
|
private static function removeEdgeQuotes($str)
|
||||||
{
|
{
|
||||||
if (strlen($str) >= 2) {
|
if (2 <= strlen($str)) {
|
||||||
$newStr = $str;
|
$newStr = $str;
|
||||||
|
|
||||||
if ($newStr[0] == '\'' && $newStr[strlen($newStr) - 1] == '\'') {
|
if ('\'' == $newStr[0] && '\'' == $newStr[strlen($newStr) - 1]) {
|
||||||
$newStr = substr($newStr, 1, strlen($newStr) - 2);
|
$newStr = substr($newStr, 1, strlen($newStr) - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1780,33 +1792,33 @@ class RetailcrmHistory
|
|||||||
{
|
{
|
||||||
$object->product_name = static::removeEdgeQuotes($name);
|
$object->product_name = static::removeEdgeQuotes($name);
|
||||||
|
|
||||||
if ($object->validateField('product_name', $object->product_name) !== true) {
|
if (true !== $object->validateField('product_name', $object->product_name)) {
|
||||||
$object->product_name = implode('', array('\'', $name, '\''));
|
$object->product_name = implode('', ['\'', $name, '\'']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function updateOrderItems($orderId, $newItemsIds)
|
private static function updateOrderItems($orderId, $newItemsIds)
|
||||||
{
|
{
|
||||||
$upOrderItems = array(
|
$upOrderItems = [
|
||||||
'externalId' => $orderId,
|
'externalId' => $orderId,
|
||||||
);
|
];
|
||||||
|
|
||||||
$orderdb = new Order($orderId);
|
$orderdb = new Order($orderId);
|
||||||
foreach ($orderdb->getProducts() as $item) {
|
foreach ($orderdb->getProducts() as $item) {
|
||||||
if (isset($item['product_attribute_id']) && $item['product_attribute_id'] > 0) {
|
if (isset($item['product_attribute_id']) && 0 < $item['product_attribute_id']) {
|
||||||
$productId = $item['product_id'] . '#' . $item['product_attribute_id'];
|
$productId = $item['product_id'] . '#' . $item['product_attribute_id'];
|
||||||
} else {
|
} else {
|
||||||
$productId = $item['product_id'];
|
$productId = $item['product_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$crmItem = array(
|
$crmItem = [
|
||||||
'externalIds' => array(
|
'externalIds' => [
|
||||||
array(
|
[
|
||||||
'code' => 'prestashop',
|
'code' => 'prestashop',
|
||||||
'value' => $productId . "_" . $item['id_order_detail'],
|
'value' => $productId . '_' . $item['id_order_detail'],
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
if (array_key_exists($item['id_order_detail'], $newItemsIds)) {
|
if (array_key_exists($item['id_order_detail'], $newItemsIds)) {
|
||||||
$crmItem['id'] = $newItemsIds[$item['id_order_detail']];
|
$crmItem['id'] = $newItemsIds[$item['id_order_detail']];
|
||||||
@ -1825,14 +1837,15 @@ class RetailcrmHistory
|
|||||||
* Updates sinceId for orders or customers to the latest value
|
* Updates sinceId for orders or customers to the latest value
|
||||||
*
|
*
|
||||||
* @param string $entity Can be either 'orders' or 'customers'
|
* @param string $entity Can be either 'orders' or 'customers'
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function updateSinceId($entity)
|
public static function updateSinceId($entity)
|
||||||
{
|
{
|
||||||
if ($entity === 'orders') {
|
if ('orders' === $entity) {
|
||||||
$key = 'RETAILCRM_LAST_ORDERS_SYNC';
|
$key = 'RETAILCRM_LAST_ORDERS_SYNC';
|
||||||
$method = 'ordersHistory';
|
$method = 'ordersHistory';
|
||||||
} elseif ($entity === 'customers') {
|
} elseif ('customers' === $entity) {
|
||||||
$key = 'RETAILCRM_LAST_CUSTOMERS_SYNC';
|
$key = 'RETAILCRM_LAST_CUSTOMERS_SYNC';
|
||||||
$method = 'customersHistory';
|
$method = 'customersHistory';
|
||||||
} else {
|
} else {
|
||||||
@ -1843,24 +1856,24 @@ class RetailcrmHistory
|
|||||||
RetailcrmLogger::writeDebug(__METHOD__, "Current $entity sinceId: $currentSinceID");
|
RetailcrmLogger::writeDebug(__METHOD__, "Current $entity sinceId: $currentSinceID");
|
||||||
|
|
||||||
$historyResponse = call_user_func_array(
|
$historyResponse = call_user_func_array(
|
||||||
array(self::$api, $method),
|
[self::$api, $method],
|
||||||
array(
|
[
|
||||||
array('sinceId' => $currentSinceID),
|
['sinceId' => $currentSinceID],
|
||||||
null,
|
null,
|
||||||
20
|
20,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($historyResponse instanceof RetailcrmApiResponse && $historyResponse->offsetExists('pagination')) {
|
if ($historyResponse instanceof RetailcrmApiResponse && $historyResponse->offsetExists('pagination')) {
|
||||||
$lastPage = $historyResponse['pagination']['totalPageCount'];
|
$lastPage = $historyResponse['pagination']['totalPageCount'];
|
||||||
if ($lastPage > 1) {
|
if (1 < $lastPage) {
|
||||||
$historyResponse = call_user_func_array(
|
$historyResponse = call_user_func_array(
|
||||||
array(self::$api, $method),
|
[self::$api, $method],
|
||||||
array(
|
[
|
||||||
array('sinceId' => $currentSinceID),
|
['sinceId' => $currentSinceID],
|
||||||
$lastPage,
|
$lastPage,
|
||||||
20
|
20,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1871,7 +1884,7 @@ class RetailcrmHistory
|
|||||||
$history = $historyResponse['history'];
|
$history = $historyResponse['history'];
|
||||||
$lastSinceId = end($history)['id'];
|
$lastSinceId = end($history)['id'];
|
||||||
|
|
||||||
if ($currentSinceID !== strval($lastSinceId)) {
|
if ($currentSinceID !== (string) $lastSinceId) {
|
||||||
RetailcrmLogger::writeDebug(__METHOD__, "Updating to: $lastSinceId");
|
RetailcrmLogger::writeDebug(__METHOD__, "Updating to: $lastSinceId");
|
||||||
Configuration::updateValue($key, $lastSinceId);
|
Configuration::updateValue($key, $lastSinceId);
|
||||||
}
|
}
|
||||||
|
@ -35,23 +35,24 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
class RetailcrmHistoryHelper {
|
class RetailcrmHistoryHelper
|
||||||
|
{
|
||||||
public static function assemblyOrder($orderHistory)
|
public static function assemblyOrder($orderHistory)
|
||||||
{
|
{
|
||||||
if (file_exists( __DIR__ . '/../objects.xml')) {
|
if (file_exists(__DIR__ . '/../objects.xml')) {
|
||||||
$objects = simplexml_load_file(__DIR__ . '/../objects.xml');
|
$objects = simplexml_load_file(__DIR__ . '/../objects.xml');
|
||||||
foreach($objects->fields->field as $object) {
|
foreach ($objects->fields->field as $object) {
|
||||||
$fields[(string)$object["group"]][(string)$object["id"]] = (string)$object;
|
$fields[(string) $object['group']][(string) $object['id']] = (string) $object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$orders = array();
|
$orders = [];
|
||||||
foreach ($orderHistory as $change) {
|
foreach ($orderHistory as $change) {
|
||||||
$change['order'] = self::removeEmpty($change['order']);
|
$change['order'] = self::removeEmpty($change['order']);
|
||||||
|
|
||||||
if (isset($change['order']['items']) && $change['order']['items']) {
|
if (isset($change['order']['items']) && $change['order']['items']) {
|
||||||
$items = array();
|
$items = [];
|
||||||
|
|
||||||
foreach($change['order']['items'] as $item) {
|
foreach ($change['order']['items'] as $item) {
|
||||||
$items[$item['id']] = $item;
|
$items[$item['id']] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +76,10 @@ class RetailcrmHistoryHelper {
|
|||||||
} else {
|
} else {
|
||||||
$orders[$change['order']['id']]['payments'][$change['payment']['id']] = $change['payment'];
|
$orders[$change['order']['id']]['payments'][$change['payment']['id']] = $change['payment'];
|
||||||
}
|
}
|
||||||
if ($change['oldValue'] == null && $change['field'] == 'payments') {
|
if (null == $change['oldValue'] && 'payments' == $change['field']) {
|
||||||
$orders[$change['order']['id']]['payments'][$change['payment']['id']]['create'] = true;
|
$orders[$change['order']['id']]['payments'][$change['payment']['id']]['create'] = true;
|
||||||
}
|
}
|
||||||
if ($change['newValue'] == null && $change['field'] == 'payments') {
|
if (null == $change['newValue'] && 'payments' == $change['field']) {
|
||||||
$orders[$change['order']['id']]['payments'][$change['payment']['id']]['delete'] = true;
|
$orders[$change['order']['id']]['payments'][$change['payment']['id']]['delete'] = true;
|
||||||
}
|
}
|
||||||
if (!$orders[$change['order']['id']]['payments'][$change['payment']['id']] && $fields['payment'][$change['field']]) {
|
if (!$orders[$change['order']['id']]['payments'][$change['payment']['id']] && $fields['payment'][$change['field']]) {
|
||||||
@ -93,10 +94,10 @@ class RetailcrmHistoryHelper {
|
|||||||
$orders[$change['order']['id']]['items'][$change['item']['id']] = $change['item'];
|
$orders[$change['order']['id']]['items'][$change['item']['id']] = $change['item'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($change['oldValue']) && $change['field'] == 'order_product') {
|
if (empty($change['oldValue']) && 'order_product' == $change['field']) {
|
||||||
$orders[$change['order']['id']]['items'][$change['item']['id']]['create'] = true;
|
$orders[$change['order']['id']]['items'][$change['item']['id']]['create'] = true;
|
||||||
}
|
}
|
||||||
if (empty($change['newValue']) && $change['field'] == 'order_product') {
|
if (empty($change['newValue']) && 'order_product' == $change['field']) {
|
||||||
$orders[$change['order']['id']]['items'][$change['item']['id']]['delete'] = true;
|
$orders[$change['order']['id']]['items'][$change['item']['id']]['delete'] = true;
|
||||||
}
|
}
|
||||||
if (!isset($orders[$change['order']['id']]['items'][$change['item']['id']]['create'])
|
if (!isset($orders[$change['order']['id']]['items'][$change['item']['id']]['create'])
|
||||||
@ -106,7 +107,7 @@ class RetailcrmHistoryHelper {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($fields['delivery'][$change['field']])
|
if (isset($fields['delivery'][$change['field']])
|
||||||
&& $fields['delivery'][$change['field']] == 'service'
|
&& 'service' == $fields['delivery'][$change['field']]
|
||||||
) {
|
) {
|
||||||
$orders[$change['order']['id']]['delivery']['service']['code'] = self::newValue($change['newValue']);
|
$orders[$change['order']['id']]['delivery']['service']['code'] = self::newValue($change['newValue']);
|
||||||
} elseif (isset($fields['delivery'][$change['field']])
|
} elseif (isset($fields['delivery'][$change['field']])
|
||||||
@ -125,7 +126,7 @@ class RetailcrmHistoryHelper {
|
|||||||
&& $fields['customerContragent'][$change['field']]
|
&& $fields['customerContragent'][$change['field']]
|
||||||
) {
|
) {
|
||||||
$orders[$change['order']['id']][$fields['customerContragent'][$change['field']]] = self::newValue($change['newValue']);
|
$orders[$change['order']['id']][$fields['customerContragent'][$change['field']]] = self::newValue($change['newValue']);
|
||||||
} elseif (strripos($change['field'], 'custom_') !== false) {
|
} elseif (false !== strripos($change['field'], 'custom_')) {
|
||||||
$orders[$change['order']['id']]['customFields'][str_replace('custom_', '', $change['field'])] = self::newValue($change['newValue']);
|
$orders[$change['order']['id']]['customFields'][str_replace('custom_', '', $change['field'])] = self::newValue($change['newValue']);
|
||||||
} elseif (isset($fields['order'][$change['field']])
|
} elseif (isset($fields['order'][$change['field']])
|
||||||
&& $fields['order'][$change['field']]
|
&& $fields['order'][$change['field']]
|
||||||
@ -141,7 +142,7 @@ class RetailcrmHistoryHelper {
|
|||||||
$orders[$change['order']['id']]['create'] = 1;
|
$orders[$change['order']['id']]['create'] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($change['deleted'])) {
|
if (isset($change['deleted'])) {
|
||||||
$orders[$change['order']['id']]['deleted'] = 1;
|
$orders[$change['order']['id']]['deleted'] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,19 +153,19 @@ class RetailcrmHistoryHelper {
|
|||||||
|
|
||||||
public static function assemblyCustomer($customerHistory)
|
public static function assemblyCustomer($customerHistory)
|
||||||
{
|
{
|
||||||
$fields = array();
|
$fields = [];
|
||||||
|
|
||||||
if (file_exists(_PS_ROOT_DIR_ . '/modules/retailcrm/objects.xml')) {
|
if (file_exists(_PS_ROOT_DIR_ . '/modules/retailcrm/objects.xml')) {
|
||||||
$objects = simplexml_load_file(_PS_ROOT_DIR_ . '/modules/retailcrm/objects.xml');
|
$objects = simplexml_load_file(_PS_ROOT_DIR_ . '/modules/retailcrm/objects.xml');
|
||||||
|
|
||||||
foreach($objects->fields->field as $object) {
|
foreach ($objects->fields->field as $object) {
|
||||||
if ($object["group"] == 'customer') {
|
if ('customer' == $object['group']) {
|
||||||
$fields[(string)$object["group"]][(string)$object["id"]] = (string)$object;
|
$fields[(string) $object['group']][(string) $object['id']] = (string) $object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$customers = array();
|
$customers = [];
|
||||||
|
|
||||||
foreach ($customerHistory as $change) {
|
foreach ($customerHistory as $change) {
|
||||||
$change['customer'] = self::removeEmpty($change['customer']);
|
$change['customer'] = self::removeEmpty($change['customer']);
|
||||||
@ -176,7 +177,7 @@ class RetailcrmHistoryHelper {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($change['field'] == 'id') {
|
if ('id' == $change['field']) {
|
||||||
$customers[$change['customer']['id']] = $change['customer'];
|
$customers[$change['customer']['id']] = $change['customer'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,12 +195,12 @@ class RetailcrmHistoryHelper {
|
|||||||
|
|
||||||
// email_marketing_unsubscribed_at old value will be null and new value will be datetime in
|
// email_marketing_unsubscribed_at old value will be null and new value will be datetime in
|
||||||
// `Y-m-d H:i:s` format if customer was marked as unsubscribed in retailCRM
|
// `Y-m-d H:i:s` format if customer was marked as unsubscribed in retailCRM
|
||||||
if (isset($change['customer']['id']) &&
|
if (isset($change['customer']['id'])
|
||||||
$change['field'] == 'email_marketing_unsubscribed_at'
|
&& 'email_marketing_unsubscribed_at' == $change['field']
|
||||||
) {
|
) {
|
||||||
if ($change['oldValue'] == null && is_string(self::newValue($change['newValue']))) {
|
if (null == $change['oldValue'] && is_string(self::newValue($change['newValue']))) {
|
||||||
$customers[$change['customer']['id']]['subscribed'] = false;
|
$customers[$change['customer']['id']]['subscribed'] = false;
|
||||||
} elseif (is_string($change['oldValue']) && self::newValue($change['newValue']) == null) {
|
} elseif (is_string($change['oldValue']) && null == self::newValue($change['newValue'])) {
|
||||||
$customers[$change['customer']['id']]['subscribed'] = true;
|
$customers[$change['customer']['id']]['subscribed'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,19 +216,19 @@ class RetailcrmHistoryHelper {
|
|||||||
|
|
||||||
public static function assemblyCorporateCustomer($customerHistory)
|
public static function assemblyCorporateCustomer($customerHistory)
|
||||||
{
|
{
|
||||||
$fields = array();
|
$fields = [];
|
||||||
|
|
||||||
if (file_exists(_PS_ROOT_DIR_ . '/modules/retailcrm/objects.xml')) {
|
if (file_exists(_PS_ROOT_DIR_ . '/modules/retailcrm/objects.xml')) {
|
||||||
$objects = simplexml_load_file(_PS_ROOT_DIR_ . '/modules/retailcrm/objects.xml');
|
$objects = simplexml_load_file(_PS_ROOT_DIR_ . '/modules/retailcrm/objects.xml');
|
||||||
|
|
||||||
foreach($objects->fields->field as $object) {
|
foreach ($objects->fields->field as $object) {
|
||||||
if (in_array($object["group"], array('customerCorporate', 'customerAddress'))) {
|
if (in_array($object['group'], ['customerCorporate', 'customerAddress'])) {
|
||||||
$fields[(string)$object["group"]][(string)$object["id"]] = (string)$object;
|
$fields[(string) $object['group']][(string) $object['id']] = (string) $object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$customersCorporate = array();
|
$customersCorporate = [];
|
||||||
foreach ($customerHistory as $change) {
|
foreach ($customerHistory as $change) {
|
||||||
$change['customer'] = self::removeEmpty($change['customer']);
|
$change['customer'] = self::removeEmpty($change['customer']);
|
||||||
|
|
||||||
@ -261,13 +262,13 @@ class RetailcrmHistoryHelper {
|
|||||||
&& $fields['customerAddress'][$change['field']]
|
&& $fields['customerAddress'][$change['field']]
|
||||||
) {
|
) {
|
||||||
if (empty($customersCorporate[$change['customer']['id']]['address'])) {
|
if (empty($customersCorporate[$change['customer']['id']]['address'])) {
|
||||||
$customersCorporate[$change['customer']['id']]['address'] = array();
|
$customersCorporate[$change['customer']['id']]['address'] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$customersCorporate[$change['customer']['id']]['address'][$fields['customerAddress'][$change['field']]] = self::newValue($change['newValue']);
|
$customersCorporate[$change['customer']['id']]['address'][$fields['customerAddress'][$change['field']]] = self::newValue($change['newValue']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($change['field'] == 'address') {
|
if ('address' == $change['field']) {
|
||||||
$customersCorporate[$change['customer']['id']]['address'] = array_merge($change['address'], self::newValue($change['newValue']));
|
$customersCorporate[$change['customer']['id']]['address'] = array_merge($change['address'], self::newValue($change['newValue']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,10 +294,10 @@ class RetailcrmHistoryHelper {
|
|||||||
|
|
||||||
public static function removeEmpty($inputArray)
|
public static function removeEmpty($inputArray)
|
||||||
{
|
{
|
||||||
$outputArray = array();
|
$outputArray = [];
|
||||||
if (!empty($inputArray)) {
|
if (!empty($inputArray)) {
|
||||||
foreach ($inputArray as $key => $element) {
|
foreach ($inputArray as $key => $element) {
|
||||||
if(!empty($element) || $element === 0 || $element === '0'){
|
if (!empty($element) || 0 === $element || '0' === $element) {
|
||||||
if (is_array($element)) {
|
if (is_array($element)) {
|
||||||
$element = self::removeEmpty($element);
|
$element = self::removeEmpty($element);
|
||||||
}
|
}
|
||||||
@ -312,7 +313,7 @@ class RetailcrmHistoryHelper {
|
|||||||
* @param array $address Crm Order address changes
|
* @param array $address Crm Order address changes
|
||||||
*
|
*
|
||||||
* @return bool <b>true</b> if changed address field, which is used to generate
|
* @return bool <b>true</b> if changed address field, which is used to generate
|
||||||
* <b>address1</b> and <b>address2</b> fields in CMS. <b>false</b> otherwise
|
* <b>address1</b> and <b>address2</b> fields in CMS. <b>false</b> otherwise
|
||||||
*/
|
*/
|
||||||
public static function isAddressLineChanged($address)
|
public static function isAddressLineChanged($address)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@ class RetailcrmIcml
|
|||||||
$this->shop = $shop;
|
$this->shop = $shop;
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
|
|
||||||
$this->properties = array(
|
$this->properties = [
|
||||||
'name',
|
'name',
|
||||||
'productName',
|
'productName',
|
||||||
'price',
|
'price',
|
||||||
@ -62,14 +62,14 @@ class RetailcrmIcml
|
|||||||
'productActivity',
|
'productActivity',
|
||||||
'dimensions',
|
'dimensions',
|
||||||
'vatRate',
|
'vatRate',
|
||||||
);
|
];
|
||||||
|
|
||||||
$this->params = array(
|
$this->params = [
|
||||||
'article' => 'Артикул',
|
'article' => 'Артикул',
|
||||||
'color' => 'Цвет',
|
'color' => 'Цвет',
|
||||||
'weight' => 'Вес',
|
'weight' => 'Вес',
|
||||||
'tax' => 'Наценка'
|
'tax' => 'Наценка',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generate($categories, $offers)
|
public function generate($categories, $offers)
|
||||||
@ -121,7 +121,7 @@ class RetailcrmIcml
|
|||||||
$e->appendChild($this->dd->createElement('picture', $category['picture']));
|
$e->appendChild($this->dd->createElement('picture', $category['picture']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($category['parentId'] > 0) {
|
if (0 < $category['parentId']) {
|
||||||
$e->setAttribute('parentId', $category['parentId']);
|
$e->setAttribute('parentId', $category['parentId']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,11 +152,13 @@ class RetailcrmIcml
|
|||||||
$offerKeys = array_keys($offer);
|
$offerKeys = array_keys($offer);
|
||||||
|
|
||||||
foreach ($offerKeys as $key) {
|
foreach ($offerKeys as $key) {
|
||||||
if ($offer[$key] == null) continue;
|
if (null == $offer[$key]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array($key, $this->properties)) {
|
if (in_array($key, $this->properties)) {
|
||||||
if(is_array($offer[$key])) {
|
if (is_array($offer[$key])) {
|
||||||
foreach($offer[$key] as $property) {
|
foreach ($offer[$key] as $property) {
|
||||||
$e->appendChild(
|
$e->appendChild(
|
||||||
$this->dd->createElement($key)
|
$this->dd->createElement($key)
|
||||||
)->appendChild(
|
)->appendChild(
|
||||||
|
@ -52,9 +52,9 @@ class RetailcrmInventories
|
|||||||
$page = 1;
|
$page = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$result = self::$api->storeInventories(array(), $page, 250);
|
$result = self::$api->storeInventories([], $page, 250);
|
||||||
|
|
||||||
if ($result === false) {
|
if (false === $result) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,11 +63,11 @@ class RetailcrmInventories
|
|||||||
}
|
}
|
||||||
|
|
||||||
$totalPageCount = $result['pagination']['totalPageCount'];
|
$totalPageCount = $result['pagination']['totalPageCount'];
|
||||||
$page++;
|
++$page;
|
||||||
} while ($page <= $totalPageCount);
|
} while ($page <= $totalPageCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function setQuantityOffer($offer)
|
private static function setQuantityOffer($offer)
|
||||||
{
|
{
|
||||||
if (isset($offer['externalId'])) {
|
if (isset($offer['externalId'])) {
|
||||||
$invOffer = explode('#', $offer['externalId']);
|
$invOffer = explode('#', $offer['externalId']);
|
||||||
|
@ -35,14 +35,13 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
|
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
|
||||||
date_default_timezone_set(@date_default_timezone_get());
|
date_default_timezone_set(@date_default_timezone_get());
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/../../../config/config.inc.php');
|
require_once __DIR__ . '/../../../config/config.inc.php';
|
||||||
require_once(dirname(__FILE__) . '/../../../init.php');
|
require_once __DIR__ . '/../../../init.php';
|
||||||
require_once(dirname(__FILE__) . '/../bootstrap.php');
|
require_once __DIR__ . '/../bootstrap.php';
|
||||||
|
|
||||||
if (!defined('_PS_VERSION_')) {
|
if (!defined('_PS_VERSION_')) {
|
||||||
exit;
|
exit;
|
||||||
@ -53,7 +52,8 @@ if (!defined('_PS_VERSION_')) {
|
|||||||
*
|
*
|
||||||
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
||||||
* @license GPL
|
* @license GPL
|
||||||
* @link https://retailcrm.ru
|
*
|
||||||
|
* @see https://retailcrm.ru
|
||||||
*/
|
*/
|
||||||
class RetailcrmJobManager
|
class RetailcrmJobManager
|
||||||
{
|
{
|
||||||
@ -82,14 +82,14 @@ class RetailcrmJobManager
|
|||||||
* DateInterval must be positive. Pass `null` instead of DateInterval to remove
|
* DateInterval must be positive. Pass `null` instead of DateInterval to remove
|
||||||
* any delay - in other words, jobs without interval will be executed every time.
|
* any delay - in other words, jobs without interval will be executed every time.
|
||||||
*
|
*
|
||||||
* @param array $jobs Jobs list
|
* @param array $jobs Jobs list
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function startJobs(
|
public static function startJobs(
|
||||||
$jobs = array()
|
$jobs = []
|
||||||
) {
|
) {
|
||||||
RetailcrmLogger::writeDebug(__METHOD__,'starting JobManager');
|
RetailcrmLogger::writeDebug(__METHOD__, 'starting JobManager');
|
||||||
static::execJobs($jobs);
|
static::execJobs($jobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,11 +100,11 @@ class RetailcrmJobManager
|
|||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function execJobs($jobs = array())
|
public static function execJobs($jobs = [])
|
||||||
{
|
{
|
||||||
$current = date_create('now');
|
$current = date_create_immutable('now');
|
||||||
$lastRuns = array();
|
$lastRuns = [];
|
||||||
$lastRunsDetails = array();
|
$lastRunsDetails = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$lastRuns = static::getLastRuns();
|
$lastRuns = static::getLastRuns();
|
||||||
@ -140,13 +140,13 @@ class RetailcrmJobManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
uasort($jobs, function ($diff1, $diff2) {
|
uasort($jobs, function ($diff1, $diff2) {
|
||||||
$date1 = new \DateTime();
|
$date1 = new \DateTimeImmutable();
|
||||||
$date2 = new \DateTime();
|
$date2 = new \DateTimeImmutable();
|
||||||
|
|
||||||
if (!is_null($diff1)) {
|
if (null !== $diff1) {
|
||||||
$date1->add($diff1);
|
$date1->add($diff1);
|
||||||
}
|
}
|
||||||
if (!is_null($diff2)) {
|
if (null !== $diff2) {
|
||||||
$date2->add($diff2);
|
$date2->add($diff2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,21 +159,21 @@ class RetailcrmJobManager
|
|||||||
|
|
||||||
foreach ($jobs as $job => $diff) {
|
foreach ($jobs as $job => $diff) {
|
||||||
try {
|
try {
|
||||||
if (isset($lastRuns[$job]) && $lastRuns[$job] instanceof DateTime) {
|
if (isset($lastRuns[$job]) && $lastRuns[$job] instanceof DateTimeImmutable) {
|
||||||
$shouldRunAt = clone $lastRuns[$job];
|
$shouldRunAt = clone $lastRuns[$job];
|
||||||
|
|
||||||
if ($diff instanceof DateInterval) {
|
if ($diff instanceof DateInterval) {
|
||||||
$shouldRunAt->add($diff);
|
$shouldRunAt->add($diff);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$shouldRunAt = \DateTime::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00');
|
$shouldRunAt = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00');
|
||||||
}
|
}
|
||||||
|
|
||||||
RetailcrmLogger::writeDebug(__METHOD__, sprintf(
|
RetailcrmLogger::writeDebug(__METHOD__, sprintf(
|
||||||
'Checking %s, interval %s, shouldRunAt: %s: %s',
|
'Checking %s, interval %s, shouldRunAt: %s: %s',
|
||||||
$job,
|
$job,
|
||||||
is_null($diff) ? 'NULL' : $diff->format('%R%Y-%m-%d %H:%i:%s:%F'),
|
null === $diff ? 'NULL' : $diff->format('%R%Y-%m-%d %H:%i:%s:%F'),
|
||||||
isset($shouldRunAt) && $shouldRunAt instanceof \DateTime
|
isset($shouldRunAt) && $shouldRunAt instanceof \DateTimeImmutable
|
||||||
? $shouldRunAt->format(DATE_RFC3339)
|
? $shouldRunAt->format(DATE_RFC3339)
|
||||||
: 'undefined',
|
: 'undefined',
|
||||||
(isset($shouldRunAt) && $shouldRunAt <= $current) ? 'true' : 'false'
|
(isset($shouldRunAt) && $shouldRunAt <= $current) ? 'true' : 'false'
|
||||||
@ -186,7 +186,7 @@ class RetailcrmJobManager
|
|||||||
__METHOD__,
|
__METHOD__,
|
||||||
sprintf('Executed job %s, result: %s', $job, $result ? 'true' : 'false')
|
sprintf('Executed job %s, result: %s', $job, $result ? 'true' : 'false')
|
||||||
);
|
);
|
||||||
$lastRuns[$job] = new \DateTime('now');
|
$lastRuns[$job] = new \DateTimeImmutable('now');
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ class RetailcrmJobManager
|
|||||||
|
|
||||||
$lastRunsDetails[$job] = [
|
$lastRunsDetails[$job] = [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'lastRun' => new \DateTime('now'),
|
'lastRun' => new \DateTimeImmutable('now'),
|
||||||
'error' => [
|
'error' => [
|
||||||
'message' => $exception->getMessage(),
|
'message' => $exception->getMessage(),
|
||||||
'trace' => $exception->getTraceAsString(),
|
'trace' => $exception->getTraceAsString(),
|
||||||
@ -220,7 +220,7 @@ class RetailcrmJobManager
|
|||||||
if (isset($result) && $result) {
|
if (isset($result) && $result) {
|
||||||
$lastRunsDetails[$job] = [
|
$lastRunsDetails[$job] = [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'lastRun' => new \DateTime('now'),
|
'lastRun' => new \DateTimeImmutable('now'),
|
||||||
'error' => null,
|
'error' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -243,12 +243,13 @@ class RetailcrmJobManager
|
|||||||
static::unlock();
|
static::unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run job in the force mode so it will run even if there's another job running
|
* Run job in the force mode so it will run even if there's another job running
|
||||||
*
|
*
|
||||||
* @param $jobName
|
* @param $jobName
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function execManualJob($jobName)
|
public static function execManualJob($jobName)
|
||||||
@ -259,7 +260,7 @@ class RetailcrmJobManager
|
|||||||
if ($result) {
|
if ($result) {
|
||||||
static::updateLastRunDetail($jobName, [
|
static::updateLastRunDetail($jobName, [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'lastRun' => new \DateTime('now'),
|
'lastRun' => new \DateTimeImmutable('now'),
|
||||||
'error' => null,
|
'error' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -275,7 +276,7 @@ class RetailcrmJobManager
|
|||||||
RetailcrmLogger::printException($exception, '', false);
|
RetailcrmLogger::printException($exception, '', false);
|
||||||
self::updateLastRunDetail($jobName, [
|
self::updateLastRunDetail($jobName, [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'lastRun' => new \DateTime('now'),
|
'lastRun' => new \DateTimeImmutable('now'),
|
||||||
'error' => [
|
'error' => [
|
||||||
'message' => $exception->getMessage(),
|
'message' => $exception->getMessage(),
|
||||||
'trace' => $exception->getTraceAsString(),
|
'trace' => $exception->getTraceAsString(),
|
||||||
@ -286,32 +287,32 @@ class RetailcrmJobManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts jobs last runs from db
|
* Extracts jobs last runs from db
|
||||||
*
|
*
|
||||||
* @return array<string, \DateTime>
|
* @return array<string, \DateTime>
|
||||||
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function getLastRuns()
|
private static function getLastRuns()
|
||||||
{
|
{
|
||||||
$lastRuns = json_decode((string)Configuration::getGlobalValue(self::LAST_RUN_NAME), true);
|
$lastRuns = json_decode((string) Configuration::getGlobalValue(self::LAST_RUN_NAME), true);
|
||||||
|
|
||||||
if (json_last_error() != JSON_ERROR_NONE) {
|
if (JSON_ERROR_NONE != json_last_error()) {
|
||||||
$lastRuns = array();
|
$lastRuns = [];
|
||||||
} else {
|
} else {
|
||||||
foreach ($lastRuns as $job => $ran) {
|
foreach ($lastRuns as $job => $ran) {
|
||||||
$lastRan = DateTime::createFromFormat(DATE_RFC3339, $ran);
|
$lastRan = DateTimeImmutable::createFromFormat(DATE_RFC3339, $ran);
|
||||||
|
|
||||||
if ($lastRan instanceof DateTime) {
|
if ($lastRan instanceof DateTimeImmutable) {
|
||||||
$lastRuns[$job] = $lastRan;
|
$lastRuns[$job] = $lastRan;
|
||||||
} else {
|
} else {
|
||||||
$lastRuns[$job] = new DateTime();
|
$lastRuns[$job] = new DateTimeImmutable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (array)$lastRuns;
|
return (array) $lastRuns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -321,16 +322,16 @@ class RetailcrmJobManager
|
|||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function setLastRuns($lastRuns = array())
|
private static function setLastRuns($lastRuns = [])
|
||||||
{
|
{
|
||||||
$now = new DateTime();
|
$now = new DateTimeImmutable();
|
||||||
|
|
||||||
if (!is_array($lastRuns)) {
|
if (!is_array($lastRuns)) {
|
||||||
$lastRuns = array();
|
$lastRuns = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($lastRuns as $job => $ran) {
|
foreach ($lastRuns as $job => $ran) {
|
||||||
if ($ran instanceof DateTime) {
|
if ($ran instanceof DateTimeImmutable) {
|
||||||
$lastRuns[$job] = $ran->format(DATE_RFC3339);
|
$lastRuns[$job] = $ran->format(DATE_RFC3339);
|
||||||
} else {
|
} else {
|
||||||
$lastRuns[$job] = $now->format(DATE_RFC3339);
|
$lastRuns[$job] = $now->format(DATE_RFC3339);
|
||||||
@ -342,12 +343,13 @@ class RetailcrmJobManager
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration::updateGlobalValue(self::LAST_RUN_NAME, (string)json_encode($lastRuns));
|
Configuration::updateGlobalValue(self::LAST_RUN_NAME, (string) json_encode($lastRuns));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $jobName
|
* @param string $jobName
|
||||||
* @param Datetime|null $data
|
* @param Datetime|null $data
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function updateLastRun($jobName, $data)
|
public static function updateLastRun($jobName, $data)
|
||||||
@ -361,19 +363,20 @@ class RetailcrmJobManager
|
|||||||
* Extracts jobs last runs from db
|
* Extracts jobs last runs from db
|
||||||
*
|
*
|
||||||
* @return array<string, array>
|
* @return array<string, array>
|
||||||
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function getLastRunDetails()
|
public static function getLastRunDetails()
|
||||||
{
|
{
|
||||||
$lastRuns = json_decode((string)Configuration::getGlobalValue(self::LAST_RUN_DETAIL_NAME), true);
|
$lastRuns = json_decode((string) Configuration::getGlobalValue(self::LAST_RUN_DETAIL_NAME), true);
|
||||||
|
|
||||||
if (json_last_error() != JSON_ERROR_NONE) {
|
if (JSON_ERROR_NONE != json_last_error()) {
|
||||||
$lastRuns = array();
|
$lastRuns = [];
|
||||||
} else {
|
} else {
|
||||||
foreach ($lastRuns as $job => $details) {
|
foreach ($lastRuns as $job => $details) {
|
||||||
$lastRan = DateTime::createFromFormat(DATE_RFC3339, $details['lastRun']);
|
$lastRan = DateTimeImmutable::createFromFormat(DATE_RFC3339, $details['lastRun']);
|
||||||
|
|
||||||
if ($lastRan instanceof DateTime) {
|
if ($lastRan instanceof DateTimeImmutable) {
|
||||||
$lastRuns[$job]['lastRun'] = $lastRan;
|
$lastRuns[$job]['lastRun'] = $lastRan;
|
||||||
} else {
|
} else {
|
||||||
$lastRuns[$job]['lastRun'] = null;
|
$lastRuns[$job]['lastRun'] = null;
|
||||||
@ -381,7 +384,7 @@ class RetailcrmJobManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (array)$lastRuns;
|
return (array) $lastRuns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -391,26 +394,27 @@ class RetailcrmJobManager
|
|||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function setLastRunDetails($lastRuns = array())
|
private static function setLastRunDetails($lastRuns = [])
|
||||||
{
|
{
|
||||||
if (!is_array($lastRuns)) {
|
if (!is_array($lastRuns)) {
|
||||||
$lastRuns = array();
|
$lastRuns = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($lastRuns as $job => $details) {
|
foreach ($lastRuns as $job => $details) {
|
||||||
if (isset($details['lastRun']) && $details['lastRun'] instanceof DateTime) {
|
if (isset($details['lastRun']) && $details['lastRun'] instanceof DateTimeImmutable) {
|
||||||
$lastRuns[$job]['lastRun'] = $details['lastRun']->format(DATE_RFC3339);
|
$lastRuns[$job]['lastRun'] = $details['lastRun']->format(DATE_RFC3339);
|
||||||
} else {
|
} else {
|
||||||
$lastRuns[$job]['lastRun'] = null;
|
$lastRuns[$job]['lastRun'] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration::updateGlobalValue(self::LAST_RUN_DETAIL_NAME, (string)json_encode($lastRuns));
|
Configuration::updateGlobalValue(self::LAST_RUN_DETAIL_NAME, (string) json_encode($lastRuns));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $jobName
|
* @param string $jobName
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function updateLastRunDetail($jobName, $data)
|
public static function updateLastRunDetail($jobName, $data)
|
||||||
@ -424,12 +428,13 @@ class RetailcrmJobManager
|
|||||||
* Runs job
|
* Runs job
|
||||||
*
|
*
|
||||||
* @param string $job
|
* @param string $job
|
||||||
* @param bool $once
|
* @param bool $once
|
||||||
* @param bool $cliMode
|
* @param bool $cliMode
|
||||||
* @param bool $force
|
* @param bool $force
|
||||||
* @param int $shopId
|
* @param int $shopId
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
* @throws \RetailcrmJobManagerException
|
* @throws \RetailcrmJobManagerException
|
||||||
*/
|
*/
|
||||||
public static function runJob($job, $cliMode = false, $force = false, $shopId = null)
|
public static function runJob($job, $cliMode = false, $force = false, $shopId = null)
|
||||||
@ -441,7 +446,7 @@ class RetailcrmJobManager
|
|||||||
} catch (\RetailcrmJobManagerException $exception) {
|
} catch (\RetailcrmJobManagerException $exception) {
|
||||||
throw $exception;
|
throw $exception;
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
throw new RetailcrmJobManagerException($exception->getMessage(), $job, array(), 0, $exception);
|
throw new RetailcrmJobManagerException($exception->getMessage(), $job, [], 0, $exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +463,7 @@ class RetailcrmJobManager
|
|||||||
$jobs[$name] = serialize($interval);
|
$jobs[$name] = serialize($interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (string)base64_encode(json_encode($jobs));
|
return (string) base64_encode(json_encode($jobs));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -472,7 +477,7 @@ class RetailcrmJobManager
|
|||||||
*/
|
*/
|
||||||
public static function setCurrentJob($job)
|
public static function setCurrentJob($job)
|
||||||
{
|
{
|
||||||
return (bool)Configuration::updateGlobalValue(self::CURRENT_TASK, $job);
|
return (bool) Configuration::updateGlobalValue(self::CURRENT_TASK, $job);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -482,7 +487,7 @@ class RetailcrmJobManager
|
|||||||
*/
|
*/
|
||||||
public static function getCurrentJob()
|
public static function getCurrentJob()
|
||||||
{
|
{
|
||||||
return (string)Configuration::getGlobalValue(self::CURRENT_TASK);
|
return (string) Configuration::getGlobalValue(self::CURRENT_TASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -494,7 +499,7 @@ class RetailcrmJobManager
|
|||||||
*/
|
*/
|
||||||
public static function clearCurrentJob($job)
|
public static function clearCurrentJob($job)
|
||||||
{
|
{
|
||||||
if (is_null($job) || self::getCurrentJob() == $job) {
|
if (null === $job || self::getCurrentJob() == $job) {
|
||||||
return Configuration::deleteByName(self::CURRENT_TASK);
|
return Configuration::deleteByName(self::CURRENT_TASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,6 +510,7 @@ class RetailcrmJobManager
|
|||||||
* Resets JobManager internal state. Doesn't work if JobManager is active.
|
* Resets JobManager internal state. Doesn't work if JobManager is active.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function reset()
|
public static function reset()
|
||||||
@ -536,7 +542,7 @@ class RetailcrmJobManager
|
|||||||
{
|
{
|
||||||
$error = error_get_last();
|
$error = error_get_last();
|
||||||
|
|
||||||
if(null !== $error && $error['type'] === E_ERROR) {
|
if (null !== $error && E_ERROR === $error['type']) {
|
||||||
self::defaultShutdownHandler($error);
|
self::defaultShutdownHandler($error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -547,7 +553,7 @@ class RetailcrmJobManager
|
|||||||
private static function registerShutdownHandler()
|
private static function registerShutdownHandler()
|
||||||
{
|
{
|
||||||
if (!self::$shutdownHandlerRegistered) {
|
if (!self::$shutdownHandlerRegistered) {
|
||||||
register_shutdown_function(array('RetailcrmJobManager', 'shutdownHandlerWrapper'));
|
register_shutdown_function(['RetailcrmJobManager', 'shutdownHandlerWrapper']);
|
||||||
self::$shutdownHandlerRegistered = true;
|
self::$shutdownHandlerRegistered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -560,16 +566,16 @@ class RetailcrmJobManager
|
|||||||
private static function defaultShutdownHandler($error)
|
private static function defaultShutdownHandler($error)
|
||||||
{
|
{
|
||||||
if (is_callable(self::$customShutdownHandler)) {
|
if (is_callable(self::$customShutdownHandler)) {
|
||||||
call_user_func_array(self::$customShutdownHandler, array($error));
|
call_user_func_array(self::$customShutdownHandler, [$error]);
|
||||||
} else {
|
} else {
|
||||||
if (null !== $error) {
|
if (null !== $error) {
|
||||||
$job = self::getCurrentJob();
|
$job = self::getCurrentJob();
|
||||||
if(!empty($job)) {
|
if (!empty($job)) {
|
||||||
$lastRunsDetails = self::getLastRunDetails();
|
$lastRunsDetails = self::getLastRunDetails();
|
||||||
|
|
||||||
$lastRunsDetails[$job] = [
|
$lastRunsDetails[$job] = [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'lastRun' => new \DateTime('now'),
|
'lastRun' => new \DateTimeImmutable('now'),
|
||||||
'error' => [
|
'error' => [
|
||||||
'message' => (isset($error['message']) ? $error['message'] : print_r($error, true)),
|
'message' => (isset($error['message']) ? $error['message'] : print_r($error, true)),
|
||||||
'trace' => print_r($error, true),
|
'trace' => print_r($error, true),
|
||||||
@ -607,17 +613,17 @@ class RetailcrmJobManager
|
|||||||
* @param string $msg
|
* @param string $msg
|
||||||
* @param string $trace
|
* @param string $trace
|
||||||
* @param string $currentJob
|
* @param string $currentJob
|
||||||
* @param array $jobs
|
* @param array $jobs
|
||||||
*/
|
*/
|
||||||
private static function handleError($file, $msg, $trace, $currentJob = '', $jobs = array())
|
private static function handleError($file, $msg, $trace, $currentJob = '', $jobs = [])
|
||||||
{
|
{
|
||||||
$data = array();
|
$data = [];
|
||||||
|
|
||||||
if (!empty($currentJob)) {
|
if (!empty($currentJob)) {
|
||||||
$data[] = 'current job: ' . $currentJob;
|
$data[] = 'current job: ' . $currentJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($jobs) > 0) {
|
if (0 < count($jobs)) {
|
||||||
$data[] = 'jobs list: ' . self::serializeJobs($jobs);
|
$data[] = 'jobs list: ' . self::serializeJobs($jobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,12 +641,13 @@ class RetailcrmJobManager
|
|||||||
*
|
*
|
||||||
* @param string $jobName
|
* @param string $jobName
|
||||||
* @param string $phpScript
|
* @param string $phpScript
|
||||||
* @param bool $once
|
* @param bool $once
|
||||||
* @param bool $cliMode
|
* @param bool $cliMode
|
||||||
* @param bool $force
|
* @param bool $force
|
||||||
* @param int $shopId
|
* @param int $shopId
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
* @throws \RetailcrmJobManagerException
|
* @throws \RetailcrmJobManagerException
|
||||||
*/
|
*/
|
||||||
private static function execHere($jobName, $cliMode = false, $force = false, $shopId = null)
|
private static function execHere($jobName, $cliMode = false, $force = false, $shopId = null)
|
||||||
@ -650,8 +657,8 @@ class RetailcrmJobManager
|
|||||||
if (!$cliMode && !$force) {
|
if (!$cliMode && !$force) {
|
||||||
ignore_user_abort(true);
|
ignore_user_abort(true);
|
||||||
|
|
||||||
if (version_compare(phpversion(), '7.0.16', '>=') &&
|
if (version_compare(phpversion(), '7.0.16', '>=')
|
||||||
function_exists('fastcgi_finish_request')
|
&& function_exists('fastcgi_finish_request')
|
||||||
) {
|
) {
|
||||||
if (!headers_sent()) {
|
if (!headers_sent()) {
|
||||||
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
|
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
|
||||||
@ -719,7 +726,7 @@ class RetailcrmJobManager
|
|||||||
$lastRuns = array_values(static::getLastRuns());
|
$lastRuns = array_values(static::getLastRuns());
|
||||||
|
|
||||||
if (empty($lastRuns)) {
|
if (empty($lastRuns)) {
|
||||||
return \DateTime::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00');
|
return \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '1970-01-01 00:00:00');
|
||||||
}
|
}
|
||||||
|
|
||||||
usort(
|
usort(
|
||||||
@ -727,7 +734,7 @@ class RetailcrmJobManager
|
|||||||
function ($first, $second) {
|
function ($first, $second) {
|
||||||
if ($first < $second) {
|
if ($first < $second) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if ($first > $second) {
|
} elseif ($first > $second) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
@ -742,11 +749,12 @@ class RetailcrmJobManager
|
|||||||
* Returns true if lock is present and it's not expired
|
* Returns true if lock is present and it's not expired
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function isLocked()
|
private static function isLocked()
|
||||||
{
|
{
|
||||||
$inProcess = (bool)Configuration::getGlobalValue(self::IN_PROGRESS_NAME);
|
$inProcess = (bool) Configuration::getGlobalValue(self::IN_PROGRESS_NAME);
|
||||||
$lastRan = static::getLastRun();
|
$lastRan = static::getLastRun();
|
||||||
$lastRanSeconds = $lastRan->format('U');
|
$lastRanSeconds = $lastRan->format('U');
|
||||||
|
|
||||||
@ -764,6 +772,7 @@ class RetailcrmJobManager
|
|||||||
* Installs lock
|
* Installs lock
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function lock()
|
private static function lock()
|
||||||
|
@ -41,9 +41,11 @@ if (!defined('_PS_VERSION_')) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RetailcrmLogger
|
* Class RetailcrmLogger
|
||||||
|
*
|
||||||
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
||||||
* @license GPL
|
* @license GPL
|
||||||
* @link https://retailcrm.ru
|
*
|
||||||
|
* @see https://retailcrm.ru
|
||||||
*/
|
*/
|
||||||
class RetailcrmJsonResponse
|
class RetailcrmJsonResponse
|
||||||
{
|
{
|
||||||
@ -54,6 +56,7 @@ class RetailcrmJsonResponse
|
|||||||
$result = json_encode($response);
|
$result = json_encode($response);
|
||||||
|
|
||||||
echo $result;
|
echo $result;
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +66,7 @@ class RetailcrmJsonResponse
|
|||||||
|
|
||||||
return self::jsonResponse([
|
return self::jsonResponse([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'errorMsg' => $msg
|
'errorMsg' => $msg,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,11 +76,12 @@ class RetailcrmJsonResponse
|
|||||||
'success' => true,
|
'success' => true,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!is_null($data)) {
|
if (null !== $data) {
|
||||||
if (is_array($key)) {
|
if (is_array($key)) {
|
||||||
foreach ($key as $i => $value) {
|
foreach ($key as $i => $value) {
|
||||||
if (isset($data[$i]))
|
if (isset($data[$i])) {
|
||||||
$response[$value] = $data[$i];
|
$response[$value] = $data[$i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elseif (is_string($key)) {
|
} elseif (is_string($key)) {
|
||||||
$response[$key] = $data;
|
$response[$key] = $data;
|
||||||
@ -88,4 +92,4 @@ class RetailcrmJsonResponse
|
|||||||
|
|
||||||
return self::jsonResponse($response);
|
return self::jsonResponse($response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,11 @@ if (!defined('_PS_VERSION_')) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RetailcrmLogger
|
* Class RetailcrmLogger
|
||||||
|
*
|
||||||
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
||||||
* @license GPL
|
* @license GPL
|
||||||
* @link https://retailcrm.ru
|
*
|
||||||
|
* @see https://retailcrm.ru
|
||||||
*/
|
*/
|
||||||
class RetailcrmLogger
|
class RetailcrmLogger
|
||||||
{
|
{
|
||||||
@ -117,7 +119,7 @@ class RetailcrmLogger
|
|||||||
*/
|
*/
|
||||||
public static function output($message = '', $end = PHP_EOL)
|
public static function output($message = '', $end = PHP_EOL)
|
||||||
{
|
{
|
||||||
if (php_sapi_name() == 'cli') {
|
if ('cli' == php_sapi_name()) {
|
||||||
echo $message . $end;
|
echo $message . $end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,7 +160,7 @@ class RetailcrmLogger
|
|||||||
/**
|
/**
|
||||||
* Debug log record with multiple entries
|
* Debug log record with multiple entries
|
||||||
*
|
*
|
||||||
* @param string $caller
|
* @param string $caller
|
||||||
* @param array|string $messages
|
* @param array|string $messages
|
||||||
*/
|
*/
|
||||||
public static function writeDebugArray($caller, $messages)
|
public static function writeDebugArray($caller, $messages)
|
||||||
@ -170,6 +172,7 @@ class RetailcrmLogger
|
|||||||
$messages,
|
$messages,
|
||||||
function ($carry, $item) {
|
function ($carry, $item) {
|
||||||
$carry .= ' ' . print_r($item, true);
|
$carry .= ' ' . print_r($item, true);
|
||||||
|
|
||||||
return $carry;
|
return $carry;
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
@ -214,7 +217,7 @@ class RetailcrmLogger
|
|||||||
*/
|
*/
|
||||||
private static function getLogFilePrefix()
|
private static function getLogFilePrefix()
|
||||||
{
|
{
|
||||||
if (php_sapi_name() == 'cli') {
|
if ('cli' == php_sapi_name()) {
|
||||||
if (isset($_SERVER['TERM'])) {
|
if (isset($_SERVER['TERM'])) {
|
||||||
return 'cli';
|
return 'cli';
|
||||||
} else {
|
} else {
|
||||||
@ -250,13 +253,13 @@ class RetailcrmLogger
|
|||||||
$logFiles = self::getLogFiles();
|
$logFiles = self::getLogFiles();
|
||||||
|
|
||||||
foreach ($logFiles as $logFile) {
|
foreach ($logFiles as $logFile) {
|
||||||
$fileNames[] = [
|
$fileNames[] = [
|
||||||
'name' => basename($logFile),
|
'name' => basename($logFile),
|
||||||
'path' => $logFile,
|
'path' => $logFile,
|
||||||
'size' => number_format(filesize($logFile), 0, '.', ' ') . ' bytes',
|
'size' => number_format(filesize($logFile), 0, '.', ' ') . ' bytes',
|
||||||
'modified' => date('Y-m-d H:i:s', filemtime($logFile)),
|
'modified' => date('Y-m-d H:i:s', filemtime($logFile)),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $fileNames;
|
return $fileNames;
|
||||||
}
|
}
|
||||||
@ -276,7 +279,7 @@ class RetailcrmLogger
|
|||||||
|
|
||||||
$handle = opendir($logDir);
|
$handle = opendir($logDir);
|
||||||
while (($file = readdir($handle)) !== false) {
|
while (($file = readdir($handle)) !== false) {
|
||||||
if (self::checkFileName($file) !== false) {
|
if (false !== self::checkFileName($file)) {
|
||||||
yield "$logDir/$file";
|
yield "$logDir/$file";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,6 +291,7 @@ class RetailcrmLogger
|
|||||||
* Checks if given logs filename relates to the module
|
* Checks if given logs filename relates to the module
|
||||||
*
|
*
|
||||||
* @param string $file
|
* @param string $file
|
||||||
|
*
|
||||||
* @return false|string
|
* @return false|string
|
||||||
*/
|
*/
|
||||||
public static function checkFileName($file)
|
public static function checkFileName($file)
|
||||||
@ -322,4 +326,4 @@ class RetailcrmLogger
|
|||||||
|
|
||||||
return $reduced;
|
return $reduced;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,27 +39,27 @@
|
|||||||
class RetailcrmOrderBuilder
|
class RetailcrmOrderBuilder
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \RetailcrmApiClientV5 $api
|
* @var \RetailcrmApiClientV5
|
||||||
*/
|
*/
|
||||||
protected $api;
|
protected $api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int $default_lang
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $default_lang;
|
protected $default_lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Order|OrderCore|null $cmsOrder
|
* @var Order|OrderCore|null
|
||||||
*/
|
*/
|
||||||
protected $cmsOrder;
|
protected $cmsOrder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Cart|CartCore|null $cmsCart
|
* @var Cart|CartCore|null
|
||||||
*/
|
*/
|
||||||
protected $cmsCart;
|
protected $cmsCart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Customer|CustomerCore|null $cmsCustomer
|
* @var Customer|CustomerCore|null
|
||||||
*/
|
*/
|
||||||
protected $cmsCustomer;
|
protected $cmsCustomer;
|
||||||
|
|
||||||
@ -74,17 +74,17 @@ class RetailcrmOrderBuilder
|
|||||||
protected $deliveryAddress;
|
protected $deliveryAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array|null $createdCustomer
|
* @var array|null
|
||||||
*/
|
*/
|
||||||
protected $createdCustomer;
|
protected $createdCustomer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array|null $corporateCompanyExtractCache
|
* @var array|null
|
||||||
*/
|
*/
|
||||||
protected $corporateCompanyExtractCache;
|
protected $corporateCompanyExtractCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string $apiSite
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $apiSite;
|
protected $apiSite;
|
||||||
|
|
||||||
@ -93,7 +93,8 @@ class RetailcrmOrderBuilder
|
|||||||
*/
|
*/
|
||||||
public function defaultLangFromConfiguration()
|
public function defaultLangFromConfiguration()
|
||||||
{
|
{
|
||||||
$this->default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
$this->default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +106,7 @@ class RetailcrmOrderBuilder
|
|||||||
public function setDefaultLang($default_lang)
|
public function setDefaultLang($default_lang)
|
||||||
{
|
{
|
||||||
$this->default_lang = $default_lang;
|
$this->default_lang = $default_lang;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +118,7 @@ class RetailcrmOrderBuilder
|
|||||||
public function setApi($api)
|
public function setApi($api)
|
||||||
{
|
{
|
||||||
$this->api = $api;
|
$this->api = $api;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,15 +132,15 @@ class RetailcrmOrderBuilder
|
|||||||
$this->cmsOrder = $cmsOrder;
|
$this->cmsOrder = $cmsOrder;
|
||||||
|
|
||||||
if ($cmsOrder instanceof Order) {
|
if ($cmsOrder instanceof Order) {
|
||||||
if (is_null($this->cmsCustomer)) {
|
if (null === $this->cmsCustomer) {
|
||||||
$this->cmsCustomer = $cmsOrder->getCustomer();
|
$this->cmsCustomer = $cmsOrder->getCustomer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoiceAddress)) {
|
if (null === $this->invoiceAddress) {
|
||||||
$this->invoiceAddress = new Address($cmsOrder->id_address_invoice);
|
$this->invoiceAddress = new Address($cmsOrder->id_address_invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->deliveryAddress)) {
|
if (null === $this->deliveryAddress) {
|
||||||
$this->deliveryAddress = new Address($cmsOrder->id_address_delivery);
|
$this->deliveryAddress = new Address($cmsOrder->id_address_delivery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,15 +158,15 @@ class RetailcrmOrderBuilder
|
|||||||
$this->cmsCart = $cmsCart;
|
$this->cmsCart = $cmsCart;
|
||||||
|
|
||||||
if ($cmsCart instanceof Cart) {
|
if ($cmsCart instanceof Cart) {
|
||||||
if (is_null($this->cmsCustomer) && !empty($cmsCart->id_customer)) {
|
if (null === $this->cmsCustomer && !empty($cmsCart->id_customer)) {
|
||||||
$this->cmsCustomer = new Customer($cmsCart->id_customer);
|
$this->cmsCustomer = new Customer($cmsCart->id_customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->invoiceAddress) && !empty($cmsCart->id_address_invoice)) {
|
if (null === $this->invoiceAddress && !empty($cmsCart->id_address_invoice)) {
|
||||||
$this->invoiceAddress = new Address($cmsCart->id_address_invoice);
|
$this->invoiceAddress = new Address($cmsCart->id_address_invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->deliveryAddress) && !empty($cmsCart->id_address_delivery)) {
|
if (null === $this->deliveryAddress && !empty($cmsCart->id_address_delivery)) {
|
||||||
$this->deliveryAddress = new Address($cmsCart->id_address_delivery);
|
$this->deliveryAddress = new Address($cmsCart->id_address_delivery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,6 +182,7 @@ class RetailcrmOrderBuilder
|
|||||||
public function setCmsCustomer($cmsCustomer)
|
public function setCmsCustomer($cmsCustomer)
|
||||||
{
|
{
|
||||||
$this->cmsCustomer = $cmsCustomer;
|
$this->cmsCustomer = $cmsCustomer;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +263,7 @@ class RetailcrmOrderBuilder
|
|||||||
$createResponse = $this->api->customersCreate($crmCustomer);
|
$createResponse = $this->api->customersCreate($crmCustomer);
|
||||||
|
|
||||||
if (!$createResponse || !$createResponse->isSuccessful()) {
|
if (!$createResponse || !$createResponse->isSuccessful()) {
|
||||||
$this->createdCustomer = array();
|
$this->createdCustomer = [];
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -314,7 +318,8 @@ class RetailcrmOrderBuilder
|
|||||||
return $addressBuilder
|
return $addressBuilder
|
||||||
->setAddress($this->invoiceAddress)
|
->setAddress($this->invoiceAddress)
|
||||||
->build()
|
->build()
|
||||||
->getDataArray();
|
->getDataArray()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -327,7 +332,7 @@ class RetailcrmOrderBuilder
|
|||||||
private function buildCorporateAddress($isMain = true)
|
private function buildCorporateAddress($isMain = true)
|
||||||
{
|
{
|
||||||
if (empty($this->invoiceAddress) || empty($this->invoiceAddress->id)) {
|
if (empty($this->invoiceAddress) || empty($this->invoiceAddress->id)) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$addressBuilder = new RetailcrmAddressBuilder();
|
$addressBuilder = new RetailcrmAddressBuilder();
|
||||||
@ -338,7 +343,8 @@ class RetailcrmOrderBuilder
|
|||||||
->setIsMain($isMain)
|
->setIsMain($isMain)
|
||||||
->setWithExternalId(true)
|
->setWithExternalId(true)
|
||||||
->build()
|
->build()
|
||||||
->getDataArray();
|
->getDataArray()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -365,15 +371,15 @@ class RetailcrmOrderBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$company = array(
|
$company = [
|
||||||
'isMain' => true,
|
'isMain' => true,
|
||||||
'name' => $companyName
|
'name' => $companyName,
|
||||||
);
|
];
|
||||||
|
|
||||||
if (!empty($addressId)) {
|
if (!empty($addressId)) {
|
||||||
$company['address'] = array(
|
$company['address'] = [
|
||||||
'id' => $addressId
|
'id' => $addressId,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($vat)) {
|
if (!empty($vat)) {
|
||||||
@ -420,7 +426,7 @@ class RetailcrmOrderBuilder
|
|||||||
if ($corporateWasFound) {
|
if ($corporateWasFound) {
|
||||||
$contactList = $this->api->customersCorporateContacts(
|
$contactList = $this->api->customersCorporateContacts(
|
||||||
$crmCorporate['id'],
|
$crmCorporate['id'],
|
||||||
array('contactIds' => array($customer['id'])),
|
['contactIds' => [$customer['id']]],
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
'id',
|
'id',
|
||||||
@ -431,14 +437,14 @@ class RetailcrmOrderBuilder
|
|||||||
return $crmCorporate;
|
return $crmCorporate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($contactList['contacts']) == 0) {
|
if (0 == count($contactList['contacts'])) {
|
||||||
$contactData = array(
|
$contactData = [
|
||||||
'isMain' => false,
|
'isMain' => false,
|
||||||
'customer' => array(
|
'customer' => [
|
||||||
'id' => $customer['id'],
|
'id' => $customer['id'],
|
||||||
'site' => $this->getApiSite()
|
'site' => $this->getApiSite(),
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
$crmCorporateCompany = $this->extractCorporateCompanyCached(
|
$crmCorporateCompany = $this->extractCorporateCompanyCached(
|
||||||
$crmCorporate['id'],
|
$crmCorporate['id'],
|
||||||
@ -446,9 +452,9 @@ class RetailcrmOrderBuilder
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($crmCorporateCompany) && isset($crmCorporateCompany['id'])) {
|
if (!empty($crmCorporateCompany) && isset($crmCorporateCompany['id'])) {
|
||||||
$contactData['companies'] = array(array(
|
$contactData['companies'] = [[
|
||||||
'company' => array('id' => $crmCorporateCompany['id'])
|
'company' => ['id' => $crmCorporateCompany['id']],
|
||||||
));
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->api->customersCorporateContactsCreate(
|
$this->api->customersCorporateContactsCreate(
|
||||||
@ -528,17 +534,18 @@ class RetailcrmOrderBuilder
|
|||||||
$addresses = $request
|
$addresses = $request
|
||||||
->setApi($this->api)
|
->setApi($this->api)
|
||||||
->setMethod('customersCorporateAddresses')
|
->setMethod('customersCorporateAddresses')
|
||||||
->setParams(array(
|
->setParams([
|
||||||
$corporateId,
|
$corporateId,
|
||||||
array(),
|
[],
|
||||||
'{{page}}',
|
'{{page}}',
|
||||||
'{{limit}}',
|
'{{limit}}',
|
||||||
'id',
|
'id',
|
||||||
$this->getApiSite()
|
$this->getApiSite(),
|
||||||
))
|
])
|
||||||
->setDataKey('addresses')
|
->setDataKey('addresses')
|
||||||
->execute()
|
->execute()
|
||||||
->getData();
|
->getData()
|
||||||
|
;
|
||||||
|
|
||||||
foreach ($addresses as $addressInCrm) {
|
foreach ($addresses as $addressInCrm) {
|
||||||
if (!empty($addressInCrm['externalId']) && $addressInCrm['externalId'] == $this->invoiceAddress->id) {
|
if (!empty($addressInCrm['externalId']) && $addressInCrm['externalId'] == $this->invoiceAddress->id) {
|
||||||
@ -574,7 +581,7 @@ class RetailcrmOrderBuilder
|
|||||||
|
|
||||||
if (empty($this->cmsCustomer->id) || $this->cmsCustomer->is_guest) {
|
if (empty($this->cmsCustomer->id) || $this->cmsCustomer->is_guest) {
|
||||||
if (!empty($this->cmsCustomer->email)) {
|
if (!empty($this->cmsCustomer->email)) {
|
||||||
$customers = $this->api->customersList(array('email' => $this->cmsCustomer->email));
|
$customers = $this->api->customersList(['email' => $this->cmsCustomer->email]);
|
||||||
|
|
||||||
if ($customers
|
if ($customers
|
||||||
&& $customers->isSuccessful()
|
&& $customers->isSuccessful()
|
||||||
@ -594,7 +601,7 @@ class RetailcrmOrderBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -607,22 +614,22 @@ class RetailcrmOrderBuilder
|
|||||||
*/
|
*/
|
||||||
private function findCorporateCustomerByContactAndCompany($contactId, $companyName)
|
private function findCorporateCustomerByContactAndCompany($contactId, $companyName)
|
||||||
{
|
{
|
||||||
$crmCorporate = $this->api->customersCorporateList(array(
|
$crmCorporate = $this->api->customersCorporateList([
|
||||||
'contactIds' => array($contactId),
|
'contactIds' => [$contactId],
|
||||||
'companyName' => $companyName
|
'companyName' => $companyName,
|
||||||
));
|
]);
|
||||||
|
|
||||||
if ($crmCorporate instanceof RetailcrmApiResponse
|
if ($crmCorporate instanceof RetailcrmApiResponse
|
||||||
&& $crmCorporate->isSuccessful()
|
&& $crmCorporate->isSuccessful()
|
||||||
&& $crmCorporate->offsetExists('customersCorporate')
|
&& $crmCorporate->offsetExists('customersCorporate')
|
||||||
&& count($crmCorporate['customersCorporate']) > 0
|
&& 0 < count($crmCorporate['customersCorporate'])
|
||||||
) {
|
) {
|
||||||
$crmCorporate = $crmCorporate['customersCorporate'];
|
$crmCorporate = $crmCorporate['customersCorporate'];
|
||||||
|
|
||||||
return reset($crmCorporate);
|
return reset($crmCorporate);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -634,29 +641,29 @@ class RetailcrmOrderBuilder
|
|||||||
*/
|
*/
|
||||||
private function findCorporateCustomerByCompany($companyName)
|
private function findCorporateCustomerByCompany($companyName)
|
||||||
{
|
{
|
||||||
$crmCorporate = $this->api->customersCorporateList(array(
|
$crmCorporate = $this->api->customersCorporateList([
|
||||||
'companyName' => $companyName
|
'companyName' => $companyName,
|
||||||
));
|
]);
|
||||||
|
|
||||||
if ($crmCorporate instanceof RetailcrmApiResponse
|
if ($crmCorporate instanceof RetailcrmApiResponse
|
||||||
&& $crmCorporate->isSuccessful()
|
&& $crmCorporate->isSuccessful()
|
||||||
&& $crmCorporate->offsetExists('customersCorporate')
|
&& $crmCorporate->offsetExists('customersCorporate')
|
||||||
&& count($crmCorporate['customersCorporate']) > 0
|
&& 0 < count($crmCorporate['customersCorporate'])
|
||||||
) {
|
) {
|
||||||
$crmCorporate = $crmCorporate['customersCorporate'];
|
$crmCorporate = $crmCorporate['customersCorporate'];
|
||||||
|
|
||||||
return reset($crmCorporate);
|
return reset($crmCorporate);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get corporate companies, extract company data by provided identifiers
|
* Get corporate companies, extract company data by provided identifiers
|
||||||
*
|
*
|
||||||
* @param int|string $corporateCrmId
|
* @param int|string $corporateCrmId
|
||||||
* @param string $companyName
|
* @param string $companyName
|
||||||
* @param string $by
|
* @param string $by
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -664,7 +671,7 @@ class RetailcrmOrderBuilder
|
|||||||
{
|
{
|
||||||
$companiesResponse = $this->api->customersCorporateCompanies(
|
$companiesResponse = $this->api->customersCorporateCompanies(
|
||||||
$corporateCrmId,
|
$corporateCrmId,
|
||||||
array(),
|
[],
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
$by
|
$by
|
||||||
@ -673,7 +680,7 @@ class RetailcrmOrderBuilder
|
|||||||
if ($companiesResponse instanceof RetailcrmApiResponse
|
if ($companiesResponse instanceof RetailcrmApiResponse
|
||||||
&& $companiesResponse->isSuccessful()
|
&& $companiesResponse->isSuccessful()
|
||||||
&& $companiesResponse->offsetExists('companies')
|
&& $companiesResponse->offsetExists('companies')
|
||||||
&& count($companiesResponse['companies']) > 0
|
&& 0 < count($companiesResponse['companies'])
|
||||||
) {
|
) {
|
||||||
$company = array_reduce(
|
$company = array_reduce(
|
||||||
$companiesResponse['companies'],
|
$companiesResponse['companies'],
|
||||||
@ -687,19 +694,19 @@ class RetailcrmOrderBuilder
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (is_array($company)) {
|
if (is_array($company)) {
|
||||||
return $company;
|
return $company;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* extractCorporateCompany with cache
|
* extractCorporateCompany with cache
|
||||||
*
|
*
|
||||||
* @param int|string $corporateCrmId
|
* @param int|string $corporateCrmId
|
||||||
* @param string $companyName
|
* @param string $companyName
|
||||||
* @param string $by
|
* @param string $by
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -708,7 +715,7 @@ class RetailcrmOrderBuilder
|
|||||||
$cachedItemId = sprintf('%s:%s', (string) $corporateCrmId, $companyName);
|
$cachedItemId = sprintf('%s:%s', (string) $corporateCrmId, $companyName);
|
||||||
|
|
||||||
if (!is_array($this->corporateCompanyExtractCache)) {
|
if (!is_array($this->corporateCompanyExtractCache)) {
|
||||||
$this->corporateCompanyExtractCache = array();
|
$this->corporateCompanyExtractCache = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->corporateCompanyExtractCache[$cachedItemId])) {
|
if (!isset($this->corporateCompanyExtractCache[$cachedItemId])) {
|
||||||
@ -729,8 +736,8 @@ class RetailcrmOrderBuilder
|
|||||||
*/
|
*/
|
||||||
private function validateCmsCustomer()
|
private function validateCmsCustomer()
|
||||||
{
|
{
|
||||||
if (is_null($this->cmsCustomer)) {
|
if (null === $this->cmsCustomer) {
|
||||||
throw new \InvalidArgumentException("RetailcrmOrderBuilder::cmsCustomer must be set");
|
throw new \InvalidArgumentException('RetailcrmOrderBuilder::cmsCustomer must be set');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -744,7 +751,7 @@ class RetailcrmOrderBuilder
|
|||||||
$this->validateCmsCustomer();
|
$this->validateCmsCustomer();
|
||||||
|
|
||||||
if (empty($this->cmsCustomer->id)) {
|
if (empty($this->cmsCustomer->id)) {
|
||||||
throw new \InvalidArgumentException("RetailcrmOrderBuilder::cmsCustomer must be stored in DB");
|
throw new \InvalidArgumentException('RetailcrmOrderBuilder::cmsCustomer must be stored in DB');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,11 +762,11 @@ class RetailcrmOrderBuilder
|
|||||||
$contactPersonExternalId = '';
|
$contactPersonExternalId = '';
|
||||||
|
|
||||||
if (empty($customer)) {
|
if (empty($customer)) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($this->cmsCustomer->id)) {
|
if (empty($this->cmsCustomer->id)) {
|
||||||
$contacts = $this->api->customersList(array('email' => $this->cmsCustomer->email));
|
$contacts = $this->api->customersList(['email' => $this->cmsCustomer->email]);
|
||||||
|
|
||||||
if ($contacts
|
if ($contacts
|
||||||
&& $contacts->isSuccessful()
|
&& $contacts->isSuccessful()
|
||||||
@ -776,7 +783,7 @@ class RetailcrmOrderBuilder
|
|||||||
} else {
|
} else {
|
||||||
$contacts = $this->api->customersCorporateContacts(
|
$contacts = $this->api->customersCorporateContacts(
|
||||||
$customer['id'],
|
$customer['id'],
|
||||||
array('contactExternalIds' => array($this->cmsCustomer->id)),
|
['contactExternalIds' => [$this->cmsCustomer->id]],
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
'id',
|
'id',
|
||||||
@ -786,7 +793,7 @@ class RetailcrmOrderBuilder
|
|||||||
if ($contacts
|
if ($contacts
|
||||||
&& $contacts->isSuccessful()
|
&& $contacts->isSuccessful()
|
||||||
&& $contacts->offsetExists('contacts')
|
&& $contacts->offsetExists('contacts')
|
||||||
&& count($contacts['contacts']) == 1
|
&& 1 == count($contacts['contacts'])
|
||||||
) {
|
) {
|
||||||
$contactPersonExternalId = $this->cmsCustomer->id;
|
$contactPersonExternalId = $this->cmsCustomer->id;
|
||||||
}
|
}
|
||||||
@ -809,19 +816,20 @@ class RetailcrmOrderBuilder
|
|||||||
/**
|
/**
|
||||||
* Build array with order data for retailCRM from PrestaShop order data
|
* Build array with order data for retailCRM from PrestaShop order data
|
||||||
*
|
*
|
||||||
* @param Order|\OrderCore $order PrestaShop Order
|
* @param Order|\OrderCore $order PrestaShop Order
|
||||||
* @param Customer|\CustomerCore|null $customer PrestaShop Customer
|
* @param Customer|\CustomerCore|null $customer PrestaShop Customer
|
||||||
* @param Cart|\CartCore|null $orderCart Cart for provided order. Optional
|
* @param Cart|\CartCore|null $orderCart Cart for provided order. Optional
|
||||||
* @param bool $isStatusExport Use status for export
|
* @param bool $isStatusExport Use status for export
|
||||||
* @param bool $preferCustomerAddress Use customer address even if delivery address is
|
* @param bool $preferCustomerAddress Use customer address even if delivery address is
|
||||||
* provided
|
* provided
|
||||||
* @param bool $dataFromCart Prefer data from cart
|
* @param bool $dataFromCart Prefer data from cart
|
||||||
* @param string $contactPersonId Contact person id to append
|
* @param string $contactPersonId Contact person id to append
|
||||||
* @param string $contactPersonExternalId Contact person externalId to append.
|
* @param string $contactPersonExternalId contact person externalId to append
|
||||||
* @param string $customerId Customer id
|
* @param string $customerId Customer id
|
||||||
* @param string $site Site code (for customer only)
|
* @param string $site Site code (for customer only)
|
||||||
|
*
|
||||||
|
* @return array retailCRM order data
|
||||||
*
|
*
|
||||||
* @return array retailCRM order data
|
|
||||||
* @todo Refactor into OrderBuilder (current order builder should be divided into several independent builders).
|
* @todo Refactor into OrderBuilder (current order builder should be divided into several independent builders).
|
||||||
*/
|
*/
|
||||||
public static function buildCrmOrder(
|
public static function buildCrmOrder(
|
||||||
@ -840,16 +848,16 @@ class RetailcrmOrderBuilder
|
|||||||
$delivery = json_decode(Configuration::get(RetailCRM::DELIVERY), true);
|
$delivery = json_decode(Configuration::get(RetailCRM::DELIVERY), true);
|
||||||
$payment = json_decode(Configuration::get(RetailCRM::PAYMENT), true);
|
$payment = json_decode(Configuration::get(RetailCRM::PAYMENT), true);
|
||||||
$status = json_decode(Configuration::get(RetailCRM::STATUS), true);
|
$status = json_decode(Configuration::get(RetailCRM::STATUS), true);
|
||||||
$sendOrderNumber = (bool)(Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_SENDING));
|
$sendOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_SENDING));
|
||||||
$orderNumber = $sendOrderNumber ? $order->reference : null;
|
$orderNumber = $sendOrderNumber ? $order->reference : null;
|
||||||
|
|
||||||
if (Module::getInstanceByName('advancedcheckout') === false) {
|
if (false === Module::getInstanceByName('advancedcheckout')) {
|
||||||
$paymentType = $order->module;
|
$paymentType = $order->module;
|
||||||
} else {
|
} else {
|
||||||
$paymentType = $order->payment;
|
$paymentType = $order->payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($order->current_state == 0) {
|
if (0 == $order->current_state) {
|
||||||
$order_status = $statusExport;
|
$order_status = $statusExport;
|
||||||
|
|
||||||
if (!$isStatusExport) {
|
if (!$isStatusExport) {
|
||||||
@ -865,15 +873,15 @@ class RetailcrmOrderBuilder
|
|||||||
|
|
||||||
$cart = $orderCart;
|
$cart = $orderCart;
|
||||||
|
|
||||||
if (is_null($cart)) {
|
if (null === $cart) {
|
||||||
$cart = new Cart($order->getCartIdStatic($order->id));
|
$cart = new Cart($order->getCartIdStatic($order->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($customer)) {
|
if (null === $customer) {
|
||||||
$customer = new Customer($order->id_customer);
|
$customer = new Customer($order->id_customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
$crmOrder = array_filter(array(
|
$crmOrder = array_filter([
|
||||||
'externalId' => $order->id,
|
'externalId' => $order->id,
|
||||||
'number' => $orderNumber,
|
'number' => $orderNumber,
|
||||||
'createdAt' => RetailcrmTools::verifyDate($order->date_add, 'Y-m-d H:i:s')
|
'createdAt' => RetailcrmTools::verifyDate($order->date_add, 'Y-m-d H:i:s')
|
||||||
@ -882,13 +890,13 @@ class RetailcrmOrderBuilder
|
|||||||
'firstName' => $customer->firstname,
|
'firstName' => $customer->firstname,
|
||||||
'lastName' => $customer->lastname,
|
'lastName' => $customer->lastname,
|
||||||
'email' => $customer->email,
|
'email' => $customer->email,
|
||||||
));
|
]);
|
||||||
|
|
||||||
$addressCollection = $cart->getAddressCollection();
|
$addressCollection = $cart->getAddressCollection();
|
||||||
$addressDelivery = new Address($order->id_address_delivery);
|
$addressDelivery = new Address($order->id_address_delivery);
|
||||||
$addressInvoice = new Address($order->id_address_invoice);
|
$addressInvoice = new Address($order->id_address_invoice);
|
||||||
|
|
||||||
if (is_null($addressDelivery->id) || $preferCustomerAddress === true) {
|
if (null === $addressDelivery->id || true === $preferCustomerAddress) {
|
||||||
$addressDelivery = array_filter(
|
$addressDelivery = array_filter(
|
||||||
$addressCollection,
|
$addressCollection,
|
||||||
function ($v) use ($customer) {
|
function ($v) use ($customer) {
|
||||||
@ -896,7 +904,7 @@ class RetailcrmOrderBuilder
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_array($addressDelivery) && count($addressDelivery) == 1) {
|
if (is_array($addressDelivery) && 1 == count($addressDelivery)) {
|
||||||
$addressDelivery = reset($addressDelivery);
|
$addressDelivery = reset($addressDelivery);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -905,7 +913,8 @@ class RetailcrmOrderBuilder
|
|||||||
$addressBuilder
|
$addressBuilder
|
||||||
->setMode(RetailcrmAddressBuilder::MODE_ORDER_DELIVERY)
|
->setMode(RetailcrmAddressBuilder::MODE_ORDER_DELIVERY)
|
||||||
->setAddress($addressDelivery)
|
->setAddress($addressDelivery)
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
$crmOrder = array_merge($crmOrder, $addressBuilder->getDataArray());
|
$crmOrder = array_merge($crmOrder, $addressBuilder->getDataArray());
|
||||||
|
|
||||||
if ($addressInvoice instanceof Address && !empty($addressInvoice->company)) {
|
if ($addressInvoice instanceof Address && !empty($addressInvoice->company)) {
|
||||||
@ -917,18 +926,18 @@ class RetailcrmOrderBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($payment[$paymentType]) && !empty($payment[$paymentType])) {
|
if (isset($payment[$paymentType]) && !empty($payment[$paymentType])) {
|
||||||
$order_payment = array(
|
$order_payment = [
|
||||||
'externalId' => $order->id . '#' . $order->reference,
|
'externalId' => $order->id . '#' . $order->reference,
|
||||||
'type' => $payment[$paymentType]
|
'type' => $payment[$paymentType],
|
||||||
);
|
];
|
||||||
|
|
||||||
if (round($order->total_paid_real, 2) > 0) {
|
if (0 < round($order->total_paid_real, 2)) {
|
||||||
$order_payment['amount'] = round($order->total_paid_real, 2);
|
$order_payment['amount'] = round($order->total_paid_real, 2);
|
||||||
$order_payment['status'] = 'paid';
|
$order_payment['status'] = 'paid';
|
||||||
}
|
}
|
||||||
$crmOrder['payments'][] = $order_payment;
|
$crmOrder['payments'][] = $order_payment;
|
||||||
} else {
|
} else {
|
||||||
$crmOrder['payments'] = array();
|
$crmOrder['payments'] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$idCarrier = $dataFromCart ? $cart->id_carrier : $order->id_carrier;
|
$idCarrier = $dataFromCart ? $cart->id_carrier : $order->id_carrier;
|
||||||
@ -940,7 +949,7 @@ class RetailcrmOrderBuilder
|
|||||||
} else {
|
} else {
|
||||||
$totalShipping = $dataFromCart ? $cart->getCarrierCost($idCarrier) : $order->total_shipping;
|
$totalShipping = $dataFromCart ? $cart->getCarrierCost($idCarrier) : $order->total_shipping;
|
||||||
|
|
||||||
if (!empty($totalShipping) && $totalShipping != 0) {
|
if (!empty($totalShipping) && 0 != $totalShipping) {
|
||||||
$totalShippingWithoutTax = $dataFromCart
|
$totalShippingWithoutTax = $dataFromCart
|
||||||
? $totalShipping - $cart->getCarrierCost($idCarrier, false)
|
? $totalShipping - $cart->getCarrierCost($idCarrier, false)
|
||||||
: $order->total_shipping_tax_excl;
|
: $order->total_shipping_tax_excl;
|
||||||
@ -954,20 +963,20 @@ class RetailcrmOrderBuilder
|
|||||||
$crmOrder['delivery']['code'] = $delivery[$idCarrier];
|
$crmOrder['delivery']['code'] = $delivery[$idCarrier];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($totalShipping) && $order->total_discounts > $order->total_products_wt ) {
|
if (isset($totalShipping) && $order->total_discounts > $order->total_products_wt) {
|
||||||
$totalShipping -= $order->total_discounts - $order->total_products_wt;
|
$totalShipping -= $order->total_discounts - $order->total_products_wt;
|
||||||
$crmOrder['discountManualAmount'] = round($order->total_products_wt, 2);
|
$crmOrder['discountManualAmount'] = round($order->total_products_wt, 2);
|
||||||
} else {
|
} else {
|
||||||
$crmOrder['discountManualAmount'] = round($order->total_discounts, 2);
|
$crmOrder['discountManualAmount'] = round($order->total_discounts, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($totalShipping) && round($totalShipping, 2) > 0) {
|
if (isset($totalShipping) && 0 < round($totalShipping, 2)) {
|
||||||
$crmOrder['delivery']['cost'] = round($totalShipping, 2);
|
$crmOrder['delivery']['cost'] = round($totalShipping, 2);
|
||||||
} else {
|
} else {
|
||||||
$crmOrder['delivery']['cost'] = 0.00;
|
$crmOrder['delivery']['cost'] = 0.00;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($totalShippingWithoutTax) && round($totalShippingWithoutTax, 2) > 0) {
|
if (isset($totalShippingWithoutTax) && 0 < round($totalShippingWithoutTax, 2)) {
|
||||||
$crmOrder['delivery']['netCost'] = round($totalShippingWithoutTax, 2);
|
$crmOrder['delivery']['netCost'] = round($totalShippingWithoutTax, 2);
|
||||||
} else {
|
} else {
|
||||||
$crmOrder['delivery']['netCost'] = 0.00;
|
$crmOrder['delivery']['netCost'] = 0.00;
|
||||||
@ -975,14 +984,14 @@ class RetailcrmOrderBuilder
|
|||||||
|
|
||||||
$comment = $order->getFirstMessage();
|
$comment = $order->getFirstMessage();
|
||||||
|
|
||||||
if ($comment !== false) {
|
if (false !== $comment) {
|
||||||
$crmOrder['customerComment'] = $comment;
|
$crmOrder['customerComment'] = $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dataFromCart) {
|
if ($dataFromCart) {
|
||||||
$productStore = $cart;
|
$productStore = $cart;
|
||||||
$converter = function ($product) {
|
$converter = function ($product) {
|
||||||
$map = array(
|
$map = [
|
||||||
'product_attribute_id' => 'id_product_attribute',
|
'product_attribute_id' => 'id_product_attribute',
|
||||||
'product_quantity' => 'cart_quantity',
|
'product_quantity' => 'cart_quantity',
|
||||||
'product_id' => 'id_product',
|
'product_id' => 'id_product',
|
||||||
@ -990,8 +999,8 @@ class RetailcrmOrderBuilder
|
|||||||
'product_name' => 'name',
|
'product_name' => 'name',
|
||||||
'product_price' => 'price',
|
'product_price' => 'price',
|
||||||
'purchase_supplier_price' => 'price',
|
'purchase_supplier_price' => 'price',
|
||||||
'product_price_wt' => 'price_wt'
|
'product_price_wt' => 'price_wt',
|
||||||
);
|
];
|
||||||
|
|
||||||
foreach ($map as $target => $value) {
|
foreach ($map as $target => $value) {
|
||||||
if (isset($product[$value])) {
|
if (isset($product[$value])) {
|
||||||
@ -1011,19 +1020,19 @@ class RetailcrmOrderBuilder
|
|||||||
foreach ($productStore->getProducts() as $productData) {
|
foreach ($productStore->getProducts() as $productData) {
|
||||||
$product = $converter($productData);
|
$product = $converter($productData);
|
||||||
|
|
||||||
if (isset($product['product_attribute_id']) && $product['product_attribute_id'] > 0) {
|
if (isset($product['product_attribute_id']) && 0 < $product['product_attribute_id']) {
|
||||||
$productId = $product['product_id'] . '#' . $product['product_attribute_id'];
|
$productId = $product['product_id'] . '#' . $product['product_attribute_id'];
|
||||||
} else {
|
} else {
|
||||||
$productId = $product['product_id'];
|
$productId = $product['product_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($product['attributes']) && $product['attributes']) {
|
if (isset($product['attributes']) && $product['attributes']) {
|
||||||
$arProp = array();
|
$arProp = [];
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$arAttr = explode(",", $product['attributes']);
|
$arAttr = explode(',', $product['attributes']);
|
||||||
|
|
||||||
foreach ($arAttr as $valAttr) {
|
foreach ($arAttr as $valAttr) {
|
||||||
$arItem = explode(":", $valAttr);
|
$arItem = explode(':', $valAttr);
|
||||||
|
|
||||||
if ($arItem[0] && $arItem[1]) {
|
if ($arItem[0] && $arItem[1]) {
|
||||||
// Product property code should start with a letter, digit or underscore
|
// Product property code should start with a letter, digit or underscore
|
||||||
@ -1038,26 +1047,26 @@ class RetailcrmOrderBuilder
|
|||||||
$arProp[$count]['value'] = trim($arItem[1]);
|
$arProp[$count]['value'] = trim($arItem[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$count++;
|
++$count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = array(
|
$item = [
|
||||||
"externalIds" => array(
|
'externalIds' => [
|
||||||
array(
|
[
|
||||||
'code' => 'prestashop',
|
'code' => 'prestashop',
|
||||||
'value' => $productId . "_" . $product['id_order_detail'],
|
'value' => $productId . '_' . $product['id_order_detail'],
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
'offer' => array('externalId' => $productId),
|
'offer' => ['externalId' => $productId],
|
||||||
'productName' => $product['product_name'],
|
'productName' => $product['product_name'],
|
||||||
'quantity' => $product['product_quantity'],
|
'quantity' => $product['product_quantity'],
|
||||||
'initialPrice' => round($product['product_price'], 2),
|
'initialPrice' => round($product['product_price'], 2),
|
||||||
/*'initialPrice' => !empty($item['rate'])
|
/*'initialPrice' => !empty($item['rate'])
|
||||||
? $item['price'] + ($item['price'] * $item['rate'] / 100)
|
? $item['price'] + ($item['price'] * $item['rate'] / 100)
|
||||||
: $item['price'],*/
|
: $item['price'],*/
|
||||||
'purchasePrice' => round($product['purchase_supplier_price'], 2)
|
'purchasePrice' => round($product['purchase_supplier_price'], 2),
|
||||||
);
|
];
|
||||||
|
|
||||||
if (true == Configuration::get('PS_TAX') && isset($product['product_price_wt'])) {
|
if (true == Configuration::get('PS_TAX') && isset($product['product_price_wt'])) {
|
||||||
$item['initialPrice'] = round($product['product_price_wt'], 2);
|
$item['initialPrice'] = round($product['product_price_wt'], 2);
|
||||||
@ -1070,7 +1079,7 @@ class RetailcrmOrderBuilder
|
|||||||
$crmOrder['items'][] = $item;
|
$crmOrder['items'][] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($order->gift && $order->total_wrapping > 0) {
|
if ($order->gift && 0 < $order->total_wrapping) {
|
||||||
self::setOrderGiftItem($order, $crmOrder);
|
self::setOrderGiftItem($order, $crmOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1101,29 +1110,30 @@ class RetailcrmOrderBuilder
|
|||||||
return RetailcrmTools::filter(
|
return RetailcrmTools::filter(
|
||||||
'RetailcrmFilterProcessOrder',
|
'RetailcrmFilterProcessOrder',
|
||||||
RetailcrmTools::clearArray($crmOrder),
|
RetailcrmTools::clearArray($crmOrder),
|
||||||
array(
|
[
|
||||||
'order' => $order,
|
'order' => $order,
|
||||||
'customer' => $customer,
|
'customer' => $customer,
|
||||||
'cart' => $cart
|
'cart' => $cart,
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build array with order data for retailCRM from PrestaShop cart data
|
* Build array with order data for retailCRM from PrestaShop cart data
|
||||||
*
|
*
|
||||||
* @param \RetailcrmProxy|\RetailcrmApiClientV5 $api
|
* @param \RetailcrmProxy|\RetailcrmApiClientV5 $api
|
||||||
* @param Cart $cart Cart with data
|
* @param Cart $cart Cart with data
|
||||||
* @param string $externalId External ID for order
|
* @param string $externalId External ID for order
|
||||||
* @param string $paymentType Payment type (buildCrmOrder requires it)
|
* @param string $paymentType Payment type (buildCrmOrder requires it)
|
||||||
* @param string $status Status for order
|
* @param string $status Status for order
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function buildCrmOrderFromCart($api, $cart = null, $externalId = '', $paymentType = '', $status = '')
|
public static function buildCrmOrderFromCart($api, $cart = null, $externalId = '', $paymentType = '', $status = '')
|
||||||
{
|
{
|
||||||
if (empty($cart) || empty($paymentType) || empty($status)) {
|
if (empty($cart) || empty($paymentType) || empty($status)) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1134,7 +1144,7 @@ class RetailcrmOrderBuilder
|
|||||||
$order->id_address_invoice = $cart->id_address_invoice;
|
$order->id_address_invoice = $cart->id_address_invoice;
|
||||||
$order->id_currency = $cart->id_currency;
|
$order->id_currency = $cart->id_currency;
|
||||||
$order->id_carrier = $cart->id_carrier;
|
$order->id_carrier = $cart->id_carrier;
|
||||||
$order->total_discounts = $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS);;
|
$order->total_discounts = $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS);
|
||||||
$order->module = $paymentType;
|
$order->module = $paymentType;
|
||||||
$order->payment = $paymentType;
|
$order->payment = $paymentType;
|
||||||
|
|
||||||
@ -1150,7 +1160,8 @@ class RetailcrmOrderBuilder
|
|||||||
->setCmsOrder($order)
|
->setCmsOrder($order)
|
||||||
->setCmsCart($cart)
|
->setCmsCart($cart)
|
||||||
->setCmsCustomer(new Customer($cart->id_customer))
|
->setCmsCustomer(new Customer($cart->id_customer))
|
||||||
->buildOrderWithPreparedCustomer(true);
|
->buildOrderWithPreparedCustomer(true)
|
||||||
|
;
|
||||||
$orderData['externalId'] = $externalId;
|
$orderData['externalId'] = $externalId;
|
||||||
$orderData['status'] = $status;
|
$orderData['status'] = $status;
|
||||||
|
|
||||||
@ -1163,7 +1174,7 @@ class RetailcrmOrderBuilder
|
|||||||
$exception->getMessage()
|
$exception->getMessage()
|
||||||
);
|
);
|
||||||
|
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1175,10 +1186,10 @@ class RetailcrmOrderBuilder
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function buildCrmCustomer(Customer $object, $address = array())
|
public static function buildCrmCustomer(Customer $object, $address = [])
|
||||||
{
|
{
|
||||||
$customer = array_filter(array_merge(
|
$customer = array_filter(array_merge(
|
||||||
array(
|
[
|
||||||
'externalId' => !empty($object->id) ? $object->id : null,
|
'externalId' => !empty($object->id) ? $object->id : null,
|
||||||
'firstName' => $object->firstname,
|
'firstName' => $object->firstname,
|
||||||
'lastName' => $object->lastname,
|
'lastName' => $object->lastname,
|
||||||
@ -1188,20 +1199,20 @@ class RetailcrmOrderBuilder
|
|||||||
? $object->date_add : date('Y-m-d H:i:s'),
|
? $object->date_add : date('Y-m-d H:i:s'),
|
||||||
'birthday' => RetailcrmTools::verifyDate($object->birthday, 'Y-m-d')
|
'birthday' => RetailcrmTools::verifyDate($object->birthday, 'Y-m-d')
|
||||||
? $object->birthday : '',
|
? $object->birthday : '',
|
||||||
'sex' => $object->id_gender == "1" ? "male" : ($object->id_gender == "2" ? "female" : "")
|
'sex' => '1' == $object->id_gender ? 'male' : ('2' == $object->id_gender ? 'female' : ''),
|
||||||
),
|
],
|
||||||
$address
|
$address
|
||||||
), function ($value) {
|
), function ($value) {
|
||||||
return !($value === '' || $value === null || (is_array($value) ? count($value) == 0 : false));
|
return !('' === $value || null === $value || (is_array($value) ? 0 == count($value) : false));
|
||||||
});
|
});
|
||||||
|
|
||||||
return RetailcrmTools::filter(
|
return RetailcrmTools::filter(
|
||||||
'RetailcrmFilterProcessCustomer',
|
'RetailcrmFilterProcessCustomer',
|
||||||
$customer,
|
$customer,
|
||||||
array(
|
[
|
||||||
'customer' => $object,
|
'customer' => $object,
|
||||||
'address' => $address
|
'address' => $address,
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function buildCrmCustomerCorporate(
|
public static function buildCrmCustomerCorporate(
|
||||||
@ -1212,18 +1223,18 @@ class RetailcrmOrderBuilder
|
|||||||
$appendCompany = false,
|
$appendCompany = false,
|
||||||
$site = ''
|
$site = ''
|
||||||
) {
|
) {
|
||||||
$customerAddresses = array();
|
$customerAddresses = [];
|
||||||
$addresses = $object->getAddresses((int)Configuration::get('PS_LANG_DEFAULT'));
|
$addresses = $object->getAddresses((int) Configuration::get('PS_LANG_DEFAULT'));
|
||||||
$customer = array(
|
$customer = [
|
||||||
'addresses' => array(),
|
'addresses' => [],
|
||||||
'companies' => array()
|
'companies' => [],
|
||||||
);
|
];
|
||||||
$company = array(
|
$company = [
|
||||||
'isMain' => true,
|
'isMain' => true,
|
||||||
'externalId' => null,
|
'externalId' => null,
|
||||||
'active' => true,
|
'active' => true,
|
||||||
'name' => ''
|
'name' => '',
|
||||||
);
|
];
|
||||||
|
|
||||||
// TODO: $company['contragent']['INN'] may not work, should check that later...
|
// TODO: $company['contragent']['INN'] may not work, should check that later...
|
||||||
foreach ($addresses as $address) {
|
foreach ($addresses as $address) {
|
||||||
@ -1235,11 +1246,12 @@ class RetailcrmOrderBuilder
|
|||||||
->setAddress($address)
|
->setAddress($address)
|
||||||
->setWithExternalId(true)
|
->setWithExternalId(true)
|
||||||
->build()
|
->build()
|
||||||
->getDataArray();
|
->getDataArray()
|
||||||
|
;
|
||||||
$customer['nickName'] = empty($nickName) ? $address->company : $nickName;
|
$customer['nickName'] = empty($nickName) ? $address->company : $nickName;
|
||||||
$company['name'] = $address->company;
|
$company['name'] = $address->company;
|
||||||
$company['contragent']['INN'] = $address->vat_number;
|
$company['contragent']['INN'] = $address->vat_number;
|
||||||
$company['externalId'] = 'company_'.$address->id;
|
$company['externalId'] = 'company_' . $address->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($address) && !empty($address['company'])) {
|
if (is_array($address) && !empty($address['company'])) {
|
||||||
@ -1248,34 +1260,34 @@ class RetailcrmOrderBuilder
|
|||||||
->setAddressId($address['id_address'])
|
->setAddressId($address['id_address'])
|
||||||
->setWithExternalId(true)
|
->setWithExternalId(true)
|
||||||
->build()
|
->build()
|
||||||
->getDataArray();
|
->getDataArray()
|
||||||
|
;
|
||||||
$customer['nickName'] = empty($nickName) ? $address->company : $nickName;
|
$customer['nickName'] = empty($nickName) ? $address->company : $nickName;
|
||||||
$company['name'] = $address['company'];
|
$company['name'] = $address['company'];
|
||||||
$company['contragent']['INN'] = $address['vat_number'];
|
$company['contragent']['INN'] = $address['vat_number'];
|
||||||
$company['externalId'] = 'company_'.$address['id_address'];
|
$company['externalId'] = 'company_' . $address['id_address'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($appendCompany && !is_null($company['externalId'])) {
|
if ($appendCompany && null !== $company['externalId']) {
|
||||||
$customer['companies'][] = $company;
|
$customer['companies'][] = $company;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($contactExternalId) && !empty($site)) {
|
if (!empty($contactExternalId) && !empty($site)) {
|
||||||
$customer['customerContacts'] = array(array(
|
$customer['customerContacts'] = [[
|
||||||
'isMain' => true,
|
'isMain' => true,
|
||||||
'customer' => array(
|
'customer' => [
|
||||||
'externalId' => $contactExternalId,
|
'externalId' => $contactExternalId,
|
||||||
'site' => $site
|
'site' => $site,
|
||||||
)
|
],
|
||||||
));
|
]];
|
||||||
|
|
||||||
if (!empty($customer['companies'])
|
if (!empty($customer['companies'])
|
||||||
&& isset($customer['companies'][0])
|
&& isset($customer['companies'][0], $customer['companies'][0]['externalId'])
|
||||||
&& isset($customer['companies'][0]['externalId'])
|
|
||||||
) {
|
) {
|
||||||
$customer['customerContacts'][0]['companies'] = array(array(
|
$customer['customerContacts'][0]['companies'] = [[
|
||||||
'company' => array('externalId' => $customer['companies'][0]['externalId'])
|
'company' => ['externalId' => $customer['companies'][0]['externalId']],
|
||||||
));
|
]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1286,9 +1298,9 @@ class RetailcrmOrderBuilder
|
|||||||
return RetailcrmTools::filter(
|
return RetailcrmTools::filter(
|
||||||
'RetailcrmFilterProcessCustomerCorporate',
|
'RetailcrmFilterProcessCustomerCorporate',
|
||||||
RetailcrmTools::clearArray($customer),
|
RetailcrmTools::clearArray($customer),
|
||||||
array(
|
[
|
||||||
'customer' => $object
|
'customer' => $object,
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1300,17 +1312,16 @@ class RetailcrmOrderBuilder
|
|||||||
*/
|
*/
|
||||||
public static function isGiftItem($item)
|
public static function isGiftItem($item)
|
||||||
{
|
{
|
||||||
if (isset($item['offer'])
|
if (isset($item['offer'], $item['offer']['externalId'])
|
||||||
&& isset($item['offer']['externalId'])
|
&& RetailcrmReferences::GIFT_WRAPPING_ITEM_EXTERNAL_ID == $item['offer']['externalId']
|
||||||
&& $item['offer']['externalId'] == RetailcrmReferences::GIFT_WRAPPING_ITEM_EXTERNAL_ID
|
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($item['externalIds'])) {
|
if (isset($item['externalIds'])) {
|
||||||
foreach ($item['externalIds'] as $externalId) {
|
foreach ($item['externalIds'] as $externalId) {
|
||||||
if ($externalId['code'] == 'prestashop'
|
if ('prestashop' == $externalId['code']
|
||||||
&& $externalId['value'] == RetailcrmReferences::GIFT_WRAPPING_ITEM_EXTERNAL_ID
|
&& RetailcrmReferences::GIFT_WRAPPING_ITEM_EXTERNAL_ID == $externalId['value']
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1329,17 +1340,17 @@ class RetailcrmOrderBuilder
|
|||||||
*/
|
*/
|
||||||
public static function getGiftItem($giftItemPrice)
|
public static function getGiftItem($giftItemPrice)
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'externalIds' => array(array(
|
'externalIds' => [[
|
||||||
'code' => 'prestashop',
|
'code' => 'prestashop',
|
||||||
'value' => RetailcrmReferences::GIFT_WRAPPING_ITEM_EXTERNAL_ID
|
'value' => RetailcrmReferences::GIFT_WRAPPING_ITEM_EXTERNAL_ID,
|
||||||
)),
|
]],
|
||||||
'offer' => array('externalId' => RetailcrmReferences::GIFT_WRAPPING_ITEM_EXTERNAL_ID),
|
'offer' => ['externalId' => RetailcrmReferences::GIFT_WRAPPING_ITEM_EXTERNAL_ID],
|
||||||
'productName' => 'Gift Wrapping Cost',
|
'productName' => 'Gift Wrapping Cost',
|
||||||
'quantity' => 1,
|
'quantity' => 1,
|
||||||
'initialPrice' => $giftItemPrice,
|
'initialPrice' => $giftItemPrice,
|
||||||
'purchasePrice' => $giftItemPrice
|
'purchasePrice' => $giftItemPrice,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,6 +37,6 @@
|
|||||||
*/
|
*/
|
||||||
$_SERVER['HTTPS'] = 1;
|
$_SERVER['HTTPS'] = 1;
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/../../../config/config.inc.php');
|
require_once __DIR__ . '/../../../config/config.inc.php';
|
||||||
require_once(dirname(__FILE__) . '/../../../init.php');
|
require_once __DIR__ . '/../../../init.php';
|
||||||
require_once(dirname(__FILE__) . '/../bootstrap.php');
|
require_once __DIR__ . '/../bootstrap.php';
|
||||||
|
@ -41,11 +41,11 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
public $default_lang;
|
public $default_lang;
|
||||||
public $carriers;
|
public $carriers;
|
||||||
public $payment_modules = array();
|
public $payment_modules = [];
|
||||||
public $apiStatuses;
|
public $apiStatuses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool|RetailcrmApiClientV5|RetailcrmProxy $api
|
* @var bool|RetailcrmApiClientV5|RetailcrmProxy
|
||||||
*/
|
*/
|
||||||
private $api;
|
private $api;
|
||||||
|
|
||||||
@ -65,23 +65,23 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
public function getDeliveryTypes()
|
public function getDeliveryTypes()
|
||||||
{
|
{
|
||||||
$deliveryTypes = array();
|
$deliveryTypes = [];
|
||||||
$apiDeliveryTypes = $this->getApiDeliveryTypes();
|
$apiDeliveryTypes = $this->getApiDeliveryTypes();
|
||||||
|
|
||||||
if (!empty($this->carriers)) {
|
if (!empty($this->carriers)) {
|
||||||
foreach ($this->carriers as $carrier) {
|
foreach ($this->carriers as $carrier) {
|
||||||
$deliveryTypes[] = array(
|
$deliveryTypes[] = [
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'label' => $carrier['name'],
|
'label' => $carrier['name'],
|
||||||
'name' => 'RETAILCRM_API_DELIVERY[' . $carrier['id_carrier'] . ']',
|
'name' => 'RETAILCRM_API_DELIVERY[' . $carrier['id_carrier'] . ']',
|
||||||
'subname' => $carrier['id_carrier'],
|
'subname' => $carrier['id_carrier'],
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'options' => array(
|
'options' => [
|
||||||
'query' => $apiDeliveryTypes,
|
'query' => $apiDeliveryTypes,
|
||||||
'id' => 'id_option',
|
'id' => 'id_option',
|
||||||
'name' => 'name'
|
'name' => 'name',
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,26 +90,26 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
public function getStatuses()
|
public function getStatuses()
|
||||||
{
|
{
|
||||||
$statusTypes = array();
|
$statusTypes = [];
|
||||||
$states = OrderState::getOrderStates($this->default_lang, true);
|
$states = OrderState::getOrderStates($this->default_lang, true);
|
||||||
$this->apiStatuses = $this->apiStatuses ?: $this->getApiStatuses();
|
$this->apiStatuses = $this->apiStatuses ?: $this->getApiStatuses();
|
||||||
|
|
||||||
if (!empty($states)) {
|
if (!empty($states)) {
|
||||||
foreach ($states as $state) {
|
foreach ($states as $state) {
|
||||||
if ($state['name'] != ' ') {
|
if (' ' != $state['name']) {
|
||||||
$key = $state['id_order_state'];
|
$key = $state['id_order_state'];
|
||||||
$statusTypes[] = array(
|
$statusTypes[] = [
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'label' => $state['name'],
|
'label' => $state['name'],
|
||||||
'name' => "RETAILCRM_API_STATUS[$key]",
|
'name' => "RETAILCRM_API_STATUS[$key]",
|
||||||
'subname' => $key,
|
'subname' => $key,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'options' => array(
|
'options' => [
|
||||||
'query' => $this->apiStatuses,
|
'query' => $this->apiStatuses,
|
||||||
'id' => 'id_option',
|
'id' => 'id_option',
|
||||||
'name' => 'name'
|
'name' => 'name',
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,22 +119,22 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
public function getOutOfStockStatuses($arParams)
|
public function getOutOfStockStatuses($arParams)
|
||||||
{
|
{
|
||||||
$statusTypes = array();
|
$statusTypes = [];
|
||||||
$this->apiStatuses = $this->apiStatuses ?: $this->getApiStatuses();
|
$this->apiStatuses = $this->apiStatuses ?: $this->getApiStatuses();
|
||||||
|
|
||||||
foreach ($arParams as $key => $state) {
|
foreach ($arParams as $key => $state) {
|
||||||
$statusTypes[] = array(
|
$statusTypes[] = [
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'label' => $state,
|
'label' => $state,
|
||||||
'name' => "RETAILCRM_API_OUT_OF_STOCK_STATUS[$key]",
|
'name' => "RETAILCRM_API_OUT_OF_STOCK_STATUS[$key]",
|
||||||
'subname' => $key,
|
'subname' => $key,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'options' => array(
|
'options' => [
|
||||||
'query' => $this->apiStatuses,
|
'query' => $this->apiStatuses,
|
||||||
'id' => 'id_option',
|
'id' => 'id_option',
|
||||||
'name' => 'name'
|
'name' => 'name',
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $statusTypes;
|
return $statusTypes;
|
||||||
@ -143,23 +143,23 @@ class RetailcrmReferences
|
|||||||
public function getPaymentTypes()
|
public function getPaymentTypes()
|
||||||
{
|
{
|
||||||
$payments = $this->getSystemPaymentModules();
|
$payments = $this->getSystemPaymentModules();
|
||||||
$paymentTypes = array();
|
$paymentTypes = [];
|
||||||
$apiPaymentTypes = $this->getApiPaymentTypes();
|
$apiPaymentTypes = $this->getApiPaymentTypes();
|
||||||
|
|
||||||
if (!empty($payments)) {
|
if (!empty($payments)) {
|
||||||
foreach ($payments as $payment) {
|
foreach ($payments as $payment) {
|
||||||
$paymentTypes[] = array(
|
$paymentTypes[] = [
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'label' => $payment['name'],
|
'label' => $payment['name'],
|
||||||
'name' => 'RETAILCRM_API_PAYMENT[' . $payment['code'] . ']',
|
'name' => 'RETAILCRM_API_PAYMENT[' . $payment['code'] . ']',
|
||||||
'subname' => $payment['code'],
|
'subname' => $payment['code'],
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'options' => array(
|
'options' => [
|
||||||
'query' => $apiPaymentTypes,
|
'query' => $apiPaymentTypes,
|
||||||
'id' => 'id_option',
|
'id' => 'id_option',
|
||||||
'name' => 'name'
|
'name' => 'name',
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,63 +168,61 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
public function getPaymentAndDeliveryForDefault($arParams)
|
public function getPaymentAndDeliveryForDefault($arParams)
|
||||||
{
|
{
|
||||||
$paymentTypes = array();
|
$paymentTypes = [];
|
||||||
$deliveryTypes = array();
|
$deliveryTypes = [];
|
||||||
|
|
||||||
$paymentDeliveryTypes = array();
|
$paymentDeliveryTypes = [];
|
||||||
|
|
||||||
if (!empty($this->carriers)) {
|
if (!empty($this->carriers)) {
|
||||||
|
$deliveryTypes[] = [
|
||||||
$deliveryTypes[] = array(
|
|
||||||
'id_option' => '',
|
'id_option' => '',
|
||||||
'name' => '',
|
'name' => '',
|
||||||
);
|
];
|
||||||
|
|
||||||
foreach ($this->carriers as $valCarrier) {
|
foreach ($this->carriers as $valCarrier) {
|
||||||
$deliveryTypes[] = array(
|
$deliveryTypes[] = [
|
||||||
'id_option' => $valCarrier['id_carrier'],
|
'id_option' => $valCarrier['id_carrier'],
|
||||||
'name' => $valCarrier['name'],
|
'name' => $valCarrier['name'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$paymentDeliveryTypes[] = array(
|
$paymentDeliveryTypes[] = [
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'label' => $arParams[0],
|
'label' => $arParams[0],
|
||||||
'name' => 'RETAILCRM_API_DELIVERY_DEFAULT',
|
'name' => 'RETAILCRM_API_DELIVERY_DEFAULT',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'options' => array(
|
'options' => [
|
||||||
'query' => $deliveryTypes,
|
'query' => $deliveryTypes,
|
||||||
'id' => 'id_option',
|
'id' => 'id_option',
|
||||||
'name' => 'name'
|
'name' => 'name',
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
$paymentModules = $this->getSystemPaymentModules();
|
$paymentModules = $this->getSystemPaymentModules();
|
||||||
if (!empty($paymentModules)) {
|
if (!empty($paymentModules)) {
|
||||||
|
$paymentTypes[] = [
|
||||||
$paymentTypes[] = array(
|
|
||||||
'id_option' => '',
|
'id_option' => '',
|
||||||
'name' => '',
|
'name' => '',
|
||||||
);
|
];
|
||||||
|
|
||||||
foreach ($paymentModules as $valPayment) {
|
foreach ($paymentModules as $valPayment) {
|
||||||
$paymentTypes[$valPayment['id']] = array(
|
$paymentTypes[$valPayment['id']] = [
|
||||||
'id_option' => $valPayment['code'],
|
'id_option' => $valPayment['code'],
|
||||||
'name' => $valPayment['name'],
|
'name' => $valPayment['name'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$paymentDeliveryTypes[] = array(
|
$paymentDeliveryTypes[] = [
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'label' => $arParams[1],
|
'label' => $arParams[1],
|
||||||
'name' => 'RETAILCRM_API_PAYMENT_DEFAULT',
|
'name' => 'RETAILCRM_API_PAYMENT_DEFAULT',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'options' => array(
|
'options' => [
|
||||||
'query' => $paymentTypes,
|
'query' => $paymentTypes,
|
||||||
'id' => 'id_option',
|
'id' => 'id_option',
|
||||||
'name' => 'name'
|
'name' => 'name',
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $paymentDeliveryTypes;
|
return $paymentDeliveryTypes;
|
||||||
@ -239,46 +237,52 @@ class RetailcrmReferences
|
|||||||
*/
|
*/
|
||||||
$modules = RetailCRM::getCachedCmsModulesList();
|
$modules = RetailCRM::getCachedCmsModulesList();
|
||||||
$allPaymentModules = PaymentModule::getInstalledPaymentModules();
|
$allPaymentModules = PaymentModule::getInstalledPaymentModules();
|
||||||
$paymentModulesIds = array();
|
$paymentModulesIds = [];
|
||||||
|
|
||||||
foreach ($allPaymentModules as $module) {
|
foreach ($allPaymentModules as $module) {
|
||||||
$paymentModulesIds[] = $module['id_module'];
|
$paymentModulesIds[] = $module['id_module'];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
if ((!empty($module->parent_class) && $module->parent_class == 'PaymentModule')
|
if ((!empty($module->parent_class) && 'PaymentModule' == $module->parent_class)
|
||||||
|| in_array($module->id, $paymentModulesIds)
|
|| in_array($module->id, $paymentModulesIds)
|
||||||
) {
|
) {
|
||||||
if ($module->id) {
|
if ($module->id) {
|
||||||
$module_id = (int) $module->id;
|
$module_id = (int) $module->id;
|
||||||
|
|
||||||
if (!get_class($module) == 'SimpleXMLElement')
|
if ('SimpleXMLElement' == !get_class($module)) {
|
||||||
$module->country = array();
|
$module->country = [];
|
||||||
|
}
|
||||||
$countries = DB::getInstance()->executeS('SELECT id_country FROM ' . _DB_PREFIX_ . 'module_country WHERE id_module = ' . pSQL($module_id) . ' AND `id_shop`=' . pSQL($shop_id));
|
$countries = DB::getInstance()->executeS('SELECT id_country FROM ' . _DB_PREFIX_ . 'module_country WHERE id_module = ' . pSQL($module_id) . ' AND `id_shop`=' . pSQL($shop_id));
|
||||||
foreach ($countries as $country)
|
foreach ($countries as $country) {
|
||||||
$module->country[] = $country['id_country'];
|
$module->country[] = $country['id_country'];
|
||||||
if (!get_class($module) == 'SimpleXMLElement')
|
}
|
||||||
$module->currency = array();
|
if ('SimpleXMLElement' == !get_class($module)) {
|
||||||
|
$module->currency = [];
|
||||||
|
}
|
||||||
$currencies = DB::getInstance()->executeS('SELECT id_currency FROM ' . _DB_PREFIX_ . 'module_currency WHERE id_module = ' . pSQL($module_id) . ' AND `id_shop`=' . pSQL($shop_id));
|
$currencies = DB::getInstance()->executeS('SELECT id_currency FROM ' . _DB_PREFIX_ . 'module_currency WHERE id_module = ' . pSQL($module_id) . ' AND `id_shop`=' . pSQL($shop_id));
|
||||||
foreach ($currencies as $currency)
|
foreach ($currencies as $currency) {
|
||||||
$module->currency[] = $currency['id_currency'];
|
$module->currency[] = $currency['id_currency'];
|
||||||
if (!get_class($module) == 'SimpleXMLElement')
|
}
|
||||||
$module->group = array();
|
if ('SimpleXMLElement' == !get_class($module)) {
|
||||||
|
$module->group = [];
|
||||||
|
}
|
||||||
$groups = DB::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'module_group WHERE id_module = ' . pSQL($module_id) . ' AND `id_shop`=' . pSQL($shop_id));
|
$groups = DB::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'module_group WHERE id_module = ' . pSQL($module_id) . ' AND `id_shop`=' . pSQL($shop_id));
|
||||||
foreach ($groups as $group)
|
foreach ($groups as $group) {
|
||||||
$module->group[] = $group['id_group'];
|
$module->group[] = $group['id_group'];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$module->country = null;
|
$module->country = null;
|
||||||
$module->currency = null;
|
$module->currency = null;
|
||||||
$module->group = null;
|
$module->group = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($module->active != 0 || $active === false) {
|
if (0 != $module->active || false === $active) {
|
||||||
$this->payment_modules[] = array(
|
$this->payment_modules[] = [
|
||||||
'id' => $module->id,
|
'id' => $module->id,
|
||||||
'code' => $module->name,
|
'code' => $module->name,
|
||||||
'name' => $module->displayName
|
'name' => $module->displayName,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,23 +297,23 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
public function getApiDeliveryTypes()
|
public function getApiDeliveryTypes()
|
||||||
{
|
{
|
||||||
$crmDeliveryTypes = array();
|
$crmDeliveryTypes = [];
|
||||||
$request = $this->api->deliveryTypesList();
|
$request = $this->api->deliveryTypesList();
|
||||||
|
|
||||||
if ($request) {
|
if ($request) {
|
||||||
$crmDeliveryTypes[] = array(
|
$crmDeliveryTypes[] = [
|
||||||
'id_option' => '',
|
'id_option' => '',
|
||||||
'name' => '',
|
'name' => '',
|
||||||
);
|
];
|
||||||
foreach ($request->deliveryTypes as $dType) {
|
foreach ($request->deliveryTypes as $dType) {
|
||||||
if (!$dType['active']) {
|
if (!$dType['active']) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$crmDeliveryTypes[] = array(
|
$crmDeliveryTypes[] = [
|
||||||
'id_option' => $dType['code'],
|
'id_option' => $dType['code'],
|
||||||
'name' => $dType['name'],
|
'name' => $dType['name'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,31 +322,31 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
public function getApiStatuses()
|
public function getApiStatuses()
|
||||||
{
|
{
|
||||||
$crmStatusTypes = array();
|
$crmStatusTypes = [];
|
||||||
$request = $this->api->statusesList();
|
$request = $this->api->statusesList();
|
||||||
|
|
||||||
if ($request) {
|
if ($request) {
|
||||||
$crmStatusTypes[] = array(
|
$crmStatusTypes[] = [
|
||||||
'id_option' => '',
|
'id_option' => '',
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'ordering' => '',
|
'ordering' => '',
|
||||||
);
|
];
|
||||||
foreach ($request->statuses as $sType) {
|
foreach ($request->statuses as $sType) {
|
||||||
if (!$sType['active']) {
|
if (!$sType['active']) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$crmStatusTypes[] = array(
|
$crmStatusTypes[] = [
|
||||||
'id_option' => $sType['code'],
|
'id_option' => $sType['code'],
|
||||||
'name' => $sType['name'],
|
'name' => $sType['name'],
|
||||||
'ordering' => $sType['ordering'],
|
'ordering' => $sType['ordering'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
usort($crmStatusTypes, function ($a, $b) {
|
usort($crmStatusTypes, function ($a, $b) {
|
||||||
if ($a['ordering'] == $b['ordering']) {
|
if ($a['ordering'] == $b['ordering']) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return ($a['ordering'] < $b['ordering'] ? -1 : 1);
|
return $a['ordering'] < $b['ordering'] ? -1 : 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -352,23 +356,23 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
public function getApiPaymentTypes()
|
public function getApiPaymentTypes()
|
||||||
{
|
{
|
||||||
$crmPaymentTypes = array();
|
$crmPaymentTypes = [];
|
||||||
$request = $this->api->paymentTypesList();
|
$request = $this->api->paymentTypesList();
|
||||||
|
|
||||||
if ($request) {
|
if ($request) {
|
||||||
$crmPaymentTypes[] = array(
|
$crmPaymentTypes[] = [
|
||||||
'id_option' => '',
|
'id_option' => '',
|
||||||
'name' => '',
|
'name' => '',
|
||||||
);
|
];
|
||||||
foreach ($request->paymentTypes as $pType) {
|
foreach ($request->paymentTypes as $pType) {
|
||||||
if (!$pType['active']) {
|
if (!$pType['active']) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$crmPaymentTypes[] = array(
|
$crmPaymentTypes[] = [
|
||||||
'id_option' => $pType['code'],
|
'id_option' => $pType['code'],
|
||||||
'name' => $pType['name']
|
'name' => $pType['name'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,8 +385,8 @@ class RetailcrmReferences
|
|||||||
$response = $this->api->credentials();
|
$response = $this->api->credentials();
|
||||||
|
|
||||||
if (!($response instanceof RetailcrmApiResponse) || !$response->isSuccessful()
|
if (!($response instanceof RetailcrmApiResponse) || !$response->isSuccessful()
|
||||||
|| $response['siteAccess'] !== 'access_selective'
|
|| 'access_selective' !== $response['siteAccess']
|
||||||
|| count($response['sitesAvailable']) !== 1
|
|| 1 !== count($response['sitesAvailable'])
|
||||||
|| !in_array('/api/reference/sites', $response['credentials'])
|
|| !in_array('/api/reference/sites', $response['credentials'])
|
||||||
|| !in_array('/api/reference/sites/{code}/edit', $response['credentials'])
|
|| !in_array('/api/reference/sites/{code}/edit', $response['credentials'])
|
||||||
) {
|
) {
|
||||||
@ -401,7 +405,6 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
if ($response instanceof RetailcrmApiResponse && $response->isSuccessful()
|
if ($response instanceof RetailcrmApiResponse && $response->isSuccessful()
|
||||||
&& $response->offsetExists('sites') && $response['sites']) {
|
&& $response->offsetExists('sites') && $response['sites']) {
|
||||||
|
|
||||||
return current($response['sites']);
|
return current($response['sites']);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@ -423,16 +426,16 @@ class RetailcrmReferences
|
|||||||
$retailcrmStores = $this->getApiStores();
|
$retailcrmStores = $this->getApiStores();
|
||||||
|
|
||||||
foreach ($storesShop as $key => $storeShop) {
|
foreach ($storesShop as $key => $storeShop) {
|
||||||
$stores[] = array(
|
$stores[] = [
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'name' => 'RETAILCRM_STORES['. $key .']',
|
'name' => 'RETAILCRM_STORES[' . $key . ']',
|
||||||
'label' => $storeShop,
|
'label' => $storeShop,
|
||||||
'options' => array(
|
'options' => [
|
||||||
'query' => $retailcrmStores,
|
'query' => $retailcrmStores,
|
||||||
'id' => 'id_option',
|
'id' => 'id_option',
|
||||||
'name' => 'name'
|
'name' => 'name',
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $stores;
|
return $stores;
|
||||||
@ -440,7 +443,7 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
protected function getShopStores()
|
protected function getShopStores()
|
||||||
{
|
{
|
||||||
$stores = array();
|
$stores = [];
|
||||||
$warehouses = Warehouse::getWarehouses();
|
$warehouses = Warehouse::getWarehouses();
|
||||||
|
|
||||||
foreach ($warehouses as $warehouse) {
|
foreach ($warehouses as $warehouse) {
|
||||||
@ -454,20 +457,20 @@ class RetailcrmReferences
|
|||||||
|
|
||||||
protected function getApiStores()
|
protected function getApiStores()
|
||||||
{
|
{
|
||||||
$crmStores = array();
|
$crmStores = [];
|
||||||
$response = $this->api->storesList();
|
$response = $this->api->storesList();
|
||||||
|
|
||||||
if ($response) {
|
if ($response) {
|
||||||
$crmStores[] = array(
|
$crmStores[] = [
|
||||||
'id_option' => '',
|
'id_option' => '',
|
||||||
'name' => ''
|
'name' => '',
|
||||||
);
|
];
|
||||||
|
|
||||||
foreach ($response->stores as $store) {
|
foreach ($response->stores as $store) {
|
||||||
$crmStores[] = array(
|
$crmStores[] = [
|
||||||
'id_option' => $store['code'],
|
'id_option' => $store['code'],
|
||||||
'name' => $store['name']
|
'name' => $store['name'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class RetailcrmTools
|
|||||||
*/
|
*/
|
||||||
public static function isCorporateEnabled()
|
public static function isCorporateEnabled()
|
||||||
{
|
{
|
||||||
return (bool)Configuration::get(RetailCRM::ENABLE_CORPORATE_CLIENTS);
|
return (bool) Configuration::get(RetailCRM::ENABLE_CORPORATE_CLIENTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,7 +76,7 @@ class RetailcrmTools
|
|||||||
*/
|
*/
|
||||||
public static function isCustomerCorporate($customer)
|
public static function isCustomerCorporate($customer)
|
||||||
{
|
{
|
||||||
$addresses = $customer->getAddresses((int)Configuration::get('PS_LANG_DEFAULT'));
|
$addresses = $customer->getAddresses((int) Configuration::get('PS_LANG_DEFAULT'));
|
||||||
|
|
||||||
foreach ($addresses as $address) {
|
foreach ($addresses as $address) {
|
||||||
if (($address instanceof Address && !empty($address->company))
|
if (($address instanceof Address && !empty($address->company))
|
||||||
@ -116,7 +116,7 @@ class RetailcrmTools
|
|||||||
*/
|
*/
|
||||||
public static function isCrmOrderCorporate($order)
|
public static function isCrmOrderCorporate($order)
|
||||||
{
|
{
|
||||||
return isset($order['customer']['type']) && $order['customer']['type'] == 'customer_corporate';
|
return isset($order['customer']['type']) && 'customer_corporate' == $order['customer']['type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,7 +130,7 @@ class RetailcrmTools
|
|||||||
{
|
{
|
||||||
if (!empty($customer->id)) {
|
if (!empty($customer->id)) {
|
||||||
foreach ($customer->getAddresses(self::defaultLang()) as $addressArray) {
|
foreach ($customer->getAddresses(self::defaultLang()) as $addressArray) {
|
||||||
if ($addressArray['alias'] == 'default') {
|
if ('default' == $addressArray['alias']) {
|
||||||
return (int) $addressArray['id_address'];
|
return (int) $addressArray['id_address'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,9 +147,9 @@ class RetailcrmTools
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function verifyDate($date, $format = "Y-m-d")
|
public static function verifyDate($date, $format = 'Y-m-d')
|
||||||
{
|
{
|
||||||
return $date !== "0000-00-00" && (bool)date_create_from_format($format, $date);
|
return '0000-00-00' !== $date && (bool) date_create_immutable_from_format($format, $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,7 +163,7 @@ class RetailcrmTools
|
|||||||
{
|
{
|
||||||
$ids = explode(',', $ids);
|
$ids = explode(',', $ids);
|
||||||
|
|
||||||
$ranges = array();
|
$ranges = [];
|
||||||
|
|
||||||
foreach ($ids as $idx => $uid) {
|
foreach ($ids as $idx => $uid) {
|
||||||
if (strpos($uid, '-')) {
|
if (strpos($uid, '-')) {
|
||||||
@ -182,18 +182,20 @@ class RetailcrmTools
|
|||||||
/**
|
/**
|
||||||
* @param ObjectModel $object
|
* @param ObjectModel $object
|
||||||
* @param ObjectModel|null $relatedObject
|
* @param ObjectModel|null $relatedObject
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
*
|
||||||
* @throws PrestaShopException
|
* @throws PrestaShopException
|
||||||
*/
|
*/
|
||||||
public static function validateEntity($object, $relatedObject = null)
|
public static function validateEntity($object, $relatedObject = null)
|
||||||
{
|
{
|
||||||
$validate = $object->validateFields(false, true);
|
$validate = $object->validateFields(false, true);
|
||||||
if ($validate === true) {
|
if (true === $validate) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg = '';
|
$msg = '';
|
||||||
if ($relatedObject !== null) {
|
if (null !== $relatedObject) {
|
||||||
$msg = sprintf('for %s with id %s',
|
$msg = sprintf('for %s with id %s',
|
||||||
get_class($relatedObject),
|
get_class($relatedObject),
|
||||||
$relatedObject->id
|
$relatedObject->id
|
||||||
@ -224,10 +226,11 @@ class RetailcrmTools
|
|||||||
if (!is_object($object)) {
|
if (!is_object($object)) {
|
||||||
ob_start();
|
ob_start();
|
||||||
var_dump($object);
|
var_dump($object);
|
||||||
return (string)ob_get_clean();
|
|
||||||
|
return (string) ob_get_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array();
|
$data = [];
|
||||||
$type = get_class($object);
|
$type = get_class($object);
|
||||||
|
|
||||||
if (property_exists($type, 'definition')) {
|
if (property_exists($type, 'definition')) {
|
||||||
@ -243,7 +246,6 @@ class RetailcrmTools
|
|||||||
$data[$field] = $object->$field;
|
$data[$field] = $object->$field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,27 +255,28 @@ class RetailcrmTools
|
|||||||
/**
|
/**
|
||||||
* Converts CMS address to CRM address
|
* Converts CMS address to CRM address
|
||||||
*
|
*
|
||||||
* @param $address
|
* @param $address
|
||||||
* @param array $customer
|
* @param array $customer
|
||||||
* @param array $order
|
* @param array $order
|
||||||
|
*
|
||||||
* @deprecated Replaced with RetailcrmAddressBuilder
|
* @deprecated Replaced with RetailcrmAddressBuilder
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function addressParse($address, &$customer = array(), &$order = array())
|
public static function addressParse($address, &$customer = [], &$order = [])
|
||||||
{
|
{
|
||||||
if (!isset($customer)) {
|
if (!isset($customer)) {
|
||||||
$customer = array();
|
$customer = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($order)) {
|
if (!isset($order)) {
|
||||||
$order = array();
|
$order = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($address instanceof Address) {
|
if ($address instanceof Address) {
|
||||||
$postcode = $address->postcode;
|
$postcode = $address->postcode;
|
||||||
$city = $address->city;
|
$city = $address->city;
|
||||||
$addres_line = sprintf("%s %s", $address->address1, $address->address2);
|
$addres_line = sprintf('%s %s', $address->address1, $address->address2);
|
||||||
$countryIso = Country::getIsoById($address->id_country);
|
$countryIso = Country::getIsoById($address->id_country);
|
||||||
$vat = $address->vat_number;
|
$vat = $address->vat_number;
|
||||||
}
|
}
|
||||||
@ -302,31 +305,31 @@ class RetailcrmTools
|
|||||||
$order = array_merge($order, $phones['order']);
|
$order = array_merge($order, $phones['order']);
|
||||||
$customer = array_merge($customer, $phones['customer']);
|
$customer = array_merge($customer, $phones['customer']);
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
'order' => RetailcrmTools::clearArray($order),
|
'order' => RetailcrmTools::clearArray($order),
|
||||||
'customer' => RetailcrmTools::clearArray($customer),
|
'customer' => RetailcrmTools::clearArray($customer),
|
||||||
'vat' => isset($vat) && !empty($vat) ? $vat : ''
|
'vat' => isset($vat) && !empty($vat) ? $vat : '',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPhone($address, &$customer = array(), &$order = array())
|
public static function getPhone($address, &$customer = [], &$order = [])
|
||||||
{
|
{
|
||||||
if (!isset($customer)) {
|
if (!isset($customer)) {
|
||||||
$customer = array();
|
$customer = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($order)) {
|
if (!isset($order)) {
|
||||||
$order = array();
|
$order = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($address->phone_mobile)) {
|
if (!empty($address->phone_mobile)) {
|
||||||
$order['phone'] = $address->phone_mobile;
|
$order['phone'] = $address->phone_mobile;
|
||||||
$customer['phones'][] = array('number'=> $address->phone_mobile);
|
$customer['phones'][] = ['number' => $address->phone_mobile];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($address->phone)) {
|
if (!empty($address->phone)) {
|
||||||
$order['additionalPhone'] = $address->phone;
|
$order['additionalPhone'] = $address->phone;
|
||||||
$customer['phones'][] = array('number'=> $address->phone);
|
$customer['phones'][] = ['number' => $address->phone];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($order['phone']) && !empty($order['additionalPhone'])) {
|
if (!isset($order['phone']) && !empty($order['additionalPhone'])) {
|
||||||
@ -334,7 +337,7 @@ class RetailcrmTools
|
|||||||
unset($order['additionalPhone']);
|
unset($order['additionalPhone']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$phonesArray = array('customer' => $customer, 'order' => $order);
|
$phonesArray = ['customer' => $customer, 'order' => $order];
|
||||||
|
|
||||||
return $phonesArray;
|
return $phonesArray;
|
||||||
}
|
}
|
||||||
@ -368,8 +371,8 @@ class RetailcrmTools
|
|||||||
|
|
||||||
public static function explodeFIO($string)
|
public static function explodeFIO($string)
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = [];
|
||||||
$parse = (!$string) ? false : explode(" ", $string, 3);
|
$parse = (!$string) ? false : explode(' ', $string, 3);
|
||||||
|
|
||||||
switch (count($parse)) {
|
switch (count($parse)) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -410,6 +413,7 @@ class RetailcrmTools
|
|||||||
* @param callable|null $filterFunc
|
* @param callable|null $filterFunc
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
*
|
||||||
* @todo Don't filter out false & all methods MUST NOT use false as blank value.
|
* @todo Don't filter out false & all methods MUST NOT use false as blank value.
|
||||||
*/
|
*/
|
||||||
public static function clearArray(array $arr, $filterFunc = null)
|
public static function clearArray(array $arr, $filterFunc = null)
|
||||||
@ -418,16 +422,16 @@ class RetailcrmTools
|
|||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = array();
|
$result = [];
|
||||||
|
|
||||||
foreach ($arr as $index => $node) {
|
foreach ($arr as $index => $node) {
|
||||||
$result[$index] = (is_array($node))
|
$result[$index] = (is_array($node))
|
||||||
? self::clearArray($node)
|
? self::clearArray($node)
|
||||||
: $node;
|
: $node;
|
||||||
|
|
||||||
if ($result[$index] === ''
|
if ('' === $result[$index]
|
||||||
|| $result[$index] === null
|
|| null === $result[$index]
|
||||||
|| (is_array($result[$index]) && count($result[$index]) < 1)
|
|| (is_array($result[$index]) && 1 > count($result[$index]))
|
||||||
) {
|
) {
|
||||||
unset($result[$index]);
|
unset($result[$index]);
|
||||||
}
|
}
|
||||||
@ -438,7 +442,7 @@ class RetailcrmTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
return array_filter($result, function ($value) {
|
return array_filter($result, function ($value) {
|
||||||
return !is_null($value);
|
return null !== $value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,8 +503,8 @@ class RetailcrmTools
|
|||||||
*/
|
*/
|
||||||
public static function mergeCustomerAddress($customer, $address)
|
public static function mergeCustomerAddress($customer, $address)
|
||||||
{
|
{
|
||||||
$customerPhones = isset($customer['phones']) ? $customer['phones'] : array();
|
$customerPhones = isset($customer['phones']) ? $customer['phones'] : [];
|
||||||
$addressPhones = isset($address['phones']) ? $address['phones'] : array();
|
$addressPhones = isset($address['phones']) ? $address['phones'] : [];
|
||||||
$squashedCustomerPhones = array_filter(array_map(function ($val) {
|
$squashedCustomerPhones = array_filter(array_map(function ($val) {
|
||||||
return isset($val['number']) ? $val['number'] : null;
|
return isset($val['number']) ? $val['number'] : null;
|
||||||
}, $customerPhones));
|
}, $customerPhones));
|
||||||
@ -515,19 +519,21 @@ class RetailcrmTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_merge($customer, $address, array('phones' => $customerPhones));
|
return array_merge($customer, $address, ['phones' => $customerPhones]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare 'address' and 'phones' fields from crm customer info arrays
|
* Compare 'address' and 'phones' fields from crm customer info arrays
|
||||||
|
*
|
||||||
* @param $customer1
|
* @param $customer1
|
||||||
* @param $customer2
|
* @param $customer2
|
||||||
|
*
|
||||||
* @return bool <b>true</b> if addresses are equal, <b>false</b> otherwise
|
* @return bool <b>true</b> if addresses are equal, <b>false</b> otherwise
|
||||||
*/
|
*/
|
||||||
public static function isEqualCustomerAddress($customer1, $customer2)
|
public static function isEqualCustomerAddress($customer1, $customer2)
|
||||||
{
|
{
|
||||||
$customer1Phones = isset($customer1['phones']) ? $customer1['phones'] : array();
|
$customer1Phones = isset($customer1['phones']) ? $customer1['phones'] : [];
|
||||||
$customer2Phones = isset($customer2['phones']) ? $customer2['phones'] : array();
|
$customer2Phones = isset($customer2['phones']) ? $customer2['phones'] : [];
|
||||||
|
|
||||||
$squashedCustomer1Phones = array_filter(array_map(function ($val) {
|
$squashedCustomer1Phones = array_filter(array_map(function ($val) {
|
||||||
return isset($val['number']) ? $val['number'] : null;
|
return isset($val['number']) ? $val['number'] : null;
|
||||||
@ -542,8 +548,8 @@ class RetailcrmTools
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$customer1Address = isset($customer1['address']) ? $customer1['address'] : array();
|
$customer1Address = isset($customer1['address']) ? $customer1['address'] : [];
|
||||||
$customer2Address = isset($customer2['address']) ? $customer2['address'] : array();
|
$customer2Address = isset($customer2['address']) ? $customer2['address'] : [];
|
||||||
|
|
||||||
if (isset($customer1Address['id'])) {
|
if (isset($customer1Address['id'])) {
|
||||||
unset($customer1Address['id']);
|
unset($customer1Address['id']);
|
||||||
@ -573,7 +579,7 @@ class RetailcrmTools
|
|||||||
if (function_exists('http_response_code')) {
|
if (function_exists('http_response_code')) {
|
||||||
$code = http_response_code($code);
|
$code = http_response_code($code);
|
||||||
} else {
|
} else {
|
||||||
if ($code !== NULL) {
|
if (null !== $code) {
|
||||||
switch ($code) {
|
switch ($code) {
|
||||||
case 100: $text = 'Continue'; break;
|
case 100: $text = 'Continue'; break;
|
||||||
case 101: $text = 'Switching Protocols'; break;
|
case 101: $text = 'Switching Protocols'; break;
|
||||||
@ -638,7 +644,7 @@ class RetailcrmTools
|
|||||||
*/
|
*/
|
||||||
public static function isCustomerChangedToRegular($assembledOrder)
|
public static function isCustomerChangedToRegular($assembledOrder)
|
||||||
{
|
{
|
||||||
return isset($assembledOrder['contragentType']) && $assembledOrder['contragentType'] == 'individual';
|
return isset($assembledOrder['contragentType']) && 'individual' == $assembledOrder['contragentType'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -651,7 +657,7 @@ class RetailcrmTools
|
|||||||
*/
|
*/
|
||||||
public static function isCustomerChangedToLegal($assembledOrder)
|
public static function isCustomerChangedToLegal($assembledOrder)
|
||||||
{
|
{
|
||||||
return isset($assembledOrder['contragentType']) && $assembledOrder['contragentType'] == 'legal-entity';
|
return isset($assembledOrder['contragentType']) && 'legal-entity' == $assembledOrder['contragentType'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -682,13 +688,13 @@ class RetailcrmTools
|
|||||||
* (it will be set to id from provided customer, even if it doesn't have ID yet).
|
* (it will be set to id from provided customer, even if it doesn't have ID yet).
|
||||||
*
|
*
|
||||||
* @param Customer|CustomerCore $customer
|
* @param Customer|CustomerCore $customer
|
||||||
* @param Address|\AddressCore $address
|
* @param Address|\AddressCore $address
|
||||||
*/
|
*/
|
||||||
public static function assignAddressIdsByFields($customer, $address)
|
public static function assignAddressIdsByFields($customer, $address)
|
||||||
{
|
{
|
||||||
RetailcrmLogger::writeDebugArray(
|
RetailcrmLogger::writeDebugArray(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array('Called with customer', $customer->id, 'and address', self::dumpEntity($address))
|
['Called with customer', $customer->id, 'and address', self::dumpEntity($address)]
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($customer->getAddresses(self::defaultLang()) as $customerInnerAddress) {
|
foreach ($customer->getAddresses(self::defaultLang()) as $customerInnerAddress) {
|
||||||
@ -711,13 +717,13 @@ class RetailcrmTools
|
|||||||
*/
|
*/
|
||||||
public static function startJobManager()
|
public static function startJobManager()
|
||||||
{
|
{
|
||||||
$intervals = array(
|
$intervals = [
|
||||||
'RetailcrmClearLogsEvent' => new \DateInterval('P1D'),
|
'RetailcrmClearLogsEvent' => new \DateInterval('P1D'),
|
||||||
'RetailcrmIcmlEvent' => new \DateInterval('PT4H'),
|
'RetailcrmIcmlEvent' => new \DateInterval('PT4H'),
|
||||||
'RetailcrmInventoriesEvent' => new \DateInterval('PT15M'),
|
'RetailcrmInventoriesEvent' => new \DateInterval('PT15M'),
|
||||||
'RetailcrmSyncEvent' => new \DateInterval('PT7M'),
|
'RetailcrmSyncEvent' => new \DateInterval('PT7M'),
|
||||||
'RetailcrmAbandonedCartsEvent' => new \DateInterval('PT1M')
|
'RetailcrmAbandonedCartsEvent' => new \DateInterval('PT1M'),
|
||||||
);
|
];
|
||||||
|
|
||||||
RetailcrmJobManager::startJobs(self::filter(
|
RetailcrmJobManager::startJobs(self::filter(
|
||||||
'RetailcrmFilterJobManagerIntervals',
|
'RetailcrmFilterJobManagerIntervals',
|
||||||
@ -735,7 +741,7 @@ class RetailcrmTools
|
|||||||
*/
|
*/
|
||||||
protected static function isAddressesEqualByFields($first, $second)
|
protected static function isAddressesEqualByFields($first, $second)
|
||||||
{
|
{
|
||||||
$checkMapping = array(
|
$checkMapping = [
|
||||||
'alias',
|
'alias',
|
||||||
'id_country',
|
'id_country',
|
||||||
'lastname',
|
'lastname',
|
||||||
@ -748,21 +754,21 @@ class RetailcrmTools
|
|||||||
'other',
|
'other',
|
||||||
'phone',
|
'phone',
|
||||||
'company',
|
'company',
|
||||||
'vat_number'
|
'vat_number',
|
||||||
);
|
];
|
||||||
|
|
||||||
foreach ($checkMapping as $field) {
|
foreach ($checkMapping as $field) {
|
||||||
if ($first->$field != $second->$field) {
|
if ($first->$field != $second->$field) {
|
||||||
RetailcrmLogger::writeDebug(__METHOD__, json_encode(array(
|
RetailcrmLogger::writeDebug(__METHOD__, json_encode([
|
||||||
'first' => array(
|
'first' => [
|
||||||
'id' => $first->id,
|
'id' => $first->id,
|
||||||
$field => $first->$field
|
$field => $first->$field,
|
||||||
),
|
],
|
||||||
'second' => array(
|
'second' => [
|
||||||
'id' => $second->id,
|
'id' => $second->id,
|
||||||
$field => $second->$field
|
$field => $second->$field,
|
||||||
),
|
],
|
||||||
)));
|
]));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -780,7 +786,7 @@ class RetailcrmTools
|
|||||||
*
|
*
|
||||||
* @return false|mixed
|
* @return false|mixed
|
||||||
*/
|
*/
|
||||||
public static function filter($filter, $object, $parameters = array())
|
public static function filter($filter, $object, $parameters = [])
|
||||||
{
|
{
|
||||||
if (!class_exists($filter)) {
|
if (!class_exists($filter)) {
|
||||||
return $object;
|
return $object;
|
||||||
@ -798,8 +804,8 @@ class RetailcrmTools
|
|||||||
try {
|
try {
|
||||||
RetailcrmLogger::writeDebug($filter . '::before', print_r(self::dumpEntity($object), true));
|
RetailcrmLogger::writeDebug($filter . '::before', print_r(self::dumpEntity($object), true));
|
||||||
$result = call_user_func_array(
|
$result = call_user_func_array(
|
||||||
array($filter, 'filter'),
|
[$filter, 'filter'],
|
||||||
array($object, $parameters)
|
[$object, $parameters]
|
||||||
);
|
);
|
||||||
RetailcrmLogger::writeDebug($filter . '::after', print_r(self::dumpEntity($result), true));
|
RetailcrmLogger::writeDebug($filter . '::after', print_r(self::dumpEntity($result), true));
|
||||||
|
|
||||||
@ -814,6 +820,7 @@ class RetailcrmTools
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
|
*
|
||||||
* @return array|false|mixed
|
* @return array|false|mixed
|
||||||
*/
|
*/
|
||||||
public static function getConfigurationByName($name)
|
public static function getConfigurationByName($name)
|
||||||
@ -836,12 +843,13 @@ class RetailcrmTools
|
|||||||
try {
|
try {
|
||||||
return current(Db::getInstance()->executeS($sql));
|
return current(Db::getInstance()->executeS($sql));
|
||||||
} catch (PrestaShopDatabaseException $e) {
|
} catch (PrestaShopDatabaseException $e) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
|
*
|
||||||
* @return DateTime|false
|
* @return DateTime|false
|
||||||
*/
|
*/
|
||||||
public static function getConfigurationCreatedAtByName($name)
|
public static function getConfigurationCreatedAtByName($name)
|
||||||
@ -852,6 +860,6 @@ class RetailcrmTools
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DateTime::createFromFormat('Y-m-d H:i:s', $config['date_add']);
|
return DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $config['date_add']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -40,7 +40,7 @@ class RetailcrmApiErrors
|
|||||||
/** @var array */
|
/** @var array */
|
||||||
private static $errors;
|
private static $errors;
|
||||||
|
|
||||||
/** @var integer */
|
/** @var int */
|
||||||
private static $statusCode;
|
private static $statusCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,6 +69,7 @@ class RetailcrmApiErrors
|
|||||||
public static function getErrors()
|
public static function getErrors()
|
||||||
{
|
{
|
||||||
static::checkArray();
|
static::checkArray();
|
||||||
|
|
||||||
return static::$errors;
|
return static::$errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ class RetailcrmApiErrors
|
|||||||
* Returns false if incorrect data was passed to it.
|
* Returns false if incorrect data was passed to it.
|
||||||
*
|
*
|
||||||
* @param array $errors
|
* @param array $errors
|
||||||
* @param integer $statusCode
|
* @param int $statusCode
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -102,7 +103,7 @@ class RetailcrmApiErrors
|
|||||||
private static function checkArray()
|
private static function checkArray()
|
||||||
{
|
{
|
||||||
if (!is_array(static::$errors)) {
|
if (!is_array(static::$errors)) {
|
||||||
static::$errors = array();
|
static::$errors = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ class RetailcrmApiPaginatedRequest
|
|||||||
public function setApi($api)
|
public function setApi($api)
|
||||||
{
|
{
|
||||||
$this->api = $api;
|
$this->api = $api;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +104,7 @@ class RetailcrmApiPaginatedRequest
|
|||||||
public function setMethod($method)
|
public function setMethod($method)
|
||||||
{
|
{
|
||||||
$this->method = $method;
|
$this->method = $method;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +118,7 @@ class RetailcrmApiPaginatedRequest
|
|||||||
public function setParams($params)
|
public function setParams($params)
|
||||||
{
|
{
|
||||||
$this->params = $params;
|
$this->params = $params;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +132,7 @@ class RetailcrmApiPaginatedRequest
|
|||||||
public function setDataKey($dataKey)
|
public function setDataKey($dataKey)
|
||||||
{
|
{
|
||||||
$this->dataKey = $dataKey;
|
$this->dataKey = $dataKey;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +146,7 @@ class RetailcrmApiPaginatedRequest
|
|||||||
public function setLimit($limit)
|
public function setLimit($limit)
|
||||||
{
|
{
|
||||||
$this->limit = $limit;
|
$this->limit = $limit;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +160,7 @@ class RetailcrmApiPaginatedRequest
|
|||||||
public function setPageLimit($pageLimit)
|
public function setPageLimit($pageLimit)
|
||||||
{
|
{
|
||||||
$this->pageLimit = $pageLimit;
|
$this->pageLimit = $pageLimit;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,13 +171,13 @@ class RetailcrmApiPaginatedRequest
|
|||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$this->data = array();
|
$this->data = [];
|
||||||
$response = true;
|
$response = true;
|
||||||
$page = 1;
|
$page = 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$response = call_user_func_array(
|
$response = call_user_func_array(
|
||||||
array($this->api, $this->method),
|
[$this->api, $this->method],
|
||||||
$this->buildParams($this->params, $page)
|
$this->buildParams($this->params, $page)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -180,7 +186,7 @@ class RetailcrmApiPaginatedRequest
|
|||||||
$page = $response['pagination']['currentPage'] + 1;
|
$page = $response['pagination']['currentPage'] + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->pageLimit !== null && $page > $this->pageLimit) {
|
if (null !== $this->pageLimit && $page > $this->pageLimit) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +217,7 @@ class RetailcrmApiPaginatedRequest
|
|||||||
$this->method = '';
|
$this->method = '';
|
||||||
$this->limit = 100;
|
$this->limit = 100;
|
||||||
$this->pageLimit = null;
|
$this->pageLimit = null;
|
||||||
$this->data = array();
|
$this->data = [];
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -220,18 +226,18 @@ class RetailcrmApiPaginatedRequest
|
|||||||
* buildParams
|
* buildParams
|
||||||
*
|
*
|
||||||
* @param array $placeholderParams
|
* @param array $placeholderParams
|
||||||
* @param int $currentPage
|
* @param int $currentPage
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function buildParams($placeholderParams, $currentPage)
|
private function buildParams($placeholderParams, $currentPage)
|
||||||
{
|
{
|
||||||
foreach ($placeholderParams as $key => $param) {
|
foreach ($placeholderParams as $key => $param) {
|
||||||
if ($param == '{{page}}') {
|
if ('{{page}}' == $param) {
|
||||||
$placeholderParams[$key] = $currentPage;
|
$placeholderParams[$key] = $currentPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($param == '{{limit}}') {
|
if ('{{limit}}' == $param) {
|
||||||
$placeholderParams[$key] = $this->limit;
|
$placeholderParams[$key] = $this->limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,13 @@ class RetailcrmApiRequest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $api
|
* @param mixed $api
|
||||||
|
*
|
||||||
* @return RetailcrmApiRequest
|
* @return RetailcrmApiRequest
|
||||||
*/
|
*/
|
||||||
public function setApi($api)
|
public function setApi($api)
|
||||||
{
|
{
|
||||||
$this->api = $api;
|
$this->api = $api;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +42,7 @@ class RetailcrmApiRequest
|
|||||||
public function setData($data)
|
public function setData($data)
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +60,7 @@ class RetailcrmApiRequest
|
|||||||
public function setMethod($method)
|
public function setMethod($method)
|
||||||
{
|
{
|
||||||
$this->method = $method;
|
$this->method = $method;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -47,7 +47,7 @@ class RetailcrmApiResponse implements \ArrayAccess
|
|||||||
/**
|
/**
|
||||||
* ApiResponse constructor.
|
* ApiResponse constructor.
|
||||||
*
|
*
|
||||||
* @param int $statusCode HTTP status code
|
* @param int $statusCode HTTP status code
|
||||||
* @param mixed $responseBody HTTP body
|
* @param mixed $responseBody HTTP body
|
||||||
*
|
*
|
||||||
* @throws InvalidJsonException
|
* @throws InvalidJsonException
|
||||||
@ -96,14 +96,14 @@ class RetailcrmApiResponse implements \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public function isSuccessful()
|
public function isSuccessful()
|
||||||
{
|
{
|
||||||
return $this->statusCode < 400;
|
return 400 > $this->statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow to access for the property throw class method
|
* Allow to access for the property throw class method
|
||||||
*
|
*
|
||||||
* @param string $name method name
|
* @param string $name method name
|
||||||
* @param mixed $arguments method parameters
|
* @param mixed $arguments method parameters
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*
|
*
|
||||||
@ -143,9 +143,10 @@ class RetailcrmApiResponse implements \ArrayAccess
|
|||||||
* Offset set
|
* Offset set
|
||||||
*
|
*
|
||||||
* @param mixed $offset offset
|
* @param mixed $offset offset
|
||||||
* @param mixed $value value
|
* @param mixed $value value
|
||||||
*
|
*
|
||||||
* @throws \BadMethodCallException
|
* @throws \BadMethodCallException
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function offsetSet($offset, $value)
|
public function offsetSet($offset, $value)
|
||||||
@ -159,6 +160,7 @@ class RetailcrmApiResponse implements \ArrayAccess
|
|||||||
* @param mixed $offset offset
|
* @param mixed $offset offset
|
||||||
*
|
*
|
||||||
* @throws \BadMethodCallException
|
* @throws \BadMethodCallException
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function offsetUnset($offset)
|
public function offsetUnset($offset)
|
||||||
|
@ -46,12 +46,12 @@ class RetailcrmHttpClient
|
|||||||
/**
|
/**
|
||||||
* Client constructor.
|
* Client constructor.
|
||||||
*
|
*
|
||||||
* @param string $url api url
|
* @param string $url api url
|
||||||
* @param array $defaultParameters array of parameters
|
* @param array $defaultParameters array of parameters
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function __construct($url, array $defaultParameters = array())
|
public function __construct($url, array $defaultParameters = [])
|
||||||
{
|
{
|
||||||
if (false === stripos($url, 'https://')) {
|
if (false === stripos($url, 'https://')) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
@ -76,9 +76,9 @@ class RetailcrmHttpClient
|
|||||||
/**
|
/**
|
||||||
* Make HTTP request
|
* Make HTTP request
|
||||||
*
|
*
|
||||||
* @param string $path request url
|
* @param string $path request url
|
||||||
* @param string $method (default: 'GET')
|
* @param string $method (default: 'GET')
|
||||||
* @param array $parameters (default: array())
|
* @param array $parameters (default: array())
|
||||||
*
|
*
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||||
*
|
*
|
||||||
@ -91,9 +91,9 @@ class RetailcrmHttpClient
|
|||||||
public function makeRequest(
|
public function makeRequest(
|
||||||
$path,
|
$path,
|
||||||
$method,
|
$method,
|
||||||
array $parameters = array()
|
array $parameters = []
|
||||||
) {
|
) {
|
||||||
$allowedMethods = array(self::METHOD_GET, self::METHOD_POST);
|
$allowedMethods = [self::METHOD_GET, self::METHOD_POST];
|
||||||
|
|
||||||
if (!in_array($method, $allowedMethods, false)) {
|
if (!in_array($method, $allowedMethods, false)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
@ -67,7 +66,8 @@ class RetailcrmProxy
|
|||||||
->setAction(function ($request) {
|
->setAction(function ($request) {
|
||||||
return call_user_func_array([$this->client, $request->getMethod()], $request->getData());
|
return call_user_func_array([$this->client, $request->getMethod()], $request->getData());
|
||||||
})
|
})
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __call($method, $arguments)
|
public function __call($method, $arguments)
|
||||||
@ -76,7 +76,8 @@ class RetailcrmProxy
|
|||||||
|
|
||||||
$request->setApi($this->client)
|
$request->setApi($this->client)
|
||||||
->setMethod($method)
|
->setMethod($method)
|
||||||
->setData($arguments);
|
->setData($arguments)
|
||||||
|
;
|
||||||
|
|
||||||
return $this->pipeline->run($request);
|
return $this->pipeline->run($request);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -35,12 +35,10 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class RetailcrmExceptionMiddleware implements RetailcrmMiddlewareInterface
|
class RetailcrmExceptionMiddleware implements RetailcrmMiddlewareInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function __invoke(RetailcrmApiRequest $request, callable $next = null)
|
public function __invoke(RetailcrmApiRequest $request, callable $next = null)
|
||||||
{
|
{
|
||||||
@ -52,7 +50,7 @@ class RetailcrmExceptionMiddleware implements RetailcrmMiddlewareInterface
|
|||||||
|
|
||||||
$response = new RetailcrmApiResponse(500, json_encode([
|
$response = new RetailcrmApiResponse(500, json_encode([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'errorMsg' => sprintf('Internal error: %s', $e->getMessage())
|
'errorMsg' => sprintf('Internal error: %s', $e->getMessage()),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,18 +36,16 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class RetailcrmLoggerMiddleware implements RetailcrmMiddlewareInterface
|
class RetailcrmLoggerMiddleware implements RetailcrmMiddlewareInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function __invoke(RetailcrmApiRequest $request, callable $next = null)
|
public function __invoke(RetailcrmApiRequest $request, callable $next = null)
|
||||||
{
|
{
|
||||||
$method = $request->getMethod();
|
$method = $request->getMethod();
|
||||||
|
|
||||||
if (!is_null($method)) {
|
if (null !== $method) {
|
||||||
RetailcrmLogger::writeDebug($method, print_r($request->getData(), true));
|
RetailcrmLogger::writeDebug($method, print_r($request->getData(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -5,6 +5,7 @@ interface RetailcrmMiddlewareInterface
|
|||||||
/**
|
/**
|
||||||
* @param RetailcrmApiRequest $request
|
* @param RetailcrmApiRequest $request
|
||||||
* @param callable|null $next
|
* @param callable|null $next
|
||||||
|
*
|
||||||
* @return RetailcrmApiResponse
|
* @return RetailcrmApiResponse
|
||||||
*/
|
*/
|
||||||
public function __invoke(RetailcrmApiRequest $request, callable $next = null);
|
public function __invoke(RetailcrmApiRequest $request, callable $next = null);
|
||||||
|
@ -19,31 +19,37 @@ class RetailcrmPipeline
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RetailcrmApiRequest $request
|
* @param RetailcrmApiRequest $request
|
||||||
|
*
|
||||||
* @return callable
|
* @return callable
|
||||||
*/
|
*/
|
||||||
public function run(RetailcrmApiRequest $request)
|
public function run(RetailcrmApiRequest $request)
|
||||||
{
|
{
|
||||||
$pipeline = $this->pipeline;
|
$pipeline = $this->pipeline;
|
||||||
|
|
||||||
return $pipeline($request);
|
return $pipeline($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param callable $action
|
* @param callable $action
|
||||||
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setAction(callable $action)
|
public function setAction(callable $action)
|
||||||
{
|
{
|
||||||
$this->action = $action;
|
$this->action = $action;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $middlewares
|
* @param array $middlewares
|
||||||
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setMiddlewares(array $middlewares)
|
public function setMiddlewares(array $middlewares)
|
||||||
{
|
{
|
||||||
$this->middlewares = $middlewares;
|
$this->middlewares = $middlewares;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +70,8 @@ class RetailcrmPipeline
|
|||||||
{
|
{
|
||||||
return function ($stack, $middlewareClass) {
|
return function ($stack, $middlewareClass) {
|
||||||
return function ($request) use ($stack, $middlewareClass) {
|
return function ($request) use ($stack, $middlewareClass) {
|
||||||
$middleware = new $middlewareClass;
|
$middleware = new $middlewareClass();
|
||||||
|
|
||||||
return $middleware($request, $stack);
|
return $middleware($request, $stack);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
class RetailcrmAbandonedCartsEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
class RetailcrmAbandonedCartsEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
@ -58,7 +57,7 @@ class RetailcrmAbandonedCartsEvent extends RetailcrmAbstractEvent implements Ret
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($shops as $shop) {
|
foreach ($shops as $shop) {
|
||||||
RetailcrmContextSwitcher::setShopContext(intval($shop['id_shop']));
|
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||||
|
|
||||||
$syncCartsActive = Configuration::get(RetailCRM::SYNC_CARTS_ACTIVE);
|
$syncCartsActive = Configuration::get(RetailCRM::SYNC_CARTS_ACTIVE);
|
||||||
|
|
||||||
@ -86,7 +85,7 @@ class RetailcrmAbandonedCartsEvent extends RetailcrmAbstractEvent implements Ret
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -35,8 +35,7 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
@ -45,16 +44,16 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
private $shopId;
|
private $shopId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
abstract public function execute();
|
abstract public function execute();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
throw new InvalidArgumentException("Not implemented.");
|
throw new InvalidArgumentException('Not implemented.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,7 +63,7 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
*/
|
*/
|
||||||
public function setCliMode($mode)
|
public function setCliMode($mode)
|
||||||
{
|
{
|
||||||
$this->cliMode = (bool)$mode;
|
$this->cliMode = (bool) $mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +71,7 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
*/
|
*/
|
||||||
public function setForce($force)
|
public function setForce($force)
|
||||||
{
|
{
|
||||||
$this->force = (bool)$force;
|
$this->force = (bool) $force;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,8 +81,9 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
*/
|
*/
|
||||||
public function setShopId($shopId = null)
|
public function setShopId($shopId = null)
|
||||||
{
|
{
|
||||||
if (!is_null($shopId))
|
if (null !== $shopId) {
|
||||||
$this->shopId = intval($shopId);
|
$this->shopId = (int) $shopId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +93,7 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
*/
|
*/
|
||||||
protected function isRunning()
|
protected function isRunning()
|
||||||
{
|
{
|
||||||
return !$this->force && (RetailcrmJobManager::getCurrentJob() !== '' || RetailcrmCli::getCurrentJob() !== '');
|
return !$this->force && ('' !== RetailcrmJobManager::getCurrentJob() || '' !== RetailcrmCli::getCurrentJob());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,7 +103,7 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
*/
|
*/
|
||||||
protected function setRunning()
|
protected function setRunning()
|
||||||
{
|
{
|
||||||
if($this->force) {
|
if ($this->force) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,12 +124,12 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
$shops = Shop::getShops();
|
$shops = Shop::getShops();
|
||||||
|
|
||||||
if (Shop::isFeatureActive()) {
|
if (Shop::isFeatureActive()) {
|
||||||
if ($this->shopId > 0) {
|
if (0 < $this->shopId) {
|
||||||
if (isset($shops[$this->shopId])) {
|
if (isset($shops[$this->shopId])) {
|
||||||
RetailcrmLogger::writeDebug(
|
RetailcrmLogger::writeDebug(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
sprintf(
|
sprintf(
|
||||||
"Running job for shop %s (%s).",
|
'Running job for shop %s (%s).',
|
||||||
$shops[$this->shopId]['name'],
|
$shops[$this->shopId]['name'],
|
||||||
$this->shopId
|
$this->shopId
|
||||||
)
|
)
|
||||||
@ -151,7 +151,6 @@ abstract class RetailcrmAbstractEvent implements RetailcrmEventInterface
|
|||||||
|
|
||||||
return $shops;
|
return $shops;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return [$shops[Shop::getContextShopID()]];
|
return [$shops[Shop::getContextShopID()]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
class RetailcrmClearLogsEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
class RetailcrmClearLogsEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
@ -57,7 +56,7 @@ class RetailcrmClearLogsEvent extends RetailcrmAbstractEvent implements Retailcr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface RetailcrmEventInterface
|
interface RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
class RetailcrmExportEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
class RetailcrmExportEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
@ -54,7 +53,7 @@ class RetailcrmExportEvent extends RetailcrmAbstractEvent implements RetailcrmEv
|
|||||||
$shops = $this->getShops();
|
$shops = $this->getShops();
|
||||||
|
|
||||||
foreach ($shops as $shop) {
|
foreach ($shops as $shop) {
|
||||||
RetailcrmContextSwitcher::setShopContext(intval($shop['id_shop']));
|
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||||
|
|
||||||
$api = RetailcrmTools::getApiClient();
|
$api = RetailcrmTools::getApiClient();
|
||||||
|
|
||||||
@ -76,7 +75,7 @@ class RetailcrmExportEvent extends RetailcrmAbstractEvent implements RetailcrmEv
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
class RetailcrmIcmlEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
class RetailcrmIcmlEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
@ -54,7 +53,7 @@ class RetailcrmIcmlEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
|||||||
$shops = $this->getShops();
|
$shops = $this->getShops();
|
||||||
|
|
||||||
foreach ($shops as $shop) {
|
foreach ($shops as $shop) {
|
||||||
RetailcrmContextSwitcher::setShopContext(intval($shop['id_shop']));
|
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||||
|
|
||||||
$job = new RetailcrmCatalog();
|
$job = new RetailcrmCatalog();
|
||||||
$data = $job->getData();
|
$data = $job->getData();
|
||||||
@ -67,7 +66,7 @@ class RetailcrmIcmlEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
class RetailcrmIcmlUpdateUrlEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
class RetailcrmIcmlUpdateUrlEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
@ -54,7 +53,7 @@ class RetailcrmIcmlUpdateUrlEvent extends RetailcrmAbstractEvent implements Reta
|
|||||||
$shops = $this->getShops();
|
$shops = $this->getShops();
|
||||||
|
|
||||||
foreach ($shops as $shop) {
|
foreach ($shops as $shop) {
|
||||||
RetailcrmContextSwitcher::setShopContext(intval($shop['id_shop']));
|
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||||
|
|
||||||
if (!file_exists(RetailcrmCatalogHelper::getIcmlFilePath())) {
|
if (!file_exists(RetailcrmCatalogHelper::getIcmlFilePath())) {
|
||||||
continue;
|
continue;
|
||||||
@ -86,7 +85,7 @@ class RetailcrmIcmlUpdateUrlEvent extends RetailcrmAbstractEvent implements Reta
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
class RetailcrmInventoriesEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
class RetailcrmInventoriesEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
@ -54,7 +53,7 @@ class RetailcrmInventoriesEvent extends RetailcrmAbstractEvent implements Retail
|
|||||||
$shops = $this->getShops();
|
$shops = $this->getShops();
|
||||||
|
|
||||||
foreach ($shops as $shop) {
|
foreach ($shops as $shop) {
|
||||||
RetailcrmContextSwitcher::setShopContext(intval($shop['id_shop']));
|
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||||
|
|
||||||
if (!Configuration::get(RetailCRM::ENABLE_BALANCES_RECEIVING)) {
|
if (!Configuration::get(RetailCRM::ENABLE_BALANCES_RECEIVING)) {
|
||||||
RetailcrmLogger::writeDebug(
|
RetailcrmLogger::writeDebug(
|
||||||
@ -83,7 +82,7 @@ class RetailcrmInventoriesEvent extends RetailcrmAbstractEvent implements Retail
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
@ -78,25 +77,25 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
|||||||
$payment = json_decode(Configuration::get(RetailCRM::PAYMENT), true);
|
$payment = json_decode(Configuration::get(RetailCRM::PAYMENT), true);
|
||||||
$status = json_decode(Configuration::get(RetailCRM::STATUS), true);
|
$status = json_decode(Configuration::get(RetailCRM::STATUS), true);
|
||||||
|
|
||||||
$order = array(
|
$order = [
|
||||||
'externalId' => $orderInstance->id,
|
'externalId' => $orderInstance->id,
|
||||||
'createdAt' => $orderInstance->date_add,
|
'createdAt' => $orderInstance->date_add,
|
||||||
);
|
];
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Add order customer info
|
* Add order customer info
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!empty($orderInstance->id_customer)) {
|
if (!empty($orderInstance->id_customer)) {
|
||||||
$orderCustomer = new Customer($orderInstance->id_customer);
|
$orderCustomer = new Customer($orderInstance->id_customer);
|
||||||
$customer = array(
|
$customer = [
|
||||||
'externalId' => $orderCustomer->id,
|
'externalId' => $orderCustomer->id,
|
||||||
'firstName' => $orderCustomer->firstname,
|
'firstName' => $orderCustomer->firstname,
|
||||||
'lastname' => $orderCustomer->lastname,
|
'lastname' => $orderCustomer->lastname,
|
||||||
'email' => $orderCustomer->email,
|
'email' => $orderCustomer->email,
|
||||||
'createdAt' => $orderCustomer->date_add
|
'createdAt' => $orderCustomer->date_add,
|
||||||
);
|
];
|
||||||
|
|
||||||
$response = $api->customersEdit($customer);
|
$response = $api->customersEdit($customer);
|
||||||
|
|
||||||
@ -110,13 +109,12 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/**
|
|
||||||
* Add order status
|
* Add order status
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($orderInstance->current_state == 0) {
|
if (0 == $orderInstance->current_state) {
|
||||||
$order['status'] = 'completed';
|
$order['status'] = 'completed';
|
||||||
} else {
|
} else {
|
||||||
$order['status'] = array_key_exists($orderInstance->current_state, $status)
|
$order['status'] = array_key_exists($orderInstance->current_state, $status)
|
||||||
@ -127,22 +125,20 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add order address data
|
* Add order address data
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$cart = new Cart($orderInstance->getCartIdStatic($orderInstance->id));
|
$cart = new Cart($orderInstance->getCartIdStatic($orderInstance->id));
|
||||||
$addressCollection = $cart->getAddressCollection();
|
$addressCollection = $cart->getAddressCollection();
|
||||||
$address = array_shift($addressCollection);
|
$address = array_shift($addressCollection);
|
||||||
|
|
||||||
if ($address instanceof Address) {
|
if ($address instanceof Address) {
|
||||||
$phone = is_null($address->phone)
|
$phone = null === $address->phone
|
||||||
? is_null($address->phone_mobile) ? '' : $address->phone_mobile
|
? null === $address->phone_mobile ? '' : $address->phone_mobile
|
||||||
: $address->phone
|
: $address->phone
|
||||||
;
|
;
|
||||||
|
|
||||||
$postcode = $address->postcode;
|
$postcode = $address->postcode;
|
||||||
$city = $address->city;
|
$city = $address->city;
|
||||||
$addres_line = sprintf("%s %s", $address->address1, $address->address2);
|
$addres_line = sprintf('%s %s', $address->address1, $address->address2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($postcode)) {
|
if (!empty($postcode)) {
|
||||||
@ -161,11 +157,11 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
|||||||
$order['phone'] = $phone;
|
$order['phone'] = $phone;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Add payment & shippment data
|
* Add payment & shippment data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (Module::getInstanceByName('advancedcheckout') === false) {
|
if (false === Module::getInstanceByName('advancedcheckout')) {
|
||||||
$paymentType = $orderInstance->module;
|
$paymentType = $orderInstance->module;
|
||||||
} else {
|
} else {
|
||||||
$paymentType = $orderInstance->payment;
|
$paymentType = $orderInstance->payment;
|
||||||
@ -179,26 +175,24 @@ class RetailcrmMissingEvent extends RetailcrmAbstractEvent implements RetailcrmE
|
|||||||
$order['delivery']['code'] = $delivery[$orderInstance->id_carrier];
|
$order['delivery']['code'] = $delivery[$orderInstance->id_carrier];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($orderInstance->total_shipping_tax_incl) && (int) $orderInstance->total_shipping_tax_incl > 0) {
|
if (isset($orderInstance->total_shipping_tax_incl) && 0 < (int) $orderInstance->total_shipping_tax_incl) {
|
||||||
$order['delivery']['cost'] = round($orderInstance->total_shipping_tax_incl, 2);
|
$order['delivery']['cost'] = round($orderInstance->total_shipping_tax_incl, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add products
|
* Add products
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$products = $orderInstance->getProducts();
|
$products = $orderInstance->getProducts();
|
||||||
|
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
$item = array(
|
$item = [
|
||||||
//'productId' => $product['product_id'],
|
//'productId' => $product['product_id'],
|
||||||
'offer' => array('externalId' => $product['product_id']),
|
'offer' => ['externalId' => $product['product_id']],
|
||||||
'productName' => $product['product_name'],
|
'productName' => $product['product_name'],
|
||||||
'quantity' => $product['product_quantity'],
|
'quantity' => $product['product_quantity'],
|
||||||
'initialPrice' => round($product['product_price'], 2),
|
'initialPrice' => round($product['product_price'], 2),
|
||||||
'purchasePrice' => round($product['purchase_supplier_price'], 2)
|
'purchasePrice' => round($product['purchase_supplier_price'], 2),
|
||||||
);
|
];
|
||||||
|
|
||||||
$order['items'][] = $item;
|
$order['items'][] = $item;
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
class RetailcrmSyncEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
class RetailcrmSyncEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
@ -54,7 +53,7 @@ class RetailcrmSyncEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
|||||||
$shops = $this->getShops();
|
$shops = $this->getShops();
|
||||||
|
|
||||||
foreach ($shops as $shop) {
|
foreach ($shops as $shop) {
|
||||||
RetailcrmContextSwitcher::setShopContext(intval($shop['id_shop']));
|
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||||
|
|
||||||
if (!Configuration::get(RetailCRM::ENABLE_HISTORY_UPLOADS)) {
|
if (!Configuration::get(RetailCRM::ENABLE_HISTORY_UPLOADS)) {
|
||||||
RetailcrmLogger::writeDebug(
|
RetailcrmLogger::writeDebug(
|
||||||
@ -67,7 +66,7 @@ class RetailcrmSyncEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
|||||||
|
|
||||||
$apiUrl = Configuration::get(RetailCRM::API_URL);
|
$apiUrl = Configuration::get(RetailCRM::API_URL);
|
||||||
$apiKey = Configuration::get(RetailCRM::API_KEY);
|
$apiKey = Configuration::get(RetailCRM::API_KEY);
|
||||||
RetailcrmHistory::$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
RetailcrmHistory::$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
||||||
|
|
||||||
if (!empty($apiUrl) && !empty($apiKey)) {
|
if (!empty($apiUrl) && !empty($apiKey)) {
|
||||||
RetailcrmHistory::$api = new RetailcrmProxy($apiUrl, $apiKey, RetailcrmLogger::getLogFile());
|
RetailcrmHistory::$api = new RetailcrmProxy($apiUrl, $apiKey, RetailcrmLogger::getLogFile());
|
||||||
@ -85,7 +84,7 @@ class RetailcrmSyncEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
require_once __DIR__ . '/../RetailcrmPrestashopLoader.php';
|
||||||
require_once(dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php');
|
|
||||||
|
|
||||||
class RetailcrmUpdateSinceIdEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
class RetailcrmUpdateSinceIdEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
@ -54,7 +53,7 @@ class RetailcrmUpdateSinceIdEvent extends RetailcrmAbstractEvent implements Reta
|
|||||||
$shops = $this->getShops();
|
$shops = $this->getShops();
|
||||||
|
|
||||||
foreach ($shops as $shop) {
|
foreach ($shops as $shop) {
|
||||||
RetailcrmContextSwitcher::setShopContext(intval($shop['id_shop']));
|
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||||
|
|
||||||
$api = RetailcrmTools::getApiClient();
|
$api = RetailcrmTools::getApiClient();
|
||||||
|
|
||||||
@ -71,7 +70,7 @@ class RetailcrmUpdateSinceIdEvent extends RetailcrmAbstractEvent implements Reta
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -35,30 +35,28 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class RetailcrmJobManagerException extends Exception
|
class RetailcrmJobManagerException extends Exception
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string $job
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $job;
|
private $job;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $jobs
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $jobs;
|
private $jobs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RetailcrmJobManagerException constructor.
|
* RetailcrmJobManagerException constructor.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param string $job
|
* @param string $job
|
||||||
* @param array $jobs
|
* @param array $jobs
|
||||||
* @param int $code
|
* @param int $code
|
||||||
* @param \Exception|null $previous
|
* @param \Exception|null $previous
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function __construct($message = "", $job = "", $jobs = array(), $code = 0, \Exception $previous = null)
|
public function __construct($message = '', $job = '', $jobs = [], $code = 0, Exception $previous = null)
|
||||||
{
|
{
|
||||||
parent::__construct($message, $code, $previous);
|
parent::__construct($message, $code, $previous);
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -43,15 +43,15 @@ class RetailcrmCustomerSwitcherResult
|
|||||||
/** @var \Address */
|
/** @var \Address */
|
||||||
private $address;
|
private $address;
|
||||||
|
|
||||||
/** @var \Order $order */
|
/** @var \Order */
|
||||||
private $order;
|
private $order;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RetailcrmCustomerSwitcherResult constructor.
|
* RetailcrmCustomerSwitcherResult constructor.
|
||||||
*
|
*
|
||||||
* @param \Customer $customer
|
* @param \Customer $customer
|
||||||
* @param \Address $address
|
* @param \Address $address
|
||||||
* @param \Order $order
|
* @param \Order $order
|
||||||
*/
|
*/
|
||||||
public function __construct($customer, $address, $order)
|
public function __construct($customer, $address, $order)
|
||||||
{
|
{
|
||||||
@ -88,6 +88,7 @@ class RetailcrmCustomerSwitcherResult
|
|||||||
public function setAddress($address)
|
public function setAddress($address)
|
||||||
{
|
{
|
||||||
$this->address = $address;
|
$this->address = $address;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,20 +104,21 @@ class RetailcrmCustomerSwitcherResult
|
|||||||
* Save customer (if exists) and order.
|
* Save customer (if exists) and order.
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
|
*
|
||||||
* @throws \PrestaShopException
|
* @throws \PrestaShopException
|
||||||
*/
|
*/
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
RetailcrmLogger::writeDebugArray(
|
RetailcrmLogger::writeDebugArray(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array(
|
[
|
||||||
'Saving customer, address and order:',
|
'Saving customer, address and order:',
|
||||||
array(
|
[
|
||||||
'customer' => RetailcrmTools::dumpEntity($this->customer),
|
'customer' => RetailcrmTools::dumpEntity($this->customer),
|
||||||
'address' => RetailcrmTools::dumpEntity($this->address),
|
'address' => RetailcrmTools::dumpEntity($this->address),
|
||||||
'order' => RetailcrmTools::dumpEntity($this->order)
|
'order' => RetailcrmTools::dumpEntity($this->order),
|
||||||
)
|
],
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($this->customer)) {
|
if (!empty($this->customer)) {
|
||||||
|
@ -37,22 +37,22 @@
|
|||||||
*/
|
*/
|
||||||
class RetailcrmCustomerSwitcherState
|
class RetailcrmCustomerSwitcherState
|
||||||
{
|
{
|
||||||
/** @var \Order $order */
|
/** @var \Order */
|
||||||
private $order;
|
private $order;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $newCustomer;
|
private $newCustomer;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $newContact;
|
private $newContact;
|
||||||
|
|
||||||
/** @var string $newCompanyName */
|
/** @var string */
|
||||||
private $newCompanyName;
|
private $newCompanyName;
|
||||||
|
|
||||||
/** @var array $companyAddress */
|
/** @var array */
|
||||||
private $companyAddress;
|
private $companyAddress;
|
||||||
|
|
||||||
/** @var array $crmOrderShippingAddress */
|
/** @var array */
|
||||||
private $crmOrderShippingAddress;
|
private $crmOrderShippingAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,6 +71,7 @@ class RetailcrmCustomerSwitcherState
|
|||||||
public function setOrder($order)
|
public function setOrder($order)
|
||||||
{
|
{
|
||||||
$this->order = $order;
|
$this->order = $order;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ class RetailcrmCustomerSwitcherState
|
|||||||
public function setNewCustomer($newCustomer)
|
public function setNewCustomer($newCustomer)
|
||||||
{
|
{
|
||||||
$this->newCustomer = $newCustomer;
|
$this->newCustomer = $newCustomer;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +111,7 @@ class RetailcrmCustomerSwitcherState
|
|||||||
public function setNewContact($newContact)
|
public function setNewContact($newContact)
|
||||||
{
|
{
|
||||||
$this->newContact = $newContact;
|
$this->newContact = $newContact;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +131,7 @@ class RetailcrmCustomerSwitcherState
|
|||||||
public function setNewCompanyName($newCompanyName)
|
public function setNewCompanyName($newCompanyName)
|
||||||
{
|
{
|
||||||
$this->newCompanyName = $newCompanyName;
|
$this->newCompanyName = $newCompanyName;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +151,7 @@ class RetailcrmCustomerSwitcherState
|
|||||||
public function setCompanyAddress($companyAddress)
|
public function setCompanyAddress($companyAddress)
|
||||||
{
|
{
|
||||||
$this->companyAddress = $companyAddress;
|
$this->companyAddress = $companyAddress;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,6 +189,7 @@ class RetailcrmCustomerSwitcherState
|
|||||||
public function setCrmOrderShippingAddress($crmOrderShippingAddress)
|
public function setCrmOrderShippingAddress($crmOrderShippingAddress)
|
||||||
{
|
{
|
||||||
$this->crmOrderShippingAddress = $crmOrderShippingAddress;
|
$this->crmOrderShippingAddress = $crmOrderShippingAddress;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,6 +208,7 @@ class RetailcrmCustomerSwitcherState
|
|||||||
* Throws an exception if state is not valid
|
* Throws an exception if state is not valid
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function validate()
|
public function validate()
|
||||||
@ -217,11 +224,11 @@ class RetailcrmCustomerSwitcherState
|
|||||||
if (!empty($this->newCustomer) && !empty($this->newContact)) {
|
if (!empty($this->newCustomer) && !empty($this->newContact)) {
|
||||||
RetailcrmLogger::writeDebugArray(
|
RetailcrmLogger::writeDebugArray(
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array(
|
[
|
||||||
'State data (customer and contact):' . PHP_EOL,
|
'State data (customer and contact):' . PHP_EOL,
|
||||||
$this->getNewCustomer(),
|
$this->getNewCustomer(),
|
||||||
$this->getNewContact()
|
$this->getNewContact(),
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
'Too much data in state - cannot determine which customer should be used.'
|
'Too much data in state - cannot determine which customer should be used.'
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -59,7 +59,7 @@ abstract class RetailcrmAbstractTemplate
|
|||||||
/** @var array */
|
/** @var array */
|
||||||
private $confirmations;
|
private $confirmations;
|
||||||
|
|
||||||
/** @var Context $context */
|
/** @var Context */
|
||||||
protected $context;
|
protected $context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,10 +74,10 @@ abstract class RetailcrmAbstractTemplate
|
|||||||
$this->module = $module;
|
$this->module = $module;
|
||||||
$this->smarty = $smarty;
|
$this->smarty = $smarty;
|
||||||
$this->assets = $assets;
|
$this->assets = $assets;
|
||||||
$this->errors = array();
|
$this->errors = [];
|
||||||
$this->warnings = array();
|
$this->warnings = [];
|
||||||
$this->informations = array();
|
$this->informations = [];
|
||||||
$this->confirmations = array();
|
$this->confirmations = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,6 +106,7 @@ abstract class RetailcrmAbstractTemplate
|
|||||||
* @param $file
|
* @param $file
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
*
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function render($file)
|
public function render($file)
|
||||||
@ -114,21 +115,21 @@ abstract class RetailcrmAbstractTemplate
|
|||||||
$this->setTemplate();
|
$this->setTemplate();
|
||||||
|
|
||||||
if (null === $this->template) {
|
if (null === $this->template) {
|
||||||
throw new \RuntimeException("Template not be blank");
|
throw new \RuntimeException('Template not be blank');
|
||||||
}
|
}
|
||||||
|
|
||||||
// set url post for forms
|
// set url post for forms
|
||||||
if (empty($this->smarty->getTemplateVars('url_post'))) {
|
if (empty($this->smarty->getTemplateVars('url_post'))) {
|
||||||
$this->data['url_post'] = $this->smarty->getTemplateVars('current')
|
$this->data['url_post'] = $this->smarty->getTemplateVars('current')
|
||||||
.'&token='.$this->smarty->getTemplateVars('token');
|
. '&token=' . $this->smarty->getTemplateVars('token');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->smarty->assign(\array_merge($this->data, array(
|
$this->smarty->assign(\array_merge($this->data, [
|
||||||
'moduleErrors' => $this->errors,
|
'moduleErrors' => $this->errors,
|
||||||
'moduleWarnings' => $this->warnings,
|
'moduleWarnings' => $this->warnings,
|
||||||
'moduleConfirmations' => $this->confirmations,
|
'moduleConfirmations' => $this->confirmations,
|
||||||
'moduleInfos' => $this->informations,
|
'moduleInfos' => $this->informations,
|
||||||
)));
|
]));
|
||||||
|
|
||||||
return $this->module->display($file, "views/templates/admin/$this->template");
|
return $this->module->display($file, "views/templates/admin/$this->template");
|
||||||
}
|
}
|
||||||
@ -204,5 +205,6 @@ abstract class RetailcrmAbstractTemplate
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function buildParams();
|
abstract protected function buildParams();
|
||||||
|
|
||||||
abstract protected function setTemplate();
|
abstract protected function setTemplate();
|
||||||
}
|
}
|
||||||
|
@ -57,14 +57,14 @@ class RetailcrmBaseTemplate extends RetailcrmAbstractTemplate
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->data = array(
|
$this->data = [
|
||||||
'assets' => $this->assets,
|
'assets' => $this->assets,
|
||||||
'apiUrl' => RetailCRM::API_URL,
|
'apiUrl' => RetailCRM::API_URL,
|
||||||
'apiKey' => RetailCRM::API_KEY,
|
'apiKey' => RetailCRM::API_KEY,
|
||||||
'promoVideoUrl' => $promoVideoUrl,
|
'promoVideoUrl' => $promoVideoUrl,
|
||||||
'registerUrl' => $registerUrl,
|
'registerUrl' => $registerUrl,
|
||||||
'supportEmail' => $supportEmail
|
'supportEmail' => $supportEmail,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,6 +72,6 @@ class RetailcrmBaseTemplate extends RetailcrmAbstractTemplate
|
|||||||
*/
|
*/
|
||||||
protected function setTemplate()
|
protected function setTemplate()
|
||||||
{
|
{
|
||||||
$this->template = "index.tpl";
|
$this->template = 'index.tpl';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,10 +44,10 @@ class RetailcrmSettingsTemplate extends RetailcrmAbstractTemplate
|
|||||||
* RetailcrmSettingsTemplate constructor.
|
* RetailcrmSettingsTemplate constructor.
|
||||||
*
|
*
|
||||||
* @param \Module $module
|
* @param \Module $module
|
||||||
* @param $smarty
|
* @param $smarty
|
||||||
* @param $assets
|
* @param $assets
|
||||||
* @param $settings
|
* @param $settings
|
||||||
* @param $settingsNames
|
* @param $settingsNames
|
||||||
*/
|
*/
|
||||||
public function __construct(Module $module, $smarty, $assets, $settings, $settingsNames)
|
public function __construct(Module $module, $smarty, $assets, $settings, $settingsNames)
|
||||||
{
|
{
|
||||||
@ -64,7 +64,7 @@ class RetailcrmSettingsTemplate extends RetailcrmAbstractTemplate
|
|||||||
*/
|
*/
|
||||||
protected function getParams()
|
protected function getParams()
|
||||||
{
|
{
|
||||||
$params = array();
|
$params = [];
|
||||||
|
|
||||||
if ($this->module->api) {
|
if ($this->module->api) {
|
||||||
$params['statusesDefaultExport'] = $this->module->reference->getStatuseDefaultExport();
|
$params['statusesDefaultExport'] = $this->module->reference->getStatuseDefaultExport();
|
||||||
@ -103,10 +103,10 @@ class RetailcrmSettingsTemplate extends RetailcrmAbstractTemplate
|
|||||||
protected function buildParams()
|
protected function buildParams()
|
||||||
{
|
{
|
||||||
$this->data = array_merge(
|
$this->data = array_merge(
|
||||||
array(
|
[
|
||||||
'assets' => $this->assets,
|
'assets' => $this->assets,
|
||||||
'cartsDelays' => $this->module->getSynchronizedCartsTimeSelect(),
|
'cartsDelays' => $this->module->getSynchronizedCartsTimeSelect(),
|
||||||
),
|
],
|
||||||
$this->getParams(),
|
$this->getParams(),
|
||||||
$this->settingsNames,
|
$this->settingsNames,
|
||||||
$this->settings
|
$this->settings
|
||||||
@ -118,6 +118,6 @@ class RetailcrmSettingsTemplate extends RetailcrmAbstractTemplate
|
|||||||
*/
|
*/
|
||||||
protected function setTemplate()
|
protected function setTemplate()
|
||||||
{
|
{
|
||||||
$this->template = "settings.tpl";
|
$this->template = 'settings.tpl';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
|
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
|
||||||
date_default_timezone_set(@date_default_timezone_get());
|
date_default_timezone_set(@date_default_timezone_get());
|
||||||
}
|
}
|
||||||
@ -44,7 +43,7 @@ if (!defined('_PS_VERSION_')) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/bootstrap.php');
|
require_once __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
class RetailCRM extends Module
|
class RetailCRM extends Module
|
||||||
{
|
{
|
||||||
@ -89,7 +88,7 @@ class RetailCRM extends Module
|
|||||||
'RetailcrmIcmlUpdateUrlEvent' => 'Icml update URL',
|
'RetailcrmIcmlUpdateUrlEvent' => 'Icml update URL',
|
||||||
'RetailcrmSyncEvent' => 'History synchronization',
|
'RetailcrmSyncEvent' => 'History synchronization',
|
||||||
'RetailcrmInventoriesEvent' => 'Inventories uploads',
|
'RetailcrmInventoriesEvent' => 'Inventories uploads',
|
||||||
'RetailcrmClearLogsEvent' => 'Clearing logs'
|
'RetailcrmClearLogsEvent' => 'Clearing logs',
|
||||||
];
|
];
|
||||||
|
|
||||||
const TABS_TO_VALIDATE = [
|
const TABS_TO_VALIDATE = [
|
||||||
@ -101,22 +100,22 @@ class RetailCRM extends Module
|
|||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $templateErrors
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $templateErrors;
|
private $templateErrors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $templateWarnings
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $templateWarnings;
|
private $templateWarnings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $templateConfirms
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $templateConfirms;
|
private $templateConfirms;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $templateInfos
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $templateInfos;
|
private $templateInfos;
|
||||||
|
|
||||||
@ -154,7 +153,7 @@ class RetailCRM extends Module
|
|||||||
$this->default_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
|
$this->default_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
|
||||||
$this->apiUrl = Configuration::get(static::API_URL);
|
$this->apiUrl = Configuration::get(static::API_URL);
|
||||||
$this->apiKey = Configuration::get(static::API_KEY);
|
$this->apiKey = Configuration::get(static::API_KEY);
|
||||||
$this->ps_versions_compliancy = array('min' => '1.6.1.0', 'max' => _PS_VERSION_);
|
$this->ps_versions_compliancy = ['min' => '1.6.1.0', 'max' => _PS_VERSION_];
|
||||||
$this->psVersion = Tools::substr(_PS_VERSION_, 0, 3);
|
$this->psVersion = Tools::substr(_PS_VERSION_, 0, 3);
|
||||||
$this->log = RetailcrmLogger::getLogFile();
|
$this->log = RetailcrmLogger::getLogFile();
|
||||||
$this->module_key = 'dff3095326546f5fe8995d9e86288491';
|
$this->module_key = 'dff3095326546f5fe8995d9e86288491';
|
||||||
@ -165,7 +164,7 @@ class RetailCRM extends Module
|
|||||||
$this->name .
|
$this->name .
|
||||||
'/views';
|
'/views';
|
||||||
|
|
||||||
if ($this->psVersion == '1.6') {
|
if ('1.6' == $this->psVersion) {
|
||||||
$this->bootstrap = true;
|
$this->bootstrap = true;
|
||||||
$this->use_new_hooks = false;
|
$this->use_new_hooks = false;
|
||||||
}
|
}
|
||||||
@ -184,19 +183,19 @@ class RetailCRM extends Module
|
|||||||
Shop::setContext(Shop::CONTEXT_ALL);
|
Shop::setContext(Shop::CONTEXT_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return
|
||||||
parent::install() &&
|
parent::install()
|
||||||
$this->registerHook('newOrder') &&
|
&& $this->registerHook('newOrder')
|
||||||
$this->registerHook('actionOrderStatusPostUpdate') &&
|
&& $this->registerHook('actionOrderStatusPostUpdate')
|
||||||
$this->registerHook('actionPaymentConfirmation') &&
|
&& $this->registerHook('actionPaymentConfirmation')
|
||||||
$this->registerHook('actionCustomerAccountAdd') &&
|
&& $this->registerHook('actionCustomerAccountAdd')
|
||||||
$this->registerHook('actionOrderEdited') &&
|
&& $this->registerHook('actionOrderEdited')
|
||||||
$this->registerHook('actionCarrierUpdate') &&
|
&& $this->registerHook('actionCarrierUpdate')
|
||||||
$this->registerHook('header') &&
|
&& $this->registerHook('header')
|
||||||
($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true) &&
|
&& ($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true)
|
||||||
($this->use_new_hooks ? $this->registerHook('actionValidateCustomerAddressForm') : true) &&
|
&& ($this->use_new_hooks ? $this->registerHook('actionValidateCustomerAddressForm') : true)
|
||||||
$this->installDB()
|
&& $this->installDB()
|
||||||
);
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hookHeader()
|
public function hookHeader()
|
||||||
@ -225,50 +224,50 @@ class RetailCRM extends Module
|
|||||||
$this->integrationModule($api, $clientId, false);
|
$this->integrationModule($api, $clientId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::uninstall() &&
|
return parent::uninstall()
|
||||||
Configuration::deleteByName(static::API_URL) &&
|
&& Configuration::deleteByName(static::API_URL)
|
||||||
Configuration::deleteByName(static::API_KEY) &&
|
&& Configuration::deleteByName(static::API_KEY)
|
||||||
Configuration::deleteByName(static::DELIVERY) &&
|
&& Configuration::deleteByName(static::DELIVERY)
|
||||||
Configuration::deleteByName(static::STATUS) &&
|
&& Configuration::deleteByName(static::STATUS)
|
||||||
Configuration::deleteByName(static::OUT_OF_STOCK_STATUS) &&
|
&& Configuration::deleteByName(static::OUT_OF_STOCK_STATUS)
|
||||||
Configuration::deleteByName(static::PAYMENT) &&
|
&& Configuration::deleteByName(static::PAYMENT)
|
||||||
Configuration::deleteByName(static::DELIVERY_DEFAULT) &&
|
&& Configuration::deleteByName(static::DELIVERY_DEFAULT)
|
||||||
Configuration::deleteByName(static::PAYMENT_DEFAULT) &&
|
&& Configuration::deleteByName(static::PAYMENT_DEFAULT)
|
||||||
Configuration::deleteByName(static::STATUS_EXPORT) &&
|
&& Configuration::deleteByName(static::STATUS_EXPORT)
|
||||||
Configuration::deleteByName(static::CLIENT_ID) &&
|
&& Configuration::deleteByName(static::CLIENT_ID)
|
||||||
Configuration::deleteByName(static::COLLECTOR_ACTIVE) &&
|
&& Configuration::deleteByName(static::COLLECTOR_ACTIVE)
|
||||||
Configuration::deleteByName(static::COLLECTOR_KEY) &&
|
&& Configuration::deleteByName(static::COLLECTOR_KEY)
|
||||||
Configuration::deleteByName(static::SYNC_CARTS_ACTIVE) &&
|
&& Configuration::deleteByName(static::SYNC_CARTS_ACTIVE)
|
||||||
Configuration::deleteByName(static::SYNC_CARTS_STATUS) &&
|
&& Configuration::deleteByName(static::SYNC_CARTS_STATUS)
|
||||||
Configuration::deleteByName(static::SYNC_CARTS_DELAY) &&
|
&& Configuration::deleteByName(static::SYNC_CARTS_DELAY)
|
||||||
Configuration::deleteByName(static::UPLOAD_ORDERS) &&
|
&& Configuration::deleteByName(static::UPLOAD_ORDERS)
|
||||||
Configuration::deleteByName(static::MODULE_LIST_CACHE_CHECKSUM) &&
|
&& Configuration::deleteByName(static::MODULE_LIST_CACHE_CHECKSUM)
|
||||||
Configuration::deleteByName(static::ENABLE_CORPORATE_CLIENTS) &&
|
&& Configuration::deleteByName(static::ENABLE_CORPORATE_CLIENTS)
|
||||||
Configuration::deleteByName(static::ENABLE_HISTORY_UPLOADS) &&
|
&& Configuration::deleteByName(static::ENABLE_HISTORY_UPLOADS)
|
||||||
Configuration::deleteByName(static::ENABLE_BALANCES_RECEIVING) &&
|
&& Configuration::deleteByName(static::ENABLE_BALANCES_RECEIVING)
|
||||||
Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_SENDING) &&
|
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_SENDING)
|
||||||
Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_RECEIVING) &&
|
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_RECEIVING)
|
||||||
Configuration::deleteByName(static::ENABLE_DEBUG_MODE) &&
|
&& Configuration::deleteByName(static::ENABLE_DEBUG_MODE)
|
||||||
Configuration::deleteByName(static::ENABLE_WEB_JOBS) &&
|
&& Configuration::deleteByName(static::ENABLE_WEB_JOBS)
|
||||||
Configuration::deleteByName('RETAILCRM_LAST_SYNC') &&
|
&& Configuration::deleteByName('RETAILCRM_LAST_SYNC')
|
||||||
Configuration::deleteByName('RETAILCRM_LAST_ORDERS_SYNC') &&
|
&& Configuration::deleteByName('RETAILCRM_LAST_ORDERS_SYNC')
|
||||||
Configuration::deleteByName('RETAILCRM_LAST_CUSTOMERS_SYNC') &&
|
&& Configuration::deleteByName('RETAILCRM_LAST_CUSTOMERS_SYNC')
|
||||||
Configuration::deleteByName(RetailcrmJobManager::LAST_RUN_NAME) &&
|
&& Configuration::deleteByName(RetailcrmJobManager::LAST_RUN_NAME)
|
||||||
Configuration::deleteByName(RetailcrmJobManager::LAST_RUN_DETAIL_NAME) &&
|
&& Configuration::deleteByName(RetailcrmJobManager::LAST_RUN_DETAIL_NAME)
|
||||||
Configuration::deleteByName(RetailcrmCatalogHelper::ICML_INFO_NAME) &&
|
&& Configuration::deleteByName(RetailcrmCatalogHelper::ICML_INFO_NAME)
|
||||||
Configuration::deleteByName(RetailcrmJobManager::IN_PROGRESS_NAME) &&
|
&& Configuration::deleteByName(RetailcrmJobManager::IN_PROGRESS_NAME)
|
||||||
Configuration::deleteByName(RetailcrmJobManager::CURRENT_TASK) &&
|
&& Configuration::deleteByName(RetailcrmJobManager::CURRENT_TASK)
|
||||||
Configuration::deleteByName(RetailcrmCli::CURRENT_TASK_CLI) &&
|
&& Configuration::deleteByName(RetailcrmCli::CURRENT_TASK_CLI)
|
||||||
$this->uninstallDB();
|
&& $this->uninstallDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function installDB()
|
public function installDB()
|
||||||
{
|
{
|
||||||
return Db::getInstance()->execute(
|
return Db::getInstance()->execute(
|
||||||
'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'retailcrm_abandonedcarts` (
|
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'retailcrm_abandonedcarts` (
|
||||||
`id_cart` INT UNSIGNED UNIQUE NOT NULL,
|
`id_cart` INT UNSIGNED UNIQUE NOT NULL,
|
||||||
`last_uploaded` DATETIME,
|
`last_uploaded` DATETIME,
|
||||||
FOREIGN KEY (id_cart) REFERENCES '._DB_PREFIX_.'cart (id_cart)
|
FOREIGN KEY (id_cart) REFERENCES ' . _DB_PREFIX_ . 'cart (id_cart)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
ON UPDATE CASCADE
|
ON UPDATE CASCADE
|
||||||
) DEFAULT CHARSET=utf8;'
|
) DEFAULT CHARSET=utf8;'
|
||||||
@ -277,7 +276,7 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
public function uninstallDB()
|
public function uninstallDB()
|
||||||
{
|
{
|
||||||
return Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'retailcrm_abandonedcarts`;');
|
return Db::getInstance()->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'retailcrm_abandonedcarts`;');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent()
|
public function getContent()
|
||||||
@ -288,13 +287,13 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
if (Tools::isSubmit('submit' . $this->name)) {
|
if (Tools::isSubmit('submit' . $this->name)) {
|
||||||
// todo all those vars & ifs to one $command var and check in switch
|
// todo all those vars & ifs to one $command var and check in switch
|
||||||
$jobName = (string)(Tools::getValue(static::RUN_JOB));
|
$jobName = (string) (Tools::getValue(static::RUN_JOB));
|
||||||
$ordersIds = (string)(Tools::getValue(static::UPLOAD_ORDERS));
|
$ordersIds = (string) (Tools::getValue(static::UPLOAD_ORDERS));
|
||||||
$exportOrders = (int)(Tools::getValue(static::EXPORT_ORDERS));
|
$exportOrders = (int) (Tools::getValue(static::EXPORT_ORDERS));
|
||||||
$exportCustomers = (int)(Tools::getValue(static::EXPORT_CUSTOMERS));
|
$exportCustomers = (int) (Tools::getValue(static::EXPORT_CUSTOMERS));
|
||||||
$updateSinceId = (bool)(Tools::getValue(static::UPDATE_SINCE_ID));
|
$updateSinceId = (bool) (Tools::getValue(static::UPDATE_SINCE_ID));
|
||||||
$downloadLogs = (bool)(Tools::getValue(static::DOWNLOAD_LOGS));
|
$downloadLogs = (bool) (Tools::getValue(static::DOWNLOAD_LOGS));
|
||||||
$resetJobs = (bool)(Tools::getValue(static::RESET_JOBS));
|
$resetJobs = (bool) (Tools::getValue(static::RESET_JOBS));
|
||||||
|
|
||||||
if (!empty($ordersIds)) {
|
if (!empty($ordersIds)) {
|
||||||
$output .= $this->uploadOrders(RetailcrmTools::partitionId($ordersIds));
|
$output .= $this->uploadOrders(RetailcrmTools::partitionId($ordersIds));
|
||||||
@ -329,17 +328,18 @@ class RetailCRM extends Module
|
|||||||
->setWarnings($this->getWarningMessage())
|
->setWarnings($this->getWarningMessage())
|
||||||
->setInformations($this->getInformationMessages())
|
->setInformations($this->getInformationMessages())
|
||||||
->setConfirmations($this->getConfirmationMessages())
|
->setConfirmations($this->getConfirmationMessages())
|
||||||
->render(__FILE__);
|
->render(__FILE__)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function uploadOrders($orderIds)
|
public function uploadOrders($orderIds)
|
||||||
{
|
{
|
||||||
if (count($orderIds) > 10) {
|
if (10 < count($orderIds)) {
|
||||||
return $this->displayError($this->l("Can't upload more than 10 orders per request"));
|
return $this->displayError($this->l("Can't upload more than 10 orders per request"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($orderIds) < 1) {
|
if (1 > count($orderIds)) {
|
||||||
return $this->displayError($this->l("At least one order ID should be specified"));
|
return $this->displayError($this->l('At least one order ID should be specified'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!($this->api instanceof RetailcrmProxy)) {
|
if (!($this->api instanceof RetailcrmProxy)) {
|
||||||
@ -354,7 +354,7 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
$result = '';
|
$result = '';
|
||||||
$isSuccessful = true;
|
$isSuccessful = true;
|
||||||
$skippedOrders = array();
|
$skippedOrders = [];
|
||||||
RetailcrmExport::$api = $this->api;
|
RetailcrmExport::$api = $this->api;
|
||||||
$receiveOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING));
|
$receiveOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING));
|
||||||
|
|
||||||
@ -398,6 +398,7 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $jobName
|
* @param string $jobName
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function runJob($jobName)
|
public function runJob($jobName)
|
||||||
@ -430,12 +431,13 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
public function runJobMultistore($jobName)
|
public function runJobMultistore($jobName)
|
||||||
{
|
{
|
||||||
RetailcrmContextSwitcher::runInContext(array($this, 'runJob'), array($jobName));
|
RetailcrmContextSwitcher::runInContext([$this, 'runJob'], [$jobName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $step
|
* @param int $step
|
||||||
* @param string $entity
|
* @param string $entity
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function export($step, $entity = 'order')
|
public function export($step, $entity = 'order')
|
||||||
@ -444,8 +446,8 @@ class RetailCRM extends Module
|
|||||||
return RetailcrmJsonResponse::invalidResponse('This method allow only in ajax mode');
|
return RetailcrmJsonResponse::invalidResponse('This method allow only in ajax mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
$step--;
|
--$step;
|
||||||
if ($step < 0) {
|
if (0 > $step) {
|
||||||
return RetailcrmJsonResponse::invalidResponse('Invalid request data');
|
return RetailcrmJsonResponse::invalidResponse('Invalid request data');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,13 +460,13 @@ class RetailCRM extends Module
|
|||||||
RetailcrmExport::init();
|
RetailcrmExport::init();
|
||||||
RetailcrmExport::$api = $api;
|
RetailcrmExport::$api = $api;
|
||||||
|
|
||||||
if ($entity === 'order') {
|
if ('order' === $entity) {
|
||||||
$stepSize = RetailcrmExport::RETAILCRM_EXPORT_ORDERS_STEP_SIZE_WEB;
|
$stepSize = RetailcrmExport::RETAILCRM_EXPORT_ORDERS_STEP_SIZE_WEB;
|
||||||
|
|
||||||
RetailcrmExport::$ordersOffset = $stepSize;
|
RetailcrmExport::$ordersOffset = $stepSize;
|
||||||
RetailcrmExport::exportOrders($step * $stepSize, $stepSize);
|
RetailcrmExport::exportOrders($step * $stepSize, $stepSize);
|
||||||
// todo maybe save current step to database
|
// todo maybe save current step to database
|
||||||
} elseif ($entity === 'customer') {
|
} elseif ('customer' === $entity) {
|
||||||
$stepSize = RetailcrmExport::RETAILCRM_EXPORT_CUSTOMERS_STEP_SIZE_WEB;
|
$stepSize = RetailcrmExport::RETAILCRM_EXPORT_CUSTOMERS_STEP_SIZE_WEB;
|
||||||
|
|
||||||
RetailcrmExport::$customersOffset = $stepSize;
|
RetailcrmExport::$customersOffset = $stepSize;
|
||||||
@ -500,7 +502,7 @@ class RetailCRM extends Module
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = (string)(Tools::getValue(static::DOWNLOAD_LOGS_NAME));
|
$name = (string) (Tools::getValue(static::DOWNLOAD_LOGS_NAME));
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
if (false === ($filePath = RetailcrmLogger::checkFileName($name))) {
|
if (false === ($filePath = RetailcrmLogger::checkFileName($name))) {
|
||||||
return false;
|
return false;
|
||||||
@ -541,7 +543,7 @@ class RetailCRM extends Module
|
|||||||
*/
|
*/
|
||||||
public function resetJobs()
|
public function resetJobs()
|
||||||
{
|
{
|
||||||
$errors = array();
|
$errors = [];
|
||||||
try {
|
try {
|
||||||
if (!RetailcrmJobManager::reset()) {
|
if (!RetailcrmJobManager::reset()) {
|
||||||
$errors[] = 'Job manager internal state was NOT cleared.';
|
$errors[] = 'Job manager internal state was NOT cleared.';
|
||||||
@ -595,7 +597,7 @@ class RetailCRM extends Module
|
|||||||
$addressBuilder = new RetailcrmAddressBuilder();
|
$addressBuilder = new RetailcrmAddressBuilder();
|
||||||
|
|
||||||
/** @var Address|\AddressCore|array $address */
|
/** @var Address|\AddressCore|array $address */
|
||||||
$address = array();
|
$address = [];
|
||||||
|
|
||||||
if (isset($customerSend['externalId'])) {
|
if (isset($customerSend['externalId'])) {
|
||||||
$customerData = $this->api->customersGet($customerSend['externalId']);
|
$customerData = $this->api->customersGet($customerSend['externalId']);
|
||||||
@ -640,7 +642,8 @@ class RetailCRM extends Module
|
|||||||
$addressBuilder
|
$addressBuilder
|
||||||
->setMode(RetailcrmAddressBuilder::MODE_ORDER_DELIVERY)
|
->setMode(RetailcrmAddressBuilder::MODE_ORDER_DELIVERY)
|
||||||
->setAddressId($cart->id_address_invoice)
|
->setAddressId($cart->id_address_invoice)
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
$customerSend = RetailcrmTools::mergeCustomerAddress($customerSend, $addressBuilder->getDataArray());
|
$customerSend = RetailcrmTools::mergeCustomerAddress($customerSend, $addressBuilder->getDataArray());
|
||||||
@ -658,7 +661,7 @@ class RetailCRM extends Module
|
|||||||
public function hookActionValidateCustomerAddressForm($params)
|
public function hookActionValidateCustomerAddressForm($params)
|
||||||
{
|
{
|
||||||
$customer = new Customer($params['cart']->id_customer);
|
$customer = new Customer($params['cart']->id_customer);
|
||||||
$customerAddress = array('customer' => $customer, 'cart' => $params['cart']);
|
$customerAddress = ['customer' => $customer, 'cart' => $params['cart']];
|
||||||
|
|
||||||
return $this->hookActionCustomerAccountUpdate($customerAddress);
|
return $this->hookActionCustomerAccountUpdate($customerAddress);
|
||||||
}
|
}
|
||||||
@ -733,7 +736,7 @@ class RetailCRM extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
$status = json_decode(Configuration::get(static::STATUS), true);
|
$status = json_decode(Configuration::get(static::STATUS), true);
|
||||||
$receiveOrderNumber = (bool)(Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING));
|
$receiveOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING));
|
||||||
|
|
||||||
if (isset($params['orderStatus'])) {
|
if (isset($params['orderStatus'])) {
|
||||||
try {
|
try {
|
||||||
@ -755,10 +758,10 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
if (isset($orderStatus)) {
|
if (isset($orderStatus)) {
|
||||||
$this->api->ordersEdit(
|
$this->api->ordersEdit(
|
||||||
array(
|
[
|
||||||
'externalId' => $params['id_order'],
|
'externalId' => $params['id_order'],
|
||||||
'status' => $orderStatus
|
'status' => $orderStatus,
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -791,7 +794,7 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
$response = $this->api->ordersGet(RetailcrmTools::getCartOrderExternalId($params['cart']));
|
$response = $this->api->ordersGet(RetailcrmTools::getCartOrderExternalId($params['cart']));
|
||||||
|
|
||||||
if ($response !== false && isset($response['order'])) {
|
if (false !== $response && isset($response['order'])) {
|
||||||
$externalId = RetailcrmTools::getCartOrderExternalId($params['cart']);
|
$externalId = RetailcrmTools::getCartOrderExternalId($params['cart']);
|
||||||
} else {
|
} else {
|
||||||
if (version_compare(_PS_VERSION_, '1.7.1.0', '>=')) {
|
if (version_compare(_PS_VERSION_, '1.7.1.0', '>=')) {
|
||||||
@ -800,7 +803,7 @@ class RetailCRM extends Module
|
|||||||
$id_order = (int) Order::getOrderByCartId((int) $params['cart']->id);
|
$id_order = (int) Order::getOrderByCartId((int) $params['cart']->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($id_order > 0) {
|
if (0 < $id_order) {
|
||||||
// do not update payment if the order in Cart and OrderPayment aren't the same
|
// do not update payment if the order in Cart and OrderPayment aren't the same
|
||||||
if ($params['paymentCC']->order_reference) {
|
if ($params['paymentCC']->order_reference) {
|
||||||
$order = Order::getByReference($params['paymentCC']->order_reference)->getFirst();
|
$order = Order::getByReference($params['paymentCC']->order_reference)->getFirst();
|
||||||
@ -810,17 +813,17 @@ class RetailCRM extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
$response = $this->api->ordersGet($id_order);
|
$response = $this->api->ordersGet($id_order);
|
||||||
if ($response !== false && isset($response['order'])) {
|
if (false !== $response && isset($response['order'])) {
|
||||||
$externalId = $id_order;
|
$externalId = $id_order;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($externalId === false) {
|
if (false === $externalId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = (round($params['paymentCC']->amount, 2) > 0 ? 'paid' : null);
|
$status = (0 < round($params['paymentCC']->amount, 2) ? 'paid' : null);
|
||||||
$orderCRM = $response['order'];
|
$orderCRM = $response['order'];
|
||||||
|
|
||||||
if ($orderCRM && $orderCRM['payments']) {
|
if ($orderCRM && $orderCRM['payments']) {
|
||||||
@ -837,16 +840,16 @@ class RetailCRM extends Module
|
|||||||
if (isset($updatePayment)) {
|
if (isset($updatePayment)) {
|
||||||
$this->api->ordersPaymentEdit($updatePayment, 'id');
|
$this->api->ordersPaymentEdit($updatePayment, 'id');
|
||||||
} else {
|
} else {
|
||||||
$createPayment = array(
|
$createPayment = [
|
||||||
'externalId' => $params['paymentCC']->id,
|
'externalId' => $params['paymentCC']->id,
|
||||||
'amount' => $params['paymentCC']->amount,
|
'amount' => $params['paymentCC']->amount,
|
||||||
'paidAt' => $params['paymentCC']->date_add,
|
'paidAt' => $params['paymentCC']->date_add,
|
||||||
'type' => $paymentType,
|
'type' => $paymentType,
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'order' => array(
|
'order' => [
|
||||||
'externalId' => $externalId,
|
'externalId' => $externalId,
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
$this->api->ordersPaymentCreate($createPayment);
|
$this->api->ordersPaymentCreate($createPayment);
|
||||||
}
|
}
|
||||||
@ -867,7 +870,7 @@ class RetailCRM extends Module
|
|||||||
$consultantCode = (string) Tools::getValue(static::CONSULTANT_SCRIPT);
|
$consultantCode = (string) Tools::getValue(static::CONSULTANT_SCRIPT);
|
||||||
|
|
||||||
if (!empty($url) && !empty($apiKey)) {
|
if (!empty($url) && !empty($apiKey)) {
|
||||||
$settings = array(
|
$settings = [
|
||||||
'url' => rtrim($url, '/'),
|
'url' => rtrim($url, '/'),
|
||||||
'apiKey' => $apiKey,
|
'apiKey' => $apiKey,
|
||||||
'address' => (string) (Tools::getValue(static::API_URL)),
|
'address' => (string) (Tools::getValue(static::API_URL)),
|
||||||
@ -878,24 +881,24 @@ class RetailCRM extends Module
|
|||||||
'deliveryDefault' => json_encode(Tools::getValue(static::DELIVERY_DEFAULT)),
|
'deliveryDefault' => json_encode(Tools::getValue(static::DELIVERY_DEFAULT)),
|
||||||
'paymentDefault' => json_encode(Tools::getValue(static::PAYMENT_DEFAULT)),
|
'paymentDefault' => json_encode(Tools::getValue(static::PAYMENT_DEFAULT)),
|
||||||
'statusExport' => (string) (Tools::getValue(static::STATUS_EXPORT)),
|
'statusExport' => (string) (Tools::getValue(static::STATUS_EXPORT)),
|
||||||
'enableCorporate' => (Tools::getValue(static::ENABLE_CORPORATE_CLIENTS) !== false),
|
'enableCorporate' => (false !== Tools::getValue(static::ENABLE_CORPORATE_CLIENTS)),
|
||||||
'enableHistoryUploads' => (Tools::getValue(static::ENABLE_HISTORY_UPLOADS) !== false),
|
'enableHistoryUploads' => (false !== Tools::getValue(static::ENABLE_HISTORY_UPLOADS)),
|
||||||
'enableBalancesReceiving' => (Tools::getValue(static::ENABLE_BALANCES_RECEIVING) !== false),
|
'enableBalancesReceiving' => (false !== Tools::getValue(static::ENABLE_BALANCES_RECEIVING)),
|
||||||
'enableOrderNumberSending' => (Tools::getValue(static::ENABLE_ORDER_NUMBER_SENDING) !== false),
|
'enableOrderNumberSending' => (false !== Tools::getValue(static::ENABLE_ORDER_NUMBER_SENDING)),
|
||||||
'enableOrderNumberReceiving' => (Tools::getValue(static::ENABLE_ORDER_NUMBER_RECEIVING) !== false),
|
'enableOrderNumberReceiving' => (false !== Tools::getValue(static::ENABLE_ORDER_NUMBER_RECEIVING)),
|
||||||
'debugMode' => (Tools::getValue(static::ENABLE_DEBUG_MODE) !== false),
|
'debugMode' => (false !== Tools::getValue(static::ENABLE_DEBUG_MODE)),
|
||||||
'webJobs' => (Tools::getValue(static::ENABLE_WEB_JOBS, true) !== false ? '1' : '0'),
|
'webJobs' => (false !== Tools::getValue(static::ENABLE_WEB_JOBS, true) ? '1' : '0'),
|
||||||
'collectorActive' => (Tools::getValue(static::COLLECTOR_ACTIVE) !== false),
|
'collectorActive' => (false !== Tools::getValue(static::COLLECTOR_ACTIVE)),
|
||||||
'collectorKey' => (string) (Tools::getValue(static::COLLECTOR_KEY)),
|
'collectorKey' => (string) (Tools::getValue(static::COLLECTOR_KEY)),
|
||||||
'clientId' => Configuration::get(static::CLIENT_ID),
|
'clientId' => Configuration::get(static::CLIENT_ID),
|
||||||
'synchronizeCartsActive' => (Tools::getValue(static::SYNC_CARTS_ACTIVE) !== false),
|
'synchronizeCartsActive' => (false !== Tools::getValue(static::SYNC_CARTS_ACTIVE)),
|
||||||
'synchronizedCartStatus' => (string) (Tools::getValue(static::SYNC_CARTS_STATUS)),
|
'synchronizedCartStatus' => (string) (Tools::getValue(static::SYNC_CARTS_STATUS)),
|
||||||
'synchronizedCartDelay' => (string) (Tools::getValue(static::SYNC_CARTS_DELAY))
|
'synchronizedCartDelay' => (string) (Tools::getValue(static::SYNC_CARTS_DELAY)),
|
||||||
);
|
];
|
||||||
|
|
||||||
$output .= $this->validateForm($settings, $output);
|
$output .= $this->validateForm($settings, $output);
|
||||||
|
|
||||||
if ($output === '') {
|
if ('' === $output) {
|
||||||
Configuration::updateValue(static::API_URL, $settings['url']);
|
Configuration::updateValue(static::API_URL, $settings['url']);
|
||||||
Configuration::updateValue(static::API_KEY, $settings['apiKey']);
|
Configuration::updateValue(static::API_KEY, $settings['apiKey']);
|
||||||
Configuration::updateValue(static::DELIVERY, $settings['delivery']);
|
Configuration::updateValue(static::DELIVERY, $settings['delivery']);
|
||||||
@ -926,7 +929,7 @@ class RetailCRM extends Module
|
|||||||
$this->api = new RetailcrmProxy($this->apiUrl, $this->apiKey, $this->log);
|
$this->api = new RetailcrmProxy($this->apiUrl, $this->apiKey, $this->log);
|
||||||
$this->reference = new RetailcrmReferences($this->api);
|
$this->reference = new RetailcrmReferences($this->api);
|
||||||
|
|
||||||
if ($this->isRegisteredInHook('actionPaymentCCAdd') == 0) {
|
if (0 == $this->isRegisteredInHook('actionPaymentCCAdd')) {
|
||||||
$this->registerHook('actionPaymentCCAdd');
|
$this->registerHook('actionPaymentCCAdd');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -955,9 +958,9 @@ class RetailCRM extends Module
|
|||||||
*
|
*
|
||||||
* @param \RetailcrmProxy $apiClient
|
* @param \RetailcrmProxy $apiClient
|
||||||
* @param string $clientId
|
* @param string $clientId
|
||||||
* @param boolean $active
|
* @param bool $active
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function integrationModule($apiClient, $clientId, $active = true)
|
private function integrationModule($apiClient, $clientId, $active = true)
|
||||||
{
|
{
|
||||||
@ -966,15 +969,15 @@ class RetailCRM extends Module
|
|||||||
$integrationCode = 'prestashop';
|
$integrationCode = 'prestashop';
|
||||||
$name = 'PrestaShop';
|
$name = 'PrestaShop';
|
||||||
$accountUrl = $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
$accountUrl = $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||||
$configuration = array(
|
$configuration = [
|
||||||
'clientId' => $clientId,
|
'clientId' => $clientId,
|
||||||
'code' => $integrationCode . '-' . $clientId,
|
'code' => $integrationCode . '-' . $clientId,
|
||||||
'integrationCode' => $integrationCode,
|
'integrationCode' => $integrationCode,
|
||||||
'active' => $active,
|
'active' => $active,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'logo' => $logo,
|
'logo' => $logo,
|
||||||
'accountUrl' => $accountUrl
|
'accountUrl' => $accountUrl,
|
||||||
);
|
];
|
||||||
$response = $apiClient->integrationModulesEdit($configuration);
|
$response = $apiClient->integrationModulesEdit($configuration);
|
||||||
|
|
||||||
if (!$response) {
|
if (!$response) {
|
||||||
@ -1006,7 +1009,7 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
$response = $api->apiVersions();
|
$response = $api->apiVersions();
|
||||||
|
|
||||||
if ($response !== false && isset($response['versions']) && !empty($response['versions'])) {
|
if (false !== $response && isset($response['versions']) && !empty($response['versions'])) {
|
||||||
foreach ($response['versions'] as $version) {
|
foreach ($response['versions'] as $version) {
|
||||||
if ($version == static::LATEST_API_VERSION
|
if ($version == static::LATEST_API_VERSION
|
||||||
|| Tools::substr($version, 0, 1) == static::LATEST_API_VERSION
|
|| Tools::substr($version, 0, 1) == static::LATEST_API_VERSION
|
||||||
@ -1042,7 +1045,7 @@ class RetailCRM extends Module
|
|||||||
*/
|
*/
|
||||||
private function validateCartStatus($statuses, $statusExport, $cartStatus)
|
private function validateCartStatus($statuses, $statusExport, $cartStatus)
|
||||||
{
|
{
|
||||||
if ($cartStatus != '' && ($cartStatus == $statusExport || stripos($statuses, $cartStatus))) {
|
if ('' != $cartStatus && ($cartStatus == $statusExport || stripos($statuses, $cartStatus))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1060,7 +1063,7 @@ class RetailCRM extends Module
|
|||||||
{
|
{
|
||||||
$data = json_decode($statuses, true);
|
$data = json_decode($statuses, true);
|
||||||
|
|
||||||
if (json_last_error() != JSON_ERROR_NONE || !is_array($data)) {
|
if (JSON_ERROR_NONE != json_last_error() || !is_array($data)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1075,29 +1078,29 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
public function validateStoredSettings()
|
public function validateStoredSettings()
|
||||||
{
|
{
|
||||||
$output = array();
|
$output = [];
|
||||||
$checkApiMethods = array(
|
$checkApiMethods = [
|
||||||
'delivery' => 'getApiDeliveryTypes',
|
'delivery' => 'getApiDeliveryTypes',
|
||||||
'statuses' => 'getApiStatuses',
|
'statuses' => 'getApiStatuses',
|
||||||
'payment' => 'getApiPaymentTypes',
|
'payment' => 'getApiPaymentTypes',
|
||||||
);
|
];
|
||||||
|
|
||||||
foreach (self::TABS_TO_VALIDATE as $tabName => $settingName) {
|
foreach (self::TABS_TO_VALIDATE as $tabName => $settingName) {
|
||||||
$storedValues = Tools::getIsset($settingName)
|
$storedValues = Tools::getIsset($settingName)
|
||||||
? Tools::getValue($settingName)
|
? Tools::getValue($settingName)
|
||||||
: json_decode(Configuration::get($settingName), true);
|
: json_decode(Configuration::get($settingName), true);
|
||||||
|
|
||||||
if ($storedValues !== false && $storedValues !== null) {
|
if (false !== $storedValues && null !== $storedValues) {
|
||||||
if (!$this->validateMappingSelected($storedValues)) {
|
if (!$this->validateMappingSelected($storedValues)) {
|
||||||
$output[] = $tabName;
|
$output[] = $tabName;
|
||||||
} else {
|
} else {
|
||||||
if (array_key_exists($tabName, $checkApiMethods)) {
|
if (array_key_exists($tabName, $checkApiMethods)) {
|
||||||
$crmValues = call_user_func(array($this->reference, $checkApiMethods[$tabName]));
|
$crmValues = call_user_func([$this->reference, $checkApiMethods[$tabName]]);
|
||||||
$crmCodes = array_column($crmValues, 'id_option');
|
$crmCodes = array_column($crmValues, 'id_option');
|
||||||
|
|
||||||
if (!empty(array_diff($storedValues, $crmCodes))) {
|
if (!empty(array_diff($storedValues, $crmCodes))) {
|
||||||
$output[] = $tabName;
|
$output[] = $tabName;
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1139,8 +1142,8 @@ class RetailCRM extends Module
|
|||||||
if (!$icmlInfo || !isset($icmlInfo['lastGenerated'])) {
|
if (!$icmlInfo || !isset($icmlInfo['lastGenerated'])) {
|
||||||
$urlConfiguredAt = RetailcrmTools::getConfigurationCreatedAtByName(self::API_KEY);
|
$urlConfiguredAt = RetailcrmTools::getConfigurationCreatedAtByName(self::API_KEY);
|
||||||
|
|
||||||
if ($urlConfiguredAt instanceof DateTime) {
|
if ($urlConfiguredAt instanceof DateTimeImmutable) {
|
||||||
$now = new DateTime();
|
$now = new DateTimeImmutable();
|
||||||
/** @var DateInterval $diff */
|
/** @var DateInterval $diff */
|
||||||
$diff = $urlConfiguredAt->diff($now);
|
$diff = $urlConfiguredAt->diff($now);
|
||||||
|
|
||||||
@ -1148,7 +1151,7 @@ class RetailCRM extends Module
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($icmlInfo['isOutdated'] || (isset($icmlInfo['isUrlActual']) && $icmlInfo['isUrlActual'] === false)) {
|
} elseif ($icmlInfo['isOutdated'] || !$icmlInfo['isUrlActual']) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1162,7 +1165,7 @@ class RetailCRM extends Module
|
|||||||
*/
|
*/
|
||||||
private function validateCatalogMultistore()
|
private function validateCatalogMultistore()
|
||||||
{
|
{
|
||||||
$results = RetailcrmContextSwitcher::runInContext(array($this, 'validateCatalog'));
|
$results = RetailcrmContextSwitcher::runInContext([$this, 'validateCatalog']);
|
||||||
$results = array_filter($results, function ($item) {
|
$results = array_filter($results, function ($item) {
|
||||||
return !$item;
|
return !$item;
|
||||||
});
|
});
|
||||||
@ -1182,7 +1185,7 @@ class RetailCRM extends Module
|
|||||||
{
|
{
|
||||||
if (!RetailcrmTools::validateCrmAddress($settings['url']) || !Validate::isGenericName($settings['url'])) {
|
if (!RetailcrmTools::validateCrmAddress($settings['url']) || !Validate::isGenericName($settings['url'])) {
|
||||||
$output .= $this->displayError($this->l('Invalid or empty crm address'));
|
$output .= $this->displayError($this->l('Invalid or empty crm address'));
|
||||||
} elseif (!$settings['apiKey'] || $settings['apiKey'] == '') {
|
} elseif (!$settings['apiKey'] || '' == $settings['apiKey']) {
|
||||||
$output .= $this->displayError($this->l('Invalid or empty crm api token'));
|
$output .= $this->displayError($this->l('Invalid or empty crm api token'));
|
||||||
} elseif (!$this->validateApiVersion($settings)) {
|
} elseif (!$this->validateApiVersion($settings)) {
|
||||||
$output .= $this->displayError($this->l('The selected version of the API is unavailable'));
|
$output .= $this->displayError($this->l('The selected version of the API is unavailable'));
|
||||||
@ -1234,7 +1237,7 @@ class RetailCRM extends Module
|
|||||||
private static function requireModulesCache()
|
private static function requireModulesCache()
|
||||||
{
|
{
|
||||||
if (file_exists(static::getModulesCache())) {
|
if (file_exists(static::getModulesCache())) {
|
||||||
return require_once(static::getModulesCache());
|
return require_once static::getModulesCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1257,7 +1260,7 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
$cacheDir = _PS_ROOT_DIR_ . '/cache';
|
$cacheDir = _PS_ROOT_DIR_ . '/cache';
|
||||||
|
|
||||||
if (realpath($cacheDir) !== false && is_dir($cacheDir)) {
|
if (false !== realpath($cacheDir) && is_dir($cacheDir)) {
|
||||||
return $cacheDir . '/retailcrm_modules_cache.php';
|
return $cacheDir . '/retailcrm_modules_cache.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1274,35 +1277,35 @@ class RetailCRM extends Module
|
|||||||
$syncCartsDelay = (string) (Configuration::get(static::SYNC_CARTS_DELAY));
|
$syncCartsDelay = (string) (Configuration::get(static::SYNC_CARTS_DELAY));
|
||||||
|
|
||||||
// Use 15 minutes as default interval but don't change immediate interval to it if user already made decision
|
// Use 15 minutes as default interval but don't change immediate interval to it if user already made decision
|
||||||
if (empty($syncCartsDelay) && $syncCartsDelay !== "0") {
|
if (empty($syncCartsDelay) && '0' !== $syncCartsDelay) {
|
||||||
$syncCartsDelay = "900";
|
$syncCartsDelay = '900';
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
'url' => (string)(Configuration::get(static::API_URL)),
|
'url' => (string) (Configuration::get(static::API_URL)),
|
||||||
'apiKey' => (string)(Configuration::get(static::API_KEY)),
|
'apiKey' => (string) (Configuration::get(static::API_KEY)),
|
||||||
'delivery' => json_decode(Configuration::get(static::DELIVERY), true),
|
'delivery' => json_decode(Configuration::get(static::DELIVERY), true),
|
||||||
'status' => json_decode(Configuration::get(static::STATUS), true),
|
'status' => json_decode(Configuration::get(static::STATUS), true),
|
||||||
'outOfStockStatus' => json_decode(Configuration::get(static::OUT_OF_STOCK_STATUS), true),
|
'outOfStockStatus' => json_decode(Configuration::get(static::OUT_OF_STOCK_STATUS), true),
|
||||||
'payment' => json_decode(Configuration::get(static::PAYMENT), true),
|
'payment' => json_decode(Configuration::get(static::PAYMENT), true),
|
||||||
'deliveryDefault' => json_decode(Configuration::get(static::DELIVERY_DEFAULT), true),
|
'deliveryDefault' => json_decode(Configuration::get(static::DELIVERY_DEFAULT), true),
|
||||||
'paymentDefault' => json_decode(Configuration::get(static::PAYMENT_DEFAULT), true),
|
'paymentDefault' => json_decode(Configuration::get(static::PAYMENT_DEFAULT), true),
|
||||||
'statusExport' => (string)(Configuration::get(static::STATUS_EXPORT)),
|
'statusExport' => (string) (Configuration::get(static::STATUS_EXPORT)),
|
||||||
'collectorActive' => (Configuration::get(static::COLLECTOR_ACTIVE)),
|
'collectorActive' => (Configuration::get(static::COLLECTOR_ACTIVE)),
|
||||||
'collectorKey' => (string)(Configuration::get(static::COLLECTOR_KEY)),
|
'collectorKey' => (string) (Configuration::get(static::COLLECTOR_KEY)),
|
||||||
'clientId' => Configuration::get(static::CLIENT_ID),
|
'clientId' => Configuration::get(static::CLIENT_ID),
|
||||||
'synchronizeCartsActive' => (Configuration::get(static::SYNC_CARTS_ACTIVE)),
|
'synchronizeCartsActive' => (Configuration::get(static::SYNC_CARTS_ACTIVE)),
|
||||||
'synchronizedCartStatus' => (string)(Configuration::get(static::SYNC_CARTS_STATUS)),
|
'synchronizedCartStatus' => (string) (Configuration::get(static::SYNC_CARTS_STATUS)),
|
||||||
'synchronizedCartDelay' => $syncCartsDelay,
|
'synchronizedCartDelay' => $syncCartsDelay,
|
||||||
'consultantScript' => (string)(Configuration::get(static::CONSULTANT_SCRIPT)),
|
'consultantScript' => (string) (Configuration::get(static::CONSULTANT_SCRIPT)),
|
||||||
'enableCorporate' => (bool)(Configuration::get(static::ENABLE_CORPORATE_CLIENTS)),
|
'enableCorporate' => (bool) (Configuration::get(static::ENABLE_CORPORATE_CLIENTS)),
|
||||||
'enableHistoryUploads' => (bool)(Configuration::get(static::ENABLE_HISTORY_UPLOADS)),
|
'enableHistoryUploads' => (bool) (Configuration::get(static::ENABLE_HISTORY_UPLOADS)),
|
||||||
'enableBalancesReceiving' => (bool)(Configuration::get(static::ENABLE_BALANCES_RECEIVING)),
|
'enableBalancesReceiving' => (bool) (Configuration::get(static::ENABLE_BALANCES_RECEIVING)),
|
||||||
'enableOrderNumberSending' => (bool)(Configuration::get(static::ENABLE_ORDER_NUMBER_SENDING)),
|
'enableOrderNumberSending' => (bool) (Configuration::get(static::ENABLE_ORDER_NUMBER_SENDING)),
|
||||||
'enableOrderNumberReceiving' => (bool)(Configuration::get(static::ENABLE_ORDER_NUMBER_RECEIVING)),
|
'enableOrderNumberReceiving' => (bool) (Configuration::get(static::ENABLE_ORDER_NUMBER_RECEIVING)),
|
||||||
'debugMode' => RetailcrmTools::isDebug(),
|
'debugMode' => RetailcrmTools::isDebug(),
|
||||||
'webJobs' => RetailcrmTools::isWebJobsEnabled()
|
'webJobs' => RetailcrmTools::isWebJobsEnabled(),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1312,7 +1315,7 @@ class RetailCRM extends Module
|
|||||||
*/
|
*/
|
||||||
public static function getSettingsNames()
|
public static function getSettingsNames()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'urlName' => static::API_URL,
|
'urlName' => static::API_URL,
|
||||||
'apiKeyName' => static::API_KEY,
|
'apiKeyName' => static::API_KEY,
|
||||||
'deliveryName' => static::DELIVERY,
|
'deliveryName' => static::DELIVERY,
|
||||||
@ -1338,8 +1341,8 @@ class RetailCRM extends Module
|
|||||||
'enableOrderNumberReceivingName' => static::ENABLE_ORDER_NUMBER_RECEIVING,
|
'enableOrderNumberReceivingName' => static::ENABLE_ORDER_NUMBER_RECEIVING,
|
||||||
'debugModeName' => static::ENABLE_DEBUG_MODE,
|
'debugModeName' => static::ENABLE_DEBUG_MODE,
|
||||||
'webJobsName' => static::ENABLE_WEB_JOBS,
|
'webJobsName' => static::ENABLE_WEB_JOBS,
|
||||||
'jobsNames' => static::JOBS_NAMES
|
'jobsNames' => static::JOBS_NAMES,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1354,7 +1357,7 @@ class RetailCRM extends Module
|
|||||||
$calculatedHash = md5(implode('#', Module::getModulesDirOnDisk(true)));
|
$calculatedHash = md5(implode('#', Module::getModulesDirOnDisk(true)));
|
||||||
|
|
||||||
if ($storedHash != $calculatedHash) {
|
if ($storedHash != $calculatedHash) {
|
||||||
$serializedModules = array();
|
$serializedModules = [];
|
||||||
static::$moduleListCache = Module::getModulesOnDisk(true);
|
static::$moduleListCache = Module::getModulesOnDisk(true);
|
||||||
|
|
||||||
foreach (static::$moduleListCache as $module) {
|
foreach (static::$moduleListCache as $module) {
|
||||||
@ -1373,13 +1376,13 @@ class RetailCRM extends Module
|
|||||||
|
|
||||||
$modulesList = static::requireModulesCache();
|
$modulesList = static::requireModulesCache();
|
||||||
|
|
||||||
if ($modulesList === false) {
|
if (false === $modulesList) {
|
||||||
Configuration::updateValue(static::MODULE_LIST_CACHE_CHECKSUM, 'not exist');
|
Configuration::updateValue(static::MODULE_LIST_CACHE_CHECKSUM, 'not exist');
|
||||||
|
|
||||||
return static::getCachedCmsModulesList();
|
return static::getCachedCmsModulesList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static::$moduleListCache = array();
|
static::$moduleListCache = [];
|
||||||
|
|
||||||
foreach ($modulesList as $serializedModule) {
|
foreach ($modulesList as $serializedModule) {
|
||||||
$deserialized = json_decode($serializedModule);
|
$deserialized = json_decode($serializedModule);
|
||||||
@ -1416,7 +1419,7 @@ class RetailCRM extends Module
|
|||||||
{
|
{
|
||||||
$file = fopen(static::getModulesCache(), 'w+');
|
$file = fopen(static::getModulesCache(), 'w+');
|
||||||
|
|
||||||
if ($file !== false) {
|
if (false !== $file) {
|
||||||
fwrite($file, '<?php' . PHP_EOL);
|
fwrite($file, '<?php' . PHP_EOL);
|
||||||
fwrite($file, '// Autogenerated module list cache for retailCRM' . PHP_EOL);
|
fwrite($file, '// Autogenerated module list cache for retailCRM' . PHP_EOL);
|
||||||
fwrite($file, '// Delete this file if you cannot see some payment types in module' . PHP_EOL);
|
fwrite($file, '// Delete this file if you cannot see some payment types in module' . PHP_EOL);
|
||||||
@ -1433,24 +1436,24 @@ class RetailCRM extends Module
|
|||||||
*/
|
*/
|
||||||
public function getSynchronizedCartsTimeSelect()
|
public function getSynchronizedCartsTimeSelect()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array(
|
[
|
||||||
'id_option' => '900',
|
'id_option' => '900',
|
||||||
'name' => $this->l('After 15 minutes')
|
'name' => $this->l('After 15 minutes'),
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'id_option' => '1800',
|
'id_option' => '1800',
|
||||||
'name' => $this->l('After 30 minutes')
|
'name' => $this->l('After 30 minutes'),
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'id_option' => '2700',
|
'id_option' => '2700',
|
||||||
'name' => $this->l('After 45 minute')
|
'name' => $this->l('After 45 minute'),
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'id_option' => '3600',
|
'id_option' => '3600',
|
||||||
'name' => $this->l('After 1 hour')
|
'name' => $this->l('After 1 hour'),
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1458,20 +1461,20 @@ class RetailCRM extends Module
|
|||||||
*/
|
*/
|
||||||
private function initializeTemplateMessages()
|
private function initializeTemplateMessages()
|
||||||
{
|
{
|
||||||
if (is_null($this->templateErrors)) {
|
if (null === $this->templateErrors) {
|
||||||
$this->templateErrors = array();
|
$this->templateErrors = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->templateWarnings)) {
|
if (null === $this->templateWarnings) {
|
||||||
$this->templateWarnings = array();
|
$this->templateWarnings = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->templateConfirms)) {
|
if (null === $this->templateConfirms) {
|
||||||
$this->templateConfirms = array();
|
$this->templateConfirms = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($this->templateErrors)) {
|
if (null === $this->templateErrors) {
|
||||||
$this->templateInfos = array();
|
$this->templateInfos = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1483,7 +1486,7 @@ class RetailCRM extends Module
|
|||||||
protected function getErrorMessages()
|
protected function getErrorMessages()
|
||||||
{
|
{
|
||||||
if (empty($this->templateErrors)) {
|
if (empty($this->templateErrors)) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->templateErrors;
|
return $this->templateErrors;
|
||||||
@ -1497,7 +1500,7 @@ class RetailCRM extends Module
|
|||||||
protected function getWarningMessage()
|
protected function getWarningMessage()
|
||||||
{
|
{
|
||||||
if (empty($this->templateWarnings)) {
|
if (empty($this->templateWarnings)) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->templateWarnings;
|
return $this->templateWarnings;
|
||||||
@ -1511,7 +1514,7 @@ class RetailCRM extends Module
|
|||||||
protected function getInformationMessages()
|
protected function getInformationMessages()
|
||||||
{
|
{
|
||||||
if (empty($this->templateInfos)) {
|
if (empty($this->templateInfos)) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->templateInfos;
|
return $this->templateInfos;
|
||||||
@ -1525,7 +1528,7 @@ class RetailCRM extends Module
|
|||||||
protected function getConfirmationMessages()
|
protected function getConfirmationMessages()
|
||||||
{
|
{
|
||||||
if (empty($this->templateConfirms)) {
|
if (empty($this->templateConfirms)) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->templateConfirms;
|
return $this->templateConfirms;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
global $_MODULE;
|
global $_MODULE;
|
||||||
$_MODULE = array();
|
$_MODULE = [];
|
||||||
$_MODULE['<{retailcrm}prestashop>retailcrm_9b1e2d4b35252401dbdab3cbad2735c4'] = 'Simla.com';
|
$_MODULE['<{retailcrm}prestashop>retailcrm_9b1e2d4b35252401dbdab3cbad2735c4'] = 'Simla.com';
|
||||||
$_MODULE['<{retailcrm}prestashop>retailcrm_5e36a81536959d8cde52246dd15a6fca'] = 'Módulo de integración para Simla.com';
|
$_MODULE['<{retailcrm}prestashop>retailcrm_5e36a81536959d8cde52246dd15a6fca'] = 'Módulo de integración para Simla.com';
|
||||||
$_MODULE['<{retailcrm}prestashop>retailcrm_876f23178c29dc2552c0b48bf23cd9bd'] = '¿Está seguro de que desea eliminar el módulo?';
|
$_MODULE['<{retailcrm}prestashop>retailcrm_876f23178c29dc2552c0b48bf23cd9bd'] = '¿Está seguro de que desea eliminar el módulo?';
|
||||||
|
@ -1 +1,3 @@
|
|||||||
<?php // Silence is golden
|
<?php
|
||||||
|
|
||||||
|
// Silence is golden
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
global $_MODULE;
|
global $_MODULE;
|
||||||
$_MODULE = array();
|
$_MODULE = [];
|
||||||
$_MODULE['<{retailcrm}prestashop>retailcrm_9b1e2d4b35252401dbdab3cbad2735c4'] = 'Simla.com';
|
$_MODULE['<{retailcrm}prestashop>retailcrm_9b1e2d4b35252401dbdab3cbad2735c4'] = 'Simla.com';
|
||||||
$_MODULE['<{retailcrm}prestashop>retailcrm_5e36a81536959d8cde52246dd15a6fca'] = 'Интеграционный модуль для Simla.com';
|
$_MODULE['<{retailcrm}prestashop>retailcrm_5e36a81536959d8cde52246dd15a6fca'] = 'Интеграционный модуль для Simla.com';
|
||||||
$_MODULE['<{retailcrm}prestashop>retailcrm_876f23178c29dc2552c0b48bf23cd9bd'] = 'Вы уверены, что хотите удалить модуль?';
|
$_MODULE['<{retailcrm}prestashop>retailcrm_876f23178c29dc2552c0b48bf23cd9bd'] = 'Вы уверены, что хотите удалить модуль?';
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('_PS_VERSION_')) {
|
if (!defined('_PS_VERSION_')) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -71,15 +70,15 @@ function upgrade_module_3_0_1($module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Immediate cart synchronization is not safe anymore (causes data inconsistency)
|
// Immediate cart synchronization is not safe anymore (causes data inconsistency)
|
||||||
if (Configuration::hasKey($syncCarts) && Configuration::get($syncCarts) == "0") {
|
if (Configuration::hasKey($syncCarts) && '0' == Configuration::get($syncCarts)) {
|
||||||
Configuration::set($syncCarts, "900");
|
Configuration::set($syncCarts, '900');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result && Db::getInstance()->execute(
|
return $result && Db::getInstance()->execute(
|
||||||
'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'retailcrm_abandonedcarts` (
|
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'retailcrm_abandonedcarts` (
|
||||||
`id_cart` INT UNSIGNED UNIQUE NOT NULL,
|
`id_cart` INT UNSIGNED UNIQUE NOT NULL,
|
||||||
`last_uploaded` DATETIME,
|
`last_uploaded` DATETIME,
|
||||||
FOREIGN KEY (id_cart) REFERENCES '._DB_PREFIX_.'cart (id_cart)
|
FOREIGN KEY (id_cart) REFERENCES ' . _DB_PREFIX_ . 'cart (id_cart)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
ON UPDATE CASCADE
|
ON UPDATE CASCADE
|
||||||
) DEFAULT CHARSET=utf8;'
|
) DEFAULT CHARSET=utf8;'
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('_PS_VERSION_')) {
|
if (!defined('_PS_VERSION_')) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('_PS_VERSION_')) {
|
if (!defined('_PS_VERSION_')) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -75,13 +74,13 @@ function retailcrm_upgrade_recursive_copy($src, $dst, $childFolder = '')
|
|||||||
mkdir($dst);
|
mkdir($dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($childFolder != '') {
|
if ('' != $childFolder) {
|
||||||
if (!file_exists($dst . '/' . $childFolder)) {
|
if (!file_exists($dst . '/' . $childFolder)) {
|
||||||
mkdir($dst . '/' . $childFolder);
|
mkdir($dst . '/' . $childFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (false !== ($file = readdir($dir))) {
|
while (false !== ($file = readdir($dir))) {
|
||||||
if (($file != '.') && ($file != '..')) {
|
if (('.' != $file) && ('..' != $file)) {
|
||||||
if (is_dir($src . '/' . $file)) {
|
if (is_dir($src . '/' . $file)) {
|
||||||
retailcrm_upgrade_recursive_copy($src . '/' . $file, $dst . '/' . $childFolder . '/' . $file);
|
retailcrm_upgrade_recursive_copy($src . '/' . $file, $dst . '/' . $childFolder . '/' . $file);
|
||||||
} else {
|
} else {
|
||||||
@ -91,7 +90,7 @@ function retailcrm_upgrade_recursive_copy($src, $dst, $childFolder = '')
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (false !== ($file = readdir($dir))) {
|
while (false !== ($file = readdir($dir))) {
|
||||||
if (($file != '.') && ($file != '..')) {
|
if (('.' != $file) && ('..' != $file)) {
|
||||||
if (is_dir($src . '/' . $file)) {
|
if (is_dir($src . '/' . $file)) {
|
||||||
retailcrm_upgrade_recursive_copy($src . '/' . $file, $dst . '/' . $file);
|
retailcrm_upgrade_recursive_copy($src . '/' . $file, $dst . '/' . $file);
|
||||||
} else {
|
} else {
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
* Don't forget to prefix your containers with your own identifier
|
* Don't forget to prefix your containers with your own identifier
|
||||||
* to avoid any conflicts with others containers.
|
* to avoid any conflicts with others containers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('_PS_VERSION_')) {
|
if (!defined('_PS_VERSION_')) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -114,8 +113,8 @@ function upgrade_module_3_3_2($module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$response->isSuccessful()
|
if (!$response->isSuccessful()
|
||||||
|| $response['siteAccess'] !== 'access_selective'
|
|| 'access_selective' !== $response['siteAccess']
|
||||||
|| count($response['sitesAvailable']) !== 1
|
|| 1 !== count($response['sitesAvailable'])
|
||||||
|| !in_array('/api/reference/sites', $response['credentials'])
|
|| !in_array('/api/reference/sites', $response['credentials'])
|
||||||
|| !in_array('/api/reference/sites/{code}/edit', $response['credentials'])
|
|| !in_array('/api/reference/sites/{code}/edit', $response['credentials'])
|
||||||
) {
|
) {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
||||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||||
header("Pragma: no-cache");
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||||
header("Location: ../");
|
header('Pragma: no-cache');
|
||||||
|
header('Location: ../');
|
||||||
exit;
|
exit;
|
||||||
|
@ -4,7 +4,7 @@ class RetailcrmCorporateCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
{
|
{
|
||||||
protected $corporateCustomer;
|
protected $corporateCustomer;
|
||||||
|
|
||||||
public function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
@ -15,7 +15,8 @@ class RetailcrmCorporateCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
|
|
||||||
$this->corporateCustomer
|
$this->corporateCustomer
|
||||||
->setDataCrm($this->getDataCrm())
|
->setDataCrm($this->getDataCrm())
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$result = new RetailcrmCustomerBuilderResult(null, null);
|
$result = new RetailcrmCustomerBuilderResult(null, null);
|
||||||
|
|
||||||
@ -28,7 +29,8 @@ class RetailcrmCorporateCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
|
|
||||||
$this->corporateCustomer
|
$this->corporateCustomer
|
||||||
->setDataCrm($this->getDataCrm())
|
->setDataCrm($this->getDataCrm())
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$builtCustomer = $this->corporateCustomer->getData()->getCustomer();
|
$builtCustomer = $this->corporateCustomer->getData()->getCustomer();
|
||||||
$builtAddress = $this->corporateCustomer->getData()->getCustomerAddress();
|
$builtAddress = $this->corporateCustomer->getData()->getCustomerAddress();
|
||||||
@ -49,12 +51,13 @@ class RetailcrmCorporateCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
->setCustomer($this->getDataBuilder())
|
->setCustomer($this->getDataBuilder())
|
||||||
->setCompanyName('Test')
|
->setCompanyName('Test')
|
||||||
->setCompanyInn(5666)
|
->setCompanyInn(5666)
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$customerResult = $this->corporateCustomer->getData()->getCustomer();
|
$customerResult = $this->corporateCustomer->getData()->getCustomer();
|
||||||
$this->assertEquals('April', $customerResult->firstname);
|
$this->assertEquals('April', $customerResult->firstname);
|
||||||
$this->assertEquals('Iphone', $customerResult->lastname);
|
$this->assertEquals('Iphone', $customerResult->lastname);
|
||||||
$this->assertEquals(false, $customerResult->newsletter);
|
$this->assertFalse($customerResult->newsletter);
|
||||||
$this->assertEquals('1997-04-09', $customerResult->birthday);
|
$this->assertEquals('1997-04-09', $customerResult->birthday);
|
||||||
$this->assertEquals(2, $customerResult->id_gender);
|
$this->assertEquals(2, $customerResult->id_gender);
|
||||||
$this->assertEquals('hello@world.ru', $customerResult->email);
|
$this->assertEquals('hello@world.ru', $customerResult->email);
|
||||||
@ -67,44 +70,46 @@ class RetailcrmCorporateCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
$this->assertEquals(5666, $addressResult->vat_number);
|
$this->assertEquals(5666, $addressResult->vat_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDataBuilder() {
|
private function getDataBuilder()
|
||||||
return array(
|
{
|
||||||
|
return [
|
||||||
'type' => 'customer_corporate',
|
'type' => 'customer_corporate',
|
||||||
'id' => 9090,
|
'id' => 9090,
|
||||||
'nickName' => 'TestName',
|
'nickName' => 'TestName',
|
||||||
'mainAddress' => array(
|
'mainAddress' => [
|
||||||
'id' => 4001,
|
'id' => 4001,
|
||||||
'name' => 'Test'
|
'name' => 'Test',
|
||||||
),
|
],
|
||||||
'createdAt' => '2020-02-17 07:44:31',
|
'createdAt' => '2020-02-17 07:44:31',
|
||||||
'vip' => false,
|
'vip' => false,
|
||||||
'bad' => false,
|
'bad' => false,
|
||||||
'site' => 'opencart',
|
'site' => 'opencart',
|
||||||
'tags' => array(),
|
'tags' => [],
|
||||||
'marginSumm' => 0,
|
'marginSumm' => 0,
|
||||||
'totalSumm' => 0,
|
'totalSumm' => 0,
|
||||||
'averageSumm' => 0,
|
'averageSumm' => 0,
|
||||||
'ordersCount' => 0,
|
'ordersCount' => 0,
|
||||||
'costSumm' => 0,
|
'costSumm' => 0,
|
||||||
'customFields' => array(),
|
'customFields' => [],
|
||||||
'personalDiscount' => 0,
|
'personalDiscount' => 0,
|
||||||
'mainCustomerContact' => array(
|
'mainCustomerContact' => [
|
||||||
'id' => 37,
|
'id' => 37,
|
||||||
'customer' => array(
|
'customer' => [
|
||||||
'id' => 9089
|
'id' => 9089,
|
||||||
),
|
],
|
||||||
'companies' => array()
|
'companies' => [],
|
||||||
),
|
],
|
||||||
'mainCompany' => array(
|
'mainCompany' => [
|
||||||
'id' => 34,
|
'id' => 34,
|
||||||
'name' => 'Test',
|
'name' => 'Test',
|
||||||
'contragentInn' => 5666
|
'contragentInn' => 5666,
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDataCrm() {
|
private function getDataCrm()
|
||||||
return array(
|
{
|
||||||
|
return [
|
||||||
'type' => 'customer',
|
'type' => 'customer',
|
||||||
'id' => 9000,
|
'id' => 9000,
|
||||||
'externalId' => '1777754',
|
'externalId' => '1777754',
|
||||||
@ -113,32 +118,32 @@ class RetailcrmCorporateCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
'vip' => true,
|
'vip' => true,
|
||||||
'bad' => true,
|
'bad' => true,
|
||||||
'site' => '127-0-0-1-8080',
|
'site' => '127-0-0-1-8080',
|
||||||
'contragent' => array(
|
'contragent' => [
|
||||||
'contragentType' => 'individual'
|
'contragentType' => 'individual',
|
||||||
),
|
],
|
||||||
'tags' => array(),
|
'subscribed' => false,
|
||||||
|
'tags' => [],
|
||||||
'marginSumm' => 0,
|
'marginSumm' => 0,
|
||||||
'totalSumm' => 0,
|
'totalSumm' => 0,
|
||||||
'averageSumm' => 0,
|
'averageSumm' => 0,
|
||||||
'ordersCount' => 0,
|
'ordersCount' => 0,
|
||||||
'costSumm' => 0,
|
'costSumm' => 0,
|
||||||
'customFields' => array(),
|
'customFields' => [],
|
||||||
'personalDiscount' => 0,
|
'personalDiscount' => 0,
|
||||||
'address' => array(
|
'address' => [
|
||||||
'id' => 9718,
|
'id' => 9718,
|
||||||
'countryIso' => 'RU',
|
'countryIso' => 'RU',
|
||||||
'region' => 'Moscow',
|
'region' => 'Moscow',
|
||||||
'city' => 'г. Москва',
|
'city' => 'г. Москва',
|
||||||
'index' => '344004',
|
'index' => '344004',
|
||||||
'text' => 'MAY'
|
'text' => 'MAY',
|
||||||
),
|
],
|
||||||
'segments' => array(),
|
'segments' => [],
|
||||||
'firstName' => 'April',
|
'firstName' => 'April',
|
||||||
'lastName' => 'Iphone',
|
'lastName' => 'Iphone',
|
||||||
'email' => 'hello@world.ru',
|
'email' => 'hello@world.ru',
|
||||||
'sex' => 'female',
|
'sex' => 'female',
|
||||||
'birthday' =>'1997-04-09'
|
'birthday' => '1997-04-09',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ class RetailcrmCustomerAddressBuilderTest extends RetailcrmTestCase
|
|||||||
protected $customerAddress;
|
protected $customerAddress;
|
||||||
protected $customer;
|
protected $customer;
|
||||||
|
|
||||||
public function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
@ -16,7 +16,8 @@ class RetailcrmCustomerAddressBuilderTest extends RetailcrmTestCase
|
|||||||
|
|
||||||
$this->customerAddress
|
$this->customerAddress
|
||||||
->setDataCrm($this->getDataBuilder())
|
->setDataCrm($this->getDataBuilder())
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$this->assertNotEmpty($this->customerAddress->getData());
|
$this->assertNotEmpty($this->customerAddress->getData());
|
||||||
}
|
}
|
||||||
@ -27,7 +28,8 @@ class RetailcrmCustomerAddressBuilderTest extends RetailcrmTestCase
|
|||||||
|
|
||||||
$this->customerAddress
|
$this->customerAddress
|
||||||
->setCustomerAddress(new AddressCore(9999))
|
->setCustomerAddress(new AddressCore(9999))
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$this->assertNotEmpty($this->customerAddress->getData());
|
$this->assertNotEmpty($this->customerAddress->getData());
|
||||||
}
|
}
|
||||||
@ -41,7 +43,8 @@ class RetailcrmCustomerAddressBuilderTest extends RetailcrmTestCase
|
|||||||
->setFirstName('Test')
|
->setFirstName('Test')
|
||||||
->setLastName('Test2')
|
->setLastName('Test2')
|
||||||
->setPhone('+7999999999')
|
->setPhone('+7999999999')
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$addressResult = $this->customerAddress->getData();
|
$addressResult = $this->customerAddress->getData();
|
||||||
$this->assertEquals('Test', $addressResult->firstname);
|
$this->assertEquals('Test', $addressResult->firstname);
|
||||||
@ -61,7 +64,8 @@ class RetailcrmCustomerAddressBuilderTest extends RetailcrmTestCase
|
|||||||
->setFirstName('Test')
|
->setFirstName('Test')
|
||||||
->setLastName('Test2')
|
->setLastName('Test2')
|
||||||
->setPhone('+7999999999')
|
->setPhone('+7999999999')
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
$addressResult = $this->customerAddress->getData();
|
$addressResult = $this->customerAddress->getData();
|
||||||
|
|
||||||
$this->customerAddress
|
$this->customerAddress
|
||||||
@ -69,7 +73,8 @@ class RetailcrmCustomerAddressBuilderTest extends RetailcrmTestCase
|
|||||||
->setDataCrm($this->getDataBuilderOverride())
|
->setDataCrm($this->getDataBuilderOverride())
|
||||||
->setFirstName('Test override')
|
->setFirstName('Test override')
|
||||||
->setPhone('+7111111111')
|
->setPhone('+7111111111')
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$addressResultOverridden = $this->customerAddress->getData();
|
$addressResultOverridden = $this->customerAddress->getData();
|
||||||
$this->assertEquals('Test override', $addressResultOverridden->firstname);
|
$this->assertEquals('Test override', $addressResultOverridden->firstname);
|
||||||
@ -81,24 +86,24 @@ class RetailcrmCustomerAddressBuilderTest extends RetailcrmTestCase
|
|||||||
$this->assertEquals('+7111111111', $addressResultOverridden->phone);
|
$this->assertEquals('+7111111111', $addressResultOverridden->phone);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDataBuilder() {
|
private function getDataBuilder()
|
||||||
return array(
|
{
|
||||||
|
return [
|
||||||
'id' => 9718,
|
'id' => 9718,
|
||||||
'countryIso' => 'RU',
|
'countryIso' => 'RU',
|
||||||
'region' => 'Moscow',
|
'region' => 'Moscow',
|
||||||
'city' => 'г. Москва',
|
'city' => 'г. Москва',
|
||||||
'index' => '344004',
|
'index' => '344004',
|
||||||
'text' => 'MAY'
|
'text' => 'MAY',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDataBuilderOverride()
|
private function getDataBuilderOverride()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'id' => 9718,
|
'id' => 9718,
|
||||||
'city' => 'г. Москва Override',
|
'city' => 'г. Москва Override',
|
||||||
'index' => '444444',
|
'index' => '444444',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ class RetailcrmCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
{
|
{
|
||||||
protected $customer;
|
protected $customer;
|
||||||
|
|
||||||
public function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
@ -15,7 +15,8 @@ class RetailcrmCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
|
|
||||||
$this->customer
|
$this->customer
|
||||||
->setDataCrm($this->getDataCrm())
|
->setDataCrm($this->getDataCrm())
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$result = new RetailcrmCustomerBuilderResult(null, null);
|
$result = new RetailcrmCustomerBuilderResult(null, null);
|
||||||
|
|
||||||
@ -28,7 +29,8 @@ class RetailcrmCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
|
|
||||||
$this->customer
|
$this->customer
|
||||||
->setCustomer(new Customer(9719))
|
->setCustomer(new Customer(9719))
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$this->assertNotEmpty($this->customer->getData());
|
$this->assertNotEmpty($this->customer->getData());
|
||||||
}
|
}
|
||||||
@ -39,7 +41,8 @@ class RetailcrmCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
|
|
||||||
$this->customer
|
$this->customer
|
||||||
->setDataCrm($this->getDataCrm())
|
->setDataCrm($this->getDataCrm())
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$builtCustomer = $this->customer->getData()->getCustomer();
|
$builtCustomer = $this->customer->getData()->getCustomer();
|
||||||
$builtAddress = $this->customer->getData()->getCustomerAddress();
|
$builtAddress = $this->customer->getData()->getCustomerAddress();
|
||||||
@ -57,7 +60,7 @@ class RetailcrmCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
|
|
||||||
$this->customer->buildAddress();
|
$this->customer->buildAddress();
|
||||||
|
|
||||||
$this->assertEquals(null, $this->customer->getData()->getCustomerAddress());
|
$this->assertNull($this->customer->getData()->getCustomerAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCorrectDataCustomer()
|
public function testCorrectDataCustomer()
|
||||||
@ -66,13 +69,14 @@ class RetailcrmCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
|
|
||||||
$this->customer
|
$this->customer
|
||||||
->setDataCrm($this->getDataCrm())
|
->setDataCrm($this->getDataCrm())
|
||||||
->build();
|
->build()
|
||||||
|
;
|
||||||
|
|
||||||
$customerResult = $this->customer->getData()->getCustomer();
|
$customerResult = $this->customer->getData()->getCustomer();
|
||||||
|
|
||||||
$this->assertEquals('April', $customerResult->firstname);
|
$this->assertEquals('April', $customerResult->firstname);
|
||||||
$this->assertEquals('Iphone', $customerResult->lastname);
|
$this->assertEquals('Iphone', $customerResult->lastname);
|
||||||
$this->assertEquals(false, $customerResult->newsletter);
|
$this->assertFalse($customerResult->newsletter);
|
||||||
$this->assertEquals('1997-04-09', $customerResult->birthday);
|
$this->assertEquals('1997-04-09', $customerResult->birthday);
|
||||||
$this->assertEquals(2, $customerResult->id_gender);
|
$this->assertEquals(2, $customerResult->id_gender);
|
||||||
$this->assertEquals('hello@world.ru', $customerResult->email);
|
$this->assertEquals('hello@world.ru', $customerResult->email);
|
||||||
@ -83,8 +87,9 @@ class RetailcrmCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
$this->assertEquals('г. Москва', $addressResult->city);
|
$this->assertEquals('г. Москва', $addressResult->city);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDataCrm() {
|
private function getDataCrm()
|
||||||
return array(
|
{
|
||||||
|
return [
|
||||||
'type' => 'customer',
|
'type' => 'customer',
|
||||||
'id' => 9000,
|
'id' => 9000,
|
||||||
'externalId' => '1777754',
|
'externalId' => '1777754',
|
||||||
@ -93,32 +98,32 @@ class RetailcrmCustomerBuilderTest extends RetailcrmTestCase
|
|||||||
'vip' => true,
|
'vip' => true,
|
||||||
'bad' => true,
|
'bad' => true,
|
||||||
'site' => '127-0-0-1-8080',
|
'site' => '127-0-0-1-8080',
|
||||||
'contragent' => array(
|
'contragent' => [
|
||||||
'contragentType' => 'individual'
|
'contragentType' => 'individual',
|
||||||
),
|
],
|
||||||
'tags' => array(),
|
'subscribed' => false,
|
||||||
|
'tags' => [],
|
||||||
'marginSumm' => 0,
|
'marginSumm' => 0,
|
||||||
'totalSumm' => 0,
|
'totalSumm' => 0,
|
||||||
'averageSumm' => 0,
|
'averageSumm' => 0,
|
||||||
'ordersCount' => 0,
|
'ordersCount' => 0,
|
||||||
'costSumm' => 0,
|
'costSumm' => 0,
|
||||||
'customFields' => array(),
|
'customFields' => [],
|
||||||
'personalDiscount' => 0,
|
'personalDiscount' => 0,
|
||||||
'address' => array(
|
'address' => [
|
||||||
'id' => 9718,
|
'id' => 9718,
|
||||||
'countryIso' => 'RU',
|
'countryIso' => 'RU',
|
||||||
'region' => 'Moscow',
|
'region' => 'Moscow',
|
||||||
'city' => 'г. Москва',
|
'city' => 'г. Москва',
|
||||||
'index' => '344004',
|
'index' => '344004',
|
||||||
'text' => 'MAY'
|
'text' => 'MAY',
|
||||||
),
|
],
|
||||||
'segments' => array(),
|
'segments' => [],
|
||||||
'firstName' => 'April',
|
'firstName' => 'April',
|
||||||
'lastName' => 'Iphone',
|
'lastName' => 'Iphone',
|
||||||
'email' => 'hello@world.ru',
|
'email' => 'hello@world.ru',
|
||||||
'sex' => 'female',
|
'sex' => 'female',
|
||||||
'birthday' =>'1997-04-09'
|
'birthday' => '1997-04-09',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class RetailcrmOrderBuilderTest extends RetailcrmTestCase
|
class RetailcrmOrderBuilderTest extends RetailcrmTestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
@ -39,22 +39,22 @@ class RetailcrmOrderBuilderTest extends RetailcrmTestCase
|
|||||||
*/
|
*/
|
||||||
private function getDataItemInitialPriceZero()
|
private function getDataItemInitialPriceZero()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'id' => 160,
|
'id' => 160,
|
||||||
'initialPrice' => 0,
|
'initialPrice' => 0,
|
||||||
'createdAt' => '2018-01-01 00:00:00',
|
'createdAt' => '2018-01-01 00:00:00',
|
||||||
'quantity' => 1,
|
'quantity' => 1,
|
||||||
'status' => 'new',
|
'status' => 'new',
|
||||||
'offer' => array(
|
'offer' => [
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'externalId' => 1,
|
'externalId' => 1,
|
||||||
'xmlId' => '1',
|
'xmlId' => '1',
|
||||||
'name' => 'Test name',
|
'name' => 'Test name',
|
||||||
'vatRate' => 'none'
|
'vatRate' => 'none',
|
||||||
),
|
],
|
||||||
'properties' => array(),
|
'properties' => [],
|
||||||
'purchasePrice' => 50
|
'purchasePrice' => 50,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,7 +62,7 @@ class RetailcrmOrderBuilderTest extends RetailcrmTestCase
|
|||||||
*/
|
*/
|
||||||
private function getDataOrder()
|
private function getDataOrder()
|
||||||
{
|
{
|
||||||
$order = array(
|
$order = [
|
||||||
'slug' => 1,
|
'slug' => 1,
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'number' => '1C',
|
'number' => '1C',
|
||||||
@ -81,38 +81,38 @@ class RetailcrmOrderBuilderTest extends RetailcrmTestCase
|
|||||||
'phone' => '80000000000',
|
'phone' => '80000000000',
|
||||||
'call' => false,
|
'call' => false,
|
||||||
'expired' => false,
|
'expired' => false,
|
||||||
'customer' => array(
|
'customer' => [
|
||||||
'segments' => array(),
|
'segments' => [],
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'externalId' => '777',
|
'externalId' => '777',
|
||||||
'type' => 'customer',
|
'type' => 'customer',
|
||||||
'firstName' => 'Test',
|
'firstName' => 'Test',
|
||||||
'lastName' => 'Test',
|
'lastName' => 'Test',
|
||||||
'email' => 'email@test.ru',
|
'email' => 'email@test.ru',
|
||||||
'phones' => array(
|
'phones' => [
|
||||||
array(
|
[
|
||||||
'number' => '111111111111111'
|
'number' => '111111111111111',
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'number' => '+7111111111'
|
'number' => '+7111111111',
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
'address' => array(
|
'address' => [
|
||||||
'id_customer' => 2222,
|
'id_customer' => 2222,
|
||||||
'index' => '111111',
|
'index' => '111111',
|
||||||
'countryIso' => 'RU',
|
'countryIso' => 'RU',
|
||||||
'region' => 'Test region',
|
'region' => 'Test region',
|
||||||
'city' => 'Test',
|
'city' => 'Test',
|
||||||
'text' => 'Test text address'
|
'text' => 'Test text address',
|
||||||
),
|
],
|
||||||
'createdAt' => '2018-01-01 00:00:00',
|
'createdAt' => '2018-01-01 00:00:00',
|
||||||
'managerId' => 1,
|
'managerId' => 1,
|
||||||
'vip' => false,
|
'vip' => false,
|
||||||
'bad' => false,
|
'bad' => false,
|
||||||
'site' => 'test-com',
|
'site' => 'test-com',
|
||||||
'contragent' => array(
|
'contragent' => [
|
||||||
'contragentType' => 'individual'
|
'contragentType' => 'individual',
|
||||||
),
|
],
|
||||||
'personalDiscount' => 0,
|
'personalDiscount' => 0,
|
||||||
'cumulativeDiscount' => 0,
|
'cumulativeDiscount' => 0,
|
||||||
'marginSumm' => 58654,
|
'marginSumm' => 58654,
|
||||||
@ -120,61 +120,60 @@ class RetailcrmOrderBuilderTest extends RetailcrmTestCase
|
|||||||
'averageSumm' => 15387.25,
|
'averageSumm' => 15387.25,
|
||||||
'ordersCount' => 4,
|
'ordersCount' => 4,
|
||||||
'costSumm' => 101,
|
'costSumm' => 101,
|
||||||
'customFields' => array(
|
'customFields' => [
|
||||||
'custom' => 'test'
|
'custom' => 'test',
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
'contragent' => array(),
|
'contragent' => [],
|
||||||
'delivery' => array(
|
'delivery' => [
|
||||||
'code' => 'delivery',
|
'code' => 'delivery',
|
||||||
'cost' => 100,
|
'cost' => 100,
|
||||||
'netCost' => 0,
|
'netCost' => 0,
|
||||||
'address' => array(
|
'address' => [
|
||||||
'id_customer' => 2222,
|
'id_customer' => 2222,
|
||||||
'index' => '111111',
|
'index' => '111111',
|
||||||
'countryIso' => 'RU',
|
'countryIso' => 'RU',
|
||||||
'region' => 'Test region',
|
'region' => 'Test region',
|
||||||
'city' => 'Test',
|
'city' => 'Test',
|
||||||
'text' => 'Test text address'
|
'text' => 'Test text address',
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
'site' => 'test-com',
|
'site' => 'test-com',
|
||||||
'status' => 'new',
|
'status' => 'new',
|
||||||
'items' => array(
|
'items' => [
|
||||||
array(
|
[
|
||||||
'id' => 160,
|
'id' => 160,
|
||||||
'initialPrice' => 100,
|
'initialPrice' => 100,
|
||||||
'createdAt' => '2018-01-01 00:00:00',
|
'createdAt' => '2018-01-01 00:00:00',
|
||||||
'quantity' => 1,
|
'quantity' => 1,
|
||||||
'status' => 'new',
|
'status' => 'new',
|
||||||
'offer' => array(
|
'offer' => [
|
||||||
'id' => 1,
|
'id' => 1,
|
||||||
'externalId' => 1,
|
'externalId' => 1,
|
||||||
'xmlId' => '1',
|
'xmlId' => '1',
|
||||||
'name' => 'Test name',
|
'name' => 'Test name',
|
||||||
'vatRate' => 'none'
|
'vatRate' => 'none',
|
||||||
),
|
],
|
||||||
'properties' => array(),
|
'properties' => [],
|
||||||
'purchasePrice' => 50
|
'purchasePrice' => 50,
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
'fromApi' => false,
|
'fromApi' => false,
|
||||||
'length' => 0,
|
'length' => 0,
|
||||||
'width' => 0,
|
'width' => 0,
|
||||||
'height' => 0,
|
'height' => 0,
|
||||||
'shipmentStore' => 'main',
|
'shipmentStore' => 'main',
|
||||||
'shipped' => false,
|
'shipped' => false,
|
||||||
'customFields' => array(),
|
'customFields' => [],
|
||||||
'uploadedToExternalStoreSystem' => false
|
'uploadedToExternalStoreSystem' => false,
|
||||||
);
|
];
|
||||||
|
|
||||||
$order['payments'][] = array(
|
$order['payments'][] = [
|
||||||
'id' => 97,
|
'id' => 97,
|
||||||
'type' => 'cheque',
|
'type' => 'cheque',
|
||||||
'amount' => 210
|
'amount' => 210,
|
||||||
);
|
];
|
||||||
|
|
||||||
return $order;
|
return $order;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
private $retailcrmModule;
|
private $retailcrmModule;
|
||||||
private $apiMock;
|
private $apiMock;
|
||||||
|
|
||||||
public function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
return $this->getMockBuilder('RetailcrmProxy')
|
return $this->getMockBuilder('RetailcrmProxy')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->setMethods(
|
->setMethods(
|
||||||
array(
|
[
|
||||||
'customersCreate',
|
'customersCreate',
|
||||||
'customersEdit',
|
'customersEdit',
|
||||||
'customersGet',
|
'customersGet',
|
||||||
@ -30,9 +30,10 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
'ordersEdit',
|
'ordersEdit',
|
||||||
'ordersGet',
|
'ordersGet',
|
||||||
'ordersPaymentEdit',
|
'ordersPaymentEdit',
|
||||||
'ordersPaymentCreate'
|
'ordersPaymentCreate',
|
||||||
)
|
]
|
||||||
);
|
)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUploadOrders()
|
public function testUploadOrders()
|
||||||
@ -44,19 +45,19 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
$updReference = 'test';
|
$updReference = 'test';
|
||||||
$this->apiMock->expects($this->any())->method('ordersGet')->willReturn(new RetailcrmApiResponse(
|
$this->apiMock->expects($this->any())->method('ordersGet')->willReturn(new RetailcrmApiResponse(
|
||||||
200,
|
200,
|
||||||
json_encode(array(
|
json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'order' => array(),
|
'order' => [],
|
||||||
))
|
])
|
||||||
));
|
));
|
||||||
$this->apiMock->expects($this->any())->method('ordersCreate')->willReturn(new RetailcrmApiResponse(
|
$this->apiMock->expects($this->any())->method('ordersCreate')->willReturn(new RetailcrmApiResponse(
|
||||||
200,
|
200,
|
||||||
json_encode(array(
|
json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'order' => array(
|
'order' => [
|
||||||
'number' => $updReference,
|
'number' => $updReference,
|
||||||
),
|
],
|
||||||
))
|
])
|
||||||
));
|
));
|
||||||
|
|
||||||
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING, false);
|
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING, false);
|
||||||
@ -75,7 +76,7 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
public function testHookActionCustomerAccountAdd()
|
public function testHookActionCustomerAccountAdd()
|
||||||
{
|
{
|
||||||
$newCustomer = new Customer(1);
|
$newCustomer = new Customer(1);
|
||||||
$params = array('newCustomer' => $newCustomer);
|
$params = ['newCustomer' => $newCustomer];
|
||||||
|
|
||||||
$this->assertTrue($this->retailcrmModule->hookActionCustomerAccountAdd($params));
|
$this->assertTrue($this->retailcrmModule->hookActionCustomerAccountAdd($params));
|
||||||
}
|
}
|
||||||
@ -83,7 +84,7 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
public function testHookActionCustomerAccountUpdate()
|
public function testHookActionCustomerAccountUpdate()
|
||||||
{
|
{
|
||||||
$customer = new Customer(1);
|
$customer = new Customer(1);
|
||||||
$params = array('customer' => $customer);
|
$params = ['customer' => $customer];
|
||||||
|
|
||||||
$this->assertTrue($this->retailcrmModule->hookActionCustomerAccountUpdate($params));
|
$this->assertTrue($this->retailcrmModule->hookActionCustomerAccountUpdate($params));
|
||||||
}
|
}
|
||||||
@ -92,29 +93,28 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
{
|
{
|
||||||
$order = new Order(1);
|
$order = new Order(1);
|
||||||
$customer = new Customer($order->id_customer);
|
$customer = new Customer($order->id_customer);
|
||||||
$params = array('order' => $order, 'customer' => $customer);
|
$params = ['order' => $order, 'customer' => $customer];
|
||||||
$reference = $order->reference;
|
$reference = $order->reference;
|
||||||
$updReference = 'test';
|
$updReference = 'test';
|
||||||
|
|
||||||
$this->apiMock->expects($this->any())->method('ordersGet')->willReturn(new RetailcrmApiResponse(
|
$this->apiMock->expects($this->any())->method('ordersGet')->willReturn(new RetailcrmApiResponse(
|
||||||
200,
|
200,
|
||||||
json_encode(array(
|
json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'order' => array()
|
'order' => [],
|
||||||
))
|
])
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->apiMock->expects($this->any())->method('ordersCreate')->willReturn(new RetailcrmApiResponse(
|
$this->apiMock->expects($this->any())->method('ordersCreate')->willReturn(new RetailcrmApiResponse(
|
||||||
200,
|
200,
|
||||||
json_encode(array(
|
json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'order' => array(
|
'order' => [
|
||||||
'number' => $updReference,
|
'number' => $updReference,
|
||||||
),
|
],
|
||||||
))
|
])
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING, false);
|
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING, false);
|
||||||
|
|
||||||
$this->assertTrue($this->retailcrmModule->hookActionOrderEdited($params));
|
$this->assertTrue($this->retailcrmModule->hookActionOrderEdited($params));
|
||||||
@ -141,40 +141,40 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
$reference = $order->reference;
|
$reference = $order->reference;
|
||||||
$updReference = 'test';
|
$updReference = 'test';
|
||||||
|
|
||||||
if ($newOrder === false) {
|
if (false === $newOrder) {
|
||||||
$status->id = 11;
|
$status->id = 11;
|
||||||
|
|
||||||
$params = array(
|
$params = [
|
||||||
'newOrderStatus' => $status,
|
'newOrderStatus' => $status,
|
||||||
'id_order' => $order->id
|
'id_order' => $order->id,
|
||||||
);
|
];
|
||||||
} else {
|
} else {
|
||||||
$status->id = 'new';
|
$status->id = 'new';
|
||||||
|
|
||||||
$params = array(
|
$params = [
|
||||||
'orderStatus' => $status,
|
'orderStatus' => $status,
|
||||||
'customer' => $customer,
|
'customer' => $customer,
|
||||||
'order' => $order,
|
'order' => $order,
|
||||||
'cart' => $cart,
|
'cart' => $cart,
|
||||||
);
|
];
|
||||||
|
|
||||||
$this->apiMock->expects($this->any())->method('ordersGet')->willReturn(new RetailcrmApiResponse(
|
$this->apiMock->expects($this->any())->method('ordersGet')->willReturn(new RetailcrmApiResponse(
|
||||||
200,
|
200,
|
||||||
json_encode(array(
|
json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'order' => array()
|
'order' => [],
|
||||||
))
|
])
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->apiMock->expects($this->any())->method('ordersCreate')->willReturn(new RetailcrmApiResponse(
|
$this->apiMock->expects($this->any())->method('ordersCreate')->willReturn(new RetailcrmApiResponse(
|
||||||
200,
|
200,
|
||||||
json_encode(array(
|
json_encode([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'order' => array(
|
'order' => [
|
||||||
'number' => $updReference,
|
'number' => $updReference,
|
||||||
),
|
],
|
||||||
))
|
])
|
||||||
));
|
));
|
||||||
|
|
||||||
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING, false);
|
Configuration::updateValue(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING, false);
|
||||||
@ -199,10 +199,10 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
$orderPayment = RetailcrmTestHelper::createOrderPayment($order->reference);
|
$orderPayment = RetailcrmTestHelper::createOrderPayment($order->reference);
|
||||||
$cart = new Cart($order->id_cart);
|
$cart = new Cart($order->id_cart);
|
||||||
|
|
||||||
$params = array(
|
$params = [
|
||||||
'paymentCC' => $orderPayment,
|
'paymentCC' => $orderPayment,
|
||||||
'cart' => $cart
|
'cart' => $cart,
|
||||||
);
|
];
|
||||||
|
|
||||||
$referenceMock = $this->createMock('RetailcrmReferences');
|
$referenceMock = $this->createMock('RetailcrmReferences');
|
||||||
$referenceMock->expects($this->once())->method('getSystemPaymentModules')->willReturn($this->getSystemPaymentModules());
|
$referenceMock->expects($this->once())->method('getSystemPaymentModules')->willReturn($this->getSystemPaymentModules());
|
||||||
@ -222,14 +222,14 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
*/
|
*/
|
||||||
public function dataProvider()
|
public function dataProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array(
|
[
|
||||||
'newOrder' => true
|
'newOrder' => true,
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'newOrder' => false
|
'newOrder' => false,
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -237,34 +237,34 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
*/
|
*/
|
||||||
public function ordersGetDataProvider()
|
public function ordersGetDataProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array(
|
[
|
||||||
'ordersGet' => array(
|
'ordersGet' => [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'order' => array(
|
'order' => [
|
||||||
'payments' => array(
|
'payments' => [
|
||||||
array(
|
[
|
||||||
'type' => 'bankwire'
|
'type' => 'bankwire',
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
'totalSumm' => 1500
|
'totalSumm' => 1500,
|
||||||
)
|
],
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'ordersGet' => array(
|
'ordersGet' => [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'order' => array(
|
'order' => [
|
||||||
'payments' => array(
|
'payments' => [
|
||||||
array(
|
[
|
||||||
'type' => 'cheque'
|
'type' => 'cheque',
|
||||||
)
|
],
|
||||||
),
|
],
|
||||||
'totalSumm' => 1500
|
'totalSumm' => 1500,
|
||||||
)
|
],
|
||||||
)
|
],
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -272,26 +272,26 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
*/
|
*/
|
||||||
private function getProducts()
|
private function getProducts()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array(
|
[
|
||||||
'id_product_attribute' => 1,
|
'id_product_attribute' => 1,
|
||||||
'id_product' => 1,
|
'id_product' => 1,
|
||||||
'attributes' => '',
|
'attributes' => '',
|
||||||
'rate' => 1,
|
'rate' => 1,
|
||||||
'price' => 100,
|
'price' => 100,
|
||||||
'name' => 'Test product 1',
|
'name' => 'Test product 1',
|
||||||
'quantity' => 2
|
'quantity' => 2,
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'id_product_attribute' => 1,
|
'id_product_attribute' => 1,
|
||||||
'id_product' => 2,
|
'id_product' => 2,
|
||||||
'attributes' => '',
|
'attributes' => '',
|
||||||
'rate' => 1,
|
'rate' => 1,
|
||||||
'price' => 100,
|
'price' => 100,
|
||||||
'name' => 'Test product 2',
|
'name' => 'Test product 2',
|
||||||
'quantity' => 1
|
'quantity' => 1,
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -301,7 +301,7 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
{
|
{
|
||||||
$address = new Address(1);
|
$address = new Address(1);
|
||||||
|
|
||||||
return array($address);
|
return [$address];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -309,17 +309,17 @@ class RetailCRMTest extends RetailcrmTestCase
|
|||||||
*/
|
*/
|
||||||
private function getSystemPaymentModules()
|
private function getSystemPaymentModules()
|
||||||
{
|
{
|
||||||
return array (
|
return [
|
||||||
array (
|
[
|
||||||
'id' => '3',
|
'id' => '3',
|
||||||
'code' => 'bankwire',
|
'code' => 'bankwire',
|
||||||
'name' => 'Bank wire',
|
'name' => 'Bank wire',
|
||||||
),
|
],
|
||||||
array (
|
[
|
||||||
'id' => '30',
|
'id' => '30',
|
||||||
'code' => 'cheque',
|
'code' => 'cheque',
|
||||||
'name' => 'Payment by check',
|
'name' => 'Payment by check',
|
||||||
)
|
],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user