rebranding, api url|key emptiness error fix, icml fixes

This commit is contained in:
Alex Lushpai 2015-07-20 17:59:27 +03:00
parent e05784c3b6
commit b35190b7e3
17 changed files with 1479 additions and 337 deletions

View File

@ -1,35 +0,0 @@
{
"name": "intarocrm/prestashop-module",
"description": "Prestashop integration for IntaroCRM",
"type": "library",
"keywords": ["api", "Intaro CRM", "rest"],
"homepage": "http://www.intarocrm.ru/",
"config": {
"vendor-dir": "intarocrm/classes"
},
"authors": [
{
"name": "Alex Lushpai",
"email": "lushpai@intaro.ru",
"role": "Developer"
}
],
"support": {
"email": "support@intarocrm.ru"
},
"require": {
"php": ">=5.3",
"intarocrm/rest-api-client": "1.2.*"
},
"autoload": {
"psr-0": {
"": "src/"
}
},
"repositories": [
{
"type": "git",
"url": "https://github.com/intarocrm/rest-api-client"
}
]
}

67
composer.lock generated
View File

@ -1,67 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "e4583dae732a6e5ebafff8cca46b1984",
"packages": [
{
"name": "intarocrm/rest-api-client",
"version": "v1.2.5",
"source": {
"type": "git",
"url": "https://github.com/intarocrm/rest-api-client",
"reference": "b54350ff2f09d8202cf2931895bba8dced4dcf21"
},
"require": {
"ext-curl": "*",
"php": ">=5.2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-0": {
"IntaroCrm\\": "lib/"
}
},
"authors": [
{
"name": "Kruglov Kirill",
"email": "kruglov@intaro.ru",
"role": "Developer"
}
],
"description": "PHP Client for IntaroCRM REST API",
"homepage": "http://www.intarocrm.ru/",
"keywords": [
"Intaro CRM",
"api",
"rest"
],
"support": {
"email": "support@intarocrm.ru"
},
"time": "2014-04-13 09:58:37"
}
],
"packages-dev": [
],
"aliases": [
],
"minimum-stability": "stable",
"stability-flags": [
],
"platform": {
"php": ">=5.3"
},
"platform-dev": [
]
}

View File

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

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<yml_catalog date="{$smarty.now|date_format:'%Y-%m-%d %H:%M'}">
<shop>
<name>{$shop_name}</name>
<company>{$yamarket_company_name}</company>
<url>{$shop_url}</url>
<platform>PrestaShop</platform>
<currencies>
{foreach from=$currencies item=cur name=currencies}
{if $cur.iso_code != 'GBP'}
<currency id="{if $cur.iso_code == 'RUB'}RUR{else}{$cur.iso_code}{/if}" rate="{math equation="1/x" x=$cur.conversion_rate}"/>
{/if}
{/foreach}
</currencies>
<categories>
{foreach from=$categories item=cat name=categories}
{if $cat.id_category!=2}
<category id="{$cat.id_category}"{if $cat.id_parent and $cat.id_parent!=2} parentId="{$cat.id_parent}"{/if}>{$cat.name}</category>
{/if}
{/foreach}
</categories>
{if $yamarket_delivery_price}<local_delivery_cost>{$yamarket_delivery_price}</local_delivery_cost>{/if}
<offers>
{foreach from=$products item=offer name=products}
<offer available="{if $offer.available_for_order}true{else}false{/if}" id="{$offer.id_product}">
<url>{$offer.url}</url>
<price>{$offer.price}</price>
<purchasePrice>{$offer.purchase_price}</purchasePrice>
<currencyId>{$currency}</currencyId>
<categoryId>{$offer.id_category_default}</categoryId>
<picture>{$offer.picture}</picture>
<name>{$offer.name}</name>
{if $offer.article}
<param name="article">{$offer.article}</param>
{/if}
</offer>
{/foreach}
</offers>
</shop>
</yml_catalog>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

136
retailcrm/classes/Icml.php Normal file
View File

@ -0,0 +1,136 @@
<?php
class Icml
{
protected $shop;
protected $file;
protected $properties;
protected $params;
protected $dd;
protected $eCategories;
protected $eOffers;
public function __construct($shop, $file)
{
$this->shop = $shop;
$this->file = $file;
$this->properties = array(
'name',
'productName',
'initialPrice',
'purchasePrice',
'vendor',
'picture',
'url',
'xmlId',
'productActivity'
);
$this->params = array(
'article' => 'Артикул',
'color' => 'Цвет',
'weight' => 'Вес',
'size' => 'Размер',
);
}
public function generate($categories, $offers)
{
$string = '<?xml version="1.0" encoding="UTF-8"?>
<yml_catalog date="'.date('Y-m-d H:i:s').'">
<shop>
<name>'.$this->shop.'</name>
<categories/>
<offers/>
</shop>
</yml_catalog>
';
$xml = new SimpleXMLElement(
$string,
LIBXML_NOENT |LIBXML_NOCDATA | LIBXML_COMPACT | LIBXML_PARSEHUGE
);
$this->dd = new DOMDocument();
$this->dd->preserveWhiteSpace = false;
$this->dd->formatOutput = true;
$this->dd->loadXML($xml->asXML());
$this->eCategories = $this->dd
->getElementsByTagName('categories')->item(0);
$this->eOffers = $this->dd
->getElementsByTagName('offers')->item(0);
$this->addCategories($categories);
$this->addOffers($offers);
$this->dd->saveXML();
$this->dd->save($this->file);
}
private function addCategories($categories)
{
foreach($categories as $category) {
$e = $this->eCategories->appendChild(
$this->dd->createElement(
'category', $category['name']
)
);
$e->setAttribute('id', $category['id']);
if ($category['parentId'] > 0) {
$e->setAttribute('parentId', $category['parentId']);
}
}
}
private function addOffers($offers)
{
foreach ($offers as $offer) {
$e = $this->eOffers->appendChild(
$this->dd->createElement('offer')
);
$e->setAttribute('id', $offer['id']);
$e->setAttribute('productId', $offer['productId']);
if (!empty($offer['quantity'])) {
$e->setAttribute('quantity', (int) $offer['quantity']);
} else {
$e->setAttribute('quantity', 0);
}
foreach ($offer['categoryId'] as $categoryId) {
$e->appendChild(
$this->dd->createElement('categoryId', $categoryId)
);
}
$offerKeys = array_keys($offer);
foreach ($offerKeys as $key) {
if (in_array($key, $this->properties)) {
$e->appendChild(
$this->dd->createElement($key)
)->appendChild(
$this->dd->createTextNode($offer[$key])
);
}
if (in_array($key, array_keys($this->params))) {
$param = $this->dd->createElement('param');
$param->setAttribute('code', $key);
$param->setAttribute('name', $this->params[$key]);
$param->appendChild(
$this->dd->createTextNode($offer[$key])
);
$e->appendChild($param);
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,43 @@
<?php
class Service
{
public static function getDate($file)
{
if (file_exists($file)) {
$result = file_get_contents($file);
} else {
$result = date('Y-m-d H:i:s', strtotime('-1 days', strtotime(date('Y-m-d H:i:s'))));
}
return $result;
}
public static function explodeFIO($string)
{
$result = array();
$parse = (!$string) ? false : explode(" ", $string, 3);
switch (count($parse)) {
case 1:
$result['firstName'] = $parse[0];
$result['lastName'] = '';
$result['patronymic'] = '';
break;
case 2:
$result['firstName'] = $parse[1];
$result['lastName'] = $parse[0];
$result['patronymic'] = '';
break;
case 3:
$result['firstName'] = $parse[1];
$result['lastName'] = $parse[0];
$result['patronymic'] = $parse[2];
break;
default:
return false;
}
return $result;
}
}

13
retailcrm/config.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[Integration module for RetailCRM]]></description>
<author><![CDATA[Retail Driver LCC]]></author>
<tab><![CDATA[market_place]]></tab>
<confirmUninstall><![CDATA[Are you sure you want to uninstall?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>

31
retailcrm/export.tpl Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<yml_catalog date="{$smarty.now|date_format:'%Y-%m-%d %H:%M'}">
<shop>
<name>{$shop_name|escape}</name>
<company>{$company|escape}</company>
<url>{$shop_url|escape}</url>
<categories>
{foreach from=$categories item=cat name=categories}
{if $cat.id_category > 2}
<category id="{$cat.id_category}"{if $cat.id_parent and $cat.id_parent!=2} parentId="{$cat.id_parent}"{/if}>{$cat.name}</category>
{/if}
{/foreach}
</categories>
<offers>
{foreach from=$products item=offer name=products}
<offer id="{$offer.id_product}" productId="{$offer.id_product}">
<productActivity>{if $offer.available_for_order}Y{else}N{/if}</productActivity>
<url>{$offer.url|escape}</url>
<price>{$offer.price}</price>
<purchasePrice>{$offer.purchase_price}</purchasePrice>
<categoryId>{$offer.id_category_default}</categoryId>
<picture>{$offer.picture|escape}</picture>
<name>{$offer.name|escape}</name>
{if $offer.article}
<param name="article">{$offer.article|escape}</param>
{/if}
</offer>
{/foreach}
</offers>
</shop>
</yml_catalog>

View File

@ -1,9 +1,9 @@
<?php
include(dirname(__FILE__). '/../../config/config.inc.php');
include(dirname(__FILE__). '/../../init.php');
include(dirname(__FILE__). '/intarocrm.php');
include(dirname(__FILE__). '/retailcrm.php');
header("Content-type: text/xml");
$export = new IntaroCRM();
echo $export->exportCatalog();
$export = new RetailCRM();
echo $export->exportCatalog();

BIN
retailcrm/logo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

BIN
retailcrm/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

View File

@ -1,28 +1,35 @@
<?php
require 'classes/autoload.php';
require 'classes/Retailcrm.php';
require 'classes/Service.php';
require 'classes/Icml.php';
if (!defined('_PS_VERSION_')) {
exit;
}
class IntaroCRM extends Module
class RetailCRM extends Module
{
function __construct()
{
$this->name = 'intarocrm';
$this->name = 'retailcrm';
$this->tab = 'market_place';
$this->version = '0.1';
$this->author = 'Intaro Ltd.';
$this->version = '0.2';
$this->author = 'Retail Driver LCC';
$this->displayName = $this->l('IntaroCRM');
$this->description = $this->l('Integration module for IntaroCRM');
$this->displayName = $this->l('RetailCRM');
$this->description = $this->l('Integration module for RetailCRM');
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
$this->intaroCRM = new \IntaroCrm\RestApi(
Configuration::get('INTAROCRM_ADDRESS'),
Configuration::get('INTAROCRM_API_TOKEN')
);
$this->apiUrl = Configuration::get('RETAILCRM_ADDRESS');
$this->apiKey = Configuration::get('RETAILCRM_API_TOKEN');
if (!empty($this->apiUrl) && !empty($this->apiKey)) {
$this->api = new ApiClient(
$this->apiUrl,
$this->apiKey
);
}
$this->default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$this->default_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT');
@ -54,12 +61,12 @@ class IntaroCRM extends Module
function uninstall()
{
return parent::uninstall() &&
Configuration::deleteByName('INTAROCRM_ADDRESS') &&
Configuration::deleteByName('INTAROCRM_API_TOKEN') &&
Configuration::deleteByName('INTAROCRM_API_STATUS') &&
Configuration::deleteByName('INTAROCRM_API_DELIVERY') &&
Configuration::deleteByName('INTAROCRM_LAST_SYNC') &&
Configuration::deleteByName('INTAROCRM_API_ADDR')
Configuration::deleteByName('RETAILCRM_ADDRESS') &&
Configuration::deleteByName('RETAILCRM_API_TOKEN') &&
Configuration::deleteByName('RETAILCRM_API_STATUS') &&
Configuration::deleteByName('RETAILCRM_API_DELIVERY') &&
Configuration::deleteByName('RETAILCRM_LAST_SYNC') &&
Configuration::deleteByName('RETAILCRM_API_ADDR')
;
}
@ -67,8 +74,8 @@ class IntaroCRM extends Module
{
$output = null;
$address = Configuration::get('INTAROCRM_ADDRESS');
$token = Configuration::get('INTAROCRM_API_TOKEN');
$address = Configuration::get('RETAILCRM_ADDRESS');
$token = Configuration::get('RETAILCRM_API_TOKEN');
if (!$address || $address == '') {
$output .= $this->displayError( $this->l('Invalid crm address') );
@ -83,24 +90,24 @@ class IntaroCRM extends Module
if (Tools::isSubmit('submit'.$this->name))
{
$address = strval(Tools::getValue('INTAROCRM_ADDRESS'));
$token = strval(Tools::getValue('INTAROCRM_API_TOKEN'));
$delivery = json_encode(Tools::getValue('INTAROCRM_API_DELIVERY'));
$status = json_encode(Tools::getValue('INTAROCRM_API_STATUS'));
$payment = json_encode(Tools::getValue('INTAROCRM_API_PAYMENT'));
$order_address = json_encode(Tools::getValue('INTAROCRM_API_ADDR'));
$address = strval(Tools::getValue('RETAILCRM_ADDRESS'));
$token = strval(Tools::getValue('RETAILCRM_API_TOKEN'));
$delivery = json_encode(Tools::getValue('RETAILCRM_API_DELIVERY'));
$status = json_encode(Tools::getValue('RETAILCRM_API_STATUS'));
$payment = json_encode(Tools::getValue('RETAILCRM_API_PAYMENT'));
$order_address = json_encode(Tools::getValue('RETAILCRM_API_ADDR'));
if (!$address || empty($address) || !Validate::isGenericName($address)) {
$output .= $this->displayError( $this->l('Invalid crm address') );
} elseif (!$token || empty($token) || !Validate::isGenericName($token)) {
$output .= $this->displayError( $this->l('Invalid crm api token') );
} else {
Configuration::updateValue('INTAROCRM_ADDRESS', $address);
Configuration::updateValue('INTAROCRM_API_TOKEN', $token);
Configuration::updateValue('INTAROCRM_API_DELIVERY', $delivery);
Configuration::updateValue('INTAROCRM_API_STATUS', $status);
Configuration::updateValue('INTAROCRM_API_PAYMENT', $payment);
Configuration::updateValue('INTAROCRM_API_ADDR', $order_address);
Configuration::updateValue('RETAILCRM_ADDRESS', $address);
Configuration::updateValue('RETAILCRM_API_TOKEN', $token);
Configuration::updateValue('RETAILCRM_API_DELIVERY', $delivery);
Configuration::updateValue('RETAILCRM_API_STATUS', $status);
Configuration::updateValue('RETAILCRM_API_PAYMENT', $payment);
Configuration::updateValue('RETAILCRM_API_ADDR', $order_address);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
}
@ -115,7 +122,7 @@ class IntaroCRM extends Module
$this->displayConfirmation($this->l('Settings updated'));
$default_lang = $this->default_lang;
$intaroCrm = $this->intaroCRM;
$intaroCrm = $this->api;
/*
* Network connection form
@ -128,14 +135,14 @@ class IntaroCRM extends Module
array(
'type' => 'text',
'label' => $this->l('CRM address'),
'name' => 'INTAROCRM_ADDRESS',
'name' => 'RETAILCRM_ADDRESS',
'size' => 20,
'required' => true
),
array(
'type' => 'text',
'label' => $this->l('CRM token'),
'name' => 'INTAROCRM_API_TOKEN',
'name' => 'RETAILCRM_API_TOKEN',
'size' => 20,
'required' => true
)
@ -146,35 +153,38 @@ class IntaroCRM extends Module
)
);
/*
* Delivery
*/
$fields_form[1]['form'] = array(
'legend' => array(
'title' => $this->l('Delivery'),
),
'input' => $this->getDeliveryTypes($default_lang, $intaroCrm),
);
/*
* Order status
*/
$fields_form[2]['form'] = array(
'legend' => array(
'title' => $this->l('Order statuses'),
),
'input' => $this->getStatusTypes($default_lang, $intaroCrm),
);
if (!empty($this->apiUrl) && !empty($this->apiKey)) {
/*
* Delivery
*/
$fields_form[1]['form'] = array(
'legend' => array(
'title' => $this->l('Delivery'),
),
'input' => $this->getDeliveryTypes(),
);
/*
* Payment
*/
$fields_form[3]['form'] = array(
'legend' => array(
'title' => $this->l('Payment types'),
),
'input' => $this->getPaymentTypes($intaroCrm),
);
/*
* Order status
*/
$fields_form[2]['form'] = array(
'legend' => array(
'title' => $this->l('Order statuses'),
),
'input' => $this->getStatusTypes(),
);
/*
* Payment
*/
$fields_form[3]['form'] = array(
'legend' => array(
'title' => $this->l('Payment types'),
),
'input' => $this->getPaymentTypes(),
);
}
/*
* Address fields
@ -218,45 +228,45 @@ class IntaroCRM extends Module
)
);
$helper->fields_value['INTAROCRM_ADDRESS'] = Configuration::get('INTAROCRM_ADDRESS');
$helper->fields_value['INTAROCRM_API_TOKEN'] = Configuration::get('INTAROCRM_API_TOKEN');
$helper->fields_value['RETAILCRM_ADDRESS'] = Configuration::get('RETAILCRM_ADDRESS');
$helper->fields_value['RETAILCRM_API_TOKEN'] = Configuration::get('RETAILCRM_API_TOKEN');
$deliverySettings = Configuration::get('INTAROCRM_API_DELIVERY');
$deliverySettings = Configuration::get('RETAILCRM_API_DELIVERY');
if (isset($deliverySettings) && $deliverySettings != '')
{
$deliveryTypes = json_decode($deliverySettings);
foreach ($deliveryTypes as $idx => $delivery) {
$name = 'INTAROCRM_API_DELIVERY[' . $idx . ']';
$name = 'RETAILCRM_API_DELIVERY[' . $idx . ']';
$helper->fields_value[$name] = $delivery;
}
}
$statusSettings = Configuration::get('INTAROCRM_API_STATUS');
$statusSettings = Configuration::get('RETAILCRM_API_STATUS');
if (isset($statusSettings) && $statusSettings != '')
{
$statusTypes = json_decode($statusSettings);
foreach ($statusTypes as $idx => $status) {
$name = 'INTAROCRM_API_STATUS[' . $idx . ']';
$name = 'RETAILCRM_API_STATUS[' . $idx . ']';
$helper->fields_value[$name] = $status;
}
}
$paymentSettings = Configuration::get('INTAROCRM_API_PAYMENT');
$paymentSettings = Configuration::get('RETAILCRM_API_PAYMENT');
if (isset($paymentSettings) && $paymentSettings != '')
{
$paymentTypes = json_decode($paymentSettings);
foreach ($paymentTypes as $idx => $payment) {
$name = 'INTAROCRM_API_PAYMENT[' . $idx . ']';
$name = 'RETAILCRM_API_PAYMENT[' . $idx . ']';
$helper->fields_value[$name] = $payment;
}
}
$addressSettings = Configuration::get('INTAROCRM_API_ADDR');
$addressSettings = Configuration::get('RETAILCRM_API_ADDR');
if (isset($addressSettings) && $addressSettings != '')
{
$addressTypes = json_decode($addressSettings);
foreach ($addressTypes as $idx => $address) {
$name = 'INTAROCRM_API_ADDR[' . $idx . ']';
$name = 'RETAILCRM_API_ADDR[' . $idx . ']';
$helper->fields_value[$name] = $address;
}
}
@ -271,13 +281,14 @@ class IntaroCRM extends Module
public function hookActionPaymentConfirmation($params)
{
$this->intaroCRM->orderEdit(
$this->api->ordersEdit(
array(
'externalId' => $params['id_order'],
'paymentStatus' => 'paid',
'createdAt' => $params['cart']->date_upd
)
);
return $this->hookActionOrderStatusPostUpdate($params);
}
@ -287,13 +298,13 @@ class IntaroCRM extends Module
$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('INTAROCRM_API_DELIVERY'));
$payment = json_decode(Configuration::get('INTAROCRM_API_PAYMENT'));
$delivery = json_decode(Configuration::get('RETAILCRM_API_DELIVERY'));
$payment = json_decode(Configuration::get('RETAILCRM_API_PAYMENT'));
$inCart = $params['cart']->getProducts();
if (isset($params['orderStatus'])) {
try {
$crmCustomerId = $this->intaroCRM->customerCreate(
$this->api->customersCreate(
array(
'externalId' => $params['cart']->id_customer,
'lastName' => $params['customer']->lastname,
@ -313,11 +324,11 @@ class IntaroCRM extends Module
)
);
}
catch (\IntaroCrm\Exception\CurlException $e) {
error_log("customerCreate: connection error", 3, "intarocrm.log");
catch (CurlException $e) {
error_log("customerCreate: connection error", 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (\IntaroCrm\Exception\ApiException $e) {
error_log('customerCreate: ' . $e->getMessage(), 3, "intarocrm.log");
catch (InvalidJsonException $e) {
error_log('customerCreate: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
try {
@ -338,7 +349,7 @@ class IntaroCRM extends Module
} else {
$pTypeKey = $params['order']->payment;
}
$this->intaroCRM->orderCreate(
$this->api->ordersCreate(
array(
'externalId' => $params['order']->id,
'orderType' => 'eshop-individual',
@ -364,23 +375,23 @@ class IntaroCRM extends Module
)
);
}
catch (\IntaroCrm\Exception\CurlException $e) {
error_log('orderCreate: connection error', 3, "intarocrm.log");
catch (CurlException $e) {
error_log('orderCreate: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (\IntaroCrm\Exception\ApiException $e) {
error_log('orderCreate: ' . $e->getMessage(), 3, "intarocrm.log");
catch (InvalidJsonException $e) {
error_log('orderCreate: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
}
if (isset($params['newOrderStatus']) && !empty($params['newOrderStatus'])) {
$statuses = OrderState::getOrderStates($this->default_lang);
$aStatuses = json_decode(Configuration::get('INTAROCRM_API_STATUS'));
$aStatuses = json_decode(Configuration::get('RETAILCRM_API_STATUS'));
foreach ($statuses as $status) {
if ($status['name'] == $params['newOrderStatus']->name) {
$currStatus = $status['id_order_state'];
try {
$this->intaroCRM->orderEdit(
$this->api->ordersEdit(
array(
'externalId' => $params['id_order'],
'status' => $aStatuses->$currStatus,
@ -388,38 +399,40 @@ class IntaroCRM extends Module
)
);
}
catch (\IntaroCrm\Exception\CurlException $e) {
error_log('orderStatusUpdate: connection error', 3, "intarocrm.log");
catch (CurlException $e) {
error_log('orderStatusUpdate: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (\IntaroCrm\Exception\ApiException $e) {
error_log('orderStatusUpdate: ' . $e->getMessage(), 3, "intarocrm.log");
catch (InvalidJsonException $e) {
error_log('orderStatusUpdate: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
}
}
}
}
protected function getApiDeliveryTypes($intaroCrm)
protected function getApiDeliveryTypes()
{
$crmDeliveryTypes = array();
try {
$deliveryTypes = $intaroCrm->deliveryTypesList();
}
catch (\IntaroCrm\Exception\CurlException $e) {
error_log('deliveryTypesList: connection error', 3, "intarocrm.log");
}
catch (\IntaroCrm\Exception\ApiException $e) {
error_log('deliveryTypesList: ' . $e->getMessage(), 3, "intarocrm.log");
}
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'],
);
if (!empty($deliveryTypes)) {
$crmDeliveryTypes[] = array();
foreach ($deliveryTypes as $dType) {
$crmDeliveryTypes[] = array(
'id_option' => $dType['code'],
'name' => $dType['name'],
);
}
}
}
@ -427,12 +440,12 @@ class IntaroCRM extends Module
}
protected function getDeliveryTypes($default_lang, $intaroCrm)
protected function getDeliveryTypes()
{
$deliveryTypes = array();
$carriers = Carrier::getCarriers(
$default_lang, true, false, false,
$this->default_lang, true, false, false,
null, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE
);
@ -441,10 +454,10 @@ class IntaroCRM extends Module
$deliveryTypes[] = array(
'type' => 'select',
'label' => $carrier['name'],
'name' => 'INTAROCRM_API_DELIVERY[' . $carrier['id_carrier'] . ']',
'name' => 'RETAILCRM_API_DELIVERY[' . $carrier['id_carrier'] . ']',
'required' => false,
'options' => array(
'query' => $this->getApiDeliveryTypes($intaroCrm),
'query' => $this->getApiDeliveryTypes(),
'id' => 'id_option',
'name' => 'name'
)
@ -455,37 +468,39 @@ class IntaroCRM extends Module
return $deliveryTypes;
}
protected function getApiStatuses($intaroCrm)
protected function getApiStatuses()
{
$crmStatusTypes = array();
try {
$statusTypes = $intaroCrm->orderStatusesList();
}
catch (\IntaroCrm\Exception\CurlException $e) {
error_log('statusTypesList: connection error', 3, "intarocrm.log");
}
catch (\IntaroCrm\Exception\ApiException $e) {
error_log('statusTypesList: ' . $e->getMessage(), 3, "intarocrm.log");
}
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']
);
if (!empty($statusTypes)) {
$crmStatusTypes[] = array();
foreach ($statusTypes as $sType) {
$crmStatusTypes[] = array(
'id_option' => $sType['code'],
'name' => $sType['name']
);
}
}
}
return $crmStatusTypes;
}
protected function getStatusTypes($default_lang, $intaroCrm)
protected function getStatusTypes()
{
$statusTypes = array();
$states = OrderState::getOrderStates($default_lang, true);
$states = OrderState::getOrderStates($this->default_lang, true);
if (!empty($states)) {
foreach ($states as $state) {
@ -493,10 +508,10 @@ class IntaroCRM extends Module
$statusTypes[] = array(
'type' => 'select',
'label' => $state['name'],
'name' => 'INTAROCRM_API_STATUS[' . $state['id_order_state'] . ']',
'name' => 'RETAILCRM_API_STATUS[' . $state['id_order_state'] . ']',
'required' => false,
'options' => array(
'query' => $this->getApiStatuses($intaroCrm),
'query' => $this->getApiStatuses(),
'id' => 'id_option',
'name' => 'name'
)
@ -508,34 +523,36 @@ class IntaroCRM extends Module
return $statusTypes;
}
protected function getApiPaymentTypes($intaroCrm)
protected function getApiPaymentTypes()
{
$crmPaymentTypes = array();
try {
$paymentTypes = $intaroCrm->paymentTypesList();
}
catch (\IntaroCrm\Exception\CurlException $e) {
error_log('paymentTypesList: connection error', 3, "intarocrm.log");
}
catch (\IntaroCrm\Exception\ApiException $e) {
error_log('paymentTypesList: ' . $e->getMessage(), 3, "intarocrm.log");
}
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']
);
if (!empty($paymentTypes)) {
$crmPaymentTypes[] = array();
foreach ($paymentTypes as $pType) {
$crmPaymentTypes[] = array(
'id_option' => $pType['code'],
'name' => $pType['name']
);
}
}
}
return $crmPaymentTypes;
}
protected function getPaymentTypes($intaroCrm)
protected function getPaymentTypes()
{
$payments = $this->getSystemPaymentModules();
$paymentTypes = array();
@ -545,10 +562,10 @@ class IntaroCRM extends Module
$paymentTypes[] = array(
'type' => 'select',
'label' => $payment['name'],
'name' => 'INTAROCRM_API_PAYMENT[' . $payment['code'] . ']',
'name' => 'RETAILCRM_API_PAYMENT[' . $payment['code'] . ']',
'required' => false,
'options' => array(
'query' => $this->getApiPaymentTypes($intaroCrm),
'query' => $this->getApiPaymentTypes(),
'id' => 'id_option',
'name' => 'name'
)
@ -647,7 +664,7 @@ class IntaroCRM extends Module
$addressFields[] = array(
'type' => 'select',
'label' => $this->l((string)$a),
'name' => 'INTAROCRM_API_ADDR[' . $idx . ']',
'name' => 'RETAILCRM_API_ADDR[' . $idx . ']',
'required' => false,
'options' => array(
'query' => array(
@ -775,16 +792,18 @@ class IntaroCRM extends Module
$crewrite = Category::getLinkRewrite($product['id_category_default'], $id_lang);
$url = $link->getProductLink($product['id_product'], $product['link_rewrite'], $crewrite);
$version = substr(_PS_VERSION_, 0, 3);
if ($version == "1.3")
$available_for_order = $product['active'] && $product['quantity'];
$available_for_order = $product['active'] && $product['quantity'];
else {
$prod = new Product($product['id_product']);
$available_for_order = $product['active'] && $product['available_for_order'] && $prod->checkQty(1);
}
$items[] = array('id_product' => $product['id_product'],
'available_for_order' => $available_for_order,
'price' => $product['price'],
'purchase_price' => $product['wholesale_price'],
'price' => round($product['price'],2),
'purchase_price' => round($product['wholesale_price'], 2),
'name' => htmlspecialchars(strip_tags($product['name'])),
'article' => htmlspecialchars($product['reference']),
'id_category_default' => $category,
@ -813,7 +832,7 @@ class IntaroCRM extends Module
/*
* get last sync date
*/
$lastSync = Configuration::get('INTAROCRM_LAST_SYNC');
$lastSync = Configuration::get('RETAILCRM_LAST_SYNC');
$startFrom = ($lastSync === false) ? null : $lastSync;
$endTime = date('Y-m-d H:i:s');
@ -826,18 +845,18 @@ class IntaroCRM extends Module
*/
do {
try {
$this->response = $this->intaroCRM->orderHistory(
$this->response = $this->api->ordersHistory(
$startDate = $startFrom, $endDate = $endTime,
$limit = 250, $offset = $counter
);
$data = array_merge($data, $this->response);
$counter += 250;
}
catch (\IntaroCrm\Exception\CurlException $e) {
error_log('orderHistory: connection error', 3, "intarocrm.log");
catch (CurlException $e) {
error_log('orderHistory: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (\IntaroCrm\Exception\ApiException $e) {
error_log('orderHistory: ' . $e->getMessage(), 3, "intarocrm.log");
catch (InvalidJsonException $e) {
error_log('orderHistory: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
} while (!empty($response));
@ -852,9 +871,9 @@ class IntaroCRM extends Module
*/
$this->customer = new Customer();
$statuses = array_flip((array)json_decode(Configuration::get('INTAROCRM_API_STATUS')));
$deliveries = array_flip((array)json_decode(Configuration::get('INTAROCRM_API_DELIVERY')));
$payments = array_flip((array)json_decode(Configuration::get('INTAROCRM_API_PAYMENT')));
$statuses = array_flip((array)json_decode(Configuration::get('RETAILCRM_API_STATUS')));
$deliveries = array_flip((array)json_decode(Configuration::get('RETAILCRM_API_DELIVERY')));
$payments = array_flip((array)json_decode(Configuration::get('RETAILCRM_API_PAYMENT')));
foreach ($data as $order) {
if (!array_key_exists('externalId', $order)) {
@ -1048,15 +1067,15 @@ class IntaroCRM extends Module
Db::getInstance()->execute(rtrim($query, ','));
try {
$this->intaroCRM->customerFixExternalIds($this->customerFix);
$this->intaroCRM->orderFixExternalIds($this->orderFix);
$this->api->customersFixExternalIds($this->customerFix);
$this->api->ordesrFixExternalIds($this->orderFix);
}
catch (\IntaroCrm\Exception\CurlException $e) {
error_log('fixExternalId: connection error', 3, "intarocrm.log");
catch (CurlException $e) {
error_log('fixExternalId: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
continue;
}
catch (\IntaroCrm\Exception\ApiException $e) {
error_log('fixExternalId: ' . $e->getMessage(), 3, "intarocrm.log");
catch (InvalidJsonException $e) {
error_log('fixExternalId: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
continue;
}
@ -1244,15 +1263,15 @@ class IntaroCRM extends Module
*/
try {
Configuration::updateValue(
'INTAROCRM_LAST_SYNC',
date_format($this->intaroCRM->getGeneratedAt(), 'Y-m-d H:i:s')
'RETAILCRM_LAST_SYNC',
date_format($this->api->getGeneratedAt(), 'Y-m-d H:i:s')
);
}
catch (\IntaroCrm\Exception\CurlException $e) {
error_log('getLastSync: connection error', 3, "intarocrm.log");
catch (CurlException $e) {
error_log('getLastSync: connection error', 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
catch (\IntaroCrm\Exception\ApiException $e) {
error_log('getLastSync: ' . $e->getMessage(), 3, "intarocrm.log");
catch (InvalidJsonException $e) {
error_log('getLastSync: ' . $e->getMessage(), 3, _PS_ROOT_DIR . "log/retailcrm.log");
}
return count($data) . " records was synced";

View File

@ -1,9 +1,9 @@
<?php
include(dirname(__FILE__). '/../../config/config.inc.php');
include(dirname(__FILE__). '/../../init.php');
include(dirname(__FILE__). '/intarocrm.php');
include(dirname(__FILE__). '/retailcrm.php');
header("Content-type: text/html");
$export = new IntaroCRM();
$export = new RetailCRM();
echo $export->orderHistory();