Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding Product Image to Admin's Customer Order View


LizHeinman

Recommended Posts

Hello Everyone,

 

I have been trying for a while to get the product image to show up on the customer order view in admin console (that is, when you click into individual orders)

 

Here is what I have done so far and as it stands, it shows an image placeholder under the product name but not the actual image. It seems it is not appending the ''productname.jpg" (where productname.jpg is the image url in the images folder).

 

Many thanks for your time.

 

 

1) Firstly, I added this code admin/includes/classes/order.php

 

'prod_id' => $orders_products['products_id'],

 

The resulting code being

 

$orders_products_query = tep_db_query("select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
while ($orders_products = tep_db_fetch_array($orders_products_query)) {
$this->products[$index] = array('qty' => $orders_products['products_quantity'],
'name' => $orders_products['products_name'],
'model' => $orders_products['products_model'],
'tax' => $orders_products['products_tax'],
'prod_id' => $orders_products['products_id'],
'price' => $orders_products['products_price'],
'final_price' => $orders_products['final_price']);

 

 

2) Then I modified admin/orders.php (I put the word ''EDITED HERE" in the last piece of code so you can easily locate the changes (2 changes)

 

 

From this :

 

	 
	<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
	  <tr class="dataTableHeadingRow">
		<td class="dataTableHeadingContent" colspan="2"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
		<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TAX; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_EXCLUDING_TAX; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_INCLUDING_TAX; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_EXCLUDING_TAX; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_INCLUDING_TAX; ?></td>
	  </tr>
<?php
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
  echo '		  <tr class="dataTableRow">' . "\n" .
	   '			<td class="dataTableContent" valign="top" align="right">' . $order->products[$i]['qty'] . ' x</td>' . "\n" .
	   '			<td class="dataTableContent" valign="top">' . $order->products[$i]['name'];

  if (isset($order->products[$i]['attributes']) && (sizeof($order->products[$i]['attributes']) > 0)) {
	for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j++) {
	  echo '<br><nobr><small> <i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];
	  if ($order->products[$i]['attributes'][$j]['price'] != '0') echo ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
	  echo '</i></small></nobr>';
	}
  }

  echo '			</td>' . "\n" .
	   '			<td class="dataTableContent" valign="top">' . $order->products[$i]['model'] . '</td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top">' . tep_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n";
  echo '		  </tr>' . "\n";

}
?>
	  <tr>
		<td align="right" colspan="8"><table border="0" cellspacing="0" cellpadding="2">
<?php
for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
  echo '			  <tr>' . "\n" .
	   '				<td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
	   '				<td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
	   '			  </tr>' . "\n";
}
?>
		</table></td>
	  </tr>
	</table>

 

 

To This:

 

 <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
	  <tr class="dataTableHeadingRow">
		<td class="dataTableHeadingContent" colspan="2"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
		<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_MODEL; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TAX; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_EXCLUDING_TAX; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_PRICE_INCLUDING_TAX; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_EXCLUDING_TAX; ?></td>
		<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_INCLUDING_TAX; ?></td>
	  </tr>
<?php
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
  echo '		  <tr class="dataTableRow">' . "\n" .
	   '			<td class="dataTableContent" valign="top" align="right">' . $order->products[$i]['qty'] . ' x</td>' . "\n" .
	   '			<td class="dataTableContent" valign="top">' . $order->products[$i]['name'];

  if (isset($order->products[$i]['attributes']) && (sizeof($order->products[$i]['attributes']) > 0)) {
	for ($j = 0, $k = sizeof($order->products[$i]['attributes']); $j < $k; $j++) {
	  echo '<br><nobr><small> <i> - ' . $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];
	  if ($order->products[$i]['attributes'][$j]['price'] != '0') echo ' (' . $order->products[$i]['attributes'][$j]['prefix'] . $currencies->format($order->products[$i]['attributes'][$j]['price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . ')';
	  echo '</i></small></nobr>';
	}
  }




// EDITED HERE
$prodimage_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int)$order->products[$i]['prod_id'] . "'");
$prodimage = tep_db_fetch_array($prodimage_query);
// EDITED HERE





  echo '			</td>' . "\n" .
	   '			<td class="dataTableContent" valign="top">' . $order->products[$i]['model'] . '</td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top">' . tep_display_tax_value($order->products[$i]['tax']) . '%</td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n" .
	   '			<td class="dataTableContent" align="right" valign="top"><b>' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</b></td>' . "\n";
  echo '		  </tr>' . "\n";






// EDITED HERE
echo ' <tr><td align="left" colspan="8" class="dataTableContent" valign="top">
' . tep_image('../' . DIR_WS_IMAGES . $prodimage['products_image'], $order->products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '</td></tr>' . "\n";
// EDITED HERE




}
?>
	  <tr>
		<td align="right" colspan="8"><table border="0" cellspacing="0" cellpadding="2">
