Commit 35e3bad9 by Angel MAS

variables extras

parent 8688b994
...@@ -9,7 +9,8 @@ use Yajra\Datatables\Datatables; ...@@ -9,7 +9,8 @@ use Yajra\Datatables\Datatables;
use Onestartup\Shop\Model\ProductCategoryShop as Category; use Onestartup\Shop\Model\ProductCategoryShop as Category;
use Onestartup\Shop\Model\ProductImageShop as Gallery; use Onestartup\Shop\Model\ProductImageShop as Gallery;
use Onestartup\Shop\Model\ProductShop as Product; use Onestartup\Shop\Model\ProductShop as Product;
//use Onestartup\Shop\Model\VariableShop; use Onestartup\Shop\Model\ExtraField as Extra;
class AdminProductController extends Controller class AdminProductController extends Controller
{ {
...@@ -25,11 +26,11 @@ class AdminProductController extends Controller ...@@ -25,11 +26,11 @@ class AdminProductController extends Controller
public function create() public function create()
{ {
$categories = Category::pluck('name', 'id'); $categories = Category::pluck('name', 'id');
//$variable = Variable::first(); $extras = Extra::where('active', true)->orderBy('variable', 'asc')->get();
return view('shop::product.create') return view('shop::product.create')
->with('categories', $categories); ->with('categories', $categories)
//->with('variable', $variable); ->with('extras', $extras);
} }
/** /**
...@@ -69,11 +70,13 @@ class AdminProductController extends Controller ...@@ -69,11 +70,13 @@ class AdminProductController extends Controller
{ {
$product = Product::find($id); $product = Product::find($id);
$categories = Category::pluck('name', 'id'); $categories = Category::pluck('name', 'id');
$extras = Extra::where('active', true)->orderBy('variable', 'asc')->get();
return view('shop::product.edit') return view('shop::product.edit')
->with('categories', $categories) ->with('categories', $categories)
->with('product', $product); ->with('product', $product)
->with('extras', $extras);
} }
/** /**
......
<?php
namespace Onestartup\Shop\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Yajra\Datatables\Datatables;
use Onestartup\Shop\Model\ExtraField as Extra;
class ExtraFieldController extends Controller
{
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
$extras = Extra::paginate(10);
$variables = [
'extra1'=>'Extra 1',
'extra2'=>'Extra 2',
'extra3'=>'Extra 3',
'extra4'=>'Extra 4',
'extra5'=>'Extra 5',
'extra6'=>'Extra 6',
'extra7'=>'Extra 7',
'extra8'=>'Extra 8',
'extra9'=>'Extra 9',
'extra10'=>'Extra 10'
];
return view('shop::extra.index')
->with('variables', $variables)
->with('extras', $extras);
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//$values = implode(",", $request->values);
//return array_combine( explode(",", $values), explode(",", $values));
$extra = Extra::where('variable', $request->variable)->first();
if ($extra != null) {
return redirect()
->back()
->withInput()
->with('message_warning', "No se pudo agregar el registro: La variable $request->variable ya existe");
}
$extra = new Extra($request->all());
if ($request->type == 'select') {
if ($request->values != null) {
$extra->values = implode(",", $request->values);
} else {
return redirect()
->back()
->withInput()
->with('message_warning', 'No agregaste los valores para el select');
}
}
$extra->save();
return redirect()
->back()
->with('message_success', 'Categoria añadida correctamente');
}
/**
* Show the form for editing the specified resource.
* @return Response
*/
public function edit($id)
{
$extra = Extra::find($id);
$variables = [
'extra1'=>'Extra 1',
'extra2'=>'Extra 2',
'extra3'=>'Extra 3',
'extra4'=>'Extra 4',
'extra5'=>'Extra 5',
'extra6'=>'Extra 6',
'extra7'=>'Extra 7',
'extra8'=>'Extra 8',
'extra9'=>'Extra 9',
'extra10'=>'Extra 10'
];
return view('shop::extra.edit')
->with('extra', $extra)
->with('variables', $variables);
}
/**
* Update the specified resource in storage.
* @param Request $request
* @return Response
*/
public function update(Request $request, $id)
{
$extra = Extra::find($id);
$extra->fill($request->all());
if ($request->type == 'select') {
if ($request->values != null) {
$extra->values = implode(",", $request->values);
} else {
return redirect()
->back()
->withInput()
->with('message_warning', 'No agregaste los valores para el select');
}
}
$extra->save();
return redirect()
->back()
->with('message_success', 'Variable actualizado correctamente');
}
/**
* Remove the specified resource from storage.
* @return Response
*/
public function destroy($id)
{
$extra = Extra::find($id);
$extra->delete();
return redirect()
->back()
->with('message_danger', 'Variable eliminada correctamente');
}
public function deleteCover($id)
{
$category = Category::find($id);
$category->cover = null;
$category->save();
return redirect()
->back()
->with('message_success', 'Imagen eliminada correctamente');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateExtraFieldsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('extra_fields', function (Blueprint $table) {
$table->increments('id');
$table->string('variable');
$table->string('alias');
$table->string('type');
$table->text('values')->nullable();
$table->boolean('active')->default(true);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('extra_fields');
}
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class ExtraField extends Model
{
protected $table = 'extra_fields';
protected $fillable = ['variable', 'alias', 'type', 'values', 'active'];
}
...@@ -5,6 +5,8 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){ ...@@ -5,6 +5,8 @@ Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
Route::resource('admin/shop/product', 'Onestartup\Shop\Controller\AdminProductController', ['as'=>'admin.shop']); Route::resource('admin/shop/product', 'Onestartup\Shop\Controller\AdminProductController', ['as'=>'admin.shop']);
Route::resource('admin/shop/category', 'Onestartup\Shop\Controller\CategoryController', ['as'=>'admin.shop']); Route::resource('admin/shop/category', 'Onestartup\Shop\Controller\CategoryController', ['as'=>'admin.shop']);
Route::resource('admin/shop/extra-fields', 'Onestartup\Shop\Controller\ExtraFieldController', ['as'=>'admin.shop']);
Route::delete('admin-shop-category/delete/cover{id}', Route::delete('admin-shop-category/delete/cover{id}',
'Onestartup\Shop\Controller\CategoryController@deleteCover') 'Onestartup\Shop\Controller\CategoryController@deleteCover')
->name('admin-shop-category.delete.cover'); ->name('admin-shop-category.delete.cover');
......
@extends('crm-admin::main-layout')
@section('content')
<div class='row'>
<div class='col-md-12'>
<div class='box'>
<div class='box-header dark'>
<h2>Actualizar información</h2>
</div>
<div class='box-body'>
<div class='col-md-12'>
{!! Form::model($extra,['route'=> ['admin.shop.extra-fields.update',$extra->id],"method"=>"PUT", 'enctype'=>'multipart/form-data']) !!}
@include('shop::extra.fields')
</div>
</div>
<div class='dker p-a text-right'>
<div class='col-md-12'>
<a class='btn danger' href="{{route('admin.shop.extra-fields.index')}}">Cancelar</a>
{!! Form::submit('Actualizar información', ['class'=>'btn dark']) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
@endsection
<div class="form-group">
{!! Form::label('variable', 'Variable') !!}
{!! Form::select('variable', $variables, null, ["class"=>"form-control", "required"=>"required", "placeholder"=>"Elija una variable"]) !!}
</div>
<div class="form-group">
{!! Form::label('alias', 'Etiqueta de la variable') !!}
{!! Form::text('alias', null, ["class"=>"form-control", "required"=>"required", "placeholder"=>"Ej. Tipo de producto"]) !!}
</div>
<div class="form-group">
{!! Form::label('type', 'Tipo de input') !!}
{!! Form::select('type', ['text'=>'Texto', 'select'=>'Select', 'textarea'=>'TextArea'], null, ["class"=>"form-control", "required"=>"required", "placeholder"=>"Elija un tipo", "id"=>"type"]) !!}
</div>
<div class="form-group" id="select-values" style="display: none;">
{!! Form::label('values', 'Valores del select: ', ['class'=>'control-label'])!!}
{{ isset($extra->values) ? $extra->values : null }}
{!! Form::select('values[]', [], isset($extra->values) ? explode(",",$extra->values) : null, ["id"=>"values", "multiple"=>"multiple", "style"=>"width:100%;"]) !!}
</div>
<div class="form-group">
{!! Form::label('active', 'Estado') !!}
{!! Form::select('active', [true=>'Activo', false=>'Inactivo'], null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
@section('script_extras')
<script>
$(function() {
$('#values').select2({
tags: true
});
$('#type').on('change', function() {
if (this.value == 'select') {
$("#select-values").show();
} else {
$("#values option:selected").each(function(){
$(this).remove();
});
$("#select-values").hide();
}
})
if($("#type").val() == "select"){
$("#select-values").show();
} else {
$("#select-values").hide();
}
});
</script>
@endsection
\ No newline at end of file
@extends('crm-admin::main-layout')
@section('content')
<div class='row'>
<div class='col-md-12 collapse' id='agregarCategoria'>
<div class='box'>
<div class='box-header dark'>
<h2>
Agregar campos extras
<span></span>
<a aria-expanded='false' class='btn btn-xs btn-danger button-ml' data-toggle='collapse' href='#agregarCategoria'>
Cancelar
</a>
</h2>
</div>
<div class='box-body'>
<div class='col-md-12'>
{!! Form::open(['route'=> 'admin.shop.extra-fields.store','method'=>'POST', 'enctype'=>'multipart/form-data']) !!}
@include('shop::extra.fields')
<div class='form-group'>
<button class='btn btn-primary' type='submit'>
Registrar
</button>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<div class='col-md-12'>
<div class='box'>
<div class='box-header dark'>
<h2>
Listado de campos extras
<span>
<a aria-expanded='false' class='btn btn-xs btn-info button-ml' data-toggle='collapse' href='#agregarCategoria'>
<i class='fas fa-plus'></i>
Agregar campos extras
</a>
</span>
</h2>
</div>
<div class='box-body'>
<div class='col-md-12'>
<table class='table'>
<tr>
<th>#</th>
<th>Informacion</th>
<th>Valores</th>
<th></th>
</tr>
@foreach ($extras as $extra)
<tr>
<td> {{$extra->id}}</td>
<td>
Variable: <b>{{$extra->variable}}</b><br>
Etiqueta: <b>{{$extra->alias}}</b><br>
Tipo: <b>{{$extra->type}}</b><br>
Estatus: <b>{{$extra->active ? "Activo" : "Inactivo"}}</b>
</td>
<td> Opciones: <br><b>{{$extra->values != null ? $extra->values : "No aplica"}}</b></td>
<td>
{!! Form::open(['route'=> ['admin.shop.extra-fields.destroy',$extra->id],'method'=>'DELETE'])!!}
<button class='btn btn-danger btn-xs button-mb' onclick="return confirm('¿Estás seguro de eliminar este elemento?');" type='submit'>
<i class='fas fa-trash-alt icon-special-size'></i>
Eliminar
</button>
{!! Form::close()!!}
<a class='btn btn-xs accent' href="{{route('admin.shop.extra-fields.edit', $extra->id)}}">
<i class='fas fa-edit icon-special-size'></i>
Editar
</a>
</td>
@endforeach
</tr>
</table>
</div>
</div>
<div class='dker p-a text-right'>
{{ $extras->links() }}
</div>
</div>
</div>
</div>
@endsection
...@@ -42,4 +42,17 @@ ...@@ -42,4 +42,17 @@
dateFormat: "yy-mm-dd" dateFormat: "yy-mm-dd"
}); });
</script> </script>
@if($extras->count() > 0)
@foreach($extras as $extra)
@if($extra->type == 'textarea')
<script type="text/javascript">
CKEDITOR.replace({{$extra->variable}}, options);
</script>
@endif
@endforeach
@endif
@endsection @endsection
...@@ -161,4 +161,16 @@ ...@@ -161,4 +161,16 @@
</script> </script>
@if($extras->count() > 0)
@foreach($extras as $extra)
@if($extra->type == 'textarea')
<script type="text/javascript">
CKEDITOR.replace({{$extra->variable}}, options);
</script>
@endif
@endforeach
@endif
@endsection @endsection
...@@ -57,97 +57,36 @@ ...@@ -57,97 +57,36 @@
</div> </div>
<div class="row"> <div class="row">
@if(isset($variable)) @if($extras->count() > 0)
@if($variable->alias1 != null) @foreach($extras as $extra)
<div class="col-md-4"> @if($extra->type == 'select')
<div class="form-group"> <div class="col-md-4">
{!! Form::label('extra1', $variable->alias1, ['class'=>'control-label'])!!} <div class="form-group">
{!! Form::text('extra1', null, ["class"=>"form-control"]) !!} {!! Form::label($extra->variable, $extra->alias, ['class'=>'control-label'])!!}
</div> {!! Form::select($extra->variable, array_combine( explode(",", $extra->values), explode(",", $extra->values)), null, ["class"=>"form-control"]) !!}
</div> </div>
@endif </div>
@endif
@if($variable->alias2 != null)
<div class="col-md-4"> @if($extra->type == 'text')
<div class="form-group"> <div class="col-md-4">
{!! Form::label('extra2', $variable->alias2, ['class'=>'control-label'])!!} <div class="form-group">
{!! Form::text('extra2', null, ["class"=>"form-control"]) !!} {!! Form::label($extra->variable, $extra->alias, ['class'=>'control-label'])!!}
</div> {!! Form::text($extra->variable, null, ["class"=>"form-control"]) !!}
</div> </div>
@endif </div>
@endif
@if($variable->alias3 != null)
<div class="col-md-4"> @if($extra->type == 'textarea')
<div class="form-group"> <div class="col-md-4">
{!! Form::label('extra3', $variable->alias3, ['class'=>'control-label'])!!} <div class="form-group">
{!! Form::text('extra3', null, ["class"=>"form-control"]) !!} {!! Form::label($extra->variable, $extra->alias, ['class'=>'control-label'])!!}
</div> {!! Form::textarea($extra->variable, null, ["class"=>"form-control"]) !!}
</div> </div>
@endif </div>
@endif
@if($variable->alias4 != null) @endforeach
<div class="col-md-4">
<div class="form-group">
{!! Form::label('extra4', $variable->alias4, ['class'=>'control-label'])!!}
{!! Form::text('extra4', null, ["class"=>"form-control"]) !!}
</div>
</div>
@endif
@if($variable->alias5 != null)
<div class="col-md-4">
<div class="form-group">
{!! Form::label('extra5', $variable->alias5, ['class'=>'control-label'])!!}
{!! Form::text('extra5', null, ["class"=>"form-control"]) !!}
</div>
</div>
@endif
@if($variable->alias6 != null)
<div class="col-md-4">
<div class="form-group">
{!! Form::label('extra6', $variable->alias6, ['class'=>'control-label'])!!}
{!! Form::text('extra6', null, ["class"=>"form-control"]) !!}
</div>
</div>
@endif
@if($variable->alias7 != null)
<div class="col-md-4">
<div class="form-group">
{!! Form::label('extra7', $variable->alias7, ['class'=>'control-label'])!!}
{!! Form::text('extra7', null, ["class"=>"form-control"]) !!}
</div>
</div>
@endif
@if($variable->alias8 != null)
<div class="col-md-4">
<div class="form-group">
{!! Form::label('extra8', $variable->alias8, ['class'=>'control-label'])!!}
{!! Form::text('extra8', null, ["class"=>"form-control"]) !!}
</div>
</div>
@endif
@if($variable->alias9 != null)
<div class="col-md-4">
<div class="form-group">
{!! Form::label('extra9', $variable->alias9, ['class'=>'control-label'])!!}
{!! Form::text('extra9', null, ["class"=>"form-control"]) !!}
</div>
</div>
@endif
@if($variable->alias10 != null)
<div class="col-md-4">
<div class="form-group">
{!! Form::label('extra10', $variable->alias10, ['class'=>'control-label'])!!}
{!! Form::text('extra10', null, ["class"=>"form-control"]) !!}
</div>
</div>
@endif
@endif @endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment