<?php 
/* 
  osCommerce, Open Source E-Commerce Solutions 
  http://www.oscommerce.com 

  Copyright (c) 2002 osCommerce 

  Released under the GNU General Public License 
  
  cieto Featured Products 2.1
  cieto@msn.com
  
*/ 

$configuration_query = tep_db_query("select configuration_key as cfgKey, configuration_value as cfgValue from " . TABLE_CONFIGURATION);
while ($configuration = tep_db_fetch_array($configuration_query)) {
	define($configuration['cfgKey'], $configuration['cfgValue']);
}

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_FEATURED); 

if(FEATURED_PRODUCTS_DISPLAY == true) 
    { 
?> 

<!-- body //--> 
<?php 

  $featured_products_category_id = $new_products_category_id; 
  
   if ( (!isset($featured_products_category_id)) || ($featured_products_category_id == '0') ) { // We are not in category depth; we are on the main page 
    $featured_products_query_raw = "select p.products_id, pd.products_name, pd.products_description, pd.products_shortdescription, p.products_image, p.products_tax_class_id, s.status as specstat, s.specials_new_products_price, p.products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' left join featured f on p.products_id = f.products_id where p.products_status = '1' and f.status = '1' order by rand() DESC limit " . MAX_DISPLAY_FEATURED_PRODUCTS; 
  } else { // We are in category depth 
    $featured_products_query_raw = "select distinct p.products_id, pd.products_name, p.products_image, p.products_tax_class_id, pd.products_description, pd.products_shortdescription, s.status as specstat, s.specials_new_products_price, p.products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' left join featured f on p.products_id = f.products_id where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $featured_products_category_id . "' and p.products_status = '1' and f.status = '1' order by rand() DESC limit " . MAX_DISPLAY_FEATURED_PRODUCTS; // Cambiar featured con TABLE_FEATURED
  } 

  $featured_products_query = tep_db_query($featured_products_query_raw); 
  while ($featured_products = tep_db_fetch_array($featured_products_query)) { 
//    $featured_products['products_name'] = tep_get_products_name($featured_products['products_id']); 
//    $featured_products['products_description'] = tep_get_products_description($featured_products['products_id']); 
    $featured_products_array[] = array('id' => $featured_products['products_id'], 
                                  'name' => $featured_products['products_name'], 
                          'description' => $featured_products['products_description'], 
                            'shortdescription' => $featured_products['products_shortdescription'], 
                          'image' => $featured_products['products_image'], 
                                  'price' => $featured_products['products_price'], 
                                  'specials_price' => $featured_products['specials_new_products_price'], 
                                  'tax_class_id' => $featured_products['products_tax_class_id'], 
                                  'manufacturer' => $featured_products['manufacturers_name']); 
  } 

  require(DIR_WS_MODULES  . FILENAME_FEATURED_PRODUCTS); 
 
} else // If it's disabled, then include the original New Products box 
    { 
      include (DIR_WS_MODULES . FILENAME_NEW_PRODUCTS); 
    } 
?>