Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Admin Search Problem: Wrong cPath for the first Item


hcamelion

Recommended Posts

Posted

There seems to be a bug with the admin search. When you search for products in the admin and the search returns products from multiple categories/products the first item returned is already selected and allows you to take action on that product. The problem is that the cPath for the action buttons will always be the cPath for the last item in the search. This is not a problem for any item except if the first item returned is the one you want to edit. It will basically change the category of the product on mistake.

 

This is the culprit:

 

 
while ($products = tep_db_fetch_array($products_query)) {
  $products_count++;
  $rows++;

// Get categories_id for product if search
  if (isset($HTTP_GET_VARS['search'])) $cPath = $products['categories_id'];

 

This goes through each item and assigns the correct cPath. But when the items are done printing to the screen the cPath value is left as the last item printed in the while loop. So then this prints:

 

default:

................
.........
....

$contents[] =
		  array('align' => 'center',
				'text' =>  '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product') . '">'
							 . tep_image_button('button_edit.gif', IMAGE_EDIT)
							 . '</a>
							<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=delete_product') . '">'
							 . tep_image_button('button_delete.gif', IMAGE_DELETE)
							 . '</a>
							<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=move_product') . '">'
							 . tep_image_button('button_move.gif', IMAGE_MOVE)
							 . '</a>
							<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=copy_to') . '">'
							 . tep_image_button('button_copy_to.gif', IMAGE_COPY_TO)
							 . '</a>
							<a href="' . tep_href_link(FILENAME_RELATED_PRODUCTS, 'products_id_view=' . $pInfo->products_id) . '" target="_new">'
							 . tep_image_button('button_related_products.gif', IMAGE_RELATED_PRODUCTS)
							 . '</a>'
				);

 

This is happening with categories that are returned as well The code that causes the problem is almost identical and is above the product while loop.

 

 

Anyway long story short here is a fix for both:

 

Find:

 while ($categories = tep_db_fetch_array($categories_query)) {
  $categories_count++;
  $rows++;

// Get parent_id for subcategories if search
  if (isset($HTTP_GET_VARS['search'])) $cPath= $categories['parent_id'];

 

Change To:

 
while ($categories = tep_db_fetch_array($categories_query)) {
  $categories_count++;
  $rows++;

// Get parent_id for subcategories if search
  if(isset($HTTP_GET_VARS['search']) && $categories_count === 1) $cat_first_cPath = $categories['parent_id'];
  if (isset($HTTP_GET_VARS['search'])) $cPath= $categories['parent_id'];

 

 

Find:

while ($products = tep_db_fetch_array($products_query)) {
  $products_count++;
  $rows++;

// Get categories_id for product if search
  if (isset($HTTP_GET_VARS['search'])) $cPath = $products['categories_id'];

 

Change to:

while ($products = tep_db_fetch_array($products_query)) {
  $products_count++;
  $rows++;

// Get categories_id for product if search
  if(isset($HTTP_GET_VARS['search']) && $products_count === 1) $first_cPath = $products['categories_id'];
  if (isset($HTTP_GET_VARS['search'])) $cPath = $products['categories_id'];

 

Find:

$heading = array();
$contents = array();

switch ($action) {
  case 'new_category':
	$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_CATEGORY . '</b>');

 

Change To::

$heading = array();
$contents = array();

if(isset($HTTP_GET_VARS['search'])) $cPath = (tep_not_null($cat_first_cPath)) ? $cat_first_cPath : $first_cPath;

switch ($action) {
  case 'new_category':
	$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_CATEGORY . '</b>');

 

 

That should fix it.

Archived

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

×
×
  • Create New...