1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Frontend; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService; |
7
|
|
|
use Hideyo\Ecommerce\Framework\Services\Product\ProductCombinationFacade as ProductCombinationService; |
8
|
|
|
use Hideyo\Ecommerce\Framework\Services\ProductCategory\ProductCategoryFacade as ProductCategoryService; |
9
|
|
|
use Illuminate\Http\Request; |
10
|
|
|
|
11
|
|
|
class ProductCategoryController extends Controller |
12
|
|
|
{ |
13
|
|
|
public function getItem(Request $request, $slug) |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
$category = ProductCategoryService::selectOneByShopIdAndSlug(config()->get('app.shop_id'), $slug); |
16
|
|
|
|
17
|
|
|
if ($category) { |
18
|
|
|
|
19
|
|
|
if ($category->refProductCategory) { |
20
|
|
|
return redirect()->to($category->refProductCategory->slug); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
if ($category->ancestors()->count()) { |
24
|
|
|
//$request->session()->put('category_id', $category->ancestors()->first()->id); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$products = ""; |
28
|
|
|
if ($category->products()->count()) { |
29
|
|
|
$products = ProductService::selectAllByShopIdAndProductCategoryId(config()->get('app.shop_id'), $category['id']); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if ($category->isLeaf()) { |
33
|
|
|
if ($category->isChild()) { |
34
|
|
|
$childrenProductCategories = ProductCategoryService::selectCategoriesByParentId(config()->get('app.shop_id'), $category->parent_id); |
35
|
|
|
} else { |
36
|
|
|
$childrenProductCategories = ProductCategoryService::selectAllByShopIdAndRoot(config()->get('app.shop_id')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$attributes = ProductCombinationService::selectAllByProductCategoryId($category->id, config()->get('app.shop_id')); |
|
|
|
|
40
|
|
|
|
41
|
|
|
return view('frontend.product_category.products')->with( |
42
|
|
|
array( |
43
|
|
|
'childrenProductCategories' => $childrenProductCategories, |
44
|
|
|
'category' => $category, |
45
|
|
|
'products' => $products, |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$childrenProductCategories = ProductCategoryService::selectCategoriesByParentId(config()->get('app.shop_id'), $category->id); |
51
|
|
|
|
52
|
|
|
return view('frontend.product_category.categories')->with( |
53
|
|
|
array( |
54
|
|
|
'category' => $category, |
55
|
|
|
'childrenProductCategories' => $childrenProductCategories |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
abort(404); |
61
|
|
|
} |
62
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.