Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 53.98 KB | None | 0 0
  1. <?php
  2. if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/constants.php"))
  3. require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/constants.php");
  4.  
  5. if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/functions.php"))
  6. require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/functions.php");
  7.  
  8. /*
  9. if(file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/include/agent.php"))
  10. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/include/agent.php");
  11.  
  12. if(file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/include/reviews.php"))
  13. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/include/reviews.php");
  14. */
  15. if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/event_handlers.php"))
  16. require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/include/event_handlers.php");
  17.  
  18. /*
  19. AddEventHandler("main", "OnPageStart", "OnBeforePrologRedirectHandler");
  20. function OnBeforePrologRedirectHandler() {
  21. global $APPLICATION;
  22. $curPageUrl = $APPLICATION->GetCurPageParam();
  23.  
  24. $arUrl = CHTTP::ParseURL($curPageUrl);
  25. $arData = explode("/", $arUrl['path']);
  26. $lastSegment = array_pop($arData);
  27. if(
  28. !preg_match('/^.*\..*$/',$lastSegment)
  29. && substr($lastSegment, -1) != "/"
  30. && strlen($lastSegment) > 1
  31. ) {
  32. $path = _normalizePath($arUrl['path'] . "/" . (array_key_exists('query', $arUrl) && strlen($arUrl['query']) > 0 ? "?{$arUrl['query']}" : ''));
  33. LocalRedirect($path,false,301);
  34. }
  35. }
  36. */
  37. include('geo.php');
  38. AddEventHandler('main', 'OnProlog', array('Handlers', 'OnProlog'));
  39. AddEventHandler('iblock', 'OnAfterIBlockElementAdd', array('Handlers', 'OnAfterIBlockElementAdd'));
  40. AddEventHandler("main", "OnPageStart", "OnPageStartHandler", 50);
  41. function OnPageStartHandler()
  42. {
  43. global $USER, $APPLICATION;
  44.  
  45. $newUri = preg_replace('#(/catalog/napolnye-pokrytiya/[\d]+/)#is', '/catalog/napolnye-pokrytiya/', $_SERVER['REQUEST_URI']);
  46. if (!CHTTP::isPathTraversalUri($newUri)) {
  47. $_SERVER['REQUEST_URI'] = $newUri;
  48. $GLOBALS['APPLICATION']->reinitPath();
  49. }
  50.  
  51. if (!CModule::IncludeModule('iblock'))
  52. return true;
  53.  
  54. $arUrlTemplates = array(
  55. "section" => "#SECTION_CODE#/"
  56. );
  57. $arVariables = array();
  58. if (!CComponentEngine::ParseComponentPath('/catalog/', $arUrlTemplates, $arVariables))
  59. return true;
  60.  
  61. $arSection = CIBlockSection::GetList(
  62. array(), array("IBLOCK_ID" => 9, "CODE" => $arVariables['SECTION_CODE']), false, array("ID", "IBLOCK_ID", "LEFT_MARGIN", "RIGHT_MARGIN", "DEPTH_LEVEL", "NAME")
  63. )->Fetch();
  64.  
  65. if (!$arSection) return true;
  66.  
  67. $attn = CIBlockSection::GetList(
  68. array('left_margin' => 'asc'), array(
  69. //"ID" => $arSection['ID'],
  70. "IBLOCK_ID" => $arSection['IBLOCK_ID'],
  71. "<=LEFT_BORDER" => $arSection["LEFT_MARGIN"],
  72. ">=RIGHT_BORDER" => $arSection["RIGHT_MARGIN"],
  73. //"<DEPTH_LEVEL" => $arSection["DEPTH_LEVEL"]
  74. ), false, array("ID", "IBLOCK_ID", "UF_OLD_TEMPLATE", "UF_NEW2_TEMPLATE", "NAME")
  75. )->Fetch();
  76.  
  77. if ($attn['ID'] == 12) {
  78. $attn = CIBlockSection::GetList(
  79. array('left_margin' => 'asc'), array(
  80. "IBLOCK_ID" => $arSection['IBLOCK_ID'],
  81. "<=LEFT_BORDER" => $arSection["LEFT_MARGIN"],
  82. ">=RIGHT_BORDER" => $arSection["RIGHT_MARGIN"],
  83. "DEPTH_LEVEL" => 2
  84. ), false, array("ID", "IBLOCK_ID", "UF_OLD_TEMPLATE", "UF_NEW2_TEMPLATE", "NAME")
  85. )->Fetch();
  86. }
  87.  
  88. if (!$attn) return true;
  89. // $GLOBALS['IS_OLD_TEMPLATE'] = array_key_exists('UF_OLD_TEMPLATE', $attn) && !empty($attn['UF_OLD_TEMPLATE']) ? true : false;
  90. // $GLOBALS['IS_NEW2_TEMPLATE'] = array_key_exists('UF_NEW2_TEMPLATE', $attn) && !empty($attn['UF_NEW2_TEMPLATE']) ? true : false;
  91. $GLOBALS['IS_OLD_TEMPLATE'] = false;
  92. $GLOBALS['IS_NEW2_TEMPLATE'] = false;
  93. $GLOBALS['PARENT_SECTON_ID'] = $attn['NAME'];
  94.  
  95. if (CModule::IncludeModule("subscribe")) {
  96. $cPosting = new CPosting;
  97. $cPosting->AutoSend();
  98. }
  99.  
  100. return true;
  101. }
  102.  
  103. AddEventHandler("main", "OnBeforeUserRegister", Array("MyClass", "OnBeforeUserRegisterHandler"));
  104. AddEventHandler("main", "OnBeforeUserUpdate", Array("MyClass", "OnBeforeUserUpdateHandler"));
  105. AddEventHandler("main", "OnBeforeEventSend", Array("MyClass", "OnBeforeEventSendHandler"));
  106.  
  107. class MyClass
  108. {
  109. function OnBeforeEventSendHandler(&$arFields, $arTemplate)
  110. {
  111. if ($arTemplate['EVENT_NAME'] == 'NEW_USER') {
  112. $user = CUser::GetByID($arFields['USER_ID'])->Fetch();
  113.  
  114. $arFields['CITY'] = $user['PERSONAL_CITY'];
  115. $arFields['PHONE'] = $user['PERSONAL_PHONE'];
  116. $arFields['NOTES'] = $user['PERSONAL_NOTES'];
  117. }
  118. }
  119.  
  120. function OnBeforeUserRegisterHandler(&$arFields)
  121. {
  122. $arFields["ACTIVE"] = "N";
  123. $arFields["LOGIN"] = $arFields["EMAIL"];
  124. $arFields["GROUP_ID"] = array(3,4,6);
  125. }
  126.  
  127. function OnBeforeUserUpdateHandler(&$arFields)
  128. {
  129. $arFields["LOGIN"] = $arFields["EMAIL"];
  130.  
  131. $user = CUser::GetById($arFields['ID'])->Fetch();
  132.  
  133. if ($user) {
  134. if ($user['ACTIVE'] != 'Y' && $arFields['ACTIVE'] == 'Y') {
  135. function KeyGen(){
  136. $key = md5(time());
  137. $new_key = '';
  138. for($i=1; $i <= 10; $i ++ ){
  139. $new_key .= $key[$i];
  140.  
  141. }
  142. return strtoupper($new_key);
  143. }
  144. $newgenpass = KeyGen();
  145.  
  146. $arFields["PASSWORD"] = $newgenpass;
  147. $arFields["CONFIRM_PASSWORD"] = $newgenpass;
  148.  
  149. $arEventFields= array(
  150. "LOGIN" => $arFields["LOGIN"],
  151. "NAME" => $arFields["NAME"],
  152. "USER_PAROL" => $arFields["PASSWORD"],
  153. "EMAIL" => $arFields["EMAIL"],
  154. );
  155. CEvent::Send("USER_ACTIVATION", 's1', $arEventFields, "N", 58);
  156.  
  157. }
  158. }
  159.  
  160.  
  161. }
  162. }
  163.  
  164.  
  165. /*
  166. // файл /bitrix/php_interface/init.php
  167. // регистрируем обработчик
  168. AddEventHandler("iblock", "OnBeforeIBlockSectionDelete", Array("MyClass5", "OnBeforeIBlockSectionDeleteHandler"));
  169.  
  170. class MyClass5
  171. {
  172. // создаем обработчик события "OnBeforeIBlockSectionDelete"
  173. function OnBeforeIBlockSectionDeleteHandler($ID)
  174. {
  175. if($ID==1161)
  176. {
  177. global $APPLICATION;
  178. $APPLICATION->throwException("раздел с ID=1161 нельзя удалить.");
  179. return false;
  180. }
  181. }
  182. }
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191. AddEventHandler("iblock", "OnBeforeIBlockElementDelete", Array("MyClass66", "OnBeforeIBlockElementDeleteHandler"));
  192.  
  193. class MyClass66
  194. {
  195. // создаем обработчик события "OnBeforeIBlockElementDelete"
  196. function OnBeforeIBlockElementDeleteHandler($ID)
  197. {
  198. $array = []; //Инициируешь массив
  199. $arSelect = Array("ID", "NAME");
  200. $arFilter = Array("IBLOCK_ID"=> 9,'INCLUDE_SUBSECTIONS' => 'Y' ,"SECTION_CODE" => array("dveri"));
  201. $res = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect);
  202. while($ob = $res->GetNextElement())
  203. {
  204. $arFields = $ob->GetFields();
  205. $array[] = $arFields["ID"];
  206. }
  207. if (in_array($ID, $array)) {
  208. global $APPLICATION;
  209. $APPLICATION->throwException("элемент с ID=1 нельзя удалить.");
  210. return false;
  211. }
  212. }
  213. }
  214.  
  215.  
  216. */
  217.  
  218. AddEventHandler("main", "OnAfterEpilog", "gdwOnAfterEpilog");
  219. function gdwOnAfterEpilog()
  220. {
  221. global $APPLICATION;
  222.  
  223. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  224. header('Expires: ' . date('r', time() + 259200));
  225.  
  226. $r301 = null;
  227. switch ($APPLICATION->GetCurPage()) {
  228. case '/massivnaya_doska':
  229. $r301 = '/catalog/massivnaya-doska/';
  230. break;
  231. case '/terrasnaya_doska':
  232. $r301 = '/catalog/terrasnaya-doska/';
  233. break;
  234. case '/parketnaya_doska':
  235. $r301 = '/catalog/parketnaya-doska/';
  236. break;
  237. case '/inzhenernaya_doska':
  238. $r301 = '/catalog/inzhenernaya-doska/';
  239. break;
  240. case '/modulnyy_parket':
  241. $r301 = '/catalog/modulnyy-parket/';
  242. break;
  243. case '/shtuchnyy_parket':
  244. $r301 = '/catalog/shtuchnyy-parket/';
  245. break;
  246. case '/o_parkete':
  247. $r301 = '/article/';
  248. break;
  249. case '/dveri_mezhkomnatnye1c':
  250. $r301 = '/catalog/mezhkomnatnye-dveri/';
  251. break;
  252. case '/plintus_massivnyy':
  253. $r301 = '/catalog/plintusy/';
  254. break;
  255. case '/plintus_shponirovannyy':
  256. $r301 = '/catalog/plintusy/';
  257. break;
  258. case '/contacts':
  259. $r301 = '/company/shops.php';
  260. break;
  261. case '/gallery':
  262. $r301 = '/gallery/';
  263. break;
  264.  
  265. case '/catalog/parketnye-masla/':
  266. $r301 = '/catalog/masla-parketnye/';
  267. break;
  268. case '/catalog/parketnye-klei/':
  269. $r301 = '/catalog/klei-parketnye/';
  270. break;
  271. case '/catalog/-/':
  272. $r301 = '/catalog/sredstva-po-ukhodu-za-parketom/';
  273. break;
  274. case '/catalog/napolnye-pokrytiya':
  275. $r301 = '/catalog/parket/';
  276. break;
  277.  
  278. }
  279. if ($r301)
  280. LocalRedirect($r301, false, '301 Moved permanently');
  281. }
  282.  
  283. Class CCAffiliatesShop
  284. {
  285. var $cityShopIblockID = 7;
  286. var $shopIblockID = 8;
  287. var $cityData = array();
  288.  
  289. var $coocieTime = false;
  290. var $cookiePath = "/ru/location/";
  291. var $APP = null;
  292.  
  293. public function __construct()
  294. {
  295. // время на 30 дней
  296. $this->coocieTime = time() + 86400 * 30;
  297. $this->APP = &$GLOBALS['APPLICATION'];
  298.  
  299. $this->GetStoredData();
  300. }
  301.  
  302. public function GetStoredData()
  303. {
  304. $cityName = $this->GetCityData('REGION');
  305. if (false !== $cityName && strlen($cityName) > 0)
  306. $this->cityData['NAME'] = $cityName;
  307.  
  308. $cityID = $this->GetCityData('REGION_ID');
  309. if (false !== $cityID && strlen($cityID) > 0)
  310. $this->cityData['ID'] = $cityID;
  311.  
  312. $cityData = $this->GetCityData('REGION_DATA');
  313. if (
  314. false !== $cityData && strlen($cityData) > 0
  315. && CheckSerializedData($cityData, strlen($cityData))
  316. ) {
  317. $this->cityData = unserialize($cityData);
  318. if (!isset($_SESSION["REGION_PHONE"])) {
  319. global $APPLICATION;
  320. $page = $APPLICATION->GetCurPageParam();
  321. $obRes = CIBlockElement::GetList(array(), array("ACTIVE" => "Y", "IBLOCK_ID" => 23, "!PROPERTY_SEARCH_STRING" => false), false, false, array("ID", "PROPERTY_PHONE", "PROPERTY_SEARCH_STRING"));
  322.  
  323. while ($arRes = $obRes->GetNext(true, false)) {
  324. if (strpos($page, $arRes["PROPERTY_SEARCH_STRING_VALUE"]) !== false) {
  325. $arElement['PROPERTYIES']["PHONE"]["VALUE"] = $arRes["PROPERTY_PHONE_VALUE"];
  326. $_SESSION["REGION_PHONE"] = $arRes["PROPERTY_PHONE_VALUE"];
  327. break;
  328. }
  329. }
  330. } else {
  331. $this->cityData["PROPERTYIES"]["PHONE"]["VALUE"] = $_SESSION["REGION_PHONE"];
  332. }
  333. }
  334.  
  335. if (
  336. (false === $cityName || strlen($cityName) <= 0)
  337. || (false === $cityID || IntVal($cityID) <= 0)
  338. || (false === $cityData || strlen($cityData) <= 0)
  339. ) {
  340. $res = $this->GetDefaultData();
  341. if (false !== $res) {
  342. $this->SetCityData($res['NAME'], 'REGION');
  343. $this->SetCityData($res['ID'], 'REGION_ID');
  344. $this->SetCityData(serialize($res), 'REGION_DATA');
  345.  
  346. $this->cityData = $res;
  347. }
  348. }
  349. }
  350.  
  351. public function SetCityData($value = false, $name = false)
  352. {
  353. if (
  354. (false == $value || strlen($value) <= 0)
  355. || (false == $name || strlen($name) <= 0)
  356. ) {
  357. return false;
  358. }
  359.  
  360. $_SESSION[$name] = $value;
  361. //if($this->coocieTime > 0)
  362. //$this->APP->set_cookie($name, $value, $this->coocieTime, $this->cookiePath);
  363.  
  364. switch ($name) {
  365. case 'REGION':
  366. $this->cityData['NAME'] = $value;
  367. break;
  368.  
  369. case 'REGION_ID':
  370. $this->cityData['ID'] = $value;
  371. break;
  372.  
  373. default:
  374. $this->cityData[$name] = $value;
  375. }
  376. }
  377.  
  378. public function GetCityData($name = false)
  379. {
  380. if (false == $name || strlen($name) <= 0)
  381. return false;
  382.  
  383. if (array_key_exists($name, $this->cityData))
  384. return $this->cityData[$name];
  385. elseif (array_key_exists($name, $_SESSION))
  386. return $_SESSION[$name];
  387. else
  388. return $this->APP->get_cookie($name);
  389.  
  390. return false;
  391. }
  392.  
  393. public function GetCityName()
  394. {
  395. return $this->cityData['NAME'];
  396. }
  397.  
  398. public function GetCityID()
  399. {
  400. return $this->cityData['ID'];
  401. }
  402.  
  403. public function GetDefaultData()
  404. {
  405. if (!CModule::IncludeModule("iblock"))
  406. return false;
  407.  
  408. $o = array(); // опции. необзятательно.
  409. $o['charset'] = 'utf-8'; // нужно указать требуемую кодировку, если она отличается от windows-1251
  410.  
  411. $geo = new Geo($o); // запускаем класс
  412.  
  413.  
  414. $city = $geo->get_value('city', true);
  415. // echo '<pre>';
  416. // var_dump($city);
  417. // echo '</pre>';
  418. $arFilter = Array(
  419. "ACTIVE" => "Y",
  420. "IBLOCK_ID" => $this->cityShopIblockID
  421. );
  422.  
  423. if ($cityID = $this->GetCityID())
  424. $arFilter['ID'] = $cityID;
  425. else if ($city) {
  426. $arFilter['NAME'] = $city;
  427. }
  428. $rsElement = CIBlockElement::GetList(
  429. Array("SORT" => "ASC"),
  430. $arFilter,
  431. false, false,
  432. Array("ID", "NAME", "IBLOCK_ID")
  433. );
  434.  
  435. if (!is_object($rsElement) || !$objElement = $rsElement->GetNextElement())
  436. return false;
  437. else {
  438. $arElement = $objElement->GetFields();
  439. $arElement['PROPERTYIES'] = $objElement->GetProperties();
  440. }
  441.  
  442. return $arElement;
  443. }
  444.  
  445. public function GetCIBlockFilterByCity($filterName = '')
  446. {
  447. if (strlen($filterName) <= 0) return false;
  448.  
  449. $cityID = $this->GetCityID();
  450.  
  451. $arRegFilter = &${$filterName};
  452. global $arRegFilter;
  453. $arRegFilter = array(
  454. "PROPERTY_REGION" => $cityID !== false ? $cityID : false
  455. );
  456. }
  457.  
  458.  
  459. public function __destruct()
  460. {
  461. }
  462. }
  463.  
  464.  
  465. AddEventHandler("catalog", "OnCountPriceWithDiscount", array("CCitrusPriceHandler", "___OnCountPriceWithDiscount"));
  466. AddEventHandler("catalog", "OnGetDiscount", array("CCitrusPriceHandler", "___OnGetDiscount"));
  467. AddEventHandler("catalog", "OnGetOptimalPrice", array("CCitrusPriceHandler", "___OnGetOptimalPriceHandler"));
  468.  
  469. Class CCitrusPriceHandler
  470. {
  471.  
  472. public function ___OnCountPriceWithDiscount($price, $currency, $arDiscounts)
  473. {
  474. $price -= $arDiscounts['VALUE'];
  475.  
  476. return $price;
  477. }
  478.  
  479. public function ___OnGetDiscount($intProductID, $intIBlockID, $arCatalogGroups, $arUserGroups, $strRenewal, $siteID, $arDiscountCoupons, $boolSKU, $boolGetIDS)
  480. {
  481. if (!CModule::IncludeModule("iblock"))
  482. return true;
  483.  
  484. $obj = CIBlockElement::GetByID($intProductID);
  485. if (!is_object($obj) || !$objEl = $obj->GetNextElement())
  486. return true;
  487.  
  488. $arProp = $objEl->GetProperties();
  489. if (!$arProp || !array_key_exists('DISCOUNT_SUMM', $arProp))
  490. return true;
  491.  
  492. $discountValue = IntVal(abs($arProp['DISCOUNT_SUMM']['VALUE']));
  493. if ($discountValue <= 0)
  494. return true;
  495.  
  496. $arResult = array(
  497. 'VALUE_TYPE' => "F",
  498. 'VALUE' => $discountValue,
  499. 'CURRENCY' => "RUB",
  500. );
  501.  
  502. return $arResult;
  503. }
  504.  
  505. public function ___OnGetOptimalPriceHandler($intProductID, $quantity, $arUserGroups, $renewal, $arPrices, $siteID, $arDiscountCoupons)
  506. {
  507. $arTmpPrice = CPrice::GetBasePrice($intProductID);
  508. if (false === $arTmpPrice || !$arTmpPrice)
  509. return true;
  510.  
  511. $obj = CIBlockElement::GetByID($intProductID);
  512. if (!is_object($obj) || !$objEl = $obj->GetNextElement())
  513. return true;
  514.  
  515. $arProp = $objEl->GetProperties();
  516. if (!$arProp || !array_key_exists('DISCOUNT_SUMM', $arProp))
  517. return true;
  518.  
  519. $discountValue = IntVal(abs($arProp['DISCOUNT_SUMM']['VALUE']));
  520.  
  521. if ($discountValue <= 0)
  522. return true;
  523.  
  524. $arPrice = array(
  525. "PRICE" => array(
  526. "ID" => $arTmpPrice["ID"],
  527. "CATALOG_GROUP_ID" => $arTmpPrice["CATALOG_GROUP_ID"],
  528. "PRICE" => $arTmpPrice["PRICE"],
  529. "CURRENCY" => $arTmpPrice["CURRENCY"],
  530. "ELEMENT_IBLOCK_ID" => $arTmpPrice["ELEMENT_IBLOCK_ID"],
  531. //"VAT_RATE" => $arCityPrice["VAT_RATE"],
  532. //"VAT_INCLUDED" => $arCityPrice["VAT_INCLUDED"],
  533. ),
  534. "DISCOUNT_PRICE" => $arTmpPrice["PRICE"],
  535. "DISCOUNT" => array(),
  536. "DISCOUNT_LIST" => array(
  537. array(
  538. "VALUE_TYPE" => "F",
  539. "CURRENCY" => "RUB",
  540. "VALUE" => $discountValue
  541. )
  542. ),
  543. );
  544.  
  545. if ($arPrice === false)
  546. return true;
  547. else
  548. return $arPrice;
  549. }
  550. }
  551.  
  552.  
  553.  
  554. class CSubsections
  555. {
  556. function Init()
  557. {
  558. global $APPLICATION;
  559.  
  560. $sef_folder = (isset($_SERVER["REAL_FILE_PATH"]) && $_SERVER["REAL_FILE_PATH"] != ""
  561. ? str_replace("index.php", "", $_SERVER["REAL_FILE_PATH"])
  562. : $APPLICATION->GetCurDir(false)
  563. );
  564. $uri = $GLOBALS["BACK_REQUEST_URI"] = $APPLICATION->GetCurDir(false);
  565. $uri = str_replace($sef_folder, "", $uri);
  566. $uri = trim($uri, "/");
  567. $tmp_uri = "";
  568.  
  569. if($uri && CModule::IncludeModule("iblock"))
  570. {
  571. $rs = CIBlockElement::GetList(
  572. array(),
  573. array("=CODE" => $uri),
  574. false,
  575. array("nTopCount" => 1),
  576. array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "NAME")
  577. );
  578. if($ar = $rs->Fetch())
  579. {
  580. $tmp_uri = $sef_folder.intval($ar["IBLOCK_SECTION_ID"])."/".$ar["ID"]."/";
  581. }
  582. else
  583. {
  584. $rs = CIBlockSection::GetList(
  585. array(),
  586. array("=CODE" => $uri),
  587. false,
  588. array("ID")
  589. );
  590. if($ar = $rs->Fetch())
  591. {
  592. $tmp_uri = $sef_folder.$ar["ID"]."/";
  593. }
  594. }
  595. }
  596.  
  597. if($tmp_uri)
  598. {
  599. $_SERVER["REQUEST_URI"] = $REQUEST_URI = $tmp_uri;
  600. $APPLICATION->sDocPath2 = $tmp_uri."index.php";
  601. CSubsections::InitParser();
  602. }
  603. elseif($sef_folder == $APPLICATION->GetCurDir(false))
  604. {
  605. CSubsections::InitParser();
  606. }
  607. }
  608.  
  609. function Back($arResult)
  610. {
  611. global $APPLICATION;
  612.  
  613. $arResult["URL_TEMPLATES"]["section"] = "#SECTION_CODE#/";
  614. $arResult["URL_TEMPLATES"]["element"] = "#ELEMENT_CODE#/";
  615. $_SERVER["REQUEST_URI"] = $REQUEST_URI = $GLOBALS["BACK_REQUEST_URI"];
  616. $APPLICATION->sDocPath2 = $GLOBALS["BACK_REQUEST_URI"]."index.php";
  617. unset($GLOBALS["BACK_REQUEST_URI"]);
  618. }
  619.  
  620. function Parse($html)
  621. {
  622. $html = str_ireplace("%"."2f", "/", $html);
  623. }
  624.  
  625. function InitParser()
  626. {
  627. if(!defined("CSUBSECTIONS_INIT_HANDLER"))
  628. {
  629. define("CSUBSECTIONS_INIT_HANDLER", true);
  630. AddEventHandler("main", "OnEndBufferContent", array("CSubsections", "Parse"), 10000);
  631. }
  632. }
  633.  
  634. function GetCode($iblock_id, $section_id, $element_name="")
  635. {
  636. $arPath = array();
  637.  
  638. if(CModule::IncludeModule("iblock"))
  639. {
  640. if($element_name)
  641. {
  642. $element_name = CUtil::translit($element_name, LANGUAGE_ID);
  643. $element_name = $element_name? "/".$element_name: "";
  644. }
  645.  
  646. if($rs = CIBlockSection::GetNavChain($iblock_id, $section_id))
  647. {
  648. while($ar = $rs->Fetch())
  649. {
  650. $arPath[] = CUtil::translit($ar["NAME"], LANGUAGE_ID);
  651. }
  652. }
  653. }
  654.  
  655. return trim(implode("/", $arPath).$element_name, "/");
  656. }
  657.  
  658. function ElementAddHandler($arFields)
  659. {
  660. //if($GLOBALS["IBLOCK_ID"] == $IBLOCK_ID)
  661. //{
  662. $oElement = new CIBlockElement();
  663. $oElement->Update($arFields["ID"], array("CODE" => "recalculate"));
  664. //}
  665. }
  666.  
  667. function ElementUpdateHandler($arFields)
  668. {
  669. //if($GLOBALS["IBLOCK_ID"] == $IBLOCK_ID)
  670. //{
  671. if($rs = CIBlockElement::GetByID($arFields["ID"]))
  672. {
  673. if($ar = $rs->Fetch())
  674. {
  675. $arFields["CODE"] = CSubsections::GetCode(
  676. $ar["IBLOCK_ID"],
  677. $ar["IBLOCK_SECTION_ID"],
  678. $ar["NAME"]
  679. );
  680. }
  681. }
  682. //}
  683. }
  684.  
  685. function SectionAddHandler($arFields)
  686. {
  687. //if($GLOBALS["IBLOCK_ID"] == $IBLOCK_ID)
  688. //{
  689. $oSection = new CIBlockSection();
  690. $oSection->Update($arFields["ID"], array("CODE" => "recalculate"));
  691. //}
  692. }
  693.  
  694. function SectionUpdateHandler($arFields)
  695. {
  696. //if($GLOBALS["IBLOCK_ID"] == $IBLOCK_ID)
  697. //{
  698. $arFields["CODE"] = CSubsections::GetCode(
  699. $arFields["IBLOCK_ID"],
  700. $arFields["ID"]
  701. );
  702. //}
  703. }
  704.  
  705. function Recalculate($iblock_id)
  706. {
  707. if(CModule::IncludeModule("iblock"))
  708. {
  709. $oSection = new CIBlockSection();
  710. if($rs = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $iblock_id), false, array("ID")))
  711. {
  712. while($ar = $rs->Fetch())
  713. {
  714. $oSection->Update($ar['ID'], array("CODE" => "recalculate"));
  715. }
  716. }
  717.  
  718. $oElement = new CIBlockElement();
  719. if($rs = CIBlockElement::GetList(array(), array("IBLOCK_ID" => $iblock_id), false, false, array("ID")))
  720. {
  721. while($ar = $rs->Fetch())
  722. {
  723. $oElement->Update($ar['ID'], array("CODE" => "recalculate"));
  724. }
  725. }
  726. }
  727. }
  728. }
  729.  
  730. AddEventHandler("iblock", "OnAfterIBlockElementAdd", array("CSubsections", "ElementAddHandler"));
  731. AddEventHandler("iblock", "OnBeforeIBlockElementUpdate", array("CSubsections", "ElementUpdateHandler"));
  732. AddEventHandler("iblock", "OnAfterIBlockSectionAdd", array("CSubsections", "SectionAddHandler"));
  733. //AddEventHandler("iblock", "OnBeforeIBlockSectionUpdate", array("CSubsections", "SectionUpdateHandler"));
  734.  
  735. CSubsections::InitParser();
  736.  
  737. function strpos_arr($haystack, $needle)
  738. {
  739. if (!is_array($needle)) {
  740. $needle = array($needle);
  741. }
  742. foreach ($needle AS $what) {
  743. if (($pos = strpos($haystack, $what)) !== false) {
  744. return $pos;
  745. }
  746. }
  747. return false;
  748. }
  749.  
  750. AddEventHandler("sale", "OnOrderNewSendEmail", "OnOrderNewSendEmailHandler");
  751. define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"] . "/log.txt");
  752.  
  753. function OnOrderNewSendEmailHandler($ID, &$eventName, &$arFields)
  754. {
  755.  
  756. CModule::IncludeModule("sale");
  757.  
  758. $strOrderList = "";
  759. $arBasketList = array();
  760. $dbBasketItems = CSaleBasket::GetList(
  761. array("ID" => "ASC"),
  762. array("ORDER_ID" => $arFields["ORDER_ID"]),
  763. false,
  764. false,
  765. array("ID", "PRODUCT_ID", "NAME", "QUANTITY", "PRICE", "CURRENCY", "TYPE", "SET_PARENT_ID")
  766. );
  767. while ($arItem = $dbBasketItems->GetNext(true, false)) {
  768. if (CSaleBasketHelper::isSetItem($arItem))
  769. continue;
  770.  
  771. $arBasketList[] = $arItem;
  772. }
  773.  
  774. $arBasketList = getMeasures($arBasketList);
  775. $sOrderList = "<table border='1'><tr><td>Наименование</td><td>Количество</td><td>Цена</td></tr>";
  776. foreach ($arBasketList as $arItem) {
  777. $measureText = (isset($arItem["MEASURE_TEXT"]) && strlen($arItem["MEASURE_TEXT"])) ? $arItem["MEASURE_TEXT"] : GetMessage("SOA_SHT");
  778. $sOrderList .= "<tr><td>" . $arItem["NAME"] . "</td><td>" . $arItem["QUANTITY"] . " " . $measureText . "</td><td>" . $arItem["PRICE"] . " руб</td></tr>";
  779. }
  780. $sOrderList .= "</table>";
  781.  
  782. $db_props = CSaleOrderPropsValue::GetOrderProps($arFields["ORDER_ID"]);
  783. while ($arProps = $db_props->GetNext(true, false)) {
  784. if ($arProps["CODE"] == "PERS_PHONE") {
  785. $arFields["ORDER_PHONE"] = $arProps["VALUE"];
  786. break;
  787. }
  788. }
  789.  
  790. $arFields["ORDER_LIST"] = $sOrderList;
  791. // $res = print_r($arFields,true);
  792. // AddMessage2Log($ID);
  793. // AddMessage2Log($res);
  794.  
  795. }
  796.  
  797. AddEventHandler("catalog", "OnSuccessCatalogImport1C", "DSOnSuccessCatalogImport1C");
  798.  
  799. //Устанавливаем тип напольного покрытия, покрытие в свойство
  800. function DSOnSuccessCatalogImport1C()
  801. {
  802. CModule::IncludeModule("iblock");
  803. $el = new CIBlockElement();
  804.  
  805. $oRes = CIBlockElement::GetList(array(), array("ACTIVE" => "Y", "IBLOCK_ID" => 9, "SECTION_ID" => 12, "INCLUDE_SUBSECTIONS" => "Y"), false, false
  806. , array("ID", "IBLOCK_SECTION_ID", "PROPERTY_TYPE_OF_FLOORING", "PROPERTY_DISCOUNT_SUMM"
  807. , "PROPERTY_EFFECT_1", "PROPERTY_CHAMFER", "PROPERTY_UKLADKA_NA_TEPLYY_POL", "PROPERTY_POPULYARNYE", "PROPERTY_NEW_TOVAR"));
  808. while ($aRes = $oRes->GetNext(true, false)) {
  809. $aFilterVal = array();
  810. /*тип напольного покрытия*/
  811. if ($aRes["IBLOCK_SECTION_ID"]) {
  812. $oResSect = CIBlockSection::GetByID($aRes["IBLOCK_SECTION_ID"]);
  813. if ($aResSect = $oResSect->GetNext(true, false)) {
  814. $aFilterVal["TYPE_OF_FLOORING"] = $aResSect["NAME"];
  815. }
  816. }
  817. /*покрытие*/
  818. if ($aRes["PROPERTY_EFFECT_1_VALUE"] != "Лак" && $aRes["PROPERTY_EFFECT_1_VALUE"] != "Масло") {
  819. $aFilterVal["EFFECT_1"] = 'Нет';
  820. }
  821.  
  822. /*фаска*/
  823. if ($aRes["PROPERTY_CHAMFER_VALUE"] == "Фаска") {
  824. $aFilterVal["CHAMFER"] = "Есть";
  825. } elseif (trim($aRes["PROPERTY_CHAMFER_VALUE"]) == "") {
  826. $aFilterVal["CHAMFER"] = 'Нет';
  827. }
  828.  
  829. /*Для поля Категория*/
  830. $aFilterVal["CATEGORY_FILTER"] = array();
  831. if ($aRes["PROPERTY_UKLADKA_NA_TEPLYY_POL_VALUE"] == "Да")
  832. $aFilterVal["CATEGORY_FILTER"][] = "Укладка на теплый пол";
  833.  
  834. if ($aRes["PROPERTY_POPULYARNYE_VALUE"] == "Да")
  835. $aFilterVal["CATEGORY_FILTER"][] = "Популярные";
  836.  
  837. if ($aRes["PROPERTY_NEW_TOVAR_VALUE"] == "Да")
  838. $aFilterVal["CATEGORY_FILTER"][] = "Новинки";
  839.  
  840. if (IntVal(abs($aRes['PROPERTY_DISCOUNT_SUMM_VALUE'])))
  841. $aFilterVal["CATEGORY_FILTER"][] = "Скидки";
  842.  
  843. if (count($aFilterVal) > 0)
  844. CIBlockElement::SetPropertyValuesEx($aRes["ID"], false, $aFilterVal);
  845.  
  846. }
  847.  
  848. /*Цена и ед измерения*/
  849. \Bitrix\Main\Loader::IncludeModule('sale');
  850. \Bitrix\Main\Loader::IncludeModule('catalog');
  851.  
  852. $measures = array();
  853. $rsMeasures = CCatalogMeasure::getList();
  854.  
  855. while ($measure = $rsMeasures->Fetch()) {
  856. $measures[$measure['SYMBOL_RUS']] = $measure;
  857. }
  858.  
  859. $oRes = CIBlockElement::GetList(array(), array(
  860. 'ACTIVE' => 'Y',
  861. 'IBLOCK_ID' => 9,
  862. 'INCLUDE_SUBSECTIONS' => 'Y'
  863. ), false, false, array(
  864. 'ID',
  865. 'IBLOCK_SECTION_ID',
  866. 'CATALOG_GROUP_1',
  867. 'PROPERTY_DISCOUNT_SUMM',
  868. 'PROPERTY_CML2_BASE_UNIT',
  869. 'PROPERTY_CML2_TRAITS'
  870. ));
  871.  
  872. while ($aRes = $oRes->GetNext(true, false)) {
  873. $aFilterVal = array();
  874.  
  875. $discountValue = IntVal(abs($aRes['PROPERTY_DISCOUNT_SUMM_VALUE']));
  876. $iPrice = $aRes["CATALOG_PRICE_1"];
  877. if ($discountValue > 0 && $aRes["CATALOG_PRICE_1"] > 0) {
  878. $iPrice = $aRes["CATALOG_PRICE_1"] - $discountValue;
  879. }
  880. $aFilterVal["DISCOUNT_PRICE"] = $iPrice;
  881.  
  882. if (count($aFilterVal) > 0) {
  883. CIBlockElement::SetPropertyValuesEx($aRes["ID"], false, $aFilterVal);
  884. }
  885.  
  886. $aRes['PROPERTY_CML2_BASE_UNIT_VALUE'] = trim($aRes['PROPERTY_CML2_BASE_UNIT_VALUE']);
  887.  
  888. CCatalogProduct::Update($aRes['ID'], array(
  889. 'MEASURE' => isset($measures[$aRes['PROPERTY_CML2_BASE_UNIT_VALUE']]) ? $measures[$aRes['PROPERTY_CML2_BASE_UNIT_VALUE']]['ID'] : $measures['шт']
  890. ));
  891.  
  892. $oResOffers = CIBlockElement::GetList(array(), array(
  893. 'ACTIVE' => 'Y',
  894. 'IBLOCK_ID' => 30,
  895. 'PROPERTY_CML2_LINK' => $aRes['ID'],
  896. ), false, false, array(
  897. 'ID',
  898. ));
  899.  
  900. while ($resOffer = $oResOffers->Fetch()) {
  901. CCatalogProduct::Update($resOffer['ID'], array(
  902. 'MEASURE' => isset($measures[$aRes['PROPERTY_CML2_BASE_UNIT_VALUE']]) ? $measures[$aRes['PROPERTY_CML2_BASE_UNIT_VALUE']]['ID'] : $measures['шт']
  903. ));
  904. }
  905.  
  906. //ед изменерия
  907. CIBlockElement::SetPropertyValuesEx($aRes["ID"], false,
  908. array(
  909. 'BASE_UNIT' => $aRes['PROPERTY_CML2_BASE_UNIT_VALUE']
  910. )
  911. );
  912.  
  913. }
  914.  
  915. //Получаем все ранее выгруженные породы из инфоблока
  916. $breeds = [];
  917. $rsBreeds = CIBlockElement::GetList([], [
  918. 'IBLOCK_TYPE' => 'content',
  919. 'IBLOCK_CODE' => 'breed',
  920. ], false, false, [
  921. 'ID',
  922. 'NAME',
  923. ]);
  924.  
  925. while ($breed = $rsBreeds->Fetch()) {
  926. $breeds[strtoupper($breed['NAME'])] = 'Y';
  927. }
  928.  
  929. //Описание и другие работы с родителем
  930. $oRes = CIBlockElement::GetList(array(), array(
  931. 'ACTIVE' => 'Y',
  932. 'IBLOCK_ID' => 9,
  933. 'INCLUDE_SUBSECTIONS' => 'Y'
  934. ));
  935.  
  936. while ($obRes = $oRes->GetNextElement()) {
  937. $arFields = $obRes->GetFields();
  938. $arProps = $obRes->GetProperties();
  939.  
  940. if (sizeof($arProps['CML2_TRAITS']['VALUE'])) {
  941. $DETAIL_TEXT = false;
  942.  
  943. foreach ($arProps['CML2_TRAITS']['VALUE'] as $key => $val) {
  944. if ($arProps['CML2_TRAITS']['DESCRIPTION'][$key] == 'ПолноеОписание') {
  945. $DETAIL_TEXT = trim($val);
  946. break;
  947. }
  948. }
  949.  
  950. if ($DETAIL_TEXT !== false) {
  951. CIBlockElement::SetPropertyValuesEx($arFields['ID'], 9, array(
  952. 'FULL_DISCRIP' => array(
  953. 'VALUE' => array(
  954. 'TYPE' => 'TEXT',
  955. 'TEXT' => $DETAIL_TEXT
  956. )
  957. )
  958. ));
  959. }
  960. }
  961.  
  962. if (sizeof($arProps['KARTINKIDOP']['VALUE'])) {
  963. $pictures = array();
  964.  
  965. foreach ($arProps['KARTINKIDOP']['VALUE'] as $src) {
  966. if (trim($src) != '') {
  967. $src = '/upload/1c_catalog/' . $src;
  968.  
  969. $pictures[] = array(
  970. 'VALUE' => CFile::MakeFileArray($src),
  971. 'DESCRIPTION' => ''
  972. );
  973. }
  974. }
  975.  
  976. if (sizeof($pictures)) {
  977. CIBlockElement::SetPropertyValuesEx($arFields['ID'], 9, array(
  978. 'MORE_PHOTO' => $pictures
  979. ));
  980. }
  981. }
  982.  
  983. //Проверяем на наличие в инфблоке Породы
  984. if (strlen($arProps['BREED']['VALUE']) && !isset($breeds[strtoupper(trim($arProps['BREED']['VALUE']))])) {
  985. $code = CUtil::translit(trim($arProps['BREED']['VALUE']), 'ru', [
  986. 'max_len' => '100',
  987. 'change_case' => 'L',
  988. 'replace_space' => '-',
  989. 'replace_other' => '-',
  990. 'delete_repeat_replace' => 'true',
  991. 'use_google' => 'true',
  992. ]);
  993.  
  994. $id = $el->Add([
  995. 'IBLOCK_ID' => 36,
  996. 'NAME' => trim($arProps['BREED']['VALUE']),
  997. 'CODE' => $code,
  998. ]);
  999.  
  1000. if ($id) {
  1001. $breeds[strtoupper(trim($arProps['BREED']['VALUE']))] = 'Y';
  1002. }
  1003. }
  1004. }
  1005.  
  1006. $arSizes = array();
  1007.  
  1008. $res = CIBlockElement::GetList(array(), array(
  1009. 'IBLOCK_CODE' => 'sizes'
  1010. ), false, false, array(
  1011. 'ID',
  1012. 'NAME'
  1013. ));
  1014.  
  1015. while ($ar = $res->Fetch()) {
  1016. $arSizes[$ar['NAME']] = $ar['ID'];
  1017. }
  1018.  
  1019. $res = CIBlockElement::GetList(array(), array(
  1020. 'IBLOCK_CODE' => 'catalog-offers'
  1021. ), false, false, array('*'));
  1022.  
  1023. while ($ar = $res->GetNextElement()) {
  1024. $arFields = $ar->GetFields();
  1025. $arProps = $ar->GetProperties();
  1026.  
  1027. if (sizeof($arProps['CML2_ATTRIBUTES']['VALUE'])) {
  1028. $size = false;
  1029. $discountValue = 0;
  1030. $remainValue = '';
  1031. $codeNom = '';
  1032. $packaged = '';
  1033.  
  1034. foreach ($arProps['CML2_ATTRIBUTES']['VALUE'] as $key => $val) {
  1035. if ($arProps['CML2_ATTRIBUTES']['DESCRIPTION'][$key] == 'Размер') {
  1036. $size = trim($val);
  1037. } elseif ($arProps['CML2_ATTRIBUTES']['DESCRIPTION'][$key] == 'ЗначениеСкидки') {
  1038. $discountValue = trim($val);
  1039. } elseif ($arProps['CML2_ATTRIBUTES']['DESCRIPTION'][$key] == 'Остаток') {
  1040. $remainValue = trim($val);
  1041. } elseif ($arProps['CML2_ATTRIBUTES']['DESCRIPTION'][$key] == 'КодыНом') {
  1042. $codeNom = trim($val);
  1043. } elseif ($arProps['CML2_ATTRIBUTES']['DESCRIPTION'][$key] == 'ВУпаковке') {
  1044. $packaged = trim($val);
  1045. }
  1046. }
  1047.  
  1048. if ($size !== false) {
  1049. if (!isset($arSizes[$size])) {
  1050. $arSizes[$size] = $el->Add(array(
  1051. 'IBLOCK_ID' => $arProps['SIZE_SELECTION']['LINK_IBLOCK_ID'],
  1052. 'ACTIVE' => 'Y',
  1053. 'NAME' => $size
  1054. ));
  1055. }
  1056.  
  1057. CIBlockElement::SetPropertyValuesEx($arFields['ID'], false, array(
  1058. 'SIZE_SELECTION' => $arSizes[$size]
  1059. ));
  1060. }
  1061.  
  1062. CIBlockElement::SetPropertyValuesEx($arFields['ID'], false, array(
  1063. 'DISCOUNT_SUMM' => $discountValue,
  1064. 'CODE_NOM' => $codeNom,
  1065. 'REMAIN' => $remainValue,
  1066. 'PACKAGED' => $packaged,
  1067. ));
  1068. }
  1069. }
  1070.  
  1071. //Добавляем категорию фильтра В наличии
  1072. $oRes = CIBlockElement::GetList(array(), array(
  1073. "ACTIVE" => "Y",
  1074. "IBLOCK_ID" => 9
  1075. ), false, false, array(
  1076. "ID", "IBLOCK_SECTION_ID", "PROPERTY_TYPE_OF_FLOORING", "PROPERTY_DISCOUNT_SUMM"
  1077. , "PROPERTY_EFFECT_1", "PROPERTY_CHAMFER", "PROPERTY_UKLADKA_NA_TEPLYY_POL", "PROPERTY_POPULYARNYE", "PROPERTY_NEW_TOVAR"
  1078. ));
  1079.  
  1080. while ($aRes = $oRes->GetNext(true, false)) {
  1081. $aFilterVal = array();
  1082.  
  1083. /*Для поля Категория*/
  1084. $aFilterVal["CATEGORY_FILTER"] = array();
  1085. if ($aRes["PROPERTY_UKLADKA_NA_TEPLYY_POL_VALUE"] == "Да")
  1086. $aFilterVal["CATEGORY_FILTER"][] = "Укладка на теплый пол";
  1087.  
  1088. if ($aRes["PROPERTY_POPULYARNYE_VALUE"] == "Да")
  1089. $aFilterVal["CATEGORY_FILTER"][] = "Популярные";
  1090.  
  1091. if ($aRes["PROPERTY_NEW_TOVAR_VALUE"] == "Да")
  1092. $aFilterVal["CATEGORY_FILTER"][] = "Новинки";
  1093.  
  1094. if (IntVal(abs($aRes['PROPERTY_DISCOUNT_SUMM_VALUE'])))
  1095. $aFilterVal["CATEGORY_FILTER"][] = "Скидки";
  1096.  
  1097. $remain = 'В наличии';
  1098. $rsOffers = CIBlockElement::GetList([], [
  1099. 'IBLOCK_CODE' => 'catalog-offers',
  1100. 'PROPERTY_CML2_LINK' => $aRes['ID'],
  1101. ], false, false, [
  1102. 'PROPERTY_REMAIN'
  1103. ]);
  1104.  
  1105. while ($offer = $rsOffers->Fetch()) {
  1106. if ($offer['PROPERTY_REMAIN_VALUE'] != $remain) {
  1107. $remain = '';
  1108. break;
  1109. }
  1110. }
  1111.  
  1112. if (!isset($offer)) {
  1113. $remain = '';
  1114. }
  1115.  
  1116. if ($remain != '') {
  1117. $aFilterVal["CATEGORY_FILTER"][] = $remain;
  1118. }
  1119.  
  1120. if (count($aFilterVal) > 0)
  1121. CIBlockElement::SetPropertyValuesEx($aRes["ID"], false, $aFilterVal);
  1122.  
  1123. }
  1124.  
  1125. /*Цена и ед измерения ТП*/
  1126. $oRes = CIBlockElement::GetList(array(), array(
  1127. 'ACTIVE' => 'Y',
  1128. 'IBLOCK_CODE' => 'catalog-offers'
  1129. ), false, false, array(
  1130. 'ID',
  1131. 'IBLOCK_SECTION_ID',
  1132. 'CATALOG_GROUP_1',
  1133. 'PROPERTY_DISCOUNT_SUMM',
  1134. 'PROPERTY_CML2_BASE_UNIT',
  1135. 'PROPERTY_CML2_TRAITS'
  1136. ));
  1137.  
  1138. while ($aRes = $oRes->GetNext(true, false)) {
  1139. $aFilterVal = array();
  1140.  
  1141. $discountValue = IntVal(abs($aRes['PROPERTY_DISCOUNT_SUMM_VALUE']));
  1142. $iPrice = $aRes["CATALOG_PRICE_1"];
  1143. if ($discountValue > 0 && $aRes["CATALOG_PRICE_1"] > 0) {
  1144. $iPrice = $aRes["CATALOG_PRICE_1"] - $discountValue;
  1145. }
  1146. $aFilterVal["DISCOUNT_PRICE"] = $iPrice;
  1147.  
  1148. if (count($aFilterVal) > 0) {
  1149. CIBlockElement::SetPropertyValuesEx($aRes["ID"], false, $aFilterVal);
  1150. }
  1151.  
  1152. //ед изменерия
  1153. // CCatalogProduct::Update($aRes['ID'], array(
  1154. // 'MEASURE' => isset($measures[$aRes['PROPERTY_CML2_BASE_UNIT_VALUE']]) ? $measures[$aRes['PROPERTY_CML2_BASE_UNIT_VALUE']]['ID'] : $measures['шт']
  1155. // ));
  1156. /*
  1157. CIBlockElement::SetPropertyValuesEx($aRes["ID"], false,
  1158. array(
  1159. 'BASE_UNIT'=>$aRes['PROPERTY_CML2_BASE_UNIT_VALUE']
  1160. )
  1161. );
  1162. */
  1163.  
  1164. }
  1165.  
  1166. CModule::IncludeModule("catalog");
  1167. CCatalogExport::PreGenerateExport(5);
  1168. }
  1169.  
  1170. AddEventHandler('iblock', 'OnAfterIBlockElementUpdate', array('Handlers', 'OnAfterIBlockElementUpdate'));
  1171. AddEventHandler('main', 'OnAdminTabControlBegin', array('Handlers', 'OnAdminTabControlBegin'));
  1172. AddEventHandler('subscribe', 'BeforePostingSendMail', array('Handlers', 'BeforePostingSendMail'));
  1173. AddEventHandler('main', 'OnEndBufferContent', array('Handlers', 'OnEndBufferContent'));
  1174.  
  1175. class Handlers
  1176. {
  1177. public static function OnEndBufferContent(&$content)
  1178. {
  1179. global $APPLICATION;
  1180.  
  1181. if (!preg_match('/\/bitrix\/admin\//is', $APPLICATION->GetCurDir())) {
  1182. \Bitrix\Main\Loader::IncludeModule('iblock');
  1183. $queryBanners = CIBlockElement::GetList(array(), array(
  1184. 'IBLOCK_ID' => 39,
  1185. 'ACTIVE' => 'Y',
  1186. ), false, false, array(
  1187. 'NAME',
  1188. 'PREVIEW_PICTURE',
  1189. 'PREVIEW_TEXT',
  1190. 'PROPERTY_TAG',
  1191. 'PROPERTY_WIDTH',
  1192. 'PROPERTY_HEIGHT',
  1193. 'PROPERTY_LINK',
  1194. 'PROPERTY_LINK_OPEN_BLANK',
  1195. ));
  1196.  
  1197. while ($resBanner = $queryBanners->Fetch()) {
  1198. /*$size = array();
  1199.  
  1200. if (strlen($resBanner['PROPERTY_WIDTH_VALUE']) && strlen($resBanner['PROPERTY_HEIGHT_VALUE'])) {
  1201. $size = array(
  1202. 'width' => strlen($resBanner['PROPERTY_WIDTH_VALUE']) ? $resBanner['PROPERTY_WIDTH_VALUE'] : '',
  1203. 'height' => strlen($resBanner['PROPERTY_HEIGHT_VALUE']) ? $resBanner['PROPERTY_HEIGHT_VALUE'] : '',
  1204. );
  1205. }
  1206.  
  1207. $picture = CFile::ResizeImageGet($resBanner['PREVIEW_PICTURE'], $size, (sizeof($size) ? BX_RESIZE_IMAGE_EXACT : BX_RESIZE_IMAGE_PROPORTIONAL), true);
  1208.  
  1209. if (strlen($resBanner['PROPERTY_LINK_VALUE'])) {
  1210. $bannerHtml = '<a href="' . $resBanner['PROPERTY_LINK_VALUE'] . '"' . ($resBanner['PROPERTY_LINK_OPEN_BLANK_VALUE'] == 'Да' ? ' target="_blank"' : '') . '><img src="' . $picture['src'] . '" width="' . $picture['width'] . '" height="' . $picture['height'] . '" alt="' . $resBanner['NAME'] . '"></a>';
  1211. } else {
  1212. $bannerHtml = '<img src="' . $picture['src'] . '" width="' . $picture['width'] . '" height="' . $picture['height'] . '" alt="' . $resBanner['NAME'] . '">';
  1213. }*/
  1214.  
  1215. $content = str_replace($resBanner['PROPERTY_TAG_VALUE'], $resBanner['PREVIEW_TEXT'], $content);
  1216. }
  1217. }
  1218. }
  1219.  
  1220. public static function OnProlog()
  1221. {
  1222. global $APPLICATION;
  1223.  
  1224. $GLOBALS['parseUrl'] = explode('/', $APPLICATION->GetCurDir());
  1225. array_shift($GLOBALS['parseUrl']);
  1226. array_pop($GLOBALS['parseUrl']);
  1227.  
  1228. switch ($APPLICATION->GetCurDir()) {
  1229. case '/catalog/napolnye-pokrytiya/':
  1230. LocalRedirect('/catalog/parket/', false, '301 Moved permanently');
  1231. break;
  1232. }
  1233.  
  1234. $GLOBALS['catalogPageType'] = 'catalog';
  1235.  
  1236. if ((sizeof($GLOBALS['parseUrl']) == 3 || sizeof($GLOBALS['parseUrl']) == 4) && $GLOBALS['parseUrl'][0] == 'catalog') {
  1237. $sectionsCodeDveri = [];
  1238. $rsSectionsDveri = CIBlockSection::GetList([], [
  1239. 'IBLOCK_ID' => 9,
  1240. 'SECTION_ID' => 13,
  1241. ], false);
  1242.  
  1243. while ($sectionsDveri = $rsSectionsDveri->Fetch()) {
  1244. $rsSectionsDveriSub = CIBlockSection::GetList(array(
  1245. 'LEFT_MARGIN' => 'ASC',
  1246. ), array(
  1247. 'IBLOCK_ID' => $sectionsDveri['IBLOCK_ID'],
  1248. '>LEFT_MARGIN' => $sectionsDveri['LEFT_MARGIN'],
  1249. '<RIGHT_MARGIN' => $sectionsDveri['RIGHT_MARGIN'],
  1250. ));
  1251.  
  1252. while ($sectionsDveriSub = $rsSectionsDveriSub->Fetch()) {
  1253. $sectionsCodeDveri[] = $sectionsDveriSub['CODE'];
  1254. }
  1255.  
  1256. $sectionsCodeDveri[] = $sectionsDveri['CODE'];
  1257. }
  1258.  
  1259. $rsElementCheck = CIBlockElement::GetList([], [
  1260. 'IBLOCK_ID' => 9,
  1261. 'CODE' => $GLOBALS['parseUrl'][2],
  1262. ], false, [
  1263. 'CODE'
  1264. ])->Fetch();
  1265.  
  1266. if (!$rsElementCheck) {
  1267. if (in_array($GLOBALS['parseUrl'][1], $sectionsCodeDveri)) {
  1268. $GLOBALS['catalogPageType'] = 'brand-dveri';
  1269. } else {
  1270. $rsBrand = CIBlockElement::GetList([], [
  1271. 'IBLOCK_ID' => 1,
  1272. 'CODE' => $GLOBALS['parseUrl'][2],
  1273. ], false, false, [
  1274. 'ID'
  1275. ]);
  1276.  
  1277. if ($brand = $rsBrand->Fetch()) {
  1278. $GLOBALS['catalogPageType'] = 'brand';
  1279. } else {
  1280. $rsBreed = CIBlockElement::GetList([], [
  1281. 'IBLOCK_TYPE' => 'content',
  1282. 'IBLOCK_CODE' => 'breed',
  1283. 'CODE' => $GLOBALS['parseUrl'][2],
  1284. ], false, false, [
  1285. 'ID'
  1286. ]);
  1287.  
  1288. if ($breed = $rsBreed->Fetch()) {
  1289. $GLOBALS['catalogPageType'] = 'breed';
  1290. }
  1291. }
  1292. }
  1293. } else {
  1294. if (in_array($GLOBALS['parseUrl'][1], $sectionsCodeDveri)) {
  1295. $GLOBALS['catalogPageType'] = 'dveri-detail';
  1296. }
  1297. }
  1298. }
  1299. }
  1300.  
  1301. public static function OnAdminTabControlBegin(&$form)
  1302. {
  1303. global $APPLICATION;
  1304.  
  1305. if ($APPLICATION->GetCurPage() == '/bitrix/admin/iblock_element_edit.php' && $_REQUEST['IBLOCK_ID'] == 2 && $_REQUEST['type'] == 'content') {
  1306. \Bitrix\Main\Loader::IncludeModule('subscribe');
  1307. $rubrics = [];
  1308. $rsRubrics = CRubric::GetList([
  1309. 'ID' => 'DESC',
  1310. ], [
  1311. 'ACTIVE' => 'Y',
  1312. ]);
  1313.  
  1314. while ($rsRubric = $rsRubrics->Fetch()) {
  1315. $rubrics[] = $rsRubric;
  1316. }
  1317.  
  1318. $content = '<tr valign="top">
  1319. <td>Отправить рассылку?:</td>
  1320. <td>
  1321. <label><input type="checkbox" name="SEND_SUBSCRIBE" value="Y"> Отправить</label>
  1322. </td>
  1323. </tr>
  1324. <tr valign="top">
  1325. <td>Выберите рубрики подписчиков:</td>
  1326. <td>
  1327. <span>Письмо будет отправлено только подписчикам из указанных рубрик.</span>
  1328. <br><br>';
  1329.  
  1330. foreach ($rubrics as $rubric) {
  1331. $content .= '<div style="margin-bottom: 5px;"><label><input type="checkbox" name="SEND_RUBRICS[]" value="' . $rubric['ID'] . '"> ' . $rubric['NAME'] . '</label></div>';
  1332. }
  1333.  
  1334. $content .= '
  1335. </td>
  1336. </tr>';
  1337.  
  1338. $form->tabs[] = [
  1339. 'DIV' => 'sendSubscribe',
  1340. 'TAB' => 'Рассылка',
  1341. 'ICON' => 'main_user_edit',
  1342. 'TITLE' => 'Рассылка',
  1343. 'CONTENT' => $content,
  1344. ];
  1345. }
  1346. }
  1347.  
  1348. public static function BeforePostingSendMail($arFields) {
  1349. if (preg_match('#\#UNSUBSCRIBE_EMAIL\##is', $arFields['BODY'])) {
  1350. \Bitrix\Main\Loader::IncludeModule('subscribe');
  1351. $subscr = new CSubscription();
  1352.  
  1353. $subscribe = $subscr->GetByEmail($arFields['EMAIL'])->Fetch();
  1354.  
  1355. if ($subscribe) {
  1356. $arFields['BODY'] = str_replace(['#UNSUBSCRIBE_EMAIL#', '#UNSUBSCRIBE_TOKEN#'], [$subscribe['EMAIL'], $subscribe['CONFIRM_CODE']], $arFields['BODY']);
  1357. }
  1358. }
  1359.  
  1360. return $arFields;
  1361. }
  1362.  
  1363. public static function OnAfterIBlockElementUpdate(&$arFields)
  1364. {
  1365. if ($arFields['IBLOCK_ID'] == 2 && $arFields['ID'] > 0 && isset($_REQUEST['SEND_SUBSCRIBE'])) {
  1366. new NewsSubscribe($arFields['IBLOCK_ID'], $arFields['ID'], $_REQUEST['SEND_RUBRICS']);
  1367. }
  1368. }
  1369.  
  1370. public static function OnAfterIBlockElementAdd($arFields)
  1371. {
  1372. if ($arFields['IBLOCK_ID'] == 34 && $arFields['ID']) {
  1373. CEvent::Send('LETTER_TO_DIRECTOR', SITE_ID, array(
  1374. 'NAME' => $arFields['PROPERTY_VALUES'][227],
  1375. 'PHONE' => $arFields['PROPERTY_VALUES'][226],
  1376. 'EMAIL' => $arFields['PROPERTY_VALUES'][231],
  1377. 'MESSAGE' => $arFields['PROPERTY_VALUES'][228]
  1378. ));
  1379. } elseif ($arFields['IBLOCK_ID'] == 35 && $arFields['ID']) {
  1380. CEvent::Send('ARCHITECTS_AND_DESIGNERS', SITE_ID, array(
  1381. 'NAME' => $arFields['PROPERTY_VALUES'][232],
  1382. 'PHONE' => $arFields['PROPERTY_VALUES'][233],
  1383. 'EMAIL' => $arFields['PROPERTY_VALUES'][234],
  1384. 'MESSAGE' => $arFields['PROPERTY_VALUES'][235]
  1385. ));
  1386. } elseif ($arFields['IBLOCK_ID'] == 37) {
  1387. CEvent::Send('QUESTION_ADD', SITE_ID, array(
  1388. 'NAME' => $arFields['PROPERTY_VALUES'][245],
  1389. 'EMAIL' => $arFields['PROPERTY_VALUES'][246],
  1390. 'QUESTION' => $arFields['PROPERTY_VALUES'][247],
  1391. 'LINK' => 'http://' . $_SERVER['HTTP_HOST'] . '/bitrix/admin/iblock_element_edit.php?IBLOCK_ID=37&type=questions&ID=' . $arFields['ID'] . '&lang=ru&find_section_section=0&WF=Y',
  1392. ));
  1393. }
  1394. }
  1395. }
  1396.  
  1397. class NewsSubscribe
  1398. {
  1399. public function __construct($iblockId, $newsId, $sendRubrics = [])
  1400. {
  1401. \Bitrix\Main\Loader::IncludeModule('iblock');
  1402.  
  1403. if (!is_null($sendRubrics) && sizeof($sendRubrics) > 0) {
  1404. $rsNews = CIBlockElement::GetList([], [
  1405. 'IBLOCK_ID' => $iblockId,
  1406. 'ID' => $newsId,
  1407. '>PROPERTY_SEND_SUBSCRIBE' => 0
  1408. ], false, false, [
  1409. 'ID',
  1410. 'IBLOCK_ID',
  1411. 'ACTIVE',
  1412. 'CODE',
  1413. 'NAME',
  1414. 'PREVIEW_PICTURE',
  1415. 'DETAIL_PICTURE',
  1416. 'DETAIL_TEXT',
  1417. ]);
  1418.  
  1419. if ($rsNews = $rsNews->Fetch()) {
  1420. $this->sendSubscribe($rsNews, $sendRubrics);
  1421. }
  1422. }
  1423. }
  1424.  
  1425. private function sendSubscribe($rsNews, $sendRubrics = [])
  1426. {
  1427. \Bitrix\Main\Loader::IncludeModule('subscribe');
  1428.  
  1429. CIBlockElement::SetPropertyValuesEx($rsNews['ID'], $rsNews['IBLOCK_ID'], [
  1430. 'SEND_SUBSCRIBE' => '',
  1431. ]);
  1432.  
  1433. $picture = '';
  1434.  
  1435. if ($rsNews['DETAIL_PICTURE'] > 0) {
  1436. $picture = CFile::ResizeImageGet($rsNews['DETAIL_PICTURE'], [
  1437. 'width' => 760,
  1438. 'height' => 1000,
  1439. ]);
  1440.  
  1441. if (isset($picture['src'])) {
  1442. $picture = '<center><img src="http://vparchetti.ru' . $picture['src'] . '" alt="' . htmlspecialchars($rsNews['NAME']) . '" /></center><br>';
  1443. } else {
  1444. $picture = '';
  1445. }
  1446. }
  1447.  
  1448. $newsText = '
  1449. <div style="width: 760px; margin: 10px auto; padding: 30px 50px; background: #fff; border: 1px solid #ccc; border-radius: 5px; font-size: 12px; color:#3f2424;">
  1450. <div style="background: url(http://www.vparchetti.ru/bitrix/templates/vdp/img/logo-vdp.png) 0 0 no-repeat transparent; width: 277px; height: 64px; float: left;"></div>
  1451. <h2 style="text-align:center;height: 64px;">' . $rsNews['NAME'] . '</h2>' . $picture;
  1452. $newsText .= str_replace(['src="/', 'href="/'], ['src="http://www.vparchetti.ru/', 'href="http://www.vparchetti.ru/'], $rsNews['DETAIL_TEXT']);
  1453.  
  1454. if ($rsNews['ACTIVE'] == 'Y') {
  1455. $newsText .= '<p><a href="http://' . $_SERVER['HTTP_HOST'] . '/news/' . $rsNews['CODE'] . '/" target="_blank">Перейти к новости на сайт</a></p>';
  1456. }
  1457.  
  1458. $newsText .= '
  1459. <p style="font-size:0.9em;text-align:center;color:#afa4a4;border-top: 1px solid #ccc;margin-top: 30px;padding-top: 4px;">Письмо сгенерировано автоматически, отвечать на него не следует.</p>
  1460. <p style="font-size:0.9em;text-align:center;color:#afa4a4;"><a href="http://' . $_SERVER['HTTP_HOST'] .'/">Villa di Parchetti - Дом паркета и дверей</a></p>
  1461. <p style="font-size:0.9em;text-align:center;color:#afa4a4;"><a href="http://' . $_SERVER['HTTP_HOST'] . '/unsubscribe/?email=#UNSUBSCRIBE_EMAIL#&token=#UNSUBSCRIBE_TOKEN#">Отписаться от рассылки</a></p>
  1462. </div>
  1463. ';
  1464. $posting = new CPosting();
  1465.  
  1466. $postingId = $posting->Add([
  1467. 'FROM_FIELD' => '' . 'Villa di Parchetti <order@vparchetti.ru>',
  1468. 'SUBJECT' => 'Villa di Parchetti: ' . $rsNews['NAME'],
  1469. 'BODY_TYPE' => 'html',
  1470. 'BODY' => $newsText,
  1471. 'DIRECT_SEND' => 'Y',
  1472. 'CHARSET' => 'UTF-8',
  1473. 'SUBSCR_FORMAT' => 'html',
  1474. 'RUB_ID' => $sendRubrics,
  1475. 'GROUP_ID' => [],
  1476. ]);
  1477.  
  1478. if ($postingId > 0) {
  1479. $posting->ChangeStatus($postingId, 'P');
  1480. // $posting->SendMessage($postingId);
  1481. // $posting->AutoSend($postingId, true);
  1482. CAgent::AddAgent("CPosting::AutoSend(" . $postingId . ", true);", "subscribe", "N", 0, '', "Y", '');
  1483. }
  1484. }
  1485. }
  1486.  
  1487. class singleClass
  1488. {
  1489. public static $brands = array();
  1490. public static $brandsData = array();
  1491. public static $breedsData = array();
  1492.  
  1493. public static function getBrandUrlFromName($name)
  1494. {
  1495. $name = strtoupper(trim($name));
  1496.  
  1497. if (!sizeof(self::$brands)) {
  1498. \Bitrix\Main\Loader::IncludeModule('iblock');
  1499.  
  1500. $rs = CIBlockElement::GetList(array(), array(
  1501. 'IBLOCK_ID' => 1
  1502. ), false, false, array(
  1503. 'NAME',
  1504. 'CODE'
  1505. ));
  1506.  
  1507. while ($ar = $rs->Fetch()) {
  1508. self::$brands[strtoupper(trim($ar['NAME']))] = '/brands/' . $ar['CODE'] . '/';
  1509. }
  1510. }
  1511.  
  1512. return isset(self::$brands[$name]) ? self::$brands[$name] : '/brands/';
  1513. }
  1514.  
  1515. public static function getCatalogBrandUrlFromName($name)
  1516. {
  1517. $name = strtoupper(trim($name));
  1518.  
  1519. if (!sizeof(self::$brandsData)) {
  1520. \Bitrix\Main\Loader::IncludeModule('iblock');
  1521.  
  1522. $rs = CIBlockElement::GetList(array(), array(
  1523. 'IBLOCK_ID' => 1
  1524. ), false, false, array(
  1525. 'NAME',
  1526. 'CODE'
  1527. ));
  1528.  
  1529. while ($ar = $rs->Fetch()) {
  1530. self::$brandsData[strtoupper(trim($ar['NAME']))] = $ar;
  1531. }
  1532. }
  1533.  
  1534. return isset(self::$brandsData[$name]) ? '/catalog/' . $GLOBALS['parseUrl'][1] . '/' . self::$brandsData[$name]['CODE'] . '/' : '';
  1535. }
  1536.  
  1537. public static function getCatalogBreedUrlFromName($name)
  1538. {
  1539. $name = strtoupper(trim($name));
  1540.  
  1541. if (!sizeof(self::$breedsData)) {
  1542. \Bitrix\Main\Loader::IncludeModule('iblock');
  1543.  
  1544. $rs = CIBlockElement::GetList(array(), array(
  1545. 'IBLOCK_TYPE' => 'content',
  1546. 'IBLOCK_CODE' => 'breed',
  1547. ), false, false, array(
  1548. 'NAME',
  1549. 'CODE'
  1550. ));
  1551.  
  1552. while ($ar = $rs->Fetch()) {
  1553. self::$breedsData[strtoupper(trim($ar['NAME']))] = $ar;
  1554. }
  1555. }
  1556.  
  1557. return isset(self::$breedsData[$name]) ? '/catalog/' . $GLOBALS['parseUrl'][1] . '/' . self::$breedsData[$name]['CODE'] . '/' : '';
  1558. }
  1559. }
  1560.  
  1561. function pr($data)
  1562. {
  1563. echo '<pre>';
  1564. print_r($data);
  1565. echo '</pre>';
  1566. }
  1567.  
  1568. date_default_timezone_set("Etc/GMT-4");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement