/
Proxy.php
183 lines (139 loc) · 5.7 KB
/
Proxy.php
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/*
* @copyright Copyright (c) 2011 by ESS-UA.
*/
class Ess_M2ePro_Model_Ebay_Order_Proxy extends Ess_M2ePro_Model_Order_Proxy
{
/** @var $order Ess_M2ePro_Model_Ebay_Order */
protected $order = NULL;
// ########################################
public function getCheckoutMethod()
{
if ($this->order->getEbayAccount()->isMagentoOrdersCustomerNew() ||
$this->order->getEbayAccount()->isMagentoOrdersCustomerPredefined()) {
return self::CHECKOUT_REGISTER;
}
return self::CHECKOUT_GUEST;
}
// ########################################
public function getBuyerEmail()
{
return $this->order->getBuyerEmail();
}
// ########################################
public function getCustomer()
{
$customer = Mage::getModel('customer/customer');
if ($this->order->getEbayAccount()->isMagentoOrdersCustomerPredefined()) {
$customer->load($this->order->getEbayAccount()->getMagentoOrdersCustomerId());
if (is_null($customer->getId())) {
throw new Exception('Customer with ID specified in eBay account settings does not exist.');
}
}
if ($this->order->getEbayAccount()->isMagentoOrdersCustomerNew()) {
$customerInfo = $this->getAddressData();
$customer->setWebsiteId($this->order->getEbayAccount()->getMagentoOrdersCustomerNewWebsiteId());
$customer->loadByEmail($customerInfo['email']);
if (!is_null($customer->getId())) {
return $customer;
}
$customerInfo['website_id'] = $this->order->getEbayAccount()->getMagentoOrdersCustomerNewWebsiteId();
$customerInfo['group_id'] = $this->order->getEbayAccount()->getMagentoOrdersCustomerNewGroupId();
$customerInfo['is_subscribed'] = $this->order->getEbayAccount()->isMagentoOrdersCustomerNewSubscribed();
/** @var $customerBuilder Ess_M2ePro_Model_Magento_Customer */
$customerBuilder = Mage::getModel('M2ePro/Magento_Customer')->setData($customerInfo);
$customerBuilder->buildCustomer();
$customer = $customerBuilder->getCustomer();
if ($this->order->getEbayAccount()->isMagentoOrdersCustomerNewNotifyWhenCreated()) {
$customer->sendNewAccountEmail('registered');
}
}
return $customer;
}
// ########################################
public function getCurrency()
{
return $this->order->getCurrency();
}
public function getPaymentData()
{
$paymentMethodTitle = $this->order->getPaymentMethod();
$paymentMethodTitle == 'None' && $paymentMethodTitle = Mage::helper('M2ePro')->__('Not Selected Yet');
$paymentData = array(
'method' => Mage::getSingleton('M2ePro/Magento_Payment')->getCode(),
'component_mode' => Ess_M2ePro_Helper_Component_Ebay::NICK,
'payment_method' => $paymentMethodTitle,
'channel_order_id' => $this->order->getEbayOrderId(),
'channel_final_fee' => $this->convertPrice($this->order->getFinalFee()),
'transactions' => $this->getPaymentTransactions()
);
return $paymentData;
}
public function getPaymentTransactions()
{
$transactions = array();
foreach ($this->order->getExternalTransactionsCollection() as $externalTransaction) {
$transactions[] = array(
'transaction_id' => $externalTransaction->getData('transaction_id'),
'fee' => $this->convertPrice((float)$externalTransaction->getData('fee')),
'sum' => $this->convertPrice((float)$externalTransaction->getData('sum')),
'transaction_date' => $externalTransaction->getData('transaction_date')
);
}
return $transactions;
}
// ########################################
public function getShippingData()
{
return array(
'shipping_method' => $this->order->getShippingMethod(),
'shipping_price' => $this->order->getShippingPrice(),
'carrier_title' => Mage::helper('M2ePro')->__('eBay Shipping')
);
}
// ########################################
public function getChannelComments()
{
$comments = array();
if ($this->order->getCheckoutBuyerMessage() != '') {
$comment = '<b>' . Mage::helper('M2ePro')->__('Checkout Message From Buyer') . ': </b>';
$comment .= $this->order->getCheckoutBuyerMessage() . '<br />';
$comments[] = $comment;
}
return $comments;
}
// ########################################
public function getTaxRate()
{
if ($this->order->getEbayAccount()->isMagentoOrdersTaxModeChannel() ||
$this->order->getEbayAccount()->isMagentoOrdersTaxModeMixed()) {
return $this->order->getTaxRate();
}
return 0;
}
public function hasTax()
{
return $this->order->hasTax();
}
public function hasVat()
{
return $this->order->hasVat();
}
public function isShippingPriceIncludesTax()
{
return $this->order->isShippingPriceIncludesTax();
}
public function isTaxModeNone()
{
return $this->order->getEbayAccount()->isMagentoOrdersTaxModeNone();
}
public function isTaxModeChannel()
{
return $this->order->getEbayAccount()->isMagentoOrdersTaxModeChannel();
}
public function isTaxModeMagento()
{
return $this->order->getEbayAccount()->isMagentoOrdersTaxModeMagento();
}
// ########################################
}