1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Magento\Actions\Cart; |
4
|
|
|
|
5
|
|
|
use Magium\Actions\StaticActionInterface; |
6
|
|
|
use Magium\Magento\Extractors\Catalog\Cart\AddToCart; |
7
|
|
|
use Magium\Magento\Extractors\Catalog\Product\ConfigurableProductOptions; |
8
|
|
|
use Magium\Magento\Extractors\Catalog\Product\Swatch; |
9
|
|
|
use Magium\Magento\Extractors\Catalog\Product\Option; |
10
|
|
|
use Magium\Magento\Extractors\Catalog\Product\SwatchValue; |
11
|
|
|
use Magium\Magento\Extractors\Catalog\Product\Value; |
12
|
|
|
use Magium\Magento\Themes\AbstractThemeConfiguration; |
13
|
|
|
use Magium\WebDriver\WebDriver; |
14
|
|
|
|
15
|
|
|
class AddConfigurableProductToCart extends AddSimpleProductToCart implements StaticActionInterface |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
const ACTION = 'Cart\AddConfigurableProductToCart'; |
19
|
|
|
|
20
|
|
|
const EXCEPTION_INVALID_CONFIGURABLE_OPTION = 'Magium\Magento\Actions\Cart\InvalidConfigurableOptionException'; |
21
|
|
|
|
22
|
|
|
protected $option; |
23
|
|
|
protected $options = []; |
24
|
|
|
|
25
|
|
|
public function __construct( |
26
|
|
|
WebDriver $webDriver, |
27
|
|
|
AbstractThemeConfiguration $themeConfiguration, |
28
|
|
|
AddToCart $addToCart, |
29
|
|
|
ConfigurableProductOptions $option |
30
|
|
|
) |
31
|
|
|
{ |
32
|
|
|
parent::__construct($webDriver, $themeConfiguration, $addToCart); |
33
|
|
|
$this->option = $option; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function setOption($attribute, $option) |
37
|
|
|
{ |
38
|
|
|
$this->options[strtolower($attribute)] = $option; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getOption($attribute) |
42
|
|
|
{ |
43
|
|
|
$attribute = strtolower($attribute); |
44
|
|
|
foreach ($this->options as $name => $option) { |
45
|
|
|
if ($name == $attribute) { |
46
|
|
|
return $option; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function execute() |
54
|
|
|
{ |
55
|
|
|
$this->option->extract(); |
56
|
|
|
if (count($this->options)) { |
57
|
|
|
$attributes = $this->option->getOptionNames(); |
58
|
|
|
foreach ($attributes as $attributeName) { |
59
|
|
|
$elementOption = $this->option->getOption($attributeName); |
|
|
|
|
60
|
|
|
if (!$elementOption) continue; |
61
|
|
|
// The options are sorted by their entry into the setOption() method. Need to have it ordered by the page order |
62
|
|
|
|
63
|
|
|
if (!$elementOption instanceof Option) { |
64
|
|
|
throw new InvalidConfigurableOptionException('Missing the attribute: ' . $attributeName); |
65
|
|
|
} |
66
|
|
|
$element = $elementOption->getValue($this->getOption($attributeName)); |
67
|
|
|
if (!$element instanceof Value) { |
68
|
|
|
throw new InvalidConfigurableOptionException(sprintf('Missing the option %s for the attribute %s ', $this->getOption($attributeName), $attributeName)); |
69
|
|
|
} |
70
|
|
|
$element->getClickElement()->click(); |
71
|
|
|
} |
72
|
|
|
} else { |
73
|
|
|
$names = $this->option->getOptionNames(); |
74
|
|
|
foreach ($names as $name) { |
75
|
|
|
$option = $this->option->getOption($name); |
76
|
|
|
$items = $option->getValues(); |
77
|
|
|
foreach ($items as $item) { |
78
|
|
|
if ($item instanceof SwatchValue) { |
79
|
|
|
if ($item->getAvailable()) { |
80
|
|
|
$item->getClickElement()->click(); |
81
|
|
|
break; |
82
|
|
|
} |
83
|
|
|
} else { |
84
|
|
|
$item->getClickElement()->click(); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
return parent::execute(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.