Merge pull request #37 from sergeygw1990/master

v2.2.7
This commit is contained in:
Alex Lushpai 2018-11-01 15:36:08 +03:00 committed by GitHub
commit 2ce4158c02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 48 deletions

View File

@ -1,3 +1,7 @@
## v.2.2.7
* Добавлена отправка адреса клиента при обновлении покупателя на стороне сайта
* Добавлены методы получения адреса и телефона
## v.2.2.6
* Добавлена активация модуля в маркетплейсе retailCRM

View File

@ -1 +1 @@
2.2.6
2.2.7

View File

@ -394,6 +394,7 @@ class RetailCRM extends Module
public function hookActionCustomerAccountUpdate($params)
{
$customer = $params['customer'];
$customerSend = array(
'externalId' => $customer->id,
'firstName' => $customer->firstname,
@ -402,6 +403,21 @@ class RetailCRM extends Module
'birthday' => $customer->birthday
);
$addreses = $customer->getAddresses($this->default_lang);
$address = array_shift($addreses);
if (!empty($address)){
if (is_object($address)) {
$address = $this->addressParse($address);
} else {
$address = new Address($address['id_address']);
$address = $this->addressParse($address);
}
$customerSend = array_merge($customerSend, $address['customer']);
}
$this->api->customersEdit($customerSend);
return $customerSend;
@ -507,53 +523,9 @@ class RetailCRM extends Module
$cart = $params['cart'];
$addressCollection = $cart->getAddressCollection();
$address = array_shift($addressCollection);
if ($address instanceof Address) {
$additionalPhone = !empty($address->phone) ? $address->phone : '';
$phone = !empty($address->phone_mobile) ? $address->phone_mobile : '';
$postcode = $address->postcode;
$city = $address->city;
$addres_line = sprintf("%s %s", $address->address1, $address->address2);
$countryIso = CountryCore::getIsoById($address->id_country);
}
if (!empty($postcode)) {
$customer['address']['index'] = $postcode;
$order['delivery']['address']['index'] = $postcode;
}
if (!empty($city)) {
$customer['address']['city'] = $city;
$order['delivery']['address']['city'] = $city;
}
if (!empty($addres_line)) {
$customer['address']['text'] = $addres_line;
$order['delivery']['address']['text'] = $addres_line;
}
if (!empty($countryIso)) {
$order['countryIso'] = $countryIso;
$customer['address']['countryIso'] = $countryIso;
}
if (!empty($phone) && !empty($additionalPhone)) {
$customer['phones'] = array(
array(
'number' => $phone
),
array(
'number' => $additionalPhone
)
);
$order['phone'] = $phone;
$order['additionalPhone'] = $additionalPhone;
} else {
$order['phone'] = !empty($phone) ? $phone : $additionalPhone;
$customer['phones'][] = array('number' => $order['phone']);
}
$address = $this->addressParse($address);
$customer = array_merge($customer, $address['customer']);
$order = array_merge($order, $address['order']);
$comment = $params['order']->getFirstMessage();
if ($comment !== false) {
@ -782,6 +754,74 @@ class RetailCRM extends Module
return $output;
}
private function addressParse($address)
{
if ($address instanceof Address) {
$postcode = $address->postcode;
$city = $address->city;
$addres_line = sprintf("%s %s", $address->address1, $address->address2);
$countryIso = CountryCore::getIsoById($address->id_country);
}
if (!empty($postcode)) {
$customer['address']['index'] = $postcode;
$order['delivery']['address']['index'] = $postcode;
}
if (!empty($city)) {
$customer['address']['city'] = $city;
$order['delivery']['address']['city'] = $city;
}
if (!empty($addres_line)) {
$customer['address']['text'] = $addres_line;
$order['delivery']['address']['text'] = $addres_line;
}
if (!empty($countryIso)) {
$order['countryIso'] = $countryIso;
$customer['address']['countryIso'] = $countryIso;
}
$phones = $this->getPhone($address);
if ($phones !== false) {
$order = array_merge($order, $phones['order']);
$customer = array_merge($customer, $phones['customer']);
}
$addressArray = array('order' => $order, 'customer' => $customer);
return $addressArray;
}
private function getPhone($address)
{
if (!empty($address->phone_mobile)){
$order['phone'] = $address->phone_mobile;
$customer['phones'][] = array('number'=> $address->phone_mobile);
}
if (!empty($address->phone)){
$order['additionalPhone'] = $address->phone;
$customer['phones'][] = array('number'=> $address->phone);
}
if (!isset($order['phone']) && !empty($order['additionalPhone'])){
$order['phone'] = $order['additionalPhone'];
unset($order['additionalPhone']);
}
if (!empty($customer) && !empty($order)) {
$phonesArray = array('customer' => $customer, 'order' => $order);
return $phonesArray;
} else {
return false;
}
}
/**
* Activate/deactivate module in marketplace retailCRM
*

View File

@ -57,6 +57,11 @@ class RetailCRMTest extends RetailcrmTestCase
$this->assertArrayHasKey('lastName', $customer);
$this->assertArrayHasKey('email', $customer);
$this->assertArrayHasKey('birthday', $customer);
$this->assertArrayHasKey('address', $customer);
$this->assertArrayHasKey('index', $customer['address']);
$this->assertArrayHasKey('city', $customer['address']);
$this->assertArrayHasKey('text', $customer['address']);
$this->assertArrayHasKey('countryIso', $customer['address']);
}
public function testHookActionOrderEdited()