|
Foros
Productos ALEATORIOS en oscommerce
|
Autor
|
Fecha: 21 de Octubre del 2006 a las 13:03:40
Descripción: Productos ALEATORIOS en oscommerce
|
Sexo: Masculino
País:
Mensajes: 186
|
Hola a toda la magnifica comunidad de ZONA-OCIO,.
Ahora vuelvo a las preguntas y en cada una de mis preguntas y dudas has sido respondidas con una rapidez increible y sobre todo con una exactitud y certeza magnifica.
Ahora expongo una duda mas y creo que esta es la mas atrevida porque considero que lleva mas tiempo y analisis. solo espero no cansar a la comunidad ni a adolfo..... quien es el que me ha respondido a todo.(gracias)
Antes de iniciar, Adolfo, gracias por la ayuda prestada y en este caso no se si sea demasiado lo que pregunto.
resulta que tengo un archivo para que en OSCOMMERCE los pruductos de la pagina inicial esten cambiando aleatoriamente, FUNCIONA DE MARAVILLA, el problema es que no me muestra el diseño original ya que tengo un template de template monster, no muestra los botones de agregar al carrito ni una imagen pequeña ni la descripcion del producto.
Este es el codigo del archivo ORIGINAL (new_products.php)
Código 
<?php
/*
edited - 2005/07/01 13:50
-----------------------------------------
$Id: new_products.php,v 1.34 2003/06/09 22:49:58 hpdl Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
*/
?>
<!-- new_products //-->
<?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_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as 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_DISPLAY_NEW_PRODUCTS);
} else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as 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 = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
}
$row = 0;
$col = 0;
echo '
<table cellspacing=0 cellpadding=0 width=519>
<tr><td colspan=3 bgcolor=#F5F5F5 height=31 style="padding-left: 9px"><img src=images/m16.gif width=13 height=12> <span class=ch2>Today's special Offers</span></td></tr>
<tr><td height=9></td></tr>
<tr>
';
while ($new_products = tep_db_fetch_array($new_products_query)) {
$new_products['products_name'] = tep_get_products_name($new_products['products_id']);
$product_query = tep_db_query("select products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$new_products['products_id'] . "' and language_id = '" . (int)$languages_id . "'");
$product = tep_db_fetch_array($product_query);
$new_products['products_description'] = $product['products_description'];
// get products category
$categories_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$new_products['products_id'] . "'");
if (tep_db_num_rows($categories_query) > 0) {
$categories = tep_db_fetch_array($categories_query);
$categories_query2 = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$categories['categories_id'] . "'");
$categories2 = tep_db_fetch_array($categories_query2);
$category_name = $categories2['categories_name'];
} else {
$category_name = '';
}
// get products manufacturers
$man_query = tep_db_query("select manufacturers_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$new_products['products_id'] . "'");
if (tep_db_num_rows($categories_query) > 0) {
$manuf = tep_db_fetch_array($man_query);
$man_query2 = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$manuf['manufacturers_id'] . "'");
$manuf2 = tep_db_fetch_array($man_query2);
$man_name = $manuf2['manufacturers_name'];
} else {
$man_name = '';
}
echo '
<td width=259 valign=top>
<table cellspacing=0 cellpadding=0 width=259>
<tr><td width=115 align=center><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'vspace=0') . '</a></td>
<td width=144 valign=top>
<table cellspacing=0 cellpadding=0 width=140>
<tr><td height=1></td></tr>
<tr><td height=35 class=ml3 style="padding-left:4px" valign=middle><a class=ml3 href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '"> ' . $man_name . '</a> <a class=ml5 href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '"> ' . $new_products['products_name'] . '</a></td></tr>
<tr><td height=1></td></tr>
<tr><td height=45 valign=middle class=ch5><img src=images/m21.gif width=4 height=4 align=absmidle> <span class=ch3>'.preg_replace('/sS*$/i', '', substr($new_products['products_description'], 0, 60)).' ...</span></td></tr>
<tr><td height=15></td></tr>
<tr><td class=ch4> Today only '.$currencies->display_price($new_products['products_price'], tep_get_tax_rate($new_products['products_tax_class_id'])).'</td></tr>
<tr><td height=10></td></tr>
<tr><td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image_button('small_view.gif') . '</a> <a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $new_products['products_id']) . '">' . tep_image_button('button_in_cart.gif') . '</a></td></tr>
</table>
</td></tr>
</table>
</td>
';
$col ++;
if ($col > 1) {
$col = 0;
$row ++;
echo '
</tr>
<tr><td height=5></td></tr>
<tr><td colspan=3 height=1 align=center style="padding-left: 1px">
<table cellspacing=0 cellpadding=0 align=center>
<tr><td background=images/m22.gif width=252 height=1></td>
<td width=4></td>
<td background=images/m22.gif width=252 height=1></td></tr>
</table>
</td></tr>
<tr><td height=5></td></tr>
<tr>
';
} else echo '
<td background=images/m17.gif>
<table cellspacing=0 cellpadding=0 width=1><tr>
<td background=images/m17.gif width=1></td>
</tr>
</table></td>
';
}
echo '
</tr>
<tr><td height=4></td></tr>
</table>
';
?>
<!-- new_products_eof //-->
Y este es el archivo que permite los productos ALEATORIOS (new_products.php)
Código 
<?php
/*
$Id: new_products.php,v 1.35 2004/02/05 15:50:00 adf Exp $
Randomize New Products
$Id: new_products.php,v 1.34 2003/06/09 22:49:58 hpdl Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
*/
?>
<!-- new_products //-->
<?php
$info_box_contents = array();
$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));
new contentBoxHeading($info_box_contents);
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_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as 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 {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as 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 = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_RANDOM_SELECT_NEW);
// end random new products
}
// start random new products
// To configure:
//
// Under Admin - Configuration - Maximum Values
// Set the following:
// 'Selection of Random New Products'
// (MAX_RANDOM_SELECT_NEW) - Sets how many of the most recent new product entries are queried
// 'New Products Module'
// (MAX_DISPLAY_NEW_PRODUCTS) - Sets how many random new products are displayed on screen
//
$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_NEW_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_NEW_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']);
$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'])));
$col ++;
if ($col > 2) {
$col = 0;
$row ++;
}
} // found
} // while pCount
} // num_rows
// end random new products
new contentBox($info_box_contents);
?>
<!-- new_products_eof //-->
Intente agregando al codigo ORIGINAL lo que yo crei diferente en el archivo aleatorio......pero algo paso.....que no resulto
mil, gracias por cualquier ayuda que se me pueda proporcionar.
Saludos a todos
adsoma
Soluciones Web desde US $9.96 mes
E-commerce, foros, chats, blogs, Joomla
nuke, subastas, y mas!
**TODO ILIMITADO!!!**
www.crisolution.com
|
|
|
|
Autor
|
Fecha: 21 de Octubre del 2006 a las 19:35:35
Descripción: Ninguna
|
Sexo: Masculino
Edad: 21 años
Ubicación: Poza Rica, Veracruz
País:
Mensajes: 1258
|
Mmm... veo que ese CMS, maneja su propia funcion para obtener filas aleatorias, lo normal es usar la funcion rand(), sobre el query, pero igual es válido.
También veo que ambos archivos tienen un diseño diferente, como ya se habia mencionado y aquel que funciona con los productos aleatorios, solo muestra pocas opciones...
Esos archivos new_products, son exclusivos de la página principal?
Para mi lo más fácil, seria usar la función rand() del mysql, y los cambios serían los siguientes:
Cambiar "order by p.products_date_added desc" por "order by rand()".
La parte a modificar seria esta:
Código 
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_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as 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_DISPLAY_NEW_PRODUCTS);
} else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as 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 = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);
}
El código modificado podria quedar mas o menos asi:
Código 
if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by rand() limit " . MAX_DISPLAY_NEW_PRODUCTS);
} else {
$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as 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 = '" . (int)$new_products_category_id . "' and p.products_status = '1' order by rand() limit " . MAX_DISPLAY_NEW_PRODUCTS);
}
Si el primer query muestra productos repetidos, se podria cambiar: "select p.products_id", por "select distinct p.products_id".
Obviamente los cambios se harian en el archivo new_products original, y despues de haber hecho una copia de respaldo. A propósito, los dos queries trabajan diferente, por asi decirlo, uno muestra productos cualquiera, sin categorizar, y el otro categorizados. Y además por defeto se ordenan por fecha... lo cual es lo que se esta cambiando.
La palabra clave "DISTINCT" sirve para mostrar productos distintos, vaya que por nada se repitan.
En teoria los cambios hechos, harán que esos productos siempre se muestren aleatoriamente, y sin repetirse, esten o no categorizados.
Bueno, haces las pruebas y ya veremos.
|
|
|
|
Autor
|
Fecha: 21 de Octubre del 2006 a las 20:38:17
Descripción: Ninguna
|
Sexo: Masculino
Edad: 21 años
Ubicación: Poza Rica, Veracruz
País:
Mensajes: 1258
|
| adsoma escribió: | Gracias....de verdad....estuve buscando mucho en las "contribuciones" de los mismos desarrolladores de OSCOMMERCE pero nop.....proponen soluciones muy complejas.......
|
Pues de nada 
| adsoma escribió: | Tal vez si me autorizas y estas de acuerdo....aportare esta solucion a la comunidad de desarrolladores de OSCOMMERCE, obviamente dandote el credito.
|
Pues por mi no hay ningún problema. Aunque aclaro, que a algunas personas puede no gustarles la funcion rand(), tal y como lo dice la página oficial del MySQL, rand() no es una función de resultados aleatorios perfecta, sin embargo es una solución muy rápida, sencilla, eficaz y a mi me a dado buenos resultados... 
Para mi una seleccion aleatoria de resultados perfecta, tendria que tomar en cuenta las impresiones de los resultados, y basarse en la funcion microtime del php, entre otras cosas, para evitar repeticiones, y un sistema que verifique que productos se han mostrado mas, cuales menos, mostrar los que casi no se han mostrado y bueno. Obviamente eso es más complejo, y creo que ni el OSCOMMERCE lo hace.
Esta demás decirlo, pero el sistema que yo comente, para mostrar resultados aleatorios, lo he pensado implementar en la seccion de afiliados... pero para eso falta.
Una vez más. Saludos
|
|
|
|