Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2005
    Posts
    229
    Plugin Contributions
    0

    Default Need help coding attribute sort order

    Here is my problem,

    more than the attributes included in ZC I need two great attributes families, one is options that you can add, the other one is things that are already in the product but that the customer can remove (ingredients).

    I know the best would have be to build a whole new attrib system for these ingredients but I choose to use the sort order as discriminating value : under 100 the option is an option, and over 100 the option is (for me) an ingredient.

    Each ingredient has two values : Included or No Thanks.

    I modified my files so that the ingredients are in a separate tab on the product page, and that works.

    Now my problem is that I need to sort my ingredients, not according to products_options_sort_order from the options table, but according to products_options_sort_order from the attributes table.

    I begun by testing my code on the attributes_preview page.
    The original code is :
    Code:
     //line 30
        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';
          }
    
          $sql = "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
                  from        " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib
                  where           patrib.products_id='" . (int)$_GET['products_id'] . "'
                  and             patrib.options_id = popt.products_options_id
                  and             popt.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
                  $options_order_by;
    
          $products_options_names = $db->Execute($sql);
    I've changed it to :

    Code:
     if (PRODUCTS_OPTIONS_SORT_ORDER=='0') {
            $attributes_order_by= ' AND popt.products_options_sort_order <100 order by LPAD(popt.products_options_sort_order,11,"0")';
            $ingredients_order_by= ' AND popt.products_options_sort_order > 99 order by LPAD(patrib.products_options_sort_order,11,"0")';
          } else {
            $options_order_by= ' order by popt.products_options_name';
          }
    //on forme deux queries que l'on réunira par la suite pour donner le résultat.
         
          $attributes_sql = "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
                  from        " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib
                  where           patrib.products_id='" . (int)$_GET['products_id'] . "'
                  and             patrib.options_id = popt.products_options_id
                  and             popt.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
                  
                  $attributes_order_by;
            $attributes_options_names = $db->Execute($attributes_sql);
          
          $ingredients_sql = "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
                  from        " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib
                  where           patrib.products_id='" . (int)$_GET['products_id'] . "'
                  and             patrib.options_id = popt.products_options_id
                  and             popt.language_id = '" . (int)$_SESSION['languages_id'] . "' " .
                  $ingredients_order_by;
          
            $ingredients_options_names = $db->Execute($ingredients_sql);
     
            $products_options_names = array_merge((array)$attributes_options_names, (array)$ingredients_options_names);
    As you can see, I make one query for usual options, one for my ingredients, and then I try to merge the answers.

    Last line doesn't give me what I expect. I'm working with NetBeans and the variable view only show me the first value of the array. I tried array_merge_recursive but that make an array of arrays which is not what I need.

    I'm looking for a solution to make $products_options_names one array that contains the answers of my two queries.

    Perhaps there's an more simple way of doing this in sql, but I didn't find how to use two sort orders in one query.

    If ever someone can look at my code and tell me how to do that it would be greatly appreciated.

    Thanks for your precious help

    Regards

    Hubert

  2. #2
    Join Date
    Mar 2005
    Posts
    229
    Plugin Contributions
    0

    Default Re: Need help coding attribute sort order

    Hello,

    I'm answering my own question, the idea came while wrting the question here : why not set option sort order of all my ingredients to 101, and then add a criterea to the sorting function.

    Here is the code in the attribute_preview.php file :

    Code:
                  if (PRODUCTS_OPTIONS_SORT_ORDER=='0') {
            $options_order_by= ' order by LPAD(popt.products_options_sort_order,11,"0"), LPAD(patrib.products_options_sort_order,11,"0")';
          } else {
            $options_order_by= ' order by popt.products_options_name';
          }
    As you can see I only added LPAD(patrib.products_options_sort_order,11,"0") to the ORDER By query.

    Now I have to find how to do that in the attribute controler and then in the product page.

    If ever someone has the answer it would save me time.

    Thanks

    Hubert

 

 

Similar Threads

  1. need coding help for google search attribute availability
    By snowsports in forum General Questions
    Replies: 1
    Last Post: 7 Nov 2011, 08:02 PM
  2. Coding an Order Total module, help?
    By conner_bw in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 21 Apr 2011, 07:04 PM
  3. I need coding help BAD...... :(
    By g0d4lm1ty in forum General Questions
    Replies: 3
    Last Post: 22 Sep 2006, 07:47 AM

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