Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

creating loop for multiple wholesale special prices


Portman

Recommended Posts

Hi.... 

I am trying to modify my admin/specials.php file so that I can change the price for multiple "wholesale" customer groups (think SPPC)

I have got it to work for a price value, but I am trying to make it work for a percentage and that is where I am coming unstuck...

can someone have a look at the following code and help me out ....

      case 'update':

        $specials_id = tep_db_prepare_input($_POST['specials_id']);
        $products_price = tep_db_prepare_input($_POST['products_price']);
        $specials_price = tep_db_prepare_input($_POST['specials_price']);
        $expdate = tep_db_prepare_input($_POST['expdate']);
		
		// Added by peter for Wholesale special prices 		
		$array_specials_ws_price = array();
		for ($i=1; $i<=MODULE_STORE_WHOLESALE_GROUPS; $i++) {
			
			$value_specials_ws_price = ['specials_price_ws_' . $i];
			$wholesale_price = ("products_ws_price_$i");
			
			$value_specials_ws_price = tep_db_prepare_input($_POST['specials_price_ws_' . $i]);

			if (substr($value_specials_ws_price, -1) == '%') {
					
				$new_special_ws_insert_query = tep_db_query("select products_id, products_ws_price_1 from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
				$new_special_ws_insert = tep_db_fetch_array($new_special_ws_insert_query);

				$wholesale_price_holder = $new_special_ws_insert['products_ws_price_1'];

				$value_specials_ws_price = ($wholesale_price_holder - (($value_specials_ws_price / 100) * $wholesale_price_holder));	
	
				
			}
			
			$array_specials_ws_price[] = ("specials_new_ws_price_$i = " . $value_specials_ws_price);

// *********************************************************************			

		}

		$array_specials_ws_price = implode(', ', $array_specials_ws_price);
			

			// EOF Added by Peter 	

        if (substr($specials_price, -1) == '%') $specials_price = ($products_price - (($specials_price / 100) * $products_price));

        $expires_date = '';
        if (tep_not_null($expdate)) {
          $expires_date = substr($expdate, 0, 4) . substr($expdate, 5, 2) . substr($expdate, 8, 2);
        }	

		// Next Line modified By Peter for Wholesale special prices 
        tep_db_query("update " . TABLE_SPECIALS . " set specials_new_products_price = '" . tep_db_input($specials_price) . "', $array_specials_ws_price, specials_last_modified = now(), expires_date = " . (tep_not_null($expires_date) ? "'" . tep_db_input($expires_date) . "'" : 'null') . " where specials_id = '" . (int)$specials_id . "'");

        tep_redirect(tep_href_link('specials.php', 'page=' . $_GET['page'] . '&sID=' . $specials_id));
        break;

 I have simplified it a bit to try and find what I am doing wrong... my hope is to select the value in  $wholesale_price in the query eventually, but for now I am querying a static field "products_ws_price_1".

Basically, when I enter a percentage in the first field , but put price values in the other fields I get this error ;

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' specials_new_ws_price_2 = 32.0000, specials_new_ws_price_3 = 33.0000, specials_' at line 1

update specials set specials_new_products_price = '28.7920', specials_new_ws_price_1 = , specials_new_ws_price_2 = 32.0000, specials_new_ws_price_3 = 33.0000, specials_new_ws_price_4 = 34.0000, specials_new_ws_price_5 = 35.0000, specials_new_ws_price_6 = 36.0000, specials_new_ws_price_7 = 37.0000, specials_last_modified = now(), expires_date = '20190301' where specials_id = '6'

Any help would be appreciated.

 

 

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...