restruct & custom

This commit is contained in:
Alex Lushpai 2015-07-21 15:21:12 +03:00
parent 956414d08a
commit 22ba5c906a
9 changed files with 434 additions and 419 deletions

13
CHANGELOG.md Normal file
View File

@ -0,0 +1,13 @@
Changelog
=========
v0.2
* Ребрендинг, intarocrm заменено на retailcrm
* Обновлена библиотека api-client-php
* Сборка через composer больше надоступна, все необходимые файлы включены в основноую поставку
* Добавлен механизм кастомизации
* Добавлены переводы
* Генерация ICML перенесена с контроллера на cron для более эффективного использования ресурсов
* Устранен раяд ошибок

View File

@ -1,32 +1,31 @@
Prestashop module
=============
=================
Prestashop module for interaction with [IntaroCRM](http://www.intarocrm.com) through [REST API](http://docs.intarocrm.ru/rest-api/).
Модуль интеграции CMS Prestashop c [RetailCRM](http://www.retailcrm.com)
Module allows:
Модуль позволяет:
* Send to IntaroCRM new orders
* Configure relations between dictionaries of IntaroCRM and Prestashop (statuses, payments, delivery types and etc)
* Generate [ICML](http://docs.intarocrm.ru/index.php?n=Пользователи.ФорматICML) (IntaroCRM Markup Language) for catalog loading by IntaroCRM
* Экспортировать в CRM заказы
* Синхронизировать справочники (способы доставки и оплаты, статусы заказов и т.п.)
* Выгружать каталог товаров в формате [ICML](http://retailcrm.ru/docs/Разработчики/ФорматICML) (IntaroCRM Markup Language)
Installation
Установка
-------------
### 1. Manual installation
### 1. Ручная установка
#### Clone module.
#### Скопируйте модуль
```
git clone git@github.com:/intarocrm/prestashop-module.git
```
#### Create .zip file.
#### Создайте загружаемый .zip архив.
```
cd prestashop-module
zip -r retailcrm.zip retailcrm
```
#### Install via Admin interface.
#### Установите через административный интерфейс управления модулями.
Go to Modules -> Add module. After that upload your zipped module and activate it.
![Установка модуля](/docs/images/add.png)

BIN
docs/images/add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,210 @@
<?php
class References
{
public function __construct($client)
{
$this->api = $client;
$this->default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
$this->default_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
$this->default_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
}
public function getDeliveryTypes()
{
$deliveryTypes = array();
$carriers = Carrier::getCarriers(
$this->default_lang, true, false, false,
null, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE
);
if (!empty($carriers)) {
foreach ($carriers as $carrier) {
$deliveryTypes[] = array(
'type' => 'select',
'label' => $carrier['name'],
'name' => 'RETAILCRM_API_DELIVERY[' . $carrier['id_carrier'] . ']',
'required' => false,
'options' => array(
'query' => $this->getApiDeliveryTypes(),
'id' => 'id_option',
'name' => 'name'
)
);
}
}
return $deliveryTypes;
}
public function getStatuses()
{
$statusTypes = array();
$states = array_merge(
OrderState::getOrderStates($this->default_lang, true),
OrderReturnState::getOrderReturnStates($this->default_lang, true)
);
if (!empty($states)) {
foreach ($states as $state) {
if ($state['name'] != ' ') {
$statusTypes[] = array(
'type' => 'select',
'label' => $state['name'],
'name' => 'RETAILCRM_API_STATUS[' . $state['id_order_state'] . ']',
'required' => false,
'options' => array(
'query' => $this->getApiStatuses(),
'id' => 'id_option',
'name' => 'name'
)
);
}
}
}
return $statusTypes;
}
public function getPaymentTypes()
{
$payments = $this->getSystemPaymentModules();
$paymentTypes = array();
if (!empty($payments)) {
foreach ($payments as $payment) {
$paymentTypes[] = array(
'type' => 'select',
'label' => $payment['name'],
'name' => 'RETAILCRM_API_PAYMENT[' . $payment['code'] . ']',
'required' => false,
'options' => array(
'query' => $this->getApiPaymentTypes(),
'id' => 'id_option',
'name' => 'name'
)
);
}
}
return $paymentTypes;
}
protected function getSystemPaymentModules()
{
$shop_id = Context::getContext()->shop->id;
/* Get all modules then select only payment ones */
$modules = Module::getModulesOnDisk(true);
foreach ($modules as $module) {
if ($module->tab == 'payments_gateways') {
if ($module->id) {
if (!get_class($module) == 'SimpleXMLElement') $module->country = array();
$countries = DB::getInstance()->executeS('SELECT id_country FROM ' . _DB_PREFIX_ . 'module_country WHERE id_module = ' . (int) $module->id . ' AND `id_shop`=' . (int) $shop_id);
foreach ($countries as $country) $module->country[] = $country['id_country'];
if (!get_class($module) == 'SimpleXMLElement') $module->currency = array();
$currencies = DB::getInstance()->executeS('SELECT id_currency FROM ' . _DB_PREFIX_ . 'module_currency WHERE id_module = ' . (int) $module->id . ' AND `id_shop`=' .(int) $shop_id);
foreach ($currencies as $currency) $module->currency[] = $currency['id_currency'];
if (!get_class($module) == 'SimpleXMLElement') $module->group = array();
$groups = DB::getInstance()->executeS('SELECT id_group FROM ' . _DB_PREFIX_ . 'module_group WHERE id_module = ' . (int) $module->id . ' AND `id_shop`=' . (int) $shop_id);
foreach ($groups as $group) $module->group[] = $group['id_group'];
} else {
$module->country = null;
$module->currency = null;
$module->group = null;
}
if ($module->active != 0) {
$this->payment_modules[] = array(
'id' => $module->id,
'code' => $module->name,
'name' => $module->displayName
);
}
}
}
return $this->payment_modules;
}
protected function getApiDeliveryTypes()
{
$crmDeliveryTypes = array();
try {
$request = $this->api->deliveryTypesList();
if ($request->isSuccessful()) {
$crmDeliveryTypes[] = array();
foreach ($request->deliveryTypes as $dType) {
$crmDeliveryTypes[] = array(
'id_option' => $dType['code'],
'name' => $dType['name'],
);
}
}
}
catch (CurlException $e) {
error_log('deliveryTypesList: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (InvalidJsonException $e) {
error_log('deliveryTypesList: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
return $crmDeliveryTypes;
}
protected function getApiStatuses()
{
$crmStatusTypes = array();
try {
$request = $this->api->statusesList();
if ($request->isSuccessful()) {
$crmStatusTypes[] = array();
foreach ($request->statuses as $sType) {
$crmStatusTypes[] = array(
'id_option' => $sType['code'],
'name' => $sType['name']
);
}
}
}
catch (CurlException $e) {
error_log('statusTypesList: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (InvalidJsonException $e) {
error_log('statusTypesList: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
return $crmStatusTypes;
}
protected function getApiPaymentTypes()
{
$crmPaymentTypes = array();
try {
$request = $this->api->paymentTypesList();
if ($request->isSuccessful()) {
$crmPaymentTypes[] = array();
foreach ($request->paymentTypes as $pType) {
$crmPaymentTypes[] = array(
'id_option' => $pType['code'],
'name' => $pType['name']
);
}
}
}
catch (CurlException $e) {
error_log('paymentTypesList: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (InvalidJsonException $e) {
error_log('paymentTypesList: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
return $crmPaymentTypes;
}
}

13
retailcrm/config_ru.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>retailcrm</name>
<displayName><![CDATA[RetailCRM]]></displayName>
<version><![CDATA[0.2]]></version>
<description><![CDATA[Модуль инграции с RetailCRM]]></description>
<author><![CDATA[Retail Driver LCC]]></author>
<tab><![CDATA[market_place]]></tab>
<confirmUninstall><![CDATA[Вы уверены, что хотите удалить модуль?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>

View File

@ -4,6 +4,12 @@ require 'classes/Retailcrm.php';
require 'classes/Service.php';
require 'classes/Icml.php';
if (file_exists('classes/ReferencesCustom.php')) {
require 'classes/ReferencesCustom.php';
} else {
require 'classes/References.php';
}
if (!defined('_PS_VERSION_')) {
exit;
}
@ -31,9 +37,9 @@ class RetailCRM extends Module
);
}
$this->default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$this->default_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT');
$this->default_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
$this->default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
$this->default_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
$this->default_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
$this->response = array();
$this->customerFix = array();
@ -44,6 +50,8 @@ class RetailCRM extends Module
$this->customer = null;
$this->ref = new References($this->api);
parent::__construct();
}
@ -78,9 +86,9 @@ class RetailCRM extends Module
$token = Configuration::get('RETAILCRM_API_TOKEN');
if (!$address || $address == '') {
$output .= $this->displayError( $this->l('Invalid crm address') );
$output .= $this->displayError( $this->l('Invalid or empty crm address') );
} elseif (!$token || $token == '') {
$output .= $this->displayError( $this->l('Invalid crm api token') );
$output .= $this->displayError( $this->l('Invalid or empty crm api token') );
} else {
$output .= $this->displayConfirmation(
$this->l('Timezone settings must be identical to both of your crm and shop') .
@ -162,7 +170,7 @@ class RetailCRM extends Module
'legend' => array(
'title' => $this->l('Delivery'),
),
'input' => $this->getDeliveryTypes(),
'input' => $this->ref->getDeliveryTypes(),
);
/*
@ -172,7 +180,7 @@ class RetailCRM extends Module
'legend' => array(
'title' => $this->l('Order statuses'),
),
'input' => $this->getStatusTypes(),
'input' => $this->ref->getStatuses(),
);
/*
@ -182,7 +190,7 @@ class RetailCRM extends Module
'legend' => array(
'title' => $this->l('Payment types'),
),
'input' => $this->getPaymentTypes(),
'input' => $this->ref->getPaymentTypes(),
);
}
@ -295,7 +303,7 @@ class RetailCRM extends Module
public function hookActionOrderStatusPostUpdate($params)
{
$address_id = Address::getFirstCustomerAddressId($params['cart']->id_customer);
$sql = 'SELECT * FROM '._DB_PREFIX_.'address WHERE id_address='.(int)$address_id;
$sql = 'SELECT * FROM '._DB_PREFIX_.'address WHERE id_address='.(int) $address_id;
$address = Db::getInstance()->ExecuteS($sql);
$address = $address[0];
$delivery = json_decode(Configuration::get('RETAILCRM_API_DELIVERY'));
@ -410,349 +418,11 @@ class RetailCRM extends Module
}
}
protected function getApiDeliveryTypes()
{
$crmDeliveryTypes = array();
if (!empty($this->apiUrl) && !empty($this->apiKey)) {
try {
$deliveryTypes = $this->api->deliveryTypesList();
}
catch (CurlException $e) {
error_log('deliveryTypesList: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (InvalidJsonException $e) {
error_log('deliveryTypesList: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
if (!empty($deliveryTypes)) {
$crmDeliveryTypes[] = array();
foreach ($deliveryTypes as $dType) {
$crmDeliveryTypes[] = array(
'id_option' => $dType['code'],
'name' => $dType['name'],
);
}
}
}
return $crmDeliveryTypes;
}
protected function getDeliveryTypes()
{
$deliveryTypes = array();
$carriers = Carrier::getCarriers(
$this->default_lang, true, false, false,
null, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE
);
if (!empty($carriers)) {
foreach ($carriers as $carrier) {
$deliveryTypes[] = array(
'type' => 'select',
'label' => $carrier['name'],
'name' => 'RETAILCRM_API_DELIVERY[' . $carrier['id_carrier'] . ']',
'required' => false,
'options' => array(
'query' => $this->getApiDeliveryTypes(),
'id' => 'id_option',
'name' => 'name'
)
);
}
}
return $deliveryTypes;
}
protected function getApiStatuses()
{
$crmStatusTypes = array();
if (!empty($this->apiUrl) && !empty($this->apiKey)) {
try {
$statusTypes = $this->api->statusesList();
}
catch (CurlException $e) {
error_log('statusTypesList: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (InvalidJsonException $e) {
error_log('statusTypesList: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
if (!empty($statusTypes)) {
$crmStatusTypes[] = array();
foreach ($statusTypes as $sType) {
$crmStatusTypes[] = array(
'id_option' => $sType['code'],
'name' => $sType['name']
);
}
}
}
return $crmStatusTypes;
}
protected function getStatusTypes()
{
$statusTypes = array();
$states = OrderState::getOrderStates($this->default_lang, true);
if (!empty($states)) {
foreach ($states as $state) {
if ($state['name'] != ' ') {
$statusTypes[] = array(
'type' => 'select',
'label' => $state['name'],
'name' => 'RETAILCRM_API_STATUS[' . $state['id_order_state'] . ']',
'required' => false,
'options' => array(
'query' => $this->getApiStatuses(),
'id' => 'id_option',
'name' => 'name'
)
);
}
}
}
return $statusTypes;
}
protected function getApiPaymentTypes()
{
$crmPaymentTypes = array();
if (!empty($this->apiUrl) && !empty($this->apiKey)) {
try {
$paymentTypes = $this->api->paymentTypesList();
}
catch (CurlException $e) {
error_log('paymentTypesList: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (InvalidJsonException $e) {
error_log('paymentTypesList: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
if (!empty($paymentTypes)) {
$crmPaymentTypes[] = array();
foreach ($paymentTypes as $pType) {
$crmPaymentTypes[] = array(
'id_option' => $pType['code'],
'name' => $pType['name']
);
}
}
}
return $crmPaymentTypes;
}
protected function getPaymentTypes()
{
$payments = $this->getSystemPaymentModules();
$paymentTypes = array();
if (!empty($payments)) {
foreach ($payments as $payment) {
$paymentTypes[] = array(
'type' => 'select',
'label' => $payment['name'],
'name' => 'RETAILCRM_API_PAYMENT[' . $payment['code'] . ']',
'required' => false,
'options' => array(
'query' => $this->getApiPaymentTypes(),
'id' => 'id_option',
'name' => 'name'
)
);
}
}
return $paymentTypes;
}
protected function getSystemPaymentModules()
{
$shop_id = Context::getContext()->shop->id;
/* Get all modules then select only payment ones */
$modules = Module::getModulesOnDisk(true);
/*
* Hack for knivesland
*/
if (Module::getInstanceByName('advancedcheckout') === false) {
foreach ($modules as $module) {
if ($module->tab == 'payments_gateways')
{
if ($module->id)
{
if (!get_class($module) == 'SimpleXMLElement')
$module->country = array();
$countries = DB::getInstance()->executeS('
SELECT id_country
FROM '._DB_PREFIX_.'module_country
WHERE id_module = '.(int)$module->id.' AND `id_shop`='.(int)$shop_id
);
foreach ($countries as $country)
$module->country[] = $country['id_country'];
if (!get_class($module) == 'SimpleXMLElement')
$module->currency = array();
$currencies = DB::getInstance()->executeS('
SELECT id_currency
FROM '._DB_PREFIX_.'module_currency
WHERE id_module = '.(int)$module->id.' AND `id_shop`='.(int)$shop_id
);
foreach ($currencies as $currency)
$module->currency[] = $currency['id_currency'];
if (!get_class($module) == 'SimpleXMLElement')
$module->group = array();
$groups = DB::getInstance()->executeS('
SELECT id_group
FROM '._DB_PREFIX_.'module_group
WHERE id_module = '.(int)$module->id.' AND `id_shop`='.(int)$shop_id
);
foreach ($groups as $group)
$module->group[] = $group['id_group'];
}
else
{
$module->country = null;
$module->currency = null;
$module->group = null;
}
if ($module->active != 0) {
$this->payment_modules[] = array(
'id' => $module->id,
'code' => $module->name,
'name' => $module->displayName
);
}
}
}
} else {
require_once(dirname(__FILE__) . '/../advancedcheckout/classes/Payment.php');
$modules = Payment::getPaymentMethods();
foreach ($modules as $module) {
$this->payment_modules[] = array(
'id' => $module['id_payment'],
'code' => $module['name'],
'name' => $module['name']
);
}
}
return $this->payment_modules;
}
protected function getAddressFields()
{
$addressFields = array();
$address = explode(' ', str_replace("\n", ' ', AddressFormat::getAddressCountryFormat($this->context->country->id)));
if (!empty($address)) {
foreach ($address as $idx => $a) {
if (!strpos($a, ':')) {
$addressFields[] = array(
'type' => 'select',
'label' => $this->l((string)$a),
'name' => 'RETAILCRM_API_ADDR[' . $idx . ']',
'required' => false,
'options' => array(
'query' => array(
array(
'name' => '',
'id_option' => ''
),
array(
'name' => $this->l('FIRST_NAME'),
'id_option' => 'first_name'
),
array(
'name' => $this->l('LAST_NAME'),
'id_option' => 'last_name'
),
array(
'name' => $this->l('PHONE'),
'id_option' => 'phone'
),
array(
'name' => $this->l('EMAIL'),
'id_option' => 'email'
),
array(
'name' => $this->l('ADDRESS'),
'id_option' => 'address'
),
array(
'name' => $this->l('COUNTRY'),
'id_option' => 'country'
),
array(
'name' => $this->l('REGION'),
'id_option' => 'region'
),
array(
'name' => $this->l('CITY'),
'id_option' => 'city'
),
array(
'name' => $this->l('ZIP'),
'id_option' => 'index'
),
array(
'name' => $this->l('STREET'),
'id_option' => 'street'
),
array(
'name' => $this->l('BUILDING'),
'id_option' => 'building'
),
array(
'name' => $this->l('FLAT'),
'id_option' => 'flat'
),
array(
'name' => $this->l('INTERCOMCODE'),
'id_option' => 'intercomcode'
),
array(
'name' => $this->l('FLOOR'),
'id_option' => 'floor'
),
array(
'name' => $this->l('BLOCK'),
'id_option' => 'block'
),
array(
'name' => $this->l('HOUSE'),
'ID' => 'house'
)
),
'id' => 'id_option',
'name' => 'name'
)
);
}
}
}
return $addressFields;
}
public function exportCatalog()
{
global $smarty;
$shop_url = (Configuration::get('PS_SSL_ENABLED') ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_);
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
if ($currency->iso_code == 'RUB') {
$currency->iso_code = 'RUR';
@ -952,9 +622,9 @@ class RetailCRM extends Module
$cart->id_currency = $this->default_currency;
$cart->id_lang = $this->default_lang;
$cart->id_customer = $this->customer_id;
$cart->id_address_delivery = (int)$this->address_id;
$cart->id_address_invoice = (int)$this->address_id;
$cart->id_carrier = (int)$deliveries[$delivery];
$cart->id_address_delivery = (int) $this->address_id;
$cart->id_address_invoice = (int) $this->address_id;
$cart->id_carrier = (int) $deliveries[$delivery];
$cart->add();
@ -962,9 +632,9 @@ class RetailCRM extends Module
if(!empty($order['items'])) {
foreach ($order['items'] as $item) {
$product = array();
$product['id_product'] = (int)$item['offer']['externalId'];
$product['id_product'] = (int) $item['offer']['externalId'];
$product['quantity'] = $item['quantity'];
$product['id_address_delivery'] = (int)$this->address_id;
$product['id_address_delivery'] = (int) $this->address_id;
$products[] = $product;
}
}
@ -977,13 +647,13 @@ class RetailCRM extends Module
*/
$newOrder = new Order();
$newOrder->id_address_delivery = (int)$this->address_id;
$newOrder->id_address_invoice = (int)$this->address_id;
$newOrder->id_cart = (int)$cart->id;
$newOrder->id_address_delivery = (int) $this->address_id;
$newOrder->id_address_invoice = (int) $this->address_id;
$newOrder->id_cart = (int) $cart->id;
$newOrder->id_currency = $this->default_currency;
$newOrder->id_lang = $this->default_lang;
$newOrder->id_customer = (int)$this->customer_id;
$newOrder->id_carrier = (int)$deliveries[$delivery];
$newOrder->id_customer = (int) $this->customer_id;
$newOrder->id_carrier = (int) $deliveries[$delivery];
$newOrder->payment = $payments[$payment];
$newOrder->module = (Module::getInstanceByName('advancedcheckout') === false)
? $payments[$payment]
@ -999,7 +669,7 @@ class RetailCRM extends Module
$newOrder->total_shipping_tax_incl = $order['deliveryCost'];
$newOrder->total_shipping_tax_excl = $order['deliveryCost'];
$newOrder->conversion_rate = 1.000000;
$newOrder->current_state = (int)$statuses[$state];
$newOrder->current_state = (int) $statuses[$state];
$newOrder->delivery_date = $order['deliveryDate'];
$newOrder->date_add = $order['createdAt'];
$newOrder->date_upd = $order['createdAt'];
@ -1029,7 +699,7 @@ class RetailCRM extends Module
*/
$product_list = array();
foreach ($order['items'] as $item) {
$product = new Product((int)$item['offer']['externalId'], false, $this->default_lang);
$product = new Product((int) $item['offer']['externalId'], false, $this->default_lang);
$qty = $item['quantity'];
$product_list[] = array('product' =>$product, 'quantity' => $qty);
}
@ -1046,14 +716,14 @@ class RetailCRM extends Module
foreach ($product_list as $product) {
$query .= '('
.(int)$newOrder->id.',
.(int) $newOrder->id.',
0,
'. $this->context->shop->id.',
'.(int)$product['product']->id.',
'.(int) $product['product']->id.',
0,
'.implode('', array('\'', $product['product']->name, '\'')).',
'.(int)$product['quantity'].',
'.(int)$product['quantity'].',
'.(int) $product['quantity'].',
'.(int) $product['quantity'].',
'.$product['product']->price.',
'.implode('', array('\'', $product['product']->reference, '\'')).',
'.$product['product']->price.',
@ -1087,7 +757,7 @@ class RetailCRM extends Module
*/
$toUpdate[] = $order['id'];
if ($order['paymentType'] != null && $order['deliveryType'] != null && $order['status'] != null) {
$orderToUpdate = new Order((int)$order['externalId']);
$orderToUpdate = new Order((int) $order['externalId']);
/*
* check status
@ -1098,7 +768,7 @@ class RetailCRM extends Module
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'orders`
SET `current_state` = \''.$statuses[$stype].'\'
WHERE `id_order` = '.(int)$order['externalId']);
WHERE `id_order` = '.(int) $order['externalId']);
}
}
@ -1111,7 +781,7 @@ class RetailCRM extends Module
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'orders`
SET `id_carrier` = \''.$deliveries[$dtype].'\'
WHERE `id_order` = '.(int)$order['externalId']);
WHERE `id_order` = '.(int) $order['externalId']);
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'order_carrier`
SET `id_carrier` = \''.$deliveries[$dtype].'\'
@ -1128,7 +798,7 @@ class RetailCRM extends Module
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'orders`
SET `payment` = \''.$payments[$ptype].'\'
WHERE `id_order` = '.(int)$order['externalId']);
WHERE `id_order` = '.(int) $order['externalId']);
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'order_payment`
SET `payment_method` = \''.$payments[$ptype].'\'
@ -1180,7 +850,7 @@ class RetailCRM extends Module
*/
if (!empty($order['items'])) {
foreach ($order['items'] as $key => $newItem) {
$product = new Product((int)$newItem['offer']['externalId'], false, $this->default_lang);
$product = new Product((int) $newItem['offer']['externalId'], false, $this->default_lang);
$qty = $newItem['quantity'];
$product_list[] = array('product' =>$product, 'quantity' => $qty);
}
@ -1198,14 +868,14 @@ class RetailCRM extends Module
foreach ($product_list as $product) {
$query .= '('
.(int)$orderToUpdate->id.',
.(int) $orderToUpdate->id.',
0,
'. $this->context->shop->id.',
'.(int)$product['product']->id.',
'.(int) $product['product']->id.',
0,
'.implode('', array('\'', $product['product']->name, '\'')).',
'.(int)$product['quantity'].',
'.(int)$product['quantity'].',
'.(int) $product['quantity'].',
'.(int) $product['quantity'].',
'.$product['product']->price.',
'.implode('', array('\'', $product['product']->reference, '\'')).',
'.$product['product']->price.',
@ -1251,7 +921,7 @@ class RetailCRM extends Module
`total_paid` = '.$orderTotal.',
`total_paid_tax_incl` = '.$orderTotal.',
`total_paid_tax_excl` = '.$orderTotal.'
WHERE `id_order` = '.(int)$order['externalId']);
WHERE `id_order` = '.(int) $order['externalId']);
}
}
}
@ -1281,4 +951,101 @@ class RetailCRM extends Module
}
}
public function getAddressFields()
{
$addressFields = array();
$address = explode(' ', str_replace("\n", ' ', AddressFormat::getAddressCountryFormat($this->context->country->id)));
if (!empty($address)) {
foreach ($address as $idx => $a) {
if (!strpos($a, ':')) {
$a = preg_replace('/_/', ' ', $a);
$a = preg_replace('/[\,\.]/', '', $a);
$addressFields[] = array(
'type' => 'select',
'label' => $this->l((string) ucfirst($a)),
'name' => 'RETAILCRM_API_ADDR[' . $idx . ']',
'required' => false,
'options' => array(
'query' => array(
array(
'name' => '',
'id_option' => ''
),
array(
'name' => $this->l('FIRST_NAME'),
'id_option' => 'first_name'
),
array(
'name' => $this->l('LAST_NAME'),
'id_option' => 'last_name'
),
array(
'name' => $this->l('PHONE'),
'id_option' => 'phone'
),
array(
'name' => $this->l('EMAIL'),
'id_option' => 'email'
),
array(
'name' => $this->l('ADDRESS'),
'id_option' => 'address'
),
array(
'name' => $this->l('COUNTRY'),
'id_option' => 'country'
),
array(
'name' => $this->l('REGION'),
'id_option' => 'region'
),
array(
'name' => $this->l('CITY'),
'id_option' => 'city'
),
array(
'name' => $this->l('ZIP'),
'id_option' => 'index'
),
array(
'name' => $this->l('STREET'),
'id_option' => 'street'
),
array(
'name' => $this->l('BUILDING'),
'id_option' => 'building'
),
array(
'name' => $this->l('FLAT'),
'id_option' => 'flat'
),
array(
'name' => $this->l('INTERCOMCODE'),
'id_option' => 'intercomcode'
),
array(
'name' => $this->l('FLOOR'),
'id_option' => 'floor'
),
array(
'name' => $this->l('BLOCK'),
'id_option' => 'block'
),
array(
'name' => $this->l('HOUSE'),
'ID' => 'house'
)
),
'id' => 'id_option',
'name' => 'name'
)
);
}
}
}
return $addressFields;
}
}

View File

@ -2,35 +2,48 @@
global $_MODULE;
$_MODULE = array();
$_MODULE['<{intarocrm}prestashop>intarocrm_03c4d9465b9b3a7533d18cacc79c7fe4'] = 'IntaroCRM';
$_MODULE['<{intarocrm}prestashop>intarocrm_5e695dc9fe273b7bc074e608113f4662'] = 'Модуль интеграции с IntaroCRM';
$_MODULE['<{intarocrm}prestashop>intarocrm_876f23178c29dc2552c0b48bf23cd9bd'] = 'Вы уверены, что хотите удалить модуль?';
$_MODULE['<{intarocrm}prestashop>intarocrm_5effd5157947e8ba4a08883f198b2e31'] = 'Неверный адрес CRM';
$_MODULE['<{intarocrm}prestashop>intarocrm_576300f5b6faeb746bb6d034d98e7afd'] = 'Неверный API ключ';
$_MODULE['<{intarocrm}prestashop>intarocrm_fba05687b61bc936d1a9a92371ba8bcf'] = 'Внимание! Часовой пояс в CRM должен совпадать с часовым поясом в магазине, настроки часового пояса CRM можно задать по адресу:';
$_MODULE['<{intarocrm}prestashop>intarocrm_c888438d14855d7d96a2724ee9c306bd'] = 'Настройки обновлены';
$_MODULE['<{intarocrm}prestashop>intarocrm_51af428aa0dcceb5230acb267ecb91c5'] = 'Настройка соединения';
$_MODULE['<{intarocrm}prestashop>intarocrm_4cbd5dbeeef7392e50358b1bc00dd592'] = 'Адрес CRM';
$_MODULE['<{intarocrm}prestashop>intarocrm_7f775042e08eddee6bbfd8fbe0add4a3'] = 'Ключ авторизации';
$_MODULE['<{intarocrm}prestashop>intarocrm_c9cc8cce247e49bae79f15173ce97354'] = 'Сохранить';
$_MODULE['<{intarocrm}prestashop>intarocrm_065ab3a28ca4f16f55f103adc7d0226f'] = 'Способы доставки';
$_MODULE['<{intarocrm}prestashop>intarocrm_33af8066d3c83110d4bd897f687cedd2'] = 'Статусы заказов';
$_MODULE['<{intarocrm}prestashop>intarocrm_bab959acc06bb03897b294fbb892be6b'] = 'Способы оплаты';
$_MODULE['<{intarocrm}prestashop>intarocrm_dd7bf230fde8d4836917806aff6a6b27'] = 'Адрес';
$_MODULE['<{intarocrm}prestashop>intarocrm_630f6dc397fe74e52d5189e2c80f282b'] = 'Вернуться к списку';
$_MODULE['<{intarocrm}prestashop>intarocrm_5c1cf6cfec2dad86c8ca5286a0294516'] = 'Имя';
$_MODULE['<{intarocrm}prestashop>intarocrm_c695cfe527a6fcd680114851b86b7555'] = 'Фамилия';
$_MODULE['<{intarocrm}prestashop>intarocrm_f9dd946cc89c1f3b41a0edbe0f36931d'] = 'Телефон';
$_MODULE['<{intarocrm}prestashop>intarocrm_61a649a33f2869e5e35fbb7aff3a80d9'] = 'Email';
$_MODULE['<{intarocrm}prestashop>intarocrm_2664f03ac6b8bb9eee4287720e407db3'] = 'Адрес';
$_MODULE['<{intarocrm}prestashop>intarocrm_6ddc09dc456001d9854e9fe670374eb2'] = 'Страна';
$_MODULE['<{intarocrm}prestashop>intarocrm_69aede266809f89b89fe70681f6a129f'] = 'Область/Край/Республика';
$_MODULE['<{intarocrm}prestashop>intarocrm_859214628431995197c0558f7b5f8ffc'] = 'Город';
$_MODULE['<{intarocrm}prestashop>intarocrm_4348f938bbddd8475e967ccb47ecb234'] = 'Почтовый индекс';
$_MODULE['<{intarocrm}prestashop>intarocrm_78fce82336bbbdca7f6da7564b8f9325'] = 'Улица';
$_MODULE['<{intarocrm}prestashop>intarocrm_71a6834884666147c0334f0c40bc7295'] = 'Дом/Строение';
$_MODULE['<{intarocrm}prestashop>intarocrm_f88a77e3d68d251c3dc4008c327b5a0c'] = 'Квартира';
$_MODULE['<{intarocrm}prestashop>intarocrm_d977f846d110fcb7f71c6f97330c9d10'] = 'Код домофона';
$_MODULE['<{intarocrm}prestashop>intarocrm_56c1e354d36beb85b0d881c5b2e24cbe'] = 'Этаж';
$_MODULE['<{intarocrm}prestashop>intarocrm_4d34f53389ed7f28ca91fc31ea360a66'] = 'Корпус';
$_MODULE['<{intarocrm}prestashop>intarocrm_49354b452ec305136a56fe7731834156'] = 'Дом/Строение';
$_MODULE['<{retailcrm}prestashop>retailcrm_463dc31aa1a0b6e871b1a9fed8e9860a'] = 'RetailCRM';
$_MODULE['<{retailcrm}prestashop>retailcrm_30de6237576b9a24f6fc599c22a35a4b'] = 'Модуль интеграции с RetailCRM';
$_MODULE['<{retailcrm}prestashop>retailcrm_876f23178c29dc2552c0b48bf23cd9bd'] = 'Вы уверены, что хотите удалить модуль?';
$_MODULE['<{retailcrm}prestashop>retailcrm_b9b2d9f66d0112f3aae7dbdbd4e22a43'] = 'Некорректный или пустой адрес CRM';
$_MODULE['<{retailcrm}prestashop>retailcrm_942010ef43f3fec28741f62a0d9ff29c'] = 'Некорректный или пустой ключ CRM';
$_MODULE['<{retailcrm}prestashop>retailcrm_fba05687b61bc936d1a9a92371ba8bcf'] = 'Внимание! Часовой пояс в CRM должен совпадать с часовым поясом в магазине, настроки часового пояса CRM можно задать по адресу:';
$_MODULE['<{retailcrm}prestashop>retailcrm_5effd5157947e8ba4a08883f198b2e31'] = 'Неверный или пустой адрес CRM';
$_MODULE['<{retailcrm}prestashop>retailcrm_576300f5b6faeb746bb6d034d98e7afd'] = 'Неверный или пустой API ключ';
$_MODULE['<{retailcrm}prestashop>retailcrm_c888438d14855d7d96a2724ee9c306bd'] = 'Настройки обновлены';
$_MODULE['<{retailcrm}prestashop>retailcrm_51af428aa0dcceb5230acb267ecb91c5'] = 'Настройка соединения';
$_MODULE['<{retailcrm}prestashop>retailcrm_4cbd5dbeeef7392e50358b1bc00dd592'] = 'URL адрес CRM';
$_MODULE['<{retailcrm}prestashop>retailcrm_7f775042e08eddee6bbfd8fbe0add4a3'] = 'API ключ';
$_MODULE['<{retailcrm}prestashop>retailcrm_c9cc8cce247e49bae79f15173ce97354'] = 'Сохранить';
$_MODULE['<{retailcrm}prestashop>retailcrm_065ab3a28ca4f16f55f103adc7d0226f'] = 'Способы доставки';
$_MODULE['<{retailcrm}prestashop>retailcrm_33af8066d3c83110d4bd897f687cedd2'] = 'Статусы заказов';
$_MODULE['<{retailcrm}prestashop>retailcrm_bab959acc06bb03897b294fbb892be6b'] = 'Способы оплаты';
$_MODULE['<{retailcrm}prestashop>retailcrm_dd7bf230fde8d4836917806aff6a6b27'] = 'Адрес';
$_MODULE['<{retailcrm}prestashop>retailcrm_630f6dc397fe74e52d5189e2c80f282b'] = 'Вернуться к списку';
$_MODULE['<{retailcrm}prestashop>retailcrm_5c1cf6cfec2dad86c8ca5286a0294516'] = 'Имя';
$_MODULE['<{retailcrm}prestashop>retailcrm_c695cfe527a6fcd680114851b86b7555'] = 'Фамилия';
$_MODULE['<{retailcrm}prestashop>retailcrm_f9dd946cc89c1f3b41a0edbe0f36931d'] = 'Телефон';
$_MODULE['<{retailcrm}prestashop>retailcrm_61a649a33f2869e5e35fbb7aff3a80d9'] = 'Email';
$_MODULE['<{retailcrm}prestashop>retailcrm_2664f03ac6b8bb9eee4287720e407db3'] = 'Адрес';
$_MODULE['<{retailcrm}prestashop>retailcrm_6ddc09dc456001d9854e9fe670374eb2'] = 'Страна';
$_MODULE['<{retailcrm}prestashop>retailcrm_69aede266809f89b89fe70681f6a129f'] = 'Область/Край/Республика';
$_MODULE['<{retailcrm}prestashop>retailcrm_859214628431995197c0558f7b5f8ffc'] = 'Город';
$_MODULE['<{retailcrm}prestashop>retailcrm_4348f938bbddd8475e967ccb47ecb234'] = 'Почтовый индекс';
$_MODULE['<{retailcrm}prestashop>retailcrm_78fce82336bbbdca7f6da7564b8f9325'] = 'Улица';
$_MODULE['<{retailcrm}prestashop>retailcrm_71a6834884666147c0334f0c40bc7295'] = 'Дом/Строение';
$_MODULE['<{retailcrm}prestashop>retailcrm_f88a77e3d68d251c3dc4008c327b5a0c'] = 'Квартира';
$_MODULE['<{retailcrm}prestashop>retailcrm_d977f846d110fcb7f71c6f97330c9d10'] = 'Код домофона';
$_MODULE['<{retailcrm}prestashop>retailcrm_56c1e354d36beb85b0d881c5b2e24cbe'] = 'Этаж';
$_MODULE['<{retailcrm}prestashop>retailcrm_4d34f53389ed7f28ca91fc31ea360a66'] = 'Корпус';
$_MODULE['<{retailcrm}prestashop>retailcrm_49354b452ec305136a56fe7731834156'] = 'Дом/Строение';
$_MODULE['<{retailcrm}prestashop>retailcrm_04176f095283bc729f1e3926967e7034'] = 'Имя';
$_MODULE['<{retailcrm}prestashop>retailcrm_dff4bf10409100d989495c6d5486035e'] = 'Фамилия';
$_MODULE['<{retailcrm}prestashop>retailcrm_1c76cbfe21c6f44c1d1e59d54f3e4420'] = 'Компания';
$_MODULE['<{retailcrm}prestashop>retailcrm_1aadcc03a9dbba84a3c5a5cbfde8a162'] = 'ИНН';
$_MODULE['<{retailcrm}prestashop>retailcrm_93d03fe37ab3c6abc2a19dd8e41543bd'] = 'Адрес строка 1';
$_MODULE['<{retailcrm}prestashop>retailcrm_22fcffe02ab9eda5b769387122f2ddce'] = 'Адрес строка 2';
$_MODULE['<{retailcrm}prestashop>retailcrm_8bcdc441379cbf584638b0589a3f9adb'] = 'Почтовый индекс';
$_MODULE['<{retailcrm}prestashop>retailcrm_69aede266809f89b89fe70681f6a129f'] = 'Область/Край/Республика';
$_MODULE['<{retailcrm}prestashop>retailcrm_57d056ed0984166336b7879c2af3657f'] = 'Город';
$_MODULE['<{retailcrm}prestashop>retailcrm_bcc254b55c4a1babdf1dcb82c207506b'] = 'Телефон';
$_MODULE['<{retailcrm}prestashop>retailcrm_f0e1fc6f97d36cb80f29196e2662ffde'] = 'Мобильный телефон';