mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-04-11 12:50:55 +00:00
Create custom fields in CRM
This commit is contained in:
parent
d3f5a8cebc
commit
999544f416
8 changed files with 75 additions and 29 deletions
|
@ -1235,10 +1235,10 @@ class RetailcrmHistory
|
|||
$addressBuilder = new RetailcrmCustomerAddressBuilder();
|
||||
$address = $addressBuilder
|
||||
->setIdCustomer($customer->id)
|
||||
->setDataCrm(isset($order['delivery']['address']) ? $order['delivery']['address'] : [])
|
||||
->setFirstName(isset($order['firstName']) ? $order['firstName'] : null)
|
||||
->setLastName(isset($order['lastName']) ? $order['lastName'] : null)
|
||||
->setPhone(isset($order['phone']) ? $order['phone'] : null)
|
||||
->setDataCrm($order['delivery']['address'] ?? [])
|
||||
->setFirstName($order['firstName'] ?? null)
|
||||
->setLastName($order['lastName'] ?? null)
|
||||
->setPhone($order['phone'] ?? null)
|
||||
->build()
|
||||
->getData()
|
||||
;
|
||||
|
|
|
@ -985,7 +985,19 @@ class RetailcrmOrderBuilder
|
|||
? 'legal-entity'
|
||||
: 'individual';
|
||||
|
||||
if (!$isCorporateEnabled && RetailcrmTools::isCampanyAndVatNumberSendEnabled()) {
|
||||
if ($addressInvoice instanceof Address && !empty($addressInvoice->company)) {
|
||||
$crmOrder['contragent']['legalName'] = $addressInvoice->company;
|
||||
|
||||
if (!empty($addressInvoice->vat_number)) {
|
||||
$crmOrder['contragent']['INN'] = $addressInvoice->vat_number;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!$isCorporateEnabled
|
||||
&& RetailcrmTools::isCampanyAndVatNumberSendEnabled()
|
||||
&& Configuration::get(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED)
|
||||
) {
|
||||
$company = $addressDelivery->company;
|
||||
$vatNumber = $addressDelivery->vat_number;
|
||||
|
||||
|
|
|
@ -58,6 +58,28 @@ class RetailcrmTools
|
|||
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
|
||||
*
|
||||
|
|
|
@ -362,7 +362,7 @@ class RetailcrmApiClientV5
|
|||
);
|
||||
}
|
||||
|
||||
if (empty($entity) || 'customer' != $entity || 'order' != $entity) {
|
||||
if (empty($entity)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Parameter `entity` must contain a data & value must be `order` or `customer`'
|
||||
);
|
||||
|
|
|
@ -87,6 +87,13 @@ class RetailcrmSettings
|
|||
$changed['consultantScript'] = $this->consultantScript->getValueStored();
|
||||
}
|
||||
|
||||
if (
|
||||
!empty($changed['enableCompanyAndVatNumberSend'])
|
||||
&& !Configuration::get(RetailCRM::COMPANY_AND_VAT_NUMBER_CREATED)
|
||||
) {
|
||||
$this->createCompanyAndVatNumberFields();
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => $this->validator->getSuccess(),
|
||||
'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'] ?? 'Firma';
|
||||
$vatNumber = $translate[$locale]['vat_number'] ?? 'CVR-nummer';
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,28 +65,6 @@ abstract class RetailcrmAbstractTemplate
|
|||
$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
|
||||
*
|
||||
|
|
|
@ -47,7 +47,7 @@ class RetailcrmSettingsTemplate extends RetailcrmAbstractTemplate
|
|||
'chunk-vendors' => filemtime(_PS_MODULE_DIR_ . '/retailcrm/views/js/chunk-vendors.js'),
|
||||
],
|
||||
'appData' => [
|
||||
'locale' => $this->getCurrentLanguageISO(),
|
||||
'locale' => RetailcrmTools::getCurrentLanguageISO(),
|
||||
'debug' => RetailcrmTools::isDebug(),
|
||||
'routes' => [
|
||||
'settings' => RetailcrmTools::getAdminControllerUrl(RetailcrmSettingsController::class),
|
||||
|
|
|
@ -73,6 +73,7 @@ class RetailCRM extends Module
|
|||
const ENABLE_ORDER_NUMBER_SENDING = 'RETAILCRM_ENABLE_ORDER_NUMBER_SENDING';
|
||||
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 CONSULTANT_SCRIPT = 'RETAILCRM_CONSULTANT_SCRIPT';
|
||||
const CONSULTANT_RCCT = 'RETAILCRM_CONSULTANT_RCCT';
|
||||
|
|
Loading…
Add table
Reference in a new issue