function zen_get_subcategories(&$subcategories_array, $parent_id = 0)
{
    global $db;
    $subcategories_query = "select categories_id\n                            from " . TABLE_CATEGORIES . "\n                            where parent_id = '" . (int) $parent_id . "'";
    $subcategories = $db->Execute($subcategories_query);
    while (!$subcategories->EOF) {
        $subcategories_array[sizeof($subcategories_array)] = $subcategories->fields['categories_id'];
        if ($subcategories->fields['categories_id'] != $parent_id) {
            zen_get_subcategories($subcategories_array, $subcategories->fields['categories_id']);
        }
        $subcategories->MoveNext();
    }
}
Beispiel #2
0
 * @copyright Copyright 2003-2011 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: header_php.php 18697 2011-05-04 14:35:20Z wilt $
 */
// This should be first line of the script:
$zco_notifier->notify('NOTIFY_HEADER_START_INDEX');
// the following cPath references come from application_top/initSystem
$category_depth = 'top';
if (isset($cPath) && zen_not_null($cPath)) {
    $category_parent_query = "SELECT count(*) AS total\n                              FROM   " . TABLE_CATEGORIES . "\n                              WHERE  parent_id = :categoriesID";
    $category_parent_query = $db->bindVars($category_parent_query, ':categoriesID', $current_category_id, 'integer');
    $category_parent = $db->Execute($category_parent_query);
    if ($category_parent->fields['total'] > 0) {
        $sub_categories = array();
        zen_get_subcategories($sub_categories, $current_category_id);
        $sub_categories[] = $current_category_id;
        $category_product_query = $db->Execute('SELECT COUNT(*) AS total FROM ' . TABLE_PRODUCTS_TO_CATEGORIES . ' WHERE categories_id IN (' . implode(', ', $sub_categories) . ')', null, true, CACHE_TIMELIFT);
        if ($category_product_query->fields['total'] > 0) {
            $category_depth = 'products';
        } else {
            $category_depth = 'nested';
        }
        // navigate through the categories
    } else {
        $category_depth = 'products';
    }
    // 	$categories_products_query = "SELECT count(*) AS total
    //                                 FROM   " . TABLE_PRODUCTS_TO_CATEGORIES . "
    //                                 WHERE   categories_id = :categoriesID";
    // 	$categories_products_query = $db->bindVars($categories_products_query, ':categoriesID', $current_category_id, 'integer');
 //echo '<pre>';print_r($current_sub_categories);exit;
 if (!empty($sub_categories)) {
     $pc_id = $sub_categories[0];
     $subcategories_array = zen_get_categories('', $pc_id);
     $arr = array();
     foreach ($subcategories_array as $key => $val) {
         $arr[] = $val['id'];
     }
     if (count($arr)) {
         $id_str = implode(",", $arr);
         $categories_query = "select c.categories_id,c.categories_image,cd.categories_name\n\t\t\t    from categories c\n\t\t\t    inner join categories_description cd on c.categories_id=cd.categories_id\n\t\t\t    where c.categories_id in (" . $id_str . ") and c.categories_status=1";
         $categories = $db->Execute($categories_query);
         $number_of_categories = $categories->RecordCount();
     }
 } else {
     zen_get_subcategories($subcategories_array, $current_category_id);
     //echo '<pre>';print_r($subcategories_array);exit;
     // $pc_id = $sub_categories[0];
     // $subcategories_array = zen_get_categories('',$pc_id);
     $arr = array();
     foreach ($subcategories_array as $key => $val) {
         $arr[] = $val;
     }
     //echo '<pre>';print_r($arr);exit;
     if (count($arr)) {
         $id_str = implode(",", $arr);
         $categories_query = "select c.categories_id,c.categories_image,cd.categories_name\n\t\t    from categories c\n\t\t    inner join categories_description cd on c.categories_id=cd.categories_id\n\t\t    where c.categories_id in (" . $id_str . ") and c.categories_status=1";
         $categories = $db->Execute($categories_query);
         $number_of_categories = $categories->RecordCount();
     }
 }
Beispiel #4
0
// Notifier Point
$zco_notifier->notify('NOTIFY_SEARCH_FROM_STRING');
$where_str = " WHERE (p.products_status = 1\r\n               AND p.products_id = pd.products_id\r\n               AND pd.language_id = :languagesID\r\n               AND p.products_id = p2c.products_id\r\n               AND p2c.categories_id = c.categories_id ";
$where_str = $db->bindVars($where_str, ':languagesID', $_SESSION['languages_id'], 'integer');
// reset previous selection
if (!isset($_GET['inc_subcat'])) {
    $_GET['inc_subcat'] = '0';
}
if (!isset($_GET['search_in_description'])) {
    $_GET['search_in_description'] = '0';
}
$_GET['search_in_description'] = (int) $_GET['search_in_description'];
if (isset($_GET['categories_id']) && zen_not_null($_GET['categories_id'])) {
    if ($_GET['inc_subcat'] == '1') {
        $subcategories_array = array();
        zen_get_subcategories($subcategories_array, $_GET['categories_id']);
        $where_str .= " AND p2c.products_id = p.products_id\r\n                    AND p2c.products_id = pd.products_id\r\n                    AND (p2c.categories_id = :categoriesID";
        $where_str = $db->bindVars($where_str, ':categoriesID', $_GET['categories_id'], 'integer');
        if (sizeof($subcategories_array) > 0) {
            $where_str .= " OR p2c.categories_id in (";
            for ($i = 0, $n = sizeof($subcategories_array); $i < $n; $i++) {
                $where_str .= " :categoriesID";
                if ($i + 1 < $n) {
                    $where_str .= ",";
                }
                $where_str = $db->bindVars($where_str, ':categoriesID', $subcategories_array[$i], 'integer');
            }
            $where_str .= ")";
        }
        $where_str .= ")";
    } else {
 function get_search_query($select_str, $add_where = "", $force_price_with_tax = false)
 {
     global $db, $currencies;
     $price_with_tax = false;
     if ($force_price_with_tax) {
         $price_with_tax = true;
     } else {
         if (DISPLAY_PRICE_WITH_TAX == 'true' && (isset($this->search_params['price_from']) && $this->search_params['price_from'] !== '' || isset($this->search_params['price_to']) && $this->search_params['price_to'] !== '')) {
             $price_with_tax = true;
         }
     }
     /*
        from
     */
     $from_str = " FROM (" . TABLE_PRODUCTS . " p\n                 LEFT JOIN " . TABLE_MANUFACTURERS . " m\n                   USING(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c\n                 LEFT JOIN " . TABLE_META_TAGS_PRODUCTS_DESCRIPTION . " mtpd\n                   ON mtpd.products_id= p2c.products_id\n                   AND mtpd.language_id = :languagesID )";
     $from_str = $db->bindVars($from_str, ':languagesID', $_SESSION['languages_id'], 'integer');
     if (MODULE_PRODUCTS_WITH_ATTRIBUTES_STOCK_STATUS == 'true') {
         $from_str .= " LEFT JOIN " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " AS pwas\n                       ON p.products_id = pwas.products_id";
     }
     if ($price_with_tax) {
         if (!$_SESSION['customer_country_id']) {
             $_SESSION['customer_country_id'] = STORE_COUNTRY;
             $_SESSION['customer_zone_id'] = STORE_ZONE;
         }
         $from_str .= " LEFT JOIN " . TABLE_TAX_RATES . " tr\n                       ON p.products_tax_class_id = tr.tax_class_id\n                     LEFT JOIN " . TABLE_ZONES_TO_GEO_ZONES . " gz\n                       ON tr.tax_zone_id = gz.geo_zone_id\n                       AND (gz.zone_country_id IS null OR gz.zone_country_id = 0 OR gz.zone_country_id = :zoneCountryID)\n                       AND (gz.zone_id IS null OR gz.zone_id = 0 OR gz.zone_id = :zoneID)";
         $from_str = $db->bindVars($from_str, ':zoneCountryID', $_SESSION['customer_country_id'], 'integer');
         $from_str = $db->bindVars($from_str, ':zoneID', $_SESSION['customer_zone_id'], 'integer');
     }
     if ($this->search_params['featured']) {
         $from_str .= " INNER JOIN " . TABLE_FEATURED . " f\n                       ON p.products_id = f.products_id\n                      AND f.status = 1";
     }
     if ($this->search_params['specials']) {
         $from_str .= " INNER JOIN " . TABLE_SPECIALS . " sp\n                       ON p.products_id = sp.products_id\n                      AND sp.status = 1";
     }
     /*
        where
     */
     $where_str = " WHERE p.products_status = 1\n                   AND p.products_id = pd.products_id\n                   AND pd.language_id = :languagesID\n                   AND p.products_id = p2c.products_id\n                   AND p2c.categories_id = c.categories_id ";
     $where_str = $db->bindVars($where_str, ':languagesID', $_SESSION['languages_id'], 'integer');
     // keywords
     if (!empty($this->search_params['keywords_array'])) {
         $target_columns = array("pd.products_name", "pd.products_description");
         if (MODULE_PRODUCTS_WITH_ATTRIBUTES_STOCK_STATUS == 'true') {
             //        $target_columns[] = "pwas.skumodel";
         }
         $tmp = array();
         foreach ($this->search_params['keywords_array'] as $keywords) {
             $keywords = zen_db_input($keywords);
             if (MODULE_SUPER_PRODUCTS_LIST_SENNA_STATUS == 'true') {
                 $tmp[] = "MATCH(" . join(",", $target_columns) . ") AGAINST('" . $keywords . "')";
             } else {
                 $ors = array();
                 foreach ($target_columns as $target_column) {
                     $ors[] = $target_column . " LIKE '%" . $keywords . "%'";
                 }
                 $tmp[] = '(' . join(' OR ', $ors) . ')';
             }
         }
         $where_str .= " AND (" . join(" AND ", $tmp) . ")";
     }
     // categories_id
     if ($this->search_params['categories_id']) {
         $subcategories = array($this->search_params['categories_id']);
         zen_get_subcategories($subcategories, $this->search_params['categories_id']);
         $where_str .= " AND p2c.categories_id IN (" . join(',', $subcategories) . ")";
     }
     // manufacturers_id
     if ($this->search_params['manufacturers_id']) {
         $where_str .= " AND p.manufacturers_id = " . (int) $this->search_params['manufacturers_id'];
     }
     // price
     $pfrom = $this->search_params['price_from'];
     $pto = $this->search_params['price_to'];
     $rate = $currencies->get_value($_SESSION['currency']);
     if ($rate) {
         $pfrom = $pfrom / $rate;
         $pto = $pto / $rate;
     }
     if (DISPLAY_PRICE_WITH_TAX == 'true') {
         if ($this->search_params['price_from'] !== '') {
             $where_str .= " AND (p.products_price_sorter * IF(gz.geo_zone_id IS null, 1, 1 + (tr.tax_rate / 100)) >= :price)";
             $where_str = $db->bindVars($where_str, ':price', $pfrom, 'float');
         }
         if ($this->search_params['price_to'] !== '') {
             $where_str .= " AND (p.products_price_sorter * IF(gz.geo_zone_id IS null, 1, 1 + (tr.tax_rate / 100)) <= :price)";
             $where_str = $db->bindVars($where_str, ':price', $pto, 'float');
         }
     } else {
         if ($this->search_params['price_from'] !== '') {
             $where_str .= " and (p.products_price_sorter >= :price)";
             $where_str = $db->bindVars($where_str, ':price', $pfrom, 'float');
         }
         if ($this->search_params['price_to'] !== '') {
             $where_str .= " and (p.products_price_sorter <= :price)";
             $where_str = $db->bindVars($where_str, ':price', $pto, 'float');
         }
     }
     // date
     if ($this->search_params['date_from']) {
         $where_str .= " AND p.products_date_available >= :dateAvailable";
         $where_str = $db->bindVars($where_str, ':dateAvailable', zen_date_raw($this->search_params['date_from']), 'date');
     }
     if ($this->search_params['date_to']) {
         $where_str .= " AND p.products_date_available <= :dateAvailable";
         $where_str = $db->bindVars($where_str, ':dateAvailable', zen_date_raw($this->search_params['date_to']), 'date');
     }
     $where_str .= $add_where;
     return $select_str . $from_str . $where_str;
 }
Beispiel #6
0
 */
$row = 0;
$priceListArray = array();
$priceList = array();
// don't build a tree when no categories
require $template->get_template_dir('tpl_categories.php', DIR_WS_TEMPLATE, $current_page_base, 'sideboxes') . '/tpl_categories.php';
$title = BOX_HEADING_CATEGORIES_BOX;
$subtitle = BOX_SUBHEADING_CATEGORIES_BOX;
$title_link = false;
/*
 * priceList  four part
 */
if (zen_has_category_subcategories($current_category_id)) {
    $priceListQuery_sql = '';
    $priceListQueryArray = array();
    zen_get_subcategories($product_in_categoriesArray, $current_category_id);
    $priceListQuery_sql = implode(' or p2c.categories_id =', $product_in_categoriesArray);
    $priceListQuery_sql = '( p2c.categories_id = ' . $priceListQuery_sql . ')';
} else {
    $priceListQuery_sql = 'p2c.categories_id = ' . (int) $current_category_id;
}
$priceListQuery = "SELECT p. products_id ,p.`products_price`,p2c.`categories_id` FROM products p,products_to_categories p2c WHERE p2c.products_id=p.products_id AND " . $priceListQuery_sql . " order by products_price";
$priceListArray = $db->Execute($priceListQuery);
while (!$priceListArray->EOF) {
    //caizhouqing update left_discount
    $rs = $db->Execute("select specials_new_products_price from specials where products_id=" . $priceListArray->fields['products_id']);
    if (!$rs->EOF) {
        $priceList[] = $rs->fields['specials_new_products_price'];
    } else {
        $priceList[] = $priceListArray->fields['products_price'];
    }
/**
 * SNAF version 1.4
 * Specials
 *
 * @package page
 * @copyright Copyright 2003-2011 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: main_template_vars.php 18802 2011-05-25 20:23:34Z drbyte $
 */
//===========  bof SNAF (filter by category)
if ($_GET['sale_category']) {
    // find subcategories
    $subcategories_array = array();
    zen_get_subcategories($subcategories_array, $_GET['sale_category']);
    $subcategories_array[] = $_GET['sale_category'];
    foreach ($subcategories_array as $s) {
        $string .= "'" . $s . "',";
    }
    $string = substr($string, 0, -1);
    $extra = "AND p.master_categories_id IN (" . $string . ") ";
} else {
    $extra = '';
}
//===========  eof SNAF (filter by category)
if (MAX_DISPLAY_SPECIAL_PRODUCTS > 0) {
    // INCLUDE SALE ITEMS IN SPECIALS LISTING
    // add sort order
    $disp_order_default = PRODUCT_ALL_LIST_SORT_DEFAULT;
    require DIR_WS_MODULES . zen_get_module_directory(FILENAME_LISTING_DISPLAY_ORDER);
 */
if (!defined('IS_ADMIN_FLAG')) {
    die('Illegal Access');
}
//echo "===================================================$current_category_id".$current_category_id;
//require(DIR_WS_MODULES . zen_get_module_directory('category_row.php'));
/**
echo '<pre>===============------------------------------';
echo $current_category_id;
print_r(getChildCategoryId($current_category_id));
exit;
/**/
if (isset($current_category_id) && $current_category_id > 0) {
    //check if the current category  is parent category, if yes, find its child category
    //$where_cat_in_array = getChildCategoryId($current_category_id);
    zen_get_subcategories($where_cat_in_array, $current_category_id);
    if (empty($where_cat_in_array)) {
        $where_cat_in_str = "c.categories_id=" . (int) $current_category_id;
    } else {
        $where_cat_in_array[] = $current_category_id;
        $where_cat_in_str = implode(",", $where_cat_in_array);
        $where_cat_in_str = "c.categories_id in (" . $where_cat_in_str . ") ";
    }
    $products_listing_sql = 'select distinct p.products_id,p.products_image,
	                                       pd.products_name,pd.products_short_description,
										   p.products_afterbuy_model,p.products_weight
	                       from ' . TABLE_PRODUCTS . ' p,
						        ' . TABLE_PRODUCTS_TO_CATEGORIES . ' p2c,
								' . TABLE_PRODUCTS_DESCRIPTION . ' pd,
								' . TABLE_CATEGORIES . ' c
						   where p.products_status=1 						  
                ?>
			<div class="allborder right_small_con margin_t" style="overflow: hidden; width: 207px;">
			<a href="<?php 
                echo $index_categories_banner_2_link;
                ?>
"><?php 
                echo zen_image(DIR_WS_IMAGES . $index_categories_banner_2_img, '');
                ?>
</a></div>
<?php 
            }
        }
        if (!$this_is_home_page && $categories_displayTypes == 1) {
            if (zen_has_category_subcategories($current_category_id)) {
                $topSelling_subcategories = array();
                zen_get_subcategories($topSelling_subcategories, $current_category_id);
                $topSelling_subcategories_str = implode(' or pt.categories_id = ', $topSelling_subcategories);
                $suffix_sql = ' AND ( pt.categories_id =' . $topSelling_subcategories_str . ')';
            } else {
                $suffix_sql = ' AND pt.categories_id = \'' . $current_category_id . '\'';
            }
            $topSellingQuery = "SELECT p.`products_id`,p.`products_image`, pd.`products_name` \n                      FROM products p, products_description pd,products_to_categories pt\n                      WHERE pd.`language_id` = {$_SESSION['languages_id']} AND p.`products_status` = 1 AND pt.products_id=p.products_id AND pd.products_id=p.products_id " . $suffix_sql . "\n                      ORDER BY p.`products_ordered` DESC LIMIT 5";
            $topSelling = $db->Execute($topSellingQuery);
            if ($topSelling->RecordCount() > 0) {
                ?>
<div class="allborder pad_10px">
<h2 class="red"><?php 
                echo BASE_COMMON_TEXT_TOPSELLINGIN . zen_get_categories_name($current_category_id);
                ?>
</h2>
<ul class="top_selling">
}
//  $from_str = "from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_SPECIALS . " s on p.`products_id` = s.`products_id`, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c";
$from_str = "from " . TABLE_PRODUCTS . " p INNER JOIN " . TABLE_PRODUCT_TYPES . " pt ON(p.`products_type`=pt.`type_id`) left join " . TABLE_MANUFACTURERS . " m using(manufacturers_id) ";
if (DISPLAY_PRICE_WITH_TAX == 'true' && (isset($_REQUEST['pfrom']) && zen_not_null($_REQUEST['pfrom']) || isset($_REQUEST['pto']) && zen_not_null($_REQUEST['pto']))) {
    if (!$_SESSION['customer_country_id']) {
        $_SESSION['customer_country_id'] = STORE_COUNTRY;
        $_SESSIOn['customer_zone_id'] = STORE_ZONE;
    }
    $from_str .= " left join " . TABLE_TAX_RATES . " tr on p.`products_tax_class_id` = tr.tax_class_id left join " . TABLE_ZONES_TO_GEO_ZONES . " gz on tr.tax_zone_id = gz.geo_zone_id and (gz.zone_country_id is null or gz.zone_country_id = '0' or gz.zone_country_id = '" . $_SESSION['customer_country_id'] . "') and (gz.zone_id is null or gz.zone_id = '0' or gz.zone_id = '" . $_SESSION['customer_zone_id'] . "')";
}
$from_str .= " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON( p.`products_id` = p2c.`products_id` ) LEFT JOIN  " . TABLE_CATEGORIES . " c ON( p2c.`categories_id`=c.`categories_id` ) left join " . TABLE_META_TAGS_PRODUCTS_DESCRIPTION . " mtpd on mtpd.`products_id`= p.`products_id` and mtpd.`language_id` = '" . $_SESSION['languages_id'] . "', " . TABLE_PRODUCTS_DESCRIPTION . " pd ";
$where_str = " where p.`products_status` = '1' and p.`products_id` = pd.`products_id` and pd.`language_id` = '" . $_SESSION['languages_id'] . "' ";
if (isset($_REQUEST['categories_id']) && zen_not_null($_REQUEST['categories_id'])) {
    if ($_REQUEST['inc_subcat'] == '1') {
        $subcategories_array = array();
        zen_get_subcategories($subcategories_array, $_REQUEST['categories_id']);
        $where_str .= " and p2c.`products_id` = pd.`products_id` and (p2c.`categories_id` = '" . (int) $_REQUEST['categories_id'] . "'";
        for ($i = 0, $n = sizeof($subcategories_array); $i < $n; $i++) {
            $where_str .= " or p2c.`categories_id` = '" . $subcategories_array[$i] . "'";
        }
        $where_str .= ")";
    } else {
        $where_str .= " and pd.`language_id` = '" . $_SESSION['languages_id'] . "' and p2c.`categories_id` = '" . (int) $_REQUEST['categories_id'] . "'";
    }
}
if (isset($_REQUEST['manufacturers_id']) && zen_not_null($_REQUEST['manufacturers_id'])) {
    $where_str .= " and m.`manufacturers_id` = '" . $_REQUEST['manufacturers_id'] . "'";
}
if (isset($_REQUEST['keyword']) && zen_not_null($_REQUEST['keyword'])) {
    if (zen_parse_search_string(stripslashes($_REQUEST['keyword']), $search_keywords)) {
        $where_str .= " and (";
 function get_categories_query($search_param)
 {
     $category_id = (int) $search_param['category_id'];
     $category_base_id = (int) $search_param['category_base_id'];
     $keyword = $search_param['keyword'];
     $description = $search_param['description'];
     $where = array("c.categories_id=cd.categories_id", "cd.language_id=" . (int) $_SESSION['languages_id']);
     $subcategories_array = array($category_id);
     // キーワード指定した場合のみ全カテゴリ対象とする
     if ($keyword != "") {
         zen_get_subcategories($subcategories_array, $category_id);
     }
     $where[] = "c.parent_id in (" . implode(",", $subcategories_array) . ")";
     if ($keyword != "") {
         $where[] = "cd.categories_name like '%" . zen_db_input($keyword) . "%'";
     }
     if ($description != "") {
         $where[] = "cd.categories_description like '%" . zen_db_input($description) . "%'";
     }
     if ($category_base_id > 0) {
         $categories = array();
         self::zen_get_subcategories($categories, (int) $category_base_id);
         $categories[] = (int) $category_base_id;
         $where[] = "c.categories_id in (" . implode(",", $categories) . ")";
     }
     $query = "select\n                      c.categories_id,\n                      c.categories_status,\n                      c.sort_order,\n                      cd.categories_name\n                    from " . TABLE_CATEGORIES . " c," . TABLE_CATEGORIES_DESCRIPTION . " cd\n                    where " . join(" and ", $where) . "\n                      order by\n                        c.sort_order,\n                        cd.categories_name";
     return $query;
 }