1
0
mirror of synced 2025-02-21 01:13:13 +03:00

plugin for API v4, v5 (#4)

* plugin for API v4, v5
* fix icml generation
This commit is contained in:
Akolzin Dmitry 2017-07-30 15:42:49 +02:00 committed by Alex Lushpai
parent e21c214156
commit 37aa349d11
17 changed files with 3650 additions and 192 deletions

View File

View File

@ -0,0 +1,828 @@
<?php
/**
* PHP version 5.3
*
* Request class
*
* @category Integration
* @package WC_Retailcrm_Client
* @author RetailCRM <dev@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://retailcrm.ru/docs/Developers/ApiVersion3
*/
if ( ! class_exists( 'WC_Retailcrm_Request' ) ) {
include_once( __DIR__ . '/class-wc-retailcrm-request.php' );
}
if ( ! class_exists( 'WC_Retailcrm_Response' ) ) {
include_once( __DIR__ . '/class-wc-retailcrm-response.php' );
}
class WC_Retailcrm_Client_V3
{
const VERSION = 'v3';
protected $client;
/**
* Site code
*/
protected $siteCode;
/**
* Client creating
*
* @param string $url
* @param string $apiKey
* @param string $site
*/
public function __construct($url, $apiKey, $site = null)
{
if ('/' != substr($url, strlen($url) - 1, 1)) {
$url .= '/';
}
$url = $url . 'api/' . self::VERSION;
$this->client = new WC_Retailcrm_Request($url, array('apiKey' => $apiKey));
$this->siteCode = $site;
}
/**
* Create a order
*
* @param array $order
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function ordersCreate(array $order, $site = null)
{
if (!sizeof($order)) {
throw new InvalidArgumentException('Parameter `order` must contains a data');
}
return $this->client->makeRequest("/orders/create", WC_Retailcrm_Request::METHOD_POST, $this->fillSite($site, array(
'order' => json_encode($order)
)));
}
/**
* Edit a order
*
* @param array $order
* @param string $by
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function ordersEdit(array $order, $by = 'externalId', $site = null)
{
if (!sizeof($order)) {
throw new InvalidArgumentException('Parameter `order` must contains a data');
}
$this->checkIdParameter($by);
if (!isset($order[$by])) {
throw new InvalidArgumentException(sprintf('Order array must contain the "%s" parameter.', $by));
}
return $this->client->makeRequest(
"/orders/" . $order[$by] . "/edit",
WC_Retailcrm_Request::METHOD_POST,
$this->fillSite($site, array(
'order' => json_encode($order),
'by' => $by,
))
);
}
/**
* Upload array of the orders
*
* @param array $orders
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function ordersUpload(array $orders, $site = null)
{
if (!sizeof($orders)) {
throw new InvalidArgumentException('Parameter `orders` must contains array of the orders');
}
return $this->client->makeRequest("/orders/upload", WC_Retailcrm_Request::METHOD_POST, $this->fillSite($site, array(
'orders' => json_encode($orders),
)));
}
/**
* Get order by id or externalId
*
* @param string $id
* @param string $by (default: 'externalId')
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function ordersGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
return $this->client->makeRequest("/orders/$id", WC_Retailcrm_Request::METHOD_GET, $this->fillSite($site, array(
'by' => $by
)));
}
/**
* Returns a orders history
*
* @param DateTime $startDate (default: null)
* @param DateTime $endDate (default: null)
* @param int $limit (default: 100)
* @param int $offset (default: 0)
* @param bool $skipMyChanges (default: true)
* @return WC_Retailcrm_Response
*/
public function ordersHistory(
DateTime $startDate = null,
DateTime $endDate = null,
$limit = 100,
$offset = 0,
$skipMyChanges = true
) {
$parameters = array();
if ($startDate) {
$parameters['startDate'] = $startDate->format('Y-m-d H:i:s');
}
if ($endDate) {
$parameters['endDate'] = $endDate->format('Y-m-d H:i:s');
}
if ($limit) {
$parameters['limit'] = (int) $limit;
}
if ($offset) {
$parameters['offset'] = (int) $offset;
}
if ($skipMyChanges) {
$parameters['skipMyChanges'] = (bool) $skipMyChanges;
}
return $this->client->makeRequest('/orders/history', WC_Retailcrm_Request::METHOD_GET, $parameters);
}
/**
* Returns filtered orders list
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
* @return WC_Retailcrm_Response
*/
public function ordersList(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
if (sizeof($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
return $this->client->makeRequest('/orders', WC_Retailcrm_Request::METHOD_GET, $parameters);
}
/**
* Returns statuses of the orders
*
* @param array $ids (default: array())
* @param array $externalIds (default: array())
* @return WC_Retailcrm_Response
*/
public function ordersStatuses(array $ids = array(), array $externalIds = array())
{
$parameters = array();
if (sizeof($ids)) {
$parameters['ids'] = $ids;
}
if (sizeof($externalIds)) {
$parameters['externalIds'] = $externalIds;
}
return $this->client->makeRequest('/orders/statuses', WC_Retailcrm_Request::METHOD_GET, $parameters);
}
/**
* Save order IDs' (id and externalId) association in the CRM
*
* @param array $ids
* @return WC_Retailcrm_Response
*/
public function ordersFixExternalIds(array $ids)
{
if (!sizeof($ids)) {
throw new InvalidArgumentException('Method parameter must contains at least one IDs pair');
}
return $this->client->makeRequest("/orders/fix-external-ids", WC_Retailcrm_Request::METHOD_POST, array(
'orders' => json_encode($ids),
));
}
/**
* Get orders assembly history
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
* @return WC_Retailcrm_Response
*/
public function ordersPacksHistory(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
if (sizeof($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
return $this->client->makeRequest('/orders/packs/history', WC_Retailcrm_Request::METHOD_GET, $parameters);
}
/**
* Create a customer
*
* @param array $customer
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function customersCreate(array $customer, $site = null)
{
if (!sizeof($customer)) {
throw new InvalidArgumentException('Parameter `customer` must contains a data');
}
return $this->client->makeRequest("/customers/create", WC_Retailcrm_Request::METHOD_POST, $this->fillSite($site, array(
'customer' => json_encode($customer)
)));
}
/**
* Edit a customer
*
* @param array $customer
* @param string $by (default: 'externalId')
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function customersEdit(array $customer, $by = 'externalId', $site = null)
{
if (!sizeof($customer)) {
throw new InvalidArgumentException('Parameter `customer` must contains a data');
}
$this->checkIdParameter($by);
if (!isset($customer[$by])) {
throw new InvalidArgumentException(sprintf('Customer array must contain the "%s" parameter.', $by));
}
return $this->client->makeRequest(
"/customers/" . $customer[$by] . "/edit",
WC_Retailcrm_Request::METHOD_POST,
$this->fillSite(
$site,
array(
'customer' => json_encode($customer),
'by' => $by
)
)
);
}
/**
* Upload array of the customers
*
* @param array $customers
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function customersUpload(array $customers, $site = null)
{
if (!sizeof($customers)) {
throw new InvalidArgumentException('Parameter `customers` must contains array of the customers');
}
return $this->client->makeRequest("/customers/upload", WC_Retailcrm_Request::METHOD_POST, $this->fillSite($site, array(
'customers' => json_encode($customers),
)));
}
/**
* Get customer by id or externalId
*
* @param string $id
* @param string $by (default: 'externalId')
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function customersGet($id, $by = 'externalId', $site = null)
{
$this->checkIdParameter($by);
return $this->client->makeRequest("/customers/$id", WC_Retailcrm_Request::METHOD_GET, $this->fillSite($site, array(
'by' => $by
)));
}
/**
* Returns filtered customers list
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
* @return WC_Retailcrm_Response
*/
public function customersList(array $filter = array(), $page = null, $limit = null)
{
$parameters = array();
if (sizeof($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
return $this->client->makeRequest('/customers', WC_Retailcrm_Request::METHOD_GET, $parameters);
}
/**
* Save customer IDs' (id and externalId) association in the CRM
*
* @param array $ids
* @return WC_Retailcrm_Response
*/
public function customersFixExternalIds(array $ids)
{
if (!sizeof($ids)) {
throw new InvalidArgumentException('Method parameter must contains at least one IDs pair');
}
return $this->client->makeRequest("/customers/fix-external-ids", WC_Retailcrm_Request::METHOD_POST, array(
'customers' => json_encode($ids),
));
}
/**
* Get purchace prices & stock balance
*
* @param array $filter (default: array())
* @param int $page (default: null)
* @param int $limit (default: null)
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function storeInventories(array $filter = array(), $page = null, $limit = null, $site = null)
{
$parameters = array();
if (sizeof($filter)) {
$parameters['filter'] = $filter;
}
if (null !== $page) {
$parameters['page'] = (int) $page;
}
if (null !== $limit) {
$parameters['limit'] = (int) $limit;
}
return $this->client->makeRequest('/store/inventories', WC_Retailcrm_Request::METHOD_GET, $this->fillSite($site, $parameters));
}
/**
* Upload store inventories
*
* @param array $offers
* @param string $site (default: null)
* @return WC_Retailcrm_Response
*/
public function storeInventoriesUpload(array $offers, $site = null)
{
if (!sizeof($offers)) {
throw new InvalidArgumentException('Parameter `offers` must contains array of the customers');
}
return $this->client->makeRequest(
"/store/inventories/upload",
WC_Retailcrm_Request::METHOD_POST,
$this->fillSite($site, array('offers' => json_encode($offers)))
);
}
/**
* Returns deliveryServices list
*
* @return WC_Retailcrm_Response
*/
public function deliveryServicesList()
{
return $this->client->makeRequest('/reference/delivery-services', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns deliveryTypes list
*
* @return WC_Retailcrm_Response
*/
public function deliveryTypesList()
{
return $this->client->makeRequest('/reference/delivery-types', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns orderMethods list
*
* @return WC_Retailcrm_Response
*/
public function orderMethodsList()
{
return $this->client->makeRequest('/reference/order-methods', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns orderTypes list
*
* @return WC_Retailcrm_Response
*/
public function orderTypesList()
{
return $this->client->makeRequest('/reference/order-types', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns paymentStatuses list
*
* @return WC_Retailcrm_Response
*/
public function paymentStatusesList()
{
return $this->client->makeRequest('/reference/payment-statuses', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns paymentTypes list
*
* @return WC_Retailcrm_Response
*/
public function paymentTypesList()
{
return $this->client->makeRequest('/reference/payment-types', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns productStatuses list
*
* @return WC_Retailcrm_Response
*/
public function productStatusesList()
{
return $this->client->makeRequest('/reference/product-statuses', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns statusGroups list
*
* @return WC_Retailcrm_Response
*/
public function statusGroupsList()
{
return $this->client->makeRequest('/reference/status-groups', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns statuses list
*
* @return WC_Retailcrm_Response
*/
public function statusesList()
{
return $this->client->makeRequest('/reference/statuses', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns sites list
*
* @return WC_Retailcrm_Response
*/
public function sitesList()
{
return $this->client->makeRequest('/reference/sites', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Returns stores list
*
* @return WC_Retailcrm_Response
*/
public function storesList()
{
return $this->client->makeRequest('/reference/stores', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Edit deliveryService
*
* @param array $data delivery service data
* @return WC_Retailcrm_Response
*/
public function deliveryServicesEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->client->makeRequest(
'/reference/delivery-services/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'deliveryService' => json_encode($data)
)
);
}
/**
* Edit deliveryType
*
* @param array $data delivery type data
* @return WC_Retailcrm_Response
*/
public function deliveryTypesEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->client->makeRequest(
'/reference/delivery-types/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'deliveryType' => json_encode($data)
)
);
}
/**
* Edit orderMethod
*
* @param array $data order method data
* @return WC_Retailcrm_Response
*/
public function orderMethodsEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->client->makeRequest(
'/reference/order-methods/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'orderMethod' => json_encode($data)
)
);
}
/**
* Edit orderType
*
* @param array $data order type data
* @return WC_Retailcrm_Response
*/
public function orderTypesEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->client->makeRequest(
'/reference/order-types/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'orderType' => json_encode($data)
)
);
}
/**
* Edit paymentStatus
*
* @param array $data payment status data
* @return WC_Retailcrm_Response
*/
public function paymentStatusesEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->client->makeRequest(
'/reference/payment-statuses/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'paymentStatus' => json_encode($data)
)
);
}
/**
* Edit paymentType
*
* @param array $data payment type data
* @return WC_Retailcrm_Response
*/
public function paymentTypesEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->client->makeRequest(
'/reference/payment-types/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'paymentType' => json_encode($data)
)
);
}
/**
* Edit productStatus
*
* @param array $data product status data
* @return WC_Retailcrm_Response
*/
public function productStatusesEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->client->makeRequest(
'/reference/product-statuses/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'productStatus' => json_encode($data)
)
);
}
/**
* Edit order status
*
* @param array $data status data
* @return WC_Retailcrm_Response
*/
public function statusesEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->client->makeRequest(
'/reference/statuses/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'status' => json_encode($data)
)
);
}
/**
* Edit site
*
* @param array $data site data
* @return WC_Retailcrm_Response
*/
public function sitesEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
return $this->client->makeRequest(
'/reference/sites/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'site' => json_encode($data)
)
);
}
/**
* Edit store
*
* @param array $data site data
* @return WC_Retailcrm_Response
*/
public function storesEdit(array $data)
{
if (!isset($data['code'])) {
throw new InvalidArgumentException('Data must contain "code" parameter.');
}
if (!isset($data['name'])) {
throw new InvalidArgumentException('Data must contain "name" parameter.');
}
return $this->client->makeRequest(
'/reference/stores/' . $data['code'] . '/edit',
WC_Retailcrm_Request::METHOD_POST,
array(
'store' => json_encode($data)
)
);
}
/**
* Update CRM basic statistic
*
* @return WC_Retailcrm_Response
*/
public function statisticUpdate()
{
return $this->client->makeRequest('/statistic/update', WC_Retailcrm_Request::METHOD_GET);
}
/**
* Return current site
*
* @return string
*/
public function getSite()
{
return $this->siteCode;
}
/**
* Set site
*
* @param string $site
* @return void
*/
public function setSite($site)
{
$this->siteCode = $site;
}
/**
* Check ID parameter
*
* @param string $by
* @return bool
*/
protected function checkIdParameter($by)
{
$allowedForBy = array('externalId', 'id');
if (!in_array($by, $allowedForBy)) {
throw new InvalidArgumentException(sprintf(
'Value "%s" for parameter "by" is not valid. Allowed values are %s.',
$by,
implode(', ', $allowedForBy)
));
}
return true;
}
/**
* Fill params by site value
*
* @param string $site
* @param array $params
* @return array
*/
protected function fillSite($site, array $params)
{
if ($site) {
$params['site'] = $site;
} elseif ($this->siteCode) {
$params['site'] = $this->siteCode;
}
return $params;
}
}

View File

@ -6,8 +6,8 @@
* Request class
*
* @category Integration
* @package WC_RetailCrm_Client
* @author Retailcrm <dev@retailcrm.ru>
* @package WC_Retailcrm_Client
* @author RetailCRM <dev@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://retailcrm.ru/docs/Developers/ApiVersion4
*/
@ -20,9 +20,8 @@
include_once( __DIR__ . '/class-wc-retailcrm-response.php' );
}
class WC_Retailcrm_Client
class WC_Retailcrm_Client_V4
{
const VERSION = 'v4';
protected $client;
@ -33,7 +32,7 @@
protected $siteCode;
/**
* WC_Retailcrm_Request creating
* Client creating
*
* @param string $url api url
* @param string $apiKey api key

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,9 @@
*
* WC_Retailcrm_Exception_Curl class
*
* @category Retailcrm
* @category RetailCRM
* @package WC_Retailcrm_Exception_Curl
* @author Retailcrm <dev@retailcrm.ru>
* @author RetailCRM <dev@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://retailcrm.ru/docs/Developers/ApiVersion4
*/

View File

@ -5,11 +5,10 @@
*
* WC_Retailcrm_Exception_Json class
*
* @category Retailcrm
* @category RetailCRM
* @package WC_Retailcrm_Exception_Json
* @author Retailcrm <dev@retailcrm.ru>
* @author RetailCRM <dev@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://retailcrm.ru/docs/Developers/ApiVersion4
*/
class WC_Retailcrm_Exception_Json extends \DomainException

View File

@ -1,10 +1,10 @@
<?php
/**
* Retailcrm Integration.
* RetailCRM Integration.
*
* @package WC_Retailcrm_Proxy
* @category Integration
* @author Retailcrm
* @author RetailCRM
*/
if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
@ -14,16 +14,36 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
*/
class WC_Retailcrm_Proxy
{
public function __construct($api_url, $api_key)
public function __construct($api_url, $api_key, $api_vers = 'v4')
{
$this->logger = new WC_Logger();
if ( ! class_exists( 'WC_Retailcrm_Client' ) ) {
include_once( __DIR__ . '/class-wc-retailcrm-client.php' );
if ( ! class_exists( 'WC_Retailcrm_Client_V3' ) ) {
include_once( __DIR__ . '/class-wc-retailcrm-client-v3.php' );
}
if ( ! class_exists( 'WC_Retailcrm_Client_V4' ) ) {
include_once( __DIR__ . '/class-wc-retailcrm-client-v4.php' );
}
if ( ! class_exists( 'WC_Retailcrm_Client_V5' ) ) {
include_once( __DIR__ . '/class-wc-retailcrm-client-v5.php' );
}
if ($api_url && $api_key) {
$this->retailcrm = new WC_Retailcrm_Client($api_url, $api_key);
switch ($api_vers) {
case 'v3':
$this->retailcrm = new WC_Retailcrm_Client_V3($api_url, $api_key);
break;
case 'v4':
$this->retailcrm = new WC_Retailcrm_Client_V4($api_url, $api_key);
break;
case 'v5':
$this->retailcrm = new WC_Retailcrm_Client_V5($api_url, $api_key);
break;
}
}
}

View File

@ -7,9 +7,8 @@
*
* @category Integration
* @package WC_Retailcrm_Request
* @author Retailcrm <dev@retailcrm.ru>
* @author RetailCRM <dev@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://retailcrm.ru/docs/Developers/ApiVersion4
*/
if ( ! class_exists( 'WC_Retailcrm_Exception_Curl' ) ) {

View File

@ -7,9 +7,8 @@
*
* @category Integration
* @package WC_Retailcrm_Response
* @author Retailcrm <dev@retailcrm.ru>
* @author RetailCRM <dev@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://retailcrm.ru/docs/Developers/ApiVersion4
*/
if ( ! class_exists( 'WC_Retailcrm_Exception_Json' ) ) {

View File

@ -1,10 +1,10 @@
<?php
/**
* Retailcrm Integration.
* RetailCRM Integration.
*
* @package WC_Retailcrm_Base
* @category Integration
* @author Retailcrm
* @author RetailCRM
*/
if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
@ -24,7 +24,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
//global $woocommerce;
$this->id = 'integration-retailcrm';
$this->method_title = __( 'Retailcrm', 'woocommerce-integration-retailcrm' );
$this->method_title = __( 'RetailCRM', 'woocommerce-integration-retailcrm' );
$this->method_description = __( 'Интеграция с системой управления Retailcrm.', 'woocommerce-integration-retailcrm' );
// Load the settings.
@ -42,7 +42,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
public function init_form_fields() {
$this->form_fields = array(
array( 'title' => __( 'Общие настройки', 'woocommerce' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
array( 'title' => __( 'General Options', 'woocommerce' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
'api_url' => array(
'title' => __( 'API URL', 'woocommerce-integration-retailcrm' ),
@ -52,7 +52,7 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
'default' => ''
),
'api_key' => array(
'title' => __( 'API Ключ', 'woocommerce-integration-retailcrm' ),
'title' => __( 'API Key', 'woocommerce-integration-retailcrm' ),
'type' => 'text',
'description' => __( 'Введите ключ API. Вы можете найти его в интерфейсе администратора Retailcrm.', 'woocommerce-integration-retailcrm' ),
'desc_tip' => true,
@ -60,6 +60,25 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
)
);
$api_version_list = array('v4' => 'v4','v5' => 'v5');
$this->form_fields[] = array(
'title' => __( 'Настройки API', 'woocommerce' ),
'type' => 'title',
'description' => '',
'id' => 'api_options'
);
$this->form_fields['api_version'] = array(
'title' => __( 'API версия', 'textdomain' ),
'description' => __( 'Выберите версию API, которую Вы хотите использовать', 'textdomain' ),
'css' => 'min-width:50px;',
'class' => 'select',
'type' => 'select',
'options' => $api_version_list,
'desc_tip' => true,
);
if ($this->get_option( 'api_url' ) != '' && $this->get_option( 'api_key' ) != '') {
if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) {
@ -68,7 +87,8 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
$retailcrm = new WC_Retailcrm_Proxy(
$this->get_option( 'api_url' ),
$this->get_option( 'api_key' )
$this->get_option( 'api_key' ),
$this->get_option( 'api_version')
);
/**
@ -185,9 +205,9 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
$this->form_fields['sync'] = array(
'label' => __( 'Выгружать остатки из CRM', 'textdomain' ),
'title' => 'Остатки',
'title' => 'Inventories',
'class' => 'checkbox',
'type' => 'checkbox',
'type' => 'checkbox'б
'description' => 'Отметьте данный пункт, если хотите выгружать остатки товаров из CRM в магазин.'
);
@ -244,6 +264,22 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
<?php
return ob_get_clean();
}
public function validate_api_version_field( $key, $value ) {
$api = new WC_Retailcrm_Proxy(
$_POST['woocommerce_integration-retailcrm_api_url'],
$_POST['woocommerce_integration-retailcrm_api_key'],
$value
);
$response = $api->statisticUpdate();
if (!$response->isSuccessful()) {
WC_Admin_Settings::add_error( esc_html__( '"Выбранная версия API недоступна"', 'woocommerce-integration-demo' ) );
}
return $value;
}
}
endif;

View File

@ -1,10 +1,10 @@
<?php
/**
* Retailcrm Integration.
* RetailCRM Integration.
*
* @package WC_Retailcrm_Customers
* @category Integration
* @author Retailcrm
* @author RetailCRM
*/
if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) :
@ -24,7 +24,8 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) :
$this->retailcrm = new WC_Retailcrm_Proxy(
$this->retailcrm_settings['api_url'],
$this->retailcrm_settings['api_key']
$this->retailcrm_settings['api_key'],
$this->retailcrm_settings['api_version']
);
}

View File

@ -1,10 +1,10 @@
<?php
/**
* Retailcrm Integration.
* RetailCRM Integration.
*
* @package WC_Retailcrm_History
* @category Integration
* @author Retailcrm
* @author RetailCRM
*/
if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
@ -28,7 +28,8 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
$this->retailcrm = new WC_Retailcrm_Proxy(
$this->retailcrm_settings['api_url'],
$this->retailcrm_settings['api_key']
$this->retailcrm_settings['api_key'],
$this->retailcrm_settings['api_version']
);
$this->startDate = new DateTime(date('Y-m-d H:i:s', strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))));
@ -155,11 +156,11 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
}
elseif($record['field'] == 'order_product.quantity' && $record['newValue']) {
$order = new WC_Order($record['order']['externalId']);
$product = wc_get_product($record['item']['offer']['externalId']);
$items = $order->get_items();
$args = array('qty' => $record['newValue']);
foreach ($items as $order_item_id => $item) {
if ($item['variation_id'] != 0 ) {
$offer_id = $item['variation_id'];
@ -167,8 +168,8 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
$offer_id = $item['product_id'];
}
if ($offer_id == $record['item']['offer']['externalId']) {
$order->update_product($order_item_id, $product, $args);
wc_delete_order_item($order_item_id);
$order->add_product($product, $record['newValue']);
$this->update_total($order);
}
}
@ -185,8 +186,7 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
$offer_id = $item['product_id'];
}
if ($offer_id == $record['item']['offer']['externalId']) {
wc_delete_order_item($order_item_id);
wc_delete_order_item($order_item_id);
$this->update_total($order);
}
}
@ -219,34 +219,22 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
elseif ($record['field'] == 'delivery_address.region') {
$order = new WC_Order($record['order']['externalId']);
$address = array(
'state' => $record['newValue']
);
$order->set_address($address, 'shipping');
$order->set_shipping_state($record['newValue']);
}
elseif ($record['field'] == 'delivery_address.city') {
$order = new WC_Order($record['order']['externalId']);
$address = array(
'city' => $record['newValue']
);
$order->set_address($address, 'shipping');
$order->set_shipping_city($record['newValue']);
}
elseif ($record['field'] == 'delivery_address.street') {
$order = new WC_Order($record['order']['externalId']);
$address = array(
'address_1' => $record['newValue']
);
$order->set_address($address, 'shipping');
$order->set_shipping_address1($record['newValue']);
}
elseif ($record['field'] == 'delivery_address.building') {
$order = new WC_Order($record['order']['externalId']);
$address = array(
'address_2' => $record['newValue']
);
$order->set_address($address, 'shipping');
$order->set_shipping_address2($record['newValue']);
}
elseif ($record['field'] == 'payment_type') {
@ -256,7 +244,40 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
$payment = new WC_Payment_Gateways();
$payment_types = $payment->get_available_payment_gateways();
if (isset($payment_types[$options[$newValue]])) {
$order->set_payment_method($payment_types[$options[$newValue]]);
update_post_meta($order->get_id(), '_payment_method', $payment->id);
}
}
}
elseif ($record['field'] == 'payments') {
$response = $this->retailcrm->ordersGet($record['order']['externalId']);
if ($response->isSuccessful()) {
$order_data = $response['order'];
$order = new WC_Order($record['order']['externalId']);
$payment = new WC_Payment_Gateways();
$payment_types = $payment->get_available_payment_gateways();
if (count($order_data['payments']) == 1) {
$paymentType = end($order_data['payments']);
if (isset($payment_types[$options[$paymentType['type']]])) {
$payment = $payment_types[$options[$paymentType['type']]];
update_post_meta($order->get_id(), '_payment_method', $payment->id);
}
} else {
foreach ($order_data['payments'] as $payment_data) {
if (isset($payment_data['externalId'])) {
$paymentType = $payment_data;
}
}
if (!isset($paymentType)) {
$paymentType = $order_data['payments'][0];
}
if (isset($payment_types[$options[$paymentType['type']]])) {
update_post_meta($order->get_id(), '_payment_method', $payment->id);
}
}
}
}
@ -303,11 +324,26 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
'country' => $order_record['customer']['address']['countryIso']
);
if ($order_record['paymentType']) {
$payment = new WC_Payment_Gateways();
$payment_types = $payment->get_available_payment_gateways();
if (isset($payment_types[$options[$order_record['paymentType']]])) {
$order->set_payment_method($payment_types[$options[$order_record['paymentType']]]);
if ($this->retailcrm_settings['api_version'] == 'v5') {
if ($order_record['payments']) {
$payment = new WC_Payment_Gateways();
if (count($order_record['payments']) == 1) {
$payment_types = $payment->get_available_payment_gateways();
$paymentType = end($order_record['payments']);
if (isset($payment_types[$options[$paymentType['type']]])) {
$order->set_payment_method($payment_types[$options[$paymentType['type']]]);
}
}
}
} else {
if ($order_record['paymentType']) {
$payment = new WC_Payment_Gateways();
$payment_types = $payment->get_available_payment_gateways();
if (isset($payment_types[$options[$order_record['paymentType']]])) {
$order->set_payment_method($payment_types[$options[$order_record['paymentType']]]);
}
}
}
@ -358,30 +394,47 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
}
protected function removeFuncsHook()
{
remove_action('woocommerce_order_status_changed', 'retailcrm_update_order_status', 11, 1);
remove_action('woocommerce_saved_order_items', 'retailcrm_update_order_items', 10, 2);
remove_action('update_post_meta', 'retailcrm_update_order', 11, 4);
remove_action('woocommerce_payment_complete', 'retailcrm_update_order_payment', 11, 1);
remove_action('woocommerce_checkout_update_user_meta', 'update_customer', 10, 2);
{
if (version_compare(get_option('woocommerce_db_version'), '3.0', '<' )) {
remove_action('woocommerce_order_status_changed', 'retailcrm_update_order_status', 11, 1);
remove_action('woocommerce_saved_order_items', 'retailcrm_update_order_items', 10, 2);
remove_action('update_post_meta', 'retailcrm_update_order', 11, 4);
remove_action('woocommerce_payment_complete', 'retailcrm_update_order_payment', 11, 1);
remove_action('woocommerce_checkout_update_user_meta', 'update_customer', 10, 2);
} else {
remove_action('woocommerce_update_order', 'update_order', 11, 1);
remove_action('woocommerce_order_status_changed', 'retailcrm_update_order_status', 11, 1);
}
}
protected function addFuncsHook()
{
if (!has_action('woocommerce_checkout_update_user_meta', 'update_customer')) {
add_action('woocommerce_checkout_update_user_meta', 'update_customer', 10, 2);
}
if (!has_action('woocommerce_order_status_changed', 'retailcrm_update_order_status')) {
add_action('woocommerce_order_status_changed', 'retailcrm_update_order_status', 11, 1);
}
if (!has_action('woocommerce_saved_order_items', 'retailcrm_update_order_items')) {
add_action('woocommerce_saved_order_items', 'retailcrm_update_order_items', 10, 2);
}
if (!has_action('update_post_meta', 'retailcrm_update_order')) {
add_action('update_post_meta', 'retailcrm_update_order', 11, 4);
}
if (!has_action('woocommerce_payment_complete', 'retailcrm_update_order_payment')) {
add_action('woocommerce_payment_complete', 'retailcrm_update_order_payment', 11, 1);
{
if (version_compare(get_option('woocommerce_db_version'), '3.0', '<' )) {
if (!has_action('woocommerce_checkout_update_user_meta', 'update_customer')) {
add_action('woocommerce_checkout_update_user_meta', 'update_customer', 10, 2);
}
if (!has_action('woocommerce_order_status_changed', 'retailcrm_update_order_status')) {
add_action('woocommerce_order_status_changed', 'retailcrm_update_order_status', 11, 1);
}
if (!has_action('woocommerce_saved_order_items', 'retailcrm_update_order_items')) {
add_action('woocommerce_saved_order_items', 'retailcrm_update_order_items', 10, 2);
}
if (!has_action('update_post_meta', 'retailcrm_update_order')) {
add_action('update_post_meta', 'retailcrm_update_order', 11, 4);
}
if (!has_action('woocommerce_payment_complete', 'retailcrm_update_order_payment')) {
add_action('woocommerce_payment_complete', 'retailcrm_update_order_payment', 11, 1);
}
} else {
if (!has_action('woocommerce_update_order', 'update_order')) {
add_action('woocommerce_update_order', 'update_order', 11, 1);
}
if (!has_action('woocommerce_checkout_update_user_meta', 'update_customer')) {
add_action('woocommerce_checkout_update_user_meta', 'update_customer', 10, 2);
}
if (!has_action('woocommerce_order_status_changed', 'retailcrm_update_order_status')) {
add_action('woocommerce_order_status_changed', 'retailcrm_update_order_status', 11, 1);
}
}
}
@ -400,7 +453,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
protected function update_total($order)
{
$order->update_taxes();
$order->calculate_totals();
}
}

View File

@ -1,10 +1,10 @@
<?php
/**
* Retailcrm Integration.
* RetailCRM Integration.
*
* @package WC_Retailcrm_Icml
* @category Integration
* @author Retailcrm
* @author RetailCRM
*/
if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
@ -327,75 +327,88 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) :
}
else {
if (get_post_type($theid) == 'product') {
$product = new WC_Product_Simple($theid);
$product = wc_get_product($theid);
}
elseif (get_post_type($theid) == 'product_variation') {
$post = get_post($theid);
if (get_post($post->post_parent)) {
$product = new WC_Product_Variation($theid);
$parent = new WC_Product_Simple($product->get_parent_id());
}
}
}
if ($this->get_parent_product($product) > 0) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $parent->get_id() ), 'single-post-thumbnail' );
$term_list = wp_get_post_terms($parent->get_id(), 'product_cat', array('fields' => 'ids'));
$attributes = get_post_meta( $parent->get_id() , '_product_attributes' );
} else {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $theid ), 'single-post-thumbnail' );
$term_list = wp_get_post_terms($product->get_id(), 'product_cat', array('fields' => 'ids'));
$attributes = get_post_meta( $product->get_id() , '_product_attributes' );
}
$attributes = (isset($attributes[0])) ? $attributes[0] : $attributes;
$params = array();
$weight = $product->get_weight();
if (!empty($weight)) {
$params[] = array('code' => 'weight', 'name' => 'Weight', 'value' => $weight);
}
if (!empty($attributes)) {
foreach ($attributes as $attribute_name => $attribute) {
$attributeValue = get_post_meta($product->get_id(), 'attribute_'.$attribute_name);
$attributeValue = end($attributeValue);
if ($attribute['is_visible'] == 1 && !empty($attribute['value'])) {
$params[] = array(
'code' => $attribute_name,
'name' => $attribute['name'],
'value' => $attributeValue
);
$product = wc_get_product($theid);
$parent = wc_get_product($product->get_parent_id());
} else {
continue;
}
}
}
if ($product->get_sku() != '') {
$params[] = array('code' => 'sku', 'name' => 'SKU', 'value' => $product->get_sku());
if ($product->get_type() == 'variable') continue;
if ((isset($parent) && $parent->get_type() == 'variable') || $product->get_type() == 'simple') {
if ($this->get_parent_product($product) > 0) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $theid ), 'single-post-thumbnail' );
$term_list = wp_get_post_terms($parent->get_id(), 'product_cat', array('fields' => 'ids'));
$attributes = get_post_meta( $parent->get_id() , '_product_attributes' );
} else {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $theid ), 'single-post-thumbnail' );
$term_list = wp_get_post_terms($product->get_id(), 'product_cat', array('fields' => 'ids'));
$attributes = get_post_meta( $product->get_id() , '_product_attributes' );
}
$attributes = (isset($attributes[0])) ? $attributes[0] : $attributes;
$params = array();
$weight = $product->get_weight();
if (!empty($weight)) {
$params[] = array('code' => 'weight', 'name' => 'Weight', 'value' => $weight);
}
$attrName = '';
if (!empty($attributes)) {
foreach ($attributes as $attribute_name => $attribute) {
$attributeValue = get_post_meta($product->get_id(), 'attribute_'.$attribute_name);
$attributeValue = end($attributeValue);
if ($attribute['is_visible'] == 1 && !empty($attribute['value'])) {
$params[] = array(
'code' => $attribute_name,
'name' => $attribute['name'],
'value' => $attributeValue
);
$attrName .= (!empty($attributeValue)) ? ' - ' . $attributeValue : '';
}
}
}
if ($product->get_sku() != '') {
$params[] = array('code' => 'sku', 'name' => 'SKU', 'value' => $product->get_sku());
}
$name = ($post->post_title == $product->get_title()) ?
$post->post_title . $attrName :
$post->post_title;
$product_data = array(
'id' => $product->get_id(),
'productId' => ($this->get_parent_product($product) > 0) ? $parent->get_id() : $product->get_id(),
'name' => $name,
'productName' => ($this->get_parent_product($product) > 0) ? $parent->get_title() : $product->get_title(),
'price' => $this->get_price_with_tax($product),
'purchasePrice' => $product->get_regular_price(),
'picture' => $image[0],
'url' => ($this->get_parent_product($product) > 0) ? $parent->get_permalink() : $product->get_permalink(),
'quantity' => is_null($product->get_stock_quantity()) ? 0 : $product->get_stock_quantity(),
'categoryId' => $term_list
);
if (!empty($params)) {
$product_data['params'] = $params;
}
$full_product_list[$theid] = $product_data;
unset($product_data);
}
$product_data = array(
'id' => $product->get_id(),
'productId' => ($this->get_parent_product($product) > 0) ? $parent->get_id() : $product->get_id(),
'name' => $product->get_title(),
'productName' => ($this->get_parent_product($product) > 0) ? $parent->get_title() : $product->get_title(),
'price' => $this->get_price_with_tax($product),
'purchasePrice' => $product->get_regular_price(),
'picture' => $image[0],
'url' => ($this->get_parent_product($product) > 0) ? $parent->get_permalink() : $product->get_permalink(),
'quantity' => is_null($product->get_stock_quantity()) ? 0 : $product->get_stock_quantity(),
'categoryId' => $term_list
);
if (!empty($params)) {
$product_data['params'] = $params;
}
$full_product_list[] = $product_data;
unset($product_data);
endwhile;
return $full_product_list;

View File

@ -1,10 +1,10 @@
<?php
/**
* Retailcrm Integration.
* RetailCRM Integration.
*
* @package WC_Retailcrm_Inventories
* @category Integration
* @author Retailcrm
* @author RetailCRM
*/
if ( ! class_exists( 'WC_Retailcrm_Inventories' ) ) :
@ -24,7 +24,8 @@ if ( ! class_exists( 'WC_Retailcrm_Inventories' ) ) :
$this->retailcrm = new WC_Retailcrm_Proxy(
$this->retailcrm_settings['api_url'],
$this->retailcrm_settings['api_key']
$this->retailcrm_settings['api_key'],
$this->retailcrm_settings['api_version']
);
}

View File

@ -1,10 +1,10 @@
<?php
/**
* Retailcrm Integration.
* RetailCRM Integration.
*
* @package WC_Retailcrm_Orders
* @category Integration
* @author Retailcrm
* @author RetailCRM
*/
if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
@ -24,7 +24,8 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
$this->retailcrm = new WC_Retailcrm_Proxy(
$this->retailcrm_settings['api_url'],
$this->retailcrm_settings['api_key']
$this->retailcrm_settings['api_key'],
$this->retailcrm_settings['api_version']
);
}
@ -90,8 +91,8 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
$order_data['customer']['externalId'] = $search['customer']['externalId'];
}
}
$this->retailcrm->ordersCreate($order_data);
$res = $this->retailcrm->ordersCreate($order_data);
}
/**
@ -128,12 +129,34 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
*/
public function orderUpdatePaymentType($order_id, $payment_method) {
$order_data = array(
'externalId' => $order_id,
'paymentType' => $this->retailcrm_settings[$payment_method]
);
if ($this->retailcrm_settings['api_version'] != 'v5') {
$order_data = array(
'externalId' => $order_id,
'paymentType' => $this->retailcrm_settings[$payment_method]
);
$response = $this->retailcrm->ordersEdit($order_data);
$this->retailcrm->ordersEdit($order_data);
} else {
$response = $this->retailcrm->ordersGet($order_id);
if ($response->isSuccessful()) $order = $response['order'];
foreach ($order['payments'] as $payment_data) {
if ($payment_data['externalId'] == $order_id) {
$payment = $payment_data;
}
}
$order = new WC_Order($order_id);
if (isset($payment) && $payment['type'] != $this->retailcrm_settings[$order->payment_method]) {
$response = $this->retailcrm->ordersPaymentDelete($payment['id']);
if ($response->isSuccessful()) {
$this->createPayment($order, $order_id);
}
}
}
}
/**
@ -142,14 +165,23 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
* @param $order_id
*/
public function orderUpdatePayment($order_id) {
$order = new WC_Order( $order_id );
$order_data = array(
'externalId' => $order_id,
'paymentStatus' => 'paid'
);
if ($this->retailcrm_settings['api_version'] != 'v5') {
$order_data = array(
'externalId' => $order_id,
'paymentStatus' => 'paid'
);
$response = $this->retailcrm->ordersEdit($order_data);
$this->retailcrm->ordersEdit($order_data);
} else {
$payment = array(
'externalId' => $order_id,
'status' => 'paid'
);
$this->retailcrm->ordersPaymentsEdit($payment);
}
}
/**
@ -174,12 +206,22 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
}
$_product = wc_get_product($offer_id);
$items[] = array(
'offer' => array('externalId' => $offer_id),
'productName' => $product['name'],
'initialPrice' => (float)$_product->get_price(),
'quantity' => $product['qty']
);
if ($this->retailcrm_settings['api_version'] != 'v3') {
$items[] = array(
'offer' => array('externalId' => $offer_id),
'productName' => $product['name'],
'initialPrice' => (float)$_product->get_price(),
'quantity' => $product['qty']
);
} else {
$items[] = array(
'productId' => $offer_id,
'productName' => $product['name'],
'initialPrice' => (float)$_product->get_price(),
'quantity' => $product['qty']
);
}
}
$order_data['items'] = $items;
@ -209,7 +251,15 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
$order_data['number'] = $order->get_order_number();
$order_data['createdAt'] = $order->order_date;
if (!empty($order->payment_method) && !empty($this->retailcrm_settings[$order->payment_method])) {
if ($this->retailcrm_settings['api_version'] == 'v5') {
$discount = $order->data['discount_total'] + $order->data['discount_tax'];
if ($discount > 0) $order_data['discountManualAmount'] = $discount;
} else {
$discount = $order->data['discount_total'] + $order->data['discount_tax'];
if ($discount > 0) $order_data['discount'] = $discount;
}
if (!empty($order->payment_method) && !empty($this->retailcrm_settings[$order->payment_method]) && $this->retailcrm_settings['api_version'] != 'v5') {
$order_data['paymentType'] = $this->retailcrm_settings[$order->payment_method];
}
@ -228,7 +278,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
}
}
if ($order->is_paid()) {
if ($this->retailcrm_settings['api_version'] != 'v5' && $order->is_paid()) {
$order_data['paymentStatus'] = 'paid';
}
@ -243,15 +293,14 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
if (!empty($user_data['last_name'])) $order_data['lastName'] = $user_data['last_name'];
if (!empty($user_data['phone'])) $order_data['phone'] = $user_data['phone'];
if (!empty($user_data['email'])) $order_data['email'] = $user_data['email'];
if (!empty($user_data['postcode'])) $order_data['delivery']['address']['index'] = $user_data['postcode'];
if (!empty($user_data['state'])) $order_data['delivery']['address']['region'] = $user_data['state'];
if (!empty($user_data['city'])) $order_data['delivery']['address']['city'] = $user_data['city'];
if (!empty($user_data['country'])) $order_data['delivery']['address']['countryIso'] = $user_data['country'];
$order_data['delivery']['address']['text'] = sprintf(
"%s %s %s %s %s",
"%s %s %s %s",
$user_data['postcode'],
$user_data['state'],
$user_data['city'],
$user_data['address_1'],
$user_data['address_2']
@ -265,12 +314,21 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
$_product = wc_get_product($uid);
if ($_product) {
$order_item = array(
'offer' => array('externalId' => $uid),
'productName' => $item['name'],
'initialPrice' => (float)$_product->get_price(),
'quantity' => $item['qty'],
);
if ($this->retailcrm_settings['api_version'] != 'v3') {
$order_item = array(
'offer' => array('externalId' => $uid),
'productName' => $item['name'],
'initialPrice' => (float)$_product->get_price(),
'quantity' => $item['qty'],
);
} else {
$order_item = array(
'productId' => $uid,
'productName' => $item['name'],
'initialPrice' => (float)$_product->get_price(),
'quantity' => $item['qty'],
);
}
}
$order_items[] = $order_item;
@ -278,7 +336,73 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
$order_data['items'] = $order_items;
if ($this->retailcrm_settings['api_version'] == 'v5') {
$payment = array(
'amount' => $order->get_total(),
'externalId' => $order_id
);
$payment['order'] = array(
'externalId' => $order_id
);
if (!empty($order->payment_method) && !empty($this->retailcrm_settings[$order->payment_method])) {
$payment['type'] = $this->retailcrm_settings[$order->payment_method];
}
if ($order->is_paid()) {
$payment['status'] = 'paid';
}
if ($order->get_date_paid()) {
$pay_date = $order->get_date_paid();
$payment['paidAt'] = $pay_date->date('Y-m-d H:i:s');
}
$order_data['payments'][] = $payment;
}
return $order_data;
}
protected function createPayment($order, $order_id)
{
$payment = array(
'amount' => $order->get_total(),
'externalId' => $order_id
);
$payment['order'] = array(
'externalId' => $order_id
);
if (!empty($order->payment_method) && !empty($this->retailcrm_settings[$order->payment_method])) {
$payment['type'] = $this->retailcrm_settings[$order->payment_method];
}
if ($order->is_paid()) {
$payment['status'] = 'paid';
}
if ($order->get_date_paid()) {
$pay_date = $order->get_date_paid();
$payment['paidAt'] = $pay_date->date('Y-m-d H:i:s');
}
$this->retailcrm->ordersPaymentCreate($payment);
}
public function updateOrder($order_id)
{
$order = $this->processOrder($order_id);
$response = $this->retailcrm->ordersEdit($order);
$order = new WC_Order($order_id);
if ($response->isSuccessful()) {
$this->orderUpdatePaymentType($order_id, $order->payment_method);
}
}
}
endif;

View File

@ -1,9 +1,9 @@
<?php
/**
* Version: 1.0
* Plugin Name: WooCommerce Retailcrm
* Version: 1.1
* Plugin Name: WooCommerce RetailCRM
* Plugin URI: https://wordpress.org/plugins/retailcrm/
* Description: Интеграционный плагин для WooCommerce & Retailcrm
* Description: Integration plugin for WooCommerce & RetailCRM
* Author: RetailDriver LLC
* Author URI: http://retailcrm.ru/
*/
@ -278,7 +278,7 @@ function filter_cron_schedules($param) {
),
'fiveteen_minutes' => array(
'interval' => 900, // seconds
'display' => __('Every 1 hour')
'display' => __('Every 15 minutes')
)
);
}
@ -293,7 +293,7 @@ function upload_to_crm() {
}
$options = array_filter(get_option( 'woocommerce_integration-retailcrm_settings' ));
$orders = new WC_Retailcrm_Orders();
$customers = new WC_Retailcrm_Customers();
$customers->customersUpload();
@ -320,6 +320,15 @@ function ajax_upload() {
<?php
}
function update_order($order_id) {
if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) {
include_once( __DIR__ . check_custom_order() );
}
$order_class = new WC_Retailcrm_Orders();
$order_class->updateOrder($order_id);
}
register_activation_hook( __FILE__, 'retailcrm_install' );
register_deactivation_hook( __FILE__, 'retailcrm_deactivation' );
@ -327,10 +336,6 @@ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_
load_plugin_textdomain('wc_retailcrm', false, dirname(plugin_basename( __FILE__ )) . '/');
add_filter('cron_schedules', 'filter_cron_schedules', 10, 1);
add_action('woocommerce_thankyou', 'retailcrm_process_order', 10, 1);
add_action('woocommerce_order_status_changed', 'retailcrm_update_order_status', 11, 1);
add_action('woocommerce_saved_order_items', 'retailcrm_update_order_items', 10, 2);
add_action('update_post_meta', 'retailcrm_update_order', 11, 4);
add_action('woocommerce_payment_complete', 'retailcrm_update_order_payment', 11, 1);
add_action('retailcrm_history', 'retailcrm_history_get');
add_action('retailcrm_icml', 'generate_icml');
add_action('retailcrm_inventories', 'load_stocks');
@ -341,4 +346,13 @@ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_
add_action('admin_print_footer_scripts', 'ajax_upload', 99);
add_action( 'woocommerce_created_customer', 'create_customer', 10, 1 );
add_action( 'woocommerce_checkout_update_user_meta', 10, 2 );
if (version_compare(get_option('woocommerce_db_version'), '3.0', '<' )) {
add_action('woocommerce_order_status_changed', 'retailcrm_update_order_status', 11, 1);
add_action('woocommerce_saved_order_items', 'retailcrm_update_order_items', 10, 2);
add_action('update_post_meta', 'retailcrm_update_order', 11, 4);
add_action('woocommerce_payment_complete', 'retailcrm_update_order_payment', 11, 1);
} else {
add_action('woocommerce_update_order', 'update_order', 11, 1);
}
}

View File

@ -15,7 +15,7 @@
*
*
* @link https://wordpress.org/plugins/retailcrm/
* @since 1.0
* @since 1.1
*
* @package RetailCRM
*/