Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
samberrry committed Jan 9, 2023
2 parents e993082 + 9cbd011 commit 0d086a7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions binshopsrest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public function hookactionDispatcherBefore($controller)
'message' => 'This endpoint is not defined.',
'code' => 410
]);
die;
}

$controller = Controller::getController($controller_class);
Expand Down
78 changes: 78 additions & 0 deletions override/classes/controller/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

abstract class Controller extends ControllerCore
{
public function restRun(){
header('Content-Type: ' . "application/json");
if (Tools::getValue('iso_currency')){
$_GET['id_currency'] = (string)Currency::getIdByIsoCode(Tools::getValue('currency'));
$_GET['SubmitCurrency'] = "1";
}

parent::init();

$response = [
'success' => true,
'code' => 210,
'psdata' => null,
'message' => 'empty'
];

switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
$response = $this->processGetRequest();
break;
case 'POST':
$response = $this->processPostRequest();
break;
case 'PATCH':
case 'PUT':
$response = $this->processPutRequest();
break;
case 'DELETE':
$response = $this->processDeleteRequest();
break;
default:
// throw some error or whatever
}

$this->ajaxRender(json_encode($response));
die;
}

protected function processGetRequest(){
return [
'success' => true,
'code' => 310,
'psdata' => null,
'message' => $this->trans('GET not supported on this path', [], 'Modules.Binshopsrest.Admin'),
];
}

protected function processPostRequest(){
return [
'success' => true,
'code' => 310,
'psdata' => null,
'message' => $this->trans('POST not supported on this path', [], 'Modules.Binshopsrest.Admin'),
];
}

protected function processPutRequest(){
return [
'success' => true,
'code' => 310,
'psdata' => null,
'message' => $this->trans('PUT not supported on this path', [], 'Modules.Binshopsrest.Admin'),
];
}

protected function processDeleteRequest(){
return [
'success' => true,
'code' => 310,
'psdata' => null,
'message' => $this->trans('DELETE not supported on this path', [], 'Modules.Binshopsrest.Admin'),
];
}
}

0 comments on commit 0d086a7

Please sign in to comment.