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 Sylius\Behat\Behaviour\SpecifiesItsCode; |
15
|
|
|
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; |
16
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
17
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Łukasz Chruściel <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class CreatePage extends BaseCreatePage implements CreatePageInterface |
23
|
|
|
{ |
24
|
|
|
use SpecifiesItsCode; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function specifyPrice($price) |
30
|
|
|
{ |
31
|
|
|
$this->getDocument()->fillField('Price', $price); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function nameIt($name) |
38
|
|
|
{ |
39
|
|
|
$this->getDocument()->fillField('Name', $name); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function selectOption($optionName, $optionValue) |
46
|
|
|
{ |
47
|
|
|
$optionName = strtoupper($optionName); |
48
|
|
|
$this->getElement('option_select', ['%option-name%' => $optionName])->selectOption($optionValue); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function choosePricingCalculator($name) |
55
|
|
|
{ |
56
|
|
|
$this->getElement('price_calculator')->selectOption($name); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function specifyPriceForChannelAndCurrency($price, ChannelInterface $channel, CurrencyInterface $currency) |
63
|
|
|
{ |
64
|
|
|
$calculatorElement = $this->getElement('calculator'); |
65
|
|
|
$calculatorElement |
66
|
|
|
->waitFor(5, function () use ($channel, $currency) { |
67
|
|
|
return $this->getElement('calculator')->hasField(sprintf('%s %s', $channel->getName(), $currency->getCode())); |
68
|
|
|
}) |
69
|
|
|
; |
70
|
|
|
|
71
|
|
|
$calculatorElement->fillField(sprintf('%s %s', $channel->getName(), $currency->getCode()), $price); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
protected function getDefinedElements() |
78
|
|
|
{ |
79
|
|
|
return array_merge(parent::getDefinedElements(), [ |
80
|
|
|
'calculator' => '#sylius_calculator_container', |
81
|
|
|
'code' => '#sylius_product_variant_code', |
82
|
|
|
'option_select' => '#sylius_product_variant_optionValues_%option-name%', |
83
|
|
|
'price' => '#sylius_product_variant_price', |
84
|
|
|
'price_calculator' => '#sylius_product_variant_pricingCalculator', |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|