Forums / Bug Reports / Admin category sort drop-down uses order_by case for product instead of category

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

Views: 1,307

Results 1 to 9 of 9
2 Feb 2013, 7:56 AM
#1
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

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

case (0):
$order_by = " order by c.sort_order, cd.categories_name";
``` (from category_product_listing.php)

but it actually uses
```php
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:

case (1):
        $order_by = " order by cd.categories_name";

but it uses

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: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

11 Feb 2013, 4:16 PM
#2
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

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: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

11 Feb 2013, 4:48 PM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

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 ... :lookaroun

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!]
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!

11 Feb 2013, 8:49 PM
#4
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

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

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

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
<?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 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

    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

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: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

11 Feb 2013, 11:51 PM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

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:

    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!]
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!

12 Feb 2013, 6:57 AM
#6
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

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! :bangin:

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

Thanks
Steve

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

12 Feb 2013, 2:47 PM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

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:

    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!]
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!

13 Feb 2013, 3:01 PM
#8
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

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: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

13 Feb 2013, 3:06 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

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!]
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!