Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20
  1. #11
    Join Date
    Mar 2009
    Location
    Essex, UK
    Posts
    446
    Plugin Contributions
    0

    Default Re: How to set up sub-category to instead go onto the first product

    Hi mc

    I added your code first before the line and then after and after the breadcrumb menu, I just get a blank page.
    Debbie Harrison
    DVH Design | Web Design blog

  2. #12
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: How to set up sub-category to instead go onto the first product

    Quote Originally Posted by dharrison View Post
    Hi mc

    I added your code first before the line and then after and after the breadcrumb menu, I just get a blank page.
    Error message in the logs directory? (sequence really didn't matter.)
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #13
    Join Date
    Mar 2009
    Location
    Essex, UK
    Posts
    446
    Plugin Contributions
    0

    Default Re: How to set up sub-category to instead go onto the first product

    Error Log
    [09-May-2016 07:45:15 Europe/Berlin] PHP Warning: Cannot modify header information - headers already sent by (output started at path\to\oursite\includes\templates\dover_fine\templates\tpl_modules_mobile_categ ories_tabs.php:56) in path\to\oursite\includes\functions\functions_general.php on line 46
    Debbie Harrison
    DVH Design | Web Design blog

  4. #14
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: How to set up sub-category to instead go onto the first product

    Quote Originally Posted by mc12345678 View Post
    Okay, so there may be a better way to do this, but what I seemed to find was the following based on some of the discussion.

    Want to be able to navigate from category to category and see the "sub-categories" in the center of the page, but... When reaching a category that has product (which in ZC in default coding is the way things are expected to be either a category has active product or other sub-categories but not both active product and sub-categories), then display product "0" for that category which is likely to be based on some sort of sort operation...

    I didn't chase down every possibility, and there are "cleaner" ways to do this than to literally change code like to use a notifier/observer operation, but during testing a little code mod first could make the difference/easier. :)

    Anyways, so that full process is controlled by the includes/modules/pages/index/ code in that folder basically..

    When one navigates to/through the categories or back to the main (default) screen, then the code in this area is evaluating the conditions to see what page (listing) should be displayed...

    In your case, when a visitor tries to arrive at this "last page", you would like them diverted to the product that would have appeared first on that page... So... here's my thought, which does involve modifying a "non-overrideable" file...

    If you open includes/modules/pages/index/main_template_vars.php and then at/around line 196: $tpl_page_body = 'tpl_index_product_list.php';

    And just before or just after this, if you add this line which comes from includes/modules/pages/index/header_php.php:

    Code:
    zen_redirect(zen_href_link(zen_get_info_page($listing->fields['products_id']), ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing->fields['products_id']));
    Then this is likely to at least *prove* the theory. The next thing would be to ensure that the particular products_id is provided/available if in fact some sort order was applied, but this should redirect to the first item of the return list.

    Please try this on your local development site.

    As to my "setup". If you mean how am I navigating to see things currently, well, good ole' blackberry... :)
    Okay, so how about this, considering a redirect is offered in the following file, we'll just do the applicable tests here and redirect before getting to the main_template_vars.php file:

    In includes/modules/pages/index/header_php.php
    After the following code and before the final notifier:
    Code:
    // if only one product in this category, go directly to the product page, instead of displaying a link to just one item:
    // if filter_id exists the 1 product redirect is ignored
    if (SKIP_SINGLE_PRODUCT_CATEGORIES=='True' and (!isset($_GET['filter_id']) and !isset($_GET['alpha_filter_id']))) {
      if ($listing->RecordCount() == 1) {
        zen_redirect(zen_href_link(zen_get_info_page($listing->fields['products_id']), ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing->fields['products_id']));
      }
    }
    Add this code:
    Code:
    if (($category_depth == 'products' || zen_check_url_get_terms()) && $listing->RecordCount() > 0) {
      zen_redirect(zen_href_link(zen_get_info_page($listing->fields['products_id']), ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing->fields['products_id']));
    }
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #15
    Join Date
    Mar 2009
    Location
    Essex, UK
    Posts
    446
    Plugin Contributions
    0

    Default Re: How to set up sub-category to instead go onto the first product

    It works!!! Thanks so much.
    Debbie Harrison
    DVH Design | Web Design blog

  6. #16
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: How to set up sub-category to instead go onto the first product

    Quote Originally Posted by dharrison View Post
    It works!!! Thanks so much.
    Good to hear. Now there are a few ways that you could proceed...

    The file changed is basically a core file. That modification could be moved into a separate file as a sort of plugin to the store (observer) and applied/removed as necessary to suit the store owner's/developer's need.

    The alternative is that the code could remain where it is but I would suggest adding comments (start a line with comments with // or if covering multiple lines start with /* and end with */). If the code stays in place in that file, on the next ZC upgrade, attention would need to be maintained in comparing the newly provided file(s) with this file.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #17
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: How to set up sub-category to instead go onto the first product

    BTW, I was going to start to suggest the code to move this into an observer, but in review of this thread, I don't see mention of the current ZC version. There are two ways to apply the change, one better in a newer store requiring a single file and an older method requiring two files.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #18
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: How to set up sub-category to instead go onto the first product

    Quote Originally Posted by mc12345678 View Post
    Okay, so how about this, considering a redirect is offered in the following file, we'll just do the applicable tests here and redirect before getting to the main_template_vars.php file:

    In includes/modules/pages/index/header_php.php
    After the following code and before the final notifier:
    Code:
    // if only one product in this category, go directly to the product page, instead of displaying a link to just one item:
    // if filter_id exists the 1 product redirect is ignored
    if (SKIP_SINGLE_PRODUCT_CATEGORIES=='True' and (!isset($_GET['filter_id']) and !isset($_GET['alpha_filter_id']))) {
      if ($listing->RecordCount() == 1) {
        zen_redirect(zen_href_link(zen_get_info_page($listing->fields['products_id']), ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing->fields['products_id']));
      }
    }
    Add this code:
    Code:
    if (($category_depth == 'products' || zen_check_url_get_terms()) && $listing->RecordCount() > 0) {
      zen_redirect(zen_href_link(zen_get_info_page($listing->fields['products_id']), ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing->fields['products_id']));
    }
    Create a new file in:
    includes/classes/observers
    titled: auto.display_first_product_in_cat.php

    (The name is chosen to mean something, it can be changed here, but will need to be changed below where the same text is used but the underscores removed)

    In the file (nothing to exist before the first <?php):
    Code:
    <?php
    
    /**
     * Uses the observer class modified in ZC 1.5.3 to autoload the below code and not require additional files to obtain the desired result.
     * This is (was?) also PHP 7.0 compliant, though may survive for longer than that as well.
     * 
     * This redirects the visitor to the product info page for the first product that is in the $listing query results.
     * This way, once a customer has dug into the category listing and the category is identified as having product that the first
     *   product is displayed.
     * mc12345678 - 9 May 2016
     **/
    
    class zcObserverDisplayFirstProductInCat extends base 
    {
        function __construct() 
        {
            $attachThis = array();
    
            $attachThis[] = 'NOTIFY_HEADER_END_INDEX';
    
            $this->attach($this, $attachThis);
        } // end __construct
    
        // NOTIFY_HEADER_END_INDEX, Code below is to redirect customer to the "first" product identified in the $listing variable.
        //   if that variable has been modified by another observer before this one, then it resets to the first item in the list.
        function updateNotifyHeaderEndIndex(&$callingClass, $notifier) 
        {
            global $category_depth, $listing, $cPath;
    
            if (($category_depth == 'products' || zen_check_url_get_terms()) && $listing->RecordCount() > 0) 
            {
                // This next section makes this code upgrade compatible to ZC 1.5.5+ and resets the listing in case some other 
                //  header listening observer gets run before this one does and it modifies the pointer to the results. :)
                if (method_exists($listing, 'rewind'))
                {
                    reset($listing);
                } else {
                    $listing->Move(0);
                    $listing->MoveNext();
                }
    
                zen_redirect(zen_href_link(zen_get_info_page($listing->fields['products_id']), ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . (int)$listing->fields['products_id']));
            } // end if
        } // end function updateNotifyHeaderEndIndex
    } // end class definition
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #19
    Join Date
    Mar 2009
    Location
    Essex, UK
    Posts
    446
    Plugin Contributions
    0

    Default Re: How to set up sub-category to instead go onto the first product

    Does this file change having the overrides in the 2 files that we changed?

    Current ZC version is 1.5.4. I thought that was the thread that I posted in.

    Regardless thanks for your help
    Debbie Harrison
    DVH Design | Web Design blog

  10. #20
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: How to set up sub-category to instead go onto the first product

    Quote Originally Posted by dharrison View Post
    Does this file change having the overrides in the 2 files that we changed?

    Current ZC version is 1.5.4. I thought that was the thread that I posted in.

    Regardless thanks for your help
    Actually with this extra file you can restore the other two files to their original ZC grandness. :)

    As previously identified the change made to $main_template_vars.php caused headers previously sent error, the change made to header_php.php is addressed by the above provided code.

    As for your process of posting, you did tag the post as 1.5.4 and as might be visible in the below, the screenshot from my device, the "indicator" might be visible on the upper left instead of inline like DrByte showed. Name:  IMG_20160510_084702.jpg
Views: 75
Size:  64.8 KB
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. How to i set attributes to all the items in a sub category?
    By toutou21 in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 5 Feb 2010, 12:18 AM
  2. How to make top category to show products instead of sub-categories?
    By MKdiable in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 12 Oct 2009, 11:55 PM
  3. Default to the first sub category
    By odessey1 in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 1 Jul 2009, 03:38 AM
  4. Product always first in category - how do I set that up?
    By abran1984 in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 4 Dec 2008, 06:04 PM

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