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 :
I've changed it to :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);
As you can see, I make one query for usual options, one for my ingredients, and then I try to merge the answers.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);
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


Reply With Quote
