Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

In Stock Filter


FlorinRO

Recommended Posts

Hello,

 

I need an "In stock" filter, i have tried this one: http://www.oscommerce.com/community/contributions,2805/page,2 but it doesn't work.

 

I have Os Commerce v2.2 RC2 with KissMT Dynamic SEO Meta & Canonical Header Tags (http://addons.oscommerce.com/info/7199) and an "Multi Image" addon.

 

Thank you.

I used the same one and had to make a few changes to the code. Did not keep a record of the changes. There is no reason why you should not be able to get it to work with those add ons.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Onestly, i could't find in my files all the code that was indicated in the instructions (some pieces where a little bit different), i supose the addon was made for another version of OSC...

 

Do you remember what changes had you made to the code to make it work?

Link to comment
Share on other sites

Here is ALL the code from /catalog/index.php from the first edit to the end of the {} block. Maybe you can pull out what you need...

 



// begin isstock
if (isset($HTTP_GET_VARS['instock']))
     {
     $listing_sql .= " and p.products_quantity > 0";
     }
// end isstock


   if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('^[1-8][ad]$', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
     for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
       if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
         $HTTP_GET_VARS['sort'] = $i+1 . 'a';
         $listing_sql .= " order by pd.products_name";
         break;
       }
     }
   } else {
     $sort_col = substr($HTTP_GET_VARS['sort'], 0 , 1);
     $sort_order = substr($HTTP_GET_VARS['sort'], 1);

     switch ($column_list[$sort_col-1]) {
       case 'PRODUCT_LIST_MODEL':
         $listing_sql .= " order by p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_NAME':
         $listing_sql .= " order by pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
         break;
       case 'PRODUCT_LIST_MANUFACTURER':
         $listing_sql .= " order by m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_QUANTITY':
         $listing_sql .= " order by p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_IMAGE':
         $listing_sql .= " order by pd.products_name";
         break;
       case 'PRODUCT_LIST_WEIGHT':
         $listing_sql .= " order by p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_PRICE':
         $listing_sql .= " order by final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
     }
   }
   /*** Begin Header Tags SEO ***/
   if (isset($HTTP_GET_VARS['manufacturers_id']))
     $db_query = tep_db_query("select manufacturers_htc_title_tag as htc_title, manufacturers_htc_description as htc_description from " . TABLE_MANUFACTURERS_INFO . " where languages_id = '" . (int)$languages_id . "' and manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'");
   else
     $db_query = tep_db_query("select categories_htc_title_tag as htc_title, categories_htc_description as htc_description from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$current_category_id . "' and language_id = '" . (int)$languages_id . "'");

   $htc = tep_db_fetch_array($db_query);

?>
   <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
           <td><h1><?php echo $htc['htc_title']; ?></h1></td>
   <?php /*** End Header Tags SEO ***/ ?>
<?php
// optional Product List Filter
   if (PRODUCT_LIST_FILTER > 0) {
     if (isset($HTTP_GET_VARS['manufacturers_id'])) {
       $filterlist_sql = "select distinct c.categories_id as id, cd.categories_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where p.products_status = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p2c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' order by cd.categories_name";
     } else {
       $filterlist_sql= "select distinct m.manufacturers_id as id, m.manufacturers_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by m.manufacturers_name";
     }
     $filterlist_query = tep_db_query($filterlist_sql);
     if (tep_db_num_rows($filterlist_query) > 1) {
       echo '            <td align="center" class="main">' . tep_draw_form('filter', FILENAME_DEFAULT, 'get') . TEXT_SHOW . ' ';
       if (isset($HTTP_GET_VARS['manufacturers_id'])) {
         echo tep_draw_hidden_field('manufacturers_id', $HTTP_GET_VARS['manufacturers_id']);
         $options = array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES));
       } else {
         echo tep_draw_hidden_field('cPath', $cPath);
         $options = array(array('id' => '', 'text' => TEXT_ALL_MANUFACTURERS));
       }


// begin isstock
echo  tep_draw_checkbox_field('instock', 1, false, 'onClick="this.form.submit()"') . HEADER_INSTOCK . '<BR>' . "\n";
// end isstock


       echo tep_draw_hidden_field('sort', $HTTP_GET_VARS['sort']);
       while ($filterlist = tep_db_fetch_array($filterlist_query)) {
         $options[] = array('id' => $filterlist['id'], 'text' => $filterlist['name']);
       }
       echo "<B>By manufacturer: </b>" . tep_draw_pull_down_menu('filter_id', $options, (isset($HTTP_GET_VARS['filter_id']) ? $HTTP_GET_VARS['filter_id'] : ''), 'onchange="this.form.submit()"');
       echo tep_hide_session_id() . '</form></td>' . "\n";
     }
   }

