|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Frontend; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService; |
|
8
|
|
|
use Hideyo\Ecommerce\Framework\Services\ProductCategory\ProductCategoryFacade as ProductCategoryService; |
|
9
|
|
|
use Hideyo\Ecommerce\Framework\Services\Product\ProductCombinationFacade as ProductCombinationService; |
|
10
|
|
|
|
|
11
|
|
|
class ProductController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
public function getIndex(Request $request, $categorySlug, $productId, $productSlug, $productAttributeId = false) |
|
14
|
|
|
{ |
|
15
|
|
|
$product = ProductService::selectOneByShopIdAndId(config()->get('app.shop_id'), $productId, $request->get('combination_id')); |
|
16
|
|
|
|
|
17
|
|
|
if ($product) { |
|
18
|
|
|
if ($product->slug != $productSlug or $product->productCategory->slug != $categorySlug) { |
|
19
|
|
|
return redirect()->route('product.item', array('productCategorySlug' => $product->productCategory->slug, 'productId' => $product->id, 'slug' => $product->slug)); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
if ($product->ProductCategory and $product->ProductCategory->parent()->count()) { |
|
23
|
|
|
$productCategories = ProductCategoryService::selectCategoriesByParentId(config()->get('app.shop_id'), $product->ProductCategory->parent()->first()->id, 'widescreen'); |
|
24
|
|
|
} else { |
|
25
|
|
|
$productCategories = ProductCategoryService::selectRootCategories(false, array('from_stock')); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
if ($product->attributes->count() AND $product->attributeGroup AND $product->attributes->first()->combinations->count()) { |
|
29
|
|
|
|
|
30
|
|
|
if ($product->attributeGroup) { |
|
31
|
|
|
$attributeLeadingGroup = $product->attributeGroup; |
|
32
|
|
|
} else { |
|
33
|
|
|
$attributeLeadingGroup = $product->attributes->first()->combinations->first()->attribute->attributeGroup; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$pullDowns = ProductCombinationService::generatePulldowns($product, $productAttributeId, $attributeLeadingGroup); |
|
37
|
|
|
$newPullDowns = $pullDowns['newPullDowns']; |
|
38
|
|
|
|
|
39
|
|
|
$productAttribute = $pullDowns['productAttribute']; |
|
40
|
|
|
$productImages = ProductService::ajaxProductImages($product, $productAttribute->combinations->pluck('attribute_id')->toArray(), $productAttribute->id); |
|
41
|
|
|
|
|
42
|
|
|
$template = 'frontend.product.combinations'; |
|
43
|
|
|
|
|
44
|
|
|
$leadingAttributeId = key(reset($newPullDowns)); |
|
45
|
|
|
if($productAttributeId) { |
|
46
|
|
|
$leadingAttributeId = $productAttributeId; |
|
47
|
|
|
} else { |
|
48
|
|
|
$productAttributeId = $pullDowns['productAttribute']->first()->id; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return view($template)->with( |
|
52
|
|
|
array( |
|
53
|
|
|
'productImages' => $productImages, |
|
54
|
|
|
'productAttributeId' => $productAttributeId, |
|
55
|
|
|
'leadAttributeId' => $leadingAttributeId, |
|
56
|
|
|
'firstPulldown' => key($newPullDowns), |
|
57
|
|
|
'newPullDowns' => $newPullDowns, |
|
58
|
|
|
'priceDetails' => $productAttribute->getPriceDetails(), |
|
59
|
|
|
'childrenProductCategories' => $productCategories, |
|
60
|
|
|
'product' => $product |
|
61
|
|
|
) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$productImages = $product->productImages; |
|
66
|
|
|
|
|
67
|
|
|
if (isset($product['ancestors'])) { |
|
68
|
|
|
$request->session()->put('category_id', $product['ancestors'][0]['id']); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$template = 'frontend.product.index'; |
|
72
|
|
|
|
|
73
|
|
|
return view($template)->with( |
|
74
|
|
|
array( |
|
75
|
|
|
'priceDetails' => $product->getPriceDetails(), |
|
76
|
|
|
'childrenProductCategories' => $productCategories, |
|
77
|
|
|
'product' => $product, |
|
78
|
|
|
'productImages' => $productImages |
|
79
|
|
|
) |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
abort(404); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getSelectLeadingPulldown($productId, $leadingAttributeId, $secondAttributeId = false) |
|
87
|
|
|
{ |
|
88
|
|
|
$product = ProductService::selectOneByShopIdAndId(config()->get('app.shop_id'), $productId, $leadingAttributeId); |
|
89
|
|
|
|
|
90
|
|
|
if ($product) { |
|
91
|
|
|
if ($product->attributes->count()) { |
|
92
|
|
|
$pullDowns = ProductCombinationService::generatePulldowns($product, $leadingAttributeId, $product->attributeGroup, $secondAttributeId); |
|
93
|
|
|
$newPullDowns = $pullDowns['newPullDowns']; |
|
94
|
|
|
$productAttribute = $pullDowns['productAttribute']; |
|
95
|
|
|
$productImages = ProductService::ajaxProductImages($product, $productAttribute->combinations->pluck('attribute_id')->toArray(), $productAttribute->id); |
|
96
|
|
|
|
|
97
|
|
|
return view('frontend.product.ajax')->with(array( |
|
98
|
|
|
'newPullDowns' => $newPullDowns, |
|
99
|
|
|
'productImages' => $productImages, |
|
100
|
|
|
'leadAttributeId' => $leadingAttributeId, |
|
101
|
|
|
'productAttributeId' => $productAttribute->id, |
|
102
|
|
|
'firstPulldown' => key($newPullDowns), |
|
103
|
|
|
'secondAttributeId' => $secondAttributeId, |
|
104
|
|
|
'priceDetails' => $productAttribute->getPriceDetails(), |
|
105
|
|
|
'product' => $product |
|
106
|
|
|
)); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
} |