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\Shop\Cart; |
13
|
|
|
|
14
|
|
|
use Sylius\Behat\Page\SymfonyPage; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Mateusz Zalewski <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class CartSummaryPage extends SymfonyPage implements CartSummaryPageInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $elements = [ |
25
|
|
|
'grand total' => '#cart-summary td:contains("Grand total")', |
26
|
|
|
'promotion total' => '#cart-summary td:contains("Promotion total")', |
27
|
|
|
'shipping total' => '#cart-summary td:contains("Shipping total")', |
28
|
|
|
'tax total' => '#cart-summary td:contains("Tax total")', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function getGrandTotal() |
35
|
|
|
{ |
36
|
|
|
$grandTotalElement = $this->getElement('grand total'); |
37
|
|
|
|
38
|
|
|
return trim(str_replace('Grand total:', '', $grandTotalElement->getText())); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function getTaxTotal() |
45
|
|
|
{ |
46
|
|
|
$taxTotalElement = $this->getElement('tax total'); |
47
|
|
|
|
48
|
|
|
return trim(str_replace('Tax total:', '', $taxTotalElement->getText())); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function getShippingTotal() |
55
|
|
|
{ |
56
|
|
|
$shippingTotalElement = $this->getElement('shipping total'); |
57
|
|
|
|
58
|
|
|
return trim(str_replace('Shipping total:', '', $shippingTotalElement->getText())); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function getPromotionTotal() |
65
|
|
|
{ |
66
|
|
|
$shippingTotalElement = $this->getElement('promotion total'); |
67
|
|
|
|
68
|
|
|
return trim(str_replace('Promotion total:', '', $shippingTotalElement->getText())); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function getItemRegularPrice($productName) |
75
|
|
|
{ |
76
|
|
|
$this->elements['regular price'] = '#cart-summary tr:contains("'.$productName.'") .regular-price'; |
77
|
|
|
$regularPriceElement = $this->getElement('regular price'); |
78
|
|
|
|
79
|
|
|
return trim($regularPriceElement->getText()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function getItemDiscountPrice($productName) |
86
|
|
|
{ |
87
|
|
|
$this->elements['discount price'] = '#cart-summary tr:contains("'.$productName.'") .discount-price'; |
88
|
|
|
$discountPriceElement = $this->getElement('discount price'); |
89
|
|
|
|
90
|
|
|
return trim($discountPriceElement->getText()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function isItemDiscounted($productName) |
97
|
|
|
{ |
98
|
|
|
$this->elements['discount price'] = '#cart-summary tr:contains("'.$productName.'") .discount-price'; |
99
|
|
|
|
100
|
|
|
return $this->hasElement('discount price'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
|
|
public function removeProduct($productName) |
107
|
|
|
{ |
108
|
|
|
$item = $this->getDocument()->find('css', sprintf('#cart-summary tbody tr:contains("%s")', $productName)); |
109
|
|
|
$item->find('css', 'a.btn-danger')->click(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
|
|
public function changeQuantity($productName, $quantity) |
116
|
|
|
{ |
117
|
|
|
$item = $this->getDocument()->find('css', sprintf('#cart-summary tbody tr:contains("%s")', $productName)); |
118
|
|
|
$field = $item->find('css', 'input[type=number]'); |
119
|
|
|
$field->setValue($quantity); |
120
|
|
|
|
121
|
|
|
$this->getDocument()->pressButton('Save'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritdoc} |
126
|
|
|
*/ |
127
|
|
|
protected function getRouteName() |
128
|
|
|
{ |
129
|
|
|
return 'sylius_cart_summary'; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|