Ok I've got it figured out!!
I dare to even suggest that this method be implemented IMMEDIATELY in CRE 6.5, if it hasn't been fixed already!
If you've read the post above you're probably having trouble with organizing multiple linked products... this is a little hack/mod that I've implemented successfully. If you are not familiar with phpMyAdmin or diving into PHP code you will need outside help. I will outline the steps required then expand and explain the code of each step.
Prerequisites:Using CRE Loaded Pro 6.4.1a (I'm sure others will work as well)
Inside your site's configuration, Set configuration -> Product Listing Display Order = "SORT ORDER"
Here we go!
Step 1. Add a new column inside the products_to_categories table to hold the sorting values of each item in each category. Using phpMyAdmin or a similar database tool, access the products_to_categories table.
Add a new column named "product_sort_order"
Type: INT(20)
Null: YES
Step 2. Add a new function inside of admin/includes/functions/general.php Open the file admin/includes/functions/general.php.
Add this function to the bottom, or wherever you'd like - it's just a simple cPath return function that we are going to use to retrieve the Parent category that we are in... I'm sure CRE already has a built-in method but I like to make my own.
Code:
function getCatPath() {
$cat = $_GET['cPath'];
$pos = strrpos($cat,'_');
if ($pos === false) return $_GET['cPath'];
else {
$catid = substr($cat,$pos+1,strlen($cat));
return $catid;
}
}
Step 3. Modify the admin/categories.php page to pass the Parent category ID into the update sort order SQL QueryWe are going to create a hidden input field that contains the parent category id, and pass it to the SQL query once the user submits the update form.
Open admin/categories.php
Above the closing </form> tag insert this code:
Code:
<?
//Get the Parent cat (category) and store it in a hidden input type
$sortcat = getCatPath();
echo "<input type='hidden' name='SortingCat' value='".$sortcat."' >";
?>
Step 4. Modify the SQL Query to save our sort order into the new column we created in Step 1.Open admin/categories.php if you closed it.
Look for: case 'sort': This is the beginning of the $action switch, which tells CRE what to do.
FIND THIS LINE:
Code:
tep_db_query("UPDATE " . TABLE_PRODUCTS . " SET sort_order = '" . $value . "' WHERE products_id = '" . $key . "'");
(Line: 79 for me)
Below it, add this new SQL Query:Code:
tep_db_query("UPDATE " . TABLE_PRODUCTS_TO_CATEGORIES . " SET product_sort_order ='". $value ."' WHERE products_id ='" . $key ."' AND categories_id='".$_POST['SortingCat']."'");
Quick note:
We could probably remove the first SQL query now but I kept it in there just in-case some other parts of the site used it.
OK, so this will now save our sorting order into the product_sort_order column, and it will only update the one that corresponds to the category you are working in... NOW we have to change the front-end to use this new column for sorting instead of the original sort_order column inside the products table!
Step 5. Make the admin/categories.php page use the new sorting column.OK, so CRE is still programmed to use the sort_order column, but we want it to use our new one!
Open admin/categories.php if you closed it.
Scroll down to line: 3126, or find the product query that retrieves the main product array...
This is what the full statement looks like (we are going to change it)
Code:
if (isset($_POST['search'])) {
$search = str_replace("'", "'", tep_db_prepare_input($_POST['search']));
$products_query = tep_db_query("SELECT p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_model, p2c.categories_id
FROM " . TABLE_PRODUCTS . " p,
" . TABLE_PRODUCTS_DESCRIPTION . " pd,
" . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
WHERE p.products_id = pd.products_id
and pd.language_id = " . (int)$languages_id . "
and p.products_id = p2c.products_id
and (pd.products_name like '%" . tep_db_input($search) . "%' or
p.products_model like '%" . tep_db_input($search) . "%')
ORDER BY p.sort_order, p.products_name");
} else {
$products_query = tep_db_query("SELECT p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_model, p2c.categories_id
FROM " . TABLE_PRODUCTS . " p,
" . TABLE_PRODUCTS_DESCRIPTION . " pd,
" . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
WHERE p.products_id = pd.products_id
and pd.language_id = " . (int)$languages_id . "
and p.products_id = p2c.products_id
and p2c.categories_id = " . (int)$current_category_id . "
and p.products_parent_id = 0
ORDER BY p.sort_order, p.products_name");
}
LOOK closely at the ORDER BY part... it says p.sort_order... BAD!!!
Add: p2c.product_sort_order to both SELECT statements so that they look like this:
Code:
$products_query = tep_db_query("SELECT p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_model, p2c.categories_id, p2c.product_sort_order
Then change both the ORDER BY clauses to this:
Code:
ORDER BY p2c.product_sort_order
NICE! Now when you browse a category inside the admin panel it will order the products using the new sort order column...
Now we have to change the front-end too!!
LAST STEP! This is pretty much identical to Step 5 except that we will modify one of the front-end pages to use the product_sort_order column.
Open index.php (the main one in the root directory, not the admin directory!)
Find the first (of 4) product listing queries...
It looks like this:
Code:
$listing_sql = "SELECT " . $select_column_list . " p.products_id, p.sort_order, p.manufacturers_id, p.products_price, p.products_tax_class_id, p2c.categories_id
IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price,
IF(s.status, s.specials_new_products_price, p.products_price) as final_price
FROM (" . TABLE_PRODUCTS . " p
LEFT JOIN " . TABLE_SPECIALS . " s on(s.products_id = p.products_id and s.status = 1) ),
" . TABLE_MANUFACTURERS . " m,
" . TABLE_PRODUCTS_DESCRIPTION . " pd,
" . TABLE_PRODUCTS_TO_CATEGORIES . " p2c etc....etc.....
I didn't paste the whole thing because it's too long.
OK, so inside of that SELECT statement you can see: p2c.categories_id. JUST AFTER THAT ADD: ", p2c.product_sort_order" (without quotes of course) ... so the main SELECT statement will look like this now:
Code:
$listing_sql = "SELECT " . $select_column_list . " p.products_id, p.sort_order, p.manufacturers_id, p.products_price, p.products_tax_class_id, p2c.categories_id, p2c.product_sort_order
IF(s.status, s.specials_............
Add the same to the other $listing_sql queries ... there are four of them that I could see in that page, they all start with $listing_sql =, but have different conditions before that... so just to be safe I changed them all.
Almost done!!
Now adjust the query that the index page is using as defined by the "SORT ORDER" Case....
Look for this line:
Code:
case 'SORT ORDER':
$listing_sql .= "p.sort_order " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
Change it to THIS:
Code:
case 'SORT ORDER':
//$listing_sql .= "p.sort_order " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
$listing_sql .= "p2c.product_sort_order";
break;
WHOA !!! You're all done... rock on.