function AddProduct($NAME)
 {
     $iblock_permission = CIBlock::GetPermission(IBLOCK_ID);
     if ($iblock_permission < "W") {
         $GLOBALS["USER"]->RequiredHTTPAuthBasic();
         return new CSOAPFault('Server Error', 'Unable to authorize user.');
     }
     $code = self::translit($NAME);
     $i = 1;
     while (true) {
         $res = CIBlockElement::Getlist(array(), array("CODE" => $code), false, array("CODE"));
         if ($res->Fetch()) {
             $code = self::translit($NAME) . $i;
         } else {
             break;
         }
         $i++;
     }
     $arFields = array("IBLOCK_ID" => IBLOCK_ID, "NAME" => $NAME);
     $ib_element = new CIBlockElement();
     $result = $ib_element->Add($arFields);
     if ($result > 0) {
         return $result;
     }
     return new CSOAPFault('Server Error', 'Error: ' . $ib_element->LAST_ERROR);
 }
Beispiel #2
0
 public function GetElement($types, $MS)
 {
     $strXML = "";
     $arSort = array("ID" => "ASC");
     $arResult["OFFER"] = array();
     if (self::CheckArray($this->IBLOCK_ID)) {
         foreach ($this->IBLOCK_ID as $ibl) {
             $rsElements = CIBlockElement::Getlist($arSort, $this->arFilter[$ibl], false, false, $this->arSelect);
             if ($this->DETAIL_PAGE_URL) {
                 $rsElements->SetUrlTemplates($this->DETAIL_PAGE_URL);
             }
             while ($arOffer = $rsElements->GetNext()) {
                 $flag = 0;
                 if ($this->USE_SKU && $this->sku_IBLOCK_ID[$ibl] > 0) {
                     if (is_array($this->arSKU_Filter[$ibl]) && sizeof($this->arSKU_Filter[$ibl]) > 0) {
                         $skuFILTER = $this->arSKU_Filter[$ibl];
                         $skuFILTER["IBLOCK_ID"] = $this->sku_IBLOCK_ID[$ibl];
                         $skuFILTER[CGMExport::GetProp($this->sku_PROPERTY[$ibl])] = $arOffer["ID"];
                         $skuFILTER["ACTIVE"] = "Y";
                     } else {
                         $skuFILTER["IBLOCK_ID"] = $this->sku_IBLOCK_ID[$ibl];
                         $skuFILTER["ACTIVE"] = "Y";
                         $skuFILTER[CGMExport::GetProp($this->sku_PROPERTY[$ibl])] = $arOffer["ID"];
                     }
                     $arOfferInOb = CIBLockElement::GetList($arSort, $skuFILTER, false, false, $this->arSelect);
                     if ($this->DETAIL_PAGE_URL) {
                         $arOfferInOb->SetUrlTemplates($this->DETAIL_PAGE_URL);
                     }
                     while ($arOfferIn = $arOfferInOb->GetNext()) {
                         $flag = 1;
                         $arOfferIn1["g:availability"] = "in stock";
                         $arOfferIn1["g:id"] = $arOfferIn["ID"];
                         $arOfferIn1["g:condition"] = $this->CONDITIONS;
                         $arOfferIn1["g:item_group_id"] = $arOffer["ID"];
                         switch ($this->NAMESCHEMA) {
                             case "NAME_OFFER":
                                 $arOfferIn1["title"] = text2xml($arOffer["NAME"], true, true, $this->ENCODING);
                                 break;
                             case "NAME_OFFER_SKU":
                                 $arOfferIn1["title"] = text2xml($arOffer["NAME"] . "/" . $arOfferIn["NAME"], true, true, $this->ENCODING);
                                 break;
                             default:
                                 $arOfferIn1["title"] = text2xml($arOfferIn["NAME"], true, true, $this->ENCODING);
                                 break;
                         }
                         $arOfferIn1["g:price"] = $this->yandex_GetPrice(array("IBLOCK_ID" => $this->sku_IBLOCK_ID[$ibl], "ID" => $arOfferIn["ID"]));
                         if ($arOfferIn1["g:price"] > 0) {
                             $arOfferIn1["g:price"] .= " " . $this->baseCur;
                         }
                         $tr = CCatalogProduct::GetByID($arOfferIn["ID"]);
                         if ($tr["QUANTITY_TRACE"] == "N") {
                             $arOfferIn1["g:availability"] = "in stock";
                         } else {
                             if ($tr["QUANTITY"] > 0) {
                                 $arOfferIn1["g:availability"] = "in stock";
                             } else {
                                 if ($this->FORORDER) {
                                     $arOfferIn1["g:availability"] = "preorder";
                                 } else {
                                     $arOfferIn1["g:availability"] = "out of stock";
                                 }
                             }
                         }
                         $arOfferIn1["g:product_type"] = str_replace(">", "&gt;", $this->GOOGLE_CATEGORY[$arOffer["IBLOCK_SECTION_ID"]]["THIS"]);
                         $arOfferIn1["g:google_product_category"] = str_replace(">", "&gt;", $this->GOOGLE_CATEGORY[$arOffer["IBLOCK_SECTION_ID"] ? $arOffer["IBLOCK_SECTION_ID"] : $arOffer["IBLOCK_ID"]]["GOOGLE"]);
                         if ($arOffer["DETAIL_PAGE_URL"]) {
                             $arOfferIn1["g:link_href"] = "http://" . $this->DOMAIN_NAME . $arOffer["DETAIL_PAGE_URL"] . "#" . $arOfferIn["ID"];
                         } else {
                             $arOfferIn1["g:link_href"] = "http://" . $this->DOMAIN_NAME . $arOffer["DETAIL_PAGE_URL"];
                         }
                         if ($arOfferIn["PREVIEW_PICTURE"]) {
                             $db_file = CFile::GetByID($arOfferIn["PREVIEW_PICTURE"]);
                             if ($ar_file = $db_file->Fetch()) {
                                 $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                             }
                         }
                         if ($arOfferIn["DETAIL_PICTURE"]) {
                             $db_file = CFile::GetByID($arOfferIn["DETAIL_PICTURE"]);
                             if ($ar_file = $db_file->Fetch()) {
                                 $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                             }
                         }
                         if ($this->GetPropInData("g:image_link", $this->XML_DATA)) {
                             $ph = CIBlockElement::GetProperty($this->sku_IBLOCK_ID, $arOfferIn["ID"], array("sort" => "asc"), array("ID" => $this->GetPropInData("g:image_link", $this->XML_DATA)));
                             while ($ob = $ph->GetNext()) {
                                 $arFile = CFile::GetFileArray($ob["VALUE"]);
                                 if (!empty($arFile)) {
                                     if (strpos($arFile["SRC"], "http") === false) {
                                         $pic = "http://" . $this->DOMAIN_NAME . implode("/", array_map("rawurlencode", explode("/", $arFile["SRC"])));
                                     } else {
                                         $ar = explode("http://", $arFile["SRC"]);
                                         $pic = "http://" . implode("/", array_map("rawurlencode", explode("/", $ar[1])));
                                     }
                                     $arOfferIn1["g:image_link"][] = $pic;
                                 }
                             }
                         }
                         if (!$arOfferIn["g:image_link"]) {
                             if ($arOffer["PREVIEW_PICTURE"]) {
                                 $db_file = CFile::GetByID($arOffer["PREVIEW_PICTURE"]);
                                 if ($ar_file = $db_file->Fetch()) {
                                     $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                                 }
                             }
                             if ($arOffer["DETAIL_PICTURE"]) {
                                 $db_file = CFile::GetByID($arOffer["DETAIL_PICTURE"]);
                                 if ($ar_file = $db_file->Fetch()) {
                                     $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                                 }
                             }
                             if ($this->GetPropInData("g:image_link", $this->XML_DATA)) {
                                 $ph = CIBlockElement::GetProperty($this->IBLOCK_ID, $arOffer["ID"], array("value_id" => "asc"), array("ID" => $this->GetPropInData("g:image_link", $this->XML_DATA)))->Fetch();
                                 $db_file = CFile::GetByID($ph["VALUE"]);
                                 if ($ar_file = $db_file->Fetch()) {
                                     $arOfferIn1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                                 }
                             }
                         }
                         if ($arOfferIn["PREVIEW_TEXT"]) {
                             $arOfferIn["PREVIEW_TEXT"] = text2xml($arOfferIn["PREVIEW_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferIn["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferIn["~PREVIEW_TEXT"]), true, true, $this->ENCODING);
                         }
                         if ($arOfferIn["DETAIL_TEXT"]) {
                             $arOfferIn["DETAIL_TEXT"] = text2xml($arOfferIn["DETAIL_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferIn["~DETAIL_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOfferIn["~DETAIL_TEXT"]), true, true, $this->ENCODING);
                         }
                         $arOfferIn1["description"] = strlen($arOfferIn["PREVIEW_TEXT"]) > strlen($arOfferIn["DETAIL_TEXT"]) ? $arOfferIn["PREVIEW_TEXT"] : $arOfferIn["DETAIL_TEXT"];
                         if ($this->GetPropInData("description", $this->XML_DATA)) {
                             $ph = CIBlockElement::GetProperty($this->sku_IBLOCK_ID, $arOfferIn["ID"], array("value_id" => "asc"), array("ID" => $this->GetPropInData("description", $this->XML_DATA)))->Fetch();
                             $arOfferIn1["description"] = text2xml($ph["VALUE"], true, true, $this->ENCODING);
                         }
                         if (!$arOfferIn1["description"]) {
                             if ($arOffer["PREVIEW_TEXT"]) {
                                 $arOffer["PREVIEW_TEXT"] = text2xml($arOffer["PREVIEW_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~PREVIEW_TEXT"]), true, true, $this->ENCODING);
                             }
                             if ($arOffer["DETAIL_TEXT"]) {
                                 $arOffer["DETAIL_TEXT"] = text2xml($arOffer["DETAIL_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~DETAIL_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~DETAIL_TEXT"]), true, true, $this->ENCODING);
                             }
                             $arOfferIn1["description"] = strlen($arOffer["PREVIEW_TEXT"]) > strlen($arOffer["DETAIL_TEXT"]) ? $arOffer["PREVIEW_TEXT"] : $arOffer["DETAIL_TEXT"];
                         }
                         $tmpmas = $this->GetXMLData($arOfferIn);
                         if (is_array($tmpmas) && sizeof($tmpmas) > 0) {
                             foreach ($tmpmas as $code => $xml) {
                                 $arOfferIn1[$xml["PARAM"]][] = $xml["VALUE"];
                             }
                         }
                         if (intval($arOfferIn1["g:price"]) <= 0) {
                             continue;
                         }
                         foreach ($arOfferIn1 as $id => $val) {
                             if (is_array($val) && sizeof($val) > 0) {
                                 $arOfferIn1[$id] = array_filter(array_unique($val));
                                 if (sizeof($arOfferIn1[$id]) == 1) {
                                     $arOfferIn1[$id] = array_shift($arOfferIn1[$id]);
                                 }
                             }
                         }
                         $strXML .= $this->BuildXml($arOfferIn1, $types, $MS);
                         unset($arOfferIn1);
                     }
                     if ($flag == 1) {
                         continue;
                     }
                 }
                 $arOffer1["g:availability"] = true;
                 $arOffer1["g:id"] = $arOffer["ID"];
                 $arOffer1["g:condition"] = $this->CONDITIONS;
                 $arOffer1["title"] = text2xml($arOffer["NAME"], true, true, $this->ENCODING);
                 if (!$this->isCat) {
                     if ($this->GetPropInData("quantity", $this->XML_DATA)) {
                         $av = CIBlockElement::GetProperty($arOffer["IBLOCK_ID"], $arOffer["ID"], array("sort" => "asc"), array("ID" => $this->GetPropInData("quantity", $this->XML_DATA)))->Fetch();
                         if (IntVal($av["VALUE"]) > 0) {
                             $arOffer1["g:availability"] = "in stock";
                         } else {
                             if ($this->FORORDER) {
                                 $arOffer1["g:availability"] = "preorder";
                             } else {
                                 $arOffer1["g:availability"] = "out of stock";
                             }
                         }
                     }
                 }
                 $arOffer1["g:price"] = $this->yandex_GetPrice(array("IBLOCK_ID" => $ibl, "ID" => $arOffer['ID']));
                 if ($arOffer1["g:price"] > 0) {
                     $arOffer1["g:price"] .= " " . $this->baseCur;
                 }
                 if ($this->isCat) {
                     $tr = CCatalogProduct::GetByID($arOffer["ID"]);
                     if ($tr["QUANTITY_TRACE"] == "N") {
                         $arOffer1["g:availability"] = "in stock";
                     } else {
                         if ($tr["QUANTITY"] > 0) {
                             $arOffer1["g:availability"] = "in stock";
                         } else {
                             if ($this->FORORDER) {
                                 $arOffer1["g:availability"] = "preorder";
                             } else {
                                 $arOffer1["g:availability"] = "out of stock";
                             }
                         }
                     }
                 }
                 $arOffer1["g:product_type"] = str_replace(">", "&gt;", $this->GOOGLE_CATEGORY[$arOffer["IBLOCK_SECTION_ID"]]["THIS"]);
                 $arOffer1["g:google_product_category"] = str_replace(">", "&gt;", $this->GOOGLE_CATEGORY[$arOffer["IBLOCK_SECTION_ID"] ? $arOffer["IBLOCK_SECTION_ID"] : $arOffer["IBLOCK_ID"]]["GOOGLE"]);
                 if ($arOffer["DETAIL_PAGE_URL"]) {
                     $arOffer1["g:link_href"] = "http://" . $this->DOMAIN_NAME . $arOffer["DETAIL_PAGE_URL"];
                 }
                 if ($arOffer["PREVIEW_PICTURE"]) {
                     $db_file = CFile::GetByID($arOffer["PREVIEW_PICTURE"]);
                     if ($ar_file = $db_file->Fetch()) {
                         $arOffer1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                     }
                 }
                 if ($arOffer["DETAIL_PICTURE"]) {
                     $db_file = CFile::GetByID($arOffer["DETAIL_PICTURE"]);
                     if ($ar_file = $db_file->Fetch()) {
                         $arOffer1["g:image_link"] = "http://" . $this->DOMAIN_NAME . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $ar_file["SUBDIR"] . "/" . implode("/", array_map("rawurlencode", explode("/", $ar_file["FILE_NAME"])));
                     }
                 }
                 if ($this->GetPropInData("g:image_link", $this->XML_DATA)) {
                     $ph = CIBlockElement::GetProperty($arOffer['IBLOCK_ID'], $arOffer["ID"], array("sort" => "asc"), array("ID" => $this->GetPropInData("g:image_link", $this->XML_DATA)));
                     while ($ob = $ph->GetNext()) {
                         $arFile = CFile::GetFileArray($ob["VALUE"]);
                         if (!empty($arFile)) {
                             if (strpos($arFile["SRC"], "http") === false) {
                                 $pic = "http://" . $this->DOMAIN_NAME . implode("/", array_map("rawurlencode", explode("/", $arFile["SRC"])));
                             } else {
                                 $ar = explode("http://", $arFile["SRC"]);
                                 $pic = "http://" . implode("/", array_map("rawurlencode", explode("/", $ar[1])));
                             }
                             $arOffer1["g:image_link"][] = $pic;
                         }
                     }
                 }
                 if ($arOffer["PREVIEW_TEXT"]) {
                     $arOffer["PREVIEW_TEXT"] = text2xml($arOffer["PREVIEW_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~PREVIEW_TEXT"]), true, true, $this->ENCODING);
                 }
                 if ($arOffer["DETAIL_TEXT"]) {
                     $arOffer["DETAIL_TEXT"] = text2xml($arOffer["DETAIL_TEXT_TYPE"] == "html" ? strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~DETAIL_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arOffer["~DETAIL_TEXT"]), true, true, $this->ENCODING);
                 }
                 $arOffer1["description"] = strlen($arOffer["PREVIEW_TEXT"]) > strlen($arOffer["DETAIL_TEXT"]) ? $arOffer["PREVIEW_TEXT"] : $arOffer["DETAIL_TEXT"];
                 if ($this->GetPropInData("description", $this->XML_DATA)) {
                     $ph = CIBlockElement::GetProperty($arOffer, $arOffer["ID"], array("value_id" => "asc"), array("ID" => $this->GetPropInData("description", $this->XML_DATA)))->Fetch();
                     $arOffer1["description"] = text2xml($ph["VALUE"], true, true, $this->ENCODING);
                 }
                 $tmpmas = $this->GetXMLData($arOffer);
                 if (is_array($tmpmas) && sizeof($tmpmas) > 0) {
                     foreach ($tmpmas as $code => $xml) {
                         $arOffer1[$xml["PARAM"]][$code] = $xml["VALUE"];
                     }
                 }
                 if (intval($arOffer1["g:price"]) <= 0) {
                     continue;
                 }
                 $strXML .= $this->BuildXml($arOffer1, $types, $MS);
                 unset($arOffer1);
             }
         }
     }
     return $strXML;
 }