Unified address logic (#193)

This commit is contained in:
Pavel 2020-09-02 12:21:33 +03:00 committed by GitHub
parent 739c2775b5
commit 2dbccd8a02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 101 additions and 40 deletions

View File

@ -23,9 +23,9 @@ RUN wget -O /usr/bin/phpunit https://phar.phpunit.de/phpunit-7.phar && chmod +x
RUN curl --insecure https://getcomposer.org/download/1.9.3/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer RUN curl --insecure https://getcomposer.org/download/1.9.3/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
# Set timezone # Set timezone
RUN rm /etc/localtime RUN rm /etc/localtime && \
RUN ln -s /usr/share/zoneinfo/Europe/Moscow /etc/localtime ln -s /usr/share/zoneinfo/Europe/Moscow /etc/localtime && \
RUN "date" "date"
ARG TEST_SUITE ARG TEST_SUITE
ARG OPENCART ARG OPENCART
@ -51,6 +51,8 @@ ENV OC_EMAIL=${OC_EMAIL}
ADD .docker/entrypoint.sh /usr/local/bin/docker-php-entrypoint ADD .docker/entrypoint.sh /usr/local/bin/docker-php-entrypoint
RUN sed -i "s/80/$PORT/g" /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf RUN chmod +x /usr/local/bin/docker-php-entrypoint
RUN sed -i 's/var\/www\/html/opencart-module\/www/g' /etc/apache2/sites-enabled/000-default.conf
RUN sed -i 's/var\/www/opencart-module/g' /etc/apache2/apache2.conf RUN sed -i "s/80/$PORT/g" /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf && \
sed -i 's/var\/www\/html/opencart-module\/www/g' /etc/apache2/sites-enabled/000-default.conf && \
sed -i 's/var\/www/opencart-module/g' /etc/apache2/apache2.conf

View File

@ -8,8 +8,10 @@ done
make -C /opencart-module run make -C /opencart-module run
mkdir /opencart-module/www/system/storage/session mkdir -p /opencart-module/www/system/storage/session
sed -i 's/\?>//g' /opencart-module/www/config.php
sed -i 's/\?>//g' /opencart-module/www/admin/config.php
echo '\nini_set("session.save_path", DIR_SYSTEM . "storage/session");' >> /opencart-module/www/config.php echo '\nini_set("session.save_path", DIR_SYSTEM . "storage/session");' >> /opencart-module/www/config.php
echo '\nini_set("session.save_path", DIR_SYSTEM . "storage/session");' >> /opencart-module/www/admin/config.php echo '\nini_set("session.save_path", DIR_SYSTEM . "storage/session");' >> /opencart-module/www/admin/config.php

View File

@ -1,8 +1,8 @@
# OpenCart Database connection values # OpenCart Database connection values
OC_DB_HOSTNAME=host OC_DB_HOSTNAME=mysql
OC_DB_USERNAME=user OC_DB_USERNAME=opencart
OC_DB_PASSWORD=pass OC_DB_PASSWORD=opencart
OC_DB_DATABASE=database OC_DB_DATABASE=opencart
OC_DB_DRIVER=mysqli OC_DB_DRIVER=mysqli
# OpenCart Administration user # OpenCart Administration user
@ -14,5 +14,5 @@ OC_EMAIL=you@example.com
SERVER_PORT=8080 SERVER_PORT=8080
SERVER_URL=http://localhost SERVER_URL=http://localhost
TEST_SUITE= TEST_SUITE=3.0
OPENCART= OPENCART=3.0.2.0

View File

@ -1,3 +1,6 @@
## v.4.1.1
* Обновлена механика обработки адресов покупателей
## v.4.1.0 ## v.4.1.0
* Добавлена возможность подключения Online Consultant * Добавлена возможность подключения Online Consultant

View File

@ -38,7 +38,7 @@ cp -r opencart-module/* /path/to/site/root
На странице настроек модуля укажите URL retailCRM и ключ авторизации, после сохранения этих данных укажите соответствия справочников типов доставок, оплат и статусов заказа. На странице настроек модуля укажите URL retailCRM и ключ авторизации, после сохранения этих данных укажите соответствия справочников типов доставок, оплат и статусов заказа.
#### Получение измений из retailCRM #### Получение изменений из retailCRM
Для получения изменений и новых данных добавьте в cron следующую запись: Для получения изменений и новых данных добавьте в cron следующую запись:

View File

@ -1 +1 @@
4.1.0 4.1.1

View File

@ -31,6 +31,8 @@
"ext-json": "*" "ext-json": "*"
}, },
"require-dev": { "require-dev": {
"consolidation/robo": "~1.0" "consolidation/robo": "~1.0",
"beyondit/opencart-test-suite": "~3.0",
"opencart/opencart": "3.0.2.0"
} }
} }

View File

@ -163,12 +163,9 @@ class CorporateCustomer {
if ($address_response && $address_response->isSuccessful()) { if ($address_response && $address_response->isSuccessful()) {
$company = CorporateCustomerBuilder::create(false) $company = CorporateCustomerBuilder::create(false)
->setCompany($order_data['payment_company']) ->setCompany($order_data['payment_company'])
->setCompanyAddressId($address_response['id'])
->buildCompany($order_data); ->buildCompany($order_data);
$company['address'] = array(
'id' => $address_response['id']
);
$this->api->customersCorporateCompaniesCreate($corp_client_id, $company, 'id'); $this->api->customersCorporateCompaniesCreate($corp_client_id, $company, 'id');
} }
} }
@ -180,11 +177,14 @@ class CorporateCustomer {
* @return void * @return void
*/ */
private function updateOrCreateAddress($order_data, $corp_client) { private function updateOrCreateAddress($order_data, $corp_client) {
$address_id = null;
$addresses_response = $this->api->customersCorporateAddresses($corp_client['id'], array(), null, null, 'id'); $addresses_response = $this->api->customersCorporateAddresses($corp_client['id'], array(), null, null, 'id');
$corp_address = CorporateCustomerBuilder::create(false)->buildAddress($order_data); $corp_address = CorporateCustomerBuilder::create(false)->buildAddress($order_data);
if ($addresses_response && $addresses_response->isSuccessful() && !empty($addresses_response['addresses'])) { if ($addresses_response && $addresses_response->isSuccessful() && !empty($addresses_response['addresses'])) {
foreach ($addresses_response['addresses'] as $address) { foreach ($addresses_response['addresses'] as $address) {
if (Utils::addressEquals($corp_address, $address)) { if (Utils::addressEquals($corp_address, $address)) {
$address_id = $address['id'];
$exist_address = $address; $exist_address = $address;
break; break;
@ -193,25 +193,35 @@ class CorporateCustomer {
} }
if (!isset($exist_address)) { if (!isset($exist_address)) {
$this->api->customersCorporateAddressesCreate( $response = $this->api->customersCorporateAddressesCreate(
$corp_client['id'], $corp_client['id'],
$corp_address, $corp_address,
'id' 'id'
); );
if ($response && $response->isSuccessful() && isset($response['id'])) {
$address_id = $response['id'];
}
} }
if (!empty($corp_client['mainCompany'])) { $company = CorporateCustomerBuilder::create(false)
$company = CorporateCustomerBuilder::create(false) ->setCompany($order_data['payment_company'])
->setCompany($order_data['payment_company']) ->setCompanyAddressId($address_id)
->buildCompany($order_data); ->buildCompany($order_data);
$companies = $this->api->customersCorporateCompanies($corp_client['id'], array(), null, null, 'id');
$this->api->customersCorporateCompaniesEdit( if ($companies && $companies->isSuccessful() && !empty($companies['companies'])) {
$corp_client['id'], foreach ($companies['companies'] as $crm_company) {
$corp_client['mainCompany']['id'], if ($crm_company['name'] === $order_data['payment_company']) {
$company, $this->api->customersCorporateCompaniesEdit(
'id', $corp_client['id'],
'id' $crm_company['id'],
); $company,
'id',
'id'
);
}
}
} }
} }
} }

View File

@ -3,6 +3,8 @@
namespace retailcrm\service; namespace retailcrm\service;
class CorporateCustomerBuilder { class CorporateCustomerBuilder {
private $is_main_company = false;
private $company_address_id = null;
private $data = array(); private $data = array();
private $company; private $company;
@ -36,6 +38,28 @@ class CorporateCustomerBuilder {
return $this->data; return $this->data;
} }
/**
* @param bool $isMainCompany
*
* @return CorporateCustomerBuilder
*/
public function setIsMainCompany($isMainCompany)
{
$this->is_main_company = $isMainCompany;
return $this;
}
/**
* @param int $companyAddressId
*
* @return CorporateCustomerBuilder
*/
public function setCompanyAddressId($companyAddressId)
{
$this->company_address_id = $companyAddressId;
return $this;
}
public function setCompany($company) { public function setCompany($company) {
$this->company = $company; $this->company = $company;
@ -83,14 +107,23 @@ class CorporateCustomerBuilder {
} }
public function buildCompany($data) { public function buildCompany($data) {
return array( $company = array(
'isMain' => true,
'name' => $this->company, 'name' => $this->company,
'contragent' => array( 'contragent' => array(
'legalAddress' => $this->buildLegalAddress($data), 'legalAddress' => $this->buildLegalAddress($data),
'contragentType' => 'legal-entity', 'contragentType' => 'legal-entity',
) )
); );
if ($this->is_main_company) {
$company['isMain'] = true;
}
if (null !== $this->company_address_id) {
$company['address'] = array('id' => $this->company_address_id);
}
return $company;
} }
public function addCompany($data) { public function addCompany($data) {

View File

@ -21,17 +21,26 @@ class CorporateCustomerBuilderTest extends TestCase {
'shipping_address_2' => '' 'shipping_address_2' => ''
); );
$corp = \retailcrm\service\CorporateCustomerBuilder::create() $builder = \retailcrm\service\CorporateCustomerBuilder::create();
$corp = $builder
->setCustomerExternalId(1) ->setCustomerExternalId(1)
->setCompany('Company') ->setCompany('Company')
->addCompany($data) ->addCompany($data)
->addAddress($data) ->addAddress($data)
->build(); ->build();
$company_with_is_main = $builder->setIsMainCompany(true)->buildCompany($data);
$company_with_address = $builder->setCompanyAddressId(12)->buildCompany($data);
$this->assertNotEmpty($corp); self::assertNotEmpty($corp);
$this->assertNotEmpty($corp['addresses']); self::assertNotEmpty($corp['addresses']);
$this->assertNotEmpty($corp['companies']); self::assertNotEmpty($corp['companies']);
$this->assertNotEmpty($corp['customerContacts'][0]['customer']); self::assertFalse(isset($corp['companies'][0]['isMain']));
$this->assertEquals(1, $corp['customerContacts'][0]['customer']['externalId']); self::assertArrayHasKey('isMain', $company_with_is_main);
self::assertTrue($company_with_is_main['isMain']);
self::assertArrayHasKey('address', $company_with_address);
self::assertNotEmpty($company_with_address['address']);
self::assertEquals(12, $company_with_address['address']['id']);
self::assertNotEmpty($corp['customerContacts'][0]['customer']);
self::assertEquals(1, $corp['customerContacts'][0]['customer']['externalId']);
} }
} }