Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Creating order history page with images


bigbird_3156

Recommended Posts

Posted

Hi,

 

I'm trying to create a page that shows the customer all the individual items they have purchased in the past containing a product image, the product name and a purchase link ...

 

I have been playing around with an addon (called History Quick Reorder) to get this result, and I think I am getting close, but Im not quite there yet...

 

at the moment I don't get any image show up but get a repetition of about 100 of each product name down the list before the next product name comes up... I get the corresponding purchase link for each product too.

 

Can someone have a look at this for me and tell me where I'm going wrong...

 

<?php
if (tep_session_is_registered('customer_id')) {
// retreive the last x products purchased
$orders_query = tep_db_query("select distinct op.products_id from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_PRODUCTS . " p where o.customers_id = '" . $customer_id . "' and o.orders_id = op.orders_id and op.products_id = p.products_id and p.products_status = '1' group by products_id order by o.date_purchased desc limit " . MAX_DISPLAY_PRODUCTS_IN_ORDER_HISTORY_BOX);
if (tep_db_num_rows($orders_query)) {
?>

<?php
$info_box_contents = array();
$product_ids = '';
 while ($orders = tep_db_fetch_array($orders_query)) {
 $product_ids .= $orders['products_id'] . ',';
 }
 $product_ids = substr($product_ids, 0, -1);
 $customer_orders_string = '<table border="0" width="100%" cellspacing="0" cellpadding="1">';
 $products_query = tep_db_query("select c.products_id, c.products_name, cd.image from " . TABLE_PRODUCTS_DESCRIPTION . " c, " .TABLE_PRODUCTS_IMAGES . " cd where c.products_id in (" . $product_ids . ") and language_id = '" . $languages_id . "' order by c.products_name");

 while ($products = tep_db_fetch_array($products_query)) {
 $customer_orders_string .= ' <tr>' . '<td class="infoBoxContents"><a ' . tep_image(DIR_WS_IMAGES . $products['cd.image'],SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT ) . '</a></td>' .
							 ' <td class="infoBoxContents"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['c.products_id']) . '">' . $products['products_name'] . '</a></td>' .
							 ' <td class="infoBoxContents" align="right" valign="top"><a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=cust_order&pid=' . $products['products_id']) . '">' . tep_image(DIR_WS_ICONS . 'button_reorder.gif', ICON_CART) . '</a></td>' .
							 ' </tr>';
 }
 $customer_orders_string .= '</table>';
 $info_box_contents = array();
 $info_box_contents[] = array('text' => $customer_orders_string);
 new infoBox($info_box_contents);
?>

 

Thankyou!

Posted

@@bigbird_3156

 

You can try this. Please note that I added the last two } that you left out in your example.

 

<?php
if (tep_session_is_registered('customer_id')) {
   // retreive the last x products purchased
   $orders_query = tep_db_query("select distinct op.products_id from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_PRODUCTS . " p where o.customers_id = '" . (int)$customer_id . "' and o.orders_id = op.orders_id and op.products_id = p.products_id and p.products_status = '1' group by op.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_PRODUCTS_IN_ORDER_HISTORY_BOX);
   if (tep_db_num_rows($orders_query)) {
    $info_box_contents	  = array();
    $product_ids		    = '';
    $customer_orders_string = '<table border="0" width="100%" cellspacing="0" cellpadding="1">';

    while ($orders = tep_db_fetch_array($orders_query)) {

	    $product_id = (int)$orders['products_id'];
	    $products_query = tep_db_query("select c.products_id, c.products_name, cd.products_image from " . TABLE_PRODUCTS_DESCRIPTION . " c, " . TABLE_PRODUCTS . " cd where c.products_id = '" . (int)$product_id . "' and cd.products_id = c.products_id and language_id = '" . (int)$languages_id . "' order by c.products_name");
	    $products = tep_db_fetch_array($products_query);
	    $customer_orders_string .= ' <tr>' . '<td class="infoBoxContents">' . tep_image(DIR_WS_IMAGES . $products['products_image'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT ) . '</td>' .
															 ' <td class="infoBoxContents"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$products['products_id']) . '">' . tep_output_string_protected($products['products_name']) . '</a></td>' .
															 ' <td class="infoBoxContents" align="right" valign="top"><a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=cust_order&pid=' . (int)$products['products_id']) . '">' . tep_image(DIR_WS_ICONS . 'button_reorder.gif', ICON_CART) . '</a></td>' .
															 ' </tr>';
	 }

	 $customer_orders_string .= '</table>';
	 $info_box_contents[] = array('text' => $customer_orders_string);
	 new infoBox($info_box_contents);
   }
}
?>

Matt

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...