|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2023 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Shop\Controller; |
|
10
|
|
|
|
|
11
|
|
|
use Aimeos\Shop\Facades\Shop; |
|
12
|
|
|
use Illuminate\Routing\Controller; |
|
13
|
|
|
use Illuminate\Support\Facades\Request; |
|
14
|
|
|
use Illuminate\Support\Facades\Response; |
|
15
|
|
|
use Illuminate\Support\Facades\Route; |
|
16
|
|
|
use Illuminate\Support\Facades\View; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Aimeos controller for dispatching requests. |
|
21
|
|
|
*/ |
|
22
|
|
|
class ResolveController extends Controller |
|
23
|
|
|
{ |
|
24
|
|
|
private static $fcn = []; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Register a new resolver function. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $name Name of the resolver function |
|
31
|
|
|
* @param \Closure $fcn Resolver function |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function register( string $name, \Closure $fcn ) |
|
34
|
|
|
{ |
|
35
|
|
|
self::$fcn[$name] = $fcn; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Initializes the object. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct() |
|
43
|
|
|
{ |
|
44
|
|
|
self::$fcn['product'] = function( \Aimeos\MShop\ContextIface $context, string $path ) { |
|
45
|
|
|
return $this->product( $context, $path ); |
|
46
|
|
|
}; |
|
47
|
|
|
|
|
48
|
|
|
self::$fcn['catalog'] = function( \Aimeos\MShop\ContextIface $context, string $path ) { |
|
49
|
|
|
return $this->catalog( $context, $path ); |
|
50
|
|
|
}; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns the html of the resolved URLs. |
|
56
|
|
|
* |
|
57
|
|
|
* @param \Illuminate\Http\Request $request Laravel request object |
|
58
|
|
|
* @return \Illuminate\Http\Response Laravel response object containing the generated output |
|
59
|
|
|
*/ |
|
60
|
|
|
public function indexAction( \Illuminate\Http\Request $request ) |
|
61
|
|
|
{ |
|
62
|
|
|
if( ( $path = $request->route( 'path', $request->input( 'path' ) ) ) === null ) { |
|
63
|
|
|
abort( 404 ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$context = app( 'aimeos.context' )->get( true ); |
|
67
|
|
|
|
|
68
|
|
|
foreach( self::$fcn as $name => $fcn ) |
|
69
|
|
|
{ |
|
70
|
|
|
try { |
|
71
|
|
|
return $fcn( $context, $path ); |
|
72
|
|
|
} catch( \Exception $e ) {} |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
abort( 404 ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Returns the category page if the give path can be resolved to a category. |
|
81
|
|
|
* |
|
82
|
|
|
* @param \Aimeos\MShop\ContextIface $context Context object |
|
83
|
|
|
* @param string $path URL path to resolve |
|
84
|
|
|
* @return Response Response object |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function catalog( \Aimeos\MShop\ContextIface $context, string $path ) : ?\Illuminate\Http\Response |
|
87
|
|
|
{ |
|
88
|
|
|
$item = \Aimeos\Controller\Frontend::create( $context, 'catalog' )->resolve( $path ); |
|
|
|
|
|
|
89
|
|
|
$view = Shop::view(); |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
$params = ( Route::current() ? Route::current()->parameters() : [] ) + Request::all(); |
|
92
|
|
|
$params += ['f_name' => $path, 'f_catid' => $item->getId(), 'page' => 'page-catalog-tree']; |
|
93
|
|
|
|
|
94
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $view, $params ); |
|
95
|
|
|
$view->addHelper( 'param', $helper ); |
|
96
|
|
|
|
|
97
|
|
|
foreach( app( 'config' )->get( 'shop.page.catalog-tree' ) as $name ) |
|
98
|
|
|
{ |
|
99
|
|
|
$client = Shop::get( $name ); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
$params['aiheader'][$name] = $client->header(); |
|
102
|
|
|
$params['aibody'][$name] = $client->body(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return Response::view( Shop::template( 'catalog.tree' ), $params ) |
|
|
|
|
|
|
106
|
|
|
->header( 'Cache-Control', 'private, max-age=' . config( 'shop.cache_maxage', 30 ) ); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Returns the product page if the give path can be resolved to a product. |
|
112
|
|
|
* |
|
113
|
|
|
* @param \Aimeos\MShop\ContextIface $context Context object |
|
114
|
|
|
* @param string $path URL path to resolve |
|
115
|
|
|
* @return Response Response object |
|
116
|
|
|
*/ |
|
117
|
|
|
protected function product( \Aimeos\MShop\ContextIface $context, string $path ) : ?\Illuminate\Http\Response |
|
118
|
|
|
{ |
|
119
|
|
|
$item = \Aimeos\Controller\Frontend::create( $context, 'product' )->resolve( $path ); |
|
120
|
|
|
$view = Shop::view(); |
|
121
|
|
|
|
|
122
|
|
|
$params = ( Route::current() ? Route::current()->parameters() : [] ) + Request::all(); |
|
123
|
|
|
$params += ['d_name' => $path, 'd_prodid' => $item->getId(), 'page' => 'page-catalog-detail']; |
|
124
|
|
|
|
|
125
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $view, $params ); |
|
126
|
|
|
$view->addHelper( 'param', $helper ); |
|
127
|
|
|
|
|
128
|
|
|
foreach( app( 'config' )->get( 'shop.page.catalog-detail' ) as $name ) |
|
129
|
|
|
{ |
|
130
|
|
|
$client = Shop::get( $name ); |
|
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
$params['aiheader'][$name] = $client->header(); |
|
133
|
|
|
$params['aibody'][$name] = $client->body(); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return Response::view( Shop::template( 'catalog.detail' ), $params ) |
|
137
|
|
|
->header( 'Cache-Control', 'private, max-age=' . config( 'shop.cache_maxage', 30 ) ); |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
} |