Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sign in to follow this  
aodfan

Mass-Price Editor Contribution

Recommended Posts

Ok, I have had this contribution, Mass Price Editor, installed for quite awhile now, the only thing that I wish it had is a spot where I can update my product cost as well. I tried to code the best I could. I believe I have coded price_editor.php correctly, but I am needing help coding price_process.php to reflect the updated cost price as well. Below are the two files.

 

price_editor.php

<?php
  /*
 $Id: price_editor.php,v 1.0 2005/05/24 01:05 Arctic Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
  */

 require('includes/application_top.php');
  ?>
  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
  <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">
  <script language="JavaScript" src="includes/general.js"></script>
  <script language="JavaScript">
 function doCurrency(amount)
 {
   var i = parseFloat(amount);
   if(isNaN(i)) { i = 0.00; }
   var minus = '';
   if(i < 0) { minus = '-'; }
   i = Math.abs(i);
   i = parseInt((i + .005) * 100);
   i = i / 100;
   s = new String(i);
   if(s.indexOf('.') < 0) { s += '.00'; }
   if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
   s = minus + s;
   return s;
 }

 function fixPrices()
 {
   var priceValue = document.forms['priceEditor'].elements['priceVal'];
   var valueMode = document.forms['priceEditor'].elements['valueMode'].value;
   var priceMode = document.forms['priceEditor'].elements['priceMode'].value;
   var error = false;
   var factor;
   var i;

   if(isNaN(priceValue.value))
   {
	 alert('Enter a valid numerical value');
	 error = true;
   }
   else if(valueMode == 'percent')
   {
	 if(priceValue.value > 300 || priceValue.value < 0)
	 {
	   alert('Enter a percentage value from 0% to 300%');
	   error = true;
	 }

	 if(!error)
	 {
	   var result = Math.round(priceValue.value * 100) / 100;

	   for(i = 0; i < document.forms['priceEditor'].elements.length; i = i + 3)
	   {
		 if((document.forms['priceEditor'].elements.length - i) >= 8)
		 {
		   // alert(document.forms['priceEditor'].elements[i + 1].value);
		   if(!isNaN(document.forms['priceEditor'].elements[i + 1].value))
		   {
			 factor = Math.round((parseFloat(document.forms['priceEditor'].elements[i + 1].value) * (parseFloat(result) / 100)) * 100) / 100;

			 if(priceMode == 'raise')
			 {
			   document.forms['priceEditor'].elements[i + 1].value = parseFloat(document.forms['priceEditor'].elements[i + 1].value) + factor;
			 }
			 else
			 {
			   document.forms['priceEditor'].elements[i + 1].value = parseFloat(document.forms['priceEditor'].elements[i + 1].value) - factor;
			 }

			 document.forms['priceEditor'].elements[i + 1].value = doCurrency(document.forms['priceEditor'].elements[i + 1].value);

			 if(document.forms['priceEditor'].elements[i + 1].value < 0)
			 {
			   document.forms['priceEditor'].elements[i + 1].value = doCurrency(parseFloat('0'));
			 }
		   }
		 }
	   }
	 }
   }
   else if(valueMode == 'fixed')
   {
	 if(!error)
	 {
	   var result = Math.round(priceValue.value * 100) / 100;

	   for(i = 0; i < document.forms['priceEditor'].elements.length; i = i + 3)
	   {
		 if((document.forms['priceEditor'].elements.length - i) >= 8)
		 {
		   // alert(document.forms['priceEditor'].elements[i + 1].value);
		   if(!isNaN(document.forms['priceEditor'].elements[i + 1].value))
		   {
			 if(priceMode == 'raise')
			 {
			   document.forms['priceEditor'].elements[i + 1].value = parseFloat(document.forms['priceEditor'].elements[i + 1].value) + parseFloat(result);
			 }
			 else
			 {
			   document.forms['priceEditor'].elements[i + 1].value = parseFloat(document.forms['priceEditor'].elements[i + 1].value) - parseFloat(result);
			 }

			 document.forms['priceEditor'].elements[i + 1].value = doCurrency(document.forms['priceEditor'].elements[i + 1].value);

			 if(document.forms['priceEditor'].elements[i + 1].value < 0)
			 {
			   document.forms['priceEditor'].elements[i + 1].value = doCurrency(parseFloat('0'));
			 }
		   }
		 }
	   }
	 }
   }
 }
  </script>
  </head>
  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();">
  <!-- header //-->
  <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
  <!-- header_eof //-->

  <!-- body //-->
  <table border="0" width="100%" cellspacing="2" cellpadding="2">
 <tr>
   <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
  <!-- left_navigation //-->
  <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
  <!-- left_navigation_eof //-->
   </table></td>
  <!-- body_text //-->
   <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
	 <tr>
	   <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
		 <tr>
		   <td class="pageHeading"><?php echo "Price Management"; ?></td>
		   <td class="smallText" align="right">
		   <?php
			 echo tep_draw_form('goto', 'price_editor.php', '', 'get');
			 echo 'Go To: ' . tep_draw_pull_down_menu('catID', tep_get_category_tree(), $_GET['catID'], 'onChange="this.form.submit();"');
			 echo '</form>';
		   ?>
		   </td>
		 </tr>
	   </table></td>
	 </tr>
	 <tr>
	   <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
		 <tr>
		   <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
			 <?php echo tep_draw_form('priceEditor', 'price_process.php', '', 'post'); ?>
			 <tr class="dataTableHeadingRow">
			   <td class="dataTableHeadingContent"><?php echo "Product"; ?></td>
			   <td class="dataTableHeadingContent"><?php echo "Category"; ?></td>
			   <td class="dataTableHeadingContent"><?php echo "Tax Category"; ?></td>
			   <td class="dataTableHeadingContent" align="right"><?php echo "Cost"; ?> </td>
			   <td class="dataTableHeadingContent" align="right"><?php echo "Price (Net)"; ?> </td>
			 </tr>
  <?php
 $i = 1;
 $tax_class_array[0]['text'] = '-- none --';
 $tax_class_array[0]['id'] = '0';
 $tax_class_query_raw = "select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_id";
 $tax_class_query = tep_db_query($tax_class_query_raw);
 while ($tax_class = tep_db_fetch_array($tax_class_query)) {
   $tax_class_array[$i]['text'] = $tax_class['tax_class_title'];
   $tax_class_array[$i]['id'] = $tax_class['tax_class_id'];
   $i++;
 }

 if(isset($_GET['catID']))
 {
   if(is_numeric($_GET['catID']) && $_GET['catID'] != 0)
   {
	 $input['category'] = addslashes($_GET['catID']);
   }
 }

 if(isset($_GET['page']))
 {
   if(is_numeric($_GET['page']) && $_GET['page'] != 0)
   {
	 $input['page'] = addslashes($_GET['page']);
   }
 }

 if(isset($input['category']))
 {
   $category_query_where = " and categories_id = '" . $input['category'] . "'";
   $category_desc_query_raw = "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $input['category'] . "' and language_id = '" . $languages_id . "'";
   $category_desc_query = tep_db_query($category_desc_query_raw);
   $category_desc = tep_db_fetch_array($category_desc_query);
 }
 else
 {
   $category_query_where = "";
 }

 $category_query_raw = "select products_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id != 0" . $category_query_where . " order by products_id";
 $category_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $category_query_raw, $category_query_numrows);
 $category_query = tep_db_query($category_query_raw);
 while ($category = tep_db_fetch_array($category_query)) {
   $product_query_raw = "select p.products_id, pd.products_name, p.products_cost, p.products_price, p.products_tax_class_id, c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " c, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . $category['products_id'] . "' and p.products_id = c.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "'";
   $product_query = tep_db_query($product_query_raw);
   $product = tep_db_fetch_array($product_query);
   $product_cost = substr($product['products_cost'], 0, strpos($product['products_cost'], '.') + 3);
   $product_price = substr($product['products_price'], 0, strpos($product['products_price'], '.') + 3);

   if(!isset($input['category']))
   {
	 $category_desc_query_raw = "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $product['categories_id'] . "' and language_id = '" . $languages_id . "'";
	 $category_desc_query = tep_db_query($category_desc_query_raw);
	 $category_desc = tep_db_fetch_array($category_desc_query);
   }

   echo '			  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)">' . "\n";
   echo '				<td class="dataTableContent">' . $product['products_name'] . '</td>' . "\n";
  ?>
			   <td class="dataTableContent"><?php echo $category_desc['categories_name']; ?></td>
			   <td class="dataTableContent">
				 <?php echo tep_draw_pull_down_menu('tax_class_' . $category['products_id'], $tax_class_array, $product['products_tax_class_id']); ?>
			   </td>

  <td class="dataTableContent" align="right">
				 <?php echo '<b>' . DEFAULT_CURRENCY . '</b> ' . tep_draw_input_field('price_' . $category['products_id'], $product_cost, 'style="text-align: right;"'); ?>
				 <?php echo tep_draw_hidden_field('pid_' . $category['products_id'], $category['products_id']); ?>
			   </td>

			   <td class="dataTableContent" align="right">
				 <?php echo '<b>' . DEFAULT_CURRENCY . '</b> ' . tep_draw_input_field('price_' . $category['products_id'], $product_price, 'style="text-align: right;"'); ?>
				 <?php echo tep_draw_hidden_field('pid_' . $category['products_id'], $category['products_id']); ?>
			   </td>
			 </tr>
  <?php
 }

 if(tep_db_num_rows($category_query) <= 0)
 {
  ?>
			 <tr>
			   <td class="dataTableContent" colspan="4" align="center">
				 <i>- No rows to display -</i>
			   </td>
			 </tr>
  <?php
 }
 else
 {
  ?>
			 <tr>
			   <td class="dataTableContent" colspan="2">


				 <select name="priceMode">
				   <option value="raise">Raise</option>
				   <option value="lower">Lower</option>
				 </select>
				  all prices by <?php echo tep_draw_input_field('priceVal', '0', 'style="text-align: right;" size="5" maxlength="10"'); ?> 
				 <select name="valueMode">
				   <option value="percent">percent</option>
				   <option value="fixed">fixed amount</option>
				 </select>
				  <input type="button" value="Go" onClick="fixPrices()">
			   </td>
			   <td class="dataTableContent" colspan="2" align="right">


				 <?php echo tep_draw_hidden_field('page', addslashes($input['page'])); ?>
				 <?php echo tep_draw_hidden_field('catID', addslashes($input['category'])); ?>
				 <input type="submit" value="Make Changes" name="submit">
				 </form>



			   </td>
			 </tr>
			 <tr>
			   <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">
				 <tr>
				   <td class="smallText" valign="top"><?php echo $category_split->display_count($category_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], 'Displaying <b>%d</b> to <b>%d</b> (of <b>%d</b> products)'); ?></td>
				   <td class="smallText" align="right"><?php echo $category_split->display_links($category_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'],  tep_get_all_get_params(array('page'))); ?></td>
				 </tr>
			   </table></td>
			 </tr>
  <?php
 }
  ?>
		   </table></td>
		 </tr>
	   </table></td>
	 </tr>
   </table></td>
  <!-- body_text_eof //-->
 </tr>
  </table>
  <!-- body_eof //-->

  <!-- footer //-->
  <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
  <!-- footer_eof //-->


  </body>
  </html>
  <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Share this post


