diff --git a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmApiClient.php b/classes/modules/RetailCRM/classes/retailcrm/RetailcrmApiClient.php deleted file mode 100644 index a479845..0000000 --- a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmApiClient.php +++ /dev/null @@ -1,811 +0,0 @@ -client = new RetailcrmHttpClient($url, array('apiKey' => $apiKey)); - $this->siteCode = $site; - } - - /** - * Create a order - * - * @param array $order - * @param string $site (default: null) - * @return RetailcrmApiResponse - */ - 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", RetailcrmHttpClient::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 RetailcrmApiResponse - */ - 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", - RetailcrmHttpClient::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 RetailcrmApiResponse - */ - 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", RetailcrmHttpClient::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 RetailcrmApiResponse - */ - public function ordersGet($id, $by = 'externalId', $site = null) - { - $this->checkIdParameter($by); - - return $this->client->makeRequest("/orders/$id", RetailcrmHttpClient::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 RetailcrmApiResponse - */ - 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', RetailcrmHttpClient::METHOD_GET, $parameters); - } - - /** - * Returns filtered orders list - * - * @param array $filter (default: array()) - * @param int $page (default: null) - * @param int $limit (default: null) - * @return RetailcrmApiResponse - */ - 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', RetailcrmHttpClient::METHOD_GET, $parameters); - } - - /** - * Returns statuses of the orders - * - * @param array $ids (default: array()) - * @param array $externalIds (default: array()) - * @return RetailcrmApiResponse - */ - 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', RetailcrmHttpClient::METHOD_GET, $parameters); - } - - /** - * Save order IDs' (id and externalId) association in the CRM - * - * @param array $ids - * @return RetailcrmApiResponse - */ - 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", RetailcrmHttpClient::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 RetailcrmApiResponse - */ - 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', RetailcrmHttpClient::METHOD_GET, $parameters); - } - - /** - * Create a customer - * - * @param array $customer - * @param string $site (default: null) - * @return RetailcrmApiResponse - */ - 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", RetailcrmHttpClient::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 RetailcrmApiResponse - */ - 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", - RetailcrmHttpClient::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 RetailcrmApiResponse - */ - 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", RetailcrmHttpClient::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 RetailcrmApiResponse - */ - public function customersGet($id, $by = 'externalId', $site = null) - { - $this->checkIdParameter($by); - - return $this->client->makeRequest("/customers/$id", RetailcrmHttpClient::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 RetailcrmApiResponse - */ - 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', RetailcrmHttpClient::METHOD_GET, $parameters); - } - - /** - * Save customer IDs' (id and externalId) association in the CRM - * - * @param array $ids - * @return RetailcrmApiResponse - */ - 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", RetailcrmHttpClient::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 RetailcrmApiResponse - */ - 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', RetailcrmHttpClient::METHOD_GET, $this->fillSite($site, $parameters)); - } - - /** - * Upload store inventories - * - * @param array $offers - * @param string $site (default: null) - * @return RetailcrmApiResponse - */ - 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", - RetailcrmHttpClient::METHOD_POST, - $this->fillSite($site, array('offers' => json_encode($offers))) - ); - } - - /** - * Returns deliveryServices list - * - * @return RetailcrmApiResponse - */ - public function deliveryServicesList() - { - return $this->client->makeRequest('/reference/delivery-services', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns deliveryTypes list - * - * @return RetailcrmApiResponse - */ - public function deliveryTypesList() - { - return $this->client->makeRequest('/reference/delivery-types', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns orderMethods list - * - * @return RetailcrmApiResponse - */ - public function orderMethodsList() - { - return $this->client->makeRequest('/reference/order-methods', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns orderTypes list - * - * @return RetailcrmApiResponse - */ - public function orderTypesList() - { - return $this->client->makeRequest('/reference/order-types', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns paymentStatuses list - * - * @return RetailcrmApiResponse - */ - public function paymentStatusesList() - { - return $this->client->makeRequest('/reference/payment-statuses', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns paymentTypes list - * - * @return RetailcrmApiResponse - */ - public function paymentTypesList() - { - return $this->client->makeRequest('/reference/payment-types', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns productStatuses list - * - * @return RetailcrmApiResponse - */ - public function productStatusesList() - { - return $this->client->makeRequest('/reference/product-statuses', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns statusGroups list - * - * @return RetailcrmApiResponse - */ - public function statusGroupsList() - { - return $this->client->makeRequest('/reference/status-groups', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns statuses list - * - * @return RetailcrmApiResponse - */ - public function statusesList() - { - return $this->client->makeRequest('/reference/statuses', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns sites list - * - * @return RetailcrmApiResponse - */ - public function sitesList() - { - return $this->client->makeRequest('/reference/sites', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Returns stores list - * - * @return RetailcrmApiResponse - */ - public function storesList() - { - return $this->client->makeRequest('/reference/stores', RetailcrmHttpClient::METHOD_GET); - } - - /** - * Edit deliveryService - * - * @param array $data delivery service data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'deliveryService' => json_encode($data) - ) - ); - } - - /** - * Edit deliveryType - * - * @param array $data delivery type data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'deliveryType' => json_encode($data) - ) - ); - } - - /** - * Edit orderMethod - * - * @param array $data order method data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'orderMethod' => json_encode($data) - ) - ); - } - - /** - * Edit orderType - * - * @param array $data order type data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'orderType' => json_encode($data) - ) - ); - } - - /** - * Edit paymentStatus - * - * @param array $data payment status data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'paymentStatus' => json_encode($data) - ) - ); - } - - /** - * Edit paymentType - * - * @param array $data payment type data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'paymentType' => json_encode($data) - ) - ); - } - - /** - * Edit productStatus - * - * @param array $data product status data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'productStatus' => json_encode($data) - ) - ); - } - - /** - * Edit order status - * - * @param array $data status data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'status' => json_encode($data) - ) - ); - } - - /** - * Edit site - * - * @param array $data site data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'site' => json_encode($data) - ) - ); - } - - /** - * Edit store - * - * @param array $data site data - * @return RetailcrmApiResponse - */ - 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', - RetailcrmHttpClient::METHOD_POST, - array( - 'store' => json_encode($data) - ) - ); - } - - /** - * Update CRM basic statistic - * - * @return RetailcrmApiResponse - */ - public function statisticUpdate() - { - return $this->client->makeRequest('/statistic/update', RetailcrmHttpClient::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; - } -} \ No newline at end of file diff --git a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmApiResponse.php b/classes/modules/RetailCRM/classes/retailcrm/RetailcrmApiResponse.php deleted file mode 100644 index 6d169d2..0000000 --- a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmApiResponse.php +++ /dev/null @@ -1,122 +0,0 @@ -statusCode = (int) $statusCode; - - if (!empty($responseBody)) { - $response = json_decode($responseBody, true); - - if (!$response && JSON_ERROR_NONE !== ($error = json_last_error())) { - throw new InvalidJsonException( - "Invalid JSON in the API response body. Error code #$error", - $error - ); - } - - $this->response = $response; - } - } - - /** - * Return HTTP response status code - * - * @return int - */ - public function getStatusCode() - { - return $this->statusCode; - } - - /** - * HTTP request was successful - * - * @return bool - */ - public function isSuccessful() - { - return $this->statusCode < 400; - } - - /** - * Allow to access for the property throw class method - * - * @param string $name - * @return mixed - */ - public function __call($name, $arguments) - { - // convert getSomeProperty to someProperty - $propertyName = strtolower(substr($name, 3, 1)) . substr($name, 4); - - if (!isset($this->response[$propertyName])) { - throw new InvalidArgumentException("Method \"$name\" not found"); - } - - return $this->response[$propertyName]; - } - - /** - * Allow to access for the property throw object property - * - * @param string $name - * @return mixed - */ - public function __get($name) - { - if (!isset($this->response[$name])) { - throw new InvalidArgumentException("Property \"$name\" not found"); - } - - return $this->response[$name]; - } - - /** - * @param mixed $offset - * @param mixed $value - */ - public function offsetSet($offset, $value) - { - throw new BadMethodCallException('This activity not allowed'); - } - - /** - * @param mixed $offset - */ - public function offsetUnset($offset) - { - throw new BadMethodCallException('This call not allowed'); - } - - /** - * @param mixed $offset - * @return bool - */ - public function offsetExists($offset) - { - return isset($this->response[$offset]); - } - - /** - * @param mixed $offset - * @return mixed - */ - public function offsetGet($offset) - { - if (!isset($this->response[$offset])) { - throw new InvalidArgumentException("Property \"$offset\" not found"); - } - - return $this->response[$offset]; - } -} \ No newline at end of file diff --git a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmHelpers.php b/classes/modules/RetailCRM/classes/retailcrm/RetailcrmHelpers.php deleted file mode 100644 index aad9620..0000000 --- a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmHelpers.php +++ /dev/null @@ -1,41 +0,0 @@ - ', $mapItem); - $map[$mapItem[0]] = $mapItem[1]; - } - - return $map; - } - - /** - * @param $map array - * @param $item string - * @param $reversed bool - * @return string|null - */ - public function getRelationByMap($map, $item, $reversed = false) { - if(!$reversed) { - if(isset($map[$item]) && !empty($map[$item])) - return $map[$item]; - else - return null; - } else { - foreach ($map as $umiStatusOrder => $crmStatusOrder) { - if($crmStatusOrder == $item) - return $umiStatusOrder; - } - return null; - } - } -} \ No newline at end of file diff --git a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmHttpClient.php b/classes/modules/RetailCRM/classes/retailcrm/RetailcrmHttpClient.php deleted file mode 100644 index 820d518..0000000 --- a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmHttpClient.php +++ /dev/null @@ -1,113 +0,0 @@ -url = $url; - $this->defaultParameters = $defaultParameters; - $this->retry = 0; - } - - /** - * Make HTTP request - * - * @param string $path - * @param string $method (default: 'GET') - * @param array $parameters (default: array()) - * @param int $timeout - * @param bool $verify - * @param bool $debug - * @return RetailcrmApiResponse - */ - public function makeRequest( - $path, - $method, - array $parameters = array(), - $timeout = 30, - $verify = false, - $debug = false - ) { - $allowedMethods = array(self::METHOD_GET, self::METHOD_POST); - if (!in_array($method, $allowedMethods)) { - throw new InvalidArgumentException(sprintf( - 'Method "%s" is not valid. Allowed methods are %s', - $method, - implode(', ', $allowedMethods) - )); - } - - $parameters = array_merge($this->defaultParameters, $parameters); - - $url = $this->url . $path; - - if (self::METHOD_GET === $method && sizeof($parameters)) { - $url .= '?' . http_build_query($parameters, '', '&'); - } - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt($ch, CURLOPT_FAILONERROR, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verify); - - if (!$debug) { - curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int) $timeout); - } else { - curl_setopt($ch, CURLOPT_TIMEOUT_MS, (int) $timeout + ($this->retry * 2000)); - } - - if (self::METHOD_POST === $method) { - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); - } - - $responseBody = curl_exec($ch); - $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $errno = curl_errno($ch); - $error = curl_error($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, - $verify, - $debug - ); - } - - if ($errno) { - throw new CurlException($error, $errno); - } - - return new RetailcrmApiResponse($statusCode, $responseBody); - } - - public function getRetry() - { - return $this->retry; - } -} \ No newline at end of file diff --git a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmProxy.php b/classes/modules/RetailCRM/classes/retailcrm/RetailcrmProxy.php deleted file mode 100644 index e866baf..0000000 --- a/classes/modules/RetailCRM/classes/retailcrm/RetailcrmProxy.php +++ /dev/null @@ -1,39 +0,0 @@ -api = new RetailcrmApiClient($url, $key); - $this->log = $log; - } - public function __call($method, $arguments) - { - $accessLog = date('H:m:i') . ' [' . $method . '] -> ' . json_encode($arguments) . "\n"; - error_log($accessLog, 3, $this->log); - - try { - $response = call_user_func_array(array($this->api, $method), $arguments); - if (!$response->isSuccessful()) { - error_log("[$method] " . $response->getErrorMsg() . "\n", 3, $this->log); - if (isset($response['errors'])) { - $error = implode("\n", $response['errors']); - error_log($error . "\n", 3, $this->log); - } - $response = false; - } - return $response; - } catch (CurlException $e) { - error_log("[$method] " . $e->getMessage() . "\n", 3, $this->log); - return false; - } catch (InvalidJsonException $e) { - error_log("[$method] " . $e->getMessage() . "\n", 3, $this->log); - return false; - } - } -} \ No newline at end of file diff --git a/classes/modules/RetailCRM/classes/retailcrm/icml.php b/classes/modules/RetailCRM/classes/retailcrm/icml.php deleted file mode 100644 index cc20895..0000000 --- a/classes/modules/RetailCRM/classes/retailcrm/icml.php +++ /dev/null @@ -1,294 +0,0 @@ -getList(); - $domainCollection = $domainsCollectionList[1]; - $serverProtocol = mainConfiguration::getInstance()->get('system', 'server-protocol') . '://'; - $this->shopUrl = $serverProtocol . $domainCollection->getHost(); - } - - public function generateICML() - { - $string = ' - - - '.$this->shopName.' - - - - - '; - $xml = new SimpleXMLElement( - $string, - LIBXML_NOENT |LIBXML_NOCDATA | LIBXML_COMPACT | LIBXML_PARSEHUGE - ); - $this->dd = new DOMDocument(); - $this->dd->preserveWhiteSpace = false; - $this->dd->formatOutput = true; - $this->dd->loadXML($xml->asXML()); - $this->eCategories = $this->dd - ->getElementsByTagName('categories')->item(0); - $this->eOffers = $this->dd - ->getElementsByTagName('offers')->item(0); - - $this->addCategories(); - $this->addOffers(); - $this->dd->saveXML(); - $downloadPath = __DIR__ . '/../../../../../'; - if (!file_exists($downloadPath)) { - mkdir($downloadPath, 0755); - } - $this->dd->save($downloadPath . 'retailcrm.xml'); - } - - /** - * - */ - private function addCategories() - { - $categories = new selector('pages'); - $categories->types('hierarchy-type')->name('catalog', 'category'); - - $result = $categories->result(); - - foreach($result as $category) { - /** @var umiHierarchyElement $category */ - - /** @var DOMElement $e */ - $e = $this->eCategories->appendChild( - $this->dd->createElement( - 'category', $category->getName() - ) - ); - $e->setAttribute('id', $category->getId()); - if ($category->getRel() > 0) { - $e->setAttribute('parentId', $category->getRel()); - } - } - } - private function getObjectUrl(umiHierarchyElement $obj) { - $url = ''; - $url = '/' . $obj->getAltName() . $url; - - $parent = new umiHierarchyElement($obj->getRel()); - while(true) { - $url = '/' . $parent->getAltName() . $url; - - if($parent->getRel() != 0) { - $parent = new umiHierarchyElement($parent->getRel()); - } else { - break; - } - } - - $url = $this->shopUrl . $url; - - return $url; - } - - private function getCombinationsFromMultyArray($sourceData) { - $sourceDataKeys = array(); - foreach ($sourceData as $key=>$value) { - $sourceDataKeys[] = $key; - } - - $data = array(); - $data[] = ''; - for($i = 0; $i < count($sourceData); $i++) { - $oldData = $data; - $data = array(); - - foreach($oldData as $value) { - foreach ($sourceData[$sourceDataKeys[$i]] as $value2) { - $data[] = (!empty($value) ? $value.',' : '') . $sourceDataKeys[$i] . '-' . $value2; - } - } - } - - $resultData = array(); - foreach ($data as $value) { - $items = explode(',', $value); - $columns = array(); - foreach ($items as $item) { - $item = explode('-', $item); - $columns[$item[0]] = $item[1]; - } - $resultData[] = $columns; - } - - return $resultData; - } - - private function addOffers() - { - $offers = new selector('pages'); - $offers->types('hierarchy-type')->name('catalog', 'object'); - - $result = $offers->result(); - - foreach ($result as $offer) { - /** @var umiHierarchyElement $offer */ - - $objects = umiObjectsCollection::getInstance(); - - $offerObject = new umiObject($offer->getObjectId()); - - /** @var umiFieldsGroup $optionsObject */ - $optionsObject = $offerObject->getType()->getFieldsGroupByName('catalog_option_props'); - - $options = array(); - $optionValues = array(); - $optionGroups = array(); - $optionPrices = array(); - foreach ($optionsObject->getFields() as $optionField) { - /** @var umiField $optionField */ - - $optionGroups[$optionField->getId()] = $optionField; - - $values = $offerObject->getValue($optionField->getName()); - - foreach ($values as $value) { - $valueObject = $objects->getObject($value['rel']); - $options[$optionField->getId()][] = $valueObject->getId(); - - $optionPrices[$valueObject->getId()] = $value['float']; - - $optionValues[$valueObject->getId()] = $valueObject; - } - } - - if(count($options)) - $offerOptions = $this->getCombinationsFromMultyArray($options); - else { - // Если нет опционных товаров(товарных предложений) передаём массив с 1 пустым элементом - базовый товар - $offerOptions = array(); - $offerOptions[] = ''; - } - - foreach ($offerOptions as $offerOption) { - if(!empty($offerOption)) { - $options = array(); - foreach ($offerOption as $offerOptionId => $offerOptionValue) { - $options[] = $offerOptionId . '_' . $offerOptionValue; - } - - $offerId = $offer->getId() . '#' . implode('-', $options); - } else - $offerId = $offer->getId(); - - - /** @var DOMElement $e */ - $e = $this->eOffers->appendChild($this->dd->createElement('offer')); - $e->setAttribute('id', $offerId); - $e->setAttribute('productId', $offer->getId()); - $quantity = $offerObject->getPropByName('common_quantity')->getValue(); - $e->setAttribute('quantity', !empty($quantity) ? $quantity : 0); - - /** - * Offer activity - */ - $activity = $offer->getIsActive() == 1 ? 'Y' : 'N'; - $e->appendChild( - $this->dd->createElement('productActivity') - )->appendChild( - $this->dd->createTextNode($activity) - ); - - /** - * Offer category - */ - $e->appendChild($this->dd->createElement('categoryId')) - ->appendChild( - $this->dd->createTextNode($offer->getRel()) - ); - - /** - * Name & price - */ - if(!empty($offerOption)) { - $options = array(); - foreach ($offerOption as $offerOptionId => $offerOptionValue) { - $options[] = $optionGroups[$offerOptionId]->getTitle() . ': ' . $optionValues[$offerOptionValue]->getName(); - } - $offerName = $offer->getName() . ' (' . implode(', ', $options) . ')'; - } else - $offerName = $offer->getName(); - $e->appendChild($this->dd->createElement('name')) - ->appendChild($this->dd->createTextNode($offerName)); - - $e->appendChild($this->dd->createElement('productName')) - ->appendChild($this->dd->createTextNode($offer->getName())); - - $price = $offerObject->getPropByName('price')->getValue(); - if(!empty($offerOption)) { - foreach ($offerOption as $offerOptionId => $offerOptionValue) { - $price += $optionPrices[$offerOptionValue]; - } - } - $e->appendChild($this->dd->createElement('price')) - ->appendChild($this->dd->createTextNode($price)); - - /** - * Options - */ - if(!empty($offerOption)) { - $options = array(); - foreach ($offerOption as $offerOptionId => $offerOptionValue) { - $option = $this->dd->createElement('param'); - $option->setAttribute('code', $optionGroups[$offerOptionId]->getName()); - $option->setAttribute('name', $optionGroups[$offerOptionId]->getTitle()); - $option->appendChild($this->dd->createTextNode($optionValues[$offerOptionValue]->getName())); - $e->appendChild($option); - } - } - - /** - * Image - */ - /** @var umiImageFile $photo */ - $photo = $offerObject->getPropByName('photo')->getValue(); - $photoPath = $photo->getFilePath(true); - $photoFullPath = $this->shopUrl . $photoPath; - $e->appendChild($this->dd->createElement('picture')) - ->appendChild($this->dd->createTextNode($photoFullPath)); - - /** - * Url - */ - $url = $this->getObjectUrl($offer); - $e->appendChild($this->dd->createElement('url')) - ->appendChild( - $this->dd->createTextNode($url) - ); - - /** - * Additional characteristics - */ - if ($offerObject->getPropByName('weight')) { - $weight = $this->dd->createElement('param'); - $weight->setAttribute('code', 'weight'); - $weight->setAttribute('name', 'Вес'); - $weight->appendChild($this->dd->createTextNode($offerObject->getPropByName('weight')->getValue() * 1000)); - $e->appendChild($weight); - } - } - } - } -} - -?> \ No newline at end of file