Question

I have a view all category on the website I am working on (http://www.thetradinghouse.co.nz/view-all). As you can see the products are not in order by category how could I change this as I also would like to do this with the admin product listings too.

V: 1.5.1.3

Was it helpful?

Solution

This kind of thing requires quite a bit of editing in the respective model/catalog/product.php files. This is how for the catalog side of things. The admin should require something similar. To start with, you're going to need to attach the category to the SQL like it does when the category filter is used

        if (!empty($data['filter_category_id'])) {
            $sql .= " LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)";           
        }

Would then become just

            $sql .= " LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)";

Since you want it to be available regardless of the filter_category_id

Then you need to add the category id as a sort option

        $sort_data = array(
            'pd.name',
            'p.model',
            'p.quantity',
            'p.price',
            'rating',
            'p.sort_order',
            'p.date_added'
        );  

will need p2c.category_id adding to it

        $sort_data = array(
            'pd.name',
            'p2c.category_id',
            'p.model',
            'p.quantity',
            'p.price',
            'rating',
            'p.sort_order',
            'p.date_added'
        );

And also set the default sort if none is supplied, changing

$sql .= " ORDER BY p.sort_order";

To

$sql .= " ORDER BY p2c.category_id";

Finally you'll need to edit the controller for the said pages and find the default of the sort value, and change it to p2c.category_id

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top