1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Shopware\Storefront\Page\Wishlist; |
4
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Cart\Exception\CustomerNotLoggedInException; |
6
|
|
|
use Shopware\Core\Checkout\Customer\SalesChannel\AbstractLoadGuestWishlistRoute; |
7
|
|
|
use Shopware\Core\Content\Category\Exception\CategoryNotFoundException; |
8
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException; |
9
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; |
10
|
|
|
use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException; |
11
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelContext; |
12
|
|
|
use Shopware\Storefront\Page\GenericPageLoaderInterface; |
13
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
|
16
|
|
|
class WishlistGuestPageLoader |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var EventDispatcherInterface |
20
|
|
|
*/ |
21
|
|
|
private $eventDispatcher; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var AbstractLoadGuestWishlistRoute |
25
|
|
|
*/ |
26
|
|
|
private $guestWishlistLoadRoute; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var GenericPageLoaderInterface |
30
|
|
|
*/ |
31
|
|
|
private $genericPageLoader; |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
GenericPageLoaderInterface $genericPageLoader, |
35
|
|
|
AbstractLoadGuestWishlistRoute $guestWishlistLoadRoute, |
36
|
|
|
EventDispatcherInterface $eventDispatcher |
37
|
|
|
) { |
38
|
|
|
$this->guestWishlistLoadRoute = $guestWishlistLoadRoute; |
39
|
|
|
$this->eventDispatcher = $eventDispatcher; |
40
|
|
|
$this->genericPageLoader = $genericPageLoader; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @throws CategoryNotFoundException |
45
|
|
|
* @throws CustomerNotLoggedInException |
46
|
|
|
* @throws InconsistentCriteriaIdsException |
47
|
|
|
* @throws MissingRequestParameterException |
48
|
|
|
*/ |
49
|
|
|
public function load(Request $request, SalesChannelContext $context): WishlistGuestPage |
50
|
|
|
{ |
51
|
|
|
$page = $this->genericPageLoader->load($request, $context); |
52
|
|
|
$page = WishlistGuestPage::createFrom($page); |
53
|
|
|
|
54
|
|
|
$this->eventDispatcher->dispatch(new WishlistGuestPageLoadedEvent($page, $context, $request)); |
55
|
|
|
|
56
|
|
|
return $page; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @throws CategoryNotFoundException |
61
|
|
|
* @throws CustomerNotLoggedInException |
62
|
|
|
* @throws InconsistentCriteriaIdsException |
63
|
|
|
* @throws MissingRequestParameterException |
64
|
|
|
*/ |
65
|
|
|
public function loadPagelet(Request $request, SalesChannelContext $context): WishlistGuestPagelet |
66
|
|
|
{ |
67
|
|
|
$criteria = $this->createCriteria(); |
68
|
|
|
|
69
|
|
|
$page = new WishlistGuestPagelet(); |
70
|
|
|
|
71
|
|
|
$page->setSearchResult($this->guestWishlistLoadRoute->load($request, $context, $criteria)); |
72
|
|
|
|
73
|
|
|
$this->eventDispatcher->dispatch(new WishlistGuestPageletLoadedEvent($page, $context, $request)); |
74
|
|
|
|
75
|
|
|
return $page; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function createCriteria(): Criteria |
79
|
|
|
{ |
80
|
|
|
return (new Criteria()) |
81
|
|
|
->addAssociation('manufacturer') |
82
|
|
|
->addAssociation('options.group') |
83
|
|
|
->setTotalCountMode(Criteria::TOTAL_COUNT_MODE_EXACT); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|