Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Increase/Decrease price by x% for all products or products from a category


Recommended Posts

Posted (edited)

Hello,

sorry but I do not know English well so I help with google.

 

I found this interesting contrb:

http://addons.oscommerce.com/info/4663

Increase / Decrease price by x% for all products or products from a category

 

if you have 1000 products in price increases of 3% becomes hard .. this rate varies automatically ... and very simple ... but only of goods, not attributes

 

you think there is the possibility to file admin to integrate the change in price for attributes?

 

changes only the products but the prices of the attributes remain unchanged ..

 

how to change it?

 

Code:

 

<?php
/*
 $Id: mail.php,v 1.1.1.1 2004/03/04 23:38:43 ccwjr 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($_GET["action"]) && $_GET["action"]=='modify_prices') {
$category_id = $_POST["category_id"];
if (trim($_POST["amount"])!="0") {
	$amount = $_POST["amount"];
}
elseif (trim($_POST["amount_dollars"]!="0")) {
	$amount_dollars = $_POST["amount_dollars"];
}
$operation = $_POST["operation"];
if ($category_id != 'all') {
	$query = 'select p.products_id, p.products_price, ptc.categories_id from 
		 products p,
		 products_to_categories ptc
		 where p.products_id = ptc.products_id
		 and ptc.categories_id = "'.(int)$category_id.'"';
	$result = mysql_query($query) or die(mysql_error());
	$number_of_modified_records = 0;
	while ($row = mysql_fetch_array($result)) {
		if ($operation == "plus") {
			if (isset($amount) && trim($amount)!="0") {
				$new_price = round((1+($amount/100)) * $row["products_price"],2);
			}
			elseif (isset($amount_dollars) && trim($amount_dollars)!="0") {
				$new_price = $row["products_price"] + $amount_dollars;
			}
		}
		else {
			if (isset($amount) && trim($amount)!="0") {
				$new_price = round((1-($amount/100)) * $row["products_price"],2);
			}
			elseif (isset($amount_dollars) && trim($amount_dollars)!="0") {
				$new_price = $row["products_price"] - $amount_dollars;
			}
		}
		$query_update = 'update products set products_price = '.$new_price.' where products_id = '.$row["products_id"];
		mysql_query($query_update);
		$number_of_modified_records++;
	}
}
else {
	$query = 'select products_id, products_price from products';
	$result = mysql_query($query) or die(mysql_error());
	$number_of_modified_records = 0;
	while ($row = mysql_fetch_array($result)) {
		if ($operation == "plus") {
			if (isset($amount) && trim($amount)!="0") {
				$new_price = round((1+($amount/100)) * $row["products_price"],2);
			}
			elseif (isset($amount_dollars) && trim($amount_dollars)!="0") {
				$new_price = $row["products_price"] + $amount_dollars;
			}
		}
		else {
			if (isset($amount) && trim($amount)!="0") {
				$new_price = round((1-($amount/100)) * $row["products_price"],2);
			}
			elseif (isset($amount_dollars) && trim($amount_dollars)!="0") {
				$new_price = $row["products_price"] - $amount_dollars;
			}
		}
		$query_update = 'update products set products_price = '.$new_price.' where products_id = '.$row["products_id"];
		mysql_query($query_update);
		$number_of_modified_records++;
	}	
}
 }


?>
<!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 MODIFY_PRICES_TITLE;?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>

      <script language="Javascript1.2"><!-- // load htmlarea
// MaxiDVD Added WYSIWYG HTML Area Box + Admin Function v1.7 - 2.2 MS2 HTML Email HTML - <head>
     _editor_url = "<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_ADMIN; ?>htmlarea/";  // URL to htmlarea files
       var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
        if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
         if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
          if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
      <?php if (HTML_AREA_WYSIWYG_BASIC_EMAIL == 'Basic'){ ?>  if (win_ie_ver >= 5.5) {
      document.write('<scr' + 'ipt src="' +_editor_url+ 'editor_basic.js"');
      document.write(' language="Javascript1.2"></scr' + 'ipt>');
         } else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
      <?php } else{ ?> if (win_ie_ver >= 5.5) {
      document.write('<scr' + 'ipt src="' +_editor_url+ 'editor_advanced.js"');
      document.write(' language="Javascript1.2"></scr' + 'ipt>');
         } else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
      <?php }?>
// --></script>
      <script language="JavaScript" src="htmlarea/validation.js"></script>
      <script language="JavaScript">
<!-- Begin
      function init() {
define('customers_email_address', 'string', 'Customer or Newsletter Group');
}
//  End -->
</script>
</head>
<body OnLoad="init()" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">

<!-- 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="0">
     <tr>
       <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
           <td class="pageHeading"><?php echo MODIFY_PRICES_TITLE;?></td>
           <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
         <tr><?php echo tep_draw_form('mail', 'prices_per.php', 'action=modify_prices'); ?>
           <td><table border="0" width="100%" cellpadding="0" cellspacing="2">
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
             </tr>
             <tr>
               <td class="smallText"><b><?php echo MODIFY_PRICES_CATEGORY;?></b><br>
				<select name='category_id'>
					<option value='all'><?php echo MODIFY_PRICES_ALL;?></option>
					<?php
						$query = "select categories_id, categories_name from categories_description";
						$result = mysql_query($query);
						while ($row = mysql_fetch_array($result)) {
							echo '<option value='.$row["categories_id"].'>'.$row["categories_name"].'</option>';
						}
						mysql_free_result($result);
					?>
				</select>
               </td>
             </tr>
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
             </tr>
             <tr>
               <td class="smallText"><b>+/-</b><br>
				<select name='operation'>
					<option value='plus'>+</option>
					<option value='minus'>-</option>
				</select>
               </td>
             </tr>
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
             </tr>
             <tr>
               <td class="smallText"><b><?php echo MODIFY_PRICES_AMOUNT;?></b><br><input type=text name=amount size=4 value=0>%</td>
             </tr>
             <tr>
               <td class="smallText"><b><?php echo MODIFY_PRICES_OR;?></b><br>$<input type=text name=amount_dollars size=4 value=0></td>
             </tr>
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
             </tr>
             <tr>
               <td class="smallText"><b>
               	<?php
               		if (isset($_GET["action"]) && $_GET["action"]=='modify_prices') {
               			echo $number_of_modified_records . " products modified";
               			if (isset($amount) && trim($amount)!="0") echo " by ".$amount."% ";
               			else echo " by $".$amount_dollars;
               		}
               	?>
               </b></td>
             </tr>
             <tr>
               <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
             </tr>
             <tr>
               <td>
                   <tr>
                   <td align="right"><?php echo '<a href="' . tep_href_link('prices_per.php') . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a> ' . tep_image_submit('button_confirm.gif', IMAGE_SEND_EMAIL); ?></td>
                   </tr>
                   <td class="smallText"></td>
                 </tr>
               </table></td>
            </tr>
           </table></td>
         </form></tr>
<!-- body_text_eof //-->
       </table></td>
     </tr>
   </table></td>
 </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<table aling=center><tr><td>Powered by <a href=http://www.PinkCrow.net>PinkCrow</a></td></tr></table>
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Edited by Dax87
Posted

The script could be enhanced to work on the product attributes table at the same time or it might be better to have a separate page to update PA prices.

 

In the latter case the only real change is to get PA for a selected category.

 

HTH

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Posted

The script could be enhanced to work on the product attributes table at the same time or it might be better to have a separate page to update PA prices.

 

In the latter case the only real change is to get PA for a selected category.

 

HTH

 

G

 

True,

The script is a good departure point.

You could create another file to retrieve only the prices of the attributes or incorporate all the same php acting in admin with more choices ......

 

the problem is that I can not ^ _ ^ also will..

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...