33 if(!extension_loaded(
'ssh2'))
36 if(!extension_loaded(
'SimpleXML'))
47 return $_SERVER[
"DOCUMENT_ROOT"].
"/bitrix/tradingplatforms/ebay/sftp";
59 if(!$directory->isExists())
62 foreach(array(
"product",
"inventory",
"image",
"order-ack",
"shipment") as $feedType)
64 $feedDir =
new Directory($sftpDir.
"/".$feedType);
66 if(!$feedDir->isExists())
69 foreach(array(
"xml",
"tmp",
"zip") as $stage)
71 $stageDir =
new Directory($sftpDir.
"/".$feedType.
"/".$stage);
73 if(!$stageDir->isExists())
87 $dbEvent = \CEventMessage::GetList(
"id",
"asc", Array(
"EVENT_NAME" =>
"SALE_EBAY_ERROR"));
89 if(!($dbEvent->Fetch()))
91 $langs = \CLanguage::GetList();
92 while($lang = $langs->Fetch())
95 $obEventType = new \CEventType;
96 $obEventType->Add(array(
97 "EVENT_NAME" =>
"SALE_EBAY_ERROR",
101 #ERROR_TYPE# - ".
Loc::getMessage(
"SALE_EBAY_HLP_EVNT_TYPE_ERROR_TYPE").
"
102 #ERROR_DETAILS# - ".
Loc::getMessage(
"SALE_EBAY_HLP_EVNT_TYPE_ERROR_DETAIL").
"
109 $sites = \CSite::GetList(
'',
'', Array(
"LANGUAGE_ID"=>$lid));
110 while ($site = $sites->Fetch())
111 $arSites[] = $site[
"LID"];
113 if(count($arSites) > 0)
116 $arr[
"ACTIVE"] =
"Y";
117 $arr[
"EVENT_NAME"] =
"SALE_EBAY_ERROR";
118 $arr[
"LID"] = $arSites;
119 $arr[
"EMAIL_FROM"] =
"#DEFAULT_EMAIL_FROM#";
120 $arr[
"EMAIL_TO"] =
"#EMAIL_TO#";
121 $arr[
"BCC"] =
"#BCC#";
122 $arr[
"SUBJECT"] =
"#SITE_NAME# ".Loc::getMessage(
"SALE_EBAY_EVNT_MSG_SBUJ']").
".";
123 $arr[
"BODY_TYPE"] =
"text";
130 $obTemplate = new \CEventMessage;
131 $obTemplate->Add($arr);
142 public static function getEbayOrderStatuses()
158 public static function onSaleDeductOrder($orderId, $val)
163 $order = \CSaleOrder::GetByID($orderId);
170 $shipmentInfo = array();
171 $trackingInfo = array();
173 if($order[
"TRACKING_NUMBER"] <>
'')
175 $ebayDelivery =
"Other";
176 $ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
177 $settings = $ebay->getSettings();
179 if(isset($settings[$order[
"LID"]][
"DELIVERY"]) && is_array($settings[$order[
"LID"]][
"DELIVERY"]))
181 foreach($settings[$order[
"LID"]][
"DELIVERY"] as $eDelivery => $bDelivery)
183 if($bDelivery == $order[
"DELIVERY_ID"])
185 $ebayDelivery = $eDelivery;
191 $trackingInfo = array(
192 "SERVICE" => $ebayDelivery,
193 "NUMBER" => $order[
"TRACKING_NUMBER"]
197 $orderLineItemIds = array();
199 $dbBasket = \CSaleBasket::GetList(
201 array(
"ORDER_ID" => $orderId),
207 while ($arBasket = $dbBasket->GetNext())
208 $orderLineItemIds[] = $arBasket[
"XML_ID"];
210 foreach($orderLineItemIds as $orderLineItemId)
212 $tmpShipmentInfo = array(
213 "ORDER_ID" => $ebayOrderId,
214 "ORDER_LINE_ITEM_ID" => $orderLineItemId,
217 if(!empty($trackingInfo))
218 $tmpShipmentInfo[
"TRACKING"] = $trackingInfo;
220 $shipmentInfo[] = $tmpShipmentInfo;
223 $ebayFeed = Manager::createFeed(
"SHIPMENT", $order[
"LID"]);
224 $ebayFeed->setSourceData($shipmentInfo);
225 $ebayFeed->exchangeData(
"");
235 public static function OnEventLogGetAuditTypes()
241 "EBAY_AGENT_FEED_STARTED" =>
Loc::getMessage(
"SALE_EBAY_AT_AGENT_FEED_STARTED"),
243 "EBAY_DATA_PROCESSOR_ORDER_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_ERROR"),
244 "EBAY_DATA_PROCESSOR_ORDER_PROCESSED" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_PROCESSED"),
245 "EBAY_DATA_PROCESSOR_SFTPQUEUE_SEND" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_SFTPQUEUE_SEND"),
246 "EBAY_DATA_SOURCE_ORDERFILE_RECEIVED" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_SOURCE_ORDERFILE_RECEIVED"),
247 "EBAY_DATA_PROCESSOR_ORDER_CREATED" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_CREATED"),
248 "EBAY_DATA_PROCESSOR_ORDER_PROCESSING" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_PROCESSING"),
249 "EBAY_DATA_SOURCE_RESULTS_RECEIVED" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_SOURCE_RESULTS_RECEIVED"),
250 "EBAY_DATA_SOURCE_RESULTS_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_SOURCE_RESULTS_ERROR"),
251 "EBAY_AGENT_ADDING_RESULT" =>
Loc::getMessage(
"SALE_EBAY_AT_AGENT_ADDING_RESULT"),
252 "EBAY_FEED_RESULTS_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_FEED_RESULTS_ERROR"),
253 "EBAY_POLICY_REQUEST_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_POLICY_REQUEST_ERROR"),
254 "EBAY_POLICY_REQUEST_HTTP_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_POLICY_REQUEST_HTTP_ERROR"),
255 "EBAY_DATA_PROCESSOR_ORDER_SKIPPED" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_SKIPPED"),
256 "EBAY_DATA_PROCESSOR_ORDER_ALREADY_EXIST" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_ALREADY_EXIST"),
257 "EBAY_DATA_PROCESSOR_ORDER_PROCESSING_TRANSACTION_ITEM_NOT_FOUND" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_PROCESSING_TR_NOT_FOUND"),
258 "EBAY_DATA_PROCESSOR_ORDER_PROCESSING_TRANSACTION_ITEM_SKU_NOT_FOUND" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_PROCESSING_TRANSACTION_ITEM_SKU_NOT_FOUND"),
259 "EBAY_DATA_PROCESSOR_ORDER_TRANSACTION_ITEM_CREATE_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_TRANSACTION_ITEM_CREATE_ERROR"),
260 "EBAY_DATA_PROCESSOR_ORDER_CREATE_ERROR_SET_BASKET" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_CREATE_ERROR_SET_BASKET"),
261 "EBAY_DATA_PROCESSOR_ORDER_CANCELING_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_CANCELING_ERROR"),
262 "EBAY_DATA_PROCESSOR_ORDER_DEDUCTIOING_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_DEDUCTIOING_ERROR"),
263 "EBAY_DATA_PROCESSOR_ORDER_CHANGE_STATUS_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_CHANGE_STATUS_ERROR"),
264 "EBAY_DATA_PROCESSOR_ORDER_SAVE_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_SAVE_ERROR"),
265 "EBAY_DATA_PROCESSOR_ORDER_CORR_SAVE_ERROR" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_ORDER_CORR_SAVE_ERROR"),
266 "EBAY_DATA_PROCESSOR_SFTPQUEUE_FLUSHING" =>
Loc::getMessage(
"SALE_EBAY_AT_DATA_PROCESSOR_SFTPQUEUE_FLUSHING"),
267 "EBAY_SFTP_TOKEN_EXP" =>
Loc::getMessage(
"SALE_EBAY_AT_SFTP_TOKEN_EXP"),
270 array_walk($result,
function(&$value, $key, $prefix) {
271 $value = $prefix.$value;
284 public static function getSftp($siteId)
287 throw new ArgumentNullException(
"siteId");
289 static $sftp = array();
291 if(!isset($sftp[$siteId]))
293 $ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
294 $settings = $ebay->getSettings();
295 $host = isset($settings[$siteId][
"SFTP_HOST"]) ? $settings[$siteId][
"SFTP_HOST"] :
"mip.ebay.com";
296 $port = isset($settings[$siteId][
"SFTP_PORT"]) ? $settings[$siteId][
"SFTP_PORT"] : 22;
297 $fingerprint = $settings[$siteId][
"SFTP_HOST_FINGERPRINT"] <>
'' ? $settings[$siteId][
"SFTP_HOST_FINGERPRINT"] :
"DD1FEE728C2E1FF2AACC2724929C3CF1";
299 if(!empty($settings[$siteId][
"SFTP_TOKEN_EXP"]) && date(
'c') > date($settings[$siteId][
"SFTP_TOKEN_EXP"]))
302 throw new SystemException(
Loc::getMessage(
'SALE_EBAY_AT_SFTP_TOKEN_EXP_MESSAGE'));
306 $sftp[$siteId] =
new Sftp(
307 $settings[$siteId][
"SFTP_LOGIN"],
308 $settings[$siteId][
"SFTP_PASS"],
316 return $sftp[$siteId];
327 public static function getEbayCategoryVariations($ebayCategoryId, $siteId, $localInfoOnly =
false)
331 $categoriesVarResult = CategoryVariationTable::getList( array(
332 'select' => array(
'ID',
'NAME',
'REQUIRED'),
333 'order' => array(
'NAME' =>
'ASC'),
334 'filter' => array(
"=CATEGORY_ID" => $ebayCategoryId),
335 'group' => array(
'NAME')
338 while($var = $categoriesVarResult->fetch())
339 $result[$var[
'ID']] = $var;
341 if(empty($result) && !$localInfoOnly)
343 $categories = new \Bitrix\Sale\TradingPlatform\Ebay\Api\Categories($siteId);
344 $rfrCount = $categories->refreshVariationsTableData(array($ebayCategoryId));
346 if(intval($rfrCount) > 0)
347 $result = self::getEbayCategoryVariations($ebayCategoryId, $siteId,
true);
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)