* @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 RetailcrmOrdersUploadController extends RetailcrmAdminAbstractController { private $api; public function __construct() { parent::__construct(); $this->api = RetailcrmTools::getApiClient(); } public function postProcess() { $this->ajaxDie(json_encode($this->getData())); } protected function getData() { if (!($this->api instanceof RetailcrmProxy)) { return [ 'success' => false, 'errorMsg' => "Can't upload orders - set API key and API URL first!", ]; } $orderIds = Tools::getValue('orders'); try { $isSuccessful = true; $skippedOrders = []; $uploadedOrders = []; $errors = []; RetailcrmExport::$api = $this->api; foreach ($orderIds as $orderId) { $id_order = (int) $orderId; $response = false; try { $response = RetailcrmExport::exportOrder($id_order); if ($response) { $uploadedOrders[] = $id_order; } } catch (PrestaShopObjectNotFoundExceptionCore $e) { $skippedOrders[] = $id_order; } catch (Exception $e) { $errors[$id_order][] = $e->getMessage(); } $isSuccessful = $isSuccessful ? $response : false; time_nanosleep(0, 50000000); } return [ 'success' => $isSuccessful, 'uploadedOrders' => $uploadedOrders, 'skippedOrders' => $skippedOrders, 'errors' => $errors, ]; } catch (Exception $e) { return [ 'success' => false, 'errorMsg' => $e->getMessage(), ]; } } }