Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
order.php
1<?php
2
4
6use \Bitrix\Sale\TradingPlatform\Logger;
7use \Bitrix\Sale\TradingPlatform\Ebay\Ebay;
8
9class Order extends DataSource implements \Iterator
10{
11 protected $remotePath;
12 protected $siteId;
13 protected $dataFiles = array();
14 protected $currentFileIdx = 0;
15 protected $startFileIdx = 0;
16 protected $orderLatest = "";
17
18 public function __construct($params)
19 {
20 if(!isset($params["FEED_TYPE"]) || $params["FEED_TYPE"] == '')
21 throw new ArgumentNullException("FEED_TYPE");
22
23 $this->remotePath = "/store/".$params["FEED_TYPE"]."/output/".date('M-d-Y', time());
24 $this->orderLatest = "/store/".$params["FEED_TYPE"]."/output/order-latest";
25
26 if(!isset($params["SITE_ID"]) || $params["SITE_ID"] == '')
27 throw new ArgumentNullException("SITE_ID");
28
29 $this->siteId = $params["SITE_ID"];
30 $this->dataFiles = $this->receiveFiles();
31 }
32
33 public function setStartPosition($startPos = "")
34 {
35 if($startPos <> '')
36 $this->startFileIdx = $startPos;
37 }
38
39 public function current()
40 {
41 $content = file_get_contents($this->dataFiles[$this->currentFileIdx]);
42 $skipLength = mb_strtolower(SITE_CHARSET) != 'utf-8' ? 3 : 1;
43 $content = mb_substr($content, $skipLength);
44 $content = "<?xml version='1.0' encoding='UTF-8'?>".$content;
45 return $content;
46 }
47
48 public function key()
49 {
51 }
52
53 public function next()
54 {
55 $this->currentFileIdx++;
56 }
57
58 public function rewind()
59 {
60 $this->currentFileIdx = $this->startFileIdx;
61 }
62
63 public function valid()
64 {
65 return isset($this->dataFiles[$this->currentFileIdx])
66 && $this->dataFiles[$this->currentFileIdx]
67 && \Bitrix\Main\IO\File::isFileExists($this->dataFiles[$this->currentFileIdx]);
68 }
69
70 protected function receiveFiles()
71 {
72 $result = array();
73 $timeToKeepFiles = 24;
74 $tmpDir = \CTempFile::GetDirectoryName($timeToKeepFiles);
75 CheckDirPath($tmpDir);
76
77 $sftp = \Bitrix\Sale\TradingPlatform\Ebay\Helper::getSftp($this->siteId);
78
79 if(!$sftp)
80 return array();
81
82 $sftp->connect();
83
84 /*
85 $orderFiles = $sftp->getFilesList($this->remotePath);
86
87 foreach($orderFiles as $file)
88 {
89 if($sftp->downloadFile($this->remotePath."/".$file, $tmpDir.$file))
90 {
91 $result[] = $tmpDir.$file;
92 Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_SOURCE_ORDERFILE_RECEIVED", $file, "File received successfully.", $this->siteId);
93 }
94 }
95 */
96
97 $file = "orderLatest";
98
99 if($sftp->downloadFile($this->orderLatest, $tmpDir.$file))
100 {
101 $result[] = $tmpDir.$file;
102 Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_SOURCE_ORDERFILE_RECEIVED", $file, "File received successfully.", $this->siteId);
103 }
104
105 return $result;
106 }
107}
static log($level, $type, $itemId, $description, $siteId)
Definition ebay.php:147