28 if(!isset($_POST[
"SALE"][
"EBAY"]))
32 $ebayCategoryId = isset($_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_ID"]) ? $_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_ID"] :
"";
35 if(!empty($_POST[
"SALE"][
"EBAY"][
"POLICY"]) && is_array($_POST[
"SALE"][
"EBAY"][
"POLICY"]))
37 $ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
38 $settings = $ebay->getSettings();
39 $siteSettings = $settings[$arArgs[
"IBLOCK"][
"LID"]];
41 if($_POST[
"SALE"][
"EBAY"][
"POLICY"][
"RETURN"] == $siteSettings[
"POLICY"][
"RETURN"][
"DEFAULT"])
42 unset($_POST[
"SALE"][
"EBAY"][
"POLICY"][
"RETURN"]);
44 if($_POST[
"SALE"][
"EBAY"][
"POLICY"][
"PAYMENT"] == $siteSettings[
"POLICY"][
"PAYMENT"][
"DEFAULT"])
45 unset($_POST[
"SALE"][
"EBAY"][
"POLICY"][
"PAYMENT"]);
47 if($_POST[
"SALE"][
"EBAY"][
"POLICY"][
"SHIPPING"] == $siteSettings[
"POLICY"][
"SHIPPING"][
"DEFAULT"])
48 unset($_POST[
"SALE"][
"EBAY"][
"POLICY"][
"SHIPPING"]);
50 if(!empty($_POST[
"SALE"][
"EBAY"][
"POLICY"]))
51 $params = array(
"POLICY" => $_POST[
"SALE"][
"EBAY"][
"POLICY"]);
54 $catRes =
self::saveCategoryMap($arArgs[
"ID"], $arArgs[
"IBLOCK"][
"ID"], array($ebayCategoryId), $params);
57 isset($_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_VARIATIONS"])
58 && is_array($_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_VARIATIONS"])
59 && isset($_POST[
"SALE"][
"EBAY"][
"BITRIX_CATEGORY_PROPS"])
60 && is_array($_POST[
"SALE"][
"EBAY"][
"BITRIX_CATEGORY_PROPS"])
63 $propsRes =
self::saveCategoryPropsMap($arArgs[
"IBLOCK"][
"ID"], $ebayCategoryId, $_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_VARIATIONS"], $_POST[
"SALE"][
"EBAY"][
"BITRIX_CATEGORY_PROPS"]);
66 return $catRes && $propsRes;
69 protected function saveCategoryPropsMap($iblockId, $ebayCategoryId, array $ebayCatVar, array $bitrixCatProps)
75 foreach($ebayCatVar as $key => $ebayCategoryVariation)
77 if(!isset($bitrixCatProps[$key]) || $ebayCategoryVariation ==
'' )
81 "ENTITY_ID" => $mapEntityId,
82 "VALUE_EXTERNAL" => $ebayCategoryVariation,
83 "VALUE_INTERNAL" => $bitrixCatProps[$key]
86 $addRes = MapTable::add($fields);
87 $result = $result && $addRes->isSuccess();
93 protected function saveCategoryMap($bitrixCategoryId, $iblockId, array $ebayCategoriesIds, $params = array())
99 foreach($ebayCategoriesIds as $ebayCategoryId)
101 if(trim($ebayCategoryId) ==
'')
105 "ENTITY_ID" => $catMapEntId,
106 "VALUE_INTERNAL" => $bitrixCategoryId
109 $dbRes = MapTable::getList(array(
113 $fields[
"VALUE_EXTERNAL"] = $ebayCategoryId;
115 $fields[
"PARAMS"] = $params;
117 if($map = $dbRes->fetch())
118 $res = MapTable::update($map[
'ID'], $fields);
120 $res = MapTable::add($fields);
122 $result = $result && $res->isSuccess();
170 $ebay = \Bitrix\Sale\TradingPlatform\Ebay\Ebay::getInstance();
171 $settings = $ebay->getSettings();
173 if(empty($settings[$arArgs[
"IBLOCK"][
"LID"]]))
176 $siteSettings = $settings[$arArgs[
"IBLOCK"][
"LID"]];
183 '<td width="40%" valign="top">'.Loc::getMessage(
"SALE_EBAY_CSTH_CATEGORY").
':</td>'.
186 $catMapRes = \Bitrix\Sale\TradingPlatform\MapTable::getList(array(
189 "VALUE_INTERNAL" => $arArgs[
"ID"]
193 $arMapRes = $catMapRes->fetch();
196 "TOP_CATEGORY_SELECT_NAME" =>
"SALE[EBAY][TOP_CATEGORY]",
197 "CATEGORY_INPUT_NAME" =>
"SALE[EBAY][EBAY_CATEGORY_ID]",
198 "EBAY_CATEGORY_VARIATIONS_SN" =>
"SALE[EBAY][EBAY_CATEGORY_VARIATIONS]",
199 "BITRIX_CATEGORY_PROPS_SN" =>
"SALE[EBAY][BITRIX_CATEGORY_PROPS]",
200 "BITRIX_CATEGORY_ID"=> $arArgs[
"ID"],
201 "IBLOCK_ID" => $arArgs[
"IBLOCK"][
"ID"]
205 if(isset($_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_ID"]))
206 $params[
"EBAY_CATEGORY_ID"] = $_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_ID"];
207 elseif(isset($arMapRes[
"VALUE_EXTERNAL"]))
208 $params[
"EBAY_CATEGORY_ID"] = $arMapRes[
"VALUE_EXTERNAL"];
210 if(isset($_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_VARIATIONS"]) && isset($_POST[
"SALE"][
"EBAY"][
"BITRIX_CATEGORY_PROPS"]))
212 $params[
"VARIATIONS_VALUES"] = array();
214 for($i=0, $l=count($_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_VARIATIONS"]); $i<$l; $i++)
215 $params[
"VARIATIONS_VALUES"][$_POST[
"SALE"][
"EBAY"][
"EBAY_CATEGORY_VARIATIONS"][$i]] = $_POST[
"SALE"][
"EBAY"][
"BITRIX_CATEGORY_PROPS"][$i];
219 $APPLICATION->IncludeComponent(
220 "bitrix:sale.ebay.categories",
225 $resultHtml .= ob_get_contents();
237 $policyShipping =
"";
239 if(isset($_POST[
"SALE"][
"EBAY"][
"POLICY"]))
241 if(!empty($_POST[
"SALE"][
"EBAY"][
"POLICY"][
"RETURN"]))
242 $policyReturn = $_POST[
"SALE"][
"EBAY"][
"POLICY"][
"RETURN"];
244 if(!empty($_POST[
"SALE"][
"EBAY"][
"POLICY"][
"SHIPPING"]))
245 $policyShipping = $_POST[
"SALE"][
"EBAY"][
"POLICY"][
"SHIPPING"];
247 if(!empty($_POST[
"SALE"][
"EBAY"][
"POLICY"][
"PAYMENT"]))
248 $policyPayment = $_POST[
"SALE"][
"EBAY"][
"POLICY"][
"PAYMENT"];
250 elseif(!empty($arMapRes[
"PARAMS"][
"POLICY"]))
252 if(!empty($arMapRes[
"PARAMS"][
"POLICY"][
"RETURN"]))
253 $policyReturn = $arMapRes[
"PARAMS"][
"POLICY"][
"RETURN"];
255 if(!empty($arMapRes[
"PARAMS"][
"POLICY"][
"SHIPPING"]))
256 $policyShipping = $arMapRes[
"PARAMS"][
"POLICY"][
"SHIPPING"];
258 if(!empty($arMapRes[
"PARAMS"][
"POLICY"][
"PAYMENT"]))
259 $policyPayment = $arMapRes[
"PARAMS"][
"POLICY"][
"PAYMENT"];
262 if($policyReturn ==
'' && !empty($siteSettings[
"POLICY"][
"RETURN"][
"DEFAULT"]))
263 $policyReturn = $siteSettings[
"POLICY"][
"RETURN"][
"DEFAULT"];
265 if($policyShipping ==
'' && !empty($siteSettings[
"POLICY"][
"SHIPPING"][
"DEFAULT"]))
266 $policyShipping = $siteSettings[
"POLICY"][
"SHIPPING"][
"DEFAULT"];
268 if($policyPayment ==
'' && !empty($siteSettings[
"POLICY"][
"PAYMENT"][
"DEFAULT"]))
269 $policyPayment = $siteSettings[
"POLICY"][
"PAYMENT"][
"DEFAULT"];
271 if(isset($siteSettings[
"API"][
"AUTH_TOKEN"]) && $siteSettings[
"API"][
"AUTH_TOKEN"] <>
'')
272 $policy = new \Bitrix\Sale\TradingPlatform\Ebay\Policy($siteSettings[
"API"][
"AUTH_TOKEN"], $arArgs[
"IBLOCK"][
"LID"]);
274 $errorMsg .=
"You must set API token first!\n";
277 <tr></tr><td colspan="2" style="border-top: 2px solid #e0e8ea;"> </td></tr>
279 <td>'.Loc::getMessage(
"SALE_EBAY_CSTH_POLICY_RETURN").
':</span></td>
287 if($policy && !empty($names))
289 $resultHtml .=
'<select name="SALE[EBAY][POLICY][RETURN]">';
291 foreach($names as $policyId => $policyName)
292 $resultHtml .=
'<option value="'.htmlspecialcharsbx($policyId).
'"'.($policyReturn == $policyId ?
" selected" :
"").
'>'.$policyName.
'</option>';
294 $resultHtml .=
'</select>';
305 <td>'.Loc::getMessage(
"SALE_EBAY_CSTH_POLICY_SHIPMENT").
':</td>
314 if($policy && !empty($names))
316 $resultHtml .=
'<select name="SALE[EBAY][POLICY][SHIPPING]">';
318 foreach($names as $policyId => $policyName)
319 $resultHtml .=
'<option value="'.htmlspecialcharsbx($policyId).
'"'.($policyShipping == $policyId ?
" selected" :
"").
'>'.$policyName.
'</option>';
321 $resultHtml .=
'</select>';
332 <td>'.Loc::getMessage(
"SALE_EBAY_CSTH_POLICY_PAYMENT").
':</td>
340 if($policy && !empty($names))
342 $resultHtml .=
'<select name="SALE[EBAY][POLICY][PAYMENT]">';
345 $resultHtml .=
'<option value="'.htmlspecialcharsbx($policyId).
'"'.($policyPayment == $policyId ?
" selected" :
"").
'>'.$policyName.
'</option>';
347 $resultHtml .=
'</select>';
358 <td> </td><td><a href="http://www.bizpolicy.ebay.ru/businesspolicy/manage?totalPages=1">'.Loc::getMessage(
'SALE_EBAY_CSTH_EDIT_POLICIES').
'</a></td>