Link to post
Share on other sites

price_process.php

<?php
/*
 $Id: price_process.php,v 1.0 2005/05/25 01:51 Arctic Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 require('includes/application_top.php');

 if(isset($_POST['submit']))
 {

array_pop($_POST);
$input['catID'] = array_pop($_POST);
$input['page'] = array_pop($_POST);
array_pop($_POST);
array_pop($_POST);
array_pop($_POST);

$x = 0;
for($i = 0; $i < count($_POST); $i = $i + 3)
{
  $tax_classes[$x] = current($_POST);
  $prices[$x] = next($_POST);
  $products[$x] = next($_POST);
  next($_POST);
  $x++;
}

/*
  print_r($_POST);
  echo '<br><br>';
  print_r($tax_classes);
  echo '<br><br>';
  print_r($prices);
  echo '<br><br>';
  print_r($products);
  echo '<br><br>';
  echo $input['catID'];
  echo '<br><br>';
  echo $input['page'];
*/

for($y = 0; $y < count($products); $y++)
{
  if($prices[$y] && is_numeric($prices[$y]))
  {
	$price_query_raw = "update " . TABLE_PRODUCTS . " set products_price = '" . $prices[$y] . "', products_tax_class_id = '" . $tax_classes[$y] . "' where products_id = '" . $products[$y] . "'";
	$price_query = tep_db_query($price_query_raw);
  }
}

header("Location: price_editor.php?catID=" . $input['catID'] . "&page=" . $input['page']);
 }
 else
 {
header("Location: price_editor.php");
 }
?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×