|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Behat\Page\Admin\ProductVariant; |
|
15
|
|
|
|
|
16
|
|
|
use Behat\Mink\Element\NodeElement; |
|
17
|
|
|
use Sylius\Behat\Behaviour\ChecksCodeImmutability; |
|
18
|
|
|
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; |
|
19
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
20
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
|
21
|
|
|
|
|
22
|
|
|
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use ChecksCodeImmutability; |
|
25
|
|
|
|
|
26
|
|
|
protected function getCodeElement(): NodeElement |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->getElement('code'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function specifyPrice(int $price): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->getDocument()->fillField('Price', $price); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function disableTracking(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->getElement('tracked')->uncheck(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function enableTracking(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->getElement('tracked')->check(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function isTracked(): bool |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->getElement('tracked')->isChecked(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getPricingConfigurationForChannelAndCurrencyCalculator(ChannelInterface $channel, CurrencyInterface $currency): string |
|
52
|
|
|
{ |
|
53
|
|
|
$priceElement = $this->getElement('pricing_configuration')->find('css', sprintf('label:contains("%s %s")', $channel->getCode(), $currency->getCode()))->getParent(); |
|
54
|
|
|
|
|
55
|
|
|
return $priceElement->find('css', 'input')->getValue(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getPriceForChannel(string $channelName): string |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->getElement('price', ['%channelName%' => $channelName])->getValue(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getOriginalPriceForChannel(string $channelName): string |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->getElement('original_price', ['%channelName%' => $channelName])->getValue(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getNameInLanguage(string $language): string |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->getElement('name', ['%language%' => $language])->getValue(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function specifyCurrentStock(int $amount): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->getElement('on_hand')->setValue($amount); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function selectOption(string $optionName, string $optionValue): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->getElement('option_values', ['%optionName%' => $optionName])->selectOption($optionValue); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function isSelectedOptionValueOnPage(string $optionName, string $valueName): bool |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->getDocument()->find('css', sprintf('option:contains("%s")', $valueName))->isSelected(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function isShippingRequired(): bool |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->getElement('shipping_required')->isChecked(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
protected function getDefinedElements(): array |
|
94
|
|
|
{ |
|
95
|
|
|
return array_merge(parent::getDefinedElements(), [ |
|
96
|
|
|
'code' => '#sylius_product_variant_code', |
|
97
|
|
|
'name' => '#sylius_product_variant_translations_%language%_name', |
|
98
|
|
|
'on_hand' => '#sylius_product_variant_onHand', |
|
99
|
|
|
'option_values' => '#sylius_product_variant_optionValues_%optionName%', |
|
100
|
|
|
'original_price' => '#sylius_product_variant_channelPricings > .field:contains("%channelName%") input[name$="[originalPrice]"]', |
|
101
|
|
|
'price' => '#sylius_product_variant_channelPricings > .field:contains("%channelName%") input[name$="[price]"]', |
|
102
|
|
|
'pricing_configuration' => '#sylius_calculator_container', |
|
103
|
|
|
'shipping_required' => '#sylius_product_variant_shippingRequired', |
|
104
|
|
|
'tracked' => '#sylius_product_variant_tracked', |
|
105
|
|
|
]); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|