/bitrix/templates/main-template/catalog-functions.php
PHP | 349 lines | 254 code | 51 blank | 44 comment | 28 complexity | 3d1e757c5b028ea43b07bae03f9c0a87 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';
- //--------------------- функция для вывода свойств товара --------------------------------
- // $iblockPropCode - код в инфоблоке
- // $iblockId - номер блока
- //
-
- function getCatalogProperties($iblockTypeId, $iblockPropCode, $iblockId)
- {
- //$arrResult = array();
-
- $sql = "SELECT bipe.`VALUE`, 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`
- 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.`ID` = '{$iblockId}'";
-
- $result = mysql_query($sql);
- //echo mysql_num_rows($result);
- if (mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_assoc($result)) {
- //$arrResult['value'] = $row['VALUE'];
- $arrResult = $row['VALUE'];
- }
- }
-
- return $arrResult;
- }
-
-
- //----------------------------------------------------------------------------------------
-
- 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`, bcp3.`PRICE` AS PRICE_STOCK ,
- 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'
- LEFT JOIN `b_catalog_price` AS bcp3 ON bcp3.`PRODUCT_ID` = bie.`ID`
- AND bcp3.`CATALOG_GROUP_ID` = '5'
- 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]['price_stock'] = $row['PRICE_STOCK'];
- $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) {
- // переход на страницу IPHONE
- /* if (($item['id'] == 30456) OR ($item['id'] == 31462) OR ($item['id'] == 31473) OR ($item['id'] == 31460) OR ($item['id'] == 31470) OR ($item['id'] == 31468)) {
- $item['url'] = "/apple/iphone";
- $item['buy_url'] = "/apple/iphone";
- } 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) ){
- $item['url'] = "/apple/ipad?ipad=ipad2";
- $item['buy_url'] = "/apple/ipad?ipad=ipad2";
- } elseif (($item['id'] == 45035) OR ($item['id'] == 45033) OR ($item['id'] == 45029 ) OR ($item['id'] == 45026 ) OR ($item['id'] == 45042) OR ($item['id'] == 45014)) {
- $item['url'] = "/apple/iphone5";
- $item['buy_url'] = "/apple/iphone5";
- } 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) ){
- $item['url'] = "/apple/ipad";
- $item['buy_url'] = "/apple/ipad";
- } 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) ){
- $item['url'] = "/color_iphone";
- $item['buy_url'] = "/color_iphone";
- } elseif (($item['id'] == 31477) OR ($item['id'] == 31475)){
- $item['url'] = "/apple/iphone?iphone=4p";
- $item['buy_url'] = "/apple/iphone?iphone=4p";
- } */
-
- if ($separate_categories && ($iblockId != $item['iblock_id'])) {
- $iblockId = $item['iblock_id'];
- //$xHtml .= '<h2 class="clear">' . $item['iblock_name'] . '</h2><br />';
- //<div class="hhhg2" id="hhh2"><div id="hhh"><span style="font-size:15px !important;">Лидеры продаж</span><span style="font-size:15px !important;"></span></div></div>
- $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>';
- }
- $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'];
-
- //---------- Узнаем, стоит Акционна цена -----
- $pricePrint=empty($item['price_stock'])?$pricePrint:$item['price_stock'];
- //----------------------------------------------------------------------
- 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>';
- }
-
- //----------------------------------------------------------------------
- $ss = getCatalogProperties('store_goods_main', 'warranty' , $item['id']);
- if($ss<>''){
- $xHtml .= '<span class = "propert3">Гарантия ' . $ss . '</span>';
- }
- //----------------------------------------------------------------------
-
- $xHtml .= '<ul class="cart-btn">';
- $xHtml .= '<li><a href="' . $item['url'] . '" class="link-tocart"><span>Подробнее</span></a></li>';
-
- $arrMapsModels = array(36216);
- $arrMapsModelsHTCX = array(35464,35452);
- $arrMapsModelsHTCC = array(35470,35468);
- $arrMapsModelsdesireC = array(37557,37555,37550);
- $arrMapsModelsdesirev = array(40307);
- $arrMapsModelsnexus_7 = array(39978);
- $arrMapsModelIphone5 = array(45035,45033,45029,45026,45042,45014);
- $arrMapsModelsnexus_72 = array(41530);
- $arrMapsModelsGalaxySduos = array(41250);
-
- 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/?ID=' . $item['id']
- . '" class="link-order iframe" rel="nofollow"><span>Заказать</span></a></noindex></li>';
-
-
-
-
- }
- } else {
-
- $xHtml .= '<li><noindex><a href="/preorder/?ID=' . $item['id']
- . '" class="link-order iframe" rel="nofollow"><span>Заказать</span></a></noindex></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;
- }
- }