Improved work with order addresses in history methods

This commit is contained in:
max-baranikov 2021-09-17 14:05:42 +03:00 committed by GitHub
parent 9bf1c88f4b
commit d91ba6d4c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 154 additions and 86 deletions

View File

@ -185,6 +185,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
case static::MODE_ORDER_DELIVERY: case static::MODE_ORDER_DELIVERY:
$this->buildOrderAddress(); $this->buildOrderAddress();
$this->buildOrderPhones(); $this->buildOrderPhones();
$this->buildOrderNames();
break; break;
default: default:
throw new \InvalidArgumentException("Incorrect builder mode"); throw new \InvalidArgumentException("Incorrect builder mode");
@ -254,6 +255,7 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
$this->address->address1, $this->address->address1,
$this->address->address2, $this->address->address2,
])), ])),
'notes' => $this->address->other,
'region' => $state 'region' => $state
)); ));
} }
@ -290,6 +292,20 @@ class RetailcrmAddressBuilder extends RetailcrmAbstractDataBuilder
} }
} }
/**
* Extract order first and last names from address
*/
private function buildOrderNames()
{
if (!empty($this->address->firstname)) {
$this->data['order']['firstName'] = $this->address->firstname;
}
if (!empty($this->address->lastname)) {
$this->data['order']['lastName'] = $this->address->lastname;
}
}
/** /**
* Build regular customer address * Build regular customer address
*/ */

View File

@ -88,12 +88,14 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
public function setCustomerAddress($customerAddress) public function setCustomerAddress($customerAddress)
{ {
$this->customerAddress = $customerAddress; $this->customerAddress = $customerAddress;
return $this; return $this;
} }
public function setDataCrm($dataCrm) public function setDataCrm($dataCrm)
{ {
$this->dataCrm = $dataCrm; $this->dataCrm = $dataCrm;
return $this; return $this;
} }
@ -104,6 +106,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
public function setIdCustomer($idCustomer) public function setIdCustomer($idCustomer)
{ {
$this->idCustomer = $idCustomer; $this->idCustomer = $idCustomer;
return $this; return $this;
} }
@ -114,6 +117,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
public function setAlias($alias) public function setAlias($alias)
{ {
$this->alias = $alias; $this->alias = $alias;
return $this; return $this;
} }
@ -124,6 +128,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
public function setFirstName($firstName) public function setFirstName($firstName)
{ {
$this->firstName = $firstName; $this->firstName = $firstName;
return $this; return $this;
} }
@ -134,6 +139,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
public function setLastName($lastName) public function setLastName($lastName)
{ {
$this->lastName = $lastName; $this->lastName = $lastName;
return $this; return $this;
} }
@ -144,6 +150,7 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
public function setPhone($phone) public function setPhone($phone)
{ {
$this->phone = $phone; $this->phone = $phone;
return $this; return $this;
} }
@ -174,13 +181,22 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
$this->setAddressField('alias', $this->alias, 'default'); $this->setAddressField('alias', $this->alias, 'default');
$this->setAddressField('lastname', $this->lastName, ''); $this->setAddressField('lastname', $this->lastName, '');
$this->setAddressField('firstname', $this->firstName, ''); $this->setAddressField('firstname', $this->firstName, '');
$this->setAddressField('phone', $this->phone, '');
$addressLine = $this->buildAddressLine(); $this->buildAddressLine();
$this->setAddressField('address1', $addressLine[0], '--');
$this->setAddressField('address2', $addressLine[1], '');
$countryIso = isset($this->dataCrm['countryIso']) ? Country::getByIso($this->dataCrm['countryIso']) : null; if (isset($this->dataCrm['notes'])) {
$this->setAddressField('id_country', $countryIso, Configuration::get('PS_COUNTRY_DEFAULT')); $this->setAddressField('other', $this->dataCrm['notes'], '');
}
if (isset($this->dataCrm['countryIso'])) {
$countryIso = null;
if (Validate::isLanguageIsoCode($this->dataCrm['countryIso'])) {
$countryIso = Country::getByIso($this->dataCrm['countryIso']);
}
$this->setAddressField('id_country', $countryIso, Configuration::get('PS_COUNTRY_DEFAULT'));
}
if (isset($this->dataCrm['city'])) { if (isset($this->dataCrm['city'])) {
$this->setAddressField('city', $this->dataCrm['city'], '--'); $this->setAddressField('city', $this->dataCrm['city'], '--');
@ -188,23 +204,17 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
if (isset($this->dataCrm['index'])) { if (isset($this->dataCrm['index'])) {
$this->setAddressField('postcode', $this->dataCrm['index'], ''); $this->setAddressField('postcode', $this->dataCrm['index'], '');
} }
if (isset($this->dataCrm['region'])) { if (isset($this->dataCrm['region'])) {
$state = State::getIdByName($this->dataCrm['region']); $this->setAddressField('id_state', (int) State::getIdByName($this->dataCrm['region']));
if (!empty($state)) {
$this->customerAddress->id_state = $state;
}
} }
$this->setAddressField('phone', $this->phone, '');
$this->customerAddress = RetailcrmTools::filter( $this->customerAddress = RetailcrmTools::filter(
'RetailcrmFilterSaveCustomerAddress', 'RetailcrmFilterSaveCustomerAddress',
$this->customerAddress, $this->customerAddress,
array( array(
'dataCrm' => $this->dataCrm 'dataCrm' => $this->dataCrm
)); )
);
return $this; return $this;
} }
@ -217,26 +227,27 @@ class RetailcrmCustomerAddressBuilder extends RetailcrmAbstractBuilder implement
if ($value !== null) { if ($value !== null) {
$this->customerAddress->$field = $value; $this->customerAddress->$field = $value;
} elseif (empty($this->customerAddress->$field)) { } else {
$this->customerAddress->$field = $default; $this->customerAddress->$field = $default;
} }
} }
private function buildAddressLine() private function buildAddressLine()
{ {
$addressLine = [
null,
null
];
if (isset($this->dataCrm['text'])) { if (isset($this->dataCrm['text'])) {
$addressLine = explode(RetailcrmAddressBuilder::ADDRESS_LINE_DIVIDER, $this->dataCrm['text'], 2); $text = $this->dataCrm['text'];
if (isset($this->dataCrm['notes'])) {
$text = str_replace($this->dataCrm['notes'], '', $text);
}
$addressLine = explode(RetailcrmAddressBuilder::ADDRESS_LINE_DIVIDER, $text, 2);
$this->setAddressField('address1', $addressLine[0], '--');
if (count($addressLine) == 1) { if (count($addressLine) == 1) {
$addressLine[] = null; $this->setAddressField('address2', '');
} else {
$this->setAddressField('address2', $addressLine[1], '');
} }
} }
return $addressLine;
} }
} }

View File

@ -83,7 +83,7 @@ class RetailcrmHistory
$customerHistory = RetailcrmTools::filter( $customerHistory = RetailcrmTools::filter(
'RetailcrmFilterCustomersHistory', 'RetailcrmFilterCustomersHistory',
$customerHistory $customerHistory
); );
if (isset($customerHistory['deleted']) && $customerHistory['deleted']) { if (isset($customerHistory['deleted']) && $customerHistory['deleted']) {
continue; continue;
@ -228,7 +228,6 @@ class RetailcrmHistory
} }
if (count($historyChanges)) { if (count($historyChanges)) {
$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)));
@ -251,7 +250,6 @@ class RetailcrmHistory
$infoOrder = null; $infoOrder = null;
if (!array_key_exists('externalId', $order_history)) { if (!array_key_exists('externalId', $order_history)) {
// get full order // get full order
$order = self::getCRMOrder($order_history['id'], 'id'); $order = self::getCRMOrder($order_history['id'], 'id');
if (!$order) { if (!$order) {
@ -288,7 +286,8 @@ class RetailcrmHistory
} }
$crmPaymentType = isset($payment) ? $payment : null; $crmPaymentType = isset($payment) ? $payment : null;
if (!is_null($crmPaymentType) && array_key_exists($crmPaymentType, $payments) && !empty($payments[$crmPaymentType])) { if (!is_null($crmPaymentType) &&
array_key_exists($crmPaymentType, $payments) && !empty($payments[$crmPaymentType])) {
if (Module::getInstanceByName($payments[$crmPaymentType])) { if (Module::getInstanceByName($payments[$crmPaymentType])) {
$paymentType = Module::getModuleName($payments[$crmPaymentType]); $paymentType = Module::getModuleName($payments[$crmPaymentType]);
} else { } else {
@ -384,7 +383,6 @@ class RetailcrmHistory
$customer = $corporateCustomerBuilder->getData()->getCustomer(); $customer = $corporateCustomerBuilder->getData()->getCustomer();
$addressInvoice = $corporateCustomerBuilder->getData()->getCustomerAddress(); $addressInvoice = $corporateCustomerBuilder->getData()->getCustomerAddress();
} else { } else {
$customerBuilder = new RetailcrmCustomerBuilder(); $customerBuilder = new RetailcrmCustomerBuilder();
if ($customerId) { if ($customerId) {
@ -418,7 +416,10 @@ class RetailcrmHistory
self::$api->customersCorporateAddressesEdit( self::$api->customersCorporateAddressesEdit(
$order['customer']['id'], $order['customer']['id'],
$order['company']['address']['id'], $order['company']['address']['id'],
array_merge($order['company']['address'], array('externalId' => $addressInvoice->id)), array_merge(
$order['company']['address'],
array('externalId' => $addressInvoice->id)
),
'id', 'id',
'id' 'id'
); );
@ -467,7 +468,6 @@ class RetailcrmHistory
$products = array(); $products = array();
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)) {
continue; continue;
} }
@ -572,7 +572,6 @@ class RetailcrmHistory
// set status for the order // set status for the order
if (isset($newOrderHistoryRecord)) { if (isset($newOrderHistoryRecord)) {
$newOrderHistoryRecord->id_order = $newOrder->id; $newOrderHistoryRecord->id_order = $newOrder->id;
$newOrderHistoryRecord->id_order_state = $newOrder->current_state; $newOrderHistoryRecord->id_order_state = $newOrder->current_state;
$newOrderHistoryRecord->id_employee = static::getFirstEmployeeId(); $newOrderHistoryRecord->id_employee = static::getFirstEmployeeId();
@ -656,7 +655,6 @@ class RetailcrmHistory
$newItemsIds = array(); $newItemsIds = array();
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;
@ -719,13 +717,11 @@ class RetailcrmHistory
// collect orders id and reference if option sendOrderNumber enabled // collect orders id and reference if option sendOrderNumber enabled
if ($sendOrderNumber) { if ($sendOrderNumber) {
array_push($updateOrderIds, array( array_push($updateOrderIds, array(
'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 (stripos($order['externalId'], 'pscart_') !== false) {
@ -750,19 +746,22 @@ class RetailcrmHistory
/* /*
* check delivery changes * check delivery changes
*/ */
if (isset($order['delivery']) if (isset($order['delivery']['address'])
|| isset($order['firstName']) || array_key_exists('firstName', $order)
|| isset($order['lastName']) || array_key_exists('lastName', $order)
|| isset($order['phone']) || array_key_exists('phone', $order)
) { ) {
$addressBuilder = new RetailcrmCustomerAddressBuilder(); $addressBuilder = new RetailcrmCustomerAddressBuilder();
$orderAddressCrm = []; $orderAddress = new Address($orderToUpdate->id_address_delivery);
if (isset($order['delivery']['address'])) { $orderAddressCrm = isset($order['delivery']['address']) ? $order['delivery']['address'] : [];
$orderAddressCrm = $order['delivery']['address']; $orderFirstName = $orderAddress->firstname;
} $orderLastName = $orderAddress->lastname;
$orderPhone = $orderAddress->phone;
if (RetailcrmHistoryHelper::isAddressLineChanged($orderAddressCrm)) { if (RetailcrmHistoryHelper::isAddressLineChanged($orderAddressCrm)
|| !Validate::isLoadedObject($orderAddress)
) {
$infoOrder = self::getCRMOrder($order['externalId']); $infoOrder = self::getCRMOrder($order['externalId']);
if (isset($infoOrder['delivery']['address'])) { if (isset($infoOrder['delivery']['address'])) {
// array_replace used to save changes, made by custom filters // array_replace used to save changes, made by custom filters
@ -771,30 +770,64 @@ class RetailcrmHistory
$orderAddressCrm $orderAddressCrm
); );
} }
if (isset($infoOrder['firstName'])) {
$orderFirstName = $infoOrder['firstName'];
}
if (isset($infoOrder['lastName'])) {
$orderLastName = $infoOrder['lastName'];
}
if (isset($infoOrder['phone'])) {
$orderPhone = $infoOrder['phone'];
}
}
// may override actual order data, but used to save changes, made by custom filters
if (array_key_exists('firstName', $order)) {
$orderFirstName = $order['firstName'];
}
if (array_key_exists('lastName', $order)) {
$orderLastName = $order['lastName'];
}
if (array_key_exists('phone', $order)) {
$orderPhone = $order['phone'];
} }
$address = $addressBuilder $address = $addressBuilder
->setCustomerAddress(new Address($orderToUpdate->id_address_delivery)) ->setCustomerAddress($orderAddress)
->setIdCustomer($orderToUpdate->id_customer) ->setIdCustomer($orderToUpdate->id_customer)
->setDataCrm($orderAddressCrm) ->setDataCrm($orderAddressCrm)
->setFirstName(isset($order['firstName']) ? $order['firstName'] : null) ->setFirstName($orderFirstName)
->setLastName(isset($order['lastName']) ? $order['lastName'] : null) ->setLastName($orderLastName)
->setPhone(isset($order['phone']) ? $order['phone'] : null) ->setPhone($orderPhone)
->setAlias($orderAddress->alias)
->build() ->build()
->getData(); ->getData();
if (RetailcrmTools::validateEntity($address, $orderToUpdate)) { if (RetailcrmTools::validateEntity($address, $orderToUpdate)) {
// Modifying an address in order creates another address $address->id = null;
// instead of changing the original one. This issue has been fixed in PS 1.7.7 RetailcrmTools::assignAddressIdsByFields(new Customer($orderToUpdate->id_customer), $address);
if (version_compare(_PS_VERSION_, '1.7.7', '<')) {
$address->id = null; if ($address->id === null) {
self::loadInCMS($address, 'add'); // Modifying an address in order creates another address
// instead of changing the original one. This issue has been fixed in PS 1.7.7
if (version_compare(_PS_VERSION_, '1.7.7', '<')) {
self::loadInCMS($address, 'add');
$orderToUpdate->id_address_delivery = $address->id;
self::loadInCMS($orderToUpdate, 'update');
} else {
$address->id = $orderToUpdate->id_address_delivery;
self::loadInCMS($address, 'update');
}
} elseif ($address->id !== $orderToUpdate->id_address_delivery) {
RetailcrmLogger::writeDebug(__METHOD__, sprintf(
'Binding to existing address [%d]',
$address->id
));
$orderToUpdate->id_address_delivery = $address->id; $orderToUpdate->id_address_delivery = $address->id;
self::loadInCMS($orderToUpdate, 'update'); self::loadInCMS($orderToUpdate, 'update');
} else {
$address->id = $orderToUpdate->id_address_delivery;
self::loadInCMS($address, 'update');
} }
} }
} }
@ -803,12 +836,10 @@ class RetailcrmHistory
* check delivery type and cost * check delivery type and cost
*/ */
if (!empty($order['delivery']['code']) || !empty($order['delivery']['cost'])) { if (!empty($order['delivery']['code']) || !empty($order['delivery']['cost'])) {
$dtype = !empty($order['delivery']['code']) ? $order['delivery']['code'] : null; $dtype = !empty($order['delivery']['code']) ? $order['delivery']['code'] : null;
$dcost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : null; $dcost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : null;
if ( if ($dtype != null && (
$dtype != null && (
isset($deliveries[$dtype]) isset($deliveries[$dtype])
&& $deliveries[$dtype] != null && $deliveries[$dtype] != null
&& $deliveries[$dtype] != $orderToUpdate->id_carrier && $deliveries[$dtype] != $orderToUpdate->id_carrier
@ -893,7 +924,6 @@ class RetailcrmHistory
// change order totals // change order totals
if (isset($order['items']) || isset($order['delivery']['cost'])) { if (isset($order['items']) || isset($order['delivery']['cost'])) {
// get full order // get full order
if (empty($infoOrder)) { if (empty($infoOrder)) {
$infoOrder = self::getCRMOrder($order['externalId']); $infoOrder = self::getCRMOrder($order['externalId']);
@ -901,14 +931,12 @@ class RetailcrmHistory
// items // items
if (isset($order['items']) && is_array($order['items'])) { if (isset($order['items']) && is_array($order['items'])) {
/* /*
* Clean deleted items * Clean deleted items
*/ */
$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']) && $item['delete'] == true) {
if (RetailcrmOrderBuilder::isGiftItem($item)) { if (RetailcrmOrderBuilder::isGiftItem($item)) {
$orderToUpdate->gift = false; $orderToUpdate->gift = false;
} }
@ -929,7 +957,6 @@ class RetailcrmHistory
*/ */
foreach ($orderToUpdate->getProductsDetail() as $orderItem) { foreach ($orderToUpdate->getProductsDetail() as $orderItem) {
foreach ($order['items'] as $key => $item) { foreach ($order['items'] as $key => $item) {
if (RetailcrmOrderBuilder::isGiftItem($item)) { if (RetailcrmOrderBuilder::isGiftItem($item)) {
continue; continue;
} }
@ -1055,7 +1082,6 @@ class RetailcrmHistory
// delete all cart discount // delete all cart discount
$orderCartRules = $orderToUpdate->getCartRules(); $orderCartRules = $orderToUpdate->getCartRules();
foreach ($orderCartRules as $valCartRules) { foreach ($orderCartRules as $valCartRules) {
$order_cart_rule = new OrderCartRule($valCartRules['id_order_cart_rule']); $order_cart_rule = new OrderCartRule($valCartRules['id_order_cart_rule']);
$order_cart_rule->delete(); $order_cart_rule->delete();
} }
@ -1082,7 +1108,6 @@ class RetailcrmHistory
if (isset($statuses[$stype]) && !empty($statuses[$stype])) { if (isset($statuses[$stype]) && !empty($statuses[$stype])) {
if ($statuses[$stype] != $orderToUpdate->current_state) { if ($statuses[$stype] != $orderToUpdate->current_state) {
$orderHistory = new OrderHistory(); $orderHistory = new OrderHistory();
$orderHistory->id_employee = 0; $orderHistory->id_employee = 0;
$orderHistory->id_order = $orderToUpdate->id; $orderHistory->id_order = $orderToUpdate->id;
@ -1115,7 +1140,7 @@ class RetailcrmHistory
// collect orders id and reference if option sendOrderNumber enabled // collect orders id and reference if option sendOrderNumber enabled
if ($sendOrderNumber) { if ($sendOrderNumber) {
array_push($updateOrderIds, array( array_push($updateOrderIds, array(
'externalId' => $orderToUpdate->id, 'externalId' => $orderToUpdate->id,
'number' => $orderToUpdate->reference, 'number' => $orderToUpdate->reference,
)); ));
} }
@ -1126,7 +1151,7 @@ class RetailcrmHistory
if (!empty($orderFix)) { if (!empty($orderFix)) {
self::$api->ordersFixExternalIds($orderFix); self::$api->ordersFixExternalIds($orderFix);
} }
// update orders number in CRM // update orders number in CRM
if (!empty($updateOrderIds)) { if (!empty($updateOrderIds)) {
foreach ($updateOrderIds as $upOrder) { foreach ($updateOrderIds as $upOrder) {
@ -1332,15 +1357,13 @@ class RetailcrmHistory
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));
);
} }
private static function getNewOrderDetailId() private static function getNewOrderDetailId()
{ {
return Db::getInstance()->getRow(' return Db::getInstance()->getRow('
SELECT MAX(id_order_detail) FROM ' . _DB_PREFIX_ . 'order_detail' SELECT MAX(id_order_detail) FROM ' . _DB_PREFIX_ . 'order_detail');
);
} }
/** /**
@ -1442,7 +1465,7 @@ class RetailcrmHistory
&& isset($entry['apiKey']['current']) && isset($entry['apiKey']['current'])
&& $entry['apiKey']['current'] == true && $entry['apiKey']['current'] == true
) { ) {
if (isset($notOurChanges[$externalId][$field]) || $entry['field'] == 'externalId') { if (isset($notOurChanges[$externalId][$field]) || $field == 'externalId' || $field == 'status') {
$organizedHistory[$externalId][] = $entry; $organizedHistory[$externalId][] = $entry;
} else { } else {
continue; continue;
@ -1604,7 +1627,6 @@ class RetailcrmHistory
$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']) && $item['product_attribute_id'] > 0) {
$productId = $item['product_id'] . '#' . $item['product_attribute_id']; $productId = $item['product_id'] . '#' . $item['product_attribute_id'];
} else { } else {
@ -1676,7 +1698,10 @@ class RetailcrmHistory
); );
} }
if ($historyResponse instanceof RetailcrmApiResponse && $historyResponse->offsetExists('history') && !empty($historyResponse['history'])) { if ($historyResponse instanceof RetailcrmApiResponse
&& $historyResponse->offsetExists('history')
&& !empty($historyResponse['history'])
) {
$history = $historyResponse['history']; $history = $historyResponse['history'];
$lastSinceId = end($history)['id']; $lastSinceId = end($history)['id'];
@ -1690,4 +1715,3 @@ class RetailcrmHistory
return true; return true;
} }
} }

View File

@ -316,7 +316,13 @@ class RetailcrmHistoryHelper {
*/ */
public static function isAddressLineChanged($address) public static function isAddressLineChanged($address)
{ {
// TODO countryIso, city, index and region added because module can't get changes of [text] field with api.
// Should be removed when the api logic is updated
$keys = [ $keys = [
'countryIso',
'city',
'index',
'region',
'street', 'street',
'building', 'building',
'flat', 'flat',

View File

@ -678,14 +678,18 @@ class RetailcrmTools
/** /**
* Assign address ID and customer ID from customer addresses. * Assign address ID and customer ID from customer addresses.
* Customer ID in the address isn't checked (it will be set to id from provided customer, even if it doesn't have ID yet). * Customer ID in the address isn't checked
* (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(__METHOD__, array('Called with customer', $customer->id, 'and address', self::dumpEntity($address))); RetailcrmLogger::writeDebugArray(
__METHOD__,
array('Called with customer', $customer->id, 'and address', self::dumpEntity($address))
);
foreach ($customer->getAddresses(self::defaultLang()) as $customerInnerAddress) { foreach ($customer->getAddresses(self::defaultLang()) as $customerInnerAddress) {
$customerAddress = new Address($customerInnerAddress['id_address']); $customerAddress = new Address($customerInnerAddress['id_address']);
@ -738,7 +742,10 @@ class RetailcrmTools
'firstname', 'firstname',
'postcode', 'postcode',
'city', 'city',
'id_state',
'address1', 'address1',
'address2',
'other',
'phone', 'phone',
'company', 'company',
'vat_number' 'vat_number'
@ -779,7 +786,8 @@ class RetailcrmTools
return $object; return $object;
} }
if (!in_array(RetailcrmFilterInterface::class, class_implements($filter))) { if (!in_array(RetailcrmFilterInterface::class, class_implements($filter))) {
RetailcrmLogger::writeDebug(__METHOD__, sprintf('Filter class %s must implements %s interface', RetailcrmLogger::writeDebug(__METHOD__, sprintf(
'Filter class %s must implements %s interface',
$filter, $filter,
RetailcrmFilterInterface::class RetailcrmFilterInterface::class
)); ));

View File

@ -102,7 +102,7 @@
<field id="delivery_cost" group="delivery">cost</field> <field id="delivery_cost" group="delivery">cost</field>
<field id="delivery_net_cost" group="delivery">netCost</field> <field id="delivery_net_cost" group="delivery">netCost</field>
<field id="delivery_address.country" group="orderAddress">country</field> <field id="country" group="orderAddress">countryIso</field>
<field id="delivery_address.index" group="orderAddress">index</field> <field id="delivery_address.index" group="orderAddress">index</field>
<field id="delivery_address.region" group="orderAddress">region</field> <field id="delivery_address.region" group="orderAddress">region</field>
<field id="delivery_address.city" group="orderAddress">city</field> <field id="delivery_address.city" group="orderAddress">city</field>

View File

@ -1004,7 +1004,7 @@ class RetailCRM extends Module
'enableOrderNumberSending' => (Tools::getValue(static::ENABLE_ORDER_NUMBER_SENDING) !== false), 'enableOrderNumberSending' => (Tools::getValue(static::ENABLE_ORDER_NUMBER_SENDING) !== false),
'enableOrderNumberReceiving' => (Tools::getValue(static::ENABLE_ORDER_NUMBER_RECEIVING) !== false), 'enableOrderNumberReceiving' => (Tools::getValue(static::ENABLE_ORDER_NUMBER_RECEIVING) !== false),
'debugMode' => (Tools::getValue(static::ENABLE_DEBUG_MODE) !== false), 'debugMode' => (Tools::getValue(static::ENABLE_DEBUG_MODE) !== false),
'webJobs' => (Tools::getValue(static::ENABLE_WEB_JOBS) !== false ? '1' : '0'), 'webJobs' => (Tools::getValue(static::ENABLE_WEB_JOBS, true) !== false ? '1' : '0'),
'collectorActive' => (Tools::getValue(static::COLLECTOR_ACTIVE) !== false), 'collectorActive' => (Tools::getValue(static::COLLECTOR_ACTIVE) !== false),
'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),
@ -1028,7 +1028,10 @@ class RetailCRM extends Module
Configuration::updateValue(static::ENABLE_HISTORY_UPLOADS, $settings['enableHistoryUploads']); Configuration::updateValue(static::ENABLE_HISTORY_UPLOADS, $settings['enableHistoryUploads']);
Configuration::updateValue(static::ENABLE_BALANCES_RECEIVING, $settings['enableBalancesReceiving']); Configuration::updateValue(static::ENABLE_BALANCES_RECEIVING, $settings['enableBalancesReceiving']);
Configuration::updateValue(static::ENABLE_ORDER_NUMBER_SENDING, $settings['enableOrderNumberSending']); Configuration::updateValue(static::ENABLE_ORDER_NUMBER_SENDING, $settings['enableOrderNumberSending']);
Configuration::updateValue(static::ENABLE_ORDER_NUMBER_RECEIVING, $settings['enableOrderNumberReceiving']); Configuration::updateValue(
static::ENABLE_ORDER_NUMBER_RECEIVING,
$settings['enableOrderNumberReceiving']
);
Configuration::updateValue(static::COLLECTOR_ACTIVE, $settings['collectorActive']); Configuration::updateValue(static::COLLECTOR_ACTIVE, $settings['collectorActive']);
Configuration::updateValue(static::COLLECTOR_KEY, $settings['collectorKey']); Configuration::updateValue(static::COLLECTOR_KEY, $settings['collectorKey']);
Configuration::updateValue(static::SYNC_CARTS_ACTIVE, $settings['synchronizeCartsActive']); Configuration::updateValue(static::SYNC_CARTS_ACTIVE, $settings['synchronizeCartsActive']);

View File

@ -169,7 +169,7 @@
<div class="retail-alert-text"> <div class="retail-alert-text">
{$catalogTitleName|escape:'htmlall':'UTF-8'} {l s='is outdated' mod='retailcrm'} {$catalogTitleName|escape:'htmlall':'UTF-8'} {l s='is outdated' mod='retailcrm'}
</div> </div>
{elseif !$catalogInfo.isUrlActual} {elseif !isset($catalogInfo.isUrlActual) or !$catalogInfo.isUrlActual}
{assign var="showUpdateButton" value=true} {assign var="showUpdateButton" value=true}
<div class="retail-alert retail-alert-warning"> <div class="retail-alert retail-alert-warning">
<div class="retail-alert-text"> <div class="retail-alert-text">
@ -519,8 +519,8 @@
<input type="hidden" name="RETAILCRM_DOWNLOAD_LOGS" value="1"/> <input type="hidden" name="RETAILCRM_DOWNLOAD_LOGS" value="1"/>
<input type="hidden" name="RETAILCRM_DOWNLOAD_LOGS_NAME" <input type="hidden" name="RETAILCRM_DOWNLOAD_LOGS_NAME"
value="{$logItem.name|escape:'htmlall':'UTF-8'}"/> value="{$logItem.name|escape:'htmlall':'UTF-8'}"/>
<input type="submit" id="download-log-{$key}" style="display: none;"/> <input type="submit" id="download-log-{$key|escape:'htmlall':'UTF-8'}" style="display: none;"/>
<label for="download-log-{$key}" <label for="download-log-{$key|escape:'htmlall':'UTF-8'}"
style="width: 100%; text-align: center;" style="width: 100%; text-align: center;"
class="retail-btn-svg_wrapper" class="retail-btn-svg_wrapper"
title=" {l s='Download' mod='retailcrm'}" title=" {l s='Download' mod='retailcrm'}"