Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,571
    Plugin Contributions
    30

    Default Admin category sort drop-down uses order_by case for product instead of category

    vanilla zen cart 1.51.
    In the admin, go into the top category listing and choose a sorting option.

    Category Sort Order, Categories Name is array option 0 and should be using

    PHP Code:
    case (0):
    $order_by " order by c.sort_order, cd.categories_name"
    (from category_product_listing.php)

    but it actually uses
    PHP Code:
    case (0):
            
    $order_by " order by p.products_sort_order, pd.products_name"
    from the product sort array.

    Similarly for Category Name, option 1 should be:
    PHP Code:
    case (1):
            
    $order_by " order by cd.categories_name"
    but it uses
    PHP Code:
    case (1):
            
    $order_by " order by pd.products_name"
    I rest my case (ha!)

    I found this while adding more sort options to my shop that didn't work.

    Steve

    Hurrah for Superglobals!
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  2. #2
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,571
    Plugin Contributions
    30

    Default Re: Admin category sort drop-down uses order_by case for product instead of category

    The code runs through both switch blocks (category and then product) and so the second $order_by for products always replaces the category one.

    What's the verdict on this?
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  3. #3
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Admin category sort drop-down uses order_by case for product instead of category

    Have have categories with categories_id names and sort orders:

    Sort by Categories Sort Order, Categories Name:
    75 CAT D 1 Sort 1
    74 CAT C 2 Sort 2
    73 CAT B 3 Sort 3
    76 CAT F 4 Sort 4
    77 CAT E 5 Sort 5
    71 CAT A 6 Sort 6
    Sort by Categories Name:
    71 CAT A 6 Sort 6
    73 CAT B 3 Sort 3
    74 CAT C 2 Sort 2
    75 CAT D 1 Sort 1
    77 CAT E 5 Sort 5
    76 CAT F 4 Sort 4

    I have Products with products_id, Products Name and Sort Order:

    Sort by Products Name:
    195 Product A 6 Sort 6
    196 Product B 3 Sort 3
    197 Product C 1 Sort 1
    198 Product D 2 Sort 2
    199 Product E 4 Sort 4
    200 Product F 5 Sort 5
    Sort by Products Sort Order, Products Name:
    197 Product C 1 Sort 1
    198 Product D 2 Sort 2
    196 Product B 3 Sort 3
    199 Product E 4 Sort 4
    200 Product F 5 Sort 5
    195 Product A 6 Sort 6
    Each of these are Sorted as selected ...

    I am not seeing an issue on the Sort Orders for Categories or Products as they sort in the order selected ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  4. #4
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,571
    Plugin Contributions
    30

    Default Re: Admin category sort drop-down uses order_by case for product instead of category

    It think it only becomes apparent when you add more options.
    This is what I did, the extra products options work but the extra category ones not.
    The code on both the product and category listings runs through both switch groups rather than one or the other.

    Categories.php
    Line 614

    Change

    PHP Code:
    if ($zc_skip_products == true) {
            
    // toggle switch for display sort order
            
    $categories_products_sort_order_array = array(array('id' => '0''text' => TEXT_SORT_CATEGORIES_SORT_ORDER_PRODUCTS_NAME),
            array(
    'id' => '1''text' => TEXT_SORT_CATEGORIES_NAME)
            );
    } else {
            
    // toggle switch for display sort order
            
    $categories_products_sort_order_array = array(array('id' => '0''text' => TEXT_SORT_PRODUCTS_SORT_ORDER_PRODUCTS_NAME),
            array(
    'id' => '1''text' => TEXT_SORT_PRODUCTS_NAME),
            array(
    'id' => '2''text' => TEXT_SORT_PRODUCTS_MODEL),
            array(
    'id' => '3''text'=> TEXT_SORT_PRODUCTS_QUANTITY),
            array(
    'id' => '4''text'=> TEXT_SORT_PRODUCTS_QUANTITY_DESC),
            array(
    'id' => '5''text'=> TEXT_SORT_PRODUCTS_PRICE),
            array(
    'id' => '6''text'=> TEXT_SORT_PRODUCTS_PRICE_DESC)
            );
          } 
    To

    PHP Code:
     if ($zc_skip_products == true) {
            
    // toggle switch for display sort order
            
    $categories_products_sort_order_array = array(
                     array(
    'id' => '0''text' => TEXT_SORT_CATEGORIES_SORT_ORDER_PRODUCTS_NAME),
                     array(
    'id' => '1''text' => TEXT_SORT_CATEGORIES_NAME),
                     array(
    'id' => '2''text' => TEXT_SORT_CATEGORIES_ID),//steve new
                     
    array('id' => '3''text' => TEXT_SORT_CATEGORIES_ID_DESC)//steve new
            
    );
          } else {
            
    // toggle switch for display sort order, steve added more
            
    $categories_products_sort_order_array = array(
            array(
    'id' => '0''text' => TEXT_SORT_PRODUCTS_SORT_ORDER_PRODUCTS_NAME),
            array(
    'id' => '1''text' => TEXT_SORT_PRODUCTS_NAME),
            array(
    'id' => '2''text' => TEXT_SORT_PRODUCTS_MODEL),
            array(
    'id' => '3''text'=> TEXT_SORT_PRODUCTS_QUANTITY),
            array(
    'id' => '4''text'=> TEXT_SORT_PRODUCTS_QUANTITY_DESC),
            array(
    'id' => '5''text'=> TEXT_SORT_PRODUCTS_PRICE),
            array(
    'id' => '6''text'=> TEXT_SORT_PRODUCTS_PRICE_DESC),
            array(
    'id' => '7''text'=> TEXT_SORT_PRODUCTS_MODEL_DESC),//steve new
            
    array('id' => '8''text'=> TEXT_SORT_PRODUCTS_STATUS),//steve new
            
    array('id' => '9''text'=> TEXT_SORT_PRODUCTS_ID),//steve new
            
    array('id' => '10''text'=> TEXT_SORT_PRODUCTS_WEIGHT)//steve new
            
    );
          } 
    Category_product_listing.php

    Line 81
    PHP Code:
    <?php 
        
    switch ($_SESSION['categories_products_sort_order']) {
          case (
    0):
            
    $order_by " order by c.sort_order, cd.categories_name";
            break;
          case (
    1):
            
    $order_by " order by cd.categories_name";
          case (
    2);
          case (
    3);
          case (
    4);
          case (
    5);
          case (
    6);
          }
    To

    PHP Code:
    <?php echo __LINE__.":switch categories";
        switch (
    $_SESSION['categories_products_sort_order']) {
          case (
    0):
            
    $order_by " order by c.sort_order, cd.categories_name";
            break;
          case (
    1):
            
    $order_by " order by cd.categories_name";
          case (
    2)://steve added
                      
    $order_by " order by cd.categories_id";
          case (
    3)://steve added
                      
    $order_by " order by cd.categories_id DESC";
          case (
    4);
          case (
    5);
          case (
    6);
          }

    And
    Line 191
    PHP Code:
        switch ($_SESSION['categories_products_sort_order']) {
          case (
    0):
            
    $order_by " order by p.products_sort_order, pd.products_name";
            break;
          case (
    1):
            
    $order_by " order by pd.products_name";
            break;
          case (
    2);
            
    $order_by " order by p.products_model";
            break;
          case (
    3);
            
    $order_by " order by p.products_quantity, pd.products_name";
            break;
          case (
    4);
            
    $order_by " order by p.products_quantity DESC, pd.products_name";
            break;
          case (
    5);
            
    $order_by " order by p.products_price_sorter, pd.products_name";
            break;
          case (
    6);
            
    $order_by " order by p.products_price_sorter DESC, pd.products_name";
            break;
          } 
    To

    PHP Code:
    echo __LINE__.":switch products";//steve debug
        
    switch ($_SESSION['categories_products_sort_order']) {
          case (
    0):
            
    $order_by " order by p.products_sort_order, pd.products_name";
            break;
          case (
    1):
            
    $order_by " order by pd.products_name";
            break;
          case (
    2);
            
    $order_by " order by p.products_model";
            break;
          case (
    3);
            
    $order_by " order by p.products_quantity, pd.products_name";
            break;
          case (
    4);
            
    $order_by " order by p.products_quantity DESC, pd.products_name";
            break;
          case (
    5);
            
    $order_by " order by p.products_price_sorter, pd.products_name";
            break;
          case (
    6);
            
    $order_by " order by p.products_price_sorter DESC, pd.products_name";
            break;
          case (
    7);//steve added
            
    $order_by " order by p.products_model DESC";
            break;
          case (
    8);//steve added
            
    $order_by " order by p.products_status";
            break;
          case (
    9);//steve added
            
    $order_by " order by p.products_id";
            break;
          case (
    10);//steve added
            
    $order_by " order by p.products_weight";
            break;
          } 
    You'll see it does not sort the categories by id.
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  5. #5
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Admin category sort drop-down uses order_by case for product instead of category

    See what happens if you add the:
    break;

    to each of these:
    Code:
        switch ($_SESSION['categories_products_sort_order']) {
          case (0):
            $order_by = " order by c.sort_order, cd.categories_name";
            break;
          case (1):
            $order_by = " order by cd.categories_name";
            break;
          case (2)://steve added
                      $order_by = " order by cd.categories_id";
            break;
          case (3)://steve added
                      $order_by = " order by cd.categories_id DESC";
            break;
          case (4);
          case (5);
          case (6);
        }
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  6. #6
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,571
    Plugin Contributions
    30

    Default Re: Admin category sort drop-down uses order_by case for product instead of category

    See what happens if you add the:break;
    => "see what happens when you add correct code" Doh!

    Still, the original is missing the break too so something got fixed!

    Thanks
    Steve
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  7. #7
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Admin category sort drop-down uses order_by case for product instead of category

    The original, if I am not mistaken, is not affected by the breaks that are not there as there are not more things to set in the CASE below them ...

    But if you have:
    Code:
        switch ($_SESSION['categories_products_sort_order']) {
          case (0):
            $order_by = " order by c.sort_order, cd.categories_name";
            break;
          case (1):
            $order_by = " order by cd.categories_name";
          case (2)://steve added
                      $order_by = " order by cd.categories_id";
          case (3)://steve added
                      $order_by = " order by cd.categories_id DESC";
          case (4);
          case (5);
          case (6);
          }
    When it is 1 that gets overwritten by 2 which gets overwritten by 3 ... which would get overwritten by 4, 5, 6 if there was something set there for $order_by ...

    Those are there for folks that wish to expand the code ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  8. #8
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,571
    Plugin Contributions
    30

    Default Re: Admin category sort drop-down uses order_by case for product instead of category

    The original, if I am not mistaken, is not affected by the breaks that are not there
    Correct, I assumed before researching that the break was compulsory.

    Ok, lesson learned.
    Thanks.
    Steve
    github.com/torvista: Spanish Language Pack, Google reCaptcha, Structured Data, Multiple Copy-Move-Delete, Image Checker, BackupMySQL Admin/Auto...

  9. #9
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Admin category sort drop-down uses order_by case for product instead of category

    The break means to ignore anything in the case statements below ...

    When the break is not there, then the next case is evaluated and if true, will be processed ...

    There are times when you want a case statement to terminate further evaluation and times when you want case statements to be continued to be evaluated ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

 

 

Similar Threads

  1. v151 Need to add sort drop down to sub category product listings....
    By tomlcuneo in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 31 Jul 2015, 07:54 PM
  2. xpanded category tree for drop down menu
    By first trading in forum Templates, Stylesheets, Page Layout
    Replies: 53
    Last Post: 25 Feb 2012, 10:16 AM
  3. manufacturer/category drop down box in product listing page
    By buckit in forum Templates, Stylesheets, Page Layout
    Replies: 8
    Last Post: 8 Jan 2010, 11:34 PM
  4. Category and Sub Category Multiple Drop Down Menus
    By jason_dm in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 22 Oct 2009, 05:43 AM
  5. Replies: 0
    Last Post: 28 Jul 2008, 09:59 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