VirtueMart Forum

VirtueMart Dev/Coding Central: VM1 (old version) => Development Projects, Modifications, Hacks & Tweaks. VM1.1 => Topic started by: Steve on May 27, 2007, 20:36:23 pm

Title: Product Count , Categories with One Product and Random Category Images mods
Post by: Steve on May 27, 2007, 20:36:23 pm
Here's hack for the products_in_category function in ps_product_category.php

It will also count all products in sub categories.

Code: [Select]

        function products_in_category( $category_id ) {
                if( PSHOP_SHOW_PRODUCTS_IN_CATEGORY == '1' ) {

                        $category_a = array($category_id);
                        $db2 = new ps_DB;
                        while(list($key,$val) = each($category_a)) {
                                $q2 = "SELECT category_child_id FROM #__{vm}_category_xref,jos_vm_category";
                                $q2 .= " WHERE #__{vm}_category_xref.category_parent_id=$val";
                                $q2 .= " AND category_id=category_child_id AND category_publish='Y'";
                                while ($db2->next_record()) {
                        $product_a = array();
                        foreach($category_a as $val) {
                                $q2 = "SELECT #__{vm}_product_category_xref.product_id as products";
                                $q2 .= " FROM #__{vm}_product, jos_vm_product_category_xref";
                                $q2 .= " WHERE #__{vm}_product_category_xref.category_id=$val";
                                $q2 .= " AND #__{vm}_product.product_id=#__{vm}_product_category_xref.product_id";
                                $q2 .= " AND #__{vm}_product.product_publish='Y'";
                                        while ($db2->next_record()) {
                        $num = count($product_a);
                        return " ($num) ";


                return ( "" );

Here a link to a mod I posted in another topic.

It hides a category that only has one product and no sub categories from the browse page and will list the product information when viewing the products parent category.

Here's the link to the last...

It will get a list of all the products under the current category being viewed, including all sub categories. Then it will randomly select an image to use as the Category image for that category.