Code:
Table structure for table `zen_departments`
`departments_id` int(11) NOT NULL auto_increment,
`departments_name` varchar(32) NOT NULL,
`date_added` datetime default NULL,
`last_modified` datetime default NULL,
PRIMARY KEY (`departments_id`),
KEY `idx_departments_name_zen` (`departments_name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
Dumping data for table `zen_departments`
--
INSERT INTO `zen_departments` (`departments_id`, `departments_name`, `date_added`, `last_modified`) VALUES
(1, 'Men', '2008-11-11 14:27:50', NULL),
(2, 'Women', '2008-11-11 14:27:50', NULL),
(3, 'Girls', '2008-11-13 23:53:43', '2008-11-23 11:26:43'),
(4, 'Boys', '2008-11-13 23:53:48', '2008-11-23 11:28:17'),
(5, 'Infants', '2008-11-13 23:54:19', '2008-11-22 18:49:31');
PHP Code:
<?php
/**
* departments_filter.php for index filters
*
* index filter for the shoe product type
* show the products of a specified departments ie: mens/womens etc.
*
* @package productTypes
* @copyright Copyright 2003-2007 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @todo Need to add/fine-tune ability to override or insert entry-points on a per-product-type basis
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: departments_filter.php 6912 2008-11-22 02:23:45Z rwoody $
*/
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
if (!isset($select_column_list)) $select_column_list = "";
// show the products of a specified departments
if (isset($_GET['departments_id']))
{
if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id']))
{
// We are asked to show only a specific category
$listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, p.products_price, p.products_tax_class_id, pd.products_description, if(s.status = 1, s.specials_new_products_price, NULL) AS specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
from " . TABLE_PRODUCTS . " p, " .
TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_PRODUCT_SHOES_EXTRA . " pse left join " . TABLE_SPECIALS . " s on pse.products_id = s.products_id, " .
TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " .
TABLE_DEPARTMENTS . " d
where d.departments_id = '" . (int)$_GET['departments_id'] . "'
and p.products_id = pse.products_id
and p.products_status = 1
and pse.departments_id = '" . (int)$_GET['departments_id'] . "'
and pse.products_id = p2c.products_id
and pd.products_id = p2c.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and p2c.categories_id = '" . (int)$_GET['filter_id'] . "'";
} else {
// We show them all
$listing_sql = "select " . $select_column_list . " pse.products_id, p.products_type, p.master_categories_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
from " . TABLE_PRODUCTS . " p, " .
TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_PRODUCT_SHOES_EXTRA . " pse left join " . TABLE_SPECIALS . " s on pse.products_id = s.products_id, " .
TABLE_DEPARTMENTS . " d
where d.departments_id = '" . (int)$_GET['departments_id'] . "'
and p.products_id = pse.products_id
and p.products_status = 1
and pd.products_id = pse.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and pse.departments_id = '" . (int)$_GET['departments_id'] . "'";
}
} else {
// show the products in a given category
if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id']))
{
// We are asked to show only specific category
$listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, d.departments_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " .
TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_DEPARTMENTS . " d, " .
TABLE_PRODUCTS_SHOES_EXTRA . " pse, " .
TABLE_PRODUCTS_TO_CATEGORIES . " p2c
where p.products_status = 1
and pse.departments_id = d.departments_id
and d.departments_id = '" . (int)$_GET['filter_id'] . "'
and p.products_id = p2c.products_id
and pd.products_id = p2c.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and p2c.categories_id = '" . (int)$current_category_id . "'";
} else {
// We show them all
if ($current_categories_id) {
$listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, d.departments_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_PRODUCTS . " p left join " . TABLE_DEPARTMENTS . " d, " . TABLE_PRODUCT_SHOES_EXTRA . " pse on pse.departments_id = d.departments_id, " .
TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p2c.products_id = s.products_id
where p.products_status = 1
and p.products_id = p2c.products_id
and pd.products_id = p2c.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and p2c.categories_id = '" . (int)$current_category_id . "'";
} else {
$listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, d.departments_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_PRODUCTS . " p left join " . TABLE_DEPARTMENTS . " d, " . TABLE_PRODUCT_SHOES_EXTRA . " pse on pse.departments_id = d.departments_id, " .
TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p2c.products_id = s.products_id
where p.products_status = 1
and p.products_id = p2c.products_id
and pd.products_id = p2c.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
}
}
}
// set the default sort order setting from the Admin when not defined by customer
if (!isset($_GET['sort']) and PRODUCT_LISTING_DEFAULT_SORT_ORDER != '') {
$_GET['sort'] = PRODUCT_LISTING_DEFAULT_SORT_ORDER;
}
if (isset($column_list)) {
if ( (!isset($_GET['sort'])) || (!ereg('[1-8][ad]', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) )
{
for ($i=0, $n=sizeof($column_list); $i<$n; $i++)
{
if ($column_list[$i] == 'PRODUCT_LIST_NAME')
{
$_GET['sort'] = $i+1 . 'a';
$listing_sql .= " order by p.products_sort_order, pd.products_name";
break;
}
}
// if set to nothing use products_sort_order and PRODUCTS_LIST_NAME is off
if (PRODUCT_LISTING_DEFAULT_SORT_ORDER == '') {
$_GET['sort'] = '20a';
}
} else {
$sort_col = substr($_GET['sort'], 0 , 1);
$sort_order = substr($_GET['sort'], 1);
$listing_sql .= ' order by ';
switch ($column_list[$sort_col-1])
{
case 'PRODUCT_LIST_MODEL':
$listing_sql .= "p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
case 'PRODUCT_LIST_NAME':
$listing_sql .= "pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
break;
case 'PRODUCT_LIST_MANUFACTURER':
$listing_sql .= "m.manufacturers" . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
case 'PRODUCT_LIST_QUANTITY':
$listing_sql .= "p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
case 'PRODUCT_LIST_IMAGE':
$listing_sql .= "pd.products_name";
break;
case 'PRODUCT_LIST_WEIGHT':
$listing_sql .= "p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
case 'PRODUCT_LIST_PRICE':
// $listing_sql .= "final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
$listing_sql .= "p.products_price_sorter " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
}
}
}
// optional Product List Filter
if (PRODUCT_LIST_FILTER > 0)
{
if (isset($_GET['departments_id']))
{
$filterlist_sql = "select distinct c.categories_id as id, cd.categories_name as name
from " . TABLE_PRODUCTS . " p, " .
TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " .
TABLE_CATEGORIES . " c, " .
TABLE_CATEGORIES_DESCRIPTION . " cd, " .
TABLE_PRODUCT_SHOES_EXTRA . " pse
where p.products_status = 1
and pme.products_id = p2c.products_id
and p2c.categories_id = c.categories_id
and p2c.categories_id = cd.categories_id
and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and pse.departments_id = '" . (int)$_GET['departments_id'] . "'
order by cd.categories_name";
} else {
$filterlist_sql= "select distinct d.departments_id as id, d.departments_name as name
from " . TABLE_PRODUCTS . " p, " .
TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " .
TABLE_PRODUCT_SHOES_EXTRA . " pse, " .
TABLE_DEPARTMENTS . " d
where p.products_status = 1
and pse.departments_id = d.departments_id
and p.products_id = p2c.products_id
and p2c.categories_id = '" . (int)$current_category_id . "'
order by d.departments_name";
}
$getoption_set = false;
$filterlist = $db->Execute($filterlist_sql);
$do_filter_list = false;
if ($filterlist->RecordCount() > 1)
{
$do_filter_list = true;
if (isset($_GET['departments_id']))
{
//die('here');
$getoption_set = true;
$get_option_variable = 'departments_id';
$options = array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES));
} else {
$options = array(array('id' => '', 'text' => TEXT_ALL_DEPARTMENTS));
}
while (!$filterlist->EOF) {
$options[] = array('id' => $filterlist->fields['id'], 'text' => $filterlist->fields['name']);
$filterlist->MoveNext();
}
}
}
// Get the right image for the top-right
$image = DIR_WS_TEMPLATE_IMAGES . 'table_background_list.gif';
if ($current_category_id) {
$sql = "select categories_image from " . TABLE_CATEGORIES . "
where categories_id = '" . (int)$current_category_id . "'";
$image_name = $db->Execute($sql);
$image = $image_name->fields['categories_image'];
}
?>
Here's my tpl_departments_select.php
Bookmarks