mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
Added 'files' api methods
This commit is contained in:
parent
bbc458696e
commit
3436b4f956
@ -1,3 +1,9 @@
|
||||
## v3.4.9
|
||||
* Добавлены api методы для работы с файлами
|
||||
|
||||
## v3.4.8
|
||||
* Исправлена синхронизация заказов при ненастроенном маппинге статусов
|
||||
|
||||
## v3.4.7
|
||||
* Исправлена ошибка в работе воркеров публичной части сайта
|
||||
|
||||
|
@ -52,7 +52,7 @@ class RetailcrmOrdersController extends RetailcrmAdminPostAbstractController
|
||||
protected function getHandler()
|
||||
{
|
||||
$orders = Tools::getValue('orders', []);
|
||||
$page = (int) (Tools::getValue('page', 1));
|
||||
$page = (int) Tools::getValue('page', 1);
|
||||
|
||||
switch (Tools::getValue('filter')) {
|
||||
case '1':
|
||||
|
@ -61,8 +61,8 @@ class RetailcrmContextSwitcher
|
||||
self::storeContext();
|
||||
|
||||
foreach (self::getShops() as $shop) {
|
||||
self::setShopContext((int) ($shop['id_shop']));
|
||||
$result[(int) ($shop['id_shop'])] = call_user_func_array($callback, $arguments);
|
||||
self::setShopContext((int) $shop['id_shop']);
|
||||
$result[(int) $shop['id_shop']] = call_user_func_array($callback, $arguments);
|
||||
}
|
||||
|
||||
self::restoreContext();
|
||||
|
@ -56,9 +56,9 @@ class RetailcrmHistory
|
||||
|
||||
private static function init()
|
||||
{
|
||||
self::$receiveOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING));
|
||||
self::$sendOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_SENDING));
|
||||
self::$cartStatus = (string) (Configuration::get(RetailCRM::SYNC_CARTS_STATUS));
|
||||
self::$receiveOrderNumber = (bool) Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING);
|
||||
self::$sendOrderNumber = (bool) Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_SENDING);
|
||||
self::$cartStatus = (string) Configuration::get(RetailCRM::SYNC_CARTS_STATUS);
|
||||
self::$statuses = array_flip(array_filter(json_decode(Configuration::get(RetailCRM::STATUS), true)));
|
||||
self::$deliveries = array_flip(array_filter(json_decode(Configuration::get(RetailCRM::DELIVERY), true)));
|
||||
self::$payments = array_flip(array_filter(json_decode(Configuration::get(RetailCRM::PAYMENT), true)));
|
||||
@ -1002,7 +1002,7 @@ class RetailcrmHistory
|
||||
$default_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
|
||||
$newOrder = new Order();
|
||||
$newOrder->id_shop = Context::getContext()->shop->id;
|
||||
$newOrder->id_shop_group = (int) (Context::getContext()->shop->id_shop_group);
|
||||
$newOrder->id_shop_group = (int) Context::getContext()->shop->id_shop_group;
|
||||
$newOrder->id_address_delivery = isset($addressDelivery->id) ? (int) $addressDelivery->id : 0;
|
||||
$newOrder->id_address_invoice = isset($addressInvoice->id) ? (int) $addressInvoice->id : 0;
|
||||
$newOrder->id_cart = (int) $cart->id;
|
||||
|
@ -295,7 +295,6 @@ class RetailcrmOrderBuilder
|
||||
$this->cmsCustomer,
|
||||
$this->cmsCart,
|
||||
false,
|
||||
false,
|
||||
$dataFromCart,
|
||||
'',
|
||||
'',
|
||||
@ -861,7 +860,6 @@ class RetailcrmOrderBuilder
|
||||
$this->cmsCustomer,
|
||||
$this->cmsCart,
|
||||
false,
|
||||
false,
|
||||
$dataFromCart,
|
||||
$contactPersonId,
|
||||
$contactPersonExternalId,
|
||||
@ -902,7 +900,7 @@ class RetailcrmOrderBuilder
|
||||
$delivery = json_decode(Configuration::get(RetailCRM::DELIVERY), true);
|
||||
$payment = json_decode(Configuration::get(RetailCRM::PAYMENT), true);
|
||||
$status = json_decode(Configuration::get(RetailCRM::STATUS), true);
|
||||
$sendOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_SENDING));
|
||||
$sendOrderNumber = (bool) Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_SENDING);
|
||||
$orderNumber = $sendOrderNumber ? $order->reference : null;
|
||||
|
||||
if (false === Module::getInstanceByName('advancedcheckout')) {
|
||||
|
@ -207,6 +207,111 @@ class RetailcrmApiClientV5
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get files list
|
||||
*
|
||||
* @param array $filter
|
||||
* @param null $limit
|
||||
* @param null $page
|
||||
*
|
||||
* @return RetailcrmApiResponse
|
||||
*/
|
||||
public function filesList(array $filter = [], $limit = null, $page = null)
|
||||
{
|
||||
$parameters = [];
|
||||
|
||||
if (count($filter)) {
|
||||
$parameters['filter'] = $filter;
|
||||
}
|
||||
if (null !== $page) {
|
||||
$parameters['page'] = (int) $page;
|
||||
}
|
||||
if (null !== $limit) {
|
||||
$parameters['limit'] = (int) $limit;
|
||||
}
|
||||
|
||||
return $this->client->makeRequest(
|
||||
'/files',
|
||||
RetailcrmHttpClient::METHOD_GET,
|
||||
$parameters
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload file
|
||||
*
|
||||
* @param $file
|
||||
*
|
||||
* @return RetailcrmApiResponse
|
||||
*/
|
||||
public function filesUpload($file)
|
||||
{
|
||||
return $this->client->makeRequest(
|
||||
'/files/upload',
|
||||
RetailcrmHttpClient::METHOD_POST,
|
||||
['file' => $file]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns file data
|
||||
*
|
||||
* @param int $id file ID
|
||||
*
|
||||
* @throws \RetailCrm\Exception\InvalidJsonException
|
||||
* @throws \RetailCrm\Exception\CurlException
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return RetailcrmApiResponse
|
||||
*/
|
||||
public function filesGet($id)
|
||||
{
|
||||
return $this->client->makeRequest("/files/$id", RetailcrmHttpClient::METHOD_GET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete file
|
||||
*
|
||||
* @param string $id file id
|
||||
*
|
||||
* @return RetailcrmApiResponse
|
||||
*/
|
||||
public function filesDelete($id)
|
||||
{
|
||||
if (!$id) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Parameter `id` must be set'
|
||||
);
|
||||
}
|
||||
|
||||
return $this->client->makeRequest(
|
||||
sprintf('/files/%s/delete', $id),
|
||||
RetailcrmHttpClient::METHOD_POST
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit file
|
||||
*
|
||||
* @param array $file
|
||||
*
|
||||
* @return RetailcrmApiResponse
|
||||
*/
|
||||
public function filesEdit(array $file)
|
||||
{
|
||||
if (!count($file)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Parameter `file` must contains a data'
|
||||
);
|
||||
}
|
||||
|
||||
return $this->client->makeRequest(
|
||||
"/files/{$file['id']}/edit",
|
||||
RetailcrmHttpClient::METHOD_POST,
|
||||
['file' => json_encode($file), 'id' => $file['id']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom fields list
|
||||
*
|
||||
|
@ -114,6 +114,10 @@ class RetailcrmHttpClient
|
||||
$url .= '?' . http_build_query($parameters, '', '&');
|
||||
}
|
||||
|
||||
if (self::METHOD_POST === $method && '/files/upload' === $path) {
|
||||
$url .= '?apiKey=' . $parameters['apiKey'];
|
||||
}
|
||||
|
||||
$curlHandler = curl_init();
|
||||
curl_setopt($curlHandler, CURLOPT_URL, $url);
|
||||
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
|
||||
@ -126,8 +130,13 @@ class RetailcrmHttpClient
|
||||
|
||||
if (self::METHOD_POST === $method) {
|
||||
curl_setopt($curlHandler, CURLOPT_POST, true);
|
||||
|
||||
if ('/files/upload' === $path) {
|
||||
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, file_get_contents($parameters['file']));
|
||||
} else {
|
||||
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
$responseBody = curl_exec($curlHandler);
|
||||
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
|
||||
|
@ -66,7 +66,7 @@ class RetailcrmExceptionMiddleware implements RetailcrmMiddlewareInterface
|
||||
sprintf(
|
||||
'Expected instance of `%s`, but `%s` given',
|
||||
RetailcrmApiResponse::class,
|
||||
(is_object($response) ? get_class($response) : gettype($response))
|
||||
is_object($response) ? get_class($response) : gettype($response)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ class RetailcrmExportOrdersMiddleware implements RetailcrmMiddlewareInterface
|
||||
$uploadedOrders = [];
|
||||
foreach ($orders as $order) {
|
||||
RetailcrmExportOrdersHelper::updateExportState($order['externalId'], $order['id']);
|
||||
$uploadedOrders[] = (int) ($order['externalId']);
|
||||
$uploadedOrders[] = (int) $order['externalId'];
|
||||
}
|
||||
|
||||
$notUploadedOrders = array_filter($requestedOrders, function ($orderId) use ($uploadedOrders) {
|
||||
|
@ -53,7 +53,7 @@ class RetailcrmReferenceMiddleware implements RetailcrmMiddlewareInterface
|
||||
|| 'ordersEdit' === $request->getMethod()
|
||||
)
|
||||
) {
|
||||
$receiveOrderNumber = (bool) (Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING));
|
||||
$receiveOrderNumber = (bool) Configuration::get(RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING);
|
||||
$crmOrder = $response->order;
|
||||
|
||||
if ($receiveOrderNumber
|
||||
|
@ -58,7 +58,7 @@ class RetailcrmAbandonedCartsEvent extends RetailcrmAbstractEvent implements Ret
|
||||
}
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||
RetailcrmContextSwitcher::setShopContext((int) $shop['id_shop']);
|
||||
|
||||
$syncCartsActive = Configuration::get(RetailCRM::SYNC_CARTS_ACTIVE);
|
||||
|
||||
|
@ -54,7 +54,7 @@ class RetailcrmExportEvent extends RetailcrmAbstractEvent implements RetailcrmEv
|
||||
$shops = $this->getShops();
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||
RetailcrmContextSwitcher::setShopContext((int) $shop['id_shop']);
|
||||
|
||||
$api = RetailcrmTools::getApiClient();
|
||||
|
||||
|
@ -54,7 +54,7 @@ class RetailcrmIcmlEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
||||
$shops = $this->getShops();
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||
RetailcrmContextSwitcher::setShopContext((int) $shop['id_shop']);
|
||||
|
||||
$job = new RetailcrmCatalog();
|
||||
$data = $job->getData();
|
||||
|
@ -54,7 +54,7 @@ class RetailcrmIcmlUpdateUrlEvent extends RetailcrmAbstractEvent implements Reta
|
||||
$shops = $this->getShops();
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||
RetailcrmContextSwitcher::setShopContext((int) $shop['id_shop']);
|
||||
|
||||
if (!file_exists(RetailcrmCatalogHelper::getIcmlFilePath())) {
|
||||
continue;
|
||||
|
@ -54,7 +54,7 @@ class RetailcrmInventoriesEvent extends RetailcrmAbstractEvent implements Retail
|
||||
$shops = $this->getShops();
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||
RetailcrmContextSwitcher::setShopContext((int) $shop['id_shop']);
|
||||
|
||||
if (!Configuration::get(RetailCRM::ENABLE_BALANCES_RECEIVING)) {
|
||||
RetailcrmLogger::writeDebug(
|
||||
|
@ -54,7 +54,7 @@ class RetailcrmSyncEvent extends RetailcrmAbstractEvent implements RetailcrmEven
|
||||
$shops = $this->getShops();
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||
RetailcrmContextSwitcher::setShopContext((int) $shop['id_shop']);
|
||||
|
||||
if (!Configuration::get(RetailCRM::ENABLE_HISTORY_UPLOADS)) {
|
||||
RetailcrmLogger::writeDebug(
|
||||
|
@ -54,7 +54,7 @@ class RetailcrmUpdateSinceIdEvent extends RetailcrmAbstractEvent implements Reta
|
||||
$shops = $this->getShops();
|
||||
|
||||
foreach ($shops as $shop) {
|
||||
RetailcrmContextSwitcher::setShopContext((int) ($shop['id_shop']));
|
||||
RetailcrmContextSwitcher::setShopContext((int) $shop['id_shop']);
|
||||
|
||||
$api = RetailcrmTools::getApiClient();
|
||||
|
||||
|
@ -48,7 +48,7 @@ require_once dirname(__FILE__) . '/bootstrap.php';
|
||||
|
||||
class RetailCRM extends Module
|
||||
{
|
||||
const VERSION = '3.4.8';
|
||||
const VERSION = '3.4.9';
|
||||
|
||||
const API_URL = 'RETAILCRM_ADDRESS';
|
||||
const API_KEY = 'RETAILCRM_API_TOKEN';
|
||||
|
Loading…
x
Reference in New Issue
Block a user