[plugin] Random New Products Shows Specials inc SubCats 1.0

Messagepar nequaquam » Sam 06 Mai 2006, 17:45

Hello,
I've modified the contribution Random New Products Shows Specials inc SubCats 1.0 to work in OsCSS.

Copy the next code in includes/modules/new_products.php.
Code: Tout sélectionner
<div class="infobox newProducts">
 
<?php
if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
} else {
$cats[] = $new_products_category_id;
for($i=0;$i<count($cats);$i++) {
$categorie_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$cats[$i] . "'");
while ($categorie = tep_db_fetch_array($categorie_query)) {
 $cats[] = $categorie['categories_id'];
}
$cats=array_unique($cats);
}
$num = (int) MAX_DISPLAY_NEW_PRODUCTS;
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_price, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as specials_new_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 where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id in (".implode(', ', $cats).") and p.products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW); 
}
if (tep_db_num_rows($new_products_query) > 0) {
  ?>
 
<h4><?php echo sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')) ;?></h4>

<?php
$found_products = array();
$num_rows = tep_db_num_rows($new_products_query);
if (MAX_DISPLAY_NEW_PRODUCTS > MAX_RANDOM_SELECT_NEW) {
  $max_new_products = MAX_RANDOM_SELECT_NEW;
} else {
  $max_new_products = MAX_DISPLAY_NEW_PRODUCTS;
}
if ($num_rows < $max_new_products) {
 $max_new_products = $num_rows;
}
if ($num_rows > 0) {       
  while ($pCount < $max_new_products) {   
    // choose a random row
    $random_product = '';
    $random_row = tep_rand(0, ($num_rows - 1));
    tep_db_data_seek($new_products_query, $random_row);
    $random_product = tep_db_fetch_array($new_products_query);
    // see if found already, if not use else skip
    $found = 0;
    for ($ii=0; $ii < $pCount; $ii++) {
      if ($found_products[$ii] == $random_product['products_id']) {
        $found = 1;
        break;
      }
    }
    if ($found == 0) {
      $found_products[$pCount] += $random_product['products_id'];
      $pCount ++;
      $random_product['products_name'] = tep_get_products_name($random_product['products_id']);
      $random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']);
    if (tep_not_null($random_product['specials_new_products_price'])) {
      $whats_new_price = '<s>' . $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</s><br>';
      $whats_new_price .= '<span class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</span>';
    } else {
      $whats_new_price = $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id']));
  }?>
 
  <dl class="newProduct">   
    <dt class="name">
      <?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . $random_product['products_name'] . '</a>' ;?>
    </dt>
    <dd class="image">
      <?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>' ;?>
    </dd>   
    <dd class="price">
      <?php echo $whats_new_price;?>
    </dd>   
  </dl>

<?php
    }
  }
}
}
  ?>
 
<div class="spacer"></div>
_______________________________________________________________________________

Website: nequaquam
osCSS shop in development: pugnae
nequaquam
Membre actif
 
Messages: 48
Inscription: Mer 08 Fév 2006, 12:40
Localisation: Barcelona

Messagepar stepibou » Sam 06 Mai 2006, 21:53

;) gracias!
--> osCSS inside <--
stepibou
Membre très actif
 
Messages: 274
Inscription: Dim 30 Oct 2005, 02:15
Localisation: Lyon

Messagepar nequaquam » Sam 06 Mai 2006, 22:49

De nada.. :P
_______________________________________________________________________________

Website: nequaquam
osCSS shop in development: pugnae
nequaquam
Membre actif
 
Messages: 48
Inscription: Mer 08 Fév 2006, 12:40
Localisation: Barcelona

Messagepar sidarus » Jeu 27 Juil 2006, 20:45

[sticky]

[ESP] Gracias tio, en este proyecto suffrimos del echo que no somos muchos [/ESP]
sidarus
Membre très actif
 
Messages: 396
Inscription: Mar 03 Mai 2005, 23:34
Localisation: Geneva (CH)

Messagepar nequaquam » Ven 28 Juil 2006, 10:41

Thanks to you. The code can be improved, I've tried that the products aren't duplicated. I've tried with foreach in arrays but I cannot, if somebody knows it ;)
_______________________________________________________________________________

Website: nequaquam
osCSS shop in development: pugnae
nequaquam
Membre actif
 
Messages: 48
Inscription: Mer 08 Fév 2006, 12:40
Localisation: Barcelona

Messagepar sidarus » Mar 01 Aoû 2006, 20:30

Put it here, is more easy / funny to edit. :P
sidarus
Membre très actif
 
Messages: 396
Inscription: Mar 03 Mai 2005, 23:34
Localisation: Geneva (CH)


Retourner vers Plugin

 


  • Articles en relation
    Réponses
    Vus
    Dernier message

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité

cron