Skip to content
Snippets Groups Projects
Verified Commit 2c673cf3 authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #9107 admin shipping

parent a2516785
No related branches found
No related tags found
No related merge requests found
......@@ -53,14 +53,28 @@ class ShippingController
$shippingInfo['fee'] = (array)json_decode($shippingInfo['fee']);
$shippingInfo['entities'] = (array)json_decode($shippingInfo['entities']);
$entities = EntityModel::getAllowedEntitiesByUserId(['userId' => 'superadmin']);
foreach ($entities as $key => $entity) {
$entities[$key]['state']['selected'] = false;
if (in_array($entity['id'], $shippingInfo['entities'])) {
$entities[$key]['state']['selected'] = true;
$allEntities = EntityModel::get(['select' => ['id', 'entity_id', 'entity_label', 'parent_entity_id'], 'where' => ['enabled = ?'], 'data' => ['Y'], 'orderBy' => ['parent_entity_id']]);
foreach ($allEntities as $key => $value) {
$allEntities[$key]['id'] = $value['entity_id'];
$allEntities[$key]['serialId'] = $value['id'];
if (empty($value['parent_entity_id'])) {
$allEntities[$key]['parent'] = '#';
$allEntities[$key]['icon'] = "fa fa-building";
} else {
$allEntities[$key]['parent'] = $value['parent_entity_id'];
$allEntities[$key]['icon'] = "fa fa-sitemap";
}
$allEntities[$key]['state']['opened'] = false;
$allEntities[$key]['allowed'] = true;
if (in_array($value['id'], $shippingInfo['entities'])) {
$allEntities[$key]['state']['opened'] = true;
$allEntities[$key]['state']['selected'] = true;
}
$allEntities[$key]['text'] = $value['entity_label'];
}
$shippingInfo['entities'] = $entities;
$shippingInfo['entities'] = $allEntities;
return $response->withJson($shippingInfo);
}
......@@ -89,7 +103,7 @@ class ShippingController
$id = ShippingModel::create($body);
HistoryController::add([
'tableName' => 'shipping',
'tableName' => 'shippings',
'recordId' => $id,
'eventType' => 'ADD',
'eventId' => 'shippingadd',
......@@ -128,7 +142,7 @@ class ShippingController
ShippingModel::update($body);
HistoryController::add([
'tableName' => 'shipping',
'tableName' => 'shippings',
'recordId' => $aArgs['id'],
'eventType' => 'UP',
'eventId' => 'shippingup',
......@@ -152,7 +166,7 @@ class ShippingController
ShippingModel::delete(['id' => $aArgs['id']]);
HistoryController::add([
'tableName' => 'shipping',
'tableName' => 'shippings',
'recordId' => $aArgs['id'],
'eventType' => 'DEL',
'eventId' => 'shippingdel',
......@@ -198,7 +212,7 @@ class ShippingController
$errors[] = 'entities must be an array';
}
foreach ($aArgs['entities'] as $entity) {
$info = EntityModel::getByEntityId(['entityId' => $entity, 'select' => ['id']]);
$info = EntityModel::getById(['id' => $entity, 'select' => ['id']]);
if (empty($info)) {
$errors[] = $entity . ' does not exists';
}
......@@ -214,13 +228,26 @@ class ShippingController
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$entities = EntityModel::getAllowedEntitiesByUserId(['userId' => 'superadmin']);
foreach ($entities as $key => $entity) {
$entities[$key]['state']['selected'] = false;
$allEntities = EntityModel::get(['select' => ['id', 'entity_id', 'entity_label', 'parent_entity_id'], 'where' => ['enabled = ?'], 'data' => ['Y'], 'orderBy' => ['parent_entity_id']]);
foreach ($allEntities as $key => $value) {
$allEntities[$key]['id'] = $value['entity_id'];
$allEntities[$key]['serialId'] = $value['id'];
if (empty($value['parent_entity_id'])) {
$allEntities[$key]['parent'] = '#';
$allEntities[$key]['icon'] = "fa fa-building";
} else {
$allEntities[$key]['parent'] = $value['parent_entity_id'];
$allEntities[$key]['icon'] = "fa fa-sitemap";
}
$allEntities[$key]['state']['opened'] = false;
$allEntities[$key]['allowed'] = true;
$allEntities[$key]['state']['opened'] = true;
$allEntities[$key]['text'] = $value['entity_label'];
}
return $response->withJson([
'entities' => $entities,
'entities' => $allEntities,
]);
}
}
......@@ -28,7 +28,7 @@ class ShippingControllerTest extends TestCase
'sendMode' => 'fast'
],
'fee' => ['first_page' => 1, 'next_page' => 2, 'postage_price' => 12],
'entities' => ['COU', 'PJS'],
'entities' => [1, 2],
'account' => ['id' => 'toto', 'password' => '1234']
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment