ken0306 Posted March 17, 2015 Posted March 17, 2015 Hi, I am trying to add a function in my site that allow customer moving products from withlist table to registry_product table. So here is the so far I can do if(($registry_mode_id == 0)&&($customer_id == 0)){ echo 'not login'; } elseif (($registry_mode_id == 0)&&($customer_id > 0)) { echo 'login no registry'; } else { if(isset($_POST['submit'])){ $registry_prebuild_query = tep_db_query ("SELECT customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id FROM " . TABLE_REGISTRY_PRODUCTS . " WHERE customers_id=" . $customer_id . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); tep_db_query ("SELECT customers_id, products_id, products_options_id, products_options_value_id, registry_id FROM " . TABLE_REGISTRY_PRODUCTS_ATTRIBUTES . " WHERE customers_id=" . $customer_id . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); $product_check_result = mysql_query("SELECT products_id, customers_id FROM " . TABLE_REGISTRY_PRODUCTS . " WHERE products_id = " . $HTTP_POST_VARS['products_id'] . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . " and customers_id=" . $customer_id . ""); // check attributes if item in there or not $product_attributes_check_result = mysql_query("SELECT products_id, customers_id FROM " . TABLE_REGISTRY_PRODUCTS_ATTRIBUTES . " WHERE products_id = " . $HTTP_POST_VARS['products_id'] . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . " and customers_id=" . $customer_id . ""); if(mysql_num_rows($product_check_result) == 0 && ($product_attributes_check_result) == 0) { tep_db_query ("INSERT INTO " . TABLE_REGISTRY_PRODUCTS . "(customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id) VALUES ('" . $customer_id . "', '" . $HTTP_POST_VARS['products_id'] . "', '" . $HTTP_POST_VARS ['registry_products_quantity'] . "', '" . date("Ymd") . "', '" . $HTTP_POST_VARS ['registry_mode_id'] . "')"); tep_db_query ("INSERT INTO " . TABLE_REGISTRY_PRODUCTS_ATTRIBUTES . "(customers_id, products_id, products_options_id, products_options_value_id, registry_id) VALUES ('" . $customer_id . "', '" . $HTTP_POST_VARS['products_id'] . "', '" . $HTTP_POST_VARS ['products_options_id'] . "', '" . $HTTP_POST_VARS ['products_options_value_id'] . "', '" . $HTTP_POST_VARS ['registry_mode_id'] . "')"); } else { tep_db_query ("UPDATE " . TABLE_REGISTRY_PRODUCTS . " SET registry_products_quantity=registry_products_quantity+'" . $HTTP_POST_VARS ['registry_products_quantity'] . "' WHERE products_id = " . $HTTP_POST_VARS['products_id'] . " AND registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); } //echo 'add to registry'; tep_redirect(tep_href_link(FILENAME_REGISTRY_PRODUCTS, '', 'SSL')); $wishlist['products_id'] = $_POST($wishlist['products_id']); $HTTP_POST_VARS['registry_products_quantity'][$i] = $_POST['registry_products_quantity'][$i]; $HTTP_POST_VARS ['registry_mode_id'] = $registry_mode_id; } } with the current query, I am able to add the product from my wishlist_products table to my registry_products table. It also can update the qty if there are product already in there. However, the problem is the items that has attributes. The products will add to the table, but on the second adding, it will create another line of the record in the database, it doesn't update the current record. it do the same same under the registry_products_attributes table. Can somebody tell me what I did wrong in the code, and how can I fix it? thank you ken
Bob Terveuren Posted March 17, 2015 Posted March 17, 2015 Arro How about if(mysql_num_rows($product_check_result) == 0 && ($product_attributes_check_result) == 0) becomes if(mysql_num_rows($product_check_result) == 0 && mysql_num_rows($product_attributes_check_result) == 0) if that works get sexy and go for tep_db_num_rows() instead
ken0306 Posted March 17, 2015 Author Posted March 17, 2015 Arro How about if(mysql_num_rows($product_check_result) == 0 && ($product_attributes_check_result) == 0) becomes if(mysql_num_rows($product_check_result) == 0 && mysql_num_rows($product_attributes_check_result) == 0) if that works get sexy and go for tep_db_num_rows() instead HI Bob Terveuren Thank you for your reply. It still not working properly. I rethink about the query, it may not need the second part of the code (&& ($product_attributes_check_result) == 0) because if the product doesn't has record in the registry_product table, it will not be exist in the registry_products_attributes table. Here is what I test out on my page. When I trying to move a normal product from wishlist table to registry table, the input field as follow <form name="submit_registry" action="http://192.168.247.19/09262014/registry_prebuild.php" method="post"> <input type="text" value="2" name="registry_products_quantity" class="qty_box" > <input name="registry_mode_id" value="109637" id="name-data" type="text" class="hidden"/> <input type="hidden" name="products_id" value="11128"> <button id="submit" type="submit" value="Submit Order" name="submit" class="btn-warning btn"> <input type="image" src="includes/languages/english/images/buttons/button_add_to_registry.png" border="0" alt="IMAGE_BUTTON_ADD_TO_REGISTRY" title=" IMAGE_BUTTON_ADD_TO_REGISTRY "> </button> </form> The script works fine with update and insert function. I believe this is part that taking action. if(isset($_POST['submit'])){ $registry_prebuild_query = tep_db_query ("SELECT customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id FROM " . TABLE_REGISTRY_PRODUCTS . " WHERE customers_id=" . $customer_id . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); tep_db_query ("SELECT customers_id, products_id, products_options_id, products_options_value_id, registry_id FROM " . TABLE_REGISTRY_PRODUCTS_ATTRIBUTES . " WHERE customers_id=" . $customer_id . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); $product_check_result = mysql_query("SELECT products_id, customers_id FROM " . TABLE_REGISTRY_PRODUCTS . " WHERE products_id = " . $HTTP_POST_VARS['products_id'] . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . " and customers_id=" . $customer_id . ""); if(mysql_num_rows($product_check_result) == 0 && ($product_attributes_check_result) == 0) { tep_db_query ("INSERT INTO " . TABLE_REGISTRY_PRODUCTS . "(customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id) VALUES ('" . $customer_id . "', '" . $HTTP_POST_VARS['products_id'] . "', '" . $HTTP_POST_VARS ['registry_products_quantity'] . "', '" . date("Ymd") . "', '" . $HTTP_POST_VARS ['registry_mode_id'] . "')"); } else { tep_db_query ("UPDATE " . TABLE_REGISTRY_PRODUCTS . " SET registry_products_quantity=registry_products_quantity+'" . $HTTP_POST_VARS ['registry_products_quantity'] . "' WHERE products_id = " . $HTTP_POST_VARS['products_id'] . " AND registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); } Here is script that I trying to add a product with attribute from the script. <form name="submit_registry" action="http://192.168.247.19/09262014/registry_prebuild.php" method="post"> <tr> <td><a href="http://192.168.247.19/09262014/product_info.php?products_id=9684{2}18"> <img src="images/halo/10044595_s.jpg" border="0" alt="Halo Sleep Sack Wearable Blanket Cotton Pink" title=" Halo Sleep Sack Wearable Blanket Cotton Pink " width="100" height="100" /></a></td> <td><b><a href="http://192.168.247.19/09262014/product_info.php?products_id=9684{2}18">Halo Sleep Sack Wearable Blanket Cotton Pink</a></b> <input type="hidden" name="products_options_id" value="2"> <input type="hidden" name="products_options_value_id" value="18"> <input type="text" value="3" name="registry_products_quantity" class="qty_box" > <input name="registry_mode_id" value="109637" id="name-data" type="text" class="hidden"/> <input type="hidden" name="products_id" value="9684{2}18"> <button id="submit" type="submit" value="Submit Order" name="submit" class="btn-warning btn"> <input type="image" src="includes/languages/english/images/buttons/button_add_to_registry.png" border="0" alt="IMAGE_BUTTON_ADD_TO_REGISTRY" title=" IMAGE_BUTTON_ADD_TO_REGISTRY "> </button> </form> So the difference between insert form is the product_id. The products with attribute are looks like <input type="hidden" name="products_id" value="9684{2}18">, and products without attribute are look like <input type="hidden" name="products_id" value="9684">. At the beginning of the query, I am checking if the product_id in the registry_product table, if the value is numbers only, the query will run properly, if the products_id with {} which is the option_id indicator, it will not run properly. So if that is the problem, how do I fix this problem? ken
ken0306 Posted March 18, 2015 Author Posted March 18, 2015 I got it work.... So, here is code that I already test on my local server, it can add product from wishlist table to registry table. <?php /* $Id: wishlist.php,v 3.0 2005/04/20 Dennis Blake osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Released under the GNU General Public License */ require('includes/application_top.php'); require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_WISHLIST); //if(!isset($_GET['public_id'])) { // tep_redirect(tep_href_link(FILENAME_DEFAULT)); //} /**hardcode with customer id *****/ $public_id = 21; /******************************************************************* ****************** QUERY CUSTOMER INFO FROM ID ********************* *******************************************************************/ $customer_query = tep_db_query("select customers_firstname from " . TABLE_CUSTOMERS . " where customers_id = '" . $public_id . "'"); $customer = tep_db_fetch_array($customer_query); /******************************************************************* ****************** ADD PRODUCT TO SHOPPING CART ******************** *******************************************************************/ // $breadcrumb->add(NAVBAR_TITLE_WISHLIST, tep_href_link(FILENAME_WISHLIST, '', 'SSL')); if(($registry_mode_id == 0)&&($customer_id == 0)){ echo 'not login'; } elseif (($registry_mode_id == 0)&&($customer_id > 0)) { echo 'login no registry'; } else { if(isset($_POST['submit'])){ $registry_prebuild_query = tep_db_query ("SELECT customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id FROM " . TABLE_REGISTRY_PRODUCTS . " WHERE customers_id=" . $customer_id . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); $product_check_result = mysql_query("SELECT products_id, customers_id FROM " . TABLE_REGISTRY_PRODUCTS . " WHERE products_id ='" . $HTTP_POST_VARS['products_id'] . "' and registry_id = '" . $HTTP_POST_VARS ['registry_mode_id'] . "' and customers_id='" . $customer_id . "'"); // check attributes if item in there or not $registry_prebuild_query_attributes = tep_db_query ("SELECT customers_id, products_id, products_options_id, products_options_value_id, registry_id FROM " . TABLE_REGISTRY_PRODUCTS_ATTRIBUTES . " WHERE customers_id=" . $customer_id . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); if(mysql_num_rows($product_check_result) == 0 && $HTTP_POST_VARS ['products_options_id'] == 0) { // insert product to registry_products table if the product doesn't exists in the registry tep_db_query ("INSERT INTO " . TABLE_REGISTRY_PRODUCTS . "(customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id) VALUES ('" . $customer_id . "', '" . $HTTP_POST_VARS['products_id'] . "', '" . $HTTP_POST_VARS ['registry_products_quantity'] . "', '" . date("Ymd") . "', '" . $HTTP_POST_VARS ['registry_mode_id'] . "')"); } elseif (mysql_num_rows($product_check_result) == 0 && $HTTP_POST_VARS ['products_options_id'] !== 0) { // insert product to registry_products table if the product doesn't exists in the registry tep_db_query ("INSERT INTO " . TABLE_REGISTRY_PRODUCTS . "(customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id) VALUES ('" . $customer_id . "', '" . $HTTP_POST_VARS['products_id'] . "', '" . $HTTP_POST_VARS ['registry_products_quantity'] . "', '" . date("Ymd") . "', '" . $HTTP_POST_VARS ['registry_mode_id'] . "')"); // insert product attribute to registry_products_attributes table if the product has attributes tep_db_query ("INSERT INTO " . TABLE_REGISTRY_PRODUCTS_ATTRIBUTES . "(customers_id, products_id, products_options_id, products_options_value_id, registry_id) VALUES ('" . $customer_id . "', '" . $HTTP_POST_VARS['products_id'] . "', '" . $HTTP_POST_VARS ['products_options_id'] . "', '" . $HTTP_POST_VARS ['products_options_value_id'] . "', '" . $HTTP_POST_VARS ['registry_mode_id'] . "')"); } else { // update product qty if the product already in the registry tep_db_query ("UPDATE " . TABLE_REGISTRY_PRODUCTS . " SET registry_products_quantity=registry_products_quantity+'" . $HTTP_POST_VARS ['registry_products_quantity'] . "' WHERE products_id = '" . $HTTP_POST_VARS['products_id'] . "' AND registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); } tep_redirect(tep_href_link(FILENAME_REGISTRY_PREBUILD, '', 'NONSSL')); //tep_redirect(tep_href_link(FILENAME_REGISTRY_PRODUCTS, '', 'SSL')); // $public_id = $_POST[$public_id]; $wishlist['products_id'] = $_POST($wishlist['products_id']); $HTTP_POST_VARS['registry_products_quantity'][$i] = $_POST['registry_products_quantity'][$i]; $HTTP_POST_VARS ['registry_mode_id'] = $registry_mode_id; //$HTTP_POST_VARS ['products_id'] = $_POST['products_id']; } } ?> <!DOCTYPE html> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?></title> <base href="<?php echo (getenv('HTTPS') == 'on' ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <?php require(DIR_WS_INCLUDES . 'query_header.php'); ?> </head> <body> </div> <!-- header //--> <?php //require(DIR_WS_INCLUDES . 'header.php'); ?> <!-- header_eof //--> <div class="container"><?php include(DIR_WS_MODULES . FILENAME_BREADCRMB); ?></div> <div class="container"><h5><?php echo $registry_mode_id;?></h5> <h1 class="hidden"><?php echo $customer['customers_firstname'] . HEADING_TITLE2; ?></h1></div> <!-- body //--> <div class="container"> <!-- center info //--> <?php //echo tep_draw_form('submit_registry', $_PHP_SELF); ?> <?php // echo tep_draw_form('submit_registry'); ?> <?php echo tep_draw_form('submit_registry', tep_href_link(FILENAME_REGISTRY_PREBUILD, tep_get_all_get_params(array('action')) . '')); ?> <table border="0" width="100%" cellspacing="0" cellpadding="5"> <tr> <!-- body_text //--> <td width="100%" valign="top"> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <?php /* QUERY THE DATABASE FOR THE CUSTOMERS WISHLIST PRODUCTS */ $wishlist_query_raw = "select * from " . TABLE_WISHLIST . " where customers_id = '" . $public_id . "'"; $wishlist_split = new splitPageResults($wishlist_query_raw, MAX_DISPLAY_WISHLIST_PRODUCTS); $wishlist_query = tep_db_query($wishlist_split->sql_query); /* insert product to registry table */ ?> <!-- customer_wishlist //--> <?php if (tep_db_num_rows($wishlist_query)) { if ($wishlist_split > 0 && (PREV_NEXT_BAR_LOCATION == '1' || PREV_NEXT_BAR_LOCATION == '3')) { ?> <?php echo $wishlist_split->display_count(TEXT_DISPLAY_NUMBER_OF_WISHLIST); ?> <?php echo TEXT_RESULT_PAGE . ' ' . $wishlist_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?> <?php } ?> <tr> <td> <table border="0" width="100%" cellspacing="0" > <tr> <td ><?php echo BOX_TEXT_IMAGE; ?></td> <td ><?php echo BOX_TEXT_PRODUCT; ?></td> <td >QTY</td> <td ><?php echo BOX_TEXT_PRICE; ?></td> <td ><?php echo BOX_TEXT_SELECT; ?></td> </tr> <?php /******************************************************************* ***** LOOP THROUGH EACH PRODUCT ID TO DISPLAY IN THE WISHLIST ****** *******************************************************************/ $i = 0; while ($wishlist = tep_db_fetch_array($wishlist_query)) { $wishlist_id = tep_get_prid($wishlist['products_id']); $products_query = tep_db_query("select pd.products_id, pd.products_name, pd.products_description, p.products_image, p.products_price, p.products_status, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from ( " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd ) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where pd.products_id = '" . $wishlist_id . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' order by products_name"); $products = tep_db_fetch_array($products_query); ?> <?php echo tep_draw_form('submit_registry', tep_href_link(FILENAME_REGISTRY_PREBUILD, tep_get_all_get_params(array('action')) . '')); ?> <tr> <td><a href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $wishlist['products_id'], 'NONSSL'); ?>"> <?php echo tep_image(DIR_WS_IMAGES . $products['products_image'], $products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); ?></a></td> <td><b><a href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $wishlist['products_id'], 'NONSSL'); ?>"><?php echo $products['products_name']; ?></a></b> <?php /******************************************************************* ******** THIS IS THE WISHLIST CODE FOR PRODUCT ATTRIBUTES ********* *******************************************************************/ $attributes_addon_price = 0; // Now get and populate product attributes $wishlist_products_attributes_query = tep_db_query("select products_options_id as po, products_options_value_id as pov from " . TABLE_WISHLIST_ATTRIBUTES . " where customers_id='" . $public_id . "' and products_id = '" . $wishlist['products_id'] . "'"); while ($wishlist_products_attributes = tep_db_fetch_array($wishlist_products_attributes_query)) { // We now populate $id[] hidden form field with product attributes // echo tep_draw_hidden_field('id['.$wishlist['products_id'].']['.$wishlist_products_attributes['po'].']', $wishlist_products_attributes['pov']); // echo tep_draw_hidden_field('product_id', $wishlist['products_id']); echo tep_draw_hidden_field('products_options_id', $wishlist_products_attributes['po']); echo tep_draw_hidden_field('products_options_value_id', $wishlist_products_attributes['pov']); // And Output the appropriate attribute name $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $wishlist_id . "' and pa.options_id = '" . $wishlist_products_attributes['po'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $wishlist_products_attributes['pov'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'"); $attributes_values = tep_db_fetch_array($attributes); if ($attributes_values['price_prefix'] == '+') { $attributes_addon_price += $attributes_values['options_values_price']; } else if ($attributes_values['price_prefix'] == '-') { $attributes_addon_price -= $attributes_values['options_values_price']; } echo '<br /><small><i> ' . $attributes_values['products_options_name'] . ': ' . $attributes_values['products_options_values_name'] . '</i></small>'; } // end while attributes for product if (tep_not_null($products['specials_new_products_price'])) { $products_price = '<s>' . $currencies->display_price($products['products_price']+$attributes_addon_price, tep_get_tax_rate($products['products_tax_class_id'])) . '</s> <span class="list-inline">' . $currencies->display_price($products['specials_new_products_price']+$attributes_addon_price, tep_get_tax_rate($products['products_tax_class_id'])) . '</span>'; } else { $products_price = $currencies->display_price($products['products_price']+$attributes_addon_price, tep_get_tax_rate($products['products_tax_class_id'])); } $i++; ?> </td> <td > <input type="text" value="<?php echo $wishlist['products_qty'];?>" name="registry_products_quantity" class="qty_box" > </td> <td ><?php echo $products_price; ?></td> <td ><?php // echo tep_draw_checkbox_field('add_registry[]',$wishlist['products_id'], true ); ?></td> <td> <input name="registry_mode_id" value="<?php echo $registry_mode_id;?>" id="name-data" type="text" class="hidden"/> <?php if($registry_mode_id == 0){ ?> <?php // echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?> not login yet <?php } else { ?> <?php echo tep_draw_hidden_field('products_id', $wishlist['products_id'])?> <button id="submit" type="submit" value="Submit Order" name="submit" class="btn-warning btn"> <?php echo tep_image_submit('button_add_to_registry.png', IMAGE_BUTTON_ADD_TO_REGISTRY); ?> </button> <?php } ?> </form> </td> </tr> <?php } ?> <?php if($registry_mode_id == 0){ ?> <?php // echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?> redirect to registry page <?php } ?> <tr><td> <!-- registry modification //--> </td></tr> </table> </td> </tr> <tr> <td> <?php if ($wishlist_split > 0 && (PREV_NEXT_BAR_LOCATION == '2' || PREV_NEXT_BAR_LOCATION == '3')) { ?> <?php echo $wishlist_split->display_count(TEXT_DISPLAY_NUMBER_OF_WISHLIST); ?> <?php echo TEXT_RESULT_PAGE . ' ' . $wishlist_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?> </td> </tr> </table> <!-- body_text_eof //--> </tr> </table> <!-- body_eof //--> </div> <!-- center info //--> </div> <?php } } ?> <!-- end registry modification //--> <!-- footer //--> <?php //require(DIR_WS_INCLUDES . 'footer.php'); ?> <!-- footer_eof //--> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
ken0306 Posted March 19, 2015 Author Posted March 19, 2015 Hi there, Currently the code has the ability to add product with request qty from wishlist_product table to registry_product table one by one. But I want to make it be able to add everything at once. Any suggestion on the code? I have each product under one form to apply each adding action, I want to know if is there a way to trigger multiple form in one page by form ID? I also update the script that allow me to show the category of the product under the name, and I also looking for the solutions for grouping products by category, and filter by category. Here is my update code. <?php /* $Id: wishlist.php,v 3.0 2005/04/20 Dennis Blake osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Released under the GNU General Public License */ require('includes/application_top.php'); require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_REGISTRY_PREBUILD); //if(!isset($_GET['public_id'])) { // tep_redirect(tep_href_link(FILENAME_DEFAULT)); //} /**pre defind ID *****/ $public_id = 21; // $public_id = $_GET['public_id']; /******************************************************************* ****************** QUERY CUSTOMER INFO FROM ID ********************* *******************************************************************/ $customer_query = tep_db_query("select customers_firstname from " . TABLE_CUSTOMERS . " where customers_id = '" . $public_id . "'"); $customer = tep_db_fetch_array($customer_query); /******************************************************************* ****************** ADD PRODUCT TO SHOPPING CART ******************** *******************************************************************/ $breadcrumb->add(NAVBAR_TITLE_PREBUILD_REGISTRY, tep_href_link(FILENAME_REGISTRY_PREBUILD, '', 'SSL')); if(($registry_mode_id == 0)&&($customer_id == 0)){ echo '<div class="container"><h4>not login</h4></div>'; } elseif (($registry_mode_id == 0)&&($customer_id > 0)) { echo 'login no registry'; } else { if(isset($_POST['submit'])){ $registry_prebuild_query = tep_db_query ("SELECT customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id FROM " . TABLE_REGISTRY_PRODUCTS . " WHERE customers_id=" . $customer_id . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); $product_check_result = mysql_query("SELECT products_id, customers_id FROM " . TABLE_REGISTRY_PRODUCTS . " WHERE products_id ='" . $HTTP_POST_VARS['products_id'] . "' and registry_id = '" . $HTTP_POST_VARS ['registry_mode_id'] . "' and customers_id='" . $customer_id . "'"); // check attributes if item in there or not $registry_prebuild_query_attributes = tep_db_query ("SELECT customers_id, products_id, products_options_id, products_options_value_id, registry_id FROM " . TABLE_REGISTRY_PRODUCTS_ATTRIBUTES . " WHERE customers_id=" . $customer_id . " and registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); if(mysql_num_rows($product_check_result) == 0 && $HTTP_POST_VARS ['products_options_id'] == 0) { // insert product to registry_products table if the product doesn't exists in the registry tep_db_query ("INSERT INTO " . TABLE_REGISTRY_PRODUCTS . "(customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id) VALUES ('" . $customer_id . "', '" . $HTTP_POST_VARS['products_id'] . "', '" . $HTTP_POST_VARS ['registry_products_quantity'] . "', '" . date("Ymd") . "', '" . $HTTP_POST_VARS ['registry_mode_id'] . "')"); } elseif (mysql_num_rows($product_check_result) == 0 && $HTTP_POST_VARS ['products_options_id'] !== 0) { // insert product to registry_products table if the product doesn't exists in the registry tep_db_query ("INSERT INTO " . TABLE_REGISTRY_PRODUCTS . "(customers_id, products_id, registry_products_quantity, registry_products_date_added, registry_id) VALUES ('" . $customer_id . "', '" . $HTTP_POST_VARS['products_id'] . "', '" . $HTTP_POST_VARS ['registry_products_quantity'] . "', '" . date("Ymd") . "', '" . $HTTP_POST_VARS ['registry_mode_id'] . "')"); // insert product attribute to registry_products_attributes table if the product has attributes tep_db_query ("INSERT INTO " . TABLE_REGISTRY_PRODUCTS_ATTRIBUTES . "(customers_id, products_id, products_options_id, products_options_value_id, registry_id) VALUES ('" . $customer_id . "', '" . $HTTP_POST_VARS['products_id'] . "', '" . $HTTP_POST_VARS ['products_options_id'] . "', '" . $HTTP_POST_VARS ['products_options_value_id'] . "', '" . $HTTP_POST_VARS ['registry_mode_id'] . "')"); } else { // update product qty if the product already in the registry tep_db_query ("UPDATE " . TABLE_REGISTRY_PRODUCTS . " SET registry_products_quantity=registry_products_quantity+'" . $HTTP_POST_VARS ['registry_products_quantity'] . "' WHERE products_id = '" . $HTTP_POST_VARS['products_id'] . "' AND registry_id = " . $HTTP_POST_VARS ['registry_mode_id'] . ""); } //echo 'ABC add to your registry'; tep_redirect(tep_href_link(FILENAME_REGISTRY_PREBUILD, '', 'NONSSL')); //tep_redirect(tep_href_link(FILENAME_REGISTRY_PRODUCTS, '', 'SSL')); // $public_id = $_POST[$public_id]; $wishlist['products_id'] = $_POST($wishlist['products_id']); $HTTP_POST_VARS['registry_products_quantity'][$i] = $_POST['registry_products_quantity'][$i]; $HTTP_POST_VARS ['registry_mode_id'] = $registry_mode_id; //$HTTP_POST_VARS ['products_id'] = $_POST['products_id']; } } ?> <!DOCTYPE html> <html <?php echo HTML_PARAMS; ?>> <head> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> <title><?php echo TITLE; ?></title> <base href="<?php echo (getenv('HTTPS') == 'on' ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>"> <meta http-equiv="X-UA-Compatible" content="IE=edge" enctype="multipart/form-data" > <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <?php require(DIR_WS_INCLUDES . 'query_header.php'); ?> </head> <body> <!-- header //--> <?php // require(DIR_WS_INCLUDES . 'header.php'); ?> <!-- header_eof //--> <div class="container"><?php include(DIR_WS_MODULES . FILENAME_BREADCRMB); ?></div> <div class="container"><h5><?php echo $registry_mode_id;?></h5> <h1 class="hidden"><?php echo $customer['customers_firstname'] . HEADING_TITLE2; ?></h1></div> <!-- body //--> <div class="container"> <!-- center info //--> <?php /* QUERY THE DATABASE FOR THE CUSTOMERS WISHLIST PRODUCTS */ $wishlist_query_raw = "select * from " . TABLE_WISHLIST . " where customers_id = '" . $public_id . "'"; $wishlist_split = new splitPageResults($wishlist_query_raw, 1000); $wishlist_query = tep_db_query($wishlist_split->sql_query); /* insert product to registry table */ ?> <div class="container"> <?php if (tep_db_num_rows($wishlist_query)) { if ($wishlist_split > 0 && (PREV_NEXT_BAR_LOCATION == '1' || PREV_NEXT_BAR_LOCATION == '3')) { ?> <?php echo $wishlist_split->display_count(TEXT_DISPLAY_NUMBER_OF_WISHLIST); ?> <?php echo TEXT_RESULT_PAGE . ' ' . $wishlist_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?> <?php } ?> </div> <hr /> <!-- customer_wishlist //--> <div class="col-md-2 "><ul><h2>categorys</h2> <li>Stroller</li> <li>car seat</li> <li>Colthing</li> <li>Safety</li> <li>Heath</li> </ul></div> <div class="col-md-10"> <dd class="col-xs-3 hidden"><?php echo BOX_TEXT_IMAGE; ?></dd> <dd class="col-xs-5 hidden"><?php echo BOX_TEXT_PRODUCT; ?></dd> <dd class="col-xs-2 hidden"><?php echo BOX_TEXT_QTY; ?></dd> <dd class="col-xs-2 hidden"><?php echo BOX_TEXT_PRICE; ?></dd> <?php /******************************************************************* ***** LOOP THROUGH EACH PRODUCT ID TO DISPLAY IN THE WISHLIST ****** *******************************************************************/ $i = 0; while ($wishlist = tep_db_fetch_array($wishlist_query)) { $wishlist_id = tep_get_prid($wishlist['products_id']); $products_query = tep_db_query("SELECT ptc.categories_id, ptc.products_id, cd.categories_id, cd.categories_name, pd.products_id, pd.products_name, pd.products_description, p.products_image, p.products_price, p.products_status, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from (" . TABLE_PRODUCTS_TO_CATEGORIES . " ptc, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd ) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where pd.products_id = '" . $wishlist_id . "' and ptc.products_id = pd.products_id and p.products_id = pd.products_id and cd.categories_id = ptc.categories_id and pd.language_id = '" . $languages_id . "' order by products_name asc"); // $products_query = tep_db_query("select pd.products_id, pd.products_name, pd.products_description, p.products_image, p.products_price, p.products_status, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from ( " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd ) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where pd.products_id = '" . $wishlist_id . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' order by products_name asc"); ?> <?php $products = tep_db_fetch_array($products_query); ?> <?php echo tep_draw_form('submit_registry', tep_href_link(FILENAME_REGISTRY_PREBUILD, tep_get_all_get_params(array('action'))), 'post', 'id ="'. $wishlist['products_id'] .'"'); ?> <div class="col-xs-12 col-md-4 text-center nav"> <div class="img-thumbnail row"> <dd class="col-xs-12"> <a class="" href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $wishlist['products_id'], 'NONSSL'); ?>"> <?php echo tep_image_lazy(DIR_WS_IMAGES . $products['products_image'], $products['products_name']); ?> </a></dd> <dd class="col-xs-12"><a href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $wishlist['products_id'], 'NONSSL'); ?>"><?php echo $products['products_name']; ?></a> <?php $attributes_addon_price = 0; // Now get and populate product attributes $wishlist_products_attributes_query = tep_db_query("select products_options_id as po, products_options_value_id as pov from " . TABLE_WISHLIST_ATTRIBUTES . " where customers_id='" . $public_id . "' and products_id = '" . $wishlist['products_id'] . "'"); while ($wishlist_products_attributes = tep_db_fetch_array($wishlist_products_attributes_query)) { // We now populate $id[] hidden form field with product attributes // echo tep_draw_hidden_field('id['.$wishlist['products_id'].']['.$wishlist_products_attributes['po'].']', $wishlist_products_attributes['pov']); // echo tep_draw_hidden_field('product_id', $wishlist['products_id']); echo tep_draw_hidden_field('products_options_id', $wishlist_products_attributes['po']); echo tep_draw_hidden_field('products_options_value_id', $wishlist_products_attributes['pov']); // And Output the appropriate attribute name $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $wishlist_id . "' and pa.options_id = '" . $wishlist_products_attributes['po'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $wishlist_products_attributes['pov'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'"); $attributes_values = tep_db_fetch_array($attributes); if ($attributes_values['price_prefix'] == '+') { $attributes_addon_price += $attributes_values['options_values_price']; } else if ($attributes_values['price_prefix'] == '-') { $attributes_addon_price -= $attributes_values['options_values_price']; } echo '<br /><small><i> ' . $attributes_values['products_options_name'] . ': ' . $attributes_values['products_options_values_name'] . '</i></small>'; } // end while attributes for product if (tep_not_null($products['specials_new_products_price'])) { $products_price = '' . $currencies->display_price($products['specials_new_products_price']+$attributes_addon_price, tep_get_tax_rate($products['products_tax_class_id'])) . ' <s><small>' . $currencies->display_price($products['products_price']+$attributes_addon_price, tep_get_tax_rate($products['products_tax_class_id'])) . '</small></s>'; } else { $products_price = $currencies->display_price($products['products_price']+$attributes_addon_price, tep_get_tax_rate($products['products_tax_class_id'])); } $i++; ?> <br /><h4 class="row"><?php echo BOX_TEXT_PRICE;?>: <?php echo $products_price; ?> <?php // echo tep_draw_checkbox_field('add_registry[]',$wishlist['products_id'], true ); ?> </h4> <input name="registry_mode_id" value="<?php echo $registry_mode_id;?>" id="name-data" type="text" class="hidden"/> </dd> <dd class="col-xs-12 " > <h4><?php echo BOX_TEXT_QTY;?> <input type="text" value="<?php echo $wishlist['products_qty'];?>" name="registry_products_quantity" class="qty_box" > </h4> <?php echo $products["categories_name"]; ?> </dd> <?php if($registry_mode_id == 0){ ?> <?php // echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?> <dd class="col-xs-12 " > not login yet </dd> <?php } else { ?> <dd class="col-xs-12 " ><h3> <?php echo tep_draw_hidden_field('products_id', $wishlist['products_id'])?> <input id="submit" type="submit" value="<?php echo BUTTON_ADD_TO_REGISTRY;?>" name="submit" class="btn-warning btn" /></h3> </dd> <?php } ?> </div> </div> </form> <?php } ?> <?php if($registry_mode_id == 0){ ?> <?php // echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?> redirect to registry page <?php } ?> </div> </div> <div class="container"> <?php if ($wishlist_split > 0 && (PREV_NEXT_BAR_LOCATION == '2' || PREV_NEXT_BAR_LOCATION == '3')) { ?> <?php echo $wishlist_split->display_count(TEXT_DISPLAY_NUMBER_OF_WISHLIST); ?> <?php echo TEXT_RESULT_PAGE . ' ' . $wishlist_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?> </div> </div> <?php } } ?> <!-- footer //--> <?php // require(DIR_WS_INCLUDES . 'footer.php'); ?> <!-- footer_eof //--> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?> Any suggestion are welcome. Thanks in advanced. ken
Recommended Posts
Archived
This topic is now archived and is closed to further replies.