Completed
Push — master ( b5de62...4c3851 )
by
unknown
19s queued 11s
created

CartOperationsWidget::getMultiCartClearFormView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerShop\Yves\MultiCartWidget\Widget;
9
10
use Generated\Shared\Transfer\QuoteTransfer;
11
use Spryker\Yves\Kernel\Widget\AbstractWidget;
12
use Symfony\Component\Form\FormView;
13
14
/**
15
 * @method \SprykerShop\Yves\MultiCartWidget\MultiCartWidgetFactory getFactory()
16
 */
17
class CartOperationsWidget extends AbstractWidget
18
{
19
    /**
20
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
21
     */
22
    public function __construct(QuoteTransfer $quoteTransfer)
23
    {
24
        $this->addParameter('cart', $quoteTransfer)
25
            ->addParameter('isMultiCartAllowed', $this->isMultiCartAllowed())
26
            ->addParameter('isDeleteCartAllowed', $this->isDeleteCartAllowed())
27
            ->addParameter('multiCartClearForm', $this->getMultiCartClearFormView())
28
            ->addParameter('multiCartDuplicateForm', $this->getMultiCartDuplicateFormView())
29
            ->addParameter('multiCartSetDefaultForm', $this->getMultiCartSetDefaultFormView());
30
31
        /** @deprecated Use global widgets instead. */
32
        $this->addWidgets($this->getFactory()->getViewExtendWidgetPlugins());
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public static function getName(): string
39
    {
40
        return 'CartOperationsWidget';
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public static function getTemplate(): string
47
    {
48
        return '@MultiCartWidget/views/cart-operations/cart-operations.twig';
49
    }
50
51
    /**
52
     * @return bool
53
     */
54
    protected function isMultiCartAllowed(): bool
55
    {
56
        return $this->getFactory()
57
            ->getMultiCartClient()
58
            ->isMultiCartAllowed();
59
    }
60
61
    /**
62
     * @return bool
63
     */
64
    protected function isDeleteCartAllowed(): bool
65
    {
66
        $numberOfQuotes = count($this->getFactory()
67
            ->getMultiCartClient()
68
            ->getQuoteCollection()
69
            ->getQuotes());
70
71
        return $numberOfQuotes > 1;
72
    }
73
74
    /**
75
     * @return \Symfony\Component\Form\FormView
76
     */
77
    protected function getMultiCartClearFormView(): FormView
78
    {
79
        return $this->getFactory()->getMultiCartClearForm()->createView();
80
    }
81
82
    /**
83
     * @return \Symfony\Component\Form\FormView
84
     */
85
    protected function getMultiCartDuplicateFormView(): FormView
86
    {
87
        return $this->getFactory()->getMultiCartDuplicateForm()->createView();
88
    }
89
90
    /**
91
     * @return \Symfony\Component\Form\FormView
92
     */
93
    protected function getMultiCartSetDefaultFormView(): FormView
94
    {
95
        return $this->getFactory()->getMultiCartSetDefaultForm()->createView();
96
    }
97
}
98