PageRenderTime 135ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/spivovartsev/citrus.ua
PHP | 243 lines | 203 code | 30 blank | 10 comment | 25 complexity | 6abd88db4f3a95b7914ad6715d412b77 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. function getCatalogTopData($iblockTypeId, $iblockPropCode, $iblockPropValue, $cnt=6)
  12. {
  13. $arrResult = array();
  14. if($cnt==6){
  15. $sortBy = 'bie.`SORT`, bi.`ID`, bie.`NAME`';
  16. }else{
  17. $sortBy = 'bi.`ID`, bie.`SORT`, bie.`NAME`';
  18. }
  19. $sql = "SELECT bie.`ID`, bie.`IBLOCK_SECTION_ID`, bie.`NAME`,
  20. bf.`SUBDIR`, bf.`FILE_NAME`,
  21. bi.`DETAIL_PAGE_URL`, bi.`NAME` AS IBLOCK_NAME, bi.`ID` AS IBLOCK_ID,
  22. bcp.`PRICE`, bcp.`CURRENCY`,
  23. bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
  24. bcpr.`QUANTITY`, bcpr.`QUANTITY_TRACE`
  25. FROM `b_iblock_element` AS bie
  26. JOIN `b_file` AS bf ON bf.`ID` = bie.`PREVIEW_PICTURE`
  27. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  28. AND bi.`IBLOCK_TYPE_ID` = '{$iblockTypeId}'
  29. AND bi.`ACTIVE` = 'Y'
  30. JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
  31. AND bcp.`CATALOG_GROUP_ID` = '3'
  32. LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
  33. AND bcp2.`CATALOG_GROUP_ID` = '4'
  34. JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
  35. JOIN `b_iblock_property` AS bip ON bip.`IBLOCK_ID` = bie.`IBLOCK_ID`
  36. AND bip.`CODE` = '{$iblockPropCode}'
  37. JOIN `b_iblock_property_enum` AS bipe ON bipe.`PROPERTY_ID` = bip.`ID`
  38. AND bipe.`VALUE` = '{$iblockPropValue}'
  39. JOIN `b_iblock_element_property` AS biep ON biep.`IBLOCK_PROPERTY_ID` = bip.`ID`
  40. AND biep.`IBLOCK_ELEMENT_ID` = bie.`ID`
  41. AND biep.`VALUE` = bipe.`ID`
  42. WHERE bie.`ACTIVE` = 'Y'
  43. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  44. ORDER BY ".$sortBy."
  45. LIMIT 0, {$cnt}";
  46. $result = mysql_query($sql);
  47. if (mysql_num_rows($result) > 0) {
  48. while ($row = mysql_fetch_assoc($result)) {
  49. $id = (int) $row['ID'];
  50. $url = str_replace('#SITE_DIR#', '', $row['DETAIL_PAGE_URL']);
  51. $url = str_replace('#SECTION_ID#', $row['IBLOCK_SECTION_ID'], $url);
  52. $url = str_replace('#ID#', $id, $url);
  53. $img = '/upload/' . $row['SUBDIR'] . '/' . $row['FILE_NAME'];
  54. $buyUrl = $url . '?action=BUY&id=' . $id;
  55. $arrResult[$id]['id'] = $id;
  56. $arrResult[$id]['name'] = stripslashes($row['NAME']);
  57. $arrResult[$id]['section_id'] = (int) $row['IBLOCK_SECTION_ID'];
  58. $arrResult[$id]['img'] = $img;
  59. $arrResult[$id]['url'] = $url;
  60. $arrResult[$id]['buy_url'] = $buyUrl;
  61. $arrResult[$id]['iblock_name'] = stripslashes($row['IBLOCK_NAME']);
  62. $arrResult[$id]['iblock_id'] = stripslashes($row['IBLOCK_ID']);
  63. $arrResult[$id]['price'] = $row['PRICE'];
  64. $arrResult[$id]['currency'] = $row['CURRENCY'];
  65. $arrResult[$id]['price_offline'] = $row['PRICE_OFFLINE'];
  66. $arrResult[$id]['currency_offline'] = $row['CURRENCY_OFFLINE'];
  67. $arrResult[$id]['quantity'] = (int) $row['QUANTITY'];
  68. $arrResult[$id]['quantity_trace'] = $row['QUANTITY_TRACE'];
  69. }
  70. }
  71. return $arrResult;
  72. }
  73. function getCatalogTopsXhtml($arrItems, $label=null, $separate_categories=true)
  74. {
  75. $objImageGd = new Vi_Image_Gd();
  76. $arrIblockNames = getIblocksNames_forGoodsNames();
  77. $xHtml = '';
  78. if (is_array($arrItems)) {
  79. $xHtml .= '<div class="catalog-top2">';
  80. $iblockId = 0;
  81. foreach ($arrItems as $item) {
  82. if ($separate_categories && ($iblockId != $item['iblock_id'])) {
  83. $iblockId = $item['iblock_id'];
  84. $xHtml .= '<h2 class="clear">' . $item['iblock_name'] . '</h2><br />';
  85. }
  86. $xHtml .= '<div class="catalog-top2-element borders2"><div><div><div><div><div><div><div><div id="otsst">';
  87. $xHtml .= '<div class="img-preview">';
  88. if (strlen($item['img']) > 0) {
  89. $xHtml .= '<a href="' . $item['url'] . '">';
  90. $xHtml .= '<img border="0" src="' . $objImageGd->getImage($item['img'], 100, 100, $label) . '" alt="'
  91. . $item['iblock_name'] . ' - ' . $item['name'] . '" title="' . $item['name'] . '" />';
  92. $xHtml .= '</a>';
  93. }
  94. $xHtml .= '</div>';
  95. $xHtml .= '<h3 class="name" style="top:0; font-weight:bold;"><a href="' . $item['url'] . '"><span style="color:#FF6600">' . $arrIblockNames[$item['iblock_id']] . '</span><br />'
  96. . $item['name'] . '</a></h3>';
  97. if ($item['price'] > 0) {
  98. $xHtml .= '<p class="prices top45">';
  99. if($item['price']!=1){
  100. $pricePrint = $item['price'];
  101. if ($item['currency'] == 'USD') {
  102. $pricePrint .= '$' . $pricePrint;
  103. } else {
  104. $pricePrint .= '&nbsp;грн.';
  105. }
  106. $newphrase = str_replace("грн.", "<span class='price3477'>грн</span>", $pricePrint);
  107. $newphrase = str_replace(".00", "", $newphrase);
  108. $xHtml .= '<span class="catalog-price ttt">' . $newphrase . '</span><br />';
  109. if ($item['price_offline'] > $item['price']) {
  110. $pricePrint = $item['price_offline'];
  111. if ($item['currency_offline'] == 'USD') {
  112. $pricePrint .= '$' . $pricePrint;
  113. } else {
  114. $pricePrint .= '&nbsp;грн';
  115. }
  116. //$xHtml .= '<span class="catalog-price-offline ttt2">Цена в обыкновенном магазине: <strike>'
  117. // . $pricePrint . '</strike></span>';
  118. }
  119. }else{
  120. $xHtml .= '<span class="ttt12">' . 'Уже скоро!' . '</span><br />';
  121. }
  122. $xHtml .= '</p>';
  123. }
  124. $xHtml .= '<ul class="cart-btn">';
  125. $xHtml .= '<li><a href="' . $item['url'] . '" class="link-tocart"><span>Подробнее</span></a></li>';
  126. if($item['price'] < 1 OR $item['price'] > 2 ){
  127. if ($item['quantity'] > 0 OR $item['quantity_trace'] == 'N') {
  128. $xHtml .= '<li><noindex><a href="' . $item['buy_url'] . '" class="link-by" rel="nofollow">
  129. <span>Купить</span></a></noindex></li>';
  130. } else {
  131. $xHtml .= '<li><noindex><a href="/preorder.php?id=' . $item['id']
  132. . '" class="link-order iframe" rel="nofollow"><span>Заказать</span></a></noindex></li>';
  133. }
  134. } else {
  135. $xHtml .= '<li><noindex><a href="/preorder.php?id=' . $item['id']
  136. . '" class="link-order iframe" rel="nofollow"><span>Заказать</span></a></noindex></li>';
  137. }
  138. //$xHtml .= '<li><a href="' . $item['url'] . '" class="link-tocart"><span>Подробнее</span></a></li>';
  139. $xHtml .= '</ul>';
  140. $xHtml .= '</div></div></div></div></div></div></div></div></div>';
  141. }
  142. $xHtml .= '</div>';
  143. }
  144. return $xHtml;
  145. }
  146. function getCatalogTops2DataEx2($iblockTypeId, $iblockId, $iblockPropCode, $iblockPropValue, $cnt=6)
  147. {
  148. $arrResult = array();
  149. $sql = "SELECT bie.`ID`, bie.`IBLOCK_SECTION_ID`, bie.`NAME`,
  150. bf.`SUBDIR`, bf.`FILE_NAME`,
  151. bi.`DETAIL_PAGE_URL`, bi.`NAME` AS IBLOCK_NAME, bi.`ID` AS IBLOCK_ID,
  152. bcp.`PRICE`, bcp.`CURRENCY`,
  153. bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
  154. bcpr.`QUANTITY`, bcpr.`QUANTITY_TRACE`
  155. FROM `b_iblock_element` AS bie
  156. JOIN `b_file` AS bf ON bf.`ID` = bie.`PREVIEW_PICTURE`
  157. JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
  158. AND bi.`IBLOCK_TYPE_ID` = '{$iblockTypeId}'
  159. AND bi.`ACTIVE` = 'Y'
  160. JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
  161. AND bcp.`CATALOG_GROUP_ID` = '3'
  162. LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
  163. AND bcp2.`CATALOG_GROUP_ID` = '4'
  164. JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
  165. JOIN `b_iblock_property` AS bip ON bip.`IBLOCK_ID` = bie.`IBLOCK_ID`
  166. AND bip.`CODE` = '{$iblockPropCode}'
  167. JOIN `b_iblock_property_enum` AS bipe ON bipe.`PROPERTY_ID` = bip.`ID`
  168. AND bipe.`VALUE` = '{$iblockPropValue}'
  169. JOIN `b_iblock_element_property` AS biep ON biep.`IBLOCK_PROPERTY_ID` = bip.`ID`
  170. AND biep.`IBLOCK_ELEMENT_ID` = bie.`ID`
  171. AND biep.`VALUE` = bipe.`ID`
  172. WHERE bie.`ACTIVE` = 'Y'
  173. AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
  174. AND bie.`IBLOCK_ID` = '{$iblockId}'
  175. ORDER BY bi.`ID`, bie.`SORT`, bie.`NAME`
  176. LIMIT 0, {$cnt}";
  177. $result = mysql_query($sql);
  178. if (mysql_num_rows($result) > 0) {
  179. while ($row = mysql_fetch_assoc($result)) {
  180. $id = (int) $row['ID'];
  181. $url = str_replace('#SITE_DIR#', '', $row['DETAIL_PAGE_URL']);
  182. $url = str_replace('#SECTION_ID#', $row['IBLOCK_SECTION_ID'], $url);
  183. $url = str_replace('#ID#', $id, $url);
  184. $img = '/upload/' . $row['SUBDIR'] . '/' . $row['FILE_NAME'];
  185. $buyUrl = $url . '?action=BUY&id=' . $id;
  186. $arrResult[$id]['id'] = $id;
  187. $arrResult[$id]['name'] = stripslashes($row['NAME']);
  188. $arrResult[$id]['section_id'] = (int) $row['IBLOCK_SECTION_ID'];
  189. $arrResult[$id]['img'] = $img;
  190. $arrResult[$id]['url'] = $url;
  191. $arrResult[$id]['buy_url'] = $buyUrl;
  192. $arrResult[$id]['iblock_name'] = stripslashes($row['IBLOCK_NAME']);
  193. $arrResult[$id]['iblock_id'] = stripslashes($row['IBLOCK_ID']);
  194. $arrResult[$id]['price'] = $row['PRICE'];
  195. $arrResult[$id]['currency'] = $row['CURRENCY'];
  196. $arrResult[$id]['price_offline'] = $row['PRICE_OFFLINE'];
  197. $arrResult[$id]['currency_offline'] = $row['CURRENCY_OFFLINE'];
  198. $arrResult[$id]['quantity'] = (int) $row['QUANTITY'];
  199. $arrResult[$id]['quantity_trace'] = $row['QUANTITY_TRACE'];
  200. }
  201. }
  202. return $arrResult;
  203. }
  204. function insert_shy_for_opera($str){
  205. $brouser=$_SERVER['HTTP_USER_AGENT'];
  206. if (stristr($brouser,"Opera")){
  207. $str = str_replace('-','-&shy;', $str);
  208. return $str;
  209. }
  210. else{
  211. return $str;
  212. }
  213. }