/bitrix/templates/main-template/bb/catalog-functions.php
PHP | 243 lines | 203 code | 30 blank | 10 comment | 25 complexity | 6abd88db4f3a95b7914ad6715d412b77 MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php
- /**
- * catalog-functions.php
- * Дополнительные Функции для работы с каталогом товаров
- *
- * @author Vitaliy Tkachenko (aka vitalaw)
- * @version 0.1.0 2009-09-24
- */
-
- include_once $_SERVER['DOCUMENT_ROOT'] . '/../library/Vi/Image/Gd.php';
- include_once $_SERVER['DOCUMENT_ROOT'] . '/../library/May/iblock_names.php';
-
- function getCatalogTopData($iblockTypeId, $iblockPropCode, $iblockPropValue, $cnt=6)
- {
- $arrResult = array();
-
- if($cnt==6){
- $sortBy = 'bie.`SORT`, bi.`ID`, bie.`NAME`';
- }else{
- $sortBy = 'bi.`ID`, bie.`SORT`, bie.`NAME`';
- }
-
- $sql = "SELECT bie.`ID`, bie.`IBLOCK_SECTION_ID`, bie.`NAME`,
- bf.`SUBDIR`, bf.`FILE_NAME`,
- bi.`DETAIL_PAGE_URL`, bi.`NAME` AS IBLOCK_NAME, bi.`ID` AS IBLOCK_ID,
- bcp.`PRICE`, bcp.`CURRENCY`,
- bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
- bcpr.`QUANTITY`, bcpr.`QUANTITY_TRACE`
- FROM `b_iblock_element` AS bie
- JOIN `b_file` AS bf ON bf.`ID` = bie.`PREVIEW_PICTURE`
- JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
- AND bi.`IBLOCK_TYPE_ID` = '{$iblockTypeId}'
- AND bi.`ACTIVE` = 'Y'
- JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
- AND bcp.`CATALOG_GROUP_ID` = '3'
- LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
- AND bcp2.`CATALOG_GROUP_ID` = '4'
- JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
- JOIN `b_iblock_property` AS bip ON bip.`IBLOCK_ID` = bie.`IBLOCK_ID`
- AND bip.`CODE` = '{$iblockPropCode}'
- JOIN `b_iblock_property_enum` AS bipe ON bipe.`PROPERTY_ID` = bip.`ID`
- AND bipe.`VALUE` = '{$iblockPropValue}'
- JOIN `b_iblock_element_property` AS biep ON biep.`IBLOCK_PROPERTY_ID` = bip.`ID`
- AND biep.`IBLOCK_ELEMENT_ID` = bie.`ID`
- AND biep.`VALUE` = bipe.`ID`
- WHERE bie.`ACTIVE` = 'Y'
- AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
- ORDER BY ".$sortBy."
- LIMIT 0, {$cnt}";
-
- $result = mysql_query($sql);
- if (mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_assoc($result)) {
- $id = (int) $row['ID'];
- $url = str_replace('#SITE_DIR#', '', $row['DETAIL_PAGE_URL']);
- $url = str_replace('#SECTION_ID#', $row['IBLOCK_SECTION_ID'], $url);
- $url = str_replace('#ID#', $id, $url);
- $img = '/upload/' . $row['SUBDIR'] . '/' . $row['FILE_NAME'];
- $buyUrl = $url . '?action=BUY&id=' . $id;
-
- $arrResult[$id]['id'] = $id;
- $arrResult[$id]['name'] = stripslashes($row['NAME']);
- $arrResult[$id]['section_id'] = (int) $row['IBLOCK_SECTION_ID'];
- $arrResult[$id]['img'] = $img;
- $arrResult[$id]['url'] = $url;
- $arrResult[$id]['buy_url'] = $buyUrl;
- $arrResult[$id]['iblock_name'] = stripslashes($row['IBLOCK_NAME']);
- $arrResult[$id]['iblock_id'] = stripslashes($row['IBLOCK_ID']);
- $arrResult[$id]['price'] = $row['PRICE'];
- $arrResult[$id]['currency'] = $row['CURRENCY'];
- $arrResult[$id]['price_offline'] = $row['PRICE_OFFLINE'];
- $arrResult[$id]['currency_offline'] = $row['CURRENCY_OFFLINE'];
- $arrResult[$id]['quantity'] = (int) $row['QUANTITY'];
- $arrResult[$id]['quantity_trace'] = $row['QUANTITY_TRACE'];
- }
- }
-
- return $arrResult;
- }
-
- function getCatalogTopsXhtml($arrItems, $label=null, $separate_categories=true)
- {
- $objImageGd = new Vi_Image_Gd();
-
- $arrIblockNames = getIblocksNames_forGoodsNames();
-
- $xHtml = '';
-
- if (is_array($arrItems)) {
- $xHtml .= '<div class="catalog-top2">';
- $iblockId = 0;
- foreach ($arrItems as $item) {
- if ($separate_categories && ($iblockId != $item['iblock_id'])) {
- $iblockId = $item['iblock_id'];
- $xHtml .= '<h2 class="clear">' . $item['iblock_name'] . '</h2><br />';
- }
- $xHtml .= '<div class="catalog-top2-element borders2"><div><div><div><div><div><div><div><div id="otsst">';
-
- $xHtml .= '<div class="img-preview">';
- if (strlen($item['img']) > 0) {
- $xHtml .= '<a href="' . $item['url'] . '">';
- $xHtml .= '<img border="0" src="' . $objImageGd->getImage($item['img'], 100, 100, $label) . '" alt="'
- . $item['iblock_name'] . ' - ' . $item['name'] . '" title="' . $item['name'] . '" />';
- $xHtml .= '</a>';
- }
- $xHtml .= '</div>';
-
- $xHtml .= '<h3 class="name" style="top:0; font-weight:bold;"><a href="' . $item['url'] . '"><span style="color:#FF6600">' . $arrIblockNames[$item['iblock_id']] . '</span><br />'
- . $item['name'] . '</a></h3>';
-
- if ($item['price'] > 0) {
- $xHtml .= '<p class="prices top45">';
-
- if($item['price']!=1){
-
- $pricePrint = $item['price'];
- if ($item['currency'] == 'USD') {
- $pricePrint .= '$' . $pricePrint;
- } else {
- $pricePrint .= ' грн.';
- }
- $newphrase = str_replace("грн.", "<span class='price3477'>грн</span>", $pricePrint);
- $newphrase = str_replace(".00", "", $newphrase);
- $xHtml .= '<span class="catalog-price ttt">' . $newphrase . '</span><br />';
-
- if ($item['price_offline'] > $item['price']) {
- $pricePrint = $item['price_offline'];
- if ($item['currency_offline'] == 'USD') {
- $pricePrint .= '$' . $pricePrint;
- } else {
- $pricePrint .= ' грн';
- }
- //$xHtml .= '<span class="catalog-price-offline ttt2">Цена в обыкновенном магазине: <strike>'
- // . $pricePrint . '</strike></span>';
- }
- }else{
- $xHtml .= '<span class="ttt12">' . 'Уже скоро!' . '</span><br />';
- }
-
- $xHtml .= '</p>';
- }
-
- $xHtml .= '<ul class="cart-btn">';
- $xHtml .= '<li><a href="' . $item['url'] . '" class="link-tocart"><span>Подробнее</span></a></li>';
-
- if($item['price'] < 1 OR $item['price'] > 2 ){
- if ($item['quantity'] > 0 OR $item['quantity_trace'] == 'N') {
- $xHtml .= '<li><noindex><a href="' . $item['buy_url'] . '" class="link-by" rel="nofollow">
- <span>Купить</span></a></noindex></li>';
- } else {
- $xHtml .= '<li><noindex><a href="/preorder.php?id=' . $item['id']
- . '" class="link-order iframe" rel="nofollow"><span>Заказать</span></a></noindex></li>';
- }
- } else {
- $xHtml .= '<li><noindex><a href="/preorder.php?id=' . $item['id']
- . '" class="link-order iframe" rel="nofollow"><span>Заказать</span></a></noindex></li>';
-
- }
-
- //$xHtml .= '<li><a href="' . $item['url'] . '" class="link-tocart"><span>Подробнее</span></a></li>';
- $xHtml .= '</ul>';
-
- $xHtml .= '</div></div></div></div></div></div></div></div></div>';
- }
- $xHtml .= '</div>';
- }
-
- return $xHtml;
- }
-
- function getCatalogTops2DataEx2($iblockTypeId, $iblockId, $iblockPropCode, $iblockPropValue, $cnt=6)
- {
- $arrResult = array();
-
- $sql = "SELECT bie.`ID`, bie.`IBLOCK_SECTION_ID`, bie.`NAME`,
- bf.`SUBDIR`, bf.`FILE_NAME`,
- bi.`DETAIL_PAGE_URL`, bi.`NAME` AS IBLOCK_NAME, bi.`ID` AS IBLOCK_ID,
- bcp.`PRICE`, bcp.`CURRENCY`,
- bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
- bcpr.`QUANTITY`, bcpr.`QUANTITY_TRACE`
- FROM `b_iblock_element` AS bie
- JOIN `b_file` AS bf ON bf.`ID` = bie.`PREVIEW_PICTURE`
- JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
- AND bi.`IBLOCK_TYPE_ID` = '{$iblockTypeId}'
- AND bi.`ACTIVE` = 'Y'
- JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
- AND bcp.`CATALOG_GROUP_ID` = '3'
- LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
- AND bcp2.`CATALOG_GROUP_ID` = '4'
- JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
- JOIN `b_iblock_property` AS bip ON bip.`IBLOCK_ID` = bie.`IBLOCK_ID`
- AND bip.`CODE` = '{$iblockPropCode}'
- JOIN `b_iblock_property_enum` AS bipe ON bipe.`PROPERTY_ID` = bip.`ID`
- AND bipe.`VALUE` = '{$iblockPropValue}'
- JOIN `b_iblock_element_property` AS biep ON biep.`IBLOCK_PROPERTY_ID` = bip.`ID`
- AND biep.`IBLOCK_ELEMENT_ID` = bie.`ID`
- AND biep.`VALUE` = bipe.`ID`
- WHERE bie.`ACTIVE` = 'Y'
- AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
- AND bie.`IBLOCK_ID` = '{$iblockId}'
- ORDER BY bi.`ID`, bie.`SORT`, bie.`NAME`
- LIMIT 0, {$cnt}";
-
- $result = mysql_query($sql);
- if (mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_assoc($result)) {
- $id = (int) $row['ID'];
- $url = str_replace('#SITE_DIR#', '', $row['DETAIL_PAGE_URL']);
- $url = str_replace('#SECTION_ID#', $row['IBLOCK_SECTION_ID'], $url);
- $url = str_replace('#ID#', $id, $url);
- $img = '/upload/' . $row['SUBDIR'] . '/' . $row['FILE_NAME'];
- $buyUrl = $url . '?action=BUY&id=' . $id;
-
- $arrResult[$id]['id'] = $id;
- $arrResult[$id]['name'] = stripslashes($row['NAME']);
- $arrResult[$id]['section_id'] = (int) $row['IBLOCK_SECTION_ID'];
- $arrResult[$id]['img'] = $img;
- $arrResult[$id]['url'] = $url;
- $arrResult[$id]['buy_url'] = $buyUrl;
- $arrResult[$id]['iblock_name'] = stripslashes($row['IBLOCK_NAME']);
- $arrResult[$id]['iblock_id'] = stripslashes($row['IBLOCK_ID']);
- $arrResult[$id]['price'] = $row['PRICE'];
- $arrResult[$id]['currency'] = $row['CURRENCY'];
- $arrResult[$id]['price_offline'] = $row['PRICE_OFFLINE'];
- $arrResult[$id]['currency_offline'] = $row['CURRENCY_OFFLINE'];
- $arrResult[$id]['quantity'] = (int) $row['QUANTITY'];
- $arrResult[$id]['quantity_trace'] = $row['QUANTITY_TRACE'];
- }
- }
-
- return $arrResult;
- }
-
- function insert_shy_for_opera($str){
- $brouser=$_SERVER['HTTP_USER_AGENT'];
- if (stristr($brouser,"Opera")){
- $str = str_replace('-','-­', $str);
- return $str;
- }
- else{
- return $str;
- }
- }