1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
categories.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\TradingPlatform\Ebay\Api;
4
5use Bitrix\Main\Text\Encoding;
6use Bitrix\Sale\TradingPlatform\Xml2Array;
7use Bitrix\Sale\TradingPlatform\Ebay\CategoryTable;
8use Bitrix\Sale\TradingPlatform\Ebay\CategoryVariationTable;
9
10class Categories extends Entity
11{
12 protected function getItems(array $params = array())
13 {
14 $data = '<?xml version="1.0" encoding="utf-8"?>
15 <GetCategoriesRequest xmlns="urn:ebay:apis:eBLBaseComponents">
16 <RequesterCredentials>
17 <eBayAuthToken>'.$this->authToken.'</eBayAuthToken>
18 </RequesterCredentials>
19 <CategorySiteID>'.$this->ebaySiteId.'</CategorySiteID>
20 <WarningLevel>'.$this->warningLevel.'</WarningLevel>'."\n";
21
22 $data .= $this->array2Tags($params);
23 $data .= '</GetCategoriesRequest>?';
24
25 $categoriesXml = $this->apiCaller->sendRequest("GetCategories", $data);
26
27 $result = Xml2Array::convert($categoriesXml);
28 return $result;
29 }
30
31 protected function getTopItems()
32 {
33 return $this->getItems(array(
34 "LevelLimit" => 1,
35 "DetailLevel" => "ReturnAll"
36 ));
37 }
38
39 public function refreshTableData()
40 {
41 $refreshedCount = 0;
42 $catInfo = $this->getItems(array("DetailLevel" => "ReturnAll"));
43 $existCategoriesList = array();
44
45 $res = CategoryTable::getList(array(
46 "select" => array("ID", "CATEGORY_ID")
47 ));
48
49 while($category = $res->fetch())
50 $existCategoriesList[$category["CATEGORY_ID"]] = $category["ID"];
51
52 if(isset($catInfo["CategoryArray"]["Category"]))
53 {
54 $categories = Xml2Array::normalize($catInfo["CategoryArray"]["Category"]);
55
56 foreach($categories as $category)
57 {
58 $fields = array(
59 "CATEGORY_ID" => $category["CategoryID"],
60 "LEVEL" => $category["CategoryLevel"],
61 "NAME" => $category["CategoryName"],
62 "PARENT_ID" => $category["CategoryParentID"]
63 );
64
65 if(array_key_exists($category["CategoryID"], $existCategoriesList))
66 $result = CategoryTable::update($existCategoriesList[$category["CategoryID"]], $fields);
67 else
68 $result = CategoryTable::add($fields);
69
70 if($result->isSuccess())
71 {
72 $refreshedCount++;
73 }
74 }
75 }
76
77 return $refreshedCount;
78 }
79
81 {
82 $data = '<?xml version="1.0" encoding="utf-8"?>
83 <GetCategorySpecificsRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
84 $data.= $this->array2Tags($params);
85 $data.= '<RequesterCredentials>
86 <eBayAuthToken>'.$this->authToken.'</eBayAuthToken>
87 </RequesterCredentials>
88 <WarningLevel>'.$this->warningLevel.'</WarningLevel>
89 </GetCategorySpecificsRequest>?';
90
91 return $this->apiCaller->sendRequest("GetCategorySpecifics", $data);
92 }
93
94 protected function getMappedCategories()
95 {
97 $settings = $ebay->getSettings();
98 $iblocksIds = array();
99 $result = array();
100
101 foreach($settings[$this->siteId]["IBLOCK_ID"] as $iblockId)
103
104 $catMapRes = \Bitrix\Sale\TradingPlatform\MapTable::getList(array(
105 "filter" => array(
106 "ENTITY_ID" => $iblocksIds
107 )
108 ));
109
110 while($arMapRes = $catMapRes->fetch())
111 $result = $arMapRes["VALUE_EXTERNAL"];
112
113 return $result;
114 }
115
116 public function refreshVariationsTableData(array $ebayCategoriesIds = array())
117 {
118 $refreshedCount = 0;
119
120 $specXml = $this->getItemSpecifics(array(
121 "CategoryID" => empty($ebayCategoriesIds) ? $this->getMappedCategories() : $ebayCategoriesIds
122 ));
123
124 $specifics = new \SimpleXMLElement($specXml, LIBXML_NOCDATA);
125
126 foreach($specifics->Recommendations as $categoryRecommendation)
127 {
128 foreach($categoryRecommendation->NameRecommendation as $nameRecommendation)
129 {
130 $fields = array(
131 "CATEGORY_ID" => $categoryRecommendation->CategoryID->__toString(),
132 "NAME" => $nameRecommendation->Name->__toString()
133 );
134
135 if(isset($nameRecommendation->ValidationRules))
136 {
137
138 if($nameRecommendation->ValidationRules->MinValues)
139 $fields["MIN_VALUES"] = $nameRecommendation->ValidationRules->MinValues->__toString();
140 else
141 $fields["MIN_VALUES"] = 0;
142
143 if($nameRecommendation->ValidationRules->MinValues)
144 $fields["MAX_VALUES"] = $nameRecommendation->ValidationRules->MaxValues->__toString();
145 else
146 $fields["MAX_VALUES"] = 0;
147
148 $fields["REQUIRED"] = intval($fields["MIN_VALUES"]) > 0 ? "Y" : "N";
149 $fields["SELECTION_MODE"] = $nameRecommendation->ValidationRules->SelectionMode->__toString();
150 $fields["ALLOWED_AS_VARIATION"] = $nameRecommendation->ValidationRules->VariationSpecifics->__toString() == "Enabled" ? "Y" : "N";
151 $fields["HELP_URL"] = $nameRecommendation->ValidationRules->HelpURL->__toString();
152 }
153
154 if(isset($nameRecommendation->ValueRecommendation))
155 {
156 $values = array();
157
158 foreach($nameRecommendation->ValueRecommendation as $valueRecommendation)
159 $values[] = $valueRecommendation->Value->__toString();
160
161 $fields["VALUE"] = $values;
162 }
163
164 $res = CategoryVariationTable::getList(array(
165 "filter" => array(
166 "CATEGORY_ID" => $fields["CATEGORY_ID"],
167 "NAME" => $fields["NAME"]
168 ),
169 "select" => array("ID")
170 ));
171
172 if($savedVar = $res->fetch())
173 $result = CategoryVariationTable::update($savedVar["ID"], $fields);
174 else
175 $result = CategoryVariationTable::add($fields);
176
177 if($result->isSuccess())
178 {
179 $refreshedCount++;
180 }
181 }
182 }
183
184 return $refreshedCount;
185 }
186}
getItems(array $params=array())
Определения categories.php:12
refreshVariationsTableData(array $ebayCategoriesIds=array())
Определения categories.php:116
getItemSpecifics(array $params)
Определения categories.php:80
array2Tags(array $params)
Определения entity.php:42
static update($primary, array $data)
Определения category.php:133
static getInstance()
Определения ebay.php:23
static getCategoryEntityId($iblockId)
Определения maphelper.php:60
static convert($xmlData)
Определения xml2array.php:15
static normalize(array $branch)
Определения xml2array.php:69
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$iblockId
Определения iblock_catalog_edit.php:30
$settings
Определения product_settings.php:43
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$fields
Определения yandex_run.php:501