jhande Posted July 22, 2010 Posted July 22, 2010 I'm trying to add a feature - "discontinued" so that from the admin side I can tag which products will shortly no longer be available. I tried basing it on the product_status code. I added a new field to the products table - "products_discontinued" with the same values as the products_status field. I searched through the categories.php file for every instance of products_status and copied\edited for products_discontinued. But I messed something up REALLY, REALLY bad. I got the feature to showup just fine, but it made a mess of the product status feature. Here's a brief rundown on the edited bits of code: $sql_data_array = array('products_quantity' => tep_db_prepare_input($HTTP_POST_VARS['products_quantity']), 'products_model' => tep_db_prepare_input($HTTP_POST_VARS['products_model']), 'products_price' => tep_db_prepare_input($HTTP_POST_VARS['products_price']), 'products_date_available' => $products_date_available, 'products_weight' => tep_db_prepare_input($HTTP_POST_VARS['products_weight']), 'products_status' => tep_db_prepare_input($HTTP_POST_VARS['products_status']), 'products_discontinued' => tep_db_prepare_input($HTTP_POST_VARS['products_discontinued']), 'products_tax_class_id' => tep_db_prepare_input($HTTP_POST_VARS['products_tax_class_id']), 'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id'])); tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model, products_image, products_bimage, products_price, products_date_added, products_date_available, products_weight, products_status, products_discontinued, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '". tep_db_input($product['products_bimage']) . "', '". tep_db_input($product['products_price']) . "', now(), " . (empty($product['products_date_available']) ? "null" : "'" . tep_db_input($product['products_date_available']) . "'") . ", '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')"); if ($action == 'new_product') { $parameters = array('products_name' => '', 'products_description' => '', 'short_desc' => '', 'products_url' => '', 'products_id' => '', 'products_quantity' => '', 'products_model' => '', 'products_image' => '', 'products_price' => '', 'products_weight' => '', 'products_date_added' => '', 'products_last_modified' => '', 'products_date_available' => '', 'products_status' => '', 'products_discontinued' => '', 'products_tax_class_id' => '', 'manufacturers_id' => ''); /*** Begin Header Tags SEO ***/ $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_head_title_tag, pd.products_head_desc_tag, pd.products_head_keywords_tag, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, pd.short_desc, p.products_bimage, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%m-%d-%Y') as products_date_available, p.products_status, p.products_discontinued, p.products_tax_class_id, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'"); $product = tep_db_fetch_array($product_query); /*** End Header Tags SEO ***/ This "might" be the problem?? $languages = tep_get_languages(); if (!isset($pInfo->products_status)) $pInfo->products_status = '1'; switch ($pInfo->products_status) { case '0': $in_status = false; $out_status = true; break; case '1': default: $in_status = true; $out_status = false; } if (!isset($pInfo->products_discontinued)) $pInfo->products_discontinued = '1'; switch ($pInfo->products_discontinued) { case '0': $in_status = false; $out_status = true; break; case '1': default: $in_status = true; $out_status = false; } ?> <tr> <td class="main"><?php echo TEXT_PRODUCTS_STATUS; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_status', '1', $in_status) . ' ' . TEXT_PRODUCT_AVAILABLE . ' ' . tep_draw_radio_field('products_status', '0', $out_status) . ' ' . TEXT_PRODUCT_NOT_AVAILABLE; ?></td> </tr> <tr> <td class="main"><?php echo TEXT_PRODUCTS_DISCONTINUED; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_discontinued', '1', $in_status) . ' ' . TEXT_PRODUCT_DISCONTINUED . ' ' . tep_draw_radio_field('products_discontinued', '0', $out_status) . ' ' . TEXT_PRODUCT_NOT_DISCONTINUED; ?></td> </tr> $product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_head_title_tag, pd.products_head_desc_tag, pd.products_head_keywords_tag, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_bimage, pd.short_desc, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_discontinued, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'"); $products_query = tep_db_query("select p.products_model, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_bimage, pd.short_desc, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_discontinued, p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and pd.products_name like '%" . tep_db_input($search) . "%' order by p.products_model"); $products_query = tep_db_query("select p.products_model, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_bimage, pd.short_desc, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_discontinued from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by p.products_model"); <td class="dataTableContent" align="center"> <?php if ($products['products_discontinued'] == '1') { echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=0&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>'; } else { echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=1&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a> ' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10); } ?> </td> <td class="dataTableContent" align="center"> <?php if ($products['products_status'] == '1') { echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=0&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>'; } else { echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=1&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a> ' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10); } ?> </td> I sure hope someone can help me spot my OOP'S. I would like to make a similar feature to show "sold" if I can get this one to work. I'd really, really appreciate some help with this before I try moving to the catalog side. - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
MrPhil Posted July 22, 2010 Posted July 22, 2010 You seem to be missing the VALUE for 'discontinued' on your INSERT INTO the products table (second code block). I would think you would get a MySQL error message, as you have 12 fields listed but only 11 values.
jhande Posted July 22, 2010 Author Posted July 22, 2010 Thanks for the reply Phil. I'm a little stumped with that one, maybe I'm missing it. I don't see anything there for the product_status in the second part of the code. I tried to base it on the same code but obviously I really don't know what I'm doing. I'll take a guess, is this the VALUE for product_status = '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', So would I then change it to? = '" . tep_db_input($product['products_weight']) . "', '0', "' . "', '0', '" . (int)$product['products_tax_class_id'] . "', EDIT: No error messages. Maybe because I am testing it on my localhost (PC) under XAMPP? - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted July 22, 2010 Author Posted July 22, 2010 Maybe an explaination of what's also going on might help... On this page nothing changes when I click either of the Discontinued radio buttons. Also I would assume it should have defaulted to green (not discontinued). :: Below :: Clicking on Product Status: In Stock reverts back to Out of Stock. But clicking either for Discontinued will reload with the proper radio button selected. BUT it will not change on the above page. - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted July 22, 2010 Author Posted July 22, 2010 Well... I made a little bit of headway. I changed this: tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model, products_image, products_bimage, products_price, products_date_added, products_date_available, products_weight, products_status, products_discontinued, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '". tep_db_input($product['products_bimage']) . "', '". tep_db_input($product['products_price']) . "', now(), " . (empty($product['products_date_available']) ? "null" : "'" . tep_db_input($product['products_date_available']) . "'") . ", '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')"); To this: tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model, products_image, products_bimage, products_price, products_date_added, products_date_available, products_weight, products_status, products_discontinued, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '". tep_db_input($product['products_bimage']) . "', '". tep_db_input($product['products_price']) . "', now(), " . (empty($product['products_date_available']) ? "null" : "'" . tep_db_input($product['products_date_available']) . "'") . ", '" . tep_db_input($product['products_weight']) . "', '0', '" . "', '". tep_db_input($product['products_discontinued']) . "', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')"); Changed this: $languages = tep_get_languages(); if (!isset($pInfo->products_status)) $pInfo->products_status = '1'; switch ($pInfo->products_status) { case '0': $in_status = false; $out_status = true; break; case '1': default: $in_status = true; $out_status = false; } if (!isset($pInfo->products_discontinued)) $pInfo->products_discontinued = '1'; switch ($pInfo->products_discontinued) { case '0': $in_status = false; $out_status = true; break; case '1': default: $in_status = true; $out_status = false; } ?> To this: if (!isset($pInfo->products_status)) $pInfo->products_status = '1'; switch ($pInfo->products_status) { case '0': $in_status = false; $out_status = true; break; case '1': default: $in_status = true; $out_status = false; } if (!isset($pInfo->products_discontinued)) $pInfo->products_discontinued = '1'; switch ($pInfo->products_discontinued) { case '0': $in_discontinued = false; $out_discontinued = true; break; case '1': default: $in_discontinued = true; $out_discontinued = false; } ?> Now changing the values on the product info page works and also shows correctly on the Categories / Products page. But nothing happens still when trying to change the discontinued value on the Categories / Products page. - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
MrPhil Posted July 22, 2010 Posted July 22, 2010 A bit messy in the VALUES section, i.e., products_weight']) . "', '0', '" . "', '". tep_db_input($product['products_discontinued']) so you end up with ...123', '0', '', 'avail'... So, you have 13 values for 12 fields. "', '0', '" . "', '" collapses into "', '0', '', '" and probably are putting the wrong value in one or more fields.
jhande Posted July 23, 2010 Author Posted July 23, 2010 Thanks again Phil Ok, I cleaned that mess up, it is now: . tep_db_input($product['products_weight']) . "', '0', '" . tep_db_input($product['products_discontinued']) . "', '" . I am not sure where or at what else to look at. It works if I change the values on the product info page, but nothing happens on the categories page. - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted July 23, 2010 Author Posted July 23, 2010 Ok, I'm making a bigger mess and still getting nowhere. I found this in admin\includes\functions\general.php // Sets the status of a product function tep_set_product_status($products_id, $status) { if ($status == '1') { return tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '1', products_last_modified = now() where products_id = '" . (int)$products_id . "'"); } elseif ($status == '0') { return tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0', products_last_modified = now() where products_id = '" . (int)$products_id . "'"); } else { return -1; } } //// So I added this // Sets the discontinued of a product function tep_set_product_discontinued($products_id, $status) { if ($status == '1') { return tep_db_query("update " . TABLE_PRODUCTS . " set products_discontinued = '1', products_last_modified = now() where products_id = '" . (int)$products_id . "'"); } elseif ($status == '0') { return tep_db_query("update " . TABLE_PRODUCTS . " set products_discontinued = '0', products_last_modified = now() where products_id = '" . (int)$products_id . "'"); } else { return -1; } } //// Anyone? Any ideas?? Thoughts??? Please HELP... - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted July 25, 2010 Author Posted July 25, 2010 Now changing the values on the product info page works and also shows correctly on the Categories / Products page. But nothing happens still when trying to change the discontinued value on the Categories / Products page. Oop's... Actually when I try to change the products discontinued value from the Categories / Products page, it changes the product status to the opposite of whatever it was set at. It's ok having the feature working from the product info page, but it sure would be great having it work on the Categories / Products page. If I could get it to work there, I'd like to add it to a contribution page I installed - Quick Stock Update. Would it help if I posted my entire categories.php file code? It seems as if I am just a little bit of code off my mark. - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
MrPhil Posted July 31, 2010 Posted July 31, 2010 Sorry, been away for a week. So, do you think you messed up something in the admin/categories.php file? Since this is custom code, I could take a quick look at it -- since the vanilla version is 1035 lines long, do you think you could trim it down to the section(s) you changed? I just hate wading through page after page of mostly unchanged code. Please use [ code ] tags around each section of the file you post, and include enough unchanged code at the beginning and end of each section that I can correlate it to a vanilla version. Do you have any add-ons applied that hit this file? Finally, please be very specific about what has gone wrong, so (hopefully) I can see what happened just by looking at the code, and not having to actually run it.
jhande Posted August 1, 2010 Author Posted August 1, 2010 Hi again Phil, Thank you for following along with me on this. I had posted above only the sections of code that I edited but I do have a few hacks added to the file. I just found a clean copy of the original file, so I will attempt to play with that. I'm going to attempt this again from scratch. I think my problems lie in the use of the "product_status" code. It seems to be integrated into other files for reasons I don't need. All I need is a way to activate either a text message or preferably an image on the product_info and product_listing page that an item is being discontinued. I have been searching the internet for "PHP and radio button" examples. They seem less complicated than what I have tried unsuccessfully so far. I have used different form inputs with straight HTML coding, I just have to get my head around the PHP part of it. I'm not sure if my naming convention is going to throw a wrench into the works or not? Here's what I am starting with: In my database I added a field (column) to the "products" table called "products_discontinued". Field = products_discontinued, Type = tinyint(1), Null = No, Default = 0. I want the Default value of 0 to equal and be preselected as being not discontined. I want radio buttons on the admin side (similar to the Status buttons) so I can click one to change the value of products_discontinued to 1. Where the value one gets called on the catalog side to display (let's say) an image - "Discontinued - Limited Stock". Once the bossy... I me boss... uhm wife leaves me alone tonight I'll try playing with some coding. I'll post back what happens. Again, thank you Phip for hanging in there with me, I truely appreciate it!!! - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
MrPhil Posted August 2, 2010 Posted August 2, 2010 So 0 is not discontinued, and 1 is? Your products will be "not" discontinued by default. To make a radio button selection, you could have something like Discontinued: <input type="radio" name="discontinued" value="1" <?php echo $product_disc? 'checked="checked"': ''; ?> />Discontinued <input type="radio" name="discontinued" value="0" <?php echo $product_disc? '': 'checked="checked"'; ?> />Not discontinued<br/> where $product_disc is 0 or 1, read out of the database along with the rest of the product data.
jhande Posted August 3, 2010 Author Posted August 3, 2010 Thanks Phil I have that code working on the product_info page but I still need to work on it for the Categories / Products page. - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted August 4, 2010 Author Posted August 4, 2010 Ok, that code didn't work well. This code works: <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_discontinued', '0') . ' ' . TEXT_PRODUCT_NOT_DISCONTINUED . ' ' . tep_draw_radio_field('products_discontinued', '1') . ' ' . TEXT_PRODUCT_DISCONTINUED; ?></td> Except for one problem... It does not display the current value. In other words, neither radio button is ticked when loading the product info page. Any idea how I can get it to display the current value (having a radio button already ticked)? This works on the Categories / Products page to show me the current value: <td class="dataTableContent" align="center"><?php if ($products['products_discontinued'] == '0') { echo tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_LTGREEN, 10, 10); } else { if ($products['products_discontinued'] == '1') echo tep_image(DIR_WS_IMAGES . 'icon_status_yellow.gif', IMAGE_ICON_STATUS_YELLOW_LIGHT, 10, 10); } ?> </td> - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
MrPhil Posted August 5, 2010 Posted August 5, 2010 <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_discontinued', '0') . ' ' . TEXT_PRODUCT_NOT_DISCONTINUED . ' ' . tep_draw_radio_field('products_discontinued', '1') . ' ' . TEXT_PRODUCT_DISCONTINUED; ?></td> draws all buttons unchecked. If you look at the function definition in includes/functions/html_output.php, you'll see that you have to give a third parameter true for the choice which should be preselected. Something like <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_discontinued', '0', $products['products_discontinued']=='0') . ' ' . TEXT_PRODUCT_NOT_DISCONTINUED . ' ' . tep_draw_radio_field('products_discontinued', '1', $products['products_discontinued']=='1') . ' ' . TEXT_PRODUCT_DISCONTINUED; ?></td> Why are you testing twice? If $products['products_discontinued'] can have only a value of 0 or 1 (or is it '0' or '1'?), wouldn't you use <td class="dataTableContent" align="center"><?php if ($products['products_discontinued'] == '0') { // NOT discontinued echo tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_LTGREEN, 10, 10); } else { // IS discontinued echo tep_image(DIR_WS_IMAGES . 'icon_status_yellow.gif', IMAGE_ICON_STATUS_YELLOW_LIGHT, 10, 10); } ?></td>
jhande Posted August 5, 2010 Author Posted August 5, 2010 Thank you so much Phil for hanging in there with me. I am really trying to understand PHP but it is slow going... If you look at the function definition in includes/functions/html_output.php, you'll see that you have to give a third parameter true for the choice which should be preselected. Something like <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_discontinued', '0', $products['products_discontinued']=='0') . ' ' . TEXT_PRODUCT_NOT_DISCONTINUED . ' ' . tep_draw_radio_field('products_discontinued', '1', $products['products_discontinued']=='1') . ' ' . TEXT_PRODUCT_DISCONTINUED; ?></td> I am a little confussed... I used the code above, looked at the html_output.php file but still don't know what I need to change so that the radio button shows preselected based on the database value. It is still not showing as checked. What, where and how do I give the third parameter of TRUE? Why are you testing twice? If $products['products_discontinued'] can have only a value of 0 or 1 (or is it '0' or '1'?), wouldn't you use <td class="dataTableContent" align="center"><?php if ($products['products_discontinued'] == '0') { // NOT discontinued echo tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_LTGREEN, 10, 10); } else { // IS discontinued echo tep_image(DIR_WS_IMAGES . 'icon_status_yellow.gif', IMAGE_ICON_STATUS_YELLOW_LIGHT, 10, 10); } ?></td> I didn't realize I was testing twice. - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
burt Posted August 5, 2010 Posted August 5, 2010 Jim take a look at my "clubosc" featured products mod - it's in the contributions area. This uses similar code to the status radio button, but will give you an idea of where you have gone wrong. G
MrPhil Posted August 5, 2010 Posted August 5, 2010 I am a little confussed... I used the code above, looked at the html_output.php file but still don't know what I need to change so that the radio button shows preselected based on the database value. The current value of the setting is presumed to be in $products['products_discontinued'], as read from the database, and having a value of '0' (not discontinued) or '1' (discontinued). $products['products_discontinued']=='0' would give a true if the value is '0', false otherwise. Similar, roles reversed, for the other.
jhande Posted August 5, 2010 Author Posted August 5, 2010 The current value of the setting is presumed to be in $products['products_discontinued'], as read from the database, and having a value of '0' (not discontinued) or '1' (discontinued). $products['products_discontinued']=='0' would give a true if the value is '0', false otherwise. Similar, roles reversed, for the other. Thank you Phil for explaining that bit of code. Wondering why then nothing is pre-clicked??? - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted August 5, 2010 Author Posted August 5, 2010 Jim take a look at my "clubosc" featured products mod - it's in the contributions area. This uses similar code to the status radio button, but will give you an idea of where you have gone wrong. G Thanks Gary, I will look through it tonight. Rain stopped, have to replace a ball joint and wheel bearing in the wifes car. -- EDIT-- Just seen the post at Club osC about Chemo. Sad, very sad... - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted August 5, 2010 Author Posted August 5, 2010 Part 1 Ok, I am getting nowhere fast... Compared your code Burt and made all changes, double checked, triple checked. I even played around with the edit I made to includes\functions\general.php (which actually made a little difference). // Sets the discontinued availability of a product function tep_set_product_discontinued($products_id, $status) { if ($status == '0') { return tep_db_query("update " . TABLE_PRODUCTS . " set products_discontinued = '0', products_last_modified = now() where products_id = '" . (int)$products_id . "'"); } elseif ($status == '1') { return tep_db_query("update " . TABLE_PRODUCTS . " set products_discontinued = '1', products_last_modified = now() where products_id = '" . (int)$products_id . "'"); } else { return -1; } } //// Referring to the pic: If I change the values in the above code, I can click on one of the "Availability" options and it will change. But I can't change it back. Still not showing (tick selected) the default value, or any value I pick for the "Availability". It does however change the value in the database and the icons on the above Categories / Products page. See Part 2 - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted August 5, 2010 Author Posted August 5, 2010 Part 2: WOW, file to large to post. Well then, here's sections I edited in my admin\categories.php file. Changed this: if (tep_not_null($action)) { switch ($action) { case 'setflag': if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) { if (isset($HTTP_GET_VARS['pID'])) { tep_set_product_status($HTTP_GET_VARS['pID'], $HTTP_GET_VARS['flag']); } if (USE_CACHE == 'true') { tep_reset_cache_block('categories'); tep_reset_cache_block('also_purchased'); } } tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $HTTP_GET_VARS['cPath'] . '&pID=' . $HTTP_GET_VARS['pID'])); break; To this: if (tep_not_null($action)) { switch ($action) { case 'setflag': if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) { if (isset($HTTP_GET_VARS['pID'])) { tep_set_product_status($HTTP_GET_VARS['pID'], $HTTP_GET_VARS['flag']); } if (USE_CACHE == 'true') { tep_reset_cache_block('categories'); tep_reset_cache_block('also_purchased'); } } tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $HTTP_GET_VARS['cPath'] . '&pID=' . $HTTP_GET_VARS['pID'])); break; case 'setdiscontinued': if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) { if (isset($HTTP_GET_VARS['pID'])) { tep_set_product_discontinued($HTTP_GET_VARS['pID'], $HTTP_GET_VARS['flag']); } if (USE_CACHE == 'true') { tep_reset_cache_block('categories'); tep_reset_cache_block('also_purchased'); } } tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $HTTP_GET_VARS['cPath'] . '&pID=' . $HTTP_GET_VARS['pID'])); break; Changed this: $sql_data_array = array('products_quantity' => tep_db_prepare_input($HTTP_POST_VARS['products_quantity']), 'products_model' => tep_db_prepare_input($HTTP_POST_VARS['products_model']), 'products_price' => tep_db_prepare_input($HTTP_POST_VARS['products_price']), 'products_date_available' => $products_date_available, 'products_weight' => tep_db_prepare_input($HTTP_POST_VARS['products_weight']), 'products_status' => tep_db_prepare_input($HTTP_POST_VARS['products_status']), 'products_tax_class_id' => tep_db_prepare_input($HTTP_POST_VARS['products_tax_class_id']), 'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id'])); To this: $sql_data_array = array('products_quantity' => tep_db_prepare_input($HTTP_POST_VARS['products_quantity']), 'products_model' => tep_db_prepare_input($HTTP_POST_VARS['products_model']), 'products_price' => tep_db_prepare_input($HTTP_POST_VARS['products_price']), 'products_date_available' => $products_date_available, 'products_weight' => tep_db_prepare_input($HTTP_POST_VARS['products_weight']), 'products_status' => tep_db_prepare_input($HTTP_POST_VARS['products_status']), 'products_discontinued' => tep_db_prepare_input($HTTP_POST_VARS['products_discontinued']), 'products_tax_class_id' => tep_db_prepare_input($HTTP_POST_VARS['products_tax_class_id']), 'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id'])); Changed this: ##added big products image tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model, products_image, products_bimage, products_price, products_date_added, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '". tep_db_input($product['products_bimage']) . "', '". tep_db_input($product['products_price']) . "', now(), " . (empty($product['products_date_available']) ? "null" : "'" . tep_db_input($product['products_date_available']) . "'") . ", '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')"); ###### To this: ##added big products image tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model, products_image, products_bimage, products_price, products_date_added, products_date_available, products_weight, products_status, products_discontinued, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_discontinued']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '". tep_db_input($product['products_bimage']) . "', '". tep_db_input($product['products_price']) . "', now(), " . (empty($product['products_date_available']) ? "null" : "'" . tep_db_input($product['products_date_available']) . "'") . ", '" . tep_db_input($product['products_weight']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "')"); ###### Changed this: if ($action == 'new_product') { $parameters = array('products_name' => '', 'products_description' => '', 'short_desc' => '', 'products_url' => '', 'products_id' => '', 'products_quantity' => '', 'products_model' => '', 'products_image' => '', 'products_price' => '', 'products_weight' => '', 'products_date_added' => '', 'products_last_modified' => '', 'products_date_available' => '', 'products_status' => '', 'products_tax_class_id' => '', 'manufacturers_id' => ''); To this: if ($action == 'new_product') { $parameters = array('products_name' => '', 'products_description' => '', 'short_desc' => '', 'products_url' => '', 'products_id' => '', 'products_quantity' => '', 'products_model' => '', 'products_image' => '', 'products_price' => '', 'products_weight' => '', 'products_date_added' => '', 'products_last_modified' => '', 'products_date_available' => '', 'products_status' => '', 'products_discontinued' => '', 'products_tax_class_id' => '', 'manufacturers_id' => ''); Changed this: $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_head_title_tag, pd.products_head_desc_tag, pd.products_head_keywords_tag, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, pd.short_desc, p.products_bimage, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%m-%d-%Y') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'"); $product = tep_db_fetch_array($product_query); To this: $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_head_title_tag, pd.products_head_desc_tag, pd.products_head_keywords_tag, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, pd.short_desc, p.products_bimage, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%m-%d-%Y') as products_date_available, p.products_status, p.products_discontinued, p.products_tax_class_id, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'"); $product = tep_db_fetch_array($product_query); Changed this: $languages = tep_get_languages(); if (!isset($pInfo->products_status)) $pInfo->products_status = '1'; switch ($pInfo->products_status) { case '0': $in_status = false; $out_status = true; break; case '1': default: $in_status = true; $out_status = false; } ?> To this: $languages = tep_get_languages(); if (!isset($pInfo->products_status)) $pInfo->products_status = '1'; switch ($pInfo->products_status) { case '0': $in_status = false; $out_status = true; break; case '1': default: $in_status = true; $out_status = false; } if (!isset($pInfo->products_discontinued)) $pInfo->products_discontinued = '0'; switch ($pInfo->products_discontinued) { case '1': $in_discontinued = false; $out_discontinued = true; break; case '0': default: $in_discontinued = true; $out_discontinued = false; } ?> Changed this: <tr> <td class="main"><?php echo TEXT_PRODUCTS_STATUS; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_status', '1', $in_status) . ' ' . TEXT_PRODUCT_AVAILABLE . ' ' . tep_draw_radio_field('products_status', '0', $out_status) . ' ' . TEXT_PRODUCT_NOT_AVAILABLE; ?></td> </tr> To this: <tr> <td class="main"><?php echo TEXT_PRODUCTS_STATUS; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_status', '1', $in_status) . ' ' . TEXT_PRODUCT_AVAILABLE . ' ' . tep_draw_radio_field('products_status', '0', $out_status) . ' ' . TEXT_PRODUCT_NOT_AVAILABLE; ?></td> </tr> <tr> <td class="main"><?php echo TEXT_PRODUCTS_DISCONTINUED; ?></td> <td class="main"> <?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_discontinued', '0', $in_featured) . ' ' . TEXT_PRODUCT_NOT_DISCONTINUED . ' ' . tep_draw_radio_field('products_discontinued', '1', $out_featured) . ' ' . TEXT_PRODUCT_DISCONTINUED; ?> </td> </tr> Changed this: $product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_head_title_tag, pd.products_head_desc_tag, pd.products_head_keywords_tag, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_bimage, pd.short_desc, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'"); To this: $product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_head_title_tag, pd.products_head_desc_tag, pd.products_head_keywords_tag, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_bimage, pd.short_desc, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_discontinued, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'"); Changed this: <tr class="dataTableHeadingRow"> <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CATEGORIES_PRODUCTS; ?></td> <!-- Added below --> <td class="dataTableHeadingContent" align="center"><?php echo "Model #" ?></td> <!-- End Add --> <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_STATUS; ?></td> <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?> </td> </tr> To this: <tr class="dataTableHeadingRow"> <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CATEGORIES_PRODUCTS; ?></td> <!-- Added below --> <td class="dataTableHeadingContent" align="center"><?php echo "Model #" ?></td> <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_DISCONTINUED; ?></td> <!-- End Add --> <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_STATUS; ?></td> <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?> </td> </tr> Changed this: $products_query = tep_db_query("select p.products_model, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_bimage, pd.short_desc, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and pd.products_name like '%" . tep_db_input($search) . "%' order by p.products_model"); To this: $products_query = tep_db_query("select p.products_model, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_bimage, pd.short_desc, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_discontinued, p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and pd.products_name like '%" . tep_db_input($search) . "%' order by p.products_model"); Changed this: $products_query = tep_db_query("select p.products_model, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_bimage, pd.short_desc, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by p.products_model"); To this: $products_query = tep_db_query("select p.products_model, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_bimage, pd.short_desc, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_discontinued from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by p.products_model"); Changed this: <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id'] . '&action=new_product_preview&read=only') . '">' . tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a> ' . $products['products_name']; ?></td> <td class="dataTableContent" align="center"><?php echo '[' . $products['products_model'] . ']'; ?></td> <td class="dataTableContent" align="center"> <?php if ($products['products_status'] == '1') { echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=0&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>'; } else { echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=1&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a> ' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10); } ?></td> To this: <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $products['products_id'] . '&action=new_product_preview&read=only') . '">' . tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a> ' . $products['products_name']; ?></td> <td class="dataTableContent" align="center"><?php echo '[' . $products['products_model'] . ']'; ?></td> <td class="dataTableContent" align="center"> <?php if ($products['products_discontinued'] == '0') { echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_LTGREEN, 10, 10) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setdiscontinued&flag=1&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_YELLOW_LIGHT, 10, 10) . '</a>'; } else { echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setdiscontinued&flag=1&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_LTGREEN, 10, 10) . '</a> ' . tep_image(DIR_WS_IMAGES . 'icon_status_yellow.gif', IMAGE_ICON_STATUS_YELLOW_LIGHT, 10, 10); } ?></td> <td class="dataTableContent" align="center"> <?php if ($products['products_status'] == '1') { echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . ' <a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=0&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>'; } else { echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&flag=1&pID=' . $products['products_id'] . '&cPath=' . $cPath) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a> ' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10); } ?></td> Hopefully someone can spot whatever I missed... ??? Off to the lake for a quick dip... - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted August 8, 2010 Author Posted August 8, 2010 Ok, I actually accomplished something in the right direction. All the buttons work! Just one little thing that's bugging me... The radio buttons on the product info page still don't show as pre-selected. Any ideas on how to fix that would greatly be appreciated!!! Thanks Burt for pointing me towards your contribution with the code I needed. Thanks Phil for helping me along this far. I truely appreciate your help. - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
jhande Posted August 8, 2010 Author Posted August 8, 2010 One more problem. When I used this code to check quantity and display the Discontinued image on the catalog product info page it worked. Now that I want it to check the value (1) for products_discontinued it doesn't. case 'PRODUCT_LIST_MODEL': $lc_align = 'center'; $lc_width = '85px'; $lc_text = ' ' . $listing['products_model'] . ' <br>'; if (1 == $listing['products_discontinued']) { $lc_text .= tep_image(DIR_WS_IMAGES . 'discontinuedSM.gif'); } break; - :: Jim :: - - My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -
MrPhil Posted August 8, 2010 Posted August 8, 2010 Have you confirmed that $listing['products_discontinued'] contains the expected value? I should think that 1 and '1' should be interchangeable, but perhaps they're not for some reason. Are you getting any error messages (that you used l instead of 1?). If the value is a string '0' or '1', try using that in the test. So, what happens when it "doesn't work"? Are you able to click the radio button, but the value isn't "taking"? Probably you didn't properly update the database with the new value, would be my best guess.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.