Post by mystifier » Wed Dec 08, 2010 7:12 pm

I was just going to write a 'Filter Products by Category' extension which is a strange omission, but I checked in extensions first to find that Hildebrando had already added it as a free extension.

There is however, a pagination issue when a Category filter is added. A replacement getTotalProducts() function is required in admin\model\catalog\product.php:

Code: Select all

public function getTotalProducts($data = array()) {
    $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product p
    LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)
    INNER JOIN " . DB_PREFIX . "product_to_category p2c ON p.product_id = p2c.product_id
    WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";

    if (isset($data['filter_name']) && !is_null($data['filter_name'])) {
        $sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%'";
    }

    if (isset($data['filter_model']) && !is_null($data['filter_model'])) {
        $sql .= " AND LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($data['filter_model'])) . "%'";
    }

    if (isset($data['filter_category']) && !is_null($data['filter_category'])) {
        $sql .= " AND p2c.category_id = " . $this->db->escape($data['filter_category']);
    }

    if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
        $sql .= " AND p.quantity = '" . $this->db->escape($data['filter_quantity']) . "'";
    }

    if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
        $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
    }

    $query = $this->db->query($sql);

    return $query->row['total'];
}
Then it works great - thanks Hildebrando!

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by i2Paq » Thu Dec 09, 2010 2:06 am

I've just added this mod to my store (thanks for pointing me towards this Fido-X!) and I was also made aware on your fix.

But after I've added your fix it says: Showing 1 to 20 of 22 (2 Pages)
It only shows 18 products and page 2 says: No results!

Any suggestion?

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by mystifier » Thu Dec 09, 2010 2:48 am

Hi Norman,

I can't replicate the problem, but I think you will fix it by joining product_to_category with a LEFT JOIN rather than an INNER JOIN (Simply change 'INNER' to 'LEFT' on line 4 of my code).

The most likely explanation is that you have uncategorized products that get accounted in the total but not included in the result set.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by Hildebrando » Fri Dec 10, 2010 1:38 am

Hi Mystifier:

Thanx.

Updated. There is a new release (v 04) at extension zone.

http://www.opencart.com/index.php?route ... ion_id=719

Hilde

Commercial Contributions:Bulk Specials| Bulk Update Prices|Search Tyre Pro
Free Contributions: Youtube video (oc 1.5.x) | Search History Report (oc 1.5.x) | Product Filter by Category (oc 1.5.x)|Youtube Popup
More Free & commercial mods: www.fpress.com


User avatar
Active Member

Posts

Joined
Fri Mar 06, 2009 8:22 pm
Location - Spain

Post by mystifier » Wed Dec 22, 2010 12:59 am

I have just upgraded to v1.4.9.3 which, unfortunately, clashes with all files in the Filter by Category extension (which I think deserved to have been incorporated into the updated core).

To save anyone else the bother, attached are my amended files which Hildebrando might like to add as a new version.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by Hildebrando » Fri Dec 24, 2010 4:58 pm

Update Incorporated to ext OC zone.

A new thanx to @mystifier

Hilde

Commercial Contributions:Bulk Specials| Bulk Update Prices|Search Tyre Pro
Free Contributions: Youtube video (oc 1.5.x) | Search History Report (oc 1.5.x) | Product Filter by Category (oc 1.5.x)|Youtube Popup
More Free & commercial mods: www.fpress.com


User avatar
Active Member

Posts

Joined
Fri Mar 06, 2009 8:22 pm
Location - Spain

Post by wandotshop » Sun Jan 09, 2011 11:13 am

Hai i used this item so long.. but wonder that.. if u can check again..
lets say we already filter by category..
then when u try to delete the product.. Thick the box and click button delete... then process delete on going.. after done u can see ...all page going default which means it not come back as we filter before...
then we need to filter again.. r u miss something or u already have update your version?

i am using 1.4.9.1 .. let me know.. plz help me.. TQ

New member

Posts

Joined
Wed Oct 06, 2010 12:15 am
Who is online

Users browsing this forum: No registered users and 3 guests