mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-22 05:06:07 +03:00
Unified address logic (#193)
This commit is contained in:
parent
739c2775b5
commit
2dbccd8a02
@ -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
|
||||
|
||||
# Set timezone
|
||||
RUN rm /etc/localtime
|
||||
RUN ln -s /usr/share/zoneinfo/Europe/Moscow /etc/localtime
|
||||
RUN "date"
|
||||
RUN rm /etc/localtime && \
|
||||
ln -s /usr/share/zoneinfo/Europe/Moscow /etc/localtime && \
|
||||
"date"
|
||||
|
||||
ARG TEST_SUITE
|
||||
ARG OPENCART
|
||||
@ -51,6 +51,8 @@ ENV OC_EMAIL=${OC_EMAIL}
|
||||
|
||||
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 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 chmod +x /usr/local/bin/docker-php-entrypoint
|
||||
|
||||
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
|
||||
|
@ -8,8 +8,10 @@ done
|
||||
|
||||
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/admin/config.php
|
||||
|
||||
|
12
.env-dist
12
.env-dist
@ -1,8 +1,8 @@
|
||||
# OpenCart Database connection values
|
||||
OC_DB_HOSTNAME=host
|
||||
OC_DB_USERNAME=user
|
||||
OC_DB_PASSWORD=pass
|
||||
OC_DB_DATABASE=database
|
||||
OC_DB_HOSTNAME=mysql
|
||||
OC_DB_USERNAME=opencart
|
||||
OC_DB_PASSWORD=opencart
|
||||
OC_DB_DATABASE=opencart
|
||||
OC_DB_DRIVER=mysqli
|
||||
|
||||
# OpenCart Administration user
|
||||
@ -14,5 +14,5 @@ OC_EMAIL=you@example.com
|
||||
SERVER_PORT=8080
|
||||
SERVER_URL=http://localhost
|
||||
|
||||
TEST_SUITE=
|
||||
OPENCART=
|
||||
TEST_SUITE=3.0
|
||||
OPENCART=3.0.2.0
|
||||
|
@ -1,3 +1,6 @@
|
||||
## v.4.1.1
|
||||
* Обновлена механика обработки адресов покупателей
|
||||
|
||||
## v.4.1.0
|
||||
* Добавлена возможность подключения Online Consultant
|
||||
|
||||
|
@ -38,7 +38,7 @@ cp -r opencart-module/* /path/to/site/root
|
||||
|
||||
На странице настроек модуля укажите URL retailCRM и ключ авторизации, после сохранения этих данных укажите соответствия справочников типов доставок, оплат и статусов заказа.
|
||||
|
||||
#### Получение измений из retailCRM
|
||||
#### Получение изменений из retailCRM
|
||||
|
||||
Для получения изменений и новых данных добавьте в cron следующую запись:
|
||||
|
||||
|
@ -31,6 +31,8 @@
|
||||
"ext-json": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"consolidation/robo": "~1.0"
|
||||
"consolidation/robo": "~1.0",
|
||||
"beyondit/opencart-test-suite": "~3.0",
|
||||
"opencart/opencart": "3.0.2.0"
|
||||
}
|
||||
}
|
||||
|
@ -163,12 +163,9 @@ class CorporateCustomer {
|
||||
if ($address_response && $address_response->isSuccessful()) {
|
||||
$company = CorporateCustomerBuilder::create(false)
|
||||
->setCompany($order_data['payment_company'])
|
||||
->setCompanyAddressId($address_response['id'])
|
||||
->buildCompany($order_data);
|
||||
|
||||
$company['address'] = array(
|
||||
'id' => $address_response['id']
|
||||
);
|
||||
|
||||
$this->api->customersCorporateCompaniesCreate($corp_client_id, $company, 'id');
|
||||
}
|
||||
}
|
||||
@ -180,11 +177,14 @@ class CorporateCustomer {
|
||||
* @return void
|
||||
*/
|
||||
private function updateOrCreateAddress($order_data, $corp_client) {
|
||||
$address_id = null;
|
||||
$addresses_response = $this->api->customersCorporateAddresses($corp_client['id'], array(), null, null, 'id');
|
||||
$corp_address = CorporateCustomerBuilder::create(false)->buildAddress($order_data);
|
||||
|
||||
if ($addresses_response && $addresses_response->isSuccessful() && !empty($addresses_response['addresses'])) {
|
||||
foreach ($addresses_response['addresses'] as $address) {
|
||||
if (Utils::addressEquals($corp_address, $address)) {
|
||||
$address_id = $address['id'];
|
||||
$exist_address = $address;
|
||||
|
||||
break;
|
||||
@ -193,21 +193,29 @@ class CorporateCustomer {
|
||||
}
|
||||
|
||||
if (!isset($exist_address)) {
|
||||
$this->api->customersCorporateAddressesCreate(
|
||||
$response = $this->api->customersCorporateAddressesCreate(
|
||||
$corp_client['id'],
|
||||
$corp_address,
|
||||
'id'
|
||||
);
|
||||
|
||||
if ($response && $response->isSuccessful() && isset($response['id'])) {
|
||||
$address_id = $response['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($corp_client['mainCompany'])) {
|
||||
$company = CorporateCustomerBuilder::create(false)
|
||||
->setCompany($order_data['payment_company'])
|
||||
->setCompanyAddressId($address_id)
|
||||
->buildCompany($order_data);
|
||||
$companies = $this->api->customersCorporateCompanies($corp_client['id'], array(), null, null, 'id');
|
||||
|
||||
if ($companies && $companies->isSuccessful() && !empty($companies['companies'])) {
|
||||
foreach ($companies['companies'] as $crm_company) {
|
||||
if ($crm_company['name'] === $order_data['payment_company']) {
|
||||
$this->api->customersCorporateCompaniesEdit(
|
||||
$corp_client['id'],
|
||||
$corp_client['mainCompany']['id'],
|
||||
$crm_company['id'],
|
||||
$company,
|
||||
'id',
|
||||
'id'
|
||||
@ -215,3 +223,5 @@ class CorporateCustomer {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace retailcrm\service;
|
||||
|
||||
class CorporateCustomerBuilder {
|
||||
private $is_main_company = false;
|
||||
private $company_address_id = null;
|
||||
private $data = array();
|
||||
private $company;
|
||||
|
||||
@ -36,6 +38,28 @@ class CorporateCustomerBuilder {
|
||||
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) {
|
||||
$this->company = $company;
|
||||
|
||||
@ -83,14 +107,23 @@ class CorporateCustomerBuilder {
|
||||
}
|
||||
|
||||
public function buildCompany($data) {
|
||||
return array(
|
||||
'isMain' => true,
|
||||
$company = array(
|
||||
'name' => $this->company,
|
||||
'contragent' => array(
|
||||
'legalAddress' => $this->buildLegalAddress($data),
|
||||
'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) {
|
||||
|
@ -21,17 +21,26 @@ class CorporateCustomerBuilderTest extends TestCase {
|
||||
'shipping_address_2' => ''
|
||||
);
|
||||
|
||||
$corp = \retailcrm\service\CorporateCustomerBuilder::create()
|
||||
$builder = \retailcrm\service\CorporateCustomerBuilder::create();
|
||||
$corp = $builder
|
||||
->setCustomerExternalId(1)
|
||||
->setCompany('Company')
|
||||
->addCompany($data)
|
||||
->addAddress($data)
|
||||
->build();
|
||||
$company_with_is_main = $builder->setIsMainCompany(true)->buildCompany($data);
|
||||
$company_with_address = $builder->setCompanyAddressId(12)->buildCompany($data);
|
||||
|
||||
$this->assertNotEmpty($corp);
|
||||
$this->assertNotEmpty($corp['addresses']);
|
||||
$this->assertNotEmpty($corp['companies']);
|
||||
$this->assertNotEmpty($corp['customerContacts'][0]['customer']);
|
||||
$this->assertEquals(1, $corp['customerContacts'][0]['customer']['externalId']);
|
||||
self::assertNotEmpty($corp);
|
||||
self::assertNotEmpty($corp['addresses']);
|
||||
self::assertNotEmpty($corp['companies']);
|
||||
self::assertFalse(isset($corp['companies'][0]['isMain']));
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user