Bonjour,

Dans une boutique ecommerce (sous virtuemart), j'ai un module qui me ressort les X dernières ventes effectuées.

Tout fonctionne bien sauf que si le produit à déja été vendu précédemment il n'apparait alors pas dans la liste.

A priori c'est le DISTINCT qui produit cela si je comprends bien.

Mais dès que j'enlève ce DISTINCT seul le dernier produit vendu apparait alors dans la liste X fois..

Bien évidemment, ce que je souhaites c'est que meme si un produit à déja été vendu qu'il apparaisse dans la liste dans l'ordre des dernières ventes..

exemple :
aujourdhui j'ai vendu BANANE
hier j'ai vendu ORANGE
avant hier j'ai vendu BANANE

Ordre qui ressort :
-1- BANANE
-2- ORANGE
-3- BANANE

J'ai eu beau chercher dans les tutos je n'ai pas trouvé de réponse..

voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
global $mosConfig_absolute_path;
 
if( file_exists(dirname(__FILE__).'/../../components/com_virtuemart/virtuemart_parser.php' )) {
	require_once( dirname(__FILE__).'/../../components/com_virtuemart/virtuemart_parser.php' );
} else {
	require_once( dirname(__FILE__).'/../components/com_virtuemart/virtuemart_parser.php' );
}
 
$max_items = $params->get( 'max_items', 6 ); //maximum number of items to display
$category_id = $params->get( 'category_id', null ); // Display products from this category only
$display_style = $params->get( 'display_style', "horizontal" ); // Display Style
$products_per_row = $params->get( 'products_per_row', 3 ); // Display X products per Row
$show_price = (bool)$params->get( 'show_price', 1 ); // Display the Product Price?
$show_addtocart = (bool)$params->get( 'show_addtocart', 0 ); // Display the "Add-to-Cart" Link?
 
require_once( CLASSPATH . 'ps_product.php');
$ps_product = new ps_product;
 
 
$db =& new ps_DB;
$q  = "SELECT DISTINCT product_sku FROM #__{vm}_product, #__{vm}_category, #__{vm}_order_item, #__{vm}_orders WHERE ";
$q .= "(#__{vm}_orders.order_status='S' OR #__{vm}_orders.order_status='C') ";
$q .= "AND #__{vm}_product.product_id=#__{vm}_order_item.product_id ";
$q .= "AND #__{vm}_order_item.order_id=#__{vm}_orders.order_id ";
$q .= "ORDER BY #__{vm}_orders.order_id DESC ";
$q .= "LIMIT 0, $max_items ";
$db->query($q);
 
if( $db->num_rows() > 0 ){ ?>
      <table border="0" cellpadding="0" cellspacing="0" width="100%">        
        <?php
        $i = 0;
        while($db->next_record() ){
			if ($i%2)
				$sectioncolor = "sectiontableentry2";
			else
				$sectioncolor = "sectiontableentry1";
 
			if( $display_style == "vertical" ) {
				?>
				<tr align="center" class="<?php echo $sectioncolor ?>">
					<td><?php $ps_product->show_snapshot($db->f("product_sku"), $show_price, $show_addtocart); ?></td>
				</tr>
				<?php
			}
			elseif( $display_style== "horizontal" ) {
				if( $i == 0 )
					echo "<tr>\n";
				echo "<td align=\"center\">";
				$ps_product->show_snapshot($db->f("product_sku"), $show_price, $show_addtocart);
				echo "</td>\n";
				if( ($i+1) == $max_items )
					echo "</tr>\n";
			}
			elseif( $display_style== "table" ) {
				if( $i == 0 )
					echo "<tr>\n";
				echo "<td align=\"center\">";
				$ps_product->show_snapshot($db->f("product_sku"), $show_price, $show_addtocart);
				echo "</td>\n";
				if ( ($i+1) % $products_per_row == 0)
					echo "</tr><tr>\n";
				if( ($i+1) == $max_items )
					echo "</tr>\n";
			}
			$i++;
        }
?>
</table>
<?php
}
?>