70 lines
2.4 KiB
PHP
70 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use DB;
|
|
|
|
class FormproductController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
$this->_service = 'form';
|
|
$this->_module = 'formproduct';
|
|
$this->_viewname = 'formproduct';
|
|
$this->_title = 'Form Products';
|
|
$this->_base_url = '/formproduct';
|
|
}
|
|
|
|
public function list(Request $request) {
|
|
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/get_all');
|
|
//echo '<pre>'; print_r($response); exit;
|
|
$fields = $this->get_list_fields();
|
|
return $this->view('list')->with([
|
|
'title' => $this->_title,
|
|
'fields' => $fields,
|
|
'base_url' => $this->_base_url,
|
|
'items' => $response->data->items,
|
|
'buttons' => $this->get_list_buttons()
|
|
]);
|
|
}
|
|
|
|
protected function get_list_fields(){
|
|
return [
|
|
'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ],
|
|
'name' => ['title' => 'Name', 'type' => 'text'],
|
|
'code' => ['title' => 'Code', 'type' => 'text'],
|
|
'status' => ['title' => 'Status', 'type' => 'select'],
|
|
];
|
|
}
|
|
|
|
protected function get_form_fields($type, $values){
|
|
$groups = $this->getlambda('get', 'ums', 'group', 'dropdown');
|
|
$groups_dd = [];
|
|
foreach($groups->data->items as $group){
|
|
$groups_dd[$group->id] = $group->name;
|
|
}
|
|
return [
|
|
'name' => ['title' => 'Name', 'type' => 'text', 'required' => true],
|
|
'code' => ['title' => 'Code', 'type' => 'text', 'required' => true],
|
|
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
|
|
'skus' => ['title' => 'Skus', 'type' => 'mapping', 'fullwidth' => true ],
|
|
];
|
|
}
|
|
|
|
protected function _beforesave($type, $request) {
|
|
$data = $request->except('_token');
|
|
$skus = [];
|
|
foreach ($data['sku_name'] as $k => $v) {
|
|
$skus[] = ['name' => $v, 'code' => $data['sku_code'][$k], 'competitors' => explode(',', $data['sku_competitors'][$k] ) ];
|
|
}
|
|
unset($data['sku_name']);
|
|
unset($data['sku_code']);
|
|
unset($data['sku_competitors']);
|
|
$data['skus'] = $skus;
|
|
return $data;
|
|
}
|
|
|
|
}
|