Update payment, fix transferring shipping types, fix calculating discount (#44)
This commit is contained in:
parent
f7c2c71d93
commit
dd1f5c3d14
@ -1,836 +0,0 @@
|
||||
<?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
|
||||
{
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* Site code
|
||||
*/
|
||||
protected $siteCode;
|
||||
|
||||
/**
|
||||
* Client creating
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $apiKey
|
||||
* @param string $site
|
||||
*/
|
||||
public function __construct($url, $apiKey, $version = null, $site = null)
|
||||
{
|
||||
if ('/' != substr($url, strlen($url) - 1, 1)) {
|
||||
$url .= '/';
|
||||
}
|
||||
|
||||
$url = $version == null ? $url . 'api' : $url . 'api/' . $version;
|
||||
|
||||
$this->client = new WC_Retailcrm_Request($url, array('apiKey' => $apiKey));
|
||||
$this->siteCode = $site;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns api versions list
|
||||
*
|
||||
* @return WC_Retailcrm_Response
|
||||
*/
|
||||
public function apiVersions()
|
||||
{
|
||||
return $this->client->makeRequest('/api-versions', WC_Retailcrm_Request::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* Request class
|
||||
@ -12,16 +12,16 @@
|
||||
* @link http://retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WC_Retailcrm_Request' ) ) {
|
||||
if ( ! class_exists( 'WC_Retailcrm_Request' ) ) {
|
||||
include_once( __DIR__ . '/class-wc-retailcrm-request.php' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WC_Retailcrm_Response' ) ) {
|
||||
if ( ! class_exists( 'WC_Retailcrm_Response' ) ) {
|
||||
include_once( __DIR__ . '/class-wc-retailcrm-response.php' );
|
||||
}
|
||||
}
|
||||
|
||||
class WC_Retailcrm_Client_V4
|
||||
{
|
||||
class WC_Retailcrm_Client_V4
|
||||
{
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
@ -1865,4 +1865,4 @@
|
||||
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* Request class
|
||||
@ -12,16 +12,16 @@
|
||||
* @link http://retailcrm.ru/docs/Developers/ApiVersion5
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WC_Retailcrm_Request' ) ) {
|
||||
if ( ! class_exists( 'WC_Retailcrm_Request' ) ) {
|
||||
include_once( __DIR__ . '/class-wc-retailcrm-request.php' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WC_Retailcrm_Response' ) ) {
|
||||
if ( ! class_exists( 'WC_Retailcrm_Response' ) ) {
|
||||
include_once( __DIR__ . '/class-wc-retailcrm-response.php' );
|
||||
}
|
||||
}
|
||||
|
||||
class WC_Retailcrm_Client_V5
|
||||
{
|
||||
class WC_Retailcrm_Client_V5
|
||||
{
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
@ -2378,4 +2378,4 @@
|
||||
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* WC_Retailcrm_Exception_Curl class
|
||||
@ -11,6 +11,6 @@
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://retailcrm.ru/docs/Developers/ApiVersion4
|
||||
*/
|
||||
class WC_Retailcrm_Exception_Curl extends \RuntimeException
|
||||
{
|
||||
}
|
||||
class WC_Retailcrm_Exception_Curl extends \RuntimeException
|
||||
{
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* WC_Retailcrm_Exception_Json class
|
||||
@ -11,6 +11,6 @@
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
class WC_Retailcrm_Exception_Json extends \DomainException
|
||||
{
|
||||
}
|
||||
class WC_Retailcrm_Exception_Json extends \DomainException
|
||||
{
|
||||
}
|
||||
|
@ -21,10 +21,6 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
|
||||
{
|
||||
$this->logger = new WC_Logger();
|
||||
|
||||
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' );
|
||||
}
|
||||
@ -34,9 +30,6 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
|
||||
}
|
||||
|
||||
switch ($api_vers) {
|
||||
case 'v3':
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V3($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
case 'v4':
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V4($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
@ -44,7 +37,7 @@ if ( ! class_exists( 'WC_Retailcrm_Proxy' ) ) :
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V5($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
case null:
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V3($api_url, $api_key, $api_vers);
|
||||
$this->retailcrm = new WC_Retailcrm_Client_V4($api_url, $api_key, $api_vers);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* Request class
|
||||
@ -11,16 +11,16 @@
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WC_Retailcrm_Exception_Curl' ) ) {
|
||||
if ( ! class_exists( 'WC_Retailcrm_Exception_Curl' ) ) {
|
||||
include_once( __DIR__ . '/class-wc-retailcrm-exception-curl.php' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WC_Retailcrm_Response' ) ) {
|
||||
if ( ! class_exists( 'WC_Retailcrm_Response' ) ) {
|
||||
include_once( __DIR__ . '/class-wc-retailcrm-response.php' );
|
||||
}
|
||||
}
|
||||
|
||||
class WC_Retailcrm_Request
|
||||
{
|
||||
class WC_Retailcrm_Request
|
||||
{
|
||||
const METHOD_GET = 'GET';
|
||||
const METHOD_POST = 'POST';
|
||||
|
||||
@ -89,7 +89,6 @@
|
||||
$curlHandler = curl_init();
|
||||
curl_setopt($curlHandler, CURLOPT_URL, $url);
|
||||
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($curlHandler, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);
|
||||
@ -114,4 +113,4 @@
|
||||
|
||||
return new WC_Retailcrm_Response($statusCode, $responseBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
/**
|
||||
* PHP version 5.3
|
||||
*
|
||||
* Response class
|
||||
@ -11,13 +11,13 @@
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WC_Retailcrm_Exception_Json' ) ) {
|
||||
if ( ! class_exists( 'WC_Retailcrm_Exception_Json' ) ) {
|
||||
include_once( __DIR__ . '/class-wc-retailcrm-exception-json.php' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class WC_Retailcrm_Response implements \ArrayAccess
|
||||
{
|
||||
class WC_Retailcrm_Response implements \ArrayAccess
|
||||
{
|
||||
// HTTP response status code
|
||||
protected $statusCode;
|
||||
|
||||
@ -166,4 +166,4 @@
|
||||
|
||||
return $this->response[$offset];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -311,8 +311,8 @@ if ( ! class_exists( 'WC_Retailcrm_Base' ) ) :
|
||||
|
||||
public function validate_api_version_field( $key, $value ) {
|
||||
$post = $this->get_post_data();
|
||||
|
||||
$versionMap = array(
|
||||
'v3' => '3.0',
|
||||
'v4' => '4.0',
|
||||
'v5' => '5.0'
|
||||
);
|
||||
|
@ -143,6 +143,74 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
$this->removeFuncsHook();
|
||||
|
||||
try {
|
||||
$this->orderEdit($record, $options);
|
||||
} catch (Exception $exception) {
|
||||
$logger = new WC_Logger();
|
||||
$logger->add('retailcrm', sprintf("[%s] - %s", $exception->getMessage(), 'Exception in file - ' . $exception->getFile() . ' on line ' . $exception->getLine()));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->addFuncsHook();
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($response)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->retailcrm_settings['history_orders'] = $generatedAt;
|
||||
update_option('woocommerce_integration-retailcrm_settings', $this->retailcrm_settings);
|
||||
|
||||
}
|
||||
|
||||
protected function removeFuncsHook()
|
||||
{
|
||||
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 (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function orderEdit($record, $options)
|
||||
{
|
||||
if ($record['field'] == 'status' && !empty($record['newValue']) && !empty($record['oldValue'])) {
|
||||
$newStatus = $record['newValue']['code'];
|
||||
if (!empty($options[$newStatus]) && !empty($record['order']['externalId'])) {
|
||||
@ -160,7 +228,6 @@ 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();
|
||||
@ -432,69 +499,6 @@ if ( ! class_exists( 'WC_Retailcrm_History' ) ) :
|
||||
|
||||
$this->retailcrm->ordersFixExternalIds($ids);
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
$logger = new WC_Logger();
|
||||
$logger->add('retailcrm', sprintf("[%s] - %s", $exception->getMessage(), 'Exception in file - ' . $exception->getFile() . ' on line ' . $exception->getLine()));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->addFuncsHook();
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($response)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->retailcrm_settings['history_orders'] = $generatedAt;
|
||||
update_option('woocommerce_integration-retailcrm_settings', $this->retailcrm_settings);
|
||||
|
||||
}
|
||||
|
||||
protected function removeFuncsHook()
|
||||
{
|
||||
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 (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getShippingItemId($items)
|
||||
|
@ -277,10 +277,11 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
* process to combine order data
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param boolean $update
|
||||
*
|
||||
* @return array $order_data
|
||||
*/
|
||||
public function processOrder($order_id)
|
||||
public function processOrder($order_id, $update = false)
|
||||
{
|
||||
if ( !$order_id ){
|
||||
return;
|
||||
@ -303,8 +304,8 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
$shipping = end($order->get_items( 'shipping' ));
|
||||
$shipping_code = explode(':', $shipping['method_id']);
|
||||
|
||||
if (isset($this->retailcrm_settings[$shipping])) {
|
||||
$shipping_method = $shipping;
|
||||
if (isset($this->retailcrm_settings[$shipping['method_id']])) {
|
||||
$shipping_method = $shipping['method_id'];
|
||||
} else {
|
||||
$shipping_method = $shipping_code[0];
|
||||
}
|
||||
@ -369,7 +370,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
foreach ($order->get_items() as $item) {
|
||||
$uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ;
|
||||
$_product = wc_get_product($uid);
|
||||
$price = wc_get_price_including_tax($_product);
|
||||
$price = round($item['line_subtotal'] + $item['line_subtotal_tax'], 2);
|
||||
|
||||
if ($_product) {
|
||||
$product_price = $item->get_total() ? $item->get_total() / $item->get_quantity() : 0;
|
||||
@ -384,10 +385,10 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
'quantity' => $item['qty'],
|
||||
);
|
||||
|
||||
if ($this->retailcrm_settings['api_version'] == 'v5') {
|
||||
$order_item['discountManualAmount'] = $discount_price;
|
||||
} elseif ($this->retailcrm_settings['api_version'] == 'v4') {
|
||||
$order_item['discount'] = $discount_price;
|
||||
if ($this->retailcrm_settings['api_version'] == 'v5' && round($discount_price, 2)) {
|
||||
$order_item['discountManualAmount'] = round($discount_price, 2);
|
||||
} elseif ($this->retailcrm_settings['api_version'] == 'v4' && round($discount_price, 2)) {
|
||||
$order_item['discount'] = round($discount_price, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,12 +420,24 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
$payment['paidAt'] = trim($pay_date->date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
if (!$update) {
|
||||
$order_data['payments'][] = $payment;
|
||||
} else {
|
||||
$this->editPayment($payment);
|
||||
}
|
||||
}
|
||||
|
||||
return $order_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create payment in CRM
|
||||
*
|
||||
* @param WC_Order $order
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function createPayment($order, $order_id)
|
||||
{
|
||||
$payment = array(
|
||||
@ -452,16 +465,35 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) :
|
||||
$this->retailcrm->ordersPaymentCreate($payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit payment in CRM
|
||||
*
|
||||
* @param array $payment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function editPayment($payment)
|
||||
{
|
||||
$this->retailcrm->ordersPaymentEdit($payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit order in CRM
|
||||
*
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateOrder($order_id)
|
||||
{
|
||||
$order = $this->processOrder($order_id);
|
||||
$order = $this->processOrder($order_id, true);
|
||||
|
||||
$response = $this->retailcrm->ordersEdit($order);
|
||||
|
||||
$order = new WC_Order($order_id);
|
||||
$orderWc = new WC_Order($order_id);
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
$this->orderUpdatePaymentType($order_id, $order->payment_method);
|
||||
$this->orderUpdatePaymentType($order_id, $orderWc->payment_method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Version: 2.0.2
|
||||
* Version: 2.0.3
|
||||
* Plugin Name: WooCommerce RetailCRM
|
||||
* Plugin URI: https://wordpress.org/plugins/woo-retailcrm/
|
||||
* Description: Integration plugin for WooCommerce & RetailCRM
|
||||
@ -413,13 +413,5 @@ if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_
|
||||
add_action('admin_print_footer_scripts', 'ajax_generate_icml', 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);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||
* @since 2.0.2
|
||||
* @since 2.0.3
|
||||
*
|
||||
* @package RetailCRM
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user