* @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 RetailcrmReferencesController extends RetailcrmAdminPostAbstractController { protected function getHandler() { if (Tools::getIsset('delivery') || Tools::getIsset('payment') || Tools::getIsset('status')) { return $this->getSpecifiedReferences(); } return [ 'success' => true, 'references' => RetailcrmSettingsHelper::getReferences(), ]; } /** * @throws Exception */ protected function getSpecifiedReferences() { $references = []; $errors = []; $client = RetailcrmTools::getApiClient(); if (null === $client) { $errors[] = 'errors.connect'; } $moduleReferences = new RetailcrmReferences($client); switch (true) { case Tools::getIsset('delivery'): $references['deliveryTypesCRM'] = $moduleReferences->getApiDeliveryTypes(); break; case Tools::getIsset('payment'): $references['paymentTypesCRM'] = $moduleReferences->getApiPaymentTypes(); break; case Tools::getIsset('status'): $references['statusesCRM'] = $moduleReferences->getApiStatusesWithGroup(); break; default: throw new Exception('Invalid request data'); } return [ 'success' => true, 'references' => $references, 'errors' => $errors, ]; } }