Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
ebay.php
1
<?php
2
3
namespace
Bitrix\Sale\TradingPlatform\Ebay
;
4
5
use
Bitrix\Main\Localization\Loc
;
6
use
Bitrix\Sale\TradingPlatform\Logger
;
7
use
Bitrix\Sale\TradingPlatform\Platform
;
8
9
Loc::loadMessages
(__FILE__);
10
11
class
Ebay
extends
Platform
12
{
13
//todo: check if token for sftp is expired
14
15
const
TRADING_PLATFORM_CODE
=
"ebay"
;
16
const
API_URL
=
"https://api.ebay.com/ws/api.dll"
;
17
22
public
static
function
getInstance
()
23
{
24
return
parent::getInstanceByCode(self::TRADING_PLATFORM_CODE);
25
}
26
27
public
static
function
getSftpTokenUrl
($accountName)
28
{
29
return
"http://"
.self::getServiceHost().
"/buy_tmp/ebay/"
.
30
"?action=OAUTH_AUTH"
.
31
"&LICENCE_HASH="
.self::getLicenseHash().
32
"&ACCOUNT_NAME="
.htmlspecialcharsbx($accountName).
33
"&BACK_URL="
.urlencode((\CMain::IsHTTPS() ?
"https://"
:
"http://"
).$_SERVER[
'HTTP_HOST'
]);
34
}
35
36
public
static
function
getApiTokenUrl
()
37
{
38
return
"http://"
.self::getServiceHost().
"/buy_tmp/ebay/"
.
39
"?action=GET_AUTH_URL&LICENCE_HASH="
.self::getLicenseHash().
40
"&BACK_URL="
.urlencode((\CMain::IsHTTPS() ?
"https://"
:
"http://"
).$_SERVER[
'HTTP_HOST'
]);
41
}
42
43
protected
static
function
getLicenseHash
()
44
{
45
return
md5(defined(
"LICENSE_KEY"
) ? LICENSE_KEY :
"DEMO"
);
46
}
47
48
protected
static
function
getServiceHost
()
49
{
50
return
defined(
'SALE_EBAY_SERVICE_HOST'
) ? SALE_EBAY_SERVICE_HOST :
'www.1c-bitrix.ru'
;
51
}
52
58
public
function
setActive
()
59
{
60
if
($this->
isActive
())
61
return
true
;
62
63
RegisterModuleDependences(
"sale"
,
"OnSaleDeductOrder"
,
"sale"
,
'\Bitrix\Sale\TradingPlatform\Ebay\Helper'
,
"onSaleDeductOrder"
, 100);
64
return
parent::setActive();
65
}
66
71
public
function
unsetActive
()
72
{
73
if
(!$this->
isActive
())
74
return
true
;
75
76
UnRegisterModuleDependences(
"sale"
,
"OnSaleDeductOrder"
,
"sale"
,
'\Bitrix\Sale\TradingPlatform\Ebay\Helper'
,
"onSaleDeductOrder"
, 100);
77
return
parent::unsetActive();
78
}
79
84
public
function
install
()
85
{
86
RegisterModuleDependences(
'main'
,
'OnEventLogGetAuditTypes'
,
'sale'
,
'\Bitrix\Sale\TradingPlatform\Ebay\Helper'
,
'OnEventLogGetAuditTypes'
);
87
88
$tptAddRes = \Bitrix\Sale\TradingPlatformTable::add(array(
89
"CODE"
=> $this->
getCode
(),
90
"ACTIVE"
=>
"N"
,
91
"NAME"
=>
Loc::getMessage
(
"SALE_EBAY_NAME"
),
92
"DESCRIPTION"
=>
Loc::getMessage
(
"SALE_EBAY_DESCRIPTION"
),
93
"CATALOG_SECTION_TAB_CLASS_NAME"
=>
'\Bitrix\Sale\TradingPlatform\Ebay\CatalogSectionTabHandler'
,
94
"CLASS"
=>
'\Bitrix\Sale\TradingPlatform\Ebay\Ebay'
95
));
96
97
$ebay =
Ebay::getInstance
();
98
$catMapEntRes = \Bitrix\Sale\TradingPlatform\MapEntityTable::add(array(
99
"TRADING_PLATFORM_ID"
=> $ebay->getId(),
100
"CODE"
=>
"CATEGORY"
101
));
102
103
$eventRes =
Helper::installEvents
();
104
$fsRes =
Helper::createFeedFileStructure
();
105
106
return
$tptAddRes->isSuccess()
107
&& $catMapEntRes->isSuccess()
108
&& $eventRes
109
&& $fsRes;
110
}
111
119
public
function
sendErrorMail
($type, $details, $siteId)
120
{
121
if
(!isset($this->settings[$siteId][
"EMAIL_ERRORS"
]) || $this->settings[$siteId][
"EMAIL_ERRORS"
] ==
''
)
122
return
false
;
123
124
$loggerTypes = Helper::OnEventLogGetAuditTypes();
125
$errorType = isset($loggerTypes[$type]) ? $loggerTypes[$type] : $type;
126
127
$fields
= array(
128
"EMAIL_TO"
=> $this->settings[$siteId][
"EMAIL_ERRORS"
],
129
"ERROR_TYPE"
=> $errorType,
130
"ERROR_DETAILS"
=> $details
131
);
132
133
$event = new \CEvent;
134
135
return
$event->Send(
"SALE_EBAY_ERROR"
, $siteId,
$fields
,
"N"
);
136
}
137
147
public
static
function
log
($level, $type, $itemId, $description, $siteId)
148
{
149
static
$ebay =
null
;
150
151
if
($ebay ===
null
)
152
{
153
$ebay =
self::getInstance
();
154
$settings
= $ebay->getSettings();
155
156
if
(isset(
$settings
[$siteId][
"LOG_LEVEL"
]))
157
{
158
$logLevel
=
$settings
[$siteId][
"LOG_LEVEL"
];
159
$ebay->logger->setLevel(
$logLevel
);
160
}
161
}
162
163
if
($level ==
Logger::LOG_LEVEL_ERROR
)
164
$ebay->sendErrorMail($type, $description, $siteId);
165
166
return
$ebay->addLogRecord($level, $type, $itemId, $description);
167
}
168
169
public
static
function
onAfterUpdateShipment
(\
Bitrix
\Main\
Event
$event, array $additional)
170
{
171
$data = array();
172
$ebay =
self::getInstance
();
173
$settings
= $ebay->getSettings();
174
$deliveryName =
"Other"
;
175
176
if
(
177
!empty(
$settings
[$additional[
"SITE_ID"
]][
"MAPS"
][
"SHIPMENT"
])
178
&& is_array(
$settings
[$additional[
"SITE_ID"
]][
"MAPS"
][
"SHIPMENT"
])
179
)
180
{
181
$map = array_flip(
$settings
[$additional[
"SITE_ID"
]][
"MAPS"
][
"SHIPMENT"
]);
182
183
if
(isset($map[$additional[
'DELIVERY_ID'
]]))
184
{
185
$deliveryName = $map[$additional[
'DELIVERY_ID'
]];
186
187
if
(mb_substr($deliveryName, 0, 3) ==
"RU_"
)
188
$deliveryName = mb_substr($deliveryName, 3);
189
}
190
}
191
192
if
(
193
!empty($additional[
"PARAMS"
][
"ORDER_LINES"
])
194
&& is_array($additional[
"PARAMS"
][
"ORDER_LINES"
])
195
&& !empty($additional[
"PARAMS"
][
"ORDER_ID"
])
196
)
197
{
198
foreach
($additional[
"PARAMS"
][
"ORDER_LINES"
] as $lineId)
199
{
200
$data[] = array(
201
"ORDER_ID"
=> $additional[
"PARAMS"
][
"ORDER_ID"
],
202
"ORDER_LINE_ITEM_ID"
=> $lineId,
203
"DELIVERY_NAME"
=> $deliveryName,
204
"TRACKING_NUMBER"
=> $additional[
'TRACKING_NUMBER'
]
205
);
206
}
207
}
208
209
if
(!empty($data))
210
{
211
$ebayFeed = \Bitrix\Sale\TradingPlatform\Ebay\Feed\Manager::createFeed(
"SHIPMENT"
, $additional[
"SITE_ID"
]);
212
$ebayFeed->setSourceData(array($data));
213
$ebayFeed->processData();
214
\Bitrix\Sale\TradingPlatform\Ebay\Agent::add(
'SHIPMENT'
, $additional[
"SITE_ID"
], 1,
true
);
215
}
216
}
217
218
public
static
function
getApiUrl
()
219
{
220
return
static::API_URL;
221
}
222
}
Bitrix\Main\Diag\Logger
Definition
logger.php:19
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Sale\TradingPlatform\Ebay\Ebay
Definition
ebay.php:12
Bitrix\Sale\TradingPlatform\Ebay\Ebay\onAfterUpdateShipment
static onAfterUpdateShipment(\Bitrix\Main\Event $event, array $additional)
Definition
ebay.php:169
Bitrix\Sale\TradingPlatform\Ebay\Ebay\unsetActive
unsetActive()
Definition
ebay.php:71
Bitrix\Sale\TradingPlatform\Ebay\Ebay\getLicenseHash
static getLicenseHash()
Definition
ebay.php:43
Bitrix\Sale\TradingPlatform\Ebay\Ebay\getServiceHost
static getServiceHost()
Definition
ebay.php:48
Bitrix\Sale\TradingPlatform\Ebay\Ebay\setActive
setActive()
Definition
ebay.php:58
Bitrix\Sale\TradingPlatform\Ebay\Ebay\sendErrorMail
sendErrorMail($type, $details, $siteId)
Definition
ebay.php:119
Bitrix\Sale\TradingPlatform\Ebay\Ebay\TRADING_PLATFORM_CODE
const TRADING_PLATFORM_CODE
Definition
ebay.php:15
Bitrix\Sale\TradingPlatform\Ebay\Ebay\getApiTokenUrl
static getApiTokenUrl()
Definition
ebay.php:36
Bitrix\Sale\TradingPlatform\Ebay\Ebay\install
install()
Definition
ebay.php:84
Bitrix\Sale\TradingPlatform\Ebay\Ebay\API_URL
const API_URL
Definition
ebay.php:16
Bitrix\Sale\TradingPlatform\Ebay\Ebay\getSftpTokenUrl
static getSftpTokenUrl($accountName)
Definition
ebay.php:27
Bitrix\Sale\TradingPlatform\Ebay\Ebay\getApiUrl
static getApiUrl()
Definition
ebay.php:218
Bitrix\Sale\TradingPlatform\Ebay\Ebay\getInstance
static getInstance()
Definition
ebay.php:22
Bitrix\Sale\TradingPlatform\Ebay\Ebay\log
static log($level, $type, $itemId, $description, $siteId)
Definition
ebay.php:147
Bitrix\Sale\TradingPlatform\Ebay\Helper\installEvents
static installEvents()
Definition
helper.php:85
Bitrix\Sale\TradingPlatform\Ebay\Helper\createFeedFileStructure
static createFeedFileStructure()
Definition
helper.php:54
Bitrix\Sale\TradingPlatform\Logger\LOG_LEVEL_ERROR
const LOG_LEVEL_ERROR
Definition
logger.php:15
Bitrix\Sale\TradingPlatform\Platform
Definition
platform.php:19
Bitrix\Sale\TradingPlatform\Platform\$logLevel
$logLevel
Definition
platform.php:24
Bitrix\Sale\TradingPlatform\Platform\isActive
isActive()
Definition
platform.php:132
Bitrix\Sale\TradingPlatform\Platform\$fields
$fields
Definition
platform.php:34
Bitrix\Sale\TradingPlatform\Platform\getCode
getCode()
Definition
platform.php:343
Bitrix\Sale\TradingPlatform\Platform\$settings
$settings
Definition
platform.php:28
Bitrix\Sale\TradingPlatform\Ebay
Definition
agent.php:3
Bitrix
modules
sale
lib
tradingplatform
ebay
ebay.php
Создано системой
1.10.0