mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-02 19:33:14 +03:00
export archive script
This commit is contained in:
parent
cc18170153
commit
47a503fbb4
19
CHANGELOG.md
19
CHANGELOG.md
@ -1,19 +0,0 @@
|
|||||||
Changelog
|
|
||||||
=========
|
|
||||||
|
|
||||||
v1.1
|
|
||||||
|
|
||||||
* Выгрузка клиентов при регистрации
|
|
||||||
* Учет наценок (НДС) при передаче данных по заказу в CRM
|
|
||||||
* Учет наценок (НДС) при генерации ICML
|
|
||||||
|
|
||||||
v0.2
|
|
||||||
|
|
||||||
* Ребрендинг, intarocrm заменено на retailcrm
|
|
||||||
* Обновлена библиотека api-client-php
|
|
||||||
* Сборка через composer больше надоступна, все необходимые файлы включены в основноую поставку
|
|
||||||
* Добавлен механизм кастомизации
|
|
||||||
* Добавлены переводы
|
|
||||||
* Генерация ICML перенесена с контроллера на cron для более эффективного использования ресурсов
|
|
||||||
* Устранен раяд ошибок
|
|
||||||
|
|
48
README.md
48
README.md
@ -9,32 +9,46 @@ Prestashop module
|
|||||||
* Синхронизировать справочники (способы доставки и оплаты, статусы заказов и т.п.)
|
* Синхронизировать справочники (способы доставки и оплаты, статусы заказов и т.п.)
|
||||||
* Выгружать каталог товаров в формате [ICML](http://retailcrm.ru/docs/Разработчики/ФорматICML) (IntaroCRM Markup Language)
|
* Выгружать каталог товаров в формате [ICML](http://retailcrm.ru/docs/Разработчики/ФорматICML) (IntaroCRM Markup Language)
|
||||||
|
|
||||||
Установка
|
##Установка
|
||||||
-------------
|
|
||||||
|
|
||||||
### 1. Ручная установка
|
####Скачайте модуль
|
||||||
|
|
||||||
|
[Cкачать](http://download.retailcrm.pro/modules/prestashop/retailcrm-2.0.zip)
|
||||||
|
|
||||||
#### Скопируйте модуль
|
####Установите через административный интерфейс управления модулями.
|
||||||
```
|
|
||||||
git clone git@github.com:/intarocrm/prestashop-module.git
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Создайте загружаемый .zip архив.
|
|
||||||
```
|
|
||||||
cd prestashop-module
|
|
||||||
zip -r retailcrm.zip retailcrm
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Установите через административный интерфейс управления модулями.
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
#### Перейдите к настройкам
|
|
||||||
|
##Настройка
|
||||||
|
|
||||||
|
####Перейдите к настройкам
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
#### Введите адрес и API ключ вашей CRM и задайте соответствие справочников
|
####Введите адрес и API ключ вашей CRM и задайте соответствие справочников
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
####Регулярная генерация выгрузки каталога
|
||||||
|
|
||||||
|
Добавьте в крон запись вида
|
||||||
|
|
||||||
|
```
|
||||||
|
* */4 * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/icml.php
|
||||||
|
```
|
||||||
|
|
||||||
|
####Регулярное получение изменение из RetailCRM
|
||||||
|
|
||||||
|
Добавьте в крон запись вида
|
||||||
|
|
||||||
|
```
|
||||||
|
*/7 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php
|
||||||
|
```
|
||||||
|
|
||||||
|
####Единоразовая выгрузка архива клиентов и заказов в RetailCRM
|
||||||
|
|
||||||
|
```
|
||||||
|
/usr/bin/php /path/to/your/site/modules/retailcrm/job/export.php
|
||||||
|
```
|
||||||
|
@ -16,14 +16,29 @@ if (!empty($apiUrl) && !empty($apiKey)) {
|
|||||||
|
|
||||||
$orders = array();
|
$orders = array();
|
||||||
$customers = array();
|
$customers = array();
|
||||||
$instance = new Order();
|
|
||||||
$records = $instance->getOrdersWithInformations(2);
|
|
||||||
|
|
||||||
$delivery = json_decode(Configuration::get('RETAILCRM_API_DELIVERY'));
|
$customerInstance = new Customer();
|
||||||
$payment = json_decode(Configuration::get('RETAILCRM_API_PAYMENT'));
|
$orderInstance = new Order();
|
||||||
$status = json_decode(Configuration::get('RETAILCRM_API_STATUS'));
|
|
||||||
|
|
||||||
foreach ($records as $record) {
|
$customerRecords = $customerInstance->getCustomers();
|
||||||
|
$orderRecords = $orderInstance->getOrdersWithInformations();
|
||||||
|
|
||||||
|
$delivery = json_decode(Configuration::get('RETAILCRM_API_DELIVERY'), true);
|
||||||
|
$payment = json_decode(Configuration::get('RETAILCRM_API_PAYMENT'), true);
|
||||||
|
$status = json_decode(Configuration::get('RETAILCRM_API_STATUS'), true);
|
||||||
|
|
||||||
|
foreach ($customerRecords as $record) {
|
||||||
|
$customers[$record['id_customer']] = array(
|
||||||
|
'externalId' => $record['id_customer'],
|
||||||
|
'firstName' => $record['firstname'],
|
||||||
|
'lastname' => $record['lastname'],
|
||||||
|
'email' => $record['email']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($customerRecords);
|
||||||
|
|
||||||
|
foreach ($orderRecords as $record) {
|
||||||
|
|
||||||
$object = new Order($record['id_order']);
|
$object = new Order($record['id_order']);
|
||||||
|
|
||||||
@ -33,30 +48,67 @@ foreach ($records as $record) {
|
|||||||
$paymentType = $record['payment'];
|
$paymentType = $record['payment'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($record['current_state'] == 0) {
|
||||||
|
$order_status = 'completed';
|
||||||
|
} else {
|
||||||
|
$order_status = array_key_exists($record['current_state'], $status)
|
||||||
|
? $status[$record['current_state']]
|
||||||
|
: 'completed'
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
$cart = new Cart($object->getCartIdStatic($record['id_order']));
|
$cart = new Cart($object->getCartIdStatic($record['id_order']));
|
||||||
$addressCollection = $cart->getAddressCollection();
|
$addressCollection = $cart->getAddressCollection();
|
||||||
$address = array_shift($addressCollection);
|
$address = array_shift($addressCollection);
|
||||||
|
|
||||||
|
if ($address instanceof Address) {
|
||||||
|
$phone = is_null($address->phone)
|
||||||
|
? is_null($address->phone_mobile) ? '' : $address->phone_mobile
|
||||||
|
: $address->phone
|
||||||
|
;
|
||||||
|
|
||||||
|
$postcode = $address->postcode;
|
||||||
|
$city = $address->city;
|
||||||
|
$addres_line = sprintf("%s %s", $address->address1, $address->address2);
|
||||||
|
}
|
||||||
|
|
||||||
$order = array(
|
$order = array(
|
||||||
'externalId' => $record['id_order'],
|
'externalId' => $record['id_order'],
|
||||||
'createdAt' => $record['date_add'],
|
'createdAt' => $record['date_add'],
|
||||||
'status' => $record['current_state'] == 0 ? 'new' : $status->$record['current_state'],
|
'status' => $order_status,
|
||||||
'firstName' => $record['firstname'],
|
'firstName' => $record['firstname'],
|
||||||
'lastName' => $record['lastname'],
|
'lastName' => $record['lastname'],
|
||||||
'email' => $record['email'],
|
'email' => $record['email'],
|
||||||
'phone' => $address->phone,
|
|
||||||
'delivery' => array(
|
|
||||||
'code' => $delivery->$record['id_carrier'],
|
|
||||||
'cost' => $record['total_shipping_tax_incl'],
|
|
||||||
'address' => array(
|
|
||||||
'index' => $address->postcode,
|
|
||||||
'city' => $address->city,
|
|
||||||
'street' => sprintf("%s %s", $address->address1, $address->address2)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
'paymentType' => $payment->$paymentType
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isset($postcode)) {
|
||||||
|
$order['delivery']['address']['postcode'] = $postcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($city)) {
|
||||||
|
$order['delivery']['address']['city'] = $city;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($addres_line)) {
|
||||||
|
$order['delivery']['address']['text'] = $addres_line;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($phone) {
|
||||||
|
$order['phone'] = $phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists($paymentType, $payment)) {
|
||||||
|
$order['paymentType'] = $payment[$paymentType];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists($record['id_carrier'], $delivery)) {
|
||||||
|
$order['delivery']['code'] = $delivery[$record['id_carrier']];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($record['total_shipping_tax_incl']) && (int) $record['total_shipping_tax_incl'] > 0) {
|
||||||
|
$order['delivery']['cost'] = round($record['total_shipping_tax_incl'], 2);
|
||||||
|
}
|
||||||
|
|
||||||
$products = $object->getProducts();
|
$products = $object->getProducts();
|
||||||
|
|
||||||
foreach($products as $product) {
|
foreach($products as $product) {
|
||||||
@ -73,27 +125,23 @@ foreach ($records as $record) {
|
|||||||
|
|
||||||
if ($record['id_customer']) {
|
if ($record['id_customer']) {
|
||||||
$order['customer']['externalId'] = $record['id_customer'];
|
$order['customer']['externalId'] = $record['id_customer'];
|
||||||
|
|
||||||
$customer = new Customer($record['id_customer']);
|
|
||||||
$customerCRM = array(
|
|
||||||
'externalId' => $customer->id,
|
|
||||||
'firstName' => $customer->firstname,
|
|
||||||
'lastname' => $customer->lastname,
|
|
||||||
'email' => $customer->email,
|
|
||||||
'phones' => array(array('number' => $address->phone)),
|
|
||||||
'createdAt' => $customer->date_add,
|
|
||||||
'address' => array(
|
|
||||||
'index' => $address->postcode,
|
|
||||||
'city' => $address->city,
|
|
||||||
'street' => sprintf("%s %s", $address->address1, $address->address2)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$customers[$customer->id] = $customerCRM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$orders[] = $order;
|
$orders[$record['id_order']] = $order;
|
||||||
}
|
}
|
||||||
|
|
||||||
var_dump(count($customers));
|
unset($orderRecords);
|
||||||
var_dump(count($orders));
|
|
||||||
|
$customers = array_chunk($customers, 50);
|
||||||
|
|
||||||
|
foreach ($customers as $chunk) {
|
||||||
|
$api->customersUpload($chunk);
|
||||||
|
time_nanosleep(0, 200000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orders = array_chunk($orders, 50);
|
||||||
|
|
||||||
|
foreach ($orders as $chunk) {
|
||||||
|
$api->ordersUpload($chunk);
|
||||||
|
time_nanosleep(0, 200000000);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user