Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    bug Sort Attribute Dropdown by products_options_values_sort_order

    Admin > Configuration > Product Info...
    Products Info - Product Option Value of Attributes Sort Order

    Current Value: 1

    Please make any necessary changes

    Products Info - Product Option Value of Attributes Sort Order
    Sort order of Product Option Values of Attributes for Products Info
    0= Sort Order, Price
    1= Sort Order, Option Value Name
    0
    1

    Doesn't actually use the options_value_sort_order.
    Original:
    if ( PRODUCTS_OPTIONS_SORT_BY_PRICE =='1' ) {
    $order_by= ' order by LPAD(pov.products_options_values_sort_order,11,"0"), pov.products_options_values_name';
    } else {
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price';
    }



    Updated:
    if ( PRODUCTS_OPTIONS_SORT_BY_PRICE =='1' ) {
    // Twitch change dropdown sort order April 26.2021
    // (stock) $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pov.products_options_values_name';
    $order_by= ' order by LPAD(pov.products_options_values_sort_order,11,"0"), pov.products_options_values_name';
    } else {
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price';
    }


    Now the attribute dropdown follows the option value sort order.
    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base8 - Obsidian - This, is what's new.

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

    Default Re: Sort Attribute Dropdown by products_options_values_sort_order

    Quote Originally Posted by twitchtoo View Post
    Admin > Configuration > Product Info...
    Products Info - Product Option Value of Attributes Sort Order


    Current Value: 1

    Please make any necessary changes

    Products Info - Product Option Value of Attributes Sort Order
    Sort order of Product Option Values of Attributes for Products Info
    0= Sort Order, Price
    1= Sort Order, Option Value Name
    0
    1

    Doesn't actually use the options_value_sort_order.
    Original:
    Code:
                  if ( PRODUCTS_OPTIONS_SORT_BY_PRICE =='1' ) {
                    $order_by= ' order by LPAD(pov.products_options_values_sort_order,11,"0"), pov.products_options_values_name';
                  } else {
                    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price';
                  }

    Updated:
    Code:
                  if ( PRODUCTS_OPTIONS_SORT_BY_PRICE =='1' ) {
                  // Twitch change dropdown sort order April 26.2021
                    // (stock) $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pov.products_options_values_name';
                    $order_by= ' order by LPAD(pov.products_options_values_sort_order,11,"0"), pov.products_options_values_name';
                  } else {
                    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price';
                  }
    Now the attribute dropdown follows the option value sort order.
    Making this change will prevent displaying modifiable sequence of attributes as identified in the attributes controller on a per product basis. Meaning, the attribute sequence will always follow what is set in options values manager for when the PRODUCT_OPTIONS_SORT_BY_PRICE is set to 1 (Products Info - Product Option Value of Attributes Sort Order set to '1').
    Note the original code is/was:
    Code:
    if (PRODUCTS_OPTIONS_SORT_BY_PRICE =='1') {
      $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pov.products_options_values_name';
    } else {
      $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price';
    }
    Which results in presenting information in the sequence offered by the products attributes table for each of the options. The options are listed in sequence with the sort order that is assigned to each option value within an option name. The sort order for those can be set to the "default" which is the above mentioned products_options_values_sort_order and then the sequence of those can be adjusted to suit for the product (when this change is not applied). Note, if two options have the same sort order then they are sequenced by the products_options_values_name or options_values_price respectively. If that is undesirable then offer a different sort order for each option to enforce the desired sequence.

    Put another way, by making the above suggested code change, any effort taken on the products attributes screen to place items in a sequence is lost when PRODUCTS_OPTIONS_SORT_BY_PRICE is set to '1' (Products Info - Product Option Value of Attributes Sort Order set to '1').

    What problem was truly trying to be corrected by this change? Further noting that the title of that setting is 'Product Option Value of Attributes Sort Order' which can be read as the Sort Order of Product Option Values as set in the Attributes Controller. The sort order in the associated table is identified as product_options_sort_order but during operation of the manager, that value is set to the products_options_values_sort_order for the specific option value/entry.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    Default Re: Sort Attribute Dropdown by products_options_values_sort_order

    With more time I'm certain I could recode this admin switch to be more descriptive with alternate switch positions - this is the problem it resolves:

    Instead of numerical order, it looks like this:
    1 - Awesome
    10 - Roses
    11 - Red Hats
    2 - Bees
    20 - Butterflies
    3 - Green Dots
    etc.

    Needs to look like this:
    1 - Awesome
    2 - Bees
    3 - Green Dots
    etc.

    As there is a visual reference that resembles images in the order:
    Awesome [attribute image]
    Bees [attribute image]
    Green Dots [attribute image]

    We tried things like options_values_name:
    (1) Awesome
    (2) Bees
    (3) Green Dots

    or

    Setting the attribute products_options_values_sort_order to 1, 2, 3 for the same associative attributes in order above.
    Awesome (sort order set to 1)
    Bees ( sort order set to 2)
    Green Dots (sort order set to 3)

    But because nothing in the code is looking at the products_options_values_sort_order, it can't sort the Product Option Value of Attributes Sort Order.

    Instead it resorts to the standard alphabetical or numerical sort and when you reach particular numbers it will see them in single character order. Which produces a list that will get your hopes up but read like alphabet soup.


    Now when you set the sort order of the attribute products_options_values_sort_order it actually sees and uses that order correctly.

    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base8 - Obsidian - This, is what's new.

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

    Default Re: Sort Attribute Dropdown by products_options_values_sort_order

    Quote Originally Posted by twitchtoo View Post
    With more time I'm certain I could recode this admin switch to be more descriptive with alternate switch positions - this is the problem it resolves:

    Instead of numerical order, it looks like this:
    1 - Awesome
    10 - Roses
    11 - Red Hats
    2 - Bees
    20 - Butterflies
    3 - Green Dots
    etc.

    Needs to look like this:
    1 - Awesome
    2 - Bees
    3 - Green Dots
    etc.

    As there is a visual reference that resembles images in the order:
    Awesome [attribute image]
    Bees [attribute image]
    Green Dots [attribute image]

    We tried things like options_values_name:
    (1) Awesome
    (2) Bees
    (3) Green Dots

    or

    Setting the attribute products_options_values_sort_order to 1, 2, 3 for the same associative attributes in order above.
    Awesome (sort order set to 1)
    Bees ( sort order set to 2)
    Green Dots (sort order set to 3)

    But because nothing in the code is looking at the products_options_values_sort_order, it can't sort the Product Option Value of Attributes Sort Order.

    Instead it resorts to the standard alphabetical or numerical sort and when you reach particular numbers it will see them in single character order. Which produces a list that will get your hopes up but read like alphabet soup.


    Now when you set the sort order of the attribute products_options_values_sort_order it actually sees and uses that order correctly.
    The previous "incorrect" order is a result of the sort order identified in the attributes manager, assuming that the sequence 1, 10, 11, 2, etc... is referencing the option value sort order and not some arrangement of the sequence of the option value(s) being added into the admin. As far as obtaining alphabetical order by option value, that would best/easiest obtained by using the same sort order for all attributes when the option values of attribute sort order is set to 1. That sort order would again be assigned/reset within the attributes manager. There is a button/option when viewing a product that allows updating the sort order to default.

    If the option values themselves are already set with a numerical sort order that accommodates alphabetization, then calling zen_update_attributes_products_option_values_sort_order on each applicable product (done by selecting the Update Sort Order to Default option) would reset the sort order to what is stored in the options values manager. Note, the use of hard sequential numbers without "gaps" (recommendation is to use numbers in sets of 10) makes maintenance of this list difficult as multiple items after the one insert somewhere other than the end must be updated individually before adding the "next" one unless they are all set to the same sort order so that alphabetization can be used...

    Again, forcing all product display to *only* follow the products options values sort order will remove the ability to change that sort order on a per product basis. As said, per product sort order of options values is made available in the attributes manager and it appears that it is there where the "undesired" sort order exists. I say this also because changing the sort order (as indicated) in the options values manager has no direct effect (in a normal store) on the sort order of existing attributes assigned to product. And creating new option values in the options values manager won't add those option values to product.

    To do so in the admin of a store would require the use of the attributes manager where again the sort order(s) could be updated to match the default and/or be manually changed upon adding the option value to the product's list. Again though, to take advantage of alphabetization as the "primary sort factor", simply set them all to the same sort order and allow them to be sorted by option values name...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    Default Re: Sort Attribute Dropdown by products_options_values_sort_order

    The customer did not want to use alpha sort, the end result looks like this:
    (Bold is what you will see on the live site)

    [Please Choose:] (dropdown default display - [sort 0])
    (1) Awesome [sort 2]
    (2) Bees [sort 4]
    (3) Green Dots [sort 6]
    (4) Coffee [sort 8]
    (5) Brown Leaves [sort 9]
    (6) Blue Rose [sort 10]
    (7) Pink flowers [sort 11]
    (8) Sunflowers [sort 12]
    etc.

    Notice that the sort order steps by 2 to allow future changes without resorting the list - and has additions in it already (sort 9 and sort 11) due to changes made at the last minute - by the shop owner.

    If I needed to isolate this particular product attribute (prevent any change to global attribute display as you mentioned could be a problem) I would add a switch to admin that would allow one to add or change the option ID in a simple if statement, along with updating the original switch in my original post showing the two are connected.

    That way the admin could quickly and easily make changes without requiring a user manual and a coffee to simply look at what they have - then make Zen do what they want and, they don't need me making minor changes to - in this case 69 - product attributes!

    One can appreciate that there are other ways to manipulate the already complex attributes matrix as it were but really the only relative admin switch from stock says Product Option Value of Attributes Sort Order and the shop/includes/modules/YOUR_TEMPLATE/attributes.php doesn't have one single reference to the products_options_values_sort_order.
    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base8 - Obsidian - This, is what's new.

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

    Default Re: Sort Attribute Dropdown by products_options_values_sort_order

    Quote Originally Posted by twitchtoo View Post
    The customer did not want to use alpha sort, the end result looks like this:
    (Bold is what you will see on the live site)

    [Please Choose:] (dropdown default display - [sort 0])
    (1) Awesome [sort 2]
    (2) Bees [sort 4]
    (3) Green Dots [sort 6]
    (4) Coffee [sort 8]
    (5) Brown Leaves [sort 9]
    (6) Blue Rose [sort 10]
    (7) Pink flowers [sort 11]
    (8) Sunflowers [sort 12]
    etc.

    Notice that the sort order steps by 2 to allow future changes without resorting the list - and has additions in it already (sort 9 and sort 11) due to changes made at the last minute - by the shop owner.

    If I needed to isolate this particular product attribute (prevent any change to global attribute display as you mentioned could be a problem) I would add a switch to admin that would allow one to add or change the option ID in a simple if statement, along with updating the original switch in my original post showing the two are connected.

    That way the admin could quickly and easily make changes without requiring a user manual and a coffee to simply look at what they have - then make Zen do what they want and, they don't need me making minor changes to - in this case 69 - product attributes!

    One can appreciate that there are other ways to manipulate the already complex attributes matrix as it were but really the only relative admin switch from stock says Product Option Value of Attributes Sort Order and the shop/includes/modules/YOUR_TEMPLATE/attributes.php doesn't have one single reference to the products_options_values_sort_order.
    Sure, can do whatever is desired with any portion of the site. This could include changing the option ID of one option to the option ID of another which would then allow the front end CSS to be applied to that option ID instead of the former "name". Also, by changing the option ID would allow any special pricing that is attribute associated to be "transferred" to that newly numbered option so the special "Blue widget" that had an added weight would now be applied to that "White widget" and what was applied to the "White widget" would now be applied to the "Blue widget". As well, any "internal" connections to product would need to be updated such as going through the stored shopping cart(s) to swap the option ID information of those cart items so that a previous customer would be able to login, hit the shopping cart and get the item(s) that they supposedly stored for later.

    And yes, now that it has been more thoroughly explained that the "number" in the prefix is part of the option value name, sorting by alphabet *WOULD* be problematic and undesirable (unless they too were 0 padded like the sort order is). Alternatively, if all attributes are to be "so" numbered, then that numbering could be added as part of the atttributes.php processing instead of populating the option values name with that information. That numbering could be added for visual purposes only (easier) or as part of the option information throughout the process. Unfortunate that the store owner is so stuck on physically typing in and maintaining that numbering because adjustment of that information is even harder than just updating a sort order.

    Of course nothing makes it easier for a store owner to be able to self manage a store than for someone else to customize the software so much that when they do discover the simple instruction about how to operate the store that it doesn't work as described by the guidance of the document site, this forum nor input by "normal" users. But if they are given the link to this post and in some way maintain it in their history, perhaps they can remind anyone that tries to help them in the future about what was changed and the reasoning behind it.

    I mean, seems like it would be just as easy to address the sort order by following direction or gaining understanding from locations such as: Option Value Sorter | Zen Cart Documentation (zen-cart.com) or: https://docs.zen-cart.com/user/produ...-option-values.

    As far as: One can appreciate that there are other ways to manipulate the already complex attributes matrix as it were but really the only relative admin switch from stock says Product Option Value of Attributes Sort Order and the shop/includes/modules/YOUR_TEMPLATE/attributes.php doesn't have one single reference to the products_options_values_sort_order.

    Absolutely correct, there is no reference to 'products_options_values_sort_order' because there is no need for one in a properly managed/maintained site. The sort order is based on what is put into the attributes controller, which is where attributes are assigned to a product. Better shown in adding multiple attributes, but the expectation is that when new attributes are added to a product then the initial sort order is what is set in the options values manager or as established by the options values sort manager. Once assigned to the product, then until the order is updated to match the "default" the sort order is as independently stored. Now of course there are outside tools that can be used to update each of those aspects possibly en mass, but last I knew you were already aware of that.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    Have a Drink Re: Sort Attribute Dropdown by products_options_values_sort_order

    I took the time to test this out, read and follow the documentation you suggested to make the changes all on a stock 1.56c Zen Cart.


    I'll repeat, my fix works. Zen will not correctly display the sort order of these attribute option values - even if the option name is changed to remove the bracketed numbers.


    I'd like to make it clear that I respect my clients wishes and since they had already tried the changes written out in the Zen documentation and, I double checked if there were any other tricks that may convince the display to sort correctly, it will not straight out of the box.


    Considering that I have been through many of these 'just read the manual' fixes, as both a developer and store owner and, I'm aware of the frustration of a customized cart with no manual or coding remarks for daily use or yearly upgrades... I developed Twitch Base6.


    Twitch Base6 has nearly every module, from every client, from all the time I've been coding - included and working together without error.

    For each client cart that gets customized - there is a detailed record which gets reported in the admin.

    For each record - a module is built that can not interfere with any other stock code or module installed be it a Twitch Module, Zen Plugin or 3rd Party customization.

    Each module is then included in the master Twitch Base6 Owner's Manual and made available to all clients via admin dashboard.

    All SQL updates are recorded and made available to install into a new site, existing cart or upgrade from 1.38 - 1.57c (current).


    There's plenty of other features but, the goal is to give my clients the flexibility of any Zen Cart version, any developer and any module available - with enough information to do it all themselves if they want - even if I happen to miss seeing the sun tomorrow.


    Also for anyone interested Twitch Base6 - Public for Zen Cart 1.56c will be released to the Zen forum later this year as I transition my clients to Twitch Base7 for Zen Cart 1.57c (current).

    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base8 - Obsidian - This, is what's new.

  8. #8
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    Idea or Suggestion Twitch Sort Attribute Dropdown by products_options_values_sort_order

    I've tested this with all of the conditions possible on a stock Zen Cart 1.56c and included the original code for anyone wanting to see this fix in action with the new 4 position switch... or return everything back the way it was.

    -----
    Twitch Sort Attribute Dropdown by products_options_values_sort_order
    For Zen Cart 1.56c
    April 26.2021


    Method to force dropdown to follow products_options_values_sort_order globally.

    This condition remains exposed as a result of the use of multiple '0' sort order entries or a combination of correct sort order '0,1,2,3' throughout the attributes matrix - spread between product_options_sort_order and products_options_values_sort_order.


    Further explained here:
    https://www.zen-cart.com/showthread....ues_sort_order

    Backup your database and fileset locally. Test that the backups work prior to making changes to your cart.


    Redoc Tracer: // Twitch Sort Attribute Dropdown

    Copyright (C) 2021 Twitchtoo Media


    ***** DEVELOPERS START *****

    ## SQL Update - First we remove the original switch
    DELETE FROM configuration WHERE configuration_key in ('PRODUCTS_OPTIONS_SORT_BY_PRICE');


    ## SQL Update install new switch
    INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function)
    VALUES ('<b>Twitch</b> - Products Info - Product Option Value of Attributes Sort Order', 'PRODUCTS_OPTIONS_SORT_BY_PRICE', '1', '
    Sort order of Product Option Values of Attributes for Products Info - <b>po_sort= products_options_sort_order <br/> pov_sort = products_options_values_sort_order</b><br />
    0= po_sort Sort Order, Price<br />
    1= po_sort Sort Order, Option Value Name<br/>
    2= Force global use of pov_sort Sort Order, Price<br/>
    3= Force global use of pov_sort Sort Order, Option Value Name<br/>
    Default => 1', 18, 36, now(), now(), NULL, 'zen_cfg_select_option(array(\'0\', \'1\', \'2\', \'3\'),');


    ## DELETE CODE - for uninstall
    # DELETE FROM configuration WHERE configuration_key in ('PRODUCTS_OPTIONS_SORT_BY_PRICE');

    ## Original SQL - restore this switch to stock (after delete)
    ## INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES ('Products Info - Product Option Value of Attributes Sort Order', 'PRODUCTS_OPTIONS_SORT_BY_PRICE', '1', 'Sort order of Product Option Values of Attributes for Products Info<br />0= Sort Order, Price<br />1= Sort Order, Option Value Name', 18, 36, now(), now(), NULL, 'zen_cfg_select_option(array(\'0\', \'1\'),');


    Live site updates...


    includes/modules/YOUR_TEMPLATE/attributes.php
    replace this:
    if ( PRODUCTS_OPTIONS_SORT_BY_PRICE =='1' ) {
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pov.products_options_values_name';
    } else {
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price';
    }

    with this:
    // bof Twitch Sort Attribute Dropdown
    /* Twitch original code - if ( PRODUCTS_OPTIONS_SORT_BY_PRICE =='1' ) {
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pov.products_options_values_name';
    } else {
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price';
    } */

    switch (PRODUCTS_OPTIONS_SORT_BY_PRICE) {
    // Twitch change dropdown sort order April 26.2021
    // you can add ASC or DESC to change the default ASC if needed.
    case '0':
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price';
    break;
    case '1':
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pov.products_options_values_name'; // default
    break;
    case '2':
    $order_by= ' order by LPAD(pov.products_options_values_sort_order,11,"0"), pa.options_values_price';
    break;
    case '3':
    $order_by= ' order by LPAD(pov.products_options_values_sort_order,11,"0"), pov.products_options_values_name';
    break;
    }
    // eof Twitch Sort Attribute Dropdown



    ***** DEVELOPERS END *****



    ***** Please Donate *****

    If my work has helped you today in any way, show your appreciation with things like positive feedback or donations.
    Find me at www.twitchtoo.com

    Thanks

    Twitch.
    -----


    If you would like to change the sort order to DESC try this:
    $order_by= ' order by LPAD(pa.products_options_sort_order,11,"0"), pa.options_values_price DESC';

    or this:
    $order_by= ' order by LPAD(pov.products_options_values_sort_order,11,"0"), pa.options_values_price DESC';

    Note: Dropdown output will change or appear to load the same between the switch positions when a '0' (zero) sort order is encountered in the product attribute matrix as the stock cart considers a value entered but allows multiple reference points that could be '0's (zero's) without monitoring these zeros. With this update you could correct the display from the admin, without it the options will not display correctly even if the sort orders were lined up 'correctly' 1, 2, 3 etc.
    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base8 - Obsidian - This, is what's new.

 

 

Similar Threads

  1. Sort By: Dropdown Menu Mastered
    By mikeislearning in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 13 Oct 2011, 04:35 AM
  2. Sort Dropdown Menu
    By quatzl in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 12 Mar 2011, 02:10 AM
  3. Manufactuer Sort By Dropdown Disapeared..
    By josh2885 in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 1 Oct 2007, 03:09 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