Passed
Push — trunk ( 5b7d3d...2a754e )
by Christian
12:07 queued 12s
created

CheckoutCartPageLoadedHook   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getPage() 0 3 1
A getName() 0 7 2
A getCart() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Storefront\Page\Checkout\Cart;
4
5
use Shopware\Core\Checkout\Cart\Cart;
6
use Shopware\Core\Checkout\Cart\Hook\CartAware;
7
use Shopware\Core\Framework\Log\Package;
8
use Shopware\Core\Framework\Script\Execution\Awareness\SalesChannelContextAwareTrait;
9
use Shopware\Core\System\SalesChannel\SalesChannelContext;
10
use Shopware\Storefront\Page\PageLoadedHook;
11
12
/**
13
 * Triggered when the CheckoutCartPage is loaded
14
 *
15
 * @hook-use-case data_loading
16
 *
17
 * @since 6.4.8.0
18
 *
19
 * @final
20
 */
21
#[Package('storefront')]
22
class CheckoutCartPageLoadedHook extends PageLoadedHook implements CartAware
23
{
24
    use SalesChannelContextAwareTrait;
25
26
    final public const HOOK_NAME = 'checkout-cart-page-loaded';
27
28
    public function __construct(
29
        private readonly CheckoutCartPage $page,
30
        SalesChannelContext $context
31
    ) {
32
        parent::__construct($context->getContext());
33
        $this->salesChannelContext = $context;
34
    }
35
36
    public function getName(): string
37
    {
38
        if ($this->getCart()->getSource()) {
39
            return self::HOOK_NAME . '-' . $this->getCart()->getSource();
40
        }
41
42
        return self::HOOK_NAME;
43
    }
44
45
    public function getPage(): CheckoutCartPage
46
    {
47
        return $this->page;
48
    }
49
50
    public function getCart(): Cart
51
    {
52
        return $this->page->getCart();
53
    }
54
}
55