// Get the right image for the top-right
   $image = DIR_WS_IMAGES . 'table_background_list.gif';
   if (isset($HTTP_GET_VARS['manufacturers_id'])) {
     $image = tep_db_query("select manufacturers_image from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'");
     $image = tep_db_fetch_array($image);
     $image = $image['manufacturers_image'];
   } elseif ($current_category_id) {
     $image = tep_db_query("select categories_image from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
     $image = tep_db_fetch_array($image);
     $image = $image['categories_image'];
   }
?>
           <td align="right"><?php echo tep_image(DIR_WS_IMAGES . $image, HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
         </tr>
         <?php /*** Begin Header Tags SEO ***/ ?>
          <td align="right"><?php echo tep_image(DIR_WS_IMAGES . $image, $htc['htc_title'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
         </tr>
         <?php if (tep_not_null($htc['htc_description'])) { ?>
         <tr>
          <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
         </tr>
         <tr>
          <td colspan="2"><h2><?php echo $htc['htc_description']; ?></h2></td>
         </tr>
         <?php } 
         /*** End Header Tags SEO ***/ 
         ?>
       </table></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td><?php include(DIR_WS_MODULES . FILENAME_PRODUCT_LISTING); ?></td>
     </tr>
<!--- BEGIN Header Tags SEO Social Bookmarks -->
<?php if (HEADER_TAGS_DISPLAY_SOCIAL_BOOKMARKS == 'true') 
include(DIR_WS_MODULES . 'header_tags_social_bookmarks.php'); 
?>
         <!--- END Header Tags SEO Social Bookmarks -->  
   </table></td>
<?php

 

I set out the edits with extra lines but I'm certain that I had to make a couple of small code changes elsewhere to get it to work, I just don't remember them. I would NOT just copy and paste this as I have other mods in mine and likely a few custom edits that you do not have nor want. Make appropriate backups, use a compare program, whatever you need to keep from screwing this up as I take no responsibility for it...

 

If you can get this to work then we will work on specials.php or something else..

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Hello,

 

The only signifiant difference is:

 

you have:

 

// begin isstock

echo tep_draw_checkbox_field('instock', 1, false, 'onclick="this.form.submit()"') . HEADER_INSTOCK . '<BR>' . "\n";

// end isstock

 

 

 

i have:

 

echo tep_draw_checkbox_field('instock', 1, false, 'onClick="this.form.submit()"') . HEADER_INSTOCK . '</form></td>' . "\n";

 

If i change my code to '<BR>' it messes up the layout, nothing else.

 

The rest of the code is the same except for the SEO part.

 

The problem is it doesn't show the "instock" filter, i can't find it anywhere.

 

Thanks for your help.

Link to comment
Share on other sites

Yep, i had it twice and it was the problem.

 

I've retested using

echo  tep_draw_checkbox_field('instock', 1, false, 'onClick="this.form.submit()"') . HEADER_INSTOCK . '<BR>' . "\n";

instead of

echo  tep_draw_checkbox_field('instock', 1, false, 'onClick="this.form.submit()"') . HEADER_INSTOCK . '</form></td>' . "\n";

(as it apears in the addon files)

 

and IT WORKED! I must of written something wrong in the code last night because all it did was to mess out the layout..

 

Thank you very much mdtaylorlrim!

 

LE: If i click on a category it doesn't display the filter, it will only show up if i select to show only a manufacturer, it won't show up if i select all manufacturers. Can this be easily changed?

 

 

Maybe the autor of the addon reads this post and modifies the files posted in the addon.

Edited by FlorinRO
Link to comment
Share on other sites

 

LE: If i click on a category it doesn't display the filter, it will only show up if i select to show only a manufacturer, it won't show up if i select all manufacturers. Can this be easily changed?

 

 

If I select a manufacturer form the drop down list there is no in-stock filter if the manufacturer only has products in one category. (There must be multiple categories to show the category filter, and thus the in-stock filter.)

If I select a category from the category the has sub categories, there is no in-stock filter.

Once I drill down to a category with products there is an in-stock filter...

For all manufacturers, and when a manufacturer is selected in the manufacturer filter, provided multiple categories exist as well.

 

It appears the logic is tied to the other filter (whether it is manufacturer or category) and so the in-stock filter will only be shown if the other is, but not the other way around. Is that confusing enough?

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

  • 1 month later...

I've added this contribution because I also need an in/out of stock filter for sold products.

I removed the category/manufacturer filter because it had the in stock filter only showing in certain instances and I want to have it in the top categories as well as the subs.

So my code for the filter in index.php currently looks like this:

 

   if (isset($HTTP_GET_VARS['instock']))
     {
     $listing_sql .= " and p.products_quantity > 0";
     }else{
       $listing_sql = $listing_sql;
     }

   if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
     for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
       if ($column_list[$i] == 'PRODUCT_LIST_MANUFACTURER') {
         $HTTP_GET_VARS['sort'] = 'd';
         $listing_sql .= " order by p.products_date_added desc";
         break;
       }
     }
   } else {
     $sort_col = substr($HTTP_GET_VARS['sort'], 0 , 1);
     $sort_order = substr($HTTP_GET_VARS['sort'], 1);
     $listing_sql .= ' order by ';
     switch ($column_list[$sort_col-1]) {
       case 'PRODUCT_LIST_MODEL':
         $listing_sql .= "p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_NAME':
         $listing_sql .= "pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
         break;
       case 'PRODUCT_LIST_MANUFACTURER':
         $listing_sql .= "m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_QUANTITY':
         $listing_sql .= "p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_IMAGE':
         $listing_sql .= "p.manufacturers_id";
         break;
       case 'PRODUCT_LIST_WEIGHT':
         $listing_sql .= "p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_LIST_PRICE':
         $listing_sql .= "final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
     }
   }
?>
   <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="5">
   <tr>
<td align="left"><?php echo $breadcrumb->trail(' » '); ?></td>
<?php
// optional Product List Filter
   if (PRODUCT_LIST_FILTER > 0) {
    if (($HTTP_GET_VARS['cPath']) || ($HTTP_GET_VARS['manufacturers_id'])) {
       $filterlist_sql = "select p.products_carrot, p.products_id, p.manufacturers_id, pd.products_name, p.products_price, 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_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p) left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_carrot = '0' and p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and " . $cat_Search . "";
       } else {
       $filterlist_sql= "select p.products_carrot, p.products_id, p.manufacturers_id, pd.products_name, p.products_price, 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) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m where  p.products_carrot = '0' and p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'";
       }
     $filterlist_query = tep_db_query($filterlist_sql);
     if (tep_db_num_rows($filterlist_query) > 0) {
       echo '            <td align="center" class="SmallText2"><b>' . tep_draw_form('filter', FILENAME_DEFAULT, 'get') . ' ';
       echo  tep_draw_checkbox_field('instock', 1, false, 'onClick="this.form.submit()"') . HEADER_INSTOCK . '</b></td>' . "\n";
       }else{
         echo  tep_draw_checkbox_field('instock', 0, true, 'onClick="this.form.submit()"') . HEADER_OUT_OF_STOCK . '</b></td>' . "\n";
       echo tep_hide_session_id() . '</form></td></tr>' . "\n";
     }
   }

 

Now one of the problems I'm having is that when you select this filter on say page 2 of a category, it redirects to the default page/ home page.

Also, once a customer chooses to hide out of stock items, there is no switch to turn the filter off either. I've tried to have add that option, but it's not working.

Can anyone (who actually knows what they're doing, cause I definitely don't :lol: ) please have a look at the code and explain what's causing these issues?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...