/compare/notik/compareClass.php
PHP | 329 lines | 235 code | 35 blank | 59 comment | 23 complexity | 60cafcd066f16c26650f0741f8233d96 MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php
- //error_reporting(E_ALL);
- class Compare
- {
-
- protected $_dbLink = null;
- protected $_dbHost = '';
- protected $_dbUser = '';
- protected $_dbPass = '';
- protected $_dbName = '';
-
- public function __construct($dbLink=null)
- {
- require '/var/www/beta.citrus.ua/application/config/application.php';
- $this->_dbHost = $dbHost;
- $this->_dbUser = $dbUser;
- $this->_dbPass = $dbPass;
- $this->_dbName = $dbName;
-
- if (!$dbLink) {
- $this->_dbLink = mysql_connect($this->_dbHost, $this->_dbUser, $this->_dbPass, true) or die(mysql_error());
-
- } else {
- $this->_dbLink = $dbLink;
- }
-
- mysql_select_db($this->_dbName, $this->_dbLink) or die(mysql_error());
- mysql_query("SET NAMES cp1251", $this->_dbLink) or die(mysql_error());
- }
- // ¬озвращаем список товаров в категории
- public function getShopGoodsList($catId=189)
- {
- $arrItems = array();
-
- $catId = (int) $catId;
-
- $sql = "SELECT bie.`ID`, bie.`NAME`,
- bf1.`SUBDIR` AS PREVIEW_PICTURE_SUBDIR, bf1.`FILE_NAME` AS PREVIEW_PICTURE_NAME,
- bf2.`SUBDIR` AS DETAIL_PICTURE_SUBDIR, bf2.`FILE_NAME` AS DETAIL_PICTURE_NAME,
- bcp.`PRICE`
- FROM `b_iblock_section_element` AS bise
- JOIN `b_iblock_element` AS bie ON bie.`ID` = bise.`IBLOCK_ELEMENT_ID`
- AND bie.`ACTIVE` = 'Y'
- AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
- LEFt JOIN `b_file` AS bf1 ON bf1.`ID` = bie.`PREVIEW_PICTURE`
- LEFt JOIN `b_file` AS bf2 ON bf2.`ID` = bie.`DETAIL_PICTURE`
- JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
- AND bcp.`CATALOG_GROUP_ID` = '3'
- AND bcp.`EXTRA_ID` IS NULL
- JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
- AND bcpr.`QUANTITY` > '0'
- AND bcpr.`QUANTITY_TRACE` = 'Y'
- WHERE bise.`IBLOCK_SECTION_ID` = '{$catId}'
- AND bise.`ADDITIONAL_PROPERTY_ID` IS NULL
- ORDER BY bie.`NAME`";
- $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
- if (mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_assoc($result)) {
- $id = (int) $row['ID'];
- $arrItems[$id]['id'] = $id;
- $arrItems[$id]['name'] = stripslashes($row['NAME']);
- $arrItems[$id]['price'] = stripslashes($row['PRICE']);
- if (strlen($row['PREVIEW_PICTURE_NAME']) > 0) {
- $arrItems[$id]['pic'] = '/upload/' . $row['PREVIEW_PICTURE_SUBDIR'] . '/' . $row['PREVIEW_PICTURE_NAME'];
- } else {
- $arrItems[$id]['pic'] = '/upload/' . $row['DETAIL_PICTURE_SUBDIR'] . '/' . $row['DETAIL_PICTURE_NAME'];
- }
- }
- }
-
- return $arrItems;
- }
- // ƒетально товар
- public function searchModelParam($choice,$search)
- {
- $arrResult = array();
- $choice = (int) $choice; // ID производител€
- $search = iconv('utf-8', 'cp1251', $search);
- //$search = $this->_convertCyrToLat($search);
- $search = mysql_real_escape_string($search);
-
-
-
-
- /*
-
- SELECT bie.`ID`,bie.`IBLOCK_ID`, bie.`NAME`, bie.`IBLOCK_SECTION_ID`
- FROM `b_iblock_element` AS bie
- JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
- AND bi.`ACTIVE` = 'Y'
- JOIN `b_catalog_product` AS bcpr ON bcpr.`ID` = bie.`ID`
- WHERE bie.NAME LIKE '%Samsung NP300E7Z-S01UA%'
- AND bie.`ACTIVE` = 'Y'
- AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
- ORDER BY bie.`NAME`
-
-
-
- SELECT bie.`ID`,bie.`IBLOCK_ID`, bie.`NAME`, bie.`IBLOCK_SECTION_ID`
- FROM `b_iblock_element` AS bie
- JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
- AND bi.`ACTIVE` = 'Y'
- WHERE bie.NAME LIKE '%Samsung NP300E7Z-S01UA%'
- AND bie.`ACTIVE` = 'Y'
- AND bie.`IBLOCK_ID` = 69
- AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
- ORDER BY bie.`NAME`
-
-
-
-
- SELECT bie.`ID`,bie.`IBLOCK_ID`, bie.`NAME`,bie.`DETAIL_TEXT`,
- bi.`DETAIL_PAGE_URL`, bie.`IBLOCK_SECTION_ID`,
- bf1.`SUBDIR` AS PREVIEW_PICTURE_SUBDIR, bf1.`FILE_NAME` AS PREVIEW_PICTURE_NAME,
- bf2.`SUBDIR` AS DETAIL_PICTURE_SUBDIR, bf2.`FILE_NAME` AS DETAIL_PICTURE_NAME,
- bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
- bcp.`PRICE`
- FROM `b_iblock_element` AS bie
- JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
- AND bi.`ACTIVE` = 'Y'
- LEFt JOIN `b_file` AS bf1 ON bf1.`ID` = bie.`PREVIEW_PICTURE`
- LEFt JOIN `b_file` AS bf2 ON bf2.`ID` = bie.`DETAIL_PICTURE`
- JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
- AND bcp.`CATALOG_GROUP_ID` = '3'
- AND bcp.`EXTRA_ID` IS NULL
- LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
- AND bcp2.`CATALOG_GROUP_ID` = '4'
- WHERE bie.NAME LIKE '%Samsung NP300E7Z-S01UA%'
- AND bie.`ACTIVE` = 'Y'
- AND bie.`IBLOCK_ID`=69
- AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
- ORDER BY bie.`NAME`
-
- */
-
-
-
-
-
-
-
-
-
-
- $sql = "SELECT bie.`ID`,bie.`IBLOCK_ID`, bie.`NAME`,bie.`DETAIL_TEXT`,
- bi.`DETAIL_PAGE_URL`, bie.`IBLOCK_SECTION_ID`,
- bf1.`SUBDIR` AS PREVIEW_PICTURE_SUBDIR, bf1.`FILE_NAME` AS PREVIEW_PICTURE_NAME,
- bf2.`SUBDIR` AS DETAIL_PICTURE_SUBDIR, bf2.`FILE_NAME` AS DETAIL_PICTURE_NAME,
- bcp2.`PRICE` AS PRICE_OFFLINE, bcp2.`CURRENCY` AS CURRENCY_OFFLINE,
- bcp.`PRICE`
- FROM `b_iblock_element` AS bie
- JOIN `b_iblock` AS bi ON bi.`ID` = bie.`IBLOCK_ID`
- AND bi.`ACTIVE` = 'Y'
- LEFt JOIN `b_file` AS bf1 ON bf1.`ID` = bie.`PREVIEW_PICTURE`
- LEFt JOIN `b_file` AS bf2 ON bf2.`ID` = bie.`DETAIL_PICTURE`
- JOIN `b_catalog_price` AS bcp ON bcp.`PRODUCT_ID` = bie.`ID`
- AND bcp.`CATALOG_GROUP_ID` = '3'
- AND bcp.`EXTRA_ID` IS NULL
- LEFT JOIN `b_catalog_price` AS bcp2 ON bcp2.`PRODUCT_ID` = bie.`ID`
- AND bcp2.`CATALOG_GROUP_ID` = '4'
- WHERE bie.NAME LIKE '%".$search."%'
- AND bie.`ACTIVE` = 'Y'
- AND bie.`IBLOCK_ID`=69
- AND bie.`WF_PARENT_ELEMENT_ID` IS NULL
- ORDER BY bie.`NAME`";
- $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
- if (mysql_num_rows($result) > 0) {
- $row = mysql_fetch_assoc($result);
- $id = (int) $row['ID'];
- $arrResult['id'] = $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);
- $arrResult['url'] = $url;
- $arrResult['buy_url'] = $url . '?action=BUY&id=' . $id;
- $arrResult['name'] = stripslashes($row['NAME']);
- $arrResult['text'] = stripslashes($row['DETAIL_TEXT']);
- $arrResult['price'] = (float) $row['PRICE'];
- $arrResult['price_offline'] = (float) $row['PRICE_OFFLINE'];
- $arrResult['quantity'] = (int) $row['QUANTITY'];
- $arrResult['quantity_trace'] = $row['QUANTITY_TRACE'];
- $sql2 = "SELECT bipe.VALUE FROM b_iblock_element AS bie,
- b_iblock_property AS bip,b_iblock_property_enum AS bipe,
- b_iblock_element_property AS biep
- Where bip.IBLOCK_ID = '".$row['IBLOCK_ID']."'
- AND bip.CODE = 'LENDING'
- AND bipe.PROPERTY_ID = bip.ID
- AND biep.IBLOCK_PROPERTY_ID = bip.ID
- AND biep.IBLOCK_ELEMENT_ID = '".$id."'
- AND biep.VALUE = bipe.ID LIMIT 1";
- $result2 = mysql_query($sql2, $this->_dbLink) or die(mysql_error());
- if (mysql_num_rows($result2) > 0) {
- $row2 = mysql_fetch_assoc($result2);
- $arrResult['lending'] = $row2['VALUE'];
- } else { $arrResult['lending'] = 'нет';}
- $sql3 = "SELECT biep.VALUE FROM b_iblock_element_property AS biep
- WHERE biep.IBLOCK_PROPERTY_ID = (select ID FROM b_iblock_property WHERE IBLOCK_ID = '".$row['IBLOCK_ID']."' AND CODE = 'MORE_PHOTO')
- AND biep.IBLOCK_ELEMENT_ID = '".$id."'";
- $result3 = mysql_query($sql3, $this->_dbLink) or die(mysql_error());
- if (mysql_num_rows($result3) > 0) {
- while ($row3 = mysql_fetch_assoc($result3)) {
- $arrResult['img'][] = $row3['VALUE'];
- } }
- if (strlen($row['PREVIEW_PICTURE_NAME']) > 0) {
- $arrResult['pic'] = '/upload/' . $row['PREVIEW_PICTURE_SUBDIR'] . '/' . $row['PREVIEW_PICTURE_NAME'];
- } else {
- $arrResult['pic'] = '/upload/' . $row['DETAIL_PICTURE_SUBDIR'] . '/' . $row['DETAIL_PICTURE_NAME'];
- }
- }
-
- return $arrResult;
- }
- // ћен€ем символы
- protected function _convertCyrToLat($string)
- {
- $string = strtr($string, "йцукенгшщзхъфывапролджэ€чсмитьбю", "qwertyuiop[]asdfghjkl;'zxcvbnm,.");
- $string = strtr($string, "…÷” ≈Ќ√Ўў«’Џ‘џ¬јѕ–ќЋƒ∆Ёя„—ћ»“№Ѕё", "QWERTYUIOP[]ASDFGHJKL;'ZXCVBNM,.");
- return $string;
- }
- // вывод моделей в список по шаблону %LIKE%
- public function searchTradeinModelName($search,$develop,$id)
- {
- $arrItems = array();
-
- $search = iconv('utf-8', 'cp1251', $search);
- $search = $this->_convertCyrToLat($search);
- $search = mysql_real_escape_string($search);
-
- $sql = "select bie.NAME from b_iblock_element as bie, b_iblock_element_property as biep
- WHERE bie.NAME LIKE '%{$search}%'
- AND biep.VALUE = '{$develop}'
- and bie.IBLOCK_ID = '{$id}'
- and bie.ID = biep.IBLOCK_ELEMENT_ID
- and bie.ACTIVE = 'Y'
- and bie.`WF_PARENT_ELEMENT_ID` IS NULL
- LIMIT 30";
- $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
- if (mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_assoc($result)) {
- $arrItems[] = stripslashes($row['NAME']);
- }
- }
- return $arrItems;
- }
- // ¬ывод каталогов в категории
- public function getShopCategories($id = '20')
- {
- $arrItems = array();
-
- $sql = "SELECT `ID`, `NAME`
- FROM `b_iblock_section`
- WHERE `IBLOCK_ID` = '".$id."'
- AND `IBLOCK_SECTION_ID` IS NULL
- AND `ACTIVE` = 'Y'
- ORDER BY `SORT`, `NAME`";
- $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
- if (mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_assoc($result)) {
- $arrItems[$row['ID']] = stripslashes($row['NAME']);
- }
- }
-
- return $arrItems;
- }
- // ¬ывод цены
- public function getShopGoodPriceById($id)
- {
- $id = (int) $id;
- $price = 0;
-
- $sql = "SELECT bcp.`PRICE`
- FROM `b_catalog_price` AS bcp
- WHERE bcp.`PRODUCT_ID` = '{$id}'
- AND bcp.`CATALOG_GROUP_ID` = '3'
- AND bcp.`EXTRA_ID` IS NULL
- LIMIT 1";
- $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
- if (mysql_num_rows($result) > 0) {
- $row = mysql_fetch_assoc($result);
- $price = (float) $row['PRICE'];
- }
-
- return $price;
- }
- // ¬ывод списка производителей
- public function getDevelopersById($id='20') {
- $id = (int) $id;
- $sql = "select bipe.ID, bipe.VALUE from b_iblock_property_enum as bipe
- where bipe.PROPERTY_ID = (select id from b_iblock_property where IBLOCK_ID = '".$id."' and CODE = 'developer')";
- $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
- if (mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_assoc($result)) {
- $id = (int) $row['ID'];
- $arrDevs[$id]['id'] = $id;
- $arrDevs[$id]['name'] = stripslashes($row['VALUE']);
- }
- }
- return $arrDevs;
- }
-
- public function getTradeinModels($develop,$id='20')
- {
- $develop = (int) $develop;
- $id = (int) $id;
- $arrItems = array();
-
- $sql = "select bie.ID ,bie.NAME from b_iblock_element as bie, b_iblock_element_property as biep
- WHERE biep.VALUE = '{$develop}'
- and bie.IBLOCK_ID = '{$id}'
- and bie.ID = biep.IBLOCK_ELEMENT_ID
- and bie.ACTIVE = 'Y'
- and bie.`WF_PARENT_ELEMENT_ID` IS NULL
- LIMIT 30";
-
- $result = mysql_query($sql, $this->_dbLink) or die(mysql_error());
- if (mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_assoc($result)) {
- $arrItems[$row['ID']] = stripslashes($row['NAME']);
- }
- } else {
- $arrItems['0'] = stripslashes('Ќет товаров');
- }
-
- return $arrItems;
- }
-
- }
-
- ?>