Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
image.php
1<?php
2
4
6
7class Image extends DataConverter
8{
9 protected $siteId;
10 protected $morePhotoProp;
11 protected $domainName;
12
13 public function __construct($params)
14 {
15 if(!isset($params["SITE_ID"]) || $params["SITE_ID"] == '')
16 throw new ArgumentNullException("SITE_ID");
17
18 $this->siteId = $params["SITE_ID"];
19 }
20
21 public function convert($data)
22 {
23 $result = "";
24 $ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
25 $ebaySettings = $ebay->getSettings();
26 $this->morePhotoProp = isset($ebaySettings[$this->siteId]["MORE_PHOTO_PROP"][$data["IBLOCK_ID"]]) ? $ebaySettings[$this->siteId]["MORE_PHOTO_PROP"][$data["IBLOCK_ID"]] : null;
27
28 if(!$this->morePhotoProp)
29 return "";
30
31 $this->domainName = isset($ebaySettings[$this->siteId]["DOMAIN_NAME"]) ? $ebaySettings[$this->siteId]["DOMAIN_NAME"] : null;
32
33 if(!empty($data["OFFERS"]) && is_array($data["OFFERS"]))
34 {
35 foreach($data["OFFERS"] as $offer)
36 $result .= $this->getItemData($offer, $data["IBLOCK_ID"]."_".$data["ID"]."_".$offer["ID"]);
37 }
38 else
39 {
40 $result = $this->getItemData($data, $data["IBLOCK_ID"]."_".$data["ID"]);
41 }
42
43 return $result;
44 }
45
46 protected function getItemData($data, $sku)
47 {
48 $morePhotoValue = array();
49
50 if(empty($data["PROPERTIES"]) || !is_array($data["PROPERTIES"]))
51 return "";
52
53 foreach($data["PROPERTIES"] as $propCode => $propParams)
54 {
55 if($propParams["ID"] == $this->morePhotoProp)
56 {
57 if(!empty($propParams["VALUE"]) && is_array($propParams["VALUE"]))
58 {
59 $morePhotoValue = $propParams["VALUE"];
60 break;
61 }
62 else
63 {
64 return "";
65 }
66 }
67 }
68
69 $pictureUrls = "";
70
71 foreach($morePhotoValue as $value)
72 {
73 $pictureUrl = $this->getPictureUrl($value);
74
75 if($pictureUrl <> '')
76 $pictureUrls .= "\t\t<URL>".$pictureUrl."</URL>\n";
77 }
78
79 if($pictureUrls == '')
80 return "";
81
82 $result = "\t<Image>\n".
83 "\t\t<SKU>".$sku."</SKU>\n".
84 $pictureUrls.
85 "\t</Image>\n";
86
87 return $result;
88 }
89
90 protected function getPictureUrl($pictNo)
91 {
92 $strFile = "";
93
94 if ($file = \CFile::GetFileArray($pictNo))
95 {
96 if(mb_substr($file["SRC"], 0, 1) == "/")
97 $strFile = "http://".$this->domainName.implode("/", array_map("rawurlencode", explode("/", $file["SRC"])));
98 elseif(preg_match("/^(http|https):\\/\\/(.*?)\\/(.*)\$/", $file["SRC"], $match))
99 $strFile = "http://".$match[2].'/'.implode("/", array_map("rawurlencode", explode("/", $match[3])));
100 else
101 $strFile = $file["SRC"];
102 }
103
104 return $strFile;
105 }
106
107}