From 4dfc7b8d1acbf9bdc33ac6484f0d7f4171e774d6 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 16 Jan 2019 13:11:34 +0300 Subject: [PATCH 01/12] v2.2.9 --- CHANGELOG.md | 3 +++ VERSION | 2 +- retailcrm/lib/RetailcrmCatalog.php | 20 ++++++++------------ retailcrm/lib/RetailcrmIcml.php | 5 ++--- retailcrm/retailcrm.php | 4 ++-- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8bd3fc..3c09de5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v2.2.9 +* Добавлена выгрузка габаритов в специальный тег dimensions + ## v2.2.8 * Добавлена выгрузка картинок категорий товаров в ICML diff --git a/VERSION b/VERSION index 23a63f5..a6333e4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.8 +2.2.9 diff --git a/retailcrm/lib/RetailcrmCatalog.php b/retailcrm/lib/RetailcrmCatalog.php index 57952c9..cca45b0 100644 --- a/retailcrm/lib/RetailcrmCatalog.php +++ b/retailcrm/lib/RetailcrmCatalog.php @@ -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; diff --git a/retailcrm/lib/RetailcrmIcml.php b/retailcrm/lib/RetailcrmIcml.php index 77b7f84..ab7c9ed 100644 --- a/retailcrm/lib/RetailcrmIcml.php +++ b/retailcrm/lib/RetailcrmIcml.php @@ -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') ); diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index f8b45d3..e401a84 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -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'); From 3e47ce29b470c2216623a55d19f57ce1d88777e7 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 24 Oct 2018 16:15:28 +0300 Subject: [PATCH 02/12] v2.2.5 --- CHANGELOG.md | 10 +- VERSION | 2 +- retailcrm/lib/RetailcrmHistory.php | 1 + retailcrm/retailcrm.php | 154 ++++++++++++++++------------- tests/phpunit/RetailcrmTest.php | 6 ++ 5 files changed, 99 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c09de5..6231011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,13 @@ ## v2.2.6 * Добавлена активация модуля в маркетплейсе retailCRM -## v2.2.5 -* Добавлена передача страны при создании заказа для пользователя и заказа -* Добавлен метод сохранения сущностей с обработкой исключений +## v.2.2.5 +* Добавлена передача страны при создании заказа для заказа и покупателя +* Добавлен метод для загрузки сущностей с перехватом исключений +* Для версии 1.7 добавлена передача адреса при заполнении его на стороне сайта. +* Получение адреса и телефона вынесено в отдельные методы. -## v2.2.4 +## v.2.2.4 * Добавлена установка дефолтной валюты для оплаты при получении истории * Добавлено получение суммы оплаты из заказа в CMS, если она не передается по истории diff --git a/VERSION b/VERSION index a6333e4..72d132f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.9 +2.2.9 \ No newline at end of file diff --git a/retailcrm/lib/RetailcrmHistory.php b/retailcrm/lib/RetailcrmHistory.php index aa53a7d..7339e03 100644 --- a/retailcrm/lib/RetailcrmHistory.php +++ b/retailcrm/lib/RetailcrmHistory.php @@ -53,6 +53,7 @@ class RetailcrmHistory if (self::loadInCMS($customer, 'update') === false) { continue; } + } else { $customer = new Customer(); diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index e401a84..8f22be4 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -3,7 +3,11 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL +<<<<<<< 4dfc7b8d1acbf9bdc33ac6484f0d7f4171e774d6 * @version 2.2.9 +======= + * @version 2.2.5 +>>>>>>> v2.2.5 * @link https://retailcrm.ru * */ @@ -76,7 +80,8 @@ class RetailCRM extends Module $this->registerHook('actionPaymentConfirmation') && $this->registerHook('actionCustomerAccountAdd') && $this->registerHook('actionOrderEdited') && - ($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true) + ($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true) && + ($this->use_new_hooks ? $this->registerHook('actionValidateCustomerAddressForm') : true) ); } @@ -418,11 +423,26 @@ 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']); + $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); @@ -490,6 +510,68 @@ class RetailCRM extends Module return $order; } + private function addressParse($address) + { + $addressCollection = $address->getAddressCollection(); + $address = array_shift($addressCollection); + + 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 +603,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 +838,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 * diff --git a/tests/phpunit/RetailcrmTest.php b/tests/phpunit/RetailcrmTest.php index c3cabb0..d3fd4d6 100644 --- a/tests/phpunit/RetailcrmTest.php +++ b/tests/phpunit/RetailcrmTest.php @@ -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']); From d6053cc9fe892de985b3a100bd1668703c91cdef Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 24 Oct 2018 16:34:14 +0300 Subject: [PATCH 03/12] v2.2.5 --- retailcrm/retailcrm.php | 1 + 1 file changed, 1 insertion(+) diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 8f22be4..24efb84 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -425,6 +425,7 @@ class RetailCRM extends Module if (isset($params['cart'])){ $address = $this->addressParse($params['cart']); + $customerSend = array_merge($customerSend, $address['customer']); } $customerSend = array_merge($customerSend, $address['customer']); From 058f007b366ccd4ba8f41bf3a4b7317373bcd2bc Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 18 Jan 2019 15:56:22 +0300 Subject: [PATCH 04/12] v2.2.9 --- retailcrm/job/inventories.php | 29 ++++++ retailcrm/lib/RetailcrmInventories.php | 53 ++++++++++ tests/phpunit/RetailcrmInventoriesTest.php | 112 +++++++++++++++++++++ 3 files changed, 194 insertions(+) create mode 100644 retailcrm/job/inventories.php create mode 100644 retailcrm/lib/RetailcrmInventories.php create mode 100644 tests/phpunit/RetailcrmInventoriesTest.php diff --git a/retailcrm/job/inventories.php b/retailcrm/job/inventories.php new file mode 100644 index 0000000..05c8b74 --- /dev/null +++ b/retailcrm/job/inventories.php @@ -0,0 +1,29 @@ +storeInventories(array(), $page, 250); + + if (!$result->isSuccessful()) { + return null; + } + + $totalPageCount = $result['pagination']['totalPageCount']; + $page++; + foreach ($result['offers'] as $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']); + } + } + } + } while ($page <= $totalPageCount); + + return $success; + } + + /** + * Update stock quantity in WooCommerce + * + * @return mixed + */ + public function updateQuantity() { + + return $this->load_stocks(); + + } + +} diff --git a/tests/phpunit/RetailcrmInventoriesTest.php b/tests/phpunit/RetailcrmInventoriesTest.php new file mode 100644 index 0000000..0d7b194 --- /dev/null +++ b/tests/phpunit/RetailcrmInventoriesTest.php @@ -0,0 +1,112 @@ +apiMock = $this->getMockBuilder('RetailcrmProxy') + ->disableOriginalConstructor() + ->setMethods( + array( + 'storeInventories' + ) + ) + ->getMock(); + $catalog = new RetailcrmCatalog(); + $data = $catalog->getData(); + $this->product = $data[1][0]; + + $this->setConfig(); + } + + private function getResponseData() + { + return array( + 'true' => array( + 'success' => true, + 'pagination' => array( + 'limit' => 250, + 'totalCount' => 1, + 'currentPage' => 1, + 'totalPageCount' => 1 + ), + 'offers' => array( + array( + 'id' => 1, + 'xmlId' => 'xmlId', + 'quantity' => 10 + ) + ) + ), + 'false' => array( + 'success' => false, + 'errorMsg' => 'Forbidden' + ) + ); + } + /** + * @param $retailcrm + * @param $response + * + * @dataProvider dataProviderLoadStocks + */ + public function test_load_stocks($apiVersion, $response) + { + if ($response['success'] == true) { + $response['offers'][0]['externalId'] = $this->product['id']; + $this->responseMock->expects($this->any()) + ->method('isSuccessful') + ->willReturn(true); + } elseif ($response['success'] == false) { + $this->responseMock->expects($this->any()) + ->method('isSuccessful') + ->willReturn(false); + } + + $this->responseMock->setResponse($response); + + if ($retailcrm) { + $retailcrm->expects($this->any()) + ->method('storeInventories') + ->willReturn($this->responseMock); + } + + RetailcrmInventories::$apiVersion = $apiVersion; + RetailcrmInventories::$api = $this->apiMock; + + RetailcrmInventories::load_stocks(); + + } + + public function dataProviderLoadStocks() + { + $this->setUp(); + + $response = $this->getResponseData(); + + return array( + array( + + 'response' => $response['true'], + 'api_version' => 4 + ), + array( + 'api_version' => 5, + 'response' => $response['true'] + ), + array( + 'api_version' => 4, + 'response' => $response['false'] + ), + array( + 'api_version' => 5, + 'response' => $response['false'] + ) + ); + } +} \ No newline at end of file From f520e7b181586d354d2fc61b19bd712f675da14b Mon Sep 17 00:00:00 2001 From: Sergey Date: Fri, 18 Jan 2019 16:24:10 +0300 Subject: [PATCH 05/12] v2.2.9 --- tests/phpunit/RetailcrmInventoriesTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/RetailcrmInventoriesTest.php b/tests/phpunit/RetailcrmInventoriesTest.php index 0d7b194..e68543e 100644 --- a/tests/phpunit/RetailcrmInventoriesTest.php +++ b/tests/phpunit/RetailcrmInventoriesTest.php @@ -50,7 +50,7 @@ class RetailcrmInventoriesTest extends RetailcrmTestCase ); } /** - * @param $retailcrm + * @param $apiVersion * @param $response * * @dataProvider dataProviderLoadStocks @@ -59,22 +59,22 @@ class RetailcrmInventoriesTest extends RetailcrmTestCase { if ($response['success'] == true) { $response['offers'][0]['externalId'] = $this->product['id']; - $this->responseMock->expects($this->any()) + $this->apiMock->expects($this->any()) ->method('isSuccessful') ->willReturn(true); } elseif ($response['success'] == false) { - $this->responseMock->expects($this->any()) + $this->apiMock->expects($this->any()) ->method('isSuccessful') ->willReturn(false); } - $this->responseMock->setResponse($response); + $this->apiMock->setResponse($response); - if ($retailcrm) { - $retailcrm->expects($this->any()) + + $this->apiMock->expects($this->any()) ->method('storeInventories') - ->willReturn($this->responseMock); - } + ->willReturn($this->apiMock); + RetailcrmInventories::$apiVersion = $apiVersion; RetailcrmInventories::$api = $this->apiMock; From e13ddff1b5fd667fe68383b7bb5a22a3905a3cb7 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 18 Jan 2019 17:04:32 +0300 Subject: [PATCH 06/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20Daemon=20Collector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- retailcrm/lib/RetailcrmDaemonCollector.php | 52 ++++++++++++ retailcrm/retailcrm.php | 84 ++++++++++++++----- .../phpunit/RetailcrmDaemonCollectorTest.php | 40 +++++++++ 3 files changed, 155 insertions(+), 21 deletions(-) create mode 100644 retailcrm/lib/RetailcrmDaemonCollector.php create mode 100644 tests/phpunit/RetailcrmDaemonCollectorTest.php diff --git a/retailcrm/lib/RetailcrmDaemonCollector.php b/retailcrm/lib/RetailcrmDaemonCollector.php new file mode 100644 index 0000000..42e6d6e --- /dev/null +++ b/retailcrm/lib/RetailcrmDaemonCollector.php @@ -0,0 +1,52 @@ + + (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'); + +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; + } +} diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 24efb84..248952c 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -3,11 +3,7 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL -<<<<<<< 4dfc7b8d1acbf9bdc33ac6484f0d7f4171e774d6 * @version 2.2.9 -======= - * @version 2.2.5 ->>>>>>> v2.2.5 * @link https://retailcrm.ru * */ @@ -80,11 +76,26 @@ class RetailCRM extends Module $this->registerHook('actionPaymentConfirmation') && $this->registerHook('actionCustomerAccountAdd') && $this->registerHook('actionOrderEdited') && + $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( @@ -125,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, @@ -145,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')); } @@ -174,7 +190,6 @@ class RetailCRM extends Module public function displayForm() { - $this->displayConfirmation($this->l('Settings updated')); $default_lang = $this->default_lang; @@ -194,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'), ), @@ -204,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( @@ -230,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(), ); @@ -243,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(), ); @@ -251,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(), ); @@ -259,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')) @@ -269,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' ) )), ); @@ -324,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 != '') { @@ -465,7 +511,6 @@ class RetailCRM extends Module public function hookActionOrderEdited($params) { - $order = array( 'externalId' => $params['order']->id, 'firstName' => $params['customer']->firstname, @@ -513,9 +558,6 @@ class RetailCRM extends Module private function addressParse($address) { - $addressCollection = $address->getAddressCollection(); - $address = array_shift($addressCollection); - if ($address instanceof Address) { $postcode = $address->postcode; $city = $address->city; diff --git a/tests/phpunit/RetailcrmDaemonCollectorTest.php b/tests/phpunit/RetailcrmDaemonCollectorTest.php new file mode 100644 index 0000000..1df7f36 --- /dev/null +++ b/tests/phpunit/RetailcrmDaemonCollectorTest.php @@ -0,0 +1,40 @@ +id = self::ID; + + $collector = new RetailcrmDaemonCollector( + $customer, + self::KEY + ); + + $js = $collector->buildScript()->getJs(); + + $this->assertContains('customerId', $js); + $this->assertContains('assertContains('', $js); + } + + public function testBuildJsWithoutCustomer() + { + $customer = new Customer; + + $collector = new RetailcrmDaemonCollector( + $customer, + self::KEY + ); + + $js = $collector->buildScript()->getJs(); + + $this->assertNotContains('customerId', $js); + $this->assertContains('assertContains('', $js); + } +} From b64bb2599cf01ef356fe29388ff0797c73bf8752 Mon Sep 17 00:00:00 2001 From: Sergey Date: Mon, 21 Jan 2019 14:42:19 +0300 Subject: [PATCH 07/12] v2.2.9 --- CHANGELOG.md | 2 + README.md | 8 ++ README.ru.md | 8 ++ retailcrm/job/inventories.php | 5 +- retailcrm/lib/RetailcrmInventories.php | 47 ++++---- tests/phpunit/RetailcrmInventoriesTest.php | 123 ++++++++++++--------- 6 files changed, 108 insertions(+), 85 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c09de5..f5bf55a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## v2.2.9 * Добавлена выгрузка габаритов в специальный тег dimensions +* Добавлена выгрузка остатков из CRM +* Добавлена передача номера заказа ## v2.2.8 * Добавлена выгрузка картинок категорий товаров в ICML diff --git a/README.md b/README.md index 60b891f..885e710 100644 --- a/README.md +++ b/README.md @@ -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/sync.php +``` + #### Single orders archive export to retailCRM ``` diff --git a/README.ru.md b/README.ru.md index d7a5e80..92904fc 100644 --- a/README.ru.md +++ b/README.ru.md @@ -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/sync.php +``` + #### Единоразовая выгрузка архива клиентов и заказов в retailCRM ``` diff --git a/retailcrm/job/inventories.php b/retailcrm/job/inventories.php index 05c8b74..04a992b 100644 --- a/retailcrm/job/inventories.php +++ b/retailcrm/job/inventories.php @@ -3,7 +3,7 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL - * @version 2.2.0 + * @version 2.2.9 * @link https://retailcrm.ru * */ @@ -18,7 +18,6 @@ $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 { @@ -26,4 +25,4 @@ if (!empty($apiUrl) && !empty($apiKey)) { exit(); } -RetailcrmInventories::load_stocks(); +RetailcrmInventories::loadStocks(); diff --git a/retailcrm/lib/RetailcrmInventories.php b/retailcrm/lib/RetailcrmInventories.php index eaa8bbc..a8c2486 100644 --- a/retailcrm/lib/RetailcrmInventories.php +++ b/retailcrm/lib/RetailcrmInventories.php @@ -1,53 +1,44 @@ storeInventories(array(), $page, 250); - if (!$result->isSuccessful()) { - return null; + if ($result === false) { + return $result; + } + + foreach ($result['offers'] as $offer) { + self::setQuantityOffer($offer); } $totalPageCount = $result['pagination']['totalPageCount']; $page++; - foreach ($result['offers'] as $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']); - } - } - } } while ($page <= $totalPageCount); - - return $success; } - /** - * Update stock quantity in WooCommerce - * - * @return mixed - */ - public function updateQuantity() { + private static function setQuantityOffer($offer) + { + if (isset($offer['externalId'])) { + $invOffer = explode('#', $offer['externalId']); - return $this->load_stocks(); - + if (isset($invOffer[1])) { + StockAvailable::setQuantity($invOffer[0], $invOffer[1], $offer['quantity']); + } else { + StockAvailable::setQuantity($offer['externalId'], 0, $offer['quantity']); + } + } } - } diff --git a/tests/phpunit/RetailcrmInventoriesTest.php b/tests/phpunit/RetailcrmInventoriesTest.php index e68543e..352b408 100644 --- a/tests/phpunit/RetailcrmInventoriesTest.php +++ b/tests/phpunit/RetailcrmInventoriesTest.php @@ -3,8 +3,12 @@ class RetailcrmInventoriesTest extends RetailcrmTestCase { private $apiMock; - private $product; + private $product1; + private $product2; + const PRODUCT1_QUANTITY = 10; + const PRODUCT2_QUANTITY = 15; + public function setUp() { parent::setUp(); @@ -17,83 +21,61 @@ class RetailcrmInventoriesTest extends RetailcrmTestCase ) ) ->getMock(); + $catalog = new RetailcrmCatalog(); $data = $catalog->getData(); - $this->product = $data[1][0]; - $this->setConfig(); + $this->product1 = $data[1][0]; + $this->product2 = $data[1][1]; } - private function getResponseData() - { - return array( - 'true' => array( - 'success' => true, - 'pagination' => array( - 'limit' => 250, - 'totalCount' => 1, - 'currentPage' => 1, - 'totalPageCount' => 1 - ), - 'offers' => array( - array( - 'id' => 1, - 'xmlId' => 'xmlId', - 'quantity' => 10 - ) - ) - ), - 'false' => array( - 'success' => false, - 'errorMsg' => 'Forbidden' - ) - ); - } /** * @param $apiVersion * @param $response * * @dataProvider dataProviderLoadStocks */ - public function test_load_stocks($apiVersion, $response) + public function testLoadStocks($apiVersion, $response) { if ($response['success'] == true) { - $response['offers'][0]['externalId'] = $this->product['id']; - $this->apiMock->expects($this->any()) - ->method('isSuccessful') - ->willReturn(true); - } elseif ($response['success'] == false) { - $this->apiMock->expects($this->any()) - ->method('isSuccessful') - ->willReturn(false); - } - - $this->apiMock->setResponse($response); - - $this->apiMock->expects($this->any()) ->method('storeInventories') - ->willReturn($this->apiMock); - - - RetailcrmInventories::$apiVersion = $apiVersion; + ->willReturn( + new RetailcrmApiResponse( + '200', + json_encode( + $this->getApiInventories() + ) + ) + ); + } else { + $this->apiMock->expects($this->any()) + ->method('storeInventories') + ->willReturn($response); + } + RetailcrmInventories::$api = $this->apiMock; - - RetailcrmInventories::load_stocks(); - + + RetailcrmInventories::loadStocks(); + + $product1Id = explode('#', $this->product1['id']); + $product2Id = explode('#', $this->product2['id']); + + $prod1Quantity = StockAvailable::getQuantityAvailableByProduct($product1Id[0], $product1Id[1] ); + $prod2Quantity = StockAvailable::getQuantityAvailableByProduct($product2Id[0], $product2Id[1] ); + + $this->assertEquals(self::PRODUCT1_QUANTITY, $prod1Quantity); + $this->assertEquals(self::PRODUCT2_QUANTITY, $prod2Quantity); } public function dataProviderLoadStocks() { - $this->setUp(); - $response = $this->getResponseData(); return array( array( - + 'api_version' => 4, 'response' => $response['true'], - 'api_version' => 4 ), array( 'api_version' => 5, @@ -109,4 +91,37 @@ class RetailcrmInventoriesTest extends RetailcrmTestCase ) ); } -} \ No newline at end of file + + 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, + ) + ) + ); + } +} From b92579e515204794a7bcb6197dd41804bfe36552 Mon Sep 17 00:00:00 2001 From: Sergey Date: Mon, 21 Jan 2019 16:50:46 +0300 Subject: [PATCH 08/12] v2.2.9 --- tests/phpunit/RetailcrmInventoriesTest.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/RetailcrmInventoriesTest.php b/tests/phpunit/RetailcrmInventoriesTest.php index 352b408..8e720ee 100644 --- a/tests/phpunit/RetailcrmInventoriesTest.php +++ b/tests/phpunit/RetailcrmInventoriesTest.php @@ -60,9 +60,18 @@ class RetailcrmInventoriesTest extends RetailcrmTestCase $product1Id = explode('#', $this->product1['id']); $product2Id = explode('#', $this->product2['id']); - - $prod1Quantity = StockAvailable::getQuantityAvailableByProduct($product1Id[0], $product1Id[1] ); - $prod2Quantity = StockAvailable::getQuantityAvailableByProduct($product2Id[0], $product2Id[1] ); + + 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); From 54d4091f63d628bdf973f92fc8d5dffa3fc2e4c7 Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 24 Oct 2018 16:15:28 +0300 Subject: [PATCH 09/12] v2.2.5 --- CHANGELOG.md | 10 +- VERSION | 2 +- retailcrm/lib/RetailcrmHistory.php | 1 + retailcrm/retailcrm.php | 154 ++++++++++++++++------------- tests/phpunit/RetailcrmTest.php | 6 ++ 5 files changed, 99 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5bf55a..f6160c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,11 +13,13 @@ ## v2.2.6 * Добавлена активация модуля в маркетплейсе retailCRM -## v2.2.5 -* Добавлена передача страны при создании заказа для пользователя и заказа -* Добавлен метод сохранения сущностей с обработкой исключений +## v.2.2.5 +* Добавлена передача страны при создании заказа для заказа и покупателя +* Добавлен метод для загрузки сущностей с перехватом исключений +* Для версии 1.7 добавлена передача адреса при заполнении его на стороне сайта. +* Получение адреса и телефона вынесено в отдельные методы. -## v2.2.4 +## v.2.2.4 * Добавлена установка дефолтной валюты для оплаты при получении истории * Добавлено получение суммы оплаты из заказа в CMS, если она не передается по истории diff --git a/VERSION b/VERSION index a6333e4..72d132f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.9 +2.2.9 \ No newline at end of file diff --git a/retailcrm/lib/RetailcrmHistory.php b/retailcrm/lib/RetailcrmHistory.php index aa53a7d..7339e03 100644 --- a/retailcrm/lib/RetailcrmHistory.php +++ b/retailcrm/lib/RetailcrmHistory.php @@ -53,6 +53,7 @@ class RetailcrmHistory if (self::loadInCMS($customer, 'update') === false) { continue; } + } else { $customer = new Customer(); diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index e401a84..8f22be4 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -3,7 +3,11 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL +<<<<<<< 4dfc7b8d1acbf9bdc33ac6484f0d7f4171e774d6 * @version 2.2.9 +======= + * @version 2.2.5 +>>>>>>> v2.2.5 * @link https://retailcrm.ru * */ @@ -76,7 +80,8 @@ class RetailCRM extends Module $this->registerHook('actionPaymentConfirmation') && $this->registerHook('actionCustomerAccountAdd') && $this->registerHook('actionOrderEdited') && - ($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true) + ($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true) && + ($this->use_new_hooks ? $this->registerHook('actionValidateCustomerAddressForm') : true) ); } @@ -418,11 +423,26 @@ 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']); + $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); @@ -490,6 +510,68 @@ class RetailCRM extends Module return $order; } + private function addressParse($address) + { + $addressCollection = $address->getAddressCollection(); + $address = array_shift($addressCollection); + + 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 +603,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 +838,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 * diff --git a/tests/phpunit/RetailcrmTest.php b/tests/phpunit/RetailcrmTest.php index c3cabb0..d3fd4d6 100644 --- a/tests/phpunit/RetailcrmTest.php +++ b/tests/phpunit/RetailcrmTest.php @@ -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']); From a1fc009db6a3a5e06804fe7c680a996e6d36ec5d Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 24 Oct 2018 16:34:14 +0300 Subject: [PATCH 10/12] v2.2.5 --- retailcrm/retailcrm.php | 1 + 1 file changed, 1 insertion(+) diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 8f22be4..24efb84 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -425,6 +425,7 @@ class RetailCRM extends Module if (isset($params['cart'])){ $address = $this->addressParse($params['cart']); + $customerSend = array_merge($customerSend, $address['customer']); } $customerSend = array_merge($customerSend, $address['customer']); From 8e88456b44afde599991a0edc166c2a41e14f7df Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 18 Jan 2019 17:04:32 +0300 Subject: [PATCH 11/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20Daemon=20Collector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- retailcrm/lib/RetailcrmDaemonCollector.php | 52 ++++++++++++ retailcrm/retailcrm.php | 84 ++++++++++++++----- .../phpunit/RetailcrmDaemonCollectorTest.php | 40 +++++++++ 3 files changed, 155 insertions(+), 21 deletions(-) create mode 100644 retailcrm/lib/RetailcrmDaemonCollector.php create mode 100644 tests/phpunit/RetailcrmDaemonCollectorTest.php diff --git a/retailcrm/lib/RetailcrmDaemonCollector.php b/retailcrm/lib/RetailcrmDaemonCollector.php new file mode 100644 index 0000000..42e6d6e --- /dev/null +++ b/retailcrm/lib/RetailcrmDaemonCollector.php @@ -0,0 +1,52 @@ + + (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'); + +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; + } +} diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 24efb84..248952c 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -3,11 +3,7 @@ * @author Retail Driver LCC * @copyright RetailCRM * @license GPL -<<<<<<< 4dfc7b8d1acbf9bdc33ac6484f0d7f4171e774d6 * @version 2.2.9 -======= - * @version 2.2.5 ->>>>>>> v2.2.5 * @link https://retailcrm.ru * */ @@ -80,11 +76,26 @@ class RetailCRM extends Module $this->registerHook('actionPaymentConfirmation') && $this->registerHook('actionCustomerAccountAdd') && $this->registerHook('actionOrderEdited') && + $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( @@ -125,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, @@ -145,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')); } @@ -174,7 +190,6 @@ class RetailCRM extends Module public function displayForm() { - $this->displayConfirmation($this->l('Settings updated')); $default_lang = $this->default_lang; @@ -194,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'), ), @@ -204,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( @@ -230,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(), ); @@ -243,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(), ); @@ -251,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(), ); @@ -259,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')) @@ -269,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' ) )), ); @@ -324,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 != '') { @@ -465,7 +511,6 @@ class RetailCRM extends Module public function hookActionOrderEdited($params) { - $order = array( 'externalId' => $params['order']->id, 'firstName' => $params['customer']->firstname, @@ -513,9 +558,6 @@ class RetailCRM extends Module private function addressParse($address) { - $addressCollection = $address->getAddressCollection(); - $address = array_shift($addressCollection); - if ($address instanceof Address) { $postcode = $address->postcode; $city = $address->city; diff --git a/tests/phpunit/RetailcrmDaemonCollectorTest.php b/tests/phpunit/RetailcrmDaemonCollectorTest.php new file mode 100644 index 0000000..1df7f36 --- /dev/null +++ b/tests/phpunit/RetailcrmDaemonCollectorTest.php @@ -0,0 +1,40 @@ +id = self::ID; + + $collector = new RetailcrmDaemonCollector( + $customer, + self::KEY + ); + + $js = $collector->buildScript()->getJs(); + + $this->assertContains('customerId', $js); + $this->assertContains('assertContains('', $js); + } + + public function testBuildJsWithoutCustomer() + { + $customer = new Customer; + + $collector = new RetailcrmDaemonCollector( + $customer, + self::KEY + ); + + $js = $collector->buildScript()->getJs(); + + $this->assertNotContains('customerId', $js); + $this->assertContains('assertContains('', $js); + } +} From 3050ba7978f3de05ce82926a771ef4dc4efa57ce Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Tue, 22 Jan 2019 10:12:42 +0300 Subject: [PATCH 12/12] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + README.md | 2 +- README.ru.md | 2 +- retailcrm/translations/es.php | 3 +++ retailcrm/translations/ru.php | 3 +++ 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6160c8..78a65e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Добавлена выгрузка габаритов в специальный тег dimensions * Добавлена выгрузка остатков из CRM * Добавлена передача номера заказа +* Добавлена настройка Daemon Collector ## v2.2.8 * Добавлена выгрузка картинок категорий товаров в ICML diff --git a/README.md b/README.md index 885e710..37c66c4 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Add to cron: Add to cron: ``` -*/15 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php +*/15 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/inventories.php ``` #### Single orders archive export to retailCRM diff --git a/README.ru.md b/README.ru.md index 92904fc..978ebb9 100644 --- a/README.ru.md +++ b/README.ru.md @@ -34,7 +34,7 @@ Prestashop module Добавьте в крон запись вида ``` -*/15 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/sync.php +*/15 * * * * /usr/bin/php /path/to/your/site/modules/retailcrm/job/inventories.php ``` #### Единоразовая выгрузка архива клиентов и заказов в retailCRM diff --git a/retailcrm/translations/es.php b/retailcrm/translations/es.php index d5a5466..16d63e5 100644 --- a/retailcrm/translations/es.php +++ b/retailcrm/translations/es.php @@ -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'; diff --git a/retailcrm/translations/ru.php b/retailcrm/translations/ru.php index 4bb08b2..9c20f00 100644 --- a/retailcrm/translations/ru.php +++ b/retailcrm/translations/ru.php @@ -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'] = 'Статусы заказов';