Pagina 1 di 1

Modulo prodotti in offerta

Inviato: 15/10/2007, 8:31
da Chryses
Ciao, sto ultimando il negozio online fin'ora diciamo che bene o male sono riuscito a fare ciò che dovevo, ora però ho un problema.

Vorrei creare un modulo (come products_new.php per intenderci) dove però siano visualizzati anche i prodotti in offerta, ovviamente con i relativi prezzi barrati.

In sostanza avrei un modulo dove compaiono i prodotti inseriti di recente e se un prodotto è in offerta c'è il doppio prezzo.

Ho trovato un file che sembra un mix fra il l'infobox delle offerte e il modulo dei prodotti nuovi.

Qualcuno sa se esiste una contrib con un modulo simile a ciò che cerco?

Oppure, chi mi da una mano a metter "mano" al modulo products_new?

Correggetemi se sbaglio, ma credo si tratti di modificare la query giusto?

Grazie in anticipo.

Cry.

Inviato: 15/10/2007, 18:24
da Chryses
Ciao, allora io nel frattempo ho trovato una contrib che pesca sia i prodotti normali sia i prodotti in offerta, e fino a qui un passo è stato fatto, riporto il codice.

Codice: Seleziona tutto

<?php
/*
$Id: new_products.php,v 1.35 2004/02/05 15:50:00 adf Exp $
Randomize New Products

osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com

Copyright (c) 2003 osCommerce

Released under the GNU General Public License

changes :
v1.1 modified by azer for multicurrency compatibility 
*/
?>
<!-- new_products //-->
<?php

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
// start random new products
$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 {   // in a category

$cats[] = $new_products_category_id; // current catID as starting value
// put cat-IDs of all cats nested in current branch into $cats array, go through all subbranches
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); // sort out doubles
}

$num = (int) MAX_DISPLAY_SPECIAL_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);
// end random new products    
}

if (tep_db_num_rows($new_products_query) > 0) {
$info_box_contents = array();
$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));
new contentBoxHeading($info_box_contents);
$row = 0;
$col = 0;
$pCount = 0;
$info_box_contents = array();
$found_products = array();
$num_rows = tep_db_num_rows($new_products_query);
if (MAX_DISPLAY_SPECIAL_PRODUCTS > MAX_RANDOM_SELECT_NEW) {
  // don't allow more new products than will be queried
  $max_new_products = MAX_RANDOM_SELECT_NEW;
} else {
  $max_new_products = MAX_DISPLAY_SPECIAL_PRODUCTS;
}
if ($num_rows < $max_new_products) {
 $max_new_products = $num_rows;
}
//  echo "num_rows: " . $num_rows . " max_new_products " . $max_new_products . "<br>";
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) {
      // keep track of found id's
      $found_products[$pCount] += $random_product['products_id'];
      $pCount ++; 
      // add to display array
      $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']));
    }

      $info_box_contents[$row][$col] = array('align' => 'center',
                                      'params' => 'class="smallText" width="33%" valign="top"',
      'text' => '<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><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . $random_product['products_name'] . '</a><br>' 
. $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id']))
. $currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])));

      $col ++;
      if ($col > 2) {
        $col = 0;
        $row ++;
      }
    } // found
  } // while pCount
} // num_rows  
// end random new products

new contentBox($info_box_contents);
}
?>
<!-- new_products_eof //-->
Verso la fine ho modificato la stringa del prezzo e ho aggiunto

$currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id']))

così ora vengono visualizati sempre 2 prezzi, quello base e quello scontato, ovviamente nei prodotti non in offerta visualizzo 0 come prezzo scontato.

Chi mi sa una mano a mettere giù un ciclo di if per far si che se il prodotto è in offerta ci sia il doppio prezzo di cui uno?

Grazie.

Cry

Inviato: 15/10/2007, 22:56
da Bass
Chryses ha scritto:Ciao, allora io nel frattempo ho trovato una contrib che pesca sia i prodotti normali sia i prodotti in offerta, e fino a qui un passo è stato fatto, riporto il codice.
Se hai voglia di farti passare la board dei Negozi degli utenti, in un messaggio avevo postato il codice per fare quello che tu chiedi. E' piuttosto vecchiotto pero', dovrai cercare parecchio indietro. Purtroppo non ricordo piu' qual'e'

'iao

Sergio

Inviato: 16/10/2007, 8:40
da Chryses
Ciao Sergio, effettivamente bastava guardare il codice, poco più su, commentato c'è ciò che serve a me, il doppio prezzo in caso di offerta....

Ho modificato il layout per le necessità grafiche del caso.......ora devo solo trovare il modo di dirgli di pescare solo da una categoria......

se non riesco poi chiedo consiglio......

Grazie.

Cry