1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Magento\Extractors\Customer\Order; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Facebook\WebDriver\WebDriverElement; |
7
|
|
|
use Magium\WebDriver\WebDriver; |
8
|
|
|
|
9
|
|
|
class ItemList extends AbstractOrderExtractor |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
const EXTRACTOR = 'Customer\Order\ItemList'; |
13
|
|
|
|
14
|
|
|
protected $element; |
15
|
|
|
protected $items; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @return Item[] |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
public function getItems() |
22
|
|
|
{ |
23
|
|
|
return $this->items; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function extract() |
27
|
|
|
{ |
28
|
|
|
if ($this->element instanceof WebDriverElement && $this->webDriver->elementAttached($this->element)) { |
29
|
|
|
return; |
30
|
|
|
} |
31
|
|
|
$this->element = $this->webDriver->byXpath('//body'); // Just need any element on the page |
32
|
|
|
$count = 0; |
33
|
|
|
|
34
|
|
|
$this->items = []; |
35
|
|
|
|
36
|
|
|
while ($this->webDriver->elementExists($this->theme->getOrderItemNameXpath(++$count), WebDriver::BY_XPATH)) { |
37
|
|
|
$productName = trim($this->webDriver->byXpath($this->theme->getOrderItemNameXpath($count))->getText()); |
38
|
|
|
$productSku = trim($this->webDriver->byXpath($this->theme->getOrderItemSkuXpath($count))->getText()); |
39
|
|
|
$productPrice = trim($this->webDriver->byXpath($this->theme->getOrderItemPriceXpath($count))->getText()); |
40
|
|
|
$qty = trim($this->webDriver->byXpath($this->theme->getOrderItemQtyXpath($count))->getText()); |
41
|
|
|
$qtyShipped = $qtyOrdered = 0; |
42
|
|
|
$matched = null; |
43
|
|
|
if (preg_match($this->theme->getOrderItemQtyOrderedRegex(), $qty, $matched)) { |
44
|
|
|
$qtyOrdered = $matched[1]; |
45
|
|
|
} |
46
|
|
|
if (preg_match($this->theme->getOrderItemQtyShippedRegex(), $qty, $matched)) { |
47
|
|
|
$qtyShipped = $matched[1]; |
48
|
|
|
} |
49
|
|
|
$orderSubtotal = trim($this->webDriver->byXpath($this->theme->getOrderItemSubtotalXpath($count))->getText()); |
50
|
|
|
$item = new Item($productPrice, $productName, $qtyOrdered, $qtyShipped, $productSku, $orderSubtotal); |
51
|
|
|
$this->items[] = $item; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
} |