Commit 4e939bd5 by Angel MAS

Merge branch 'master' of bunkrbit.com:bsabbath/onestartup-shop

parents b9083438 17cb5a0c
......@@ -3,6 +3,9 @@ return [
"slug-shop" => "tienda",
"billing_enabled"=>false,
"slug-shop-category" => "categoria",
"tags-enable" => false,
"subcategory-enable" => false,
"version-minima-enable" => true,
"product-index" => [
"pagination" => 15,
"otros" => 3
......
......@@ -95,7 +95,7 @@ public function add(Product $product)
\Session::put('cart', $cart);
return redirect()->route('cart.show');
return redirect()->back();
}
......@@ -186,7 +186,7 @@ public function shipping()
->with('shipping', $shipping);
}
public function storeClient(RequestClient $request)
public function storeClient(Client $request)
{
$client = new Client();
$addres = new Addres();
......
......@@ -7,6 +7,8 @@ use App\Http\Controllers\Controller;
use Onestartup\Shop\Model\ProductCategoryShop as Category;
use Onestartup\Shop\Model\ProductSubCategoryShop as SubCategory;
use Onestartup\Shop\Model\ProductShop as Product;
use Onestartup\Shop\Requests\RequestSubCategory;
......@@ -18,8 +20,9 @@ class SubCategoryController extends Controller{
return $subcategories = $category->subcategories()->get();
}
$subcategories = $category->subcategories()->paginate(30);
$products = Product::pluck('name', 'id');
return view("shop::subcategory.index")
->with("products", $products)
->with("subcategories", $subcategories)
->with("category", $category);
}
......@@ -27,8 +30,10 @@ class SubCategoryController extends Controller{
public function edit($category_id, $id){
$category = Category::find($category_id);
$subcategory = SubCategory::where("category_id", $category_id)->find($id);
$products = Product::pluck('name', 'id');
return view("shop::subcategory.edit")
->with('products', $products)
->with("subcategory", $subcategory)
->with("category", $category);
}
......@@ -37,6 +42,8 @@ class SubCategoryController extends Controller{
$subcategory = new SubCategory($request->all());
$subcategory->category_id = $category_id;
$subcategory->save();
$subcategory->related_products()->sync($request->related_products);
if (isset($request->portada)) {
$file = $request->file('portada');
......@@ -59,6 +66,7 @@ class SubCategoryController extends Controller{
$subcategory = SubCategory::where("category_id", $category_id)->find($id);
$subcategory->fill($request->all());
$subcategory->save();
$subcategory->related_products()->sync($request->related_products);
if (isset($request->portada) && $request->portada != null ) {
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRelatedProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('related_products', function (Blueprint $table) {
$table->increments('id');
$table->integer('product_id')->unsigned();
$table->foreign('product_id')
->references('id')
->on('products_shop')
->onDelete('cascade');
$table->integer('subcategory_id')->unsigned();
$table->foreign('subcategory_id')
->references('id')
->on('product_subcategories_shop')
->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('related_products');
}
}
......@@ -19,6 +19,7 @@ class ProductShop extends Model
'active',
'publication_date',
'category_id',
'subcategory_id',
'category_sat_id',
'cover',
'extra1',
......@@ -66,4 +67,13 @@ class ProductShop extends Model
public function tags(){
return $this->belongsToMany('Onestartup\Shop\Model\ProductTag', 'product_product_tags', 'product_id', 'tag_id');
}
public function subcategories_related(){
return $this->belongsToMany('Onestartup\Shop\Model\ProductSubCategoryShop', 'related_products', 'product_id', 'subcategory_id');
}
public function details_sale()
{
return $this->hasMany('Onestartup\Shop\Model\DetailShop', 'product_id');
}
}
......@@ -24,4 +24,8 @@ class ProductSubCategoryShop extends Model
public function products(){
return $this->hasMany('Onestartup\Shop\Model\ProductShop', 'subcategory_id');
}
public function related_products(){
return $this->belongsToMany('Onestartup\Shop\Model\ProductShop', 'related_products', 'subcategory_id', 'product_id');
}
}
<?php
namespace Onestartup\Shop\Model;
use Illuminate\Database\Eloquent\Model;
class RelatedProducts extends Model
{
protected $table = 'related_products';
protected $fillable = ["product_id", "subcategory_id"];
public function products(){
return $this->belongsToMany('Onestartup\Shop\Model\ProductShop', 'product_id');
}
public function subcategories(){
return $this->hasMany('Onestartup\Shop\Model\ProductSubCategoryShop', 'subcategory_id');
}
}
......@@ -7,18 +7,17 @@
{!! Form::label('slug', 'URL Slug *') !!}
{!! Form::text('slug', null, ["class"=>"form-control", "required"=>"required", "placeholder"=>"Coloque aquí la liga o URL de la categoría", "id"=>"second"]) !!}
</div>
@if(config("shop.version-minima-enable") == false)
<div class="form-group">
{!! Form::label('description', 'Resumen') !!}
{!! Form::text('description', null, ["class"=>"form-control", "placeholder"=>"Coloque la información descriptiva de la categoría"]) !!}
</div>
@endif
<div class="form-group">
{!! Form::label('active', 'Estado') !!}
{!! Form::select('active', [true=>'Activo', false=>'Inactivo'], null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
@if(config("shop.version-minima-enable") == false)
<div class="form-group">
{!! Form::label('portada', 'Imagén de portada') !!}
@if (isset($category))
......@@ -31,4 +30,5 @@
@endif
<br>
{!! Form::file('portada', null, ["class"=>"form-control"]) !!}
</div>
\ No newline at end of file
</div>
@endif
\ No newline at end of file
......@@ -58,7 +58,9 @@
<th>Categoría</th>
<th>Descripción</th>
<th>Productos</th>
<th>Subcategorias</th>
@if(config("shop.subcategory-enable"))
<th>Subcategorias</th>
@endif
<th></th>
</tr>
@foreach ($categories as $category)
......@@ -73,12 +75,16 @@
</td>
<td> {{$category->description}}</td>
<td class="text-center"> {{$category->products->count()}}</td>
<td class="text-center"> {{$category->subcategories->count()}}</td>
@if(config("shop.subcategory-enable"))
<td class="text-center"> {{$category->subcategories->count()}}</td>
@endif
<td class="text-center">
<a class='btn btn-xs btn-success button-mb' href="{{route('admin.shop.subcategory.index', $category->id)}}">
<i class='fas fa-plus icon-special-size'></i>
Subcategorías
</a>
@if(config("shop.subcategory-enable"))
<a class='btn btn-xs btn-success button-mb' href="{{route('admin.shop.subcategory.index', $category->id)}}">
<i class='fas fa-plus icon-special-size'></i>
Subcategorías
</a>
@endif
{!! Form::open(['route'=> ['admin.shop.category.destroy',$category->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>
......
......@@ -24,8 +24,10 @@
</div>
<div class='col-md-6'>
<div class="form-group" >
{!! Form::label('category_id', 'Categoría', ['class'=>'control-label'])!!}
{!! Form::select('category_id', $categories, null, ["class"=>"form-control", "required"=>"required"]) !!}
{!! Form::label('publication_date', 'Fecha de publicación', ['class'=>'control-label'])!!}
{!! Form::text('publication_date', isset($product) ? null: date('Y-m-d'), ["class"=>"form-control", "required"=>"required", "id"=>"publication_date"]) !!}
</div>
</div>
</div>
......@@ -48,25 +50,29 @@
</div>
<div class="col-md-6">
<div class="form-group" >
{!! Form::label('subcategory_id', 'Subcategoría', ['class'=>'control-label'])!!}
{!! Form::select('subcategory_id', $subcategories, null, ["class"=>"form-control", "placeholder"=>"Selecciona una subcategoría"]) !!}
{!! Form::label('category_id', 'Categoría', ['class'=>'control-label'])!!}
{!! Form::select('category_id', $categories, null, ["class"=>"form-control", "required"=>"required"]) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
{!! Form::label('publication_date', 'Fecha de publicación', ['class'=>'control-label'])!!}
{!! Form::text('publication_date', isset($product) ? null: date('Y-m-d'), ["class"=>"form-control", "required"=>"required", "id"=>"publication_date"]) !!}
@if(config("shop.tags-enable"))
<div class="col-md-6">
<div class="form-group">
{!! Form::label('tags', 'Etiquetas', ['class'=>'control-label'])!!}
{!! Form::select('tags[]', $tags, null, ["class"=>"form-control", "id"=>"tags", "multiple"=>"multiple"]) !!}
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
{!! Form::label('tags', 'Etiquetas', ['class'=>'control-label'])!!}
{!! Form::select('tags[]', $tags, null, ["class"=>"form-control", "id"=>"tags", "multiple"=>"multiple"]) !!}
@endif
@if(config("shop.subcategory-enable"))
<div class="col-md-6">
<div class="form-group">
{!! Form::label('subcategory_id', 'Subcategoría', ['class'=>'control-label'])!!}
{!! Form::select('subcategory_id', $subcategories, null, ["class"=>"form-control", "placeholder"=>"Selecciona una subcategoría"]) !!}
</div>
</div>
</div>
@endif
</div>
......@@ -116,7 +122,7 @@
@endif
</div>
@if(config("shop.version-minima-enable") == false)
<div class="row">
<div class="col-md-6">
{!! Form::label('description', 'Descripción', ['class'=>'control-label'])!!}
......@@ -134,5 +140,14 @@
{!! Form::textarea('specifications', null, ["class"=>"form-control", "required"=>"required", 'id'=>'body', 'rows'=>"30", 'cols'=>"80"]) !!}
</div>
</div>
@endif
@if(config("shop.version-minima-enable"))
<div class="row">
<div class="col-md-12">
{!! Form::label('description', 'Descripción', ['class'=>'control-label'])!!}
{!! Form::textarea('description', null, ["class"=>"form-control", "required"=>"required", 'id'=>'body', 'rows'=>"30", 'cols'=>"80"]) !!}
</div>
</div>
@endif
......@@ -32,8 +32,10 @@
<th>#</th>
<th>Producto</th>
<th>Descripción</th>
<th>Características</th>
<th>Especificaciones</th>
@if(config("shop.version-minima-enable") == false)
<th>Características</th>
<th>Especificaciones</th>
@endif
<th></th>
</tr>
</thead>
......@@ -56,8 +58,10 @@
{data: 'id', name: 'id'},
{data: 'main', name: 'main'},
{data: 'description', name: 'description'},
{data: 'features', name: 'features'},
@if(config("shop.version-minima-enable") == false)
{data: 'features', name: 'features'},
{data: 'specifications', name: 'specifications'},
@endif
{data: 'form', name: 'form'},
]
});
......
......@@ -35,7 +35,7 @@
</div>
<div class='dker p-a text-right'>
<div class='col-md-12'>
<a class='btn danger' href="{{route('admin.product.subcategory.index', $category->id)}}">Cancelar</a>
<a class='btn danger' href="{{route('admin.shop.subcategory.index', $category->id)}}">Cancelar</a>
{!! Form::submit('Actualizar información', ['class'=>'btn dark']) !!}
{!! Form::close() !!}
</div>
......@@ -71,3 +71,9 @@
</div>
</div>
@endsection
@section('script_extras')
<script>
$('#related_products').select2();
</script>
@endsection
......@@ -20,6 +20,11 @@
</div>
<div class="form-group">
{!! Form::label('related_products', 'Productos relacionados') !!}
{!! Form::select('related_products[]', $products, null, ["class"=>"form-control", "required"=>"required", "multiple" => "multiple", "id" => "related_products", "style" => "width: 100%;"]) !!}
</div>
<div class="form-group">
{!! Form::label('portada', 'Imagén de portada') !!}
@if (isset($subcategory))
<span>
......
......@@ -100,4 +100,10 @@
</div>
</div>
</div>
@endsection
@section('script_extras')
<script>
$('#related_products').select2();
</script>
@endsection
\ No newline at end of file
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