1 | <?php |
||
27 | class CreateSimpleProductPage extends BaseCreatePage implements CreateSimpleProductPageInterface |
||
28 | { |
||
29 | use SpecifiesItsCode; |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | public function getRouteName() |
||
35 | { |
||
36 | return parent::getRouteName() . '_simple'; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function nameItIn($name, $localeCode) |
||
43 | { |
||
44 | $this->activateLanguageTab($localeCode); |
||
45 | $this->getElement('name', ['%locale%' => $localeCode])->setValue($name); |
||
46 | |||
47 | $this->waitForSlugGenerationIfNecessary($localeCode); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | public function specifySlugIn($slug, $locale) |
||
54 | { |
||
55 | $this->activateLanguageTab($locale); |
||
56 | |||
57 | $this->getElement('slug', ['%locale%' => $locale])->setValue($slug); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | public function specifyPrice($price) |
||
64 | { |
||
65 | $this->getDocument()->fillField('Price', $price); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function addAttribute($attribute, $value) |
||
72 | { |
||
73 | $this->clickTabIfItsNotActive('attributes'); |
||
74 | |||
75 | $attributeOption = $this->getElement('attributes_choice')->find('css', sprintf('option:contains("%s")', $attribute)); |
||
76 | $this->selectElementFromAttributesDropdown($attributeOption->getAttribute('value')); |
||
77 | |||
78 | $this->getDocument()->pressButton('Add attributes'); |
||
79 | $this->waitForFormElement(); |
||
80 | |||
81 | $this->getElement('attribute_value', ['%attribute%' => $attribute])->setValue($value); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | public function removeAttribute($attribute) |
||
88 | { |
||
89 | $this->clickTabIfItsNotActive('attributes'); |
||
90 | |||
91 | $this->getElement('attribute_delete_button', ['%attribute%' => $attribute])->press(); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function attachImage($path, $code = null) |
||
98 | { |
||
99 | $this->clickTabIfItsNotActive('media'); |
||
100 | |||
101 | $filesPath = $this->getParameter('files_path'); |
||
102 | |||
103 | $this->getDocument()->clickLink('Add'); |
||
104 | |||
105 | $imageForm = $this->getLastImageElement(); |
||
106 | if (null !== $code) { |
||
107 | $imageForm->fillField('Code', $code); |
||
108 | } |
||
109 | |||
110 | $imageForm->find('css', 'input[type="file"]')->attachFile($filesPath.$path); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function associateProducts(ProductAssociationTypeInterface $productAssociationType, array $productsNames) |
||
|
|||
117 | { |
||
118 | $this->clickTab('associations'); |
||
119 | |||
120 | Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class); |
||
121 | |||
122 | $dropdown = $this->getElement('association_dropdown', [ |
||
123 | '%association%' => $productAssociationType->getName() |
||
124 | ]); |
||
125 | $dropdown->click(); |
||
126 | |||
127 | foreach ($productsNames as $productName) { |
||
128 | $dropdown->waitFor(5, function () use ($productName, $productAssociationType) { |
||
129 | return $this->hasElement('association_dropdown_item', [ |
||
130 | '%association%' => $productAssociationType->getName(), |
||
131 | '%item%' => $productName, |
||
132 | ]); |
||
133 | }); |
||
134 | |||
135 | $item = $this->getElement('association_dropdown_item', [ |
||
136 | '%association%' => $productAssociationType->getName(), |
||
137 | '%item%' => $productName, |
||
138 | ]); |
||
139 | $item->click(); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | public function removeAssociatedProduct($productName, ProductAssociationTypeInterface $productAssociationType) |
||
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | public function choosePricingCalculator($name) |
||
161 | { |
||
162 | $this->getElement('price_calculator')->selectOption($name); |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | public function specifyPriceForChannelAndCurrency($price, ChannelInterface $channel, CurrencyInterface $currency) |
||
179 | |||
180 | /** |
||
181 | * {@inheritdoc} |
||
182 | */ |
||
183 | public function activateLanguageTab($locale) |
||
194 | |||
195 | /** |
||
196 | * {@inheritdoc} |
||
197 | */ |
||
198 | protected function getElement($name, array $parameters = []) |
||
206 | |||
207 | /** |
||
208 | * {@inheritdoc} |
||
209 | */ |
||
210 | protected function getDefinedElements() |
||
232 | |||
233 | /** |
||
234 | * @param int $id |
||
235 | */ |
||
236 | private function selectElementFromAttributesDropdown($id) |
||
245 | |||
246 | /** |
||
247 | * @param int $timeout |
||
248 | */ |
||
249 | private function waitForFormElement($timeout = 5) |
||
256 | |||
257 | /** |
||
258 | * @param string $tabName |
||
259 | */ |
||
260 | private function clickTabIfItsNotActive($tabName) |
||
267 | |||
268 | /** |
||
269 | * @param string $tabName |
||
270 | */ |
||
271 | private function clickTab($tabName) |
||
276 | |||
277 | /** |
||
278 | * @return NodeElement |
||
279 | */ |
||
280 | private function getLastImageElement() |
||
289 | |||
290 | /** |
||
291 | * @param string $locale |
||
292 | */ |
||
293 | private function waitForSlugGenerationIfNecessary($locale) |
||
301 | } |
||
302 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.