<?php
for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
  echo '			  <tr>' . "\n" .
	   '				<td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
	   '				<td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
	   '			  </tr>' . "\n";
}
?>
		</table>

Link to comment
Share on other sites

Could you try the following (added prod_id and brackets) and see what you get as the alt tag for the image?

// EDITED HERE
echo ' <tr><td align="left" colspan="8" class="dataTableContent" valign="top">
' . tep_image('../' . DIR_WS_IMAGES . $prodimage['products_image'], 'PROD_ID[' . $order->products[$i]['prod_id'] . ']' . $order->products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '</td></tr>' . "\n";
// EDITED HERE

Also, have you tried running those database queries manually through something like phpMyAdmin to see if you get the results you expect? It may be worth echoing the query strings to the page to get the identical syntax.

Always back up before making changes.

Link to comment
Share on other sites

Hi Ecartz, thanks for taking a look at this.

 

Unfortunately that did not work either..the alt tag states : PROD_ID[]Yellow Twist Sleeve Top

 

Now..the product id for this product is 60. So..I dont think it's passing along the '60' and its corresponding image url.

 

As a test, if I change the first edit in admin/orders.php from:

 

// EDITED HERE
$prodimage_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '" . (int)$order->products[$i]['prod_id'] . "'");
$prodimage = tep_db_fetch_array($prodimage_query);
// EDITED HERE

 

To this (inserting the product id '60' manually] ...it works, the image shows (at least for product 60)

 

// EDITED HERE
$prodimage_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " where products_id = '60'");
$prodimage = tep_db_fetch_array($prodimage_query);
// EDITED HERE

 

 

And this is with both before and after using your suggestion. I am stumped as to what the issue is and why it's not returning the product id and it's corresponding image url.

Link to comment
Share on other sites

If you do the same select

"select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'"

manually in phpMyAdmin (or whatever database viewer), substituting appropriately for TABLE_ORDERS_PRODUCTS and $order_id, do you get the product ID showing up?

Always back up before making changes.

Link to comment
Share on other sites

Hey Ecartz,

 

I ran the query in PHPmyadmin as below:

 

select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from orders_products where orders_id = 6;

 

It DOES return everything ok - product_id came back as expected (60). So it isnt likely the db?

 

Strange thing to note..however..is when I run the above query with the table name in capital letters (ORDERS_PRODUCTS instead of orders_products)..it says table not found..Is that normal? (Sorry..self trained in coding..still learning..in case that was a silly question.. :lol: )

Link to comment
Share on other sites

Strange thing to note..however..is when I run the above query with the table name in capital letters (ORDERS_PRODUCTS instead of orders_products)..it says table not found..Is that normal?
Yes, MySQL table identifiers are case sensitive in most installs.

 

In regards to the problem, try doing a

print_r($order);

right before the for loop for the products:

	for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {

If this is a real customer order, then don't post the private data here, just the part about products.

 

The other things that I would want to do would be to double check that you have products_id in the query. If so, try changing "products_name" to "'FAKE_NAME' as products_name" (" are just there for delineation; ' is needed) in the query. Quite honestly, I don't know what is wrong, so I'm throwing troubleshooting steps at it until it makes sense.

Always back up before making changes.

Link to comment
Share on other sites

  • 7 months later...
  • 1 month later...

For anyone who still want to get this to work, im just giving back something to help out. Here are the fixes:

 

In admin/includes/classes/order.php:

 

add: product_id

 

to the line below:

 

$orders_products_query = tep_db_query("select orders_products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");

 

so it will be like this:

 

$orders_products_query = tep_db_query("select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price, product_id from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$order_id . "'");
while ($orders_products = tep_db_fetch_array($orders_products_query)) {
$this->products[$index] = array('qty' => $orders_products['products_quantity'],
'name' => $orders_products['products_name'],
'model' => $orders_products['products_model'],
'tax' => $orders_products['products_tax'],
'prod_id' => $orders_products['products_id'],
'price' => $orders_products['products_price'],
'final_price' => $orders_products['final_price']);

 

in admin/orders.php:

 

Replace this:

 

// EDITED HERE
echo ' <tr><td align="left" colspan="8" class="dataTableContent" valign="top">
' . tep_image('../' . DIR_WS_IMAGES . $prodimage['products_image'], $order->products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '</td></tr>' . "\n";
// EDITED HERE

 

 

with this:

 

// EDITED HERE
echo ' <tr><td align="left" colspan="8" class="dataTableContent" valign="top">
' . tep_image(DIR_WS_CATALOG_IMAGES . $prodimage['products_image'], $order->products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '</td></tr>' . "\n";
// EDITED HERE

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...