|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kunstmaan\SeoBundle\Helper; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class OrderConverter |
|
7
|
|
|
* |
|
8
|
|
|
* @package Kunstmaan\SeoBundle\Helper |
|
9
|
|
|
*/ |
|
10
|
|
|
class OrderConverter |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Converts an Order object to an Array. |
|
15
|
|
|
* |
|
16
|
|
|
* @param Order $order |
|
17
|
|
|
* |
|
18
|
|
|
* @return array |
|
|
|
|
|
|
19
|
|
|
*/ |
|
20
|
|
|
public function convert(Order $order) |
|
21
|
|
|
{ |
|
22
|
|
|
$orderItems = array(); |
|
23
|
|
|
|
|
24
|
|
|
foreach ($order->orderItems as $orderItem) { |
|
25
|
|
|
/** @var $orderItem OrderItem */ |
|
26
|
|
|
$orderItems[] = array( |
|
27
|
|
|
'sku' => $orderItem->getSKU(), |
|
28
|
|
|
'quantity' => $this->formatNumber($orderItem->getQuantity()), |
|
29
|
|
|
'unit_price' => $this->formatNumber($orderItem->getUnitPrice()), |
|
30
|
|
|
'taxes' => $this->formatNumber($orderItem->getTaxes()), |
|
31
|
|
|
'category_or_variation' => $orderItem->getCategoryOrVariation(), |
|
32
|
|
|
'name' => $orderItem->getName(), |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return array( |
|
37
|
|
|
'transaction_id' => $order->getTransactionID(), |
|
38
|
|
|
'store_name' => $order->getStoreName(), |
|
39
|
|
|
'total' => $this->formatNumber($order->getTotal()), |
|
40
|
|
|
'taxes_total' => $this->formatNumber($order->getTaxesTotal()), |
|
41
|
|
|
'shipping_total' => $this->formatNumber($order->getShippingTotal()), |
|
42
|
|
|
'city' => $order->getCity(), |
|
43
|
|
|
'state_or_province' => $order->getStateOrProvince(), |
|
44
|
|
|
'country' => $order->getCountry(), |
|
45
|
|
|
'order_items' => $orderItems |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Formats a number to a format google an easily comprehend. |
|
51
|
|
|
* |
|
52
|
|
|
* @param $number number |
|
53
|
|
|
* |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function formatNumber($number) |
|
57
|
|
|
{ |
|
58
|
|
|
return number_format($number, 2, '.', ''); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.