PageRenderTime 57ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/bitrix/templates/main-template/catalog-functions.php

https://bitbucket.org/spivovartsev/citrus.ua
PHP | 349 lines | 254 code | 51 blank | 44 comment | 28 complexity | 3d1e757c5b028ea43b07bae03f9c0a87 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * catalog-functions.php
  4. * Дополнительные Функции для работы с каталогом товаров
  5. *
  6. * @author Vitaliy Tkachenko (aka vitalaw)
  7. * @version 0.1.0 2009-09-24
  8. */
  9. include_once $_SERVER['DOCUMENT_ROOT'] . '/../library/Vi/Image/Gd.php';
  10. include_once $_SERVER['DOCUMENT_ROOT'] . '/../library/May/iblock_names.php';
  11. //--------------------- функция для вывода свойств товара --------------------------------
  12. // $iblockPropCode - код в инфоблоке
  13. // $iblockId - номер блока
  14. //
  15. function getCatalogProperties($iblockTypeId, $iblockPropCode, $iblockId)
  16. {
  17. //$arrResult = array();
  18. $sql = "SELECT bipe.`VALUE`, bie.`ID`, bie.`IBLOCK_SECTION_ID`, bie.`NAME`,
  19. bf.`SUBDIR`, bf.`FILE_NAME`,
  20. bi.`DETAIL_PAGE_URL`, bi.`NAME` AS IBLOCK_NAME, bi.`ID` AS IBLOCK_ID,
  21. bcp.`PRICE`, bcp.`CURRENCY`,
  22. bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
  23. bcpr.`QUANTITY`, bcpr.`QUANTITY_TRACE`
  24. FROM `b_iblock_element` AS bie
  25. JOIN `b_file` AS bf ON bf.`ID` = bie.`PREVIEW_PICTURE`
  26. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  27. AND bi.`IBLOCK_TYPE_ID` = '{$iblockTypeId}'
  28. AND bi.`ACTIVE` = 'Y'
  29. JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
  30. AND bcp.`CATALOG_GROUP_ID` = '3'
  31. LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
  32. AND bcp2.`CATALOG_GROUP_ID` = '4'
  33. JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
  34. JOIN `b_iblock_property` AS bip ON bip.`IBLOCK_ID` = bie.`IBLOCK_ID`
  35. AND bip.`CODE` = '{$iblockPropCode}'
  36. JOIN `b_iblock_property_enum` AS bipe ON bipe.`PROPERTY_ID` = bip.`ID`
  37. JOIN `b_iblock_element_property` AS biep ON biep.`IBLOCK_PROPERTY_ID` = bip.`ID`
  38. AND biep.`IBLOCK_ELEMENT_ID` = bie.`ID`
  39. AND biep.`VALUE` = bipe.`ID`
  40. WHERE bie.`ACTIVE` = 'Y'
  41. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  42. AND bie.`ID` = '{$iblockId}'";
  43. $result = mysql_query($sql);
  44. //echo mysql_num_rows($result);
  45. if (mysql_num_rows($result) > 0) {
  46. while ($row = mysql_fetch_assoc($result)) {
  47. //$arrResult['value'] = $row['VALUE'];
  48. $arrResult = $row['VALUE'];
  49. }
  50. }
  51. return $arrResult;
  52. }
  53. //----------------------------------------------------------------------------------------
  54. function getCatalogTopData($iblockTypeId, $iblockPropCode, $iblockPropValue, $cnt=6)
  55. {
  56. $arrResult = array();
  57. if($cnt==6){
  58. $sortBy = 'bie.`SORT`, bi.`ID`, bie.`NAME`';
  59. }else{
  60. $sortBy = 'bi.`ID`, bie.`SORT`, bie.`NAME`';
  61. }
  62. $sql = "SELECT bie.`ID`, bie.`IBLOCK_SECTION_ID`, bie.`NAME`,
  63. bf.`SUBDIR`, bf.`FILE_NAME`,
  64. bi.`DETAIL_PAGE_URL`, bi.`NAME` AS IBLOCK_NAME, bi.`ID` AS IBLOCK_ID,
  65. bcp.`PRICE`, bcp.`CURRENCY`, bcp3.`PRICE` AS PRICE_STOCK ,
  66. bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
  67. bcpr.`QUANTITY`, bcpr.`QUANTITY_TRACE`
  68. FROM `b_iblock_element` AS bie
  69. JOIN `b_file` AS bf ON bf.`ID` = bie.`PREVIEW_PICTURE`
  70. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  71. AND bi.`IBLOCK_TYPE_ID` = '{$iblockTypeId}'
  72. AND bi.`ACTIVE` = 'Y'
  73. JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
  74. AND bcp.`CATALOG_GROUP_ID` = '3'
  75. LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
  76. AND bcp2.`CATALOG_GROUP_ID` = '4'
  77. LEFT JOIN `b_catalog_price` AS bcp3 ON bcp3.`PRODUCT_ID` = bie.`ID`
  78. AND bcp3.`CATALOG_GROUP_ID` = '5'
  79. JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
  80. JOIN `b_iblock_property` AS bip ON bip.`IBLOCK_ID` = bie.`IBLOCK_ID`
  81. AND bip.`CODE` = '{$iblockPropCode}'
  82. JOIN `b_iblock_property_enum` AS bipe ON bipe.`PROPERTY_ID` = bip.`ID`
  83. AND bipe.`VALUE` = '{$iblockPropValue}'
  84. JOIN `b_iblock_element_property` AS biep ON biep.`IBLOCK_PROPERTY_ID` = bip.`ID`
  85. AND biep.`IBLOCK_ELEMENT_ID` = bie.`ID`
  86. AND biep.`VALUE` = bipe.`ID`
  87. WHERE bie.`ACTIVE` = 'Y'
  88. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  89. ORDER BY ".$sortBy."
  90. LIMIT 0, {$cnt}";
  91. $result = mysql_query($sql);
  92. if (mysql_num_rows($result) > 0) {
  93. while ($row = mysql_fetch_assoc($result)) {
  94. $id = (int) $row['ID'];
  95. $url = str_replace('#SITE_DIR#', '', $row['DETAIL_PAGE_URL']);
  96. $url = str_replace('#SECTION_ID#', $row['IBLOCK_SECTION_ID'], $url);
  97. $url = str_replace('#ID#', $id, $url);
  98. $img = '/upload/' . $row['SUBDIR'] . '/' . $row['FILE_NAME'];
  99. $buyUrl = $url . '?action=BUY&id=' . $id;
  100. $arrResult[$id]['id'] = $id;
  101. $arrResult[$id]['name'] = stripslashes($row['NAME']);
  102. $arrResult[$id]['section_id'] = (int) $row['IBLOCK_SECTION_ID'];
  103. $arrResult[$id]['img'] = $img;
  104. $arrResult[$id]['url'] = $url;
  105. $arrResult[$id]['buy_url'] = $buyUrl;
  106. $arrResult[$id]['iblock_name'] = stripslashes($row['IBLOCK_NAME']);
  107. $arrResult[$id]['iblock_id'] = stripslashes($row['IBLOCK_ID']);
  108. $arrResult[$id]['price'] = $row['PRICE'];
  109. $arrResult[$id]['currency'] = $row['CURRENCY'];
  110. $arrResult[$id]['price_offline'] = $row['PRICE_OFFLINE'];
  111. $arrResult[$id]['price_stock'] = $row['PRICE_STOCK'];
  112. $arrResult[$id]['currency_offline'] = $row['CURRENCY_OFFLINE'];
  113. $arrResult[$id]['quantity'] = (int) $row['QUANTITY'];
  114. $arrResult[$id]['quantity_trace'] = $row['QUANTITY_TRACE'];
  115. }
  116. }
  117. return $arrResult;
  118. }
  119. function getCatalogTopsXhtml($arrItems, $label=null, $separate_categories=true)
  120. {
  121. $objImageGd = new Vi_Image_Gd();
  122. $arrIblockNames = getIblocksNames_forGoodsNames();
  123. $xHtml = '';
  124. if (is_array($arrItems)) {
  125. $xHtml .= '<div class="catalog-top2">';
  126. $iblockId = 0;
  127. foreach ($arrItems as $item) {
  128. // переход на страницу IPHONE
  129. /* if (($item['id'] == 30456) OR ($item['id'] == 31462) OR ($item['id'] == 31473) OR ($item['id'] == 31460) OR ($item['id'] == 31470) OR ($item['id'] == 31468)) {
  130. $item['url'] = "/apple/iphone";
  131. $item['buy_url'] = "/apple/iphone";
  132. } elseif (($item['id'] == 34567) OR ($item['id'] == 29779) OR ($item['id'] == 23635 ) OR ($item['id'] == 23633 ) OR ($item['id'] == 23673) OR ($item['id'] == 23669) OR ($item['id'] == 23675) OR ($item['id'] == 23671) ){
  133. $item['url'] = "/apple/ipad?ipad=ipad2";
  134. $item['buy_url'] = "/apple/ipad?ipad=ipad2";
  135. } elseif (($item['id'] == 45035) OR ($item['id'] == 45033) OR ($item['id'] == 45029 ) OR ($item['id'] == 45026 ) OR ($item['id'] == 45042) OR ($item['id'] == 45014)) {
  136. $item['url'] = "/apple/iphone5";
  137. $item['buy_url'] = "/apple/iphone5";
  138. } elseif (($item['id'] == 35974) OR ($item['id'] == 35971) OR ($item['id'] == 35972 ) OR ($item['id'] == 35969 ) OR ($item['id'] == 35970) OR ($item['id'] == 33251) OR ($item['id'] == 35968) ){
  139. $item['url'] = "/apple/ipad";
  140. $item['buy_url'] = "/apple/ipad";
  141. } elseif (($item['id'] == 41048) OR ($item['id'] == 41050) OR ($item['id'] == 41052 ) OR ($item['id'] == 41054 ) OR ($item['id'] == 41056) OR ($item['id'] == 41058) OR ($item['id'] == 41060) ){
  142. $item['url'] = "/color_iphone";
  143. $item['buy_url'] = "/color_iphone";
  144. } elseif (($item['id'] == 31477) OR ($item['id'] == 31475)){
  145. $item['url'] = "/apple/iphone?iphone=4p";
  146. $item['buy_url'] = "/apple/iphone?iphone=4p";
  147. } */
  148. if ($separate_categories && ($iblockId != $item['iblock_id'])) {
  149. $iblockId = $item['iblock_id'];
  150. //$xHtml .= '<h2 class="clear">' . $item['iblock_name'] . '</h2><br />';
  151. //<div class="hhhg2" id="hhh2"><div id="hhh"><span style="font-size:15px !important;">Лидеры продаж</span><span style="font-size:15px !important;"></span></div></div>
  152. $xHtml .= '<div class="hhhg2" id="hhh2"><div id="hhh"><span style="font-size:15px !important;">' . $item['iblock_name'] . '</span><span style="font-size:15px !important;"></span></div></div>';
  153. }
  154. $xHtml .= '<div class="catalog-top2-element borders2"><div><div><div><div><div><div><div><div id="otsst">';
  155. $xHtml .= '<div class="img-preview">';
  156. if (strlen($item['img']) > 0) {
  157. $xHtml .= '<a href="' . $item['url'] . '">';
  158. $xHtml .= '<img border="0" src="' . $objImageGd->getImage($item['img'], 100, 100, $label) . '" alt="'
  159. . $item['iblock_name'] . ' - ' . $item['name'] . '" title="' . $item['name'] . '" />';
  160. $xHtml .= '</a>';
  161. }
  162. $xHtml .= '</div>';
  163. $xHtml .= '<h3 class="name" style="top:0; font-weight:bold;"><a href="' . $item['url'] . '"><span style="color:#FF6600">' . $arrIblockNames[$item['iblock_id']] . '</span><br />'
  164. . $item['name'] . '</a></h3>';
  165. if ($item['price'] > 0) {
  166. $xHtml .= '<p class="prices top45">';
  167. if($item['price']!=1){
  168. $pricePrint = $item['price'];
  169. //---------- Узнаем, стоит Акционна цена -----
  170. $pricePrint=empty($item['price_stock'])?$pricePrint:$item['price_stock'];
  171. //----------------------------------------------------------------------
  172. if ($item['currency'] == 'USD') {
  173. $pricePrint .= '$' . $pricePrint;
  174. } else {
  175. $pricePrint .= '&nbsp;грн.';
  176. }
  177. $newphrase = str_replace("грн.", "<span class='price3477'>грн</span>", $pricePrint);
  178. $newphrase = str_replace(".00", "", $newphrase);
  179. $xHtml .= '<span class="catalog-price ttt">' . $newphrase . '</span><br />';
  180. if ($item['price_offline'] > $item['price']) {
  181. $pricePrint = $item['price_offline'];
  182. if ($item['currency_offline'] == 'USD') {
  183. $pricePrint .= '$' . $pricePrint;
  184. } else {
  185. $pricePrint .= '&nbsp;грн';
  186. }
  187. //$xHtml .= '<span class="catalog-price-offline ttt2">Цена в обыкновенном магазине: <strike>'
  188. // . $pricePrint . '</strike></span>';
  189. }
  190. }else{
  191. // $xHtml .= '<span class="ttt12">' . 'Уже скоро!' . '</span><br />';
  192. }
  193. $xHtml .= '</p>';
  194. }
  195. //----------------------------------------------------------------------
  196. $ss = getCatalogProperties('store_goods_main', 'warranty' , $item['id']);
  197. if($ss<>''){
  198. $xHtml .= '<span class = "propert3">Гарантия ' . $ss . '</span>';
  199. }
  200. //----------------------------------------------------------------------
  201. $xHtml .= '<ul class="cart-btn">';
  202. $xHtml .= '<li><a href="' . $item['url'] . '" class="link-tocart"><span>Подробнее</span></a></li>';
  203. $arrMapsModels = array(36216);
  204. $arrMapsModelsHTCX = array(35464,35452);
  205. $arrMapsModelsHTCC = array(35470,35468);
  206. $arrMapsModelsdesireC = array(37557,37555,37550);
  207. $arrMapsModelsdesirev = array(40307);
  208. $arrMapsModelsnexus_7 = array(39978);
  209. $arrMapsModelIphone5 = array(45035,45033,45029,45026,45042,45014);
  210. $arrMapsModelsnexus_72 = array(41530);
  211. $arrMapsModelsGalaxySduos = array(41250);
  212. if($item['price'] < 1 OR $item['price'] > 2 ){
  213. if ($item['quantity'] > 0 OR $item['quantity_trace'] == 'N') {
  214. $xHtml .= '<li><noindex><a href="' . $item['buy_url'] . '" class="link-by" rel="nofollow">
  215. <span>Купить</span></a></noindex></li>';
  216. } else {
  217. $xHtml .= '<li><noindex><a href="/preorder/?ID=' . $item['id']
  218. . '" class="link-order iframe" rel="nofollow"><span>Заказать</span></a></noindex></li>';
  219. }
  220. } else {
  221. $xHtml .= '<li><noindex><a href="/preorder/?ID=' . $item['id']
  222. . '" class="link-order iframe" rel="nofollow"><span>Заказать</span></a></noindex></li>';
  223. }
  224. $xHtml .= '</ul>';
  225. $xHtml .= '</div></div></div></div></div></div></div></div></div>';
  226. }
  227. $xHtml .= '</div>';
  228. }
  229. return $xHtml;
  230. }
  231. function getCatalogTops2DataEx2($iblockTypeId, $iblockId, $iblockPropCode, $iblockPropValue, $cnt=6)
  232. {
  233. $arrResult = array();
  234. $sql = "SELECT bie.`ID`, bie.`IBLOCK_SECTION_ID`, bie.`NAME`,
  235. bf.`SUBDIR`, bf.`FILE_NAME`,
  236. bi.`DETAIL_PAGE_URL`, bi.`NAME` AS IBLOCK_NAME, bi.`ID` AS IBLOCK_ID,
  237. bcp.`PRICE`, bcp.`CURRENCY`,
  238. bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
  239. bcpr.`QUANTITY`, bcpr.`QUANTITY_TRACE`
  240. FROM `b_iblock_element` AS bie
  241. JOIN `b_file` AS bf ON bf.`ID` = bie.`PREVIEW_PICTURE`
  242. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  243. AND bi.`IBLOCK_TYPE_ID` = '{$iblockTypeId}'
  244. AND bi.`ACTIVE` = 'Y'
  245. JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
  246. AND bcp.`CATALOG_GROUP_ID` = '3'
  247. LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
  248. AND bcp2.`CATALOG_GROUP_ID` = '4'
  249. JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
  250. JOIN `b_iblock_property` AS bip ON bip.`IBLOCK_ID` = bie.`IBLOCK_ID`
  251. AND bip.`CODE` = '{$iblockPropCode}'
  252. JOIN `b_iblock_property_enum` AS bipe ON bipe.`PROPERTY_ID` = bip.`ID`
  253. AND bipe.`VALUE` = '{$iblockPropValue}'
  254. JOIN `b_iblock_element_property` AS biep ON biep.`IBLOCK_PROPERTY_ID` = bip.`ID`
  255. AND biep.`IBLOCK_ELEMENT_ID` = bie.`ID`
  256. AND biep.`VALUE` = bipe.`ID`
  257. WHERE bie.`ACTIVE` = 'Y'
  258. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  259. AND bie.`IBLOCK_ID` = '{$iblockId}'
  260. ORDER BY bi.`ID`, bie.`SORT`, bie.`NAME`
  261. LIMIT 0, {$cnt}";
  262. $result = mysql_query($sql);
  263. if (mysql_num_rows($result) > 0) {
  264. while ($row = mysql_fetch_assoc($result)) {
  265. $id = (int) $row['ID'];
  266. $url = str_replace('#SITE_DIR#', '', $row['DETAIL_PAGE_URL']);
  267. $url = str_replace('#SECTION_ID#', $row['IBLOCK_SECTION_ID'], $url);
  268. $url = str_replace('#ID#', $id, $url);
  269. $img = '/upload/' . $row['SUBDIR'] . '/' . $row['FILE_NAME'];
  270. $buyUrl = $url . '?action=BUY&id=' . $id;
  271. $arrResult[$id]['id'] = $id;
  272. $arrResult[$id]['name'] = stripslashes($row['NAME']);
  273. $arrResult[$id]['section_id'] = (int) $row['IBLOCK_SECTION_ID'];
  274. $arrResult[$id]['img'] = $img;
  275. $arrResult[$id]['url'] = $url;
  276. $arrResult[$id]['buy_url'] = $buyUrl;
  277. $arrResult[$id]['iblock_name'] = stripslashes($row['IBLOCK_NAME']);
  278. $arrResult[$id]['iblock_id'] = stripslashes($row['IBLOCK_ID']);
  279. $arrResult[$id]['price'] = $row['PRICE'];
  280. $arrResult[$id]['currency'] = $row['CURRENCY'];
  281. $arrResult[$id]['price_offline'] = $row['PRICE_OFFLINE'];
  282. $arrResult[$id]['currency_offline'] = $row['CURRENCY_OFFLINE'];
  283. $arrResult[$id]['quantity'] = (int) $row['QUANTITY'];
  284. $arrResult[$id]['quantity_trace'] = $row['QUANTITY_TRACE'];
  285. }
  286. }
  287. return $arrResult;
  288. }
  289. function insert_shy_for_opera($str){
  290. $brouser=$_SERVER['HTTP_USER_AGENT'];
  291. if (stristr($brouser,"Opera")){
  292. $str = str_replace('-','-&shy;', $str);
  293. return $str;
  294. }
  295. else{
  296. return $str;
  297. }
  298. }