Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,401
    Plugin Contributions
    87

    Default [Done] Product attribute sorting

    I'm currently chasing an attribute-ordering issue in Edit Orders, where its ordering of a product's attributes is different from the storefront-placed order.

    What I noticed when viewing Configuration->Product Info->Products Info - Products Option Name Sort Order (a.k.a. PRODUCTS_OPTIONS_SORT_ORDER) is that the comments on the configuration setting don't match what the built-in processing is doing.

    The comments for this setting read
    Code:
    Sort order of Option Names for Products Info
    0= Sort Order, Option Name
    1= Option Name
    ... but when the configuration setting is 0 (as it is the EO case), only the sort-order is used ... as seen in /includes/attributes.php:
    Code:
                  if (PRODUCTS_OPTIONS_SORT_ORDER=='0') {
                    $options_order_by= ' order by LPAD(popt.products_options_sort_order,11,"0")';
                  } else {
                    $options_order_by= ' order by popt.products_options_name';
                  }
    Shouldn't that code fragment be changed to
    Code:
                  if (PRODUCTS_OPTIONS_SORT_ORDER=='0') {
                    $options_order_by= ' order by LPAD(popt.products_options_sort_order,11,"0"), popt.products_options_name';
                  } else {
                    $options_order_by= ' order by popt.products_options_name';
                  }

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

    Default Re: Product attribute sorting

    Something like that has been brought up a number of times over the years with the explanation that the options_names "automatically" sorts as part of that query; however, there are cases where it sorts that way the first time, but a subsequent requery loses the options_names sort without the additional field in the sort list.

    I came across it in the use of dynamic dropdowns if the page was reloaded, then the sort order of the option names was lost until adding in exactly that field.

    I would agree that for consistent operation throughout and in cases where the code was "duplicated" to obtain the same/desired result that is intended.

    The issue also can be duplicated by at least the following:
    I happened to choose the following from the default catalog:
    index.php?main_page=product_info&cPath=25&products_id=36

    Notice that the option names are color and memory (alphabetical order already), default sort order in the database is 10 and 50 respectively (also results in alphabetical order), change the sort order for color to 50 to match memory, then modify the option name for color to something alphabetically after memory (I chose Whole Color). Now access the product, all looks good. Refresh the page... not so much now and subsequent refreshes will maintain the "out-of-alphabetical" order.

    I believe the reason for that at that refresh point is the database sequence of the result. At any rate, if the sort order for the default value of 0 (sort order and option name) included the option name as part of the query then the order would be maintained consistently.

    Note also, on this refresh issue, adding the product to the cart now also generates a different prid because the sequence of the attributes is different than the original, intended and by database settings inspection expected order.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,401
    Plugin Contributions
    87

    Default Re: Product attribute sorting

    The issue is that without the secondary sort by option-name, the options are ordered in the order that the option was added to the database.

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

    Default Re: Product attribute sorting

    Quote Originally Posted by lat9 View Post
    The issue is that without the secondary sort by option-name, the options are ordered in the order that the option was added to the database.
    Yes, that is what is seen in edit orders after editing a product and also seen on standard product on page refresh. Edit orders scraps the remainder of the prid on edit, but that's a separate issue modifying the potentially extra use of the prid.

    Initial display on a product page is as expected based on the admin setting. Not sure if the addition of auto-caching on select statements comes into play as it was some time ago that I worked on that aspect of the attributes.php file to address the issue through not modifying or minimally modifying the file.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,401
    Plugin Contributions
    87

    Default Re: Product attribute sorting

    Make sure the store's Configuration->Product Info settings reflect an option sort type of 0 (sort-order, then name) and an option-value sort of 1 (sort-order, then name).

    What I did to reproduce the issue was to:
    1. Create 3 options in the order ZZZ 1, ZZZ 3, ZZZ 2 ... all using a sort order of 0. Note the order in which the options were created, they're not in alphanumeric sequence.
    2. Create 2 option-values (One, Two) for each option
    3. Assign the 3 options to a product.
    4. View the product on the storefront. The options display (top-to-bottom) in the order 3-2-1.
    5. Place an order with the product. The options display in the order 2-3-1 when the order is displayed in Customers->Orders and when viewed in the customer's order-history.

    That said, while the issue affects Edit Orders ... EO is not the only victim.

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

    Default Re: Product attribute sorting

    Quote Originally Posted by lat9 View Post
    Make sure the store's Configuration->Product Info settings reflect an option sort type of 0 (sort-order, then name) and an option-value sort of 1 (sort-order, then name).

    What I did to reproduce the issue was to:
    1. Create 3 options in the order ZZZ 1, ZZZ 3, ZZZ 2 ... all using a sort order of 0. Note the order in which the options were created, they're not in alphanumeric sequence.
    2. Create 2 option-values (One, Two) for each option
    3. Assign the 3 options to a product.
    4. View the product on the storefront. The options display (top-to-bottom) in the order 3-2-1.
    5. Place an order with the product. The options display in the order 2-3-1 when the order is displayed in Customers->Orders and when viewed in the customer's order-history.

    That said, while the issue affects Edit Orders ... EO is not the only victim.
    Nor is it solely that the order added to the database makes the final display.

    It appears to be a myriad of factors, but yes adding one more field to one of the database queries related to attributes does seem to rectify the issue. In step 3 above the order of adding the attributes to the attributes controller also makes a difference.

    1. Adding in order of ZZZ 1, ZZZ 2, and ZZZ 3 seems to cause a sequence of 2-1-3 in the cart but 1, 3, 2 in attributes manager sequence.
    2. then adding them to the product in ZZZ 3, ZZZ 2, ZZZ 1 causes the product to show them in 2, 1, 3 order in the cart.
    3. Though when I just logged out of the store front, logged in, and added the product when I arrived at the product info page it was in the 3,2,1 order that I added it to the attributes manager.
    4. Go to the shopping cart and still in 3,2,1 order.
    5. Get to checkout_confirmation and now the order is sorted as expected of 1,2,3.
    6. Go back to the shopping cart at this point and the attributes are 1,2,3 now.
    7. Click on the link to return to the product and the product's option names are in 2,1,3 order (again).
    8. Add product to the cart, (2 total expected) but now have two different variants, one with the attributes in the order of 1,2,3 (from step 5 above) the other just added having 2,1,3 the order of which is unrelated to adding to the cart, adding to the option names manager, or adding to the option values manager.

    In the end, the sequence identified at the checkout_confirmation page matched the sequence in the order review, so therefore it is action occurring at the point of adding attributes to the product in the attributes manager to then between displaying the product's attributes and displaying at the checkout_confirmation page at which sequence gets modified with the stored result/sequence presented at the order history page.

    Its certainly screwy and is so in several places leading up to the purchase (and data recording) point.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,401
    Plugin Contributions
    87

    Default Re: Product attribute sorting

    PR generated: https://github.com/zencart/zencart/pull/1424 ... and merged.
    Last edited by DrByte; 24 Apr 2017 at 06:49 PM. Reason: merged.

  8. #8
    Join Date
    Aug 2005
    Location
    San Juan, Puerto Rico
    Posts
    1,525
    Plugin Contributions
    9

    Default Re: [Done] Product attribute sorting

    Quote Originally Posted by lat9 View Post
    I'm currently chasing an attribute-ordering issue in Edit Orders, where its ordering of a product's attributes is different from the storefront-placed order.

    What I noticed when viewing Configuration->Product Info->Products Info - Products Option Name Sort Order (a.k.a. PRODUCTS_OPTIONS_SORT_ORDER) is that the comments on the configuration setting don't match what the built-in processing is doing.

    The comments for this setting read...
    Hello,

    Doing this will give me a product info page with: "WARNING: An Error occurred, please refresh the page and try again."

    The error on the logs is the following:
    [30-Aug-2017 15:33:21 ] Request URI: /.../index.php?main_page=product_info&cPath=6_14_49&products_id=107, IP address: 64.237.233.3
    #1 trigger_error() called at [/.../includes/classes/db/mysql/query_factory.php:167]
    #2 queryFactory->show_error() called at [/.../includes/classes/db/mysql/query_factory.php:139]
    #3 queryFactory->set_error() called at [/.../includes/classes/db/mysql/query_factory.php:266]
    #4 queryFactory->Execute() called at [/.../includes/modules/template/attributes.php:51]
    #5 require(/.../includes/modules/template/attributes.php) called at [/.../includes/modules/pages/product_info/main_template_vars.php:76]
    #6 require(/.../includes/modules/pages/product_info/main_template_vars.php) called at [/.../includes/templates/template/common/tpl_main_page.php:253]
    #7 require(/.../includes/templates/template/common/tpl_main_page.php) called at [/.../index.php:97]

    [30-Aug-2017 15:33:21 ] PHP Fatal error: 1582:Incorrect parameter count in the call to native function 'LPAD' :: select distinct popt.products_options_id, popt.products_options_name, popt.products_options_sort_order,
    popt.products_options_type, popt.products_options_length, popt.products_options_comment,
    popt.products_options_size,
    popt.products_options_images_per_row,
    popt.products_options_images_style,
    popt.products_options_rows
    from zen_products_options popt, zen_products_attributes patrib
    where patrib.products_id='107'
    and patrib.options_id = popt.products_options_id
    and popt.language_id = '1' order by LPAD(popt.products_options_sort_order,11,"0", popt.products_options_name) ==> (as called by) /.../includes/modules/template/attributes.php on line 51 <== in /.../includes/classes/db/mysql/query_factory.php on line 167
    IDEAS Girl
    IDEAS Creative Group
    = Your image... our business!
    My contributions: SophyBlue / Sophy Blue-Grey / Mistik / The Bookshelf / Dynamic Sideboxes

  9. #9
    Join Date
    Jul 2012
    Posts
    16,719
    Plugin Contributions
    17

    Default Re: [Done] Product attribute sorting

    The line has been entered/modified incorrectly. It should look like:
    Code:
    $options_order_by= ' order by LPAD(popt.products_options_sort_order,11,"0"), popt.products_options_name';
    With the LPAD parentheses group having only three parameters, a comma to follow and then the newly added field to maintain that field as one on which to sort.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #10
    Join Date
    Aug 2005
    Location
    San Juan, Puerto Rico
    Posts
    1,525
    Plugin Contributions
    9

    Default Re: [Done] Product attribute sorting

    PERFECT!
    IDEAS Girl
    IDEAS Creative Group
    = Your image... our business!
    My contributions: SophyBlue / Sophy Blue-Grey / Mistik / The Bookshelf / Dynamic Sideboxes

 

 

Similar Threads

  1. v154 Sorting Product list by newest Product added
    By cyberfolli in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 20 Aug 2016, 12:20 PM
  2. Replies: 16
    Last Post: 20 May 2011, 12:22 AM
  3. product sorting with buttons - has it been done?
    By Mrchristoh in forum General Questions
    Replies: 0
    Last Post: 21 May 2009, 03:26 PM
  4. featured items sorting mod not sorting
    By elishama3 in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 27 Mar 2008, 04:39 AM
  5. Product-independent attribute images - can this be done?
    By bodyjewelrystores in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 22 Dec 2006, 06:57 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