..
This commit is contained in:
parent
c4553a0f58
commit
57bf7f4c18
@ -31,6 +31,23 @@ class Retailcrm_Retailcrm_Block_Adminhtml_System_Config_Form_Fieldset_Base exten
|
|||||||
if ($response->isSuccessful()) {
|
if ($response->isSuccessful()) {
|
||||||
$this->_isCredentialCorrect = true;
|
$this->_isCredentialCorrect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$lastRun = Mage::getStoreConfig('retailcrm/general/history');
|
||||||
|
|
||||||
|
if (!empty($lastRun)) {
|
||||||
|
$lastRun = new DateTime(
|
||||||
|
date(
|
||||||
|
'Y-m-d H:i:s',
|
||||||
|
strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$lastRun = new DateTime($lastRun);
|
||||||
|
}
|
||||||
|
|
||||||
|
$history = $client->ordersHistory($lastRun);
|
||||||
|
var_dump($history);
|
||||||
|
Mage::getModel('core/config')->saveConfig('retailcrm/general/history', $history->getGeneratedAt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,16 +15,16 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
protected $siteCode;
|
protected $siteCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client creating
|
* Retailcrm_Retailcrm_Model_Http_Client init
|
||||||
*
|
*
|
||||||
* @param array $parameters
|
* @param string $url
|
||||||
* @internal param string $siteCode
|
* @param string $apiKey
|
||||||
|
* @param string $siteCode
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function __construct($parameters)
|
public function __construct($params)
|
||||||
{
|
{
|
||||||
$url = $parameters['url'];
|
$url = $params['url'];
|
||||||
$apiKey = $parameters['key'];
|
|
||||||
$site = $parameters['site'];
|
|
||||||
|
|
||||||
if ('/' != substr($url, strlen($url) - 1, 1)) {
|
if ('/' != substr($url, strlen($url) - 1, 1)) {
|
||||||
$url .= '/';
|
$url .= '/';
|
||||||
@ -32,8 +32,8 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
|
|
||||||
$url = $url . 'api/' . self::VERSION;
|
$url = $url . 'api/' . self::VERSION;
|
||||||
|
|
||||||
$this->client = new Retailcrm_Retailcrm_Model_Http_Client($url, array('apiKey' => $apiKey));
|
$this->client = new Retailcrm_Retailcrm_Model_Http_Client($url, array('apiKey' => $params['key']));
|
||||||
$this->siteCode = $site;
|
$this->siteCode = $params['site'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,12 +41,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
*
|
*
|
||||||
* @param array $order
|
* @param array $order
|
||||||
* @param string $site (default: null)
|
* @param string $site (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function ordersCreate(array $order, $site = null)
|
public function ordersCreate(array $order, $site = null)
|
||||||
{
|
{
|
||||||
if (!sizeof($order)) {
|
if (!sizeof($order)) {
|
||||||
throw new InvalidArgumentException('Parameter `order` must contains a data');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Parameter `order` must contains a data');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest("/orders/create", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, $this->fillSite($site, array(
|
return $this->client->makeRequest("/orders/create", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, $this->fillSite($site, array(
|
||||||
@ -58,20 +58,19 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Edit a order
|
* Edit a order
|
||||||
*
|
*
|
||||||
* @param array $order
|
* @param array $order
|
||||||
* @param string $by
|
|
||||||
* @param string $site (default: null)
|
* @param string $site (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function ordersEdit(array $order, $by = 'externalId', $site = null)
|
public function ordersEdit(array $order, $by = 'externalId', $site = null)
|
||||||
{
|
{
|
||||||
if (!sizeof($order)) {
|
if (!sizeof($order)) {
|
||||||
throw new InvalidArgumentException('Parameter `order` must contains a data');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Parameter `order` must contains a data');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checkIdParameter($by);
|
$this->checkIdParameter($by);
|
||||||
|
|
||||||
if (!isset($order[$by])) {
|
if (!isset($order[$by])) {
|
||||||
throw new InvalidArgumentException(sprintf('Order array must contain the "%s" parameter.', $by));
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException(sprintf('Order array must contain the "%s" parameter.', $by));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -89,12 +88,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
*
|
*
|
||||||
* @param array $orders
|
* @param array $orders
|
||||||
* @param string $site (default: null)
|
* @param string $site (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function ordersUpload(array $orders, $site = null)
|
public function ordersUpload(array $orders, $site = null)
|
||||||
{
|
{
|
||||||
if (!sizeof($orders)) {
|
if (!sizeof($orders)) {
|
||||||
throw new InvalidArgumentException('Parameter `orders` must contains array of the orders');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Parameter `orders` must contains array of the orders');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest("/orders/upload", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, $this->fillSite($site, array(
|
return $this->client->makeRequest("/orders/upload", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, $this->fillSite($site, array(
|
||||||
@ -108,7 +107,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* @param string $id
|
* @param string $id
|
||||||
* @param string $by (default: 'externalId')
|
* @param string $by (default: 'externalId')
|
||||||
* @param string $site (default: null)
|
* @param string $site (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function ordersGet($id, $by = 'externalId', $site = null)
|
public function ordersGet($id, $by = 'externalId', $site = null)
|
||||||
{
|
{
|
||||||
@ -127,7 +126,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* @param int $limit (default: 100)
|
* @param int $limit (default: 100)
|
||||||
* @param int $offset (default: 0)
|
* @param int $offset (default: 0)
|
||||||
* @param bool $skipMyChanges (default: true)
|
* @param bool $skipMyChanges (default: true)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function ordersHistory(
|
public function ordersHistory(
|
||||||
DateTime $startDate = null,
|
DateTime $startDate = null,
|
||||||
@ -163,7 +162,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* @param array $filter (default: array())
|
* @param array $filter (default: array())
|
||||||
* @param int $page (default: null)
|
* @param int $page (default: null)
|
||||||
* @param int $limit (default: null)
|
* @param int $limit (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function ordersList(array $filter = array(), $page = null, $limit = null)
|
public function ordersList(array $filter = array(), $page = null, $limit = null)
|
||||||
{
|
{
|
||||||
@ -187,7 +186,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
*
|
*
|
||||||
* @param array $ids (default: array())
|
* @param array $ids (default: array())
|
||||||
* @param array $externalIds (default: array())
|
* @param array $externalIds (default: array())
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function ordersStatuses(array $ids = array(), array $externalIds = array())
|
public function ordersStatuses(array $ids = array(), array $externalIds = array())
|
||||||
{
|
{
|
||||||
@ -207,12 +206,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Save order IDs' (id and externalId) association in the CRM
|
* Save order IDs' (id and externalId) association in the CRM
|
||||||
*
|
*
|
||||||
* @param array $ids
|
* @param array $ids
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function ordersFixExternalIds(array $ids)
|
public function ordersFixExternalIds(array $ids)
|
||||||
{
|
{
|
||||||
if (!sizeof($ids)) {
|
if (!sizeof($ids)) {
|
||||||
throw new InvalidArgumentException('Method parameter must contains at least one IDs pair');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Method parameter must contains at least one IDs pair');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest("/orders/fix-external-ids", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, array(
|
return $this->client->makeRequest("/orders/fix-external-ids", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, array(
|
||||||
@ -220,17 +219,42 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get orders assembly history
|
||||||
|
*
|
||||||
|
* @param array $filter (default: array())
|
||||||
|
* @param int $page (default: null)
|
||||||
|
* @param int $limit (default: null)
|
||||||
|
* @return ApiResponse
|
||||||
|
*/
|
||||||
|
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', Retailcrm_Retailcrm_Model_Http_Client::METHOD_GET, $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a customer
|
* Create a customer
|
||||||
*
|
*
|
||||||
* @param array $customer
|
* @param array $customer
|
||||||
* @param string $site (default: null)
|
* @param string $site (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function customersCreate(array $customer, $site = null)
|
public function customersCreate(array $customer, $site = null)
|
||||||
{
|
{
|
||||||
if (!sizeof($customer)) {
|
if (!sizeof($customer)) {
|
||||||
throw new InvalidArgumentException('Parameter `customer` must contains a data');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Parameter `customer` must contains a data');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest("/customers/create", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, $this->fillSite($site, array(
|
return $this->client->makeRequest("/customers/create", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, $this->fillSite($site, array(
|
||||||
@ -244,28 +268,31 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* @param array $customer
|
* @param array $customer
|
||||||
* @param string $by (default: 'externalId')
|
* @param string $by (default: 'externalId')
|
||||||
* @param string $site (default: null)
|
* @param string $site (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function customersEdit(array $customer, $by = 'externalId', $site = null)
|
public function customersEdit(array $customer, $by = 'externalId', $site = null)
|
||||||
{
|
{
|
||||||
if (!sizeof($customer)) {
|
if (!sizeof($customer)) {
|
||||||
throw new InvalidArgumentException('Parameter `customer` must contains a data');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Parameter `customer` must contains a data');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->checkIdParameter($by);
|
$this->checkIdParameter($by);
|
||||||
|
|
||||||
if (!isset($customer[$by])) {
|
if (!isset($customer[$by])) {
|
||||||
throw new InvalidArgumentException(sprintf('Customer array must contain the "%s" parameter.', $by));
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException(sprintf('Customer array must contain the "%s" parameter.', $by));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
"/customers/" . $customer[$by] . "/edit",
|
"/customers/" . $customer[$by] . "/edit",
|
||||||
Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST,
|
Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST,
|
||||||
$this->fillSite($site, array(
|
$this->fillSite(
|
||||||
|
$site,
|
||||||
|
array(
|
||||||
'customer' => json_encode($customer),
|
'customer' => json_encode($customer),
|
||||||
'by' => $by,
|
'by' => $by
|
||||||
)
|
)
|
||||||
));
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -273,12 +300,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
*
|
*
|
||||||
* @param array $customers
|
* @param array $customers
|
||||||
* @param string $site (default: null)
|
* @param string $site (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function customersUpload(array $customers, $site = null)
|
public function customersUpload(array $customers, $site = null)
|
||||||
{
|
{
|
||||||
if (!sizeof($customers)) {
|
if (!sizeof($customers)) {
|
||||||
throw new InvalidArgumentException('Parameter `customers` must contains array of the customers');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Parameter `customers` must contains array of the customers');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest("/customers/upload", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, $this->fillSite($site, array(
|
return $this->client->makeRequest("/customers/upload", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, $this->fillSite($site, array(
|
||||||
@ -292,7 +319,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* @param string $id
|
* @param string $id
|
||||||
* @param string $by (default: 'externalId')
|
* @param string $by (default: 'externalId')
|
||||||
* @param string $site (default: null)
|
* @param string $site (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function customersGet($id, $by = 'externalId', $site = null)
|
public function customersGet($id, $by = 'externalId', $site = null)
|
||||||
{
|
{
|
||||||
@ -309,7 +336,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* @param array $filter (default: array())
|
* @param array $filter (default: array())
|
||||||
* @param int $page (default: null)
|
* @param int $page (default: null)
|
||||||
* @param int $limit (default: null)
|
* @param int $limit (default: null)
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function customersList(array $filter = array(), $page = null, $limit = null)
|
public function customersList(array $filter = array(), $page = null, $limit = null)
|
||||||
{
|
{
|
||||||
@ -332,12 +359,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Save customer IDs' (id and externalId) association in the CRM
|
* Save customer IDs' (id and externalId) association in the CRM
|
||||||
*
|
*
|
||||||
* @param array $ids
|
* @param array $ids
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function customersFixExternalIds(array $ids)
|
public function customersFixExternalIds(array $ids)
|
||||||
{
|
{
|
||||||
if (!sizeof($ids)) {
|
if (!sizeof($ids)) {
|
||||||
throw new InvalidArgumentException('Method parameter must contains at least one IDs pair');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Method parameter must contains at least one IDs pair');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest("/customers/fix-external-ids", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, array(
|
return $this->client->makeRequest("/customers/fix-external-ids", Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST, array(
|
||||||
@ -345,10 +372,56 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 ApiResponse
|
||||||
|
*/
|
||||||
|
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', Retailcrm_Retailcrm_Model_Http_Client::METHOD_GET, $this->fillSite($site, $parameters));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload store inventories
|
||||||
|
*
|
||||||
|
* @param array $offers
|
||||||
|
* @param string $site (default: null)
|
||||||
|
* @return ApiResponse
|
||||||
|
*/
|
||||||
|
public function storeInventoriesUpload(array $offers, $site = null)
|
||||||
|
{
|
||||||
|
if (!sizeof($offers)) {
|
||||||
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Parameter `offers` must contains array of the customers');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
"/store/inventories/upload",
|
||||||
|
Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST,
|
||||||
|
$this->fillSite($site, array('offers' => json_encode($offers)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns deliveryServices list
|
* Returns deliveryServices list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function deliveryServicesList()
|
public function deliveryServicesList()
|
||||||
{
|
{
|
||||||
@ -358,7 +431,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
/**
|
/**
|
||||||
* Returns deliveryTypes list
|
* Returns deliveryTypes list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function deliveryTypesList()
|
public function deliveryTypesList()
|
||||||
{
|
{
|
||||||
@ -368,7 +441,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
/**
|
/**
|
||||||
* Returns orderMethods list
|
* Returns orderMethods list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function orderMethodsList()
|
public function orderMethodsList()
|
||||||
{
|
{
|
||||||
@ -378,7 +451,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
/**
|
/**
|
||||||
* Returns orderTypes list
|
* Returns orderTypes list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function orderTypesList()
|
public function orderTypesList()
|
||||||
{
|
{
|
||||||
@ -388,7 +461,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
/**
|
/**
|
||||||
* Returns paymentStatuses list
|
* Returns paymentStatuses list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function paymentStatusesList()
|
public function paymentStatusesList()
|
||||||
{
|
{
|
||||||
@ -398,7 +471,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
/**
|
/**
|
||||||
* Returns paymentTypes list
|
* Returns paymentTypes list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function paymentTypesList()
|
public function paymentTypesList()
|
||||||
{
|
{
|
||||||
@ -408,7 +481,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
/**
|
/**
|
||||||
* Returns productStatuses list
|
* Returns productStatuses list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function productStatusesList()
|
public function productStatusesList()
|
||||||
{
|
{
|
||||||
@ -418,7 +491,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
/**
|
/**
|
||||||
* Returns statusGroups list
|
* Returns statusGroups list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function statusGroupsList()
|
public function statusGroupsList()
|
||||||
{
|
{
|
||||||
@ -428,7 +501,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
/**
|
/**
|
||||||
* Returns statuses list
|
* Returns statuses list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function statusesList()
|
public function statusesList()
|
||||||
{
|
{
|
||||||
@ -438,23 +511,33 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
/**
|
/**
|
||||||
* Returns sites list
|
* Returns sites list
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function sitesList()
|
public function sitesList()
|
||||||
{
|
{
|
||||||
return $this->client->makeRequest('/reference/sites', Retailcrm_Retailcrm_Model_Http_Client::METHOD_GET);
|
return $this->client->makeRequest('/reference/sites', Retailcrm_Retailcrm_Model_Http_Client::METHOD_GET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns stores list
|
||||||
|
*
|
||||||
|
* @return ApiResponse
|
||||||
|
*/
|
||||||
|
public function storesList()
|
||||||
|
{
|
||||||
|
return $this->client->makeRequest('/reference/stores', Retailcrm_Retailcrm_Model_Http_Client::METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit deliveryService
|
* Edit deliveryService
|
||||||
*
|
*
|
||||||
* @param array $data delivery service data
|
* @param array $data delivery service data
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function deliveryServicesEdit(array $data)
|
public function deliveryServicesEdit(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['code'])) {
|
if (!isset($data['code'])) {
|
||||||
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -470,12 +553,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Edit deliveryType
|
* Edit deliveryType
|
||||||
*
|
*
|
||||||
* @param array $data delivery type data
|
* @param array $data delivery type data
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function deliveryTypesEdit(array $data)
|
public function deliveryTypesEdit(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['code'])) {
|
if (!isset($data['code'])) {
|
||||||
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -491,12 +574,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Edit orderMethod
|
* Edit orderMethod
|
||||||
*
|
*
|
||||||
* @param array $data order method data
|
* @param array $data order method data
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function orderMethodsEdit(array $data)
|
public function orderMethodsEdit(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['code'])) {
|
if (!isset($data['code'])) {
|
||||||
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -512,12 +595,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Edit orderType
|
* Edit orderType
|
||||||
*
|
*
|
||||||
* @param array $data order type data
|
* @param array $data order type data
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function orderTypesEdit(array $data)
|
public function orderTypesEdit(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['code'])) {
|
if (!isset($data['code'])) {
|
||||||
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -533,12 +616,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Edit paymentStatus
|
* Edit paymentStatus
|
||||||
*
|
*
|
||||||
* @param array $data payment status data
|
* @param array $data payment status data
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function paymentStatusesEdit(array $data)
|
public function paymentStatusesEdit(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['code'])) {
|
if (!isset($data['code'])) {
|
||||||
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -554,12 +637,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Edit paymentType
|
* Edit paymentType
|
||||||
*
|
*
|
||||||
* @param array $data payment type data
|
* @param array $data payment type data
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function paymentTypesEdit(array $data)
|
public function paymentTypesEdit(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['code'])) {
|
if (!isset($data['code'])) {
|
||||||
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -575,12 +658,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Edit productStatus
|
* Edit productStatus
|
||||||
*
|
*
|
||||||
* @param array $data product status data
|
* @param array $data product status data
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function productStatusesEdit(array $data)
|
public function productStatusesEdit(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['code'])) {
|
if (!isset($data['code'])) {
|
||||||
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -596,12 +679,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Edit order status
|
* Edit order status
|
||||||
*
|
*
|
||||||
* @param array $data status data
|
* @param array $data status data
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function statusesEdit(array $data)
|
public function statusesEdit(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['code'])) {
|
if (!isset($data['code'])) {
|
||||||
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -617,12 +700,12 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
* Edit site
|
* Edit site
|
||||||
*
|
*
|
||||||
* @param array $data site data
|
* @param array $data site data
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function sitesEdit(array $data)
|
public function sitesEdit(array $data)
|
||||||
{
|
{
|
||||||
if (!isset($data['code'])) {
|
if (!isset($data['code'])) {
|
||||||
throw new InvalidArgumentException('Data must contain "code" parameter.');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->client->makeRequest(
|
return $this->client->makeRequest(
|
||||||
@ -634,10 +717,35 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit store
|
||||||
|
*
|
||||||
|
* @param array $data site data
|
||||||
|
* @return ApiResponse
|
||||||
|
*/
|
||||||
|
public function storesEdit(array $data)
|
||||||
|
{
|
||||||
|
if (!isset($data['code'])) {
|
||||||
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "code" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($data['name'])) {
|
||||||
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('Data must contain "name" parameter.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->client->makeRequest(
|
||||||
|
'/reference/stores/' . $data['code'] . '/edit',
|
||||||
|
Retailcrm_Retailcrm_Model_Http_Client::METHOD_POST,
|
||||||
|
array(
|
||||||
|
'store' => json_encode($data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update CRM basic statistic
|
* Update CRM basic statistic
|
||||||
*
|
*
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public function statisticUpdate()
|
public function statisticUpdate()
|
||||||
{
|
{
|
||||||
@ -675,7 +783,7 @@ class Retailcrm_Retailcrm_Model_ApiClient
|
|||||||
{
|
{
|
||||||
$allowedForBy = array('externalId', 'id');
|
$allowedForBy = array('externalId', 'id');
|
||||||
if (!in_array($by, $allowedForBy)) {
|
if (!in_array($by, $allowedForBy)) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException(sprintf(
|
||||||
'Value "%s" for parameter "by" is not valid. Allowed values are %s.',
|
'Value "%s" for parameter "by" is not valid. Allowed values are %s.',
|
||||||
$by,
|
$by,
|
||||||
implode(', ', $allowedForBy)
|
implode(', ', $allowedForBy)
|
||||||
|
@ -124,14 +124,29 @@ class Retailcrm_Retailcrm_Model_Exchange
|
|||||||
|
|
||||||
public function ordersHistory()
|
public function ordersHistory()
|
||||||
{
|
{
|
||||||
$this->_config = Mage::getStoreConfig('retailcrm');
|
/*$this->_config = Mage::getStoreConfig('retailcrm');
|
||||||
|
|
||||||
$statuses = array_flip(array_filter($this->_config['status']));
|
$statuses = array_flip(array_filter($this->_config['status']));
|
||||||
$paymentsStatuses = array_flip(array_filter($this->_config['paymentstatus']));
|
$paymentsStatuses = array_flip(array_filter($this->_config['paymentstatus']));
|
||||||
$payments = array_filter($this->_config['payment']);
|
$payments = array_filter($this->_config['payment']);
|
||||||
$shippings = array_filter($this->_config['shipping']);
|
$shippings = array_filter($this->_config['shipping']);
|
||||||
|
*/
|
||||||
|
|
||||||
Mage::log(var_export($this->_config, TRUE), null, 'history.log');
|
$timeMark = date('Y-m-d H:i:s');
|
||||||
|
$lastRun = Mage::getStoreConfig('retailcrm/general/history');
|
||||||
|
|
||||||
|
if (!empty($lastRun)) {
|
||||||
|
$lastRun = new DateTime(
|
||||||
|
date(
|
||||||
|
'Y-m-d H:i:s',
|
||||||
|
strtotime('-1 days', strtotime(date('Y-m-d H:i:s')))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$lastRun = new DateTime($lastRun);
|
||||||
|
}
|
||||||
|
|
||||||
|
$history = $client->ordersHistory($lastRun);
|
||||||
|
Mage::getModel('core/config')->saveConfig('retailcrm/general/history', $timeMark);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,11 +14,12 @@ class Retailcrm_Retailcrm_Model_Http_Client
|
|||||||
public function __construct($url, array $defaultParameters = array())
|
public function __construct($url, array $defaultParameters = array())
|
||||||
{
|
{
|
||||||
if (false === stripos($url, 'https://')) {
|
if (false === stripos($url, 'https://')) {
|
||||||
throw new InvalidArgumentException('API schema requires HTTPS protocol');
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException('API schema requires HTTPS protocol');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->defaultParameters = $defaultParameters;
|
$this->defaultParameters = $defaultParameters;
|
||||||
|
$this->retry = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,11 +31,11 @@ class Retailcrm_Retailcrm_Model_Http_Client
|
|||||||
* @param int $timeout
|
* @param int $timeout
|
||||||
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
* @return Retailcrm_Retailcrm_Model_Response_ApiResponse
|
||||||
*/
|
*/
|
||||||
public function makeRequest($path, $method, array $parameters = array(), $timeout = 60)
|
public function makeRequest($path, $method, array $parameters = array(), $timeout = 90)
|
||||||
{
|
{
|
||||||
$allowedMethods = array(self::METHOD_GET, self::METHOD_POST);
|
$allowedMethods = array(self::METHOD_GET, self::METHOD_POST);
|
||||||
if (!in_array($method, $allowedMethods)) {
|
if (!in_array($method, $allowedMethods)) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new Retailcrm_Retailcrm_Model_Exception_InvalidJsonException(sprintf(
|
||||||
'Method "%s" is not valid. Allowed methods are %s',
|
'Method "%s" is not valid. Allowed methods are %s',
|
||||||
$method,
|
$method,
|
||||||
implode(', ', $allowedMethods)
|
implode(', ', $allowedMethods)
|
||||||
@ -43,18 +44,21 @@ class Retailcrm_Retailcrm_Model_Http_Client
|
|||||||
|
|
||||||
$parameters = array_merge($this->defaultParameters, $parameters);
|
$parameters = array_merge($this->defaultParameters, $parameters);
|
||||||
|
|
||||||
$path = $this->url . $path;
|
$url = $this->url . $path;
|
||||||
|
|
||||||
if (self::METHOD_GET === $method && sizeof($parameters)) {
|
if (self::METHOD_GET === $method && sizeof($parameters)) {
|
||||||
$path .= '?' . http_build_query($parameters);
|
$url .= '?' . http_build_query($parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $path);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout);
|
|
||||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout);
|
||||||
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int) $timeout);
|
||||||
|
|
||||||
if (self::METHOD_POST === $method) {
|
if (self::METHOD_POST === $method) {
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
@ -63,11 +67,23 @@ class Retailcrm_Retailcrm_Model_Http_Client
|
|||||||
|
|
||||||
$responseBody = curl_exec($ch);
|
$responseBody = curl_exec($ch);
|
||||||
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
|
||||||
$errno = curl_errno($ch);
|
$errno = curl_errno($ch);
|
||||||
$error = curl_error($ch);
|
$error = curl_error($ch);
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($errno && in_array($errno, array(6, 7, 28, 34, 35)) && $this->retry < 3) {
|
||||||
|
$errno = null;
|
||||||
|
$error = null;
|
||||||
|
$this->retry += 1;
|
||||||
|
$this->makeRequest(
|
||||||
|
$path,
|
||||||
|
$method,
|
||||||
|
$parameters,
|
||||||
|
$timeout
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($errno) {
|
if ($errno) {
|
||||||
throw new Retailcrm_Retailcrm_Model_Exception_CurlException($error, $errno);
|
throw new Retailcrm_Retailcrm_Model_Exception_CurlException($error, $errno);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user