Jump to content

Archived

This topic is now archived and is closed to further replies.

Guzappum

products_new.php filter by category - Possible to make it work?

Recommended Posts

Hi,

I wish to start by thanking all who help people in the forums. I have been using OsC for years now, and searching the forums and contributions was almos always enough. I only had to ask for help once and I have to thank @@Bob Terveuren for his solution at that time.

However, I have hit a brick wall again as I do not know php coding, and it seems there isn't a solution available yet that I can implement.

What I'm looking for is:
-to filter the products_new.php by category
-by placing a drop-down list on the user-end of available categories
-so users won't have to look trough hundreds of products (which they don't) in order to find the item types they might be interested in

There is a contribution posted for this, but it doesn't work ( http://addons.oscommerce.com/info/5785). For me it only adds the dropdown list, but no categories appear.

It seems that others also had a problem with this one, but no solution was posted yet:
http://forums.oscommerce.com/topic/298696-filter-new-products-and-latest-products-by-category/
and
http://forums.oscommerce.com/topic/297248-specials-products-new/

Could any of you see what the problem might be and suggest a fix? Or I would also love a different solution to filter the products_new.php by category if there is an easier way.

Thank you in advance!

The original contributor suggests to do this:


Find: <?php echo HEADING_TITLE; ?>

immidiately after insert:



        </td>
            <td class="pageHeading" align="right">
    <FORM>
<?php
$cat_id1=0;
$chkSub1 = 0;
$conn1 = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die ('Error connecting to mysql');
mysql_select_db(DB_DATABASE);

if (isset($categories_id)){
        if (!empty($categories_id) && $categories_id!=""){
                $rst = mysql_query("SELECT parent_id FROM categories WHERE categories_id = ".$categories_id);
                if(mysql_num_rows($rst) > 0){
                        $rparent = mysql_fetch_object($rst);
                        if($rparent->parent_id > 0){
                                $cat_id1 = $rparent->parent_id;
                        }
                        else{
                                $cat_id1 = $categories_id;
                        }
                }
                else{
                        $cat_id1 = $categories_id;
                }
        }
        else{
                $cat_id1 = $categories_id;
        }
}
else{
        $cat_id1 = $categories_id;
}

if (isset($categories_id)){
        if (empty($categories_id) && $categories_id==""){
                //$result = mysql_query("SELECT CD.*, C.* FROM categories AS C, categories_description AS CD WHERE CD.language_id=1 AND C.categories_id = CD.categories_id AND C.parent_id=0");
                $result = mysql_query("select distinct CD.categories_id, CD.categories_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, categories AS C, categories_description AS CD, products_to_categories as pc where CD.language_id=1 AND p.products_status = '1' AND C.categories_id = CD.categories_id AND C.parent_id=0 and p.products_id = pc.products_id and pc.categories_id = C.categories_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
        }
        else{
                //$result = mysql_query("SELECT CD.*, C.* FROM categories AS C, categories_description AS CD WHERE CD.language_id=1 AND C.categories_id = CD.categories_id AND C.parent_id=$cat_id1");
                $result = mysql_query("select distinct CD.categories_id, CD.categories_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, categories AS C, categories_description AS CD, products_to_categories as pc where CD.language_id=1 AND p.products_status = '1' AND C.categories_id = CD.categories_id AND C.parent_id=$cat_id1 and p.products_id = pc.products_id and pc.categories_id = C.categories_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
                $chkSub1 = 1;
        }
}
else{
        //$result = mysql_query("SELECT CD.*, C.* FROM categories AS C, categories_description AS CD WHERE CD.language_id=1 AND C.categories_id = CD.categories_id AND C.parent_id=0");
        $result = mysql_query("select distinct CD.categories_id, CD.categories_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, categories AS C, categories_description AS CD, products_to_categories as pc where CD.language_id=1 AND p.products_status = '1' AND C.categories_id = CD.categories_id AND C.parent_id=0 and p.products_id = pc.products_id and pc.categories_id = C.categories_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
}
//print("<br><br>select distinct CD.categories_id, CD.categories_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, categories AS C, categories_description AS CD, products_to_categories as pc where CD.language_id=1 AND p.products_status = '1' AND C.categories_id = CD.categories_id AND C.parent_id=0 and p.products_id = pc.products_id and pc.categories_id = C.categories_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name");
//$result = mysql_query("SELECT CD.*, C.* FROM categories AS C, categories_description AS CD WHERE CD.language_id=1 AND C.categories_id = CD.categories_id AND C.parent_id=0");
?>

<SELECT NAME="clicklist"style="background-color:#F0F1F4" onChange="location.href=this.form.clicklist.options[this.form.clicklist.selectedIndex].value">
<?php
if ($chkSub1 == 1){
?>
<OPTION>Sub-categories
<?php
}
else{
?>
<OPTION>Select by category
<?php
}
?>
<option>----------------------
<?php
while ($row = mysql_fetch_object($result)) {
        print('<option value="products_new.php?categories_id='.$row->categories_id.'&inc_subcat=1&manufacturers_id">'.$row->categories_name);
}
mysql_free_result($result);
?>
<option value="products_new.php?categories_id=&inc_subcat=1&manufacturers_id">View All
</SELECT NAME></form></div>  


-----
Find:
-----

<?php
  $products_new_array = array();

  $products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
  $products_new_split = new splitPageResults($products_new_query_raw, MAX_DISPLAY_PRODUCTS_NEW);

  if (($products_new_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>

-----------------
And replace with:
-----------------

           <?php
  $products_new_array = array();
if (isset($categories_id)){
          if (empty($categories_id) && $categories_id==""){
                  $products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
        }
        else{
                  $products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pcat, " . TABLE_CATEGORIES . " cat where p.products_status = '1' and p.products_id = pcat.products_id and pcat.categories_id = cat.categories_id and ((cat.categories_id = " . $categories_id . " or cat.parent_id = " . $categories_id . ")) and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
        }
  }
  else{
                  $products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
        }
  $products_new_split = new splitPageResults($products_new_query_raw, MAX_DISPLAY_PRODUCTS_NEW);

  if (($products_new_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>

Share this post


Link to post
Share on other sites

HI Denes....

 

What you ask it can be easily done via a select box. The code you submitted above it is not "valid" because it contains mysql_select_db so the whole thing should be rewritten. The easy part of this is to add a dropdown meu somewhere having all the categories and when the user selects one then it passes a get var in te url cID and then it shows the new products for the selected category.

 

I can propose another method - view without having a select menu dropdown. It would be better if there was a treeview on the left side with a width lets say col-md-4 and on the right (col-md-8) displaying the new products based on what is selected on the treeview.

Note the treeview could contain radioboxes (so you can select only one category) or checkboxes for selecting multiple categories....

 

what do you think?


Check out the great Alternative Administration System addon for osCommerce!

Share this post


Link to post
Share on other sites

HI Denes....

 

What you ask it can be easily done via a select box. The code you submitted above it is not "valid" because it contains mysql_select_db so the whole thing should be rewritten. The easy part of this is to add a dropdown meu somewhere having all the categories and when the user selects one then it passes a get var in te url cID and then it shows the new products for the selected category.

 

I can propose another method - view without having a select menu dropdown. It would be better if there was a treeview on the left side with a width lets say col-md-4 and on the right (col-md-8) displaying the new products based on what is selected on the treeview.

Note the treeview could contain radioboxes (so you can select only one category) or checkboxes for selecting multiple categories....

 

what do you think?

Hi,

 

Thank you for the reply!

 

Both sound great, and the checkbox solution is particularly interesting but I assume the dropdown is easier to implement so I would perfer that one.

 

Could you tell me what code to put in? (I'm sorry to say that I don't know php.)

 

Thanks

Denes

Share this post


Link to post
Share on other sites

×