|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Storefront\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Customer\CustomerEntity; |
|
6
|
|
|
use Shopware\Core\Checkout\Customer\Exception\CustomerWishlistNotFoundException; |
|
7
|
|
|
use Shopware\Core\Checkout\Customer\Exception\DuplicateWishlistProductException; |
|
8
|
|
|
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractAddWishlistProductRoute; |
|
9
|
|
|
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractLoadWishlistRoute; |
|
10
|
|
|
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractMergeWishlistProductRoute; |
|
11
|
|
|
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractRemoveWishlistProductRoute; |
|
12
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; |
|
13
|
|
|
use Shopware\Core\Framework\Feature; |
|
14
|
|
|
use Shopware\Core\Framework\Routing\Annotation\LoginRequired; |
|
15
|
|
|
use Shopware\Core\Framework\Routing\Annotation\RouteScope; |
|
16
|
|
|
use Shopware\Core\Framework\Routing\Annotation\Since; |
|
17
|
|
|
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException; |
|
18
|
|
|
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; |
|
19
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelContext; |
|
20
|
|
|
use Shopware\Storefront\Page\Wishlist\WishlistGuestPageLoader; |
|
21
|
|
|
use Shopware\Storefront\Page\Wishlist\WishlistPageLoader; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
23
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
24
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
25
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
26
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @RouteScope(scopes={"storefront"}) |
|
30
|
|
|
*/ |
|
31
|
|
|
class WishlistController extends StorefrontController |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var WishlistPageLoader |
|
35
|
|
|
*/ |
|
36
|
|
|
private $wishlistPageLoader; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var AbstractLoadWishlistRoute |
|
40
|
|
|
*/ |
|
41
|
|
|
private $wishlistLoadRoute; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var AbstractAddWishlistProductRoute |
|
45
|
|
|
*/ |
|
46
|
|
|
private $addWishlistRoute; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var AbstractRemoveWishlistProductRoute |
|
50
|
|
|
*/ |
|
51
|
|
|
private $removeWishlistProductRoute; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var AbstractMergeWishlistProductRoute |
|
55
|
|
|
*/ |
|
56
|
|
|
private $mergeWishlistProductRoute; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var WishlistGuestPageLoader |
|
60
|
|
|
*/ |
|
61
|
|
|
private $guestPageLoader; |
|
62
|
|
|
|
|
63
|
|
|
public function __construct( |
|
64
|
|
|
WishlistPageLoader $wishlistPageLoader, |
|
65
|
|
|
AbstractLoadWishlistRoute $wishlistLoadRoute, |
|
66
|
|
|
AbstractAddWishlistProductRoute $addWishlistRoute, |
|
67
|
|
|
AbstractRemoveWishlistProductRoute $removeWishlistProductRoute, |
|
68
|
|
|
AbstractMergeWishlistProductRoute $mergeWishlistProductRoute, |
|
69
|
|
|
WishlistGuestPageLoader $guestPageLoader |
|
70
|
|
|
) { |
|
71
|
|
|
$this->wishlistPageLoader = $wishlistPageLoader; |
|
72
|
|
|
$this->wishlistLoadRoute = $wishlistLoadRoute; |
|
73
|
|
|
$this->addWishlistRoute = $addWishlistRoute; |
|
74
|
|
|
$this->removeWishlistProductRoute = $removeWishlistProductRoute; |
|
75
|
|
|
$this->mergeWishlistProductRoute = $mergeWishlistProductRoute; |
|
76
|
|
|
$this->guestPageLoader = $guestPageLoader; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @Since("6.3.4.0") |
|
81
|
|
|
* @Route("/wishlist", name="frontend.wishlist.page", options={"seo"="false"}, methods={"GET"}) |
|
82
|
|
|
*/ |
|
83
|
|
|
public function index(Request $request, SalesChannelContext $context): Response |
|
84
|
|
|
{ |
|
85
|
|
|
if ($context->getCustomer()) { |
|
86
|
|
|
$page = $this->wishlistPageLoader->load($request, $context); |
|
87
|
|
|
} else { |
|
88
|
|
|
$page = $this->guestPageLoader->load($request, $context); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $this->renderStorefront('@Storefront/storefront/page/wishlist/index.html.twig', ['page' => $page]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @Since("6.3.5.0") |
|
96
|
|
|
* @Route("/wishlist/guest-pagelet", name="frontend.wishlist.guestPage.pagelet", options={"seo"="false"}, methods={"POST"}, defaults={"XmlHttpRequest"=true}) |
|
97
|
|
|
*/ |
|
98
|
|
|
public function guestPagelet(Request $request, SalesChannelContext $context): Response |
|
99
|
|
|
{ |
|
100
|
|
|
$pagelet = $this->guestPageLoader->loadPagelet($request, $context); |
|
101
|
|
|
|
|
102
|
|
|
return $this->renderStorefront('@Storefront/storefront/page/wishlist/wishlist-pagelet.html.twig', ['searchResult' => $pagelet->getSearchResult()->getResult()]); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @Since("6.3.4.0") |
|
107
|
|
|
* @LoginRequired() |
|
108
|
|
|
* @Route("/widgets/wishlist", name="widgets.wishlist.pagelet", options={"seo"="false"}, methods={"GET", "POST"}, defaults={"XmlHttpRequest"=true}) |
|
109
|
|
|
*/ |
|
110
|
|
|
public function ajaxPagination(Request $request, SalesChannelContext $context): Response |
|
111
|
|
|
{ |
|
112
|
|
|
$request->request->set('no-aggregations', true); |
|
113
|
|
|
|
|
114
|
|
|
$page = $this->wishlistPageLoader->load($request, $context); |
|
115
|
|
|
|
|
116
|
|
|
return $this->renderStorefront('@Storefront/storefront/page/wishlist/index.html.twig', ['page' => $page]); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @Since("6.3.4.0") |
|
121
|
|
|
* @Route("/wishlist/list", name="frontend.wishlist.product.list", options={"seo"="false"}, methods={"GET"}, defaults={"XmlHttpRequest"=true}) |
|
122
|
|
|
*/ |
|
123
|
|
|
public function ajaxList(Request $request, SalesChannelContext $context): Response |
|
124
|
|
|
{ |
|
125
|
|
|
if (!Feature::isActive('FEATURE_NEXT_10549')) { |
|
126
|
|
|
throw new NotFoundHttpException(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
try { |
|
130
|
|
|
$res = $this->wishlistLoadRoute->load($request, $context, new Criteria()); |
|
131
|
|
|
} catch (CustomerWishlistNotFoundException $exception) { |
|
132
|
|
|
return new JsonResponse([]); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return new JsonResponse($res->getProductListing()->getIds()); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @Since("6.3.4.0") |
|
140
|
|
|
* @LoginRequired() |
|
141
|
|
|
* @Route("/wishlist/product/delete/{id}", name="frontend.wishlist.product.delete", methods={"POST", "DELETE"}, defaults={"XmlHttpRequest"=true}) |
|
142
|
|
|
*/ |
|
143
|
|
|
public function remove(string $id, Request $request, SalesChannelContext $context, ?CustomerEntity $customer = null): Response |
|
144
|
|
|
{ |
|
145
|
|
|
if (!$id) { |
|
146
|
|
|
throw new MissingRequestParameterException('Parameter id missing'); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
try { |
|
150
|
|
|
/* @deprecated tag:v6.4.0 - Parameter $customer will be mandatory when using with @LoginRequired() */ |
|
151
|
|
|
$this->removeWishlistProductRoute->delete($id, $context, $customer); |
|
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
$this->addFlash('success', $this->trans('wishlist.itemDeleteSuccess')); |
|
154
|
|
|
} catch (\Throwable $exception) { |
|
155
|
|
|
$this->addFlash('danger', $this->trans('error.message-default')); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
return $this->createActionResponse($request); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @Since("6.3.4.0") |
|
163
|
|
|
* @LoginRequired() |
|
164
|
|
|
* @Route("/wishlist/add/{productId}", name="frontend.wishlist.product.add", options={"seo"="false"}, methods={"POST"}, defaults={"XmlHttpRequest"=true}) |
|
165
|
|
|
*/ |
|
166
|
|
|
public function ajaxAdd(string $productId, SalesChannelContext $context, ?CustomerEntity $customer = null): JsonResponse |
|
167
|
|
|
{ |
|
168
|
|
|
if (!Feature::isActive('FEATURE_NEXT_10549')) { |
|
169
|
|
|
throw new NotFoundHttpException(); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/* @deprecated tag:v6.4.0 - Parameter $customer will be mandatory when using with @LoginRequired() */ |
|
173
|
|
|
$this->addWishlistRoute->add($productId, $context, $customer); |
|
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
return new JsonResponse([ |
|
176
|
|
|
'success' => true, |
|
177
|
|
|
]); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @Since("6.3.4.0") |
|
182
|
|
|
* @LoginRequired() |
|
183
|
|
|
* @Route("/wishlist/remove/{productId}", name="frontend.wishlist.product.remove", options={"seo"="false"}, methods={"POST"}, defaults={"XmlHttpRequest"=true}) |
|
184
|
|
|
*/ |
|
185
|
|
|
public function ajaxRemove(string $productId, SalesChannelContext $context, ?CustomerEntity $customer = null): JsonResponse |
|
186
|
|
|
{ |
|
187
|
|
|
if (!Feature::isActive('FEATURE_NEXT_10549')) { |
|
188
|
|
|
throw new NotFoundHttpException(); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/* @deprecated tag:v6.4.0 - Parameter $customer will be mandatory when using with @LoginRequired() */ |
|
192
|
|
|
$this->removeWishlistProductRoute->delete($productId, $context, $customer); |
|
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
return new JsonResponse([ |
|
195
|
|
|
'success' => true, |
|
196
|
|
|
]); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @Since("6.3.4.0") |
|
201
|
|
|
* @LoginRequired() |
|
202
|
|
|
* @Route("/wishlist/add-after-login/{productId}", name="frontend.wishlist.add.after.login", options={"seo"="false"}, methods={"GET"}) |
|
203
|
|
|
*/ |
|
204
|
|
|
public function addAfterLogin(string $productId, SalesChannelContext $context, ?CustomerEntity $customer = null): Response |
|
205
|
|
|
{ |
|
206
|
|
|
if (!Feature::isActive('FEATURE_NEXT_10549')) { |
|
207
|
|
|
throw new NotFoundHttpException(); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
try { |
|
211
|
|
|
/* @deprecated tag:v6.4.0 - Parameter $customer will be mandatory when using with @LoginRequired() */ |
|
212
|
|
|
$this->addWishlistRoute->add($productId, $context, $customer); |
|
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
$this->addFlash('success', $this->trans('wishlist.itemAddedSuccess')); |
|
215
|
|
|
} catch (DuplicateWishlistProductException $exception) { |
|
216
|
|
|
$this->addFlash('warning', $exception->getMessage()); |
|
217
|
|
|
} catch (\Throwable $exception) { |
|
218
|
|
|
$this->addFlash('danger', $this->trans('error.message-default')); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
return $this->redirectToRoute('frontend.home.page'); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @Since("6.3.4.0") |
|
226
|
|
|
* @LoginRequired() |
|
227
|
|
|
* @Route("/wishlist/merge", name="frontend.wishlist.product.merge", options={"seo"="false"}, methods={"POST"}, defaults={"XmlHttpRequest"=true}) |
|
228
|
|
|
*/ |
|
229
|
|
|
public function ajaxMerge(RequestDataBag $requestDataBag, Request $request, SalesChannelContext $context, ?CustomerEntity $customer = null): Response |
|
230
|
|
|
{ |
|
231
|
|
|
if (!Feature::isActive('FEATURE_NEXT_10549')) { |
|
232
|
|
|
throw new NotFoundHttpException(); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
try { |
|
236
|
|
|
/* @deprecated tag:v6.4.0 - Parameter $customer will be mandatory when using with @LoginRequired() */ |
|
237
|
|
|
$this->mergeWishlistProductRoute->merge($requestDataBag, $context, $customer); |
|
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
return $this->renderStorefront('@Storefront/storefront/utilities/alert.html.twig', [ |
|
240
|
|
|
'type' => 'info', 'content' => $this->trans('wishlist.wishlistMergeHint'), |
|
241
|
|
|
]); |
|
242
|
|
|
} catch (\Throwable $exception) { |
|
243
|
|
|
$this->addFlash('danger', $this->trans('error.message-default')); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
return $this->createActionResponse($request); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @Since("6.3.4.0") |
|
251
|
|
|
* @LoginRequired() |
|
252
|
|
|
* @Route("/wishlist/merge/pagelet", name="frontend.wishlist.product.merge.pagelet", methods={"GET", "POST"}, defaults={"XmlHttpRequest"=true}) |
|
253
|
|
|
*/ |
|
254
|
|
|
public function ajaxPagelet(Request $request, SalesChannelContext $context): Response |
|
255
|
|
|
{ |
|
256
|
|
|
$request->request->set('no-aggregations', true); |
|
257
|
|
|
|
|
258
|
|
|
$page = $this->wishlistPageLoader->load($request, $context); |
|
259
|
|
|
|
|
260
|
|
|
return $this->renderStorefront('@Storefront/storefront/page/wishlist/wishlist-pagelet.html.twig', ['page' => $page]); |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.