<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
if(!CModule::IncludeModule("webservice") || !CModule::IncludeModule("iblock"))
return;
// наш новый класс наследуется от базового IWebService
class CAddGoodsWS extends IWebService
{
function AddGoods($XML_ID, $NAME, $CODE, $QUANTITY, $CATALOG_WEIGHT, $PRICE_1, $CURRENCY_1, $ACTIVE)
{
$iblock_permission = CIBlock::GetPermission(8);
if ($iblock_permission < "W")
{
$GLOBALS["USER"]->RequiredHTTPAuthBasic();
return new CSOAPFault('Server Error', 'Unable to authorize user.');
}
$arFields = Array(
"IBLOCK_ID"=>8, // инфоблок "Товары рус"
"XML_ID"=>$XML_ID,
"NAME"=>$NAME,
"CODE"=>$CODE,
"QUANTITY"=>$QUANTITY,
"CATALOG_WEIGHT"=>$CATALOG_WEIGHT,
"CATALOG_PRICE_1"=>$PRICE_1,
"CATALOG_CURRENCY_1"=>$CURRENCY_1,
"ACTIVE"=>$ACTIVE,
);
$ib_element = new CIBlockElement();
$result = $ib_element->Add($arFields);
if($result>0)
return Array("id"=>$result);
return new CSOAPFault( 'Server Error', 'Error: '.$ib_element->LAST_ERROR );
}
// метод GetWebServiceDesc возвращает описание сервиса и его методов
function GetWebServiceDesc()
{
$wsdesc = new CWebServiceDesc();
$wsdesc->wsname = "bitrix.webservice.addgoods";
$wsdesc->wsclassname = "CAddGoodsWS";
$wsdesc->wsdlauto = true;
$wsdesc->wsendpoint = CWebService::GetDefaultEndpoint();
$wsdesc->wstargetns = CWebService::GetDefaultTargetNS();
$wsdesc->classTypes = array();
$wsdesc->structTypes = Array();
$wsdesc->classes = array(
"CAddGoodsWS"=> array(
"AddGoods" => array(
"type" => "public",
"input" => array(
"XML_ID" => array("varType" => "string"),
"NAME" => array("varType" => "string"),
"CODE" => array("varType" => "string"),
"QUANTITY" => array("varType" => "string"),
"CATALOG_WEIGHT" => array("varType" => "string"),
"CATALOG_PRICE_1" => array("varType" => "string"),
"CATALOG_CURRENCY_1" => array("varType" => "string"),
"ACTIVE" => array("varType" => "string"),
),
"output" => array(
"id" => array("varType" => "integer")
),
"httpauth" => "Y"
),
)
);
return $wsdesc;
}
}
$arParams["WEBSERVICE_NAME"] = "bitrix.webservice.addgoods";
$arParams["WEBSERVICE_CLASS"] = "CAddGoodsWS";
$arParams["WEBSERVICE_MODULE"] = "";
// передаем в компонент описание веб-сервиса
$APPLICATION->IncludeComponent(
"bitrix:webservice.server",
"",
$arParams
);
die();
?>
|