mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
commit
dea4a2a51b
16
CHANGELOG.md
16
CHANGELOG.md
@ -1,3 +1,9 @@
|
||||
## v2.2.9
|
||||
* Добавлена выгрузка габаритов в специальный тег dimensions
|
||||
* Добавлена выгрузка остатков из CRM
|
||||
* Добавлена передача номера заказа
|
||||
* Добавлена настройка Daemon Collector
|
||||
|
||||
## v2.2.8
|
||||
* Добавлена выгрузка картинок категорий товаров в ICML
|
||||
|
||||
@ -8,11 +14,13 @@
|
||||
## v2.2.6
|
||||
* Добавлена активация модуля в маркетплейсе retailCRM
|
||||
|
||||
## v2.2.5
|
||||
* Добавлена передача страны при создании заказа для пользователя и заказа
|
||||
* Добавлен метод сохранения сущностей с обработкой исключений
|
||||
## v.2.2.5
|
||||
* Добавлена передача страны при создании заказа для заказа и покупателя
|
||||
* Добавлен метод для загрузки сущностей с перехватом исключений
|
||||
* Для версии 1.7 добавлена передача адреса при заполнении его на стороне сайта.
|
||||
* Получение адреса и телефона вынесено в отдельные методы.
|
||||
|
||||
## v2.2.4
|
||||
## v.2.2.4
|
||||
* Добавлена установка дефолтной валюты для оплаты при получении истории
|
||||
* Добавлено получение суммы оплаты из заказа в CMS, если она не передается по истории
|
||||
|
||||
|
@ -34,6 +34,14 @@ Add to cron:
|
||||
*/7 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php
|
||||
```
|
||||
|
||||
#### Receiving balances from retailCRM
|
||||
|
||||
Add to cron:
|
||||
|
||||
```
|
||||
*/15 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/inventories.php
|
||||
```
|
||||
|
||||
#### Single orders archive export to retailCRM
|
||||
|
||||
```
|
||||
|
@ -29,6 +29,14 @@ Prestashop module
|
||||
*/7 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php
|
||||
```
|
||||
|
||||
#### Получение остатков из retailCRM
|
||||
|
||||
Добавьте в крон запись вида
|
||||
|
||||
```
|
||||
*/15 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/inventories.php
|
||||
```
|
||||
|
||||
#### Единоразовая выгрузка архива клиентов и заказов в retailCRM
|
||||
|
||||
```
|
||||
|
28
retailcrm/job/inventories.php
Normal file
28
retailcrm/job/inventories.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Retail Driver LCC
|
||||
* @copyright RetailCRM
|
||||
* @license GPL
|
||||
* @version 2.2.9
|
||||
* @link https://retailcrm.ru
|
||||
*
|
||||
*/
|
||||
|
||||
$_SERVER['HTTPS'] = 1;
|
||||
|
||||
require(dirname(__FILE__) . '/../../../config/config.inc.php');
|
||||
require(dirname(__FILE__) . '/../../../init.php');
|
||||
require(dirname(__FILE__) . '/../bootstrap.php');
|
||||
|
||||
$apiUrl = Configuration::get('RETAILCRM_ADDRESS');
|
||||
$apiKey = Configuration::get('RETAILCRM_API_TOKEN');
|
||||
$apiVersion = Configuration::get('RETAILCRM_API_VERSION');
|
||||
|
||||
if (!empty($apiUrl) && !empty($apiKey)) {
|
||||
RetailcrmInventories::$api = new RetailcrmProxy($apiUrl, $apiKey, _PS_ROOT_DIR_ . '/retailcrm.log', $apiVersion);
|
||||
} else {
|
||||
error_log('inventories: set api key & url first', 3, _PS_ROOT_DIR_ . '/retailcrm.log');
|
||||
exit();
|
||||
}
|
||||
|
||||
RetailcrmInventories::loadStocks();
|
@ -99,18 +99,14 @@ class RetailcrmCatalog
|
||||
$weight = null;
|
||||
}
|
||||
|
||||
$width = round($product['width'], 2);
|
||||
$height = round($product['height'], 2);
|
||||
$depth = round($product['depth'], 2);
|
||||
|
||||
$width = round($product['width'], 3);
|
||||
$height = round($product['height'], 3);
|
||||
$depth = round($product['depth'], 3);
|
||||
|
||||
if (!empty($width) && !empty($height)) {
|
||||
if (!empty($depth)) {
|
||||
$size = implode('x', array($width, $height, $depth));
|
||||
} else {
|
||||
$size = implode('x', array($width, $height));
|
||||
}
|
||||
$dimensions = implode('/', array($width, $height, $depth));
|
||||
} else {
|
||||
$size = null;
|
||||
$dimensions = null;
|
||||
}
|
||||
|
||||
$productForCombination = new Product($product['id_product']);
|
||||
@ -170,7 +166,7 @@ class RetailcrmCatalog
|
||||
'vendor' => $vendor,
|
||||
'article' => $article,
|
||||
'weight' => $weight,
|
||||
'size' => $size
|
||||
'dimensions' => $dimensions
|
||||
);
|
||||
|
||||
if (!empty($combinations)) {
|
||||
@ -210,7 +206,7 @@ class RetailcrmCatalog
|
||||
'vendor' => $vendor,
|
||||
'article' => $article,
|
||||
'weight' => $weight,
|
||||
'size' => $size
|
||||
'dimensions' => $dimensions
|
||||
);
|
||||
|
||||
$items[] = $item;
|
||||
|
52
retailcrm/lib/RetailcrmDaemonCollector.php
Normal file
52
retailcrm/lib/RetailcrmDaemonCollector.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
class RetailcrmDaemonCollector
|
||||
{
|
||||
private $customer, $siteKey, $js;
|
||||
|
||||
private $template = <<<EOT
|
||||
<script type="text/javascript">
|
||||
(function(_,r,e,t,a,i,l){_['retailCRMObject']=a;_[a]=_[a]||function(){(_[a].q=_[a].q||[]).push(arguments)};_[a].l=1*new Date();l=r.getElementsByTagName(e)[0];i=r.createElement(e);i.async=!0;i.src=t;l.parentNode.insertBefore(i,l)})(window,document,'script','https://collector.retailcrm.pro/w.js','_rc');
|
||||
{{ code }}
|
||||
_rc('send', 'pageView');
|
||||
</script>
|
||||
EOT;
|
||||
|
||||
public function __construct($customer, $siteKey)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
$this->siteKey = $siteKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJs()
|
||||
{
|
||||
return $this->js;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function buildScript()
|
||||
{
|
||||
$params = array();
|
||||
|
||||
if ($this->customer->id) {
|
||||
$params['customerId'] = $this->customer->id;
|
||||
}
|
||||
|
||||
$this->js = preg_replace(
|
||||
'/{{ code }}/',
|
||||
sprintf(
|
||||
"\t_rc('create', '%s', %s);\n",
|
||||
$this->siteKey,
|
||||
json_encode((object) $params)
|
||||
),
|
||||
$this->template
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -53,6 +53,7 @@ class RetailcrmHistory
|
||||
if (self::loadInCMS($customer, 'update') === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
} else {
|
||||
$customer = new Customer();
|
||||
|
||||
|
@ -24,14 +24,14 @@ class RetailcrmIcml
|
||||
'picture',
|
||||
'url',
|
||||
'xmlId',
|
||||
'productActivity'
|
||||
'productActivity',
|
||||
'dimensions'
|
||||
);
|
||||
|
||||
$this->params = array(
|
||||
'article' => 'Артикул',
|
||||
'color' => 'Цвет',
|
||||
'weight' => 'Вес',
|
||||
'size' => 'Размер',
|
||||
'tax' => 'Наценка'
|
||||
);
|
||||
}
|
||||
@ -94,7 +94,6 @@ class RetailcrmIcml
|
||||
private function addOffers($offers)
|
||||
{
|
||||
foreach ($offers as $offer) {
|
||||
|
||||
$e = $this->eOffers->appendChild(
|
||||
$this->dd->createElement('offer')
|
||||
);
|
||||
|
44
retailcrm/lib/RetailcrmInventories.php
Normal file
44
retailcrm/lib/RetailcrmInventories.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class RetailcrmInventories
|
||||
{
|
||||
public static $api;
|
||||
|
||||
/**
|
||||
* Load stock from retailCRM
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function loadStocks()
|
||||
{
|
||||
$page = 1;
|
||||
|
||||
do {
|
||||
$result = self::$api->storeInventories(array(), $page, 250);
|
||||
|
||||
if ($result === false) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
foreach ($result['offers'] as $offer) {
|
||||
self::setQuantityOffer($offer);
|
||||
}
|
||||
|
||||
$totalPageCount = $result['pagination']['totalPageCount'];
|
||||
$page++;
|
||||
} while ($page <= $totalPageCount);
|
||||
}
|
||||
|
||||
private static function setQuantityOffer($offer)
|
||||
{
|
||||
if (isset($offer['externalId'])) {
|
||||
$invOffer = explode('#', $offer['externalId']);
|
||||
|
||||
if (isset($invOffer[1])) {
|
||||
StockAvailable::setQuantity($invOffer[0], $invOffer[1], $offer['quantity']);
|
||||
} else {
|
||||
StockAvailable::setQuantity($offer['externalId'], 0, $offer['quantity']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
* @author Retail Driver LCC
|
||||
* @copyright RetailCRM
|
||||
* @license GPL
|
||||
* @version 2.2.6
|
||||
* @version 2.2.9
|
||||
* @link https://retailcrm.ru
|
||||
*
|
||||
*/
|
||||
@ -38,7 +38,7 @@ class RetailCRM extends Module
|
||||
{
|
||||
$this->name = 'retailcrm';
|
||||
$this->tab = 'export';
|
||||
$this->version = '2.2.6';
|
||||
$this->version = '2.2.9';
|
||||
$this->author = 'Retail Driver LCC';
|
||||
$this->displayName = $this->l('RetailCRM');
|
||||
$this->description = $this->l('Integration module for RetailCRM');
|
||||
@ -76,10 +76,26 @@ class RetailCRM extends Module
|
||||
$this->registerHook('actionPaymentConfirmation') &&
|
||||
$this->registerHook('actionCustomerAccountAdd') &&
|
||||
$this->registerHook('actionOrderEdited') &&
|
||||
($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true)
|
||||
$this->registerHook('header') &&
|
||||
($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true) &&
|
||||
($this->use_new_hooks ? $this->registerHook('actionValidateCustomerAddressForm') : true)
|
||||
);
|
||||
}
|
||||
|
||||
public function hookHeader()
|
||||
{
|
||||
if (Configuration::get('RETAILCRM_DAEMON_COLLECTOR_ACTIVE')
|
||||
&& Configuration::get('RETAILCRM_DAEMON_COLLECTOR_KEY')
|
||||
) {
|
||||
$collector = new RetailcrmDaemonCollector(
|
||||
$this->context->customer,
|
||||
Configuration::get('RETAILCRM_DAEMON_COLLECTOR_KEY')
|
||||
);
|
||||
|
||||
return $collector->buildScript()->getJs();
|
||||
}
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
$api = new RetailcrmProxy(
|
||||
@ -120,7 +136,10 @@ class RetailCRM extends Module
|
||||
$deliveryDefault = json_encode(Tools::getValue('RETAILCRM_API_DELIVERY_DEFAULT'));
|
||||
$paymentDefault = json_encode(Tools::getValue('RETAILCRM_API_PAYMENT_DEFAULT'));
|
||||
$statusExport = (string)(Tools::getValue('RETAILCRM_STATUS_EXPORT'));
|
||||
$collectorActive = (Tools::getValue('RETAILCRM_DAEMON_COLLECTOR_ACTIVE_1'));
|
||||
$collectorKey = (string)(Tools::getValue('RETAILCRM_DAEMON_COLLECTOR_KEY'));
|
||||
$clientId = Configuration::get('RETAILCRM_CLIENT_ID');
|
||||
|
||||
$settings = array(
|
||||
'address' => $address,
|
||||
'token' => $token,
|
||||
@ -140,6 +159,8 @@ class RetailCRM extends Module
|
||||
Configuration::updateValue('RETAILCRM_API_DELIVERY_DEFAULT', $deliveryDefault);
|
||||
Configuration::updateValue('RETAILCRM_API_PAYMENT_DEFAULT', $paymentDefault);
|
||||
Configuration::updateValue('RETAILCRM_STATUS_EXPORT', $statusExport);
|
||||
Configuration::updateValue('RETAILCRM_DAEMON_COLLECTOR_ACTIVE', $collectorActive);
|
||||
Configuration::updateValue('RETAILCRM_DAEMON_COLLECTOR_KEY', $collectorKey);
|
||||
|
||||
$output .= $this->displayConfirmation($this->l('Settings updated'));
|
||||
}
|
||||
@ -169,7 +190,6 @@ class RetailCRM extends Module
|
||||
|
||||
public function displayForm()
|
||||
{
|
||||
|
||||
$this->displayConfirmation($this->l('Settings updated'));
|
||||
|
||||
$default_lang = $this->default_lang;
|
||||
@ -189,7 +209,7 @@ class RetailCRM extends Module
|
||||
/*
|
||||
* Network connection form
|
||||
*/
|
||||
$fields_form[0]['form'] = array(
|
||||
$fields_form[]['form'] = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Network connection'),
|
||||
),
|
||||
@ -199,9 +219,9 @@ class RetailCRM extends Module
|
||||
'name' => 'RETAILCRM_API_VERSION',
|
||||
'label' => $this->l('API version'),
|
||||
'options' => array(
|
||||
'query' => $apiVersions,
|
||||
'id' => 'option_id',
|
||||
'name' => 'name'
|
||||
'query' => $apiVersions,
|
||||
'id' => 'option_id',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
@ -225,12 +245,41 @@ class RetailCRM extends Module
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
* Daemon Collector
|
||||
*/
|
||||
$fields_form[]['form'] = array(
|
||||
'legend' => array('title' => $this->l('Daemon Collector')),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'label' => $this->l('Activate'),
|
||||
'name' => 'RETAILCRM_DAEMON_COLLECTOR_ACTIVE',
|
||||
'values' => array(
|
||||
'query' => array(
|
||||
array(
|
||||
'id_option' => 1,
|
||||
)
|
||||
),
|
||||
'id' => 'id_option',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Site key'),
|
||||
'name' => 'RETAILCRM_DAEMON_COLLECTOR_KEY',
|
||||
'size' => 20,
|
||||
'required' => false
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if ($this->api) {
|
||||
/*
|
||||
* Delivery
|
||||
*/
|
||||
$fields_form[1]['form'] = array(
|
||||
$fields_form[]['form'] = array(
|
||||
'legend' => array('title' => $this->l('Delivery')),
|
||||
'input' => $this->reference->getDeliveryTypes(),
|
||||
);
|
||||
@ -238,7 +287,7 @@ class RetailCRM extends Module
|
||||
/*
|
||||
* Order status
|
||||
*/
|
||||
$fields_form[2]['form'] = array(
|
||||
$fields_form[]['form'] = array(
|
||||
'legend' => array('title' => $this->l('Order statuses')),
|
||||
'input' => $this->reference->getStatuses(),
|
||||
);
|
||||
@ -246,7 +295,7 @@ class RetailCRM extends Module
|
||||
/*
|
||||
* Payment
|
||||
*/
|
||||
$fields_form[3]['form'] = array(
|
||||
$fields_form[]['form'] = array(
|
||||
'legend' => array('title' => $this->l('Payment types')),
|
||||
'input' => $this->reference->getPaymentTypes(),
|
||||
);
|
||||
@ -254,7 +303,7 @@ class RetailCRM extends Module
|
||||
/*
|
||||
* Default
|
||||
*/
|
||||
$fields_form[4]['form'] = array(
|
||||
$fields_form[]['form'] = array(
|
||||
'legend' => array('title' => $this->l('Default')),
|
||||
'input' => $this->reference->getPaymentAndDeliveryForDefault(
|
||||
array($this->l('Delivery method'), $this->l('Payment type'))
|
||||
@ -264,16 +313,16 @@ class RetailCRM extends Module
|
||||
/*
|
||||
* Status in export
|
||||
*/
|
||||
$fields_form[5]['form'] = array(
|
||||
$fields_form[]['form'] = array(
|
||||
'legend' => array('title' => $this->l('Default status')),
|
||||
'input' => array(array(
|
||||
'type' => 'select',
|
||||
'name' => 'RETAILCRM_STATUS_EXPORT',
|
||||
'label' => $this->l('Default status in export'),
|
||||
'options' => array(
|
||||
'query' => $this->reference->getStatuseDefaultExport(),
|
||||
'id' => 'id_option',
|
||||
'name' => 'name'
|
||||
'query' => $this->reference->getStatuseDefaultExport(),
|
||||
'id' => 'id_option',
|
||||
'name' => 'name'
|
||||
)
|
||||
)),
|
||||
);
|
||||
@ -319,6 +368,8 @@ class RetailCRM extends Module
|
||||
$helper->fields_value['RETAILCRM_API_TOKEN'] = Configuration::get('RETAILCRM_API_TOKEN');
|
||||
$helper->fields_value['RETAILCRM_API_VERSION'] = Configuration::get('RETAILCRM_API_VERSION');
|
||||
$helper->fields_value['RETAILCRM_STATUS_EXPORT'] = Configuration::get('RETAILCRM_STATUS_EXPORT');
|
||||
$helper->fields_value['RETAILCRM_DAEMON_COLLECTOR_ACTIVE_1'] = Configuration::get('RETAILCRM_DAEMON_COLLECTOR_ACTIVE');
|
||||
$helper->fields_value['RETAILCRM_DAEMON_COLLECTOR_KEY'] = Configuration::get('RETAILCRM_DAEMON_COLLECTOR_KEY');
|
||||
|
||||
$deliverySettings = Configuration::get('RETAILCRM_API_DELIVERY');
|
||||
if (isset($deliverySettings) && $deliverySettings != '') {
|
||||
@ -418,11 +469,27 @@ class RetailCRM extends Module
|
||||
$customerSend = array_merge($customerSend, $address['customer']);
|
||||
}
|
||||
|
||||
if (isset($params['cart'])){
|
||||
$address = $this->addressParse($params['cart']);
|
||||
$customerSend = array_merge($customerSend, $address['customer']);
|
||||
}
|
||||
|
||||
$customerSend = array_merge($customerSend, $address['customer']);
|
||||
|
||||
$this->api->customersEdit($customerSend);
|
||||
|
||||
return $customerSend;
|
||||
}
|
||||
|
||||
// this hook added in 1.7
|
||||
public function hookActionValidateCustomerAddressForm($params)
|
||||
{
|
||||
$customer = new Customer($params['cart']->id_customer);
|
||||
$customerAddress = array('customer' => $customer, 'cart' => $params['cart']);
|
||||
|
||||
return $this->hookActionCustomerAccountUpdate($customerAddress);
|
||||
}
|
||||
|
||||
public function hookNewOrder($params)
|
||||
{
|
||||
return $this->hookActionOrderStatusPostUpdate($params);
|
||||
@ -444,7 +511,6 @@ class RetailCRM extends Module
|
||||
|
||||
public function hookActionOrderEdited($params)
|
||||
{
|
||||
|
||||
$order = array(
|
||||
'externalId' => $params['order']->id,
|
||||
'firstName' => $params['customer']->firstname,
|
||||
@ -490,6 +556,65 @@ class RetailCRM extends Module
|
||||
return $order;
|
||||
}
|
||||
|
||||
private function addressParse($address)
|
||||
{
|
||||
if ($address instanceof Address) {
|
||||
$postcode = $address->postcode;
|
||||
$city = $address->city;
|
||||
$addres_line = sprintf("%s %s", $address->address1, $address->address2);
|
||||
$countryIso = CountryCore::getIsoById($address->id_country);
|
||||
}
|
||||
|
||||
if (!empty($postcode)) {
|
||||
$customer['address']['index'] = $postcode;
|
||||
$order['delivery']['address']['index'] = $postcode;
|
||||
}
|
||||
|
||||
if (!empty($city)) {
|
||||
$customer['address']['city'] = $city;
|
||||
$order['delivery']['address']['city'] = $city;
|
||||
}
|
||||
|
||||
if (!empty($addres_line)) {
|
||||
$customer['address']['text'] = $addres_line;
|
||||
$order['delivery']['address']['text'] = $addres_line;
|
||||
}
|
||||
|
||||
if (!empty($countryIso)) {
|
||||
$order['countryIso'] = $countryIso;
|
||||
$customer['address']['countryIso'] = $countryIso;
|
||||
}
|
||||
|
||||
$phones = $this->getPhone($address);
|
||||
$order = array_merge($order, $phones['order']);
|
||||
$customer = array_merge($customer, $phones['customer']);
|
||||
$addressArray = array('order' => $order, 'customer' => $customer);
|
||||
|
||||
return $addressArray;
|
||||
}
|
||||
|
||||
private function getPhone($address)
|
||||
{
|
||||
if (!empty($address->phone_mobile)){
|
||||
$order['phone'] = $address->phone_mobile;
|
||||
$customer['phones'][] = array('number'=> $address->phone_mobile);
|
||||
}
|
||||
|
||||
if (!empty($address->phone)){
|
||||
$order['additionalPhone'] = $address->phone;
|
||||
$customer['phones'][] = array('number'=> $address->phone);
|
||||
}
|
||||
|
||||
if (!isset($order['phone']) && !empty($order['additionalPhone'])){
|
||||
$order['phone'] = $order['additionalPhone'];
|
||||
unset($order['additionalPhone']);
|
||||
}
|
||||
|
||||
$phonesArray = array('customer' => $customer, 'order' => $order);
|
||||
|
||||
return $phonesArray;
|
||||
}
|
||||
|
||||
public function hookActionOrderStatusPostUpdate($params)
|
||||
{
|
||||
$delivery = json_decode(Configuration::get('RETAILCRM_API_DELIVERY'), true);
|
||||
@ -521,9 +646,11 @@ class RetailCRM extends Module
|
||||
}
|
||||
|
||||
$cart = $params['cart'];
|
||||
|
||||
$addressCollection = $cart->getAddressCollection();
|
||||
$address = array_shift($addressCollection);
|
||||
$address = $this->addressParse($address);
|
||||
|
||||
$customer = array_merge($customer, $address['customer']);
|
||||
$order = array_merge($order, $address['order']);
|
||||
$comment = $params['order']->getFirstMessage();
|
||||
@ -754,74 +881,6 @@ class RetailCRM extends Module
|
||||
return $output;
|
||||
}
|
||||
|
||||
private function addressParse($address)
|
||||
{
|
||||
|
||||
if ($address instanceof Address) {
|
||||
$postcode = $address->postcode;
|
||||
$city = $address->city;
|
||||
$addres_line = sprintf("%s %s", $address->address1, $address->address2);
|
||||
$countryIso = CountryCore::getIsoById($address->id_country);
|
||||
}
|
||||
|
||||
if (!empty($postcode)) {
|
||||
$customer['address']['index'] = $postcode;
|
||||
$order['delivery']['address']['index'] = $postcode;
|
||||
}
|
||||
|
||||
if (!empty($city)) {
|
||||
$customer['address']['city'] = $city;
|
||||
$order['delivery']['address']['city'] = $city;
|
||||
}
|
||||
|
||||
if (!empty($addres_line)) {
|
||||
$customer['address']['text'] = $addres_line;
|
||||
$order['delivery']['address']['text'] = $addres_line;
|
||||
}
|
||||
|
||||
if (!empty($countryIso)) {
|
||||
$order['countryIso'] = $countryIso;
|
||||
$customer['address']['countryIso'] = $countryIso;
|
||||
}
|
||||
|
||||
$phones = $this->getPhone($address);
|
||||
|
||||
if ($phones !== false) {
|
||||
$order = array_merge($order, $phones['order']);
|
||||
$customer = array_merge($customer, $phones['customer']);
|
||||
}
|
||||
|
||||
$addressArray = array('order' => $order, 'customer' => $customer);
|
||||
|
||||
return $addressArray;
|
||||
}
|
||||
|
||||
private function getPhone($address)
|
||||
{
|
||||
if (!empty($address->phone_mobile)){
|
||||
$order['phone'] = $address->phone_mobile;
|
||||
$customer['phones'][] = array('number'=> $address->phone_mobile);
|
||||
}
|
||||
|
||||
if (!empty($address->phone)){
|
||||
$order['additionalPhone'] = $address->phone;
|
||||
$customer['phones'][] = array('number'=> $address->phone);
|
||||
}
|
||||
|
||||
if (!isset($order['phone']) && !empty($order['additionalPhone'])){
|
||||
$order['phone'] = $order['additionalPhone'];
|
||||
unset($order['additionalPhone']);
|
||||
}
|
||||
if (!empty($customer) && !empty($order)) {
|
||||
$phonesArray = array('customer' => $customer, 'order' => $order);
|
||||
|
||||
return $phonesArray;
|
||||
} else {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate/deactivate module in marketplace retailCRM
|
||||
*
|
||||
|
@ -15,6 +15,9 @@ $_MODULE['<{retailcrm}prestashop>retailcrm_c888438d14855d7d96a2724ee9c306bd'] =
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_51af428aa0dcceb5230acb267ecb91c5'] = 'La configuración de la conexión';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_4cbd5dbeeef7392e50358b1bc00dd592'] = 'URL CRM';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_7f775042e08eddee6bbfd8fbe0add4a3'] = 'La clave API';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_52a13123e134b8b72b6299bc14a36aad'] = 'Daemon Collector';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_a13367a8e2a3f3bf4f3409079e3fdf87'] = 'Active';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_f75d8fa5c89351544d372cf90528ccf2'] = 'Clave de la página web';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_c9cc8cce247e49bae79f15173ce97354'] = 'Guardar';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_065ab3a28ca4f16f55f103adc7d0226f'] = 'Los métodos del envío';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_33af8066d3c83110d4bd897f687cedd2'] = 'Los estados de pedidos';
|
||||
|
@ -15,6 +15,9 @@ $_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_52a13123e134b8b72b6299bc14a36aad'] = 'Daemon Collector';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_a13367a8e2a3f3bf4f3409079e3fdf87'] = 'Активировать';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_f75d8fa5c89351544d372cf90528ccf2'] = 'Ключ сайта';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_c9cc8cce247e49bae79f15173ce97354'] = 'Сохранить';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_065ab3a28ca4f16f55f103adc7d0226f'] = 'Способы доставки';
|
||||
$_MODULE['<{retailcrm}prestashop>retailcrm_33af8066d3c83110d4bd897f687cedd2'] = 'Статусы заказов';
|
||||
|
40
tests/phpunit/RetailcrmDaemonCollectorTest.php
Normal file
40
tests/phpunit/RetailcrmDaemonCollectorTest.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
class RetailcrmDaemonCollectorTest extends RetailcrmTestCase
|
||||
{
|
||||
const KEY = 'test-key';
|
||||
const ID = '1';
|
||||
|
||||
public function testBuildJsWithCustomer()
|
||||
{
|
||||
$customer = new Customer;
|
||||
$customer->id = self::ID;
|
||||
|
||||
$collector = new RetailcrmDaemonCollector(
|
||||
$customer,
|
||||
self::KEY
|
||||
);
|
||||
|
||||
$js = $collector->buildScript()->getJs();
|
||||
|
||||
$this->assertContains('customerId', $js);
|
||||
$this->assertContains('<script', $js);
|
||||
$this->assertContains('</script>', $js);
|
||||
}
|
||||
|
||||
public function testBuildJsWithoutCustomer()
|
||||
{
|
||||
$customer = new Customer;
|
||||
|
||||
$collector = new RetailcrmDaemonCollector(
|
||||
$customer,
|
||||
self::KEY
|
||||
);
|
||||
|
||||
$js = $collector->buildScript()->getJs();
|
||||
|
||||
$this->assertNotContains('customerId', $js);
|
||||
$this->assertContains('<script', $js);
|
||||
$this->assertContains('</script>', $js);
|
||||
}
|
||||
}
|
136
tests/phpunit/RetailcrmInventoriesTest.php
Normal file
136
tests/phpunit/RetailcrmInventoriesTest.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
class RetailcrmInventoriesTest extends RetailcrmTestCase
|
||||
{
|
||||
private $apiMock;
|
||||
private $product1;
|
||||
private $product2;
|
||||
|
||||
const PRODUCT1_QUANTITY = 10;
|
||||
const PRODUCT2_QUANTITY = 15;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->apiMock = $this->getMockBuilder('RetailcrmProxy')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(
|
||||
array(
|
||||
'storeInventories'
|
||||
)
|
||||
)
|
||||
->getMock();
|
||||
|
||||
$catalog = new RetailcrmCatalog();
|
||||
$data = $catalog->getData();
|
||||
|
||||
$this->product1 = $data[1][0];
|
||||
$this->product2 = $data[1][1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $apiVersion
|
||||
* @param $response
|
||||
*
|
||||
* @dataProvider dataProviderLoadStocks
|
||||
*/
|
||||
public function testLoadStocks($apiVersion, $response)
|
||||
{
|
||||
if ($response['success'] == true) {
|
||||
$this->apiMock->expects($this->any())
|
||||
->method('storeInventories')
|
||||
->willReturn(
|
||||
new RetailcrmApiResponse(
|
||||
'200',
|
||||
json_encode(
|
||||
$this->getApiInventories()
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->apiMock->expects($this->any())
|
||||
->method('storeInventories')
|
||||
->willReturn($response);
|
||||
}
|
||||
|
||||
RetailcrmInventories::$api = $this->apiMock;
|
||||
|
||||
RetailcrmInventories::loadStocks();
|
||||
|
||||
$product1Id = explode('#', $this->product1['id']);
|
||||
$product2Id = explode('#', $this->product2['id']);
|
||||
|
||||
if (isset($product1Id[1])){
|
||||
$prod1Quantity = StockAvailable::getQuantityAvailableByProduct($product1Id[0], $product1Id[1]);
|
||||
} else {
|
||||
$prod1Quantity = StockAvailable::getQuantityAvailableByProduct($product1Id[0], 0);
|
||||
}
|
||||
|
||||
if (isset($product2Id[1])){
|
||||
$prod2Quantity = StockAvailable::getQuantityAvailableByProduct($product2Id[0], $product2Id[1]);
|
||||
} else {
|
||||
$prod2Quantity = StockAvailable::getQuantityAvailableByProduct($product2Id[0], 0);
|
||||
}
|
||||
|
||||
$this->assertEquals(self::PRODUCT1_QUANTITY, $prod1Quantity);
|
||||
$this->assertEquals(self::PRODUCT2_QUANTITY, $prod2Quantity);
|
||||
}
|
||||
|
||||
public function dataProviderLoadStocks()
|
||||
{
|
||||
$response = $this->getResponseData();
|
||||
|
||||
return array(
|
||||
array(
|
||||
'api_version' => 4,
|
||||
'response' => $response['true'],
|
||||
),
|
||||
array(
|
||||
'api_version' => 5,
|
||||
'response' => $response['true']
|
||||
),
|
||||
array(
|
||||
'api_version' => 4,
|
||||
'response' => $response['false']
|
||||
),
|
||||
array(
|
||||
'api_version' => 5,
|
||||
'response' => $response['false']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function getResponseData()
|
||||
{
|
||||
return array(
|
||||
'true' => $this->getApiInventories(),
|
||||
'false' => false
|
||||
);
|
||||
}
|
||||
|
||||
private function getApiInventories()
|
||||
{
|
||||
return array(
|
||||
"success" => true,
|
||||
"pagination"=> array(
|
||||
"limit"=> 250,
|
||||
"totalCount"=> 1,
|
||||
"currentPage"=> 1,
|
||||
"totalPageCount"=> 1
|
||||
),
|
||||
"offers" => array(
|
||||
array(
|
||||
'externalId' => $this->product1['id'],
|
||||
'xmlId' => 'xmlId',
|
||||
'quantity' => self::PRODUCT1_QUANTITY,
|
||||
),
|
||||
array(
|
||||
'externalId' => $this->product2['id'],
|
||||
'xmlId' => 'xmlId',
|
||||
'quantity' => self::PRODUCT2_QUANTITY,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -48,6 +48,7 @@ class RetailCRMTest extends RetailcrmTestCase
|
||||
public function testHookActionCustomerAccountUpdate()
|
||||
{
|
||||
$customer = new Customer(1);
|
||||
|
||||
$params = array('customer' => $customer);
|
||||
$customer = $this->retailcrmModule->hookActionCustomerAccountUpdate($params);
|
||||
|
||||
@ -125,6 +126,11 @@ class RetailCRMTest extends RetailcrmTestCase
|
||||
$this->assertArrayHasKey('lastName', $result);
|
||||
$this->assertArrayHasKey('email', $result);
|
||||
$this->assertArrayHasKey('delivery', $result);
|
||||
$this->assertArrayHasKey('address', $result['delivery']);
|
||||
$this->assertArrayHasKey('city', $result['delivery']['address']);
|
||||
$this->assertArrayHasKey('text', $result['delivery']['address']);
|
||||
$this->assertArrayHasKey('index', $result['delivery']['address']);
|
||||
$this->assertArrayHasKey('countryIso', $result);
|
||||
$this->assertArrayHasKey('items', $result);
|
||||
$this->assertArrayHasKey('customer', $result);
|
||||
$this->assertArrayHasKey('externalId', $result['customer']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user