Results 1 to 10 of 62

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Location
    Los Angeles, California, United States
    Posts
    10,021
    Plugin Contributions
    32

    Default Re: Advanced Search Question (limit to category box)

    Quote Originally Posted by DrByte View Post
    You asked if this code is safe to use, so I'm reviewing it from a coding perspective, not from whether it "works" or is the "best" way to do it. You said it works, so I won't concern myself with the functionality.

    1. But the code *is* using the deprecated split() function, so the code will not work on PHP 5.3.0 or newer.
    Those references to split() should be replaced with explode(). See more detail here: http://www.zen-cart.com/entry.php?2-...use-on-PHP-5-3

    2. If there is no valid result returned from the query (again, only in the part of the code you had highlighted), you're triggering PHP Notices needlessly.
    So, changing this line, by adding the part in bold, would be suggested:
    Code:
        if (!$hide_status->EOF && $hide_status->fields['visibility_status'] < 1) {
    If you've got a lot of categories, then it would be smarter to rewrite your whole "read the hide-categories status from the db for each category one-by-one in real time" into "read all the hide-categories-table data into an array once and just do the lookup on that array" in order to minimize the amount of database queries you're triggering.
    But that's getting into optimization, instead of merely "will it work".
    So I do have one more question.. if I make the code change you suggest above as follows:
    Code:
    //  Begin hideCategories code
        list($nada, $mycpath)= explode('=', $box_categories_array[$i]['path']);
        $mycid = explode('_', $mycpath);
        $categories_id = array_pop($mycid);
        $hide_status = $db->Execute("select visibility_status 
                        FROM " . TABLE_HIDE_CATEGORIES . "
                        WHERE categories_id = " . $categories_id . "
                        LIMIT 1");
       if (!$hide_status->EOF && $hide_status->fields['visibility_status'] < 1) {
    //  End hideCategories code
        switch(true) {
    // to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
    // uncomment the select below and set the cPath=3 to the cPath= your_categories_id
    // many variations of this can be done
    //      case ($box_categories_array[$i]['path'] == 'cPath=3'):
    //        $new_style = 'category-holiday';
    //        break;
          case ($box_categories_array[$i]['top'] == 'true'):
            $new_style = 'category-top';
            break;
          case ($box_categories_array[$i]['has_sub_cat']):
            $new_style = 'category-subs';
            break;
          default:
            $new_style = 'category-products';
          }
         if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
            // skip if this is for the document box (==3)
          } else {
          $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
    
          if ($box_categories_array[$i]['current']) {
            if ($box_categories_array[$i]['has_sub_cat']) {
              $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
            } else {
              $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
            }
          } else {
            $content .= $box_categories_array[$i]['name'];
          }
    
          if ($box_categories_array[$i]['has_sub_cat']) {
            $content .= CATEGORIES_SEPARATOR;
          }
          $content .= '</a>';
    
          if (SHOW_COUNTS == 'true') {
            if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
              $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
            }
          }
    
          $content .= '<br />' . "\n";
        }
      }
    } //  hideCategories code
    Will this negate the need to make the changes to the ../includes/functions/html_output.php as posted previously by moosesoom.. (referenced post below)

    Quote Originally Posted by moosesoom View Post
    I temporarily solved this issue by modifying the following line from ../includes/functions/html_output.php from:

    PHP Code:
    if (empty($default) && isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) ) $default stripslashes($GLOBALS[$name]); 
    to

    PHP Code:
    if ( ($name != 'categories_id') && empty($default) && isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) ) $default stripslashes($GLOBALS[$name]); 
    But please tell me if that solution can break something all over the shop.
    Last edited by DivaVocals; 7 May 2013 at 05:51 PM.
    My Site - Zen Cart & WordPress integration specialist
    I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,450
    Plugin Contributions
    81

    Default Re: Advanced Search Question (limit to category box)

    Quote Originally Posted by DivaVocals View Post
    Will this negate the need to make the changes to the ../includes/functions/html_output.php as posted previously by moosesoom.. (referenced post below)
    No, but in tpl-categories, if you simply change both references of $categories_id to some other variable like $cat_to_check then that should remove the clash that was driving the need for changes to html_output.php



    And, I take back my prior suggestion about adding !$hide_status->EOF && ... because I think that will negate the logic in undesired cases.

    ... which leads me to another, related, observation ...

    Also, looking at the contribution I'm a bit confused why any template files were altered at all. It would be much more efficient for all the changes from the template files to have been done in the modules files that prepare the data for the templates .... again, separating logic from display.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jan 2007
    Location
    Los Angeles, California, United States
    Posts
    10,021
    Plugin Contributions
    32

    Default Re: Advanced Search Question (limit to category box)

    Quote Originally Posted by DrByte View Post
    No, but in tpl-categories, if you simply change both references of $categories_id to some other variable like $cat_to_check then that should remove the clash that was driving the need for changes to html_output.php
    Got it.. will make the suggested changes.. Only thing left for me to figure out is why the code for excluding hidden products from the search results worked in Zen Cart v1.3.9 (when I tested the code provided by another community member), doesn't seem to work in Zen Cart v1.5.1
    **sigh**


    Quote Originally Posted by DrByte View Post
    And, I take back my prior suggestion about adding !$hide_status->EOF && ... because I think that will negate the logic in undesired cases.

    ... which leads me to another, related, observation ...

    Also, looking at the contribution I'm a bit confused why any template files were altered at all. It would be much more efficient for all the changes from the template files to have been done in the modules files that prepare the data for the templates .... again, separating logic from display.
    Dude you're asking ME??!! I had a client who needed this capability for certain custom products (wigs for chemo and alopecia patients) that she wanted to send direct links to clients while hiding these products from other customers.. I found this add-on and simply picked this thing up as it was and compiled all the verified posted fixes from the support forum into the base fileset.. I've NO DOUBT (especially if you point it out) that it could be done better.. but as I'm not a real coder, I haven't the first bit of an idea how to go about making that happen.. (though like many things I've tackled in Zen Cart, I certainly am willing to take a slash at it..)
    My Site - Zen Cart & WordPress integration specialist
    I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,450
    Plugin Contributions
    81

    Default Re: Advanced Search Question (limit to category box)

    Quote Originally Posted by DivaVocals View Post
    Dude you're asking ME??!!
    Haha! No, I wasn't directing that question at you specifically. More just commenting aloud about additional observations I made.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Jan 2007
    Location
    Los Angeles, California, United States
    Posts
    10,021
    Plugin Contributions
    32

    Default Re: Advanced Search Question (limit to category box)

    Quote Originally Posted by DrByte View Post
    Haha! No, I wasn't directing that question at you specifically. More just commenting aloud about additional observations I made.
    Whew!!! because I was looking the screen like this:



    But I took a quick looksee at the files and I think I've figured out how to replace at least TWO of the template files --new products and featured products-- with the correct modules files.. (this is in theory.. I can't test this until I get home tonight)

    Not sure how to do the same with the following:
    • sideboxes/tpl_categories.php (the module doesn't contain the actual data query, this file does or am I missing something??)
    • templates/tpl_products_all_default.php (not quite sure what the module file equivilent is to this.. though I admit that I looked fairly quickly)


    I'm not sure if there is a better way to exclude the hidden categories from the advanced search page's category dropdown without modifying the templates/tpl_advanced_search_default.php file, and I STILL can't figure out why the code to includes/modules/pages/advanced_search_result/header_php.php doesn't work.. in theory it SHOULD (and it did in my previous testing)..

    Code:
    //bof hidden categories change to hide hidden categories from search function
    $from_str = "FROM (" . TABLE_HIDE_CATEGORIES . " h, " . TABLE_PRODUCTS . " p
                 LEFT JOIN " . TABLE_MANUFACTURERS . " m
                 USING(manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c )
                 LEFT JOIN " . TABLE_META_TAGS_PRODUCTS_DESCRIPTION . " mtpd
                 ON mtpd.products_id= p2c.products_id
                 AND mtpd.language_id = :languagesID";
    //eof hidden categories change    
    $from_str = $db->bindVars($from_str, ':languagesID', $_SESSION['languages_id'], 'integer');
    if ((DISPLAY_PRICE_WITH_TAX == 'true') && ((isset($_GET['pfrom']) && zen_not_null($_GET['pfrom'])) || (isset($_GET['pto']) && zen_not_null($_GET['pto'])))) {
      if (!$_SESSION['customer_country_id']) {
        $_SESSION['customer_country_id'] = STORE_COUNTRY;
        $_SESSION['customer_zone_id'] = STORE_ZONE;
      }
      $from_str .= " LEFT JOIN " . TABLE_TAX_RATES . " tr
                     ON p.products_tax_class_id = tr.tax_class_id
                     LEFT JOIN " . TABLE_ZONES_TO_GEO_ZONES . " gz
                     ON tr.tax_zone_id = gz.geo_zone_id
                     AND (gz.zone_country_id IS null OR gz.zone_country_id = 0 OR gz.zone_country_id = :zoneCountryID)
                     AND (gz.zone_id IS null OR gz.zone_id = 0 OR gz.zone_id = :zoneID)";
      $from_str = $db->bindVars($from_str, ':zoneCountryID', $_SESSION['customer_country_id'], 'integer');
      $from_str = $db->bindVars($from_str, ':zoneID', $_SESSION['customer_zone_id'], 'integer');
    }
    // Notifier Point
    $zco_notifier->notify('NOTIFY_SEARCH_FROM_STRING');
    //bof hidden categories change to hide hidden categories from search
    $where_str = " WHERE (p.products_status = 1
                   AND p.products_id = pd.products_id
                   AND pd.language_id = :languagesID
                   AND p.products_id = p2c.products_id
          AND (p.master_categories_id = h.categories_id and h.visibility_status !=2) 
                   AND p2c.categories_id = c.categories_id ";
    //eof hidden categories change

    (I am supposed to writing use cases, but can ya tell I'm a little BORED!!??)
    My Site - Zen Cart & WordPress integration specialist
    I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

 

 

Similar Threads

  1. Width of "Limit to Manufacturer" under advanced search
    By elena1707 in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 12 May 2011, 11:20 PM
  2. Advanced search Limit the manufacturers list
    By ladyink in forum General Questions
    Replies: 1
    Last Post: 9 Oct 2009, 04:10 PM
  3. Replies: 0
    Last Post: 27 May 2009, 06:59 PM
  4. Questions about "Limit to Manufacturer" in Advanced Search.
    By marshall in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 22 Jun 2007, 05:05 AM
  5. "Limit to Category" in Advanced Search defaults to subcateogry
    By lukemcr in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 11 Mar 2007, 04:26 PM

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