mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
Support transfer company and vat number in CRM custom fields (#224)
This commit is contained in:
parent
d0782028ee
commit
41509493e4
@ -1,3 +1,6 @@
|
|||||||
|
## v3.6.7
|
||||||
|
* Добавлена передача полей "Компания" и "Номер НДС" из заказа CMS в пользовательские поля заказа CRM
|
||||||
|
|
||||||
## v3.6.6
|
## v3.6.6
|
||||||
* Добавлена передача поля link при выгрузке брошенных корзин
|
* Добавлена передача поля link при выгрузке брошенных корзин
|
||||||
|
|
||||||
|
@ -1235,10 +1235,10 @@ class RetailcrmHistory
|
|||||||
$addressBuilder = new RetailcrmCustomerAddressBuilder();
|
$addressBuilder = new RetailcrmCustomerAddressBuilder();
|
||||||
$address = $addressBuilder
|
$address = $addressBuilder
|
||||||
->setIdCustomer($customer->id)
|
->setIdCustomer($customer->id)
|
||||||
->setDataCrm(isset($order['delivery']['address']) ? $order['delivery']['address'] : [])
|
->setDataCrm($order['delivery']['address'] ?? [])
|
||||||
->setFirstName(isset($order['firstName']) ? $order['firstName'] : null)
|
->setFirstName($order['firstName'] ?? null)
|
||||||
->setLastName(isset($order['lastName']) ? $order['lastName'] : null)
|
->setLastName($order['lastName'] ?? null)
|
||||||
->setPhone(isset($order['phone']) ? $order['phone'] : null)
|
->setPhone($order['phone'] ?? null)
|
||||||
->build()
|
->build()
|
||||||
->getData()
|
->getData()
|
||||||
;
|
;
|
||||||
@ -1525,10 +1525,13 @@ class RetailcrmHistory
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RetailcrmTools::validateEntity($addressInvoice, null, true)) {
|
if (RetailcrmTools::validateEntity($addressInvoice, null, true)) {
|
||||||
$addressInvoice->id_customer = $customer->id;
|
$addressInvoice->id_customer = $customer->id;
|
||||||
RetailcrmTools::assignAddressIdsByFields($customer, $addressInvoice);
|
RetailcrmTools::assignAddressIdsByFields($customer, $addressInvoice);
|
||||||
|
|
||||||
|
self::setCompanyAndVatNumberForInvoiceAddress($order, $addressInvoice);
|
||||||
|
|
||||||
if (empty($addressInvoice->id)) {
|
if (empty($addressInvoice->id)) {
|
||||||
self::loadInPrestashop($addressInvoice, 'save');
|
self::loadInPrestashop($addressInvoice, 'save');
|
||||||
|
|
||||||
@ -1954,6 +1957,24 @@ class RetailcrmHistory
|
|||||||
return $orderDetail;
|
return $orderDetail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function setCompanyAndVatNumberForInvoiceAddress($crmOrder, $addressInvoice)
|
||||||
|
{
|
||||||
|
if (!RetailcrmTools::isCorporateEnabled()
|
||||||
|
&& RetailcrmTools::isCampanyAndVatNumberSendEnabled()
|
||||||
|
) {
|
||||||
|
$company = $crmOrder['customFields']['ps_company'] ?? '';
|
||||||
|
$vatNumber = $crmOrder['customFields']['ps_vat_number'] ?? '';
|
||||||
|
|
||||||
|
if ('' !== $company) {
|
||||||
|
$addressInvoice->company = $company;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('' !== $vatNumber) {
|
||||||
|
$addressInvoice->vat_number = $vatNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static function handleError($order, $e)
|
private static function handleError($order, $e)
|
||||||
{
|
{
|
||||||
RetailcrmLogger::writeCaller(
|
RetailcrmLogger::writeCaller(
|
||||||
|
@ -979,15 +979,25 @@ class RetailcrmOrderBuilder
|
|||||||
;
|
;
|
||||||
$crmOrder = array_merge($crmOrder, $addressBuilder->getDataArray());
|
$crmOrder = array_merge($crmOrder, $addressBuilder->getDataArray());
|
||||||
|
|
||||||
if ($addressInvoice instanceof Address && !empty($addressInvoice->company)) {
|
$isCorporateEnabled = RetailcrmTools::isCorporateEnabled();
|
||||||
$crmOrder['contragent']['legalName'] = $addressInvoice->company;
|
|
||||||
|
|
||||||
if (!empty($addressInvoice->vat_number)) {
|
if ($isCorporateEnabled && RetailcrmTools::isOrderCorporate($order)) {
|
||||||
$crmOrder['contragent']['INN'] = $addressInvoice->vat_number;
|
$crmOrder['contragent']['contragentType'] = 'legal-entity';
|
||||||
|
$crmOrder['contragent']['legalName'] = $addressInvoice->company ?? '';
|
||||||
|
$crmOrder['contragent']['INN'] = $addressInvoice->vat_number ?? '';
|
||||||
|
} else {
|
||||||
|
$crmOrder['contragent']['contragentType'] = 'individual';
|
||||||
|
|
||||||
|
if (
|
||||||
|
RetailcrmTools::isCampanyAndVatNumberSendEnabled()
|
||||||
|
&& Configuration::get(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED)
|
||||||
|
) {
|
||||||
|
$crmOrder['customFields']['ps_company'] = $addressInvoice->company ?? '';
|
||||||
|
$crmOrder['customFields']['ps_vat_number'] = $addressInvoice->vat_number ?? '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($payment[$paymentType]) && !empty($payment[$paymentType])) {
|
if (!empty($payment[$paymentType])) {
|
||||||
$order_payment = [
|
$order_payment = [
|
||||||
'externalId' => $order->id . '#' . $order->reference,
|
'externalId' => $order->id . '#' . $order->reference,
|
||||||
'type' => $payment[$paymentType],
|
'type' => $payment[$paymentType],
|
||||||
@ -1124,9 +1134,6 @@ class RetailcrmOrderBuilder
|
|||||||
'productName' => $product['product_name'],
|
'productName' => $product['product_name'],
|
||||||
'quantity' => $product['product_quantity'],
|
'quantity' => $product['product_quantity'],
|
||||||
'initialPrice' => round($product['product_price'], 2),
|
'initialPrice' => round($product['product_price'], 2),
|
||||||
/*'initialPrice' => !empty($item['rate'])
|
|
||||||
? $item['price'] + ($item['price'] * $item['rate'] / 100)
|
|
||||||
: $item['price'],*/
|
|
||||||
'purchasePrice' => round($product['purchase_supplier_price'], 2),
|
'purchasePrice' => round($product['purchase_supplier_price'], 2),
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -1161,12 +1168,6 @@ class RetailcrmOrderBuilder
|
|||||||
if (!empty($site)) {
|
if (!empty($site)) {
|
||||||
$crmOrder['customer']['site'] = $site;
|
$crmOrder['customer']['site'] = $site;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RetailcrmTools::isCorporateEnabled() && RetailcrmTools::isOrderCorporate($order)) {
|
|
||||||
$crmOrder['contragent']['contragentType'] = 'legal-entity';
|
|
||||||
} else {
|
|
||||||
$crmOrder['contragent']['contragentType'] = 'individual';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RetailcrmTools::filter(
|
return RetailcrmTools::filter(
|
||||||
|
@ -58,6 +58,28 @@ class RetailcrmTools
|
|||||||
return self::$default_lang;
|
return self::$default_lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns ISO code of current employee language or default language.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getCurrentLanguageISO()
|
||||||
|
{
|
||||||
|
global $cookie;
|
||||||
|
|
||||||
|
$context = Context::getContext();
|
||||||
|
|
||||||
|
if (!empty($context) && !empty($context->employee)) {
|
||||||
|
$langId = (int) $context->employee->id_lang;
|
||||||
|
} elseif ($cookie instanceof Cookie) {
|
||||||
|
$langId = (int) $cookie->id_lang;
|
||||||
|
} else {
|
||||||
|
$langId = (int) Configuration::get('PS_LANG_DEFAULT');
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) Language::getIsoById($langId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if corporate customers are enabled in settings
|
* Returns true if corporate customers are enabled in settings
|
||||||
*
|
*
|
||||||
@ -78,6 +100,16 @@ class RetailcrmTools
|
|||||||
return (bool) Configuration::get(RetailCRM::ENABLE_ICML_SERVICES);
|
return (bool) Configuration::get(RetailCRM::ENABLE_ICML_SERVICES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the transfer of company and VAT number is enabled in the settings
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isCampanyAndVatNumberSendEnabled()
|
||||||
|
{
|
||||||
|
return (bool) Configuration::get(RetailCRM::ENABLE_COMPANY_AND_VAT_NUMBER_SEND);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if customer is corporate
|
* Returns true if customer is corporate
|
||||||
*
|
*
|
||||||
@ -969,22 +1001,6 @@ class RetailcrmTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $name
|
|
||||||
*
|
|
||||||
* @return DateTime|false
|
|
||||||
*/
|
|
||||||
public static function getConfigurationCreatedAtByName($name)
|
|
||||||
{
|
|
||||||
$config = self::getConfigurationByName($name);
|
|
||||||
|
|
||||||
if (empty($config)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $config['date_add']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -362,7 +362,7 @@ class RetailcrmApiClientV5
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($entity) || 'customer' != $entity || 'order' != $entity) {
|
if (empty($entity)) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
'Parameter `entity` must contain a data & value must be `order` or `customer`'
|
'Parameter `entity` must contain a data & value must be `order` or `customer`'
|
||||||
);
|
);
|
||||||
|
@ -87,6 +87,13 @@ class RetailcrmSettings
|
|||||||
$changed['consultantScript'] = $this->consultantScript->getValueStored();
|
$changed['consultantScript'] = $this->consultantScript->getValueStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!empty($changed['enableCompanyAndVatNumberSend'])
|
||||||
|
&& !Configuration::get(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED)
|
||||||
|
) {
|
||||||
|
$this->createCompanyAndVatNumberFields();
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => $this->validator->getSuccess(),
|
'success' => $this->validator->getSuccess(),
|
||||||
'errors' => $this->validator->getErrors(),
|
'errors' => $this->validator->getErrors(),
|
||||||
@ -127,4 +134,30 @@ class RetailcrmSettings
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createCompanyAndVatNumberFields()
|
||||||
|
{
|
||||||
|
$api = RetailcrmTools::getApiClient();
|
||||||
|
$locale = RetailcrmTools::getCurrentLanguageISO();
|
||||||
|
$translate = [
|
||||||
|
'ru' => ['company' => 'Компания', 'vat_number' => 'Номер НДС'],
|
||||||
|
'en' => ['company' => 'Company', 'vat_number' => 'VAT number'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$company = $translate[$locale]['company'] ?? 'Empresa';
|
||||||
|
$vatNumber = $translate[$locale]['vat_number'] ?? 'Número de IVA';
|
||||||
|
|
||||||
|
$customFields = [
|
||||||
|
['code' => 'ps_company', 'name' => $company, 'type' => 'string', 'displayArea' => 'customer'],
|
||||||
|
['code' => 'ps_vat_number', 'name' => $vatNumber, 'type' => 'string', 'displayArea' => 'customer'],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (null !== $api) {
|
||||||
|
foreach ($customFields as $field) {
|
||||||
|
$api->customFieldsCreate('order', $field);
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration::updateValue(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ class RetailcrmSettingsItems
|
|||||||
'enableCorporate' => new RetailcrmSettingsItemBool('enableCorporate', RetailCRM::ENABLE_CORPORATE_CLIENTS),
|
'enableCorporate' => new RetailcrmSettingsItemBool('enableCorporate', RetailCRM::ENABLE_CORPORATE_CLIENTS),
|
||||||
'enableOrderNumberSending' => new RetailcrmSettingsItemBool('enableOrderNumberSending', RetailCRM::ENABLE_ORDER_NUMBER_SENDING),
|
'enableOrderNumberSending' => new RetailcrmSettingsItemBool('enableOrderNumberSending', RetailCRM::ENABLE_ORDER_NUMBER_SENDING),
|
||||||
'enableOrderNumberReceiving' => new RetailcrmSettingsItemBool('enableOrderNumberReceiving', RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING),
|
'enableOrderNumberReceiving' => new RetailcrmSettingsItemBool('enableOrderNumberReceiving', RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING),
|
||||||
|
'enableCompanyAndVatNumberSend' => new RetailcrmSettingsItemBool('enableCompanyAndVatNumberSend', RetailCRM::ENABLE_COMPANY_AND_VAT_NUMBER_SEND),
|
||||||
'webJobs' => new RetailcrmSettingsItemBool('webJobs', RetailCRM::ENABLE_WEB_JOBS, '1'),
|
'webJobs' => new RetailcrmSettingsItemBool('webJobs', RetailCRM::ENABLE_WEB_JOBS, '1'),
|
||||||
'debugMode' => new RetailcrmSettingsItemBool('debugMode', RetailCRM::ENABLE_DEBUG_MODE),
|
'debugMode' => new RetailcrmSettingsItemBool('debugMode', RetailCRM::ENABLE_DEBUG_MODE),
|
||||||
|
|
||||||
|
@ -65,28 +65,6 @@ abstract class RetailcrmAbstractTemplate
|
|||||||
$this->assets = $assets;
|
$this->assets = $assets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns ISO code of current employee language or default language.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getCurrentLanguageISO()
|
|
||||||
{
|
|
||||||
$langId = 0;
|
|
||||||
|
|
||||||
global $cookie;
|
|
||||||
|
|
||||||
if (!empty($this->context) && !empty($this->context->employee)) {
|
|
||||||
$langId = (int) $this->context->employee->id_lang;
|
|
||||||
} elseif ($cookie instanceof Cookie) {
|
|
||||||
$langId = (int) $cookie->id_lang;
|
|
||||||
} else {
|
|
||||||
$langId = (int) Configuration::get('PS_LANG_DEFAULT');
|
|
||||||
}
|
|
||||||
|
|
||||||
return (string) Language::getIsoById($langId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $file
|
* @param $file
|
||||||
*
|
*
|
||||||
|
@ -47,7 +47,7 @@ class RetailcrmSettingsTemplate extends RetailcrmAbstractTemplate
|
|||||||
'chunk-vendors' => filemtime(_PS_MODULE_DIR_ . '/retailcrm/views/js/chunk-vendors.js'),
|
'chunk-vendors' => filemtime(_PS_MODULE_DIR_ . '/retailcrm/views/js/chunk-vendors.js'),
|
||||||
],
|
],
|
||||||
'appData' => [
|
'appData' => [
|
||||||
'locale' => $this->getCurrentLanguageISO(),
|
'locale' => RetailcrmTools::getCurrentLanguageISO(),
|
||||||
'debug' => RetailcrmTools::isDebug(),
|
'debug' => RetailcrmTools::isDebug(),
|
||||||
'routes' => [
|
'routes' => [
|
||||||
'settings' => RetailcrmTools::getAdminControllerUrl(RetailcrmSettingsController::class),
|
'settings' => RetailcrmTools::getAdminControllerUrl(RetailcrmSettingsController::class),
|
||||||
|
@ -48,7 +48,7 @@ require_once dirname(__FILE__) . '/bootstrap.php';
|
|||||||
|
|
||||||
class RetailCRM extends Module
|
class RetailCRM extends Module
|
||||||
{
|
{
|
||||||
const VERSION = '3.6.6';
|
const VERSION = '3.6.7';
|
||||||
|
|
||||||
const API_URL = 'RETAILCRM_ADDRESS';
|
const API_URL = 'RETAILCRM_ADDRESS';
|
||||||
const API_KEY = 'RETAILCRM_API_TOKEN';
|
const API_KEY = 'RETAILCRM_API_TOKEN';
|
||||||
@ -72,12 +72,12 @@ class RetailCRM extends Module
|
|||||||
const ENABLE_BALANCES_RECEIVING = 'RETAILCRM_ENABLE_BALANCES_RECEIVING';
|
const ENABLE_BALANCES_RECEIVING = 'RETAILCRM_ENABLE_BALANCES_RECEIVING';
|
||||||
const ENABLE_ORDER_NUMBER_SENDING = 'RETAILCRM_ENABLE_ORDER_NUMBER_SENDING';
|
const ENABLE_ORDER_NUMBER_SENDING = 'RETAILCRM_ENABLE_ORDER_NUMBER_SENDING';
|
||||||
const ENABLE_ORDER_NUMBER_RECEIVING = 'RETAILCRM_ENABLE_ORDER_NUMBER_RECEIVING';
|
const ENABLE_ORDER_NUMBER_RECEIVING = 'RETAILCRM_ENABLE_ORDER_NUMBER_RECEIVING';
|
||||||
|
const ENABLE_COMPANY_AND_VAT_NUMBER_SEND = 'RETAILCRM_ENABLE_COMPANY_AND_VAT_NUMBER_SEND';
|
||||||
|
const COMPANY_AND_VAT_NUMBER_CREATED = 'RETAILCRM_COMPANY_AND_VAT_NUMBER_CREATED';
|
||||||
const ENABLE_DEBUG_MODE = 'RETAILCRM_ENABLE_DEBUG_MODE';
|
const ENABLE_DEBUG_MODE = 'RETAILCRM_ENABLE_DEBUG_MODE';
|
||||||
|
|
||||||
const CONSULTANT_SCRIPT = 'RETAILCRM_CONSULTANT_SCRIPT';
|
const CONSULTANT_SCRIPT = 'RETAILCRM_CONSULTANT_SCRIPT';
|
||||||
const CONSULTANT_RCCT = 'RETAILCRM_CONSULTANT_RCCT';
|
const CONSULTANT_RCCT = 'RETAILCRM_CONSULTANT_RCCT';
|
||||||
const ENABLE_WEB_JOBS = 'RETAILCRM_ENABLE_WEB_JOBS';
|
const ENABLE_WEB_JOBS = 'RETAILCRM_ENABLE_WEB_JOBS';
|
||||||
|
|
||||||
const REQUIRED_CRM_SITE_ACCESS = 'access_selective';
|
const REQUIRED_CRM_SITE_ACCESS = 'access_selective';
|
||||||
const REQUIRED_CRM_SITE_COUNT = 1;
|
const REQUIRED_CRM_SITE_COUNT = 1;
|
||||||
const REQUIRED_CRM_SCOPES = [
|
const REQUIRED_CRM_SCOPES = [
|
||||||
@ -343,6 +343,7 @@ class RetailCRM extends Module
|
|||||||
&& Configuration::deleteByName(static::ENABLE_BALANCES_RECEIVING)
|
&& Configuration::deleteByName(static::ENABLE_BALANCES_RECEIVING)
|
||||||
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_SENDING)
|
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_SENDING)
|
||||||
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_RECEIVING)
|
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_RECEIVING)
|
||||||
|
&& Configuration::deleteByName(static::ENABLE_COMPANY_AND_VAT_NUMBER_SEND)
|
||||||
&& Configuration::deleteByName(static::ENABLE_DEBUG_MODE)
|
&& Configuration::deleteByName(static::ENABLE_DEBUG_MODE)
|
||||||
&& Configuration::deleteByName(static::ENABLE_WEB_JOBS)
|
&& Configuration::deleteByName(static::ENABLE_WEB_JOBS)
|
||||||
&& Configuration::deleteByName('RETAILCRM_LAST_SYNC')
|
&& Configuration::deleteByName('RETAILCRM_LAST_SYNC')
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user