Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Posts
    2,123
    Plugin Contributions
    0

    Default Why Can't I Use Products and Categories Together?

    Why can't I put both products and sub categories in the same category folder? I know I'm not supposed to, but when I do it, it doesn't seem to cause any problems, on the contrary in fact.

    I'm trying to make my main jewelery and lingerie categories display all the products from their sub categories in a random order (20 per page) in the same way all my other main categories do (my other main categories do not have sub-cats just products).

    I can't figure out what files to modify in order to replicate this behaviour, but I'm thinking of just copying (linking) all the sub category products straight into the main jewelery and lingerie categories as linked products.

    This would mean that there'd be both categories and products in the main categories. Again, I know you're not supposed to do this, but I've tested it and it does solve my problem. I can't see what harm it is doing, so can anyone please advise why we're not supposed to have both categories and products in the same category folders?

  2. #2
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Why Can't I Use Products and Categories Together?

    This mixes up two issues: data storage and product display.

    For storage you need to keep them separate as the algorithms that currently step recursively through the category tree expect to find products at the end nodes and not in the middle of hierarchical sequences. And the MPTT algorithm that will replace this recursive approach (and should give huge performance gains when compiling category data) for 2.0 will be even less forgiving.

    However, that doesn't preclude you from writing display modules that list all categories underneath a particular parent and then retrieving and displaying all products in those categories.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  3. #3
    Join Date
    Jan 2009
    Posts
    2,123
    Plugin Contributions
    0

    Default Re: Why Can't I Use Products and Categories Together?

    Yes, that explains pretty well why not to mix products and categories. Thank you for that.

    After I'd posted this, I actually managed to do just that (write a display module that lists all my categories underneath the main parent categories and then retrieves and displays all of the products in those categories).

    So, it's working perfectly now, just as I needed.

  4. #4
    Join Date
    Jul 2005
    Location
    Brooklyn NY
    Posts
    507
    Plugin Contributions
    0

    Default Re: Why Can't I Use Products and Categories Together?

    can you post here to show us how you did that. I am trying to do the same thing

  5. #5
    Join Date
    Jan 2009
    Posts
    2,123
    Plugin Contributions
    0

    Default Re: Why Can't I Use Products and Categories Together?

    Quote Originally Posted by touchclothing View Post
    can you post here to show us how you did that. I am trying to do the same thing
    I made some changes to default_filter.php

    PHP Code:
    <?php
    /**
     * default_filter.php  for index filters
     *
     * index filter for the default product type
     * show the products of a specified manufacturer
     *
     * @package productTypes
     * @copyright Copyright 2003-2007 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @todo Need to add/fine-tune ability to override or insert entry-points on a per-product-type basis
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: default_filter.php 6912 2007-09-02 02:23:45Z drbyte $
     */
    if (!defined('IS_ADMIN_FLAG')) {
      die(
    'Illegal Access');
    }
      if (isset(
    $_GET['alpha_filter_id']) && (int)$_GET['alpha_filter_id'] > 0) {
        
    //$alpha_sort = " and pd.products_name LIKE '" . chr((int)$_GET['alpha_filter_id']) . "%' ";
        
    $filterid = (int)$_GET['alpha_filter_id'];
        switch(
    $filterid)
        {
                case 
    1:
                    
    $alpha_sort " order by pd.products_viewed";
                    break;
                case 
    2:
                    
    $alpha_sort " order by p.products_price";
                    break;
                case 
    3:
                    
    $alpha_sort " order by p.products_price DESC";
                    break;
                case 
    4:
                    
    $alpha_sort " order by pd.products_name";
                    break;
                case 
    5:
                    
    $alpha_sort " order by m.manufacturers_name";
                    break;
                case 
    6:
                    
    $alpha_sort " order by p.products_date_added DESC";
                    break;
                case 
    7:
                    
    $alpha_sort " order by p.products_date_added";
                    break;
                    
                    
                
            
        }
      } else {
        
    $alpha_sort ' order by p.products_date_added DESC';
    $filterid 6// 6 is the case sortquery to list new to old.
      
    }
      if (!isset(
    $select_column_list)) $select_column_list "";
       
    // show the products of a specified manufacturer
      
    if (isset($_GET['manufacturers_id']) && $_GET['manufacturers_id'] != '' ) {
        if (isset(
    $_GET['filter_id']) && zen_not_null($_GET['filter_id'])) {
    // We are asked to show only a specific category
          
    $listing_sql "select distinct " $select_column_list " p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description, if(s.status = 1, s.specials_new_products_price, NULL) AS specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
           from " 
    TABLE_PRODUCTS " p left join " TABLE_SPECIALS " s on p.products_id = s.products_id , " .
           
    TABLE_PRODUCTS_DESCRIPTION " pd, " .
           
    TABLE_MANUFACTURERS " m, " .
           
    TABLE_PRODUCTS_TO_CATEGORIES " p2c
           where p.products_status = 1
             and p.manufacturers_id = m.manufacturers_id
             and m.manufacturers_id = '" 
    . (int)$_GET['manufacturers_id'] . "'
             and p.products_id = p2c.products_id
             and pd.products_id = p2c.products_id
             and pd.language_id = '" 
    . (int)$_SESSION['languages_id'] . "'
             "
    ;/* bof all_sub_cats_products */
             
    if(!empty($sub_cats)) 
                 
    $listing_sql .=  "and p2c.categories_id IN($sub_cats)" .
             
    $alpha_sort;
             else 
    /* eof all_sub_cats_products*/ $listing_sql .=  "
             and p2c.categories_id = '" 
    . (int)$_GET['filter_id'] . "'" .
             
    $alpha_sort;
        } else {
    // We show them all
          
    $listing_sql "select distinct " $select_column_list " p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
          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_status = 1
            and pd.products_id = p.products_id
            and pd.language_id = '" 
    . (int)$_SESSION['languages_id'] . "'
            "
    ;/* bof all_sub_cats_products */
             
    if(!empty($sub_cats)) 
                 
    $listing_sql .=  "and p2c.categories_id IN($sub_cats)" .
             
    $alpha_sort;
             else 
    /* eof all_sub_cats_products*/ $listing_sql .=  "
            and p.manufacturers_id = m.manufacturers_id
            and m.manufacturers_id = '" 
    . (int)$_GET['manufacturers_id'] . "'" .
            
    $alpha_sort;
        }
      } else {
    // show the products in a given category
        
    if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id'])) {
    // We are asked to show only specific category
          
    $listing_sql "select distinct " $select_column_list " p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status = 1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
          from " 
    TABLE_PRODUCTS " p left join " TABLE_SPECIALS " s on p.products_id = s.products_id, " .
          
    TABLE_PRODUCTS_DESCRIPTION " pd, " .
          
    TABLE_MANUFACTURERS " m, " .
          
    TABLE_PRODUCTS_TO_CATEGORIES " p2c
          where p.products_status = 1
            and p.manufacturers_id = m.manufacturers_id
            and m.manufacturers_id = '" 
    . (int)$_GET['filter_id'] . "'
            and p.products_id = p2c.products_id
            and pd.products_id = p2c.products_id
            and pd.language_id = '" 
    . (int)$_SESSION['languages_id'] . "'
            "
    ;/* bof all_sub_cats_products */
             
    if(!empty($sub_cats)) 
                 
    $listing_sql .=  "and p2c.categories_id IN($sub_cats)" .
             
    $alpha_sort;
             else 
    /* eof all_sub_cats_products*/ $listing_sql .=  "
            and p2c.categories_id = '" 
    . (int)$current_category_id "'" .
            
    $alpha_sort;
        } else {
    // We show them all
          
    $listing_sql "select distinct " $select_column_list " p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status =1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
           from " 
    TABLE_PRODUCTS_DESCRIPTION " pd, " .
           
    TABLE_PRODUCTS " p left join " TABLE_MANUFACTURERS " m on p.manufacturers_id = m.manufacturers_id, " .
           
    TABLE_PRODUCTS_TO_CATEGORIES " p2c left join " TABLE_SPECIALS " s on p2c.products_id = s.products_id
           where p.products_status = 1
             and p.products_id = p2c.products_id
             and pd.products_id = p2c.products_id
             and pd.language_id = '" 
    . (int)$_SESSION['languages_id'] . "'
             "
    ;/* bof all_sub_cats_products */
             
    if(!empty($sub_cats)) 
                 
    $listing_sql .=  "and p2c.categories_id IN($sub_cats)" .
             
    $alpha_sort;
             else 
    /* eof all_sub_cats_products*/ $listing_sql .=  "
             and p2c.categories_id = '" 
    . (int)$current_category_id "'" .
             
    $alpha_sort;
        }
      }

    // set the default sort order setting from the Admin when not defined by customer
      
    if (!isset($_GET['sort']) and PRODUCT_LISTING_DEFAULT_SORT_ORDER != '') {
        
    $_GET['sort'] = PRODUCT_LISTING_DEFAULT_SORT_ORDER;
      }

      if (isset(
    $column_list)) {
        if ((!isset(
    $_GET['sort'])) || (isset($_GET['sort']) && !ereg('[1-8][ad]'$_GET['sort'])) || (substr($_GET['sort'], 01) > sizeof($column_list)) ) {
          for (
    $i=0$n=sizeof($column_list); $i<$n$i++) {
            if (isset(
    $column_list[$i]) && $column_list[$i] == 'PRODUCT_LIST_NAME') {
              
    $_GET['sort'] = $i+'a';
              
    $listing_sql .= " order by p.products_sort_order, pd.products_name";
              break;
            } else {
    // sort by products_sort_order when PRODUCT_LISTING_DEFAULT_SORT_ORDER is left blank
    // for reverse, descending order use:
    //       $listing_sql .= " order by p.products_sort_order desc, pd.products_name";
     //         $listing_sql .= " order by p.products_date_added DESC, pd.products_name";
              
    break;
            }
          }  
    // if set to nothing use products_sort_order and PRODUCTS_LIST_NAME is off
          
    if (PRODUCT_LISTING_DEFAULT_SORT_ORDER == '') {
            
    $_GET['sort'] = '20a';
          }
        } else {
          
    $sort_col substr($_GET['sort'], 1);
          
    $sort_order substr($_GET['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 .= "pd.products_name";
              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";
              
    $listing_sql .= "p.products_price_sorter " . ($sort_order == 'd' 'desc' '') . ", pd.products_name";
              break;
          }
        }
      }
    // optional Product List Filter
      
    if (PRODUCT_LIST_FILTER 0) {
        if (isset(
    $_GET['manufacturers_id']) && $_GET['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)$_SESSION['languages_id'] . "'
            and p.manufacturers_id = '" 
    . (int)$_GET['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"
    ;
        }
        
    $do_filter_list false;
        
    $filterlist $db->Execute($filterlist_sql);
        if (
    $filterlist->RecordCount() > 1) {
            
    $do_filter_list true;
          if (isset(
    $_GET['manufacturers_id'])) {
            
    $getoption_set =  true;
            
    $get_option_variable 'manufacturers_id';
            
    $options = array(array('id' => '''text' => TEXT_ALL_CATEGORIES));
          } else {
            
    $options = array(array('id' => '''text' => TEXT_ALL_MANUFACTURERS));
          }
          while (!
    $filterlist->EOF) {
            
    $options[] = array('id' => $filterlist->fields['id'], 'text' => $filterlist->fields['name']);
            
    $filterlist->MoveNext();
          }
        }
      }

    // Get the right image for the top-right
      
    $image DIR_WS_TEMPLATE_IMAGES 'table_background_list.gif';
      if (isset(
    $_GET['manufacturers_id'])) {
        
    $sql "select manufacturers_image
                  from   " 
    TABLE_MANUFACTURERS "
                  where      manufacturers_id = '" 
    . (int)$_GET['manufacturers_id'] . "'";

        
    $image_name $db->Execute($sql);
        
    $image $image_name->fields['manufacturers_image'];

      } elseif (
    $current_category_id) {

        
    $sql "select categories_image from " TABLE_CATEGORIES "
                where  categories_id = '" 
    . (int)$current_category_id "'";

        
    $image_name $db->Execute($sql);
        
    $image $image_name->fields['categories_image'];
      }
    ?>
    Look specifically at the four blocks labelled /bof all_sub_cats_products coding.

  6. #6
    Join Date
    May 2009
    Posts
    10
    Plugin Contributions
    0

    Default Re: Why Can't I Use Products and Categories Together?

    Nice but it doesnt work, what do I need? beside changing that file?

 

 

Similar Threads

  1. Can I use both Paypal Standard and PayPall Express together in 1.3.9h?
    By janissaire in forum PayPal Express Checkout support
    Replies: 8
    Last Post: 22 Sep 2012, 03:17 AM
  2. v139h Can I use ultimate seo urls and Ceon URI Mapping together?
    By sansan0831 in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 19 Apr 2012, 08:29 PM
  3. Why Can Not Create Categories/Products?
    By brihan in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 4 Jan 2012, 02:17 AM
  4. Can similar subcategories of different Categories be grouped and displayed together?
    By Mac in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 8 Mar 2010, 05:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR