-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPayload.php
More file actions
78 lines (73 loc) · 2.13 KB
/
Copy pathPayload.php
File metadata and controls
78 lines (73 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Stock2Shop\OrderExport;
use Magento\Sales\Api\Data\OrderAddressInterface as IOA;
use Magento\Sales\Model\Order as O;
use Magento\Sales\Model\Order\Address as OA;
use Magento\Sales\Model\Order\Item as OI;
// 2018-08-11 Dmitry Fedyuk https://www.upwork.com/fl/mage2pro
final class Payload {
/**
* 2018-08-11
* @used-by get()
* @param IOA|OA|null $a
* @return array(string => mixed)
*/
private function address(IOA $a) {return !$a ? [] : dfa_remove_objects($a);}
/**
* 2018-08-11
* @used-by get()
* @return array(string => mixed)
*/
private function items() {return df_oqi_leafs($this->_o, function(OI $i) {return [
'name' => $i->getName()
,'image' => df_oqi_image($i)
,'price' => df_oqi_price($i)
,'price_with_discount' => df_oqi_price($i, false, true)
,'price_with_discount_and_tax' => df_oqi_price($i, true, true)
,'price_with_tax' => df_oqi_price($i, true)
,'qty' => df_oqi_qty($i)
,'tax_rate' => df_oqi_tax_rate($i)
,'url' => df_oqi_url($i)
];});}
/**
* 2018-08-11
* @used-by get()
* @return array(string => mixed)
*/
private function payment() {return array_filter(
dfa_remove_objects($this->_o->getPayment())
,function($k) {return !df_starts_with($k, 'cc_');}
,ARRAY_FILTER_USE_KEY
);}
/**
* 2018-08-11
* @used-by get()
* @return array(string => mixed)
*/
private function visitor() {return df_clean([
'http_user_agent' => df_request_ua()
,'http_x_forwarded_for' => dfa($_ENV, 'HTTP_X_FORWARDED_FOR')
,'http_via' => dfa($_ENV, 'HTTP_VIA')
,'remote_addr' => df_visitor_ip()
]);}
/**
* 2018-08-11
* @used-by get()
* @var O
*/
private $_o;
/**
* 2018-08-11
* @used-by \Stock2Shop\OrderExport\Observer\OrderSaveAfter::execute()
* @param O $o
* @return string
*/
static function get(O $o) {$i = new self; $i->_o = $o; return [
'billing_address' => $i->address($o->getBillingAddress())
,'customer' => !($cid = $o->getCustomerId()) ? [] : dfa_remove_objects(df_customer($cid))
,'line_items' => $i->items()
,'payment' => $i->payment()
,'shipping_address' => $i->address($o->getShippingAddress())
,'visitor' => $i->visitor()
] + dfa_remove_objects($o);}
}