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

CheckoutInfoWidgetLoadedHook::getCart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Storefront\Page\Checkout\Offcanvas;
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 CheckoutInfoWidget 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 CheckoutInfoWidgetLoadedHook extends PageLoadedHook implements CartAware
23
{
24
    use SalesChannelContextAwareTrait;
25
26
    final public const HOOK_NAME = 'checkout-info-widget-loaded';
27
28
    public function __construct(
29
        private readonly OffcanvasCartPage $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(): OffcanvasCartPage
46
    {
47
        return $this->page;
48
    }
49
50
    public function getCart(): Cart
51
    {
52
        return $this->page->getCart();
53
    }
54
}
55