* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL * @license https://opensource.org/licenses/MIT The MIT License * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ require_once dirname(__FILE__) . '/../../bootstrap.php'; class RetailcrmExportController extends RetailcrmAdminPostAbstractController { protected function postHandler() { $api = RetailcrmTools::getApiClient(); if (empty($api)) { throw new Exception('Set API key & URL first'); } RetailcrmExport::init(); RetailcrmExport::$api = $api; RetailcrmHistory::$api = $api; if (Tools::getIsset('stepOrders')) { $skipUploaded = Tools::getIsset('skipUploaded') && 'true' === Tools::getValue('skipUploaded'); RetailcrmExport::export(Tools::getValue('stepOrders'), 'order', $skipUploaded); } elseif (Tools::getIsset('stepCustomers')) { RetailcrmExport::export(Tools::getValue('stepCustomers'), 'customer'); } elseif (Tools::getIsset('stepSinceId')) { RetailcrmHistory::updateSinceId('customers'); RetailcrmHistory::updateSinceId('orders'); } else { throw new Exception('Invalid request data'); } return RetailcrmJsonResponse::successfullResponse(); } protected function getHandler() { // todo move to helper return [ 'success' => true, 'orders' => [ 'count' => RetailcrmExport::getOrdersCount(), 'exportCount' => RetailcrmExport::getOrdersCount(true), 'exportStepSize' => RetailcrmExport::RETAILCRM_EXPORT_ORDERS_STEP_SIZE_WEB, ], 'customers' => [ 'count' => RetailcrmExport::getCustomersCount(), 'exportCount' => RetailcrmExport::getCustomersCount(false), 'exportStepSize' => RetailcrmExport::RETAILCRM_EXPORT_CUSTOMERS_STEP_SIZE_WEB, ], ]; } }