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\ChecksCodeImmutability; |
15
|
|
|
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; |
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 UpdatePage extends BaseUpdatePage implements UpdatePageInterface |
23
|
|
|
{ |
24
|
|
|
use ChecksCodeImmutability; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
protected function getCodeElement() |
30
|
|
|
{ |
31
|
|
|
return $this->getElement('code'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function specifyPrice($price) |
38
|
|
|
{ |
39
|
|
|
$this->getDocument()->fillField('Price', $price); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function disableTracking() |
43
|
|
|
{ |
44
|
|
|
$this->getElement('tracked')->uncheck(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function enableTracking() |
48
|
|
|
{ |
49
|
|
|
$this->getElement('tracked')->check(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function isTracked() |
56
|
|
|
{ |
57
|
|
|
return $this->getElement('tracked')->isChecked(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function getPricingConfigurationForChannelAndCurrencyCalculator(ChannelInterface $channel, CurrencyInterface $currency) |
64
|
|
|
{ |
65
|
|
|
$priceElement = $this->getElement('pricing_configuration')->find('css', sprintf('label:contains("%s %s")', $channel->getCode(), $currency->getCode()))->getParent(); |
66
|
|
|
|
67
|
|
|
return $priceElement->find('css', 'input')->getValue(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function getPriceForChannel($channelName) |
74
|
|
|
{ |
75
|
|
|
return $this->getElement('price', ['%channelName%' => $channelName])->getValue(); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function getOriginalPriceForChannel($channelName) |
82
|
|
|
{ |
83
|
|
|
return $this->getElement('original_price', ['%channelName%' => $channelName])->getValue(); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function getNameInLanguage($language) |
90
|
|
|
{ |
91
|
|
|
return $this->getElement('name', ['%language%' => $language])->getValue(); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
|
|
public function specifyCurrentStock($amount) |
98
|
|
|
{ |
99
|
|
|
$this->getElement('on_hand')->setValue($amount); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function isShippingRequired() |
106
|
|
|
{ |
107
|
|
|
return $this->getElement('shipping_required')->isChecked(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
|
|
protected function getDefinedElements() |
114
|
|
|
{ |
115
|
|
|
return array_merge(parent::getDefinedElements(), [ |
116
|
|
|
'code' => '#sylius_product_variant_code', |
117
|
|
|
'name' => '#sylius_product_variant_translations_%language%_name', |
118
|
|
|
'on_hand' => '#sylius_product_variant_onHand', |
119
|
|
|
'original_price' => '#sylius_product_variant_channelPricings > .field:contains("%channelName%") input[name$="[originalPrice]"]', |
120
|
|
|
'price' => '#sylius_product_variant_channelPricings > .field:contains("%channelName%") input[name$="[price]"]', |
121
|
|
|
'pricing_configuration' => '#sylius_calculator_container', |
122
|
|
|
'shipping_required' => '#sylius_product_variant_shippingRequired', |
123
|
|
|
'tracked' => '#sylius_product_variant_tracked', |
124
|
|
|
]); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.