Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
onestartup-shop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Angel Martin
onestartup-shop
Commits
f6da2f63
Commit
f6da2f63
authored
Sep 20, 2018
by
Francisco Salazar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
productos relacionados a subcategorias
parent
93d8203d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
98 additions
and
1 deletions
+98
-1
SubCategoryController.php
src/controllers/SubCategoryController.php
+9
-1
2018_09_20_004720_create_related_products_table.php
...tions/2018_09_20_004720_create_related_products_table.php
+44
-0
ProductShop.php
src/models/ProductShop.php
+4
-0
ProductSubCategoryShop.php
src/models/ProductSubCategoryShop.php
+4
-0
RelatedProducts.php
src/models/RelatedProducts.php
+19
-0
edit.blade.php
src/views/subcategory/edit.blade.php
+6
-0
fields.blade.php
src/views/subcategory/fields.blade.php
+5
-0
index.blade.php
src/views/subcategory/index.blade.php
+7
-0
No files found.
src/controllers/SubCategoryController.php
View file @
f6da2f63
...
...
@@ -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
)
{
...
...
src/migrations/2018_09_20_004720_create_related_products_table.php
0 → 100644
View file @
f6da2f63
<?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'
);
}
}
src/models/ProductShop.php
View file @
f6da2f63
...
...
@@ -66,4 +66,8 @@ 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'
);
}
}
src/models/ProductSubCategoryShop.php
View file @
f6da2f63
...
...
@@ -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'
);
}
}
src/models/RelatedProducts.php
0 → 100644
View file @
f6da2f63
<?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'
);
}
}
src/views/subcategory/edit.blade.php
View file @
f6da2f63
...
...
@@ -71,3 +71,9 @@
</div>
</div>
@endsection
@section('script_extras')
<script>
$('#related_products').select2();
</script>
@endsection
src/views/subcategory/fields.blade.php
View file @
f6da2f63
...
...
@@ -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>
...
...
src/views/subcategory/index.blade.php
View file @
f6da2f63
...
...
@@ -100,4 +100,10 @@
</div>
</div>
</div>
@endsection
@section('script_extras')
<script>
$('#related_products').select2();
</script>
@endsection
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment