2017-06-22 00:55:08 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
2017-06-22 16:42:42 +03:00
|
|
|
* Orders
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace RetailCrm\Methods\V3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 5.4
|
|
|
|
*
|
2017-06-22 16:42:42 +03:00
|
|
|
* Orders class
|
2017-06-22 00:55:08 +03:00
|
|
|
*
|
|
|
|
* @category RetailCrm
|
|
|
|
* @package RetailCrm
|
|
|
|
*/
|
|
|
|
trait Orders
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns filtered orders list
|
|
|
|
*
|
|
|
|
* @param array $filter (default: array())
|
|
|
|
* @param int $page (default: null)
|
|
|
|
* @param int $limit (default: null)
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function ordersList(array $filter = [], $page = null, $limit = null)
|
|
|
|
{
|
|
|
|
$parameters = [];
|
|
|
|
|
|
|
|
if (count($filter)) {
|
|
|
|
$parameters['filter'] = $filter;
|
|
|
|
}
|
|
|
|
if (null !== $page) {
|
|
|
|
$parameters['page'] = (int) $page;
|
|
|
|
}
|
|
|
|
if (null !== $limit) {
|
|
|
|
$parameters['limit'] = (int) $limit;
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/orders',
|
|
|
|
"GET",
|
|
|
|
$parameters
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an order
|
|
|
|
*
|
|
|
|
* @param array $order order data
|
|
|
|
* @param string $site (default: null)
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function ordersCreate(array $order, $site = null)
|
|
|
|
{
|
|
|
|
if (!count($order)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `order` must contains a data'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/orders/create',
|
|
|
|
"POST",
|
|
|
|
$this->fillSite($site, ['order' => json_encode($order)])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save order IDs' (id and externalId) association into CRM
|
|
|
|
*
|
|
|
|
* @param array $ids order identificators
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function ordersFixExternalIds(array $ids)
|
|
|
|
{
|
|
|
|
if (! count($ids)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Method parameter must contains at least one IDs pair'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/orders/fix-external-ids',
|
|
|
|
"POST",
|
|
|
|
['orders' => json_encode($ids)
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns statuses of the orders
|
|
|
|
*
|
|
|
|
* @param array $ids (default: array())
|
|
|
|
* @param array $externalIds (default: array())
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function ordersStatuses(array $ids = [], array $externalIds = [])
|
|
|
|
{
|
|
|
|
$parameters = [];
|
|
|
|
|
|
|
|
if (count($ids)) {
|
|
|
|
$parameters['ids'] = $ids;
|
|
|
|
}
|
|
|
|
if (count($externalIds)) {
|
|
|
|
$parameters['externalIds'] = $externalIds;
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/orders/statuses',
|
|
|
|
"GET",
|
|
|
|
$parameters
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload array of the orders
|
|
|
|
*
|
|
|
|
* @param array $orders array of orders
|
|
|
|
* @param string $site (default: null)
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function ordersUpload(array $orders, $site = null)
|
|
|
|
{
|
|
|
|
if (!count($orders)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `orders` must contains array of the orders'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/orders/upload',
|
|
|
|
"POST",
|
|
|
|
$this->fillSite($site, ['orders' => json_encode($orders)])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get order by id or externalId
|
|
|
|
*
|
|
|
|
* @param string $id order identificator
|
|
|
|
* @param string $by (default: 'externalId')
|
|
|
|
* @param string $site (default: null)
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function ordersGet($id, $by = 'externalId', $site = null)
|
|
|
|
{
|
|
|
|
$this->checkIdParameter($by);
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
"/orders/$id",
|
|
|
|
"GET",
|
|
|
|
$this->fillSite($site, ['by' => $by])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit an order
|
|
|
|
*
|
|
|
|
* @param array $order order data
|
|
|
|
* @param string $by (default: 'externalId')
|
|
|
|
* @param string $site (default: null)
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \RetailCrm\Exception\CurlException
|
|
|
|
* @throws \RetailCrm\Exception\InvalidJsonException
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function ordersEdit(array $order, $by = 'externalId', $site = null)
|
|
|
|
{
|
|
|
|
if (!count($order)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
'Parameter `order` must contains a data'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->checkIdParameter($by);
|
|
|
|
|
|
|
|
if (!array_key_exists($by, $order)) {
|
|
|
|
throw new \InvalidArgumentException(
|
|
|
|
sprintf('Order array must contain the "%s" parameter.', $by)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
sprintf('/orders/%s/edit', $order[$by]),
|
|
|
|
"POST",
|
|
|
|
$this->fillSite(
|
|
|
|
$site,
|
|
|
|
['order' => json_encode($order), 'by' => $by]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get orders history
|
|
|
|
* @param array $filter
|
|
|
|
* @param null $page
|
|
|
|
* @param null $limit
|
|
|
|
*
|
|
|
|
* @return \RetailCrm\Response\ApiResponse
|
|
|
|
*/
|
|
|
|
public function ordersHistory(array $filter = [], $page = null, $limit = null)
|
|
|
|
{
|
|
|
|
$parameters = [];
|
|
|
|
|
|
|
|
if (count($filter)) {
|
|
|
|
$parameters['filter'] = $filter;
|
|
|
|
}
|
|
|
|
if (null !== $page) {
|
|
|
|
$parameters['page'] = (int) $page;
|
|
|
|
}
|
|
|
|
if (null !== $limit) {
|
|
|
|
$parameters['limit'] = (int) $limit;
|
|
|
|
}
|
|
|
|
|
2018-02-20 17:50:45 +03:00
|
|
|
/* @noinspection PhpUndefinedMethodInspection */
|
2017-06-22 00:55:08 +03:00
|
|
|
return $this->client->makeRequest(
|
|
|
|
'/orders/history',
|
|
|
|
"GET",
|
|
|
|
$parameters
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|