EricPrice Posted April 7, 2003 Share Posted April 7, 2003 I've been looking through the contributions for a group or customer-pricing contribution that would be easy to integrate with a MS1 snapshot. So far I dont seem to have had any luck. I was considering delving into writing my own, and I want to get some feedback. I want to add a field to the customer group that assigns them to a pricing group. I want to create a table for the pricing group and assign a percentage. Then, on the screens where pricing is shown I want to insert a command that would read the group id, read the percentage discount, and update the pricing shown on the page to reflect the discount before it is displayed. What files will I have to touch to make this price change travel through all the way to checkout? Is there another problem in my logic? Any comments would be greatly appreciated. Eric Price IR Waterjet Quote Link to comment Share on other sites More sharing options...
EricPrice Posted April 7, 2003 Author Share Posted April 7, 2003 I've looked through the code and found the following places I would need to update to make this work. /admin/includes/application_top.php /admin/includes/languages/english.php /admin/includes/functions/general.php /admin/customers.php (to assign customer to group) /catalog/includes/application_top.php /catalog/product_info.php /includes/classes/order.php /includes/classes/shopping_cart.php /includes/modules/new_products.php /includes/modules/product_listing.php /includes/modules/products_new.php /includes/modules/new_products.php includes/boxes/whats_new.php For all the places in the modules, classes, and includes could I not just make a call to a function that reads the information out of the DB and applies the discount before passing the adjusted pricing back to the calling program? If so, is anyone out there willing to help? While I have some background in C, Im no guru with SQL calls. Eric Price IR Waterjet Quote Link to comment Share on other sites More sharing options...
pilot1 Posted April 7, 2003 Share Posted April 7, 2003 sound like you need to look through this http://www.oscommerce.com/forums/viewtopic.php...er=asc&start=10 Quote What goes up MUST come down Link to comment Share on other sites More sharing options...
EricPrice Posted April 7, 2003 Author Share Posted April 7, 2003 No. I dont think that accomplishes what I want to do, though I could be wrong. I made some code (unfortunately it doesnt seem to work, lol). Its pasted below. I marked the spot where the browser says my error is. The error is Parse error: parse error, unexpected T_ELSE in /var/www/html/irwj.com/www/product_info.php on line 100 Before I started I did this. ALTER TABLE `customers` ADD `customers_group_id` int(11) NOT NULL; CREATE TABLE customers_groups ( customers_group_id int(11) NOT NULL, customers_group_name varchar(20) NOT NULL, customers_group_discount decimal(4,4) NOT NULL, PRIMARY KEY (customers_group_id) ) TYPE=MyISAM; Then I replaced this <?php $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . $languages_id . "'"); if (!tep_db_num_rows($product_info_query)) { // product not found in database ?> <tr> <td class="main"><br><?php echo TEXT_PRODUCT_NOT_FOUND; ?></td> </tr> <tr> <td align="right"><br><a href="<?php echo tep_href_link(FILENAME_DEFAULT); ?>"><?php echo tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></a></td> </tr> <?php } else { tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . $languages_id . "'"); $product_info = tep_db_fetch_array($product_info_query); if ($new_price = tep_get_products_special_price($product_info['products_id'])) { $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>'; } else { $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); } ?> With this code <?php $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . $languages_id . "'"); // this gets the customers_id from the session global $customer_id; // first if decides if customer_group_discount is already known. If not, it executes code to learn it. if($customer_group = 0) { // this reads the group id from the customer?s record. $customer_group_query = tep_db_query("select customers_group_id from " . TABLE_CUSTOMERS . " where customers_id = '" . $customer_id . "'"); $customer_group = tep_db_fetch_array($customer_group_query); //this takes the group id just read and queries the db again to learn the discount to be applied $customer_group_discount_query = tep_db_query("select customers_group_discount from " . TABLE_CUSTOMERS_GROUPS . " where customer_group_id = "' . $customer_group . "'"); $customer_group_discount = tep_db_fetch_array($customer_group__discount_query); //this applies the discount to the price in question } // second if checks again to see if customer_group = 0. If it is, then customer gets default pricing. if($customer_group = 0) { // if customer_group is zero we really don?t want to do anything to change the default ?retail? price. } else { // if it isn?t zero then we want to apply the discount to the current price. // this reads the information for the product into an array $product_info = tep_db_fetch_array($product_info_query); // this // this defines product price $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); // this multiplies the product price by the customer group discount $products_price = $products_price * (1 - $customer_group_discount); } if (!tep_db_num_rows($product_info_query)) { // product not found in database ?> <tr> <td class="main"><br><?php echo TEXT_PRODUCT_NOT_FOUND; ?></td> </tr> <tr> <td align="right"><br><a href="<?php echo tep_href_link(FILENAME_DEFAULT); ?>"><?php echo tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></a></td> </tr> <?php } else { tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . $languages_id . "'"); $product_info = tep_db_fetch_array($product_info_query); if ($new_price = tep_get_products_special_price($product_info['products_id'])) { $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>'; } else { $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); } ?> <?php //this is the else at line 100 that spawns the error } else { tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . $languages_id . "'"); $product_info = tep_db_fetch_array($product_info_query); if ($new_price = tep_get_products_special_price($product_info['products_id'])) { $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>'; } else { $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])); } ?>[/b] Quote Link to comment Share on other sites More sharing options...
EricPrice Posted April 7, 2003 Author Share Posted April 7, 2003 Doh. OK, so the error was me not getting all the old code out, and having an extra else in there. The page displays without errors now but the price isnt changed. What have I done wrong? And how do I turn this into a function so I can call it from all the places I need to rather than copying and pasting in text? Quote Link to comment Share on other sites More sharing options...
davemc Posted April 8, 2003 Share Posted April 8, 2003 In your code snip $customer_group_discount_query is misspelt the second time, with two underscores. I also think you could abbreviate some of your code with some SQL joins to retrieve customer and customer group at the same time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.