Forum Moderators: coopster
Here is what I'm trying to achive with limited skill that I have.
We have 2 scenarios at the store that I work for.
1st is we look throught a porduct list and add to the order or
2nd we scan the barcode and only one result should come out.
My problems is that when we scan with the barcode, only one result show up, which is fine, but we have to go to the pop-up and choose it and then go through to other steps.
What I would like to do, is that if there is only one result in the query, to just add to the invoice and skip all of the other steps..
This is the section that I believe the mod should be done on
[Fixed]
if (($step > 1) && (!$not_found)) {
$product_array = array(array('id' => 0, 'text' => TEXT_SELECT_PRODUCT));
while($products = tep_db_fetch_array($products_query)) {
$product_array[] = array('id' => $products['products_id'], 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value']));
}
} $has_attributes = false;
$products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$add_product_products_id . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'");
$products_attributes = tep_db_fetch_array($products_attributes_query);
if ($products_attributes['total'] > 0) $has_attributes = true;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<?php if ( (isset($_GET['submitForm'])) && ($_GET['submitForm'] == 'yes') ) {
echo '<script language="javascript" type="text/javascript"><!--' . "\n" .
' window.opener.document.edit_order.subaction.value = "add_product";' . "\n" .
' window.opener.document.edit_order.submit();' . "\n" .
'//--></script>';
}
?>
</head>
<body>
<!-- body //-->
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td><table border="0" cellspacing="0" cellpadding="2" style="border: 1px solid #C9C9C9;" align="center">
<tr class="dataTableHeadingRow">
<td class="dataTableHeadingContent" colspan="3" align="center"><?php echo sprintf(ADDING_TITLE, $oID); ?></td>
</tr>
<tr class="dataTableRow">
<form action="<?php echo tep_href_link(FILENAME_ORDERS_EDIT_ADD_PRODUCT, 'oID=' . $_GET['oID']); ?>" method="POST">
<td class="dataTableContent" align="right"><?php echo TEXT_STEP_1; ?></td>
<td class="dataTableContent" valign="top"><?php echo tep_draw_pull_down_menu('add_product_categories_id', tep_get_category_tree('0', '', '0', $category_array), $add_product_categories_id,'style="width:300px;" onchange="this.form.submit();"'); ?></td>
<td class="dataTableContent" align="center">
<noscript>
<input type="submit" value="<?php echo TEXT_BUTTON_SELECT_CATEGORY; ?>">
</noscript>
<input type="hidden" name="step" value="2">
</td>
</form>
</tr>
<tr class="dataTableRow">
<td class="dataTableContent" colspan="3" align="center"><?php echo TEXT_PRODUCT_SEARCH; ?></td>
</tr>
<tr class="dataTableRow">
<form action="<?php echo tep_href_link(FILENAME_ORDERS_EDIT_ADD_PRODUCT, 'oID=' . $_GET['oID']); ?>" method="POST">
<td> </td>
<td class="dataTableContent" valign="top"> <input type="text" name="product_search" value="<?php echo $_POST['product_search']; ?>" onchange="this.form.submit();">
</td>
<td class="dataTableContent" align="center"><noscript><input type="submit" value="Search for This Product"></noscript><input type="hidden" name="step" value="2"><input type="hidden" name="search" value="1"></td>
</form>
</tr>
<?php if ($not_found) { ?>
<tr class="dataTableRow">
<td class="dataTableContent" colspan="3" align="center"><?php echo TEXT_PRODUCT_NOT_FOUND; ?></td>
</tr>
<?php } ?>
<?php
if (($step > 1) && (!$not_found)) {
echo ' <tr class="dataTableRow">' . "\n" .
' <td colspan="3" style="border-bottom: 1px solid #C9C9C9;">' . tep_draw_separator('pixel_trans.gif', '1', '1') . '</td>' . "\n" .
' </tr>' . "\n" .
' <tr class="dataTableRow">' . "\n" .
' <td colspan="3" style="background: #FFFFFF;">' . tep_draw_separator('pixel_trans.gif', '1', '10') . '</td>' . "\n" .
' </tr>' . "\n";
?>
<tr class="dataTableRow">
<td colspan="3" style="border-top: 1px solid #C9C9C9;"><?php echo tep_draw_separator('pixel_trans.gif', '1', '1'); ?></td>
</tr>
<tr class="dataTableRow">
<form action="<?php echo tep_href_link(FILENAME_ORDERS_EDIT_ADD_PRODUCT, 'oID=' . $_GET['oID']); ?>" method="POST">
<td class="dataTableContent" align="right"><?php echo TEXT_STEP_2; ?></td>
<td class="dataTableContent" valign="top"><?php echo tep_draw_pull_down_menu('add_product_products_id', $product_array, $add_product_products_id, 'style="width:300px;" onchange="this.form.submit();"'); ?></td>
<td class="dataTableContent" align="center"><noscript><input type="submit" value="<?php echo TEXT_BUTTON_SELECT_PRODUCT; ?>"></noscript><input type="hidden" name="step" value="3">
<input type="hidden" name="add_product_categories_id" value="<?php echo $add_product_categories_id; ?>">
<?php if ($_POST['search']) { ?>
<input type="hidden" name="search" value="1">
<input type="hidden" name="product_search" value="<?php echo $_POST['product_search']; ?>">
<?php } ?>
</td>
</form>
</tr>
Any help is greatly appreciated!
and Welcome to WebmasterWorld!
Anyways here is where the query start, Atleast I think.
$not_found = true;
if ($_POST['search']) {
$search_array = explode(" ", $_POST['product_search']);
$search_array = oe_clean_SQL_keywords($search_array);
if (sizeof($search_array) <= 1) {
$search_fields = array('p.products_id', 'p.products_price', 'p.products_model', 'pd.products_name', 'p.products_barcode');
$product_search = oe_generate_search_SQL($search_array, $search_fields);
} else {
$search_fields = array('pd.products_name');
$product_search = oe_generate_search_SQL($search_array, $search_fields, 'AND');
}
$products_query = tep_db_query("select p.products_id, p.products_price, p.products_model, pd.products_name, p.products_barcode from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on (p.products_id = pd.products_id) where pd.language_id = '" . $languages_id . "' and (" . $product_search . ") order by pd.products_name");
$not_found = ((tep_db_num_rows($products_query)) ? false : true);
}
if ((!$_POST['search'])) {
$product_search = " where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id ";
$_GET['inc_subcat'] = '1';
if ($_GET['inc_subcat'] == '1') {
$subcategories_array = array();
oe_get_subcategories($subcategories_array, $add_product_categories_id);
$product_search .= " and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and (p2c.categories_id = '" . (int)$add_product_categories_id . "'";
for ($i=0, $n=sizeof($subcategories_array); $i<$n; $i++ ) {
$product_search .= " or p2c.categories_id = '" . $subcategories_array[$i] . "'";
}
$product_search .= ")";
} else {
$product_search .= " and p2c.products_id = p.products_id and p2c.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p2c.categories_id = '" . (int)$add_product_categories_id . "'";
} $products_query = tep_db_query("select distinct p.products_id, p.products_price, p.products_model, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c " . $product_search . " order by pd.products_name");
$not_found = ((tep_db_num_rows($products_query)) ? false : true);
}
$category_array = array(array('id' => '', 'text' => TEXT_SELECT_CATEGORY),
array('id' => '0', 'text' => TEXT_ALL_CATEGORIES));
if (($step > 1) && (!$not_found)) {
$product_array = array(array('id' => 0, 'text' => TEXT_SELECT_PRODUCT));
while($products = tep_db_fetch_array($products_query)) {
$product_array[] = array('id' => $products['products_id'], 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value']));
}
}
$has_attributes = false;
$products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$add_product_products_id . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . $languages_id . "'");
$products_attributes = tep_db_fetch_array($products_attributes_query);
if ($products_attributes['total'] > 0) $has_attributes = true;
Here is the part that has a syntax error:
if (($step > 1) && (!$not_found)) {
$products = tep_db_fetch_array($products_query)
if count($products)=1 {
$product_array = array('id' => $products['products_id'], 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value']));
} else {
$product_array = array(array('id' => 0, 'text' => TEXT_SELECT_PRODUCT));
while($products = tep_db_fetch_array($products_query)) {
$product_array[] = array('id' => $products['products_id'], 'text' => $products['products_name'] . ' (' . $products['products_model'] . ')' . ': ' . $currencies->format($products['products_price'], true, $order->info['currency'], $order->info['currency_value']));
}
}