1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Behat\Page\Admin\ProductVariant; |
13
|
|
|
|
14
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
15
|
|
|
use Sylius\Behat\Behaviour\SpecifiesItsCode; |
16
|
|
|
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; |
17
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
18
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Łukasz Chruściel <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class CreatePage extends BaseCreatePage implements CreatePageInterface |
24
|
|
|
{ |
25
|
|
|
use SpecifiesItsCode; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function specifyPrice($price, $channel) |
31
|
|
|
{ |
32
|
|
|
$this->getDocument()->fillField($channel, $price); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function specifyCurrentStock($currentStock) |
39
|
|
|
{ |
40
|
|
|
$this->getDocument()->fillField('Current stock', $currentStock); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function specifyHeightWidthDepthAndWeight($height, $width, $depth, $weight) |
47
|
|
|
{ |
48
|
|
|
$this->getDocument()->fillField('Height', $height); |
49
|
|
|
$this->getDocument()->fillField('Width', $width); |
50
|
|
|
$this->getDocument()->fillField('Depth', $depth); |
51
|
|
|
$this->getDocument()->fillField('Weight', $weight); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function nameIt($name) |
58
|
|
|
{ |
59
|
|
|
$this->getDocument()->fillField('Name', $name); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function selectOption($optionName, $optionValue) |
66
|
|
|
{ |
67
|
|
|
$optionName = strtoupper($optionName); |
68
|
|
|
$this->getElement('option_select', ['%option-name%' => $optionName])->selectOption($optionValue); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function choosePricingCalculator($name) |
75
|
|
|
{ |
76
|
|
|
$this->getElement('price_calculator')->selectOption($name); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
public function specifyPriceForChannelAndCurrency($price, ChannelInterface $channel, CurrencyInterface $currency) |
83
|
|
|
{ |
84
|
|
|
$calculatorElement = $this->getElement('calculator'); |
85
|
|
|
$calculatorElement |
86
|
|
|
->waitFor(5, function () use ($channel, $currency) { |
87
|
|
|
return $this->getElement('calculator')->hasField(sprintf('%s %s', $channel->getName(), $currency->getCode())); |
88
|
|
|
}) |
89
|
|
|
; |
90
|
|
|
|
91
|
|
|
$calculatorElement->fillField(sprintf('%s %s', $channel->getName(), $currency->getCode()), $price); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function getValidationMessageForForm() |
98
|
|
|
{ |
99
|
|
|
$formElement = $this->getDocument()->find('css', 'form[name="sylius_product_variant"]'); |
100
|
|
|
if (null === $formElement) { |
101
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Field element'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$validationMessage = $formElement->find('css', '.sylius-validation-error'); |
105
|
|
|
if (null === $validationMessage) { |
106
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $validationMessage->getText(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
|
|
public function selectShippingCategory($shippingCategoryName) |
116
|
|
|
{ |
117
|
|
|
$this->getElement('shipping_category')->selectOption($shippingCategoryName); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
|
|
public function getPricesValidationMessage() |
124
|
|
|
{ |
125
|
|
|
return $this->getElement('prices_validation_message')->getText(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* {@inheritdoc} |
130
|
|
|
*/ |
131
|
|
|
public function getFirstPriceValidationMessage() |
132
|
|
|
{ |
133
|
|
|
return $this->getElement('first_price_validation_message')->getText(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritdoc} |
138
|
|
|
*/ |
139
|
|
|
protected function getDefinedElements() |
140
|
|
|
{ |
141
|
|
|
return array_merge(parent::getDefinedElements(), [ |
142
|
|
|
'calculator' => '#sylius_calculator_container', |
143
|
|
|
'code' => '#sylius_product_variant_code', |
144
|
|
|
'depth' => '#sylius_product_variant_depth', |
145
|
|
|
'form' => 'form[name="sylius_product_variant"]', |
146
|
|
|
'height' => '#sylius_product_variant_height', |
147
|
|
|
'on_hand' => '#sylius_product_variant_onHand', |
148
|
|
|
'option_select' => '#sylius_product_variant_optionValues_%option-name%', |
149
|
|
|
'price_calculator' => '#sylius_product_variant_pricingCalculator', |
150
|
|
|
'shipping_category' => '#sylius_product_variant_shippingCategory', |
151
|
|
|
'prices_validation_message' => '#sylius_product_variant_channelPricings ~ .sylius-validation-error', |
152
|
|
|
'first_price_validation_message' => '#sylius_product_variant_channelPricings_0 .sylius-validation-error', |
153
|
|
|
'weight' => '#sylius_product_variant_weight', |
154
|
|
|
'width' => '#sylius_product_variant_width', |
155
|
|
|
]); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|