Guest Posted August 22, 2006 Share Posted August 22, 2006 Multiple Categories per product quick entry (Download here) This is a cool contribution by the authors Pavel Rojkov, Snowbird and CommLog. The installation instructions can be somewhat confusing, therefore I have updated the instructions and included the code snippets below, just so you can see what the changes should look like. All credits goto the original code writers. case 'insert_product': case 'update_product': // copy image only if modified $products_image = new upload('products_image'); $products_image->set_destination(DIR_FS_CATALOG_IMAGES); if ($products_image->parse() && $products_image->save()) { $products_image_name = $products_image->filename; } else { $products_image_name = (isset($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : ''); } if (isset($HTTP_POST_VARS['edit_x']) || isset($HTTP_POST_VARS['edit_y'])) { 'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id'])); if (isset($products_image_name) && tep_not_null($products_image_name) && ($products_image_name != 'none')) { $sql_data_array['products_image'] = tep_db_prepare_input($products_image_name); } if ($action == 'insert_product') { if ($action == 'insert_product') { $insert_sql_data = array('products_date_added' => 'now()'); $sql_data_array = array_merge($sql_data_array, $insert_sql_data); tep_db_perform(TABLE_PRODUCTS, $sql_data_array); $products_id = tep_db_insert_id(); } elseif ($action == 'update_product') { $update_sql_data = array('products_last_modified' => 'now()'); $sql_data_array = array_merge($sql_data_array, $update_sql_data); tep_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'"); #delete categories saved in the tables tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '". $products_id . "'"); } # create loop here to insert rows for multiple categories $selected_catids = $HTTP_POST_VARS['categories_ids']; if (!$selected_catids) $selected_catids[0] = 0; foreach ($selected_catids as $current_category_id) { tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . $products_id . "', '" . $current_category_id . "')"); } $languages = tep_get_languages(); for ($i=0, $n=sizeof($languages); $i<$n; $i++) { $language_id = $languages[$i]['id']; $manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE)); $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name"); while ($manufacturers = tep_db_fetch_array($manufacturers_query)) { $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'], 'text' => $manufacturers['manufacturers_name']); } # get selected categories $categories_query_selected = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $HTTP_GET_VARS['pID'] . "'"); $categories_array_selected = array(array('id' => '')); while ($categories = tep_db_fetch_array($categories_query_selected)) { $categories_array_selected[] = array('id' => $categories['categories_id']); } $categories_array = array(array('id' => '', 'text' => TEXT_NONE)); #Categories list displays only for one languge (Default is English) $language_id = 1; $categories_array = tep_get_category_tree(); // added by R Calder $form_action = ($HTTP_GET_VARS['pID']) ? 'update_product' : 'insert_product'; $tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE)); //--></script> <?php echo tep_draw_form('new_product', FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $HTTP_GET_VARS['pID'] . '&action='. $form_action, 'post', 'enctype="multipart/form-data"'); ?> <table border="0" width="100%" cellspacing="0" cellpadding="2"> The Imagineer 1 Quote Link to comment Share on other sites More sharing options...
Guest Posted August 22, 2006 Share Posted August 22, 2006 (edited) Once this contribution is installed, simply goto your admin control panel and add a product, when you come to adding the product to a category, to select multiple categories, simply hold down the <CONTROL> Key on your keyboard and select the categories you want the product to appear in. Edited August 22, 2006 by stu2000 The Imagineer 1 Quote Link to comment Share on other sites More sharing options...
pointlessjon Posted September 20, 2006 Share Posted September 20, 2006 (edited) Made a correction to correctly display "Top" as a category... wasn't in the latest version I just downloaded from Aug 22nd. Also, I'm currently working on printing the categories as checkboxes instead of the multi select to be a little more forgiving ;) i'll keep ya posted. In admin/includes/functions/html_output.php file ADD at the end of the file Before " ?>" // Output a form multiple select menu function tep_draw_mselect_menu($name, $values, $selected_vals, $params = '', $required = false) { $field = '<select name="' . $name . '"'; if ($params) $field .= ' ' . $params; $field .= ' multiple>'; for ($i=0; $i<sizeof($values); $i++) { if ($values[$i]['id']) { $field .= '<option value="' . $values[$i]['id'] . '"'; if ( ((strlen($values[$i]['id']) > 0) && ($GLOBALS[$name] == $values[$i]['id'])) ) { $field .= ' SELECTED'; } else { for ($j=0; $j<sizeof($selected_vals); $j++) { if ($selected_vals[$j]['id'] == $values[$i]['id']) { $field .= ' SELECTED'; } } } } else { $field .= '<option value="0"'; } // Added 09/20/06 To correctly offer "Top" as category $field .= '>' . $values[$i]['text'] . '</option>'; } $field .= '</select>'; if ($required) $field .= TEXT_FIELD_REQUIRED; return $field; } ================================= Edited September 20, 2006 by pointlessjon Quote Link to comment Share on other sites More sharing options...
pointlessjon Posted September 20, 2006 Share Posted September 20, 2006 Here we go... // Output a cat select checkbox menu function tep_draw_chbox_cat_menu($name, $values, $selected_vals) { $num_cols = 5; // Specify number of columns here $td_width = ( ( 1 / $num_cols ) * 100); // Auto calculate percentage of width for tds for balance $field = '<table width="100%" cellpadding="10" style="border:1px solid #CCCCCC;">'; // start the table //Cycle through cats and print checkboxes... for ($i=0; $i<sizeof($values); $i++) { if ( ($i % $num_cols) == 0 ) { $field .= '<tr>'; } // Start new table row when appropriate $field .= '<td width="'.$td_width.'%" valign="top" class="main" style="background:#e3e3e3;">'; if ($values[$i]['id']) { $field .= '<input name="' . $name . '" type="checkbox" value="' . $values[$i]['id'] . '"'; if ( ((strlen($values[$i]['id']) > 0) && ($GLOBALS[$name] == $values[$i]['id'])) ) { $field .= ' checked="checked"'; } else { for ($j=0; $j<sizeof($selected_vals); $j++) { if ($selected_vals[$j]['id'] == $values[$i]['id']) { $field .= ' checked="checked"'; } } } } else { $field .= '<input name=' . $name . '" type="checkbox" value="0"'; // print Top as checkbox } $field .= '> ' . $values[$i]['text'] . '</td>'; // print Cat name if ( ($i % $num_cols) == ($num_cols - 1) ) { $field .= '</tr>'; } } $field .= '</table>'; // end the table return $field; } Add that to the bottom of admin/includes/functions/html_output.php and then in admin/categories.php replace: <?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_mselect_menu('categories_ids[]', $categories_array, $categories_array_selected, 'size=10'); ?> with: Select Categories ?<br /> <div id="categoryDiv"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_chbox_cat_menu('categories_ids[]', $categories_array, $categories_array_selected, 'size=10'); ?></div> Quote Link to comment Share on other sites More sharing options...
HSMagic Posted September 21, 2006 Share Posted September 21, 2006 Just wondering why the Preview was eliminated. Is it directly related to the contribution? Also, small problem with the date avail calendar as it writes "under" the menu: Quote Link to comment Share on other sites More sharing options...
pracing Posted November 2, 2006 Share Posted November 2, 2006 Alright, My website has MANY categoris. Which means I have like a million checkboxes.... Any way around this? What I basically want, is the ability toadd one item, to any/all categories I choose. My website will be neatly categorized. Quote Link to comment Share on other sites More sharing options...
Bacoman Posted February 21, 2007 Share Posted February 21, 2007 Alright, My website has MANY categoris. Which means I have like a million checkboxes.... Any way around this? What I basically want, is the ability toadd one item, to any/all categories I choose. My website will be neatly categorized. I have the same problem here... The contri is good, but not for stores with many categories like mine (4000+) I have also another problem: when i copie a product witch is linked by multi categories (done with this contribution), then will the new product not linked on the multi categories, but only on the categorie the product is in at that moment. Quote Link to comment Share on other sites More sharing options...
nextwave Posted March 23, 2007 Share Posted March 23, 2007 Firstly great contrib! Problem im having is when i add a product to say three dif categories, it shows up three times on the whats new page? Even tho they all link to the same product...? can anyone suggest what i should so so it only shows the one product ? no matter how many categories its added to... maybe defaults to the first category it was first added to? or alphabetical would be fine... thanks in advance if anyone can give me some assistance with this! Kym Quote Link to comment Share on other sites More sharing options...
Guest Posted June 1, 2007 Share Posted June 1, 2007 Hi, has anyone else come across a problem with this contribution where the homepage (and all the other pages) of your site goes down after adding products to multiply categories? Its displays a HTTP 500 error, then after about an hour or two the site loads correctly. This is a huge problem as adding products to multiply categories is vital for me, but at the moment customers cannot access my site if I am adding products via admin. If you have come across this please let me know how you overcame it. Thanks, David. Quote Link to comment Share on other sites More sharing options...
carpenoctem Posted June 2, 2007 Share Posted June 2, 2007 This contribution is amazing... it is just what I needed. THANK YOU!!!!!!! I have been trying to figure out a way to do something, using this contribution. Say that I have a product that I am listing in 6 different categories. Is there a way that when I pull up the product, somewhere in or after the description I can have a listing displayed showing all the categories this product is listed in? Any help that can be provided, I would appreciate Mark Quote Link to comment Share on other sites More sharing options...
carpenoctem Posted June 4, 2007 Share Posted June 4, 2007 I do not mean to be rude..... I do not know if anybody was able to review my above question..... Any help you can provide I would appreciate it.... "I have been trying to figure out a way to do something, using this contribution. Say that I have a product that I am listing in 6 different categories. Is there a way that when I pull up the product, somewhere in or after the description I can have a listing displayed showing all the categories this product is listed in?" Thanks Mark Quote Link to comment Share on other sites More sharing options...
awbrys Posted June 19, 2007 Share Posted June 19, 2007 Just wondering why the Preview was eliminated. Is it directly related to the contribution? Hi there Great contribution! Like HSMagic, I am also wondering why the Preview function was eliminated? I've looked through the source code and can't determine why it was removed. Any ideas? I've tried putting it back on, but without success. Would be good to see it in use again. Thanks, Awbrys Quote Link to comment Share on other sites More sharing options...
edmoore1 Posted September 21, 2007 Share Posted September 21, 2007 I've used the older version and am wondering if the new version works with the new version of osCommerce 2.2rc1? Quote Link to comment Share on other sites More sharing options...
Tubbing Posted October 4, 2007 Share Posted October 4, 2007 Slightly off topic the contribution works great, but ive been using it to populate several categories with the one product them change them to suit that exact category. SO my problem is how can i get osc admin orders page to tell me which category did the item come from (all named the same, but are slightly different depending on category :(). Any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
abuelo_12 Posted October 22, 2007 Share Posted October 22, 2007 does any got this to work in RC1. I tried but it gave some problems with uploading pictures. anyone wiling to update this contrib to work with RC1?? Quote Link to comment Share on other sites More sharing options...
nyczip Posted October 29, 2007 Share Posted October 29, 2007 Hi, very nice contrib... but.. someone can help me to integrate with ultapics? actualy don't work, when i try to add o edit a products the utrapics are't visible.. Sorry for my poor english Quote Link to comment Share on other sites More sharing options...
carryG Posted July 16, 2008 Share Posted July 16, 2008 Installed this but am seeing this error: 1062 - Duplicate entry '4880-39' for key 1 insert into products_to_categories (products_id, categories_id) values ('4880', '39') Anyone had this problem before. Ideally, there would be a mod that would use ajax and have categories that would expand into subcats for checking and instant saving in the product edit field. Anyone know of anything like this? Up for the challenge and a donation? :rolleyes: Carry Quote Link to comment Share on other sites More sharing options...
dvharrison Posted January 6, 2009 Share Posted January 6, 2009 My Message is nearly the same 1062 - Duplicate entry '113-34' for key 1 insert into products_to_categories (products_id, categories_id) values ('113', '34') [TEP STOP] I have sent an email using the support email and then saw this thread, but it looks like none of the mods visit this thread anyway. :blink: Quote Debbie Harrison Link to comment Share on other sites More sharing options...
dvharrison Posted January 16, 2009 Share Posted January 16, 2009 (edited) Help I hope there is someone on this forum that can help. I am using the multiple categories at http://addons.oscommerce.com/info/1537 and have finished tying my products up in it. However, now when I add products to the catalog panel, I cannot find them again. Despite me using the drop down tree, they display under Home > product number rather than the sub-category I choose. Example can be found at: http://rocket.unitedhosting.co.uk/~admin34...products_id=850 As further insight I did cancel several products off a couple of weeks ago. as these were duplicates. Would this have affected them? Or is this written in PHP 4 or 5? I hope you can help me as I am truly stumped. i am meant to be training someone to use this next week and may have to cancel it as nothing can be found once added. Please help. i can provide further info if you PM me. Best regards Edited January 16, 2009 by dvharrison Quote Debbie Harrison Link to comment Share on other sites More sharing options...
dvharrison Posted January 20, 2009 Share Posted January 20, 2009 Forget it I uninstalled it. Quote Debbie Harrison Link to comment Share on other sites More sharing options...
PiLLaO Posted February 4, 2009 Share Posted February 4, 2009 Great Contribution It doesn't works correctly on osCommerce 2.2 rc 2a On a existyng product it works perfectly, but when you try to add a new product... the product is not added. Regards! Quote Link to comment Share on other sites More sharing options...
PiLLaO Posted February 4, 2009 Share Posted February 4, 2009 Great Contribution It doesn't works correctly on osCommerce 2.2 rc 2a On a existyng product it works perfectly, but when you try to add a new product... the product is not added. Regards! I Can't edit my previous post... the contribution works perfectly, I haven't installa correctly :blush: Regards! Quote Link to comment Share on other sites More sharing options...
n9er Posted February 11, 2010 Share Posted February 11, 2010 how to make this Multiple "manufacturers" per product quick entry, so that one item have many manufacturers Quote Link to comment Share on other sites More sharing options...
The Imagineer Posted February 11, 2010 Share Posted February 11, 2010 Excellent contribution, May I ask a question? Does this add-on give a parent - child - child - child search facility? For example I am building a parts business for motor vehicles and I want to have the client choose vehicle make, model, engine type and year. I can´t seem to find a solution on os commerce. Perhaps you can enlighten me? Thanks vadivelu 1 Quote Link to comment Share on other sites More sharing options...
vadivelu Posted May 7, 2010 Share Posted May 7, 2010 Excellent Contribution, I have added one product in multiple category, but i want to give sorting position for the product in each category, but sort position should be different for different category. could any one help me for this. Thanks 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.