|
| 1 | +<?php |
| 2 | + |
| 3 | +abstract class Controller extends ControllerCore |
| 4 | +{ |
| 5 | + public function restRun(){ |
| 6 | + header('Content-Type: ' . "application/json"); |
| 7 | + if (Tools::getValue('iso_currency')){ |
| 8 | + $_GET['id_currency'] = (string)Currency::getIdByIsoCode(Tools::getValue('currency')); |
| 9 | + $_GET['SubmitCurrency'] = "1"; |
| 10 | + } |
| 11 | + |
| 12 | + parent::init(); |
| 13 | + |
| 14 | + $response = [ |
| 15 | + 'success' => true, |
| 16 | + 'code' => 210, |
| 17 | + 'psdata' => null, |
| 18 | + 'message' => 'empty' |
| 19 | + ]; |
| 20 | + |
| 21 | + switch ($_SERVER['REQUEST_METHOD']) { |
| 22 | + case 'GET': |
| 23 | + $response = $this->processGetRequest(); |
| 24 | + break; |
| 25 | + case 'POST': |
| 26 | + $response = $this->processPostRequest(); |
| 27 | + break; |
| 28 | + case 'PATCH': |
| 29 | + case 'PUT': |
| 30 | + $response = $this->processPutRequest(); |
| 31 | + break; |
| 32 | + case 'DELETE': |
| 33 | + $response = $this->processDeleteRequest(); |
| 34 | + break; |
| 35 | + default: |
| 36 | + // throw some error or whatever |
| 37 | + } |
| 38 | + |
| 39 | + $this->ajaxRender(json_encode($response)); |
| 40 | + die; |
| 41 | + } |
| 42 | + |
| 43 | + protected function processGetRequest(){ |
| 44 | + return [ |
| 45 | + 'success' => true, |
| 46 | + 'code' => 310, |
| 47 | + 'psdata' => null, |
| 48 | + 'message' => $this->trans('GET not supported on this path', [], 'Modules.Binshopsrest.Admin'), |
| 49 | + ]; |
| 50 | + } |
| 51 | + |
| 52 | + protected function processPostRequest(){ |
| 53 | + return [ |
| 54 | + 'success' => true, |
| 55 | + 'code' => 310, |
| 56 | + 'psdata' => null, |
| 57 | + 'message' => $this->trans('POST not supported on this path', [], 'Modules.Binshopsrest.Admin'), |
| 58 | + ]; |
| 59 | + } |
| 60 | + |
| 61 | + protected function processPutRequest(){ |
| 62 | + return [ |
| 63 | + 'success' => true, |
| 64 | + 'code' => 310, |
| 65 | + 'psdata' => null, |
| 66 | + 'message' => $this->trans('PUT not supported on this path', [], 'Modules.Binshopsrest.Admin'), |
| 67 | + ]; |
| 68 | + } |
| 69 | + |
| 70 | + protected function processDeleteRequest(){ |
| 71 | + return [ |
| 72 | + 'success' => true, |
| 73 | + 'code' => 310, |
| 74 | + 'psdata' => null, |
| 75 | + 'message' => $this->trans('DELETE not supported on this path', [], 'Modules.Binshopsrest.Admin'), |
| 76 | + ]; |
| 77 | + } |
| 78 | +} |
0 commit comments