mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-02 19:33:14 +03:00
fix #97 Fixed error when validating non-crm customers address
This commit is contained in:
parent
520149394e
commit
7fd6ff80a2
@ -1,3 +1,8 @@
|
|||||||
|
## v3.2.5
|
||||||
|
* Исправлена ошибка брошенных корзин для Prestashop версии ниже 1.7.1
|
||||||
|
* Исправлена ошибка при проверке адреса клиента
|
||||||
|
* Исправлена ошибка подключения к базе данных при запуске тестов
|
||||||
|
|
||||||
## v3.2.4
|
## v3.2.4
|
||||||
* Доработана выгрузка Releases архивов в Git Actions
|
* Доработана выгрузка Releases архивов в Git Actions
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ class RetailCRM extends Module
|
|||||||
{
|
{
|
||||||
$this->name = 'retailcrm';
|
$this->name = 'retailcrm';
|
||||||
$this->tab = 'export';
|
$this->tab = 'export';
|
||||||
$this->version = '3.2.4';
|
$this->version = '3.2.5';
|
||||||
$this->author = 'DIGITAL RETAIL TECHNOLOGIES SL';
|
$this->author = 'DIGITAL RETAIL TECHNOLOGIES SL';
|
||||||
$this->displayName = $this->l('retailCRM');
|
$this->displayName = $this->l('retailCRM');
|
||||||
$this->description = $this->l('Integration module for retailCRM');
|
$this->description = $this->l('Integration module for retailCRM');
|
||||||
@ -367,6 +367,10 @@ class RetailCRM extends Module
|
|||||||
/** @var Customer|CustomerCore|null $customer */
|
/** @var Customer|CustomerCore|null $customer */
|
||||||
$customer = isset($params['customer']) ? $params['customer'] : null;
|
$customer = isset($params['customer']) ? $params['customer'] : null;
|
||||||
|
|
||||||
|
if (empty($customer)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/** @var Cart|CartCore|null $cart */
|
/** @var Cart|CartCore|null $cart */
|
||||||
$cart = isset($params['cart']) ? $params['cart'] : null;
|
$cart = isset($params['cart']) ? $params['cart'] : null;
|
||||||
|
|
||||||
@ -379,62 +383,58 @@ class RetailCRM extends Module
|
|||||||
/** @var Address|\AddressCore|array $address */
|
/** @var Address|\AddressCore|array $address */
|
||||||
$address = array();
|
$address = array();
|
||||||
|
|
||||||
if (empty($customer)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Necessary part if we don't want to overwrite other phone numbers.
|
|
||||||
if (isset($customerSend['externalId'])) {
|
if (isset($customerSend['externalId'])) {
|
||||||
$customerData = $this->api->customersGet($customerSend['externalId']);
|
$customerData = $this->api->customersGet($customerSend['externalId']);
|
||||||
|
|
||||||
|
// Necessary part if we don't want to overwrite other phone numbers.
|
||||||
if ($customerData instanceof RetailcrmApiResponse
|
if ($customerData instanceof RetailcrmApiResponse
|
||||||
&& $customerData->isSuccessful()
|
&& $customerData->isSuccessful()
|
||||||
&& $customerData->offsetExists('customer')
|
&& $customerData->offsetExists('customer')
|
||||||
) {
|
) {
|
||||||
$customerSend['phones'] = $customerData['customer']['phones'];
|
$customerSend['phones'] = $customerData['customer']['phones'];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Workaround: PrestaShop will return OLD address data, before editing.
|
// Workaround: PrestaShop will return OLD address data, before editing.
|
||||||
// In order to circumvent this we are using post data to fill new address object.
|
// In order to circumvent this we are using post data to fill new address object.
|
||||||
if (Tools::getIsset('submitAddress')
|
if (Tools::getIsset('submitAddress')
|
||||||
&& Tools::getIsset('id_customer')
|
&& Tools::getIsset('id_customer')
|
||||||
&& Tools::getIsset('id_address')
|
&& Tools::getIsset('id_address')
|
||||||
) {
|
) {
|
||||||
$address = new Address(Tools::getValue('id_address'));
|
$address = new Address(Tools::getValue('id_address'));
|
||||||
|
|
||||||
foreach (array_keys(Address::$definition['fields']) as $field) {
|
foreach (array_keys(Address::$definition['fields']) as $field) {
|
||||||
if (property_exists($address, $field) && Tools::getIsset($field)) {
|
if (property_exists($address, $field) && Tools::getIsset($field)) {
|
||||||
$address->$field = Tools::getValue($field);
|
$address->$field = Tools::getValue($field);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$addresses = $customer->getAddresses($this->default_lang);
|
|
||||||
$address = array_shift($addresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($address)) {
|
|
||||||
$addressBuilder->setMode(RetailcrmAddressBuilder::MODE_CUSTOMER);
|
|
||||||
|
|
||||||
if (is_object($address)) {
|
|
||||||
$addressBuilder->setAddress($address);
|
|
||||||
} else {
|
} else {
|
||||||
$addressBuilder->setAddressId($address['id_address']);
|
$addresses = $customer->getAddresses($this->default_lang);
|
||||||
|
$address = array_shift($addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
$addressBuilder->build();
|
if (!empty($address)) {
|
||||||
} elseif (!empty($cart)) {
|
$addressBuilder->setMode(RetailcrmAddressBuilder::MODE_CUSTOMER);
|
||||||
$addressBuilder
|
|
||||||
->setMode(RetailcrmAddressBuilder::MODE_ORDER_DELIVERY)
|
if (is_object($address)) {
|
||||||
->setAddressId($cart->id_address_invoice)
|
$addressBuilder->setAddress($address);
|
||||||
->build();
|
} else {
|
||||||
|
$addressBuilder->setAddressId($address['id_address']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$addressBuilder->build();
|
||||||
|
} elseif (!empty($cart)) {
|
||||||
|
$addressBuilder
|
||||||
|
->setMode(RetailcrmAddressBuilder::MODE_ORDER_DELIVERY)
|
||||||
|
->setAddressId($cart->id_address_invoice)
|
||||||
|
->build();
|
||||||
|
}
|
||||||
|
|
||||||
|
$customerSend = RetailcrmTools::mergeCustomerAddress($customerSend, $addressBuilder->getDataArray());
|
||||||
|
|
||||||
|
$this->api->customersEdit($customerSend);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$customerSend = RetailcrmTools::mergeCustomerAddress($customerSend, $addressBuilder->getDataArray());
|
|
||||||
|
|
||||||
$this->api->customersEdit($customerSend);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user