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 Spryker\Zed\Discount\Communication\Tabs; |
||
9 | |||
10 | use Generated\Shared\Transfer\DiscountConfiguratorTransfer; |
||
11 | use Generated\Shared\Transfer\TabItemTransfer; |
||
12 | use Generated\Shared\Transfer\TabsViewTransfer; |
||
13 | use Spryker\Shared\Discount\DiscountConstants; |
||
14 | use Spryker\Zed\Gui\Communication\Tabs\AbstractTabs; |
||
15 | use Symfony\Component\Form\FormInterface; |
||
16 | |||
17 | class DiscountFormTabs extends AbstractTabs |
||
18 | { |
||
19 | /** |
||
20 | * @var \Symfony\Component\Form\FormInterface |
||
21 | */ |
||
22 | protected $discountForm; |
||
23 | |||
24 | /** |
||
25 | * @var \Symfony\Component\Form\FormInterface|null |
||
26 | */ |
||
27 | protected $voucherForm; |
||
28 | |||
29 | /** |
||
30 | * @var \Generated\Shared\Transfer\DiscountConfiguratorTransfer|null |
||
31 | */ |
||
32 | protected $discountConfiguratorTransfer; |
||
33 | |||
34 | /** |
||
35 | * @param \Symfony\Component\Form\FormInterface $discountForm |
||
36 | * @param \Symfony\Component\Form\FormInterface|null $voucherForm |
||
37 | * @param \Generated\Shared\Transfer\DiscountConfiguratorTransfer|null $discountConfiguratorTransfer |
||
38 | */ |
||
39 | public function __construct( |
||
40 | FormInterface $discountForm, |
||
41 | ?FormInterface $voucherForm = null, |
||
42 | ?DiscountConfiguratorTransfer $discountConfiguratorTransfer = null |
||
43 | ) { |
||
44 | $this->discountForm = $discountForm; |
||
45 | $this->voucherForm = $voucherForm; |
||
46 | $this->discountConfiguratorTransfer = $discountConfiguratorTransfer; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param \Generated\Shared\Transfer\TabsViewTransfer $tabsViewTransfer |
||
51 | * |
||
52 | * @return \Generated\Shared\Transfer\TabsViewTransfer |
||
53 | */ |
||
54 | protected function build(TabsViewTransfer $tabsViewTransfer) |
||
55 | { |
||
56 | $this |
||
57 | ->addGeneralInformationTab($tabsViewTransfer) |
||
58 | ->addDiscountCalculationTab($tabsViewTransfer) |
||
59 | ->addConditionsTab($tabsViewTransfer) |
||
60 | ->addVoucherCodesTab($tabsViewTransfer); |
||
61 | |||
62 | $tabsViewTransfer |
||
63 | ->setFooterTemplate('@Discount/Index/partial/footer.twig') |
||
64 | ->setIsNavigable(true); |
||
65 | |||
66 | return $tabsViewTransfer; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @param \Generated\Shared\Transfer\TabsViewTransfer $tabsViewTransfer |
||
71 | * |
||
72 | * @return $this |
||
73 | */ |
||
74 | protected function addGeneralInformationTab(TabsViewTransfer $tabsViewTransfer) |
||
75 | { |
||
76 | $tabItemTransfer = new TabItemTransfer(); |
||
77 | $tabItemTransfer |
||
78 | ->setName('general') |
||
79 | ->setTitle('General information') |
||
80 | ->setTemplate('@Discount/Index/partial/general.twig'); |
||
81 | |||
82 | $this->setHasError($tabItemTransfer, DiscountConfiguratorTransfer::DISCOUNT_GENERAL); |
||
83 | |||
84 | $tabsViewTransfer->addTab($tabItemTransfer); |
||
85 | |||
86 | return $this; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @param \Generated\Shared\Transfer\TabsViewTransfer $tabsViewTransfer |
||
91 | * |
||
92 | * @return $this |
||
93 | */ |
||
94 | protected function addDiscountCalculationTab(TabsViewTransfer $tabsViewTransfer) |
||
95 | { |
||
96 | $tabItemTransfer = new TabItemTransfer(); |
||
97 | $tabItemTransfer |
||
98 | ->setName('discount') |
||
99 | ->setTitle('Discount calculation') |
||
100 | ->setTemplate('@Discount/Index/partial/calculation.twig'); |
||
101 | |||
102 | $this->setHasError($tabItemTransfer, DiscountConfiguratorTransfer::DISCOUNT_CALCULATOR); |
||
103 | |||
104 | $tabsViewTransfer->addTab($tabItemTransfer); |
||
105 | |||
106 | return $this; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @param \Generated\Shared\Transfer\TabsViewTransfer $tabsViewTransfer |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | protected function addConditionsTab(TabsViewTransfer $tabsViewTransfer) |
||
115 | { |
||
116 | $tabItemTransfer = new TabItemTransfer(); |
||
117 | $tabItemTransfer |
||
118 | ->setName('conditions') |
||
119 | ->setTitle('Conditions') |
||
120 | ->setTemplate('@Discount/Index/partial/condition.twig'); |
||
121 | |||
122 | $this->setHasError($tabItemTransfer, DiscountConfiguratorTransfer::DISCOUNT_CONDITION); |
||
123 | |||
124 | $tabsViewTransfer->addTab($tabItemTransfer); |
||
125 | |||
126 | return $this; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @param \Generated\Shared\Transfer\TabsViewTransfer $tabsViewTransfer |
||
131 | * |
||
132 | * @return $this |
||
133 | */ |
||
134 | protected function addVoucherCodesTab(TabsViewTransfer $tabsViewTransfer) |
||
135 | { |
||
136 | if (!$this->isVoucherType()) { |
||
137 | return $this; |
||
138 | } |
||
139 | |||
140 | $tabItemTransfer = new TabItemTransfer(); |
||
141 | $tabItemTransfer |
||
142 | ->setName('voucher') |
||
143 | ->setTitle('Voucher codes') |
||
144 | ->setTemplate('@Discount/Index/partial/voucher.twig'); |
||
145 | |||
146 | if ($this->voucherForm->isSubmitted() && !$this->voucherForm->isValid()) { |
||
0 ignored issues
–
show
|
|||
147 | $tabItemTransfer->setHasError(true); |
||
148 | } |
||
149 | |||
150 | $tabsViewTransfer->addTab($tabItemTransfer); |
||
151 | |||
152 | return $this; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * @param \Generated\Shared\Transfer\TabItemTransfer $tabItemTransfer |
||
157 | * @param string $subForm |
||
158 | * |
||
159 | * @return void |
||
160 | */ |
||
161 | protected function setHasError(TabItemTransfer $tabItemTransfer, $subForm) |
||
162 | { |
||
163 | if ($this->discountForm->isSubmitted() && !$this->discountForm->get($subForm)->isValid()) { |
||
164 | $tabItemTransfer->setHasError(true); |
||
165 | } |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * @return bool |
||
170 | */ |
||
171 | protected function isVoucherType() |
||
172 | { |
||
173 | return $this->discountConfiguratorTransfer && $this->discountConfiguratorTransfer->getDiscountGeneral()->getDiscountType() == DiscountConstants::TYPE_VOUCHER; |
||
174 | } |
||
175 | } |
||
176 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.