Partial fix for VM - Category module (mod_virtuemart_category)

Started by OpenGlobal, April 10, 2012, 16:31:58 PM

Previous topic - Next topic

OpenGlobal

I was going to create a new version of the VM-Category module which adds the category images, but I noticed that the current version is limited to two levels of category (parent-child) instead of being recursive. This is pretty much useless for most sites so I thought I'd just publish my changes here in the hope that they make it into the next release to fix the current problems.

First add the new param/field options to show the images:


<param name="show_images" type="radio" default="0" label="COM_VIRTUEMART_CATEGORY_SHOW_IMAGES" description="COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_DESC">
<option value="0">COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_NONE</option>
<option value="1">COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_THUMBNAILS</option>
<option value="2">COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_FULLSIZE</option>
</param>



<field name="show_images" type="radio" default="0" label="COM_VIRTUEMART_CATEGORY_SHOW_IMAGES" description="COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_DESC">
<option value="0">COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_NONE</option>
<option value="1">COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_THUMBNAILS</option>
<option value="2">COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_FULLSIZE</option>
</field>


And add the corresponding strings to the language files:


COM_VIRTUEMART_CATEGORY_SHOW_IMAGES="Show Images"
COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_DESC="Show category images (or thumbnails) next to the menu text."
COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_NONE="None"
COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_THUMBNAILS="Thumbnails"
COM_VIRTUEMART_CATEGORY_SHOW_IMAGES_FULLSIZE="Full Size"


Next add the recursive function to the end off helper.php to retrieve the category data:


function getRecursiveCategories($vendor_id, $category_id) {
        $categoryModel = VmModel::getModel('Category');
        $categories = $categoryModel->getChildCategoryList($vendor_id, $category_id);
        $categoryModel->addImages($categories);

        foreach ($categories as $category) {
                $category->childs = getRecursiveCategories($vendor_id, $category->virtuemart_category_id);
        }

        return $categories;
}


And update mod_virtuemart_category.php to call this (using the cache):


$categoryModel = VmModel::getModel('Category');
$category_id = $params->get('Parent_Category_id', 0);
$class_sfx = $params->get('class_sfx', '');
$moduleclass_sfx = $params->get('moduleclass_sfx','');
$layout = $params->get('layout','default');
$active_category_id = JRequest::getInt('virtuemart_category_id', '0');
$vendorId = '1';

$cache = JFactory::getCache('com_virtuemart','callback');
$categories = $cache->call('getRecursiveCategories', $vendorId, $category_id);

if(empty($categories)) return false;

$parentCategories = $categoryModel->getCategoryRecurse($active_category_id,0);


/* Load tmpl default */
require(JModuleHelper::getLayoutPath('mod_openglobal_virtuemart_categories',$layout));


And finally update tmpl/all.php to display the categories recursively:


<?php // no direct access
defined('_JEXEC') or die('Restricted access');

printCategories($params$categories);

function 
printCategories($params$virtuemart_categories) {
echo '<ul class="menu'.$class_sfx.'" >';
foreach ($virtuemart_categories as $category) {
$active_menu '';
$caturl JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$category->virtuemart_category_id);
$images $category->images;
if (== $params->get('show_images')) {
$image $images[0]->file_url_thumbnail;
} else if (== $params->get('show_images')) {
$image $images[0]->file_url;
}
$cattext '<img src="'.$image.'" alt="'.$category->category_name.'" /><span>'.$category->category_name.'</span>';

if (in_array$category->virtuemart_category_id$parentCategories)) {
$active_menu 'class="active"';
}
echo '<li '.$active_menu.'><div>'.JHTML::link($caturl$cattext).'</div>';
if ($category->childs) {
printCategories($params$category->childs);
}
echo '</li>';
}
echo '</ul>';
}


I haven't updated the default.php or current.php layouts yet because I'm not entirely sure what these layouts are trying to achieve, and I suspect the javascript will make these layouts much more complicated.

Is there any chance that these changes could make it into the next release? At least the recursive fixes if not the "show images" feature because two level categories is no use to anybody.

OpenGlobal

Studio 42

HI,
Tks for the code but it's a will to do a 2 category module only, because it's faster and only some website have more then 2 levels.
YOu can at same publish it XX times without problem, if you have XX main category. to have 3 levels.
I know some have 4 or more level, but this is not the most case and are not very userfriendly ;)

OpenGlobal

Maybe a config parameter should be added to switch between two-level and recursive.

If virtuemart can't handle recursive categories, it suggest it can't handle very many products either. Probably not a good message to be sending out.

OpenGlobal

simbus82

Quote from: openglobal on April 10, 2012, 19:02:00 PM
Maybe a config parameter should be added to switch between two-level and recursive.

If virtuemart can't handle recursive categories, it suggest it can't handle very many products either. Probably not a good message to be sending out.

OpenGlobal

i have to quote. Recursive is so slow? or queries-hungry?

I think an application could be more future-proof.
Joomla! 2.5.16 & VM 2.0.24b

Milbo

Hmmm I must I wonder about this myself, because we cache the category tree and it is quite fast even wtih 700 categories and 4 levels.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

lipes

in BE we got 3 views:
"all" -> Displays all Products Categories and Sub category (without slide down)
"current" -> Displays The Current View Sub Categorys (open - dlide down) and also the Others Main Categories (not Open)
"default" -> This dont do nothing! i cant find different from current view...

So... How about build a Option View only to Displaying the Current Sub-Categories (2nd level) and Hidding the Others 1st Level Categories ??
VM V. online: J2.5.14 | VM 2.0.20a | SQL 5.1.70 | PHP 5.3.25

tinfoilball

Only 2 Category levels. This is insane. With that said VM I know its free, its a great extension, but something is not quite right. Here's an exert from the about for VM:

With its fully-featured eCommerce engine, VirtueMart is perfect to sell your Goods online and drive your Business to new Heights. Despite being Open Source Software it powers large Online Shops providing the Performance, Usability and Security you expect from professional Software.

Can we have Flexibility added into the about us statement? And take out "Despite being Open Source Software"? Open source software is not inferior to other software. 70% of the worlds websites are served with Open Source Software.

Here's a fundamental thought. If more than two category levels is to many it would be really interesting to know how many second level categories is unmanageable to the detriment of customer usability? Also, what number of products within each second level category would be considered unmanageable and cause the UX to suffer?

Once limits are reached, second level cat or number of products per cat (which ever comes first) then what are the alternatives?


  • Bin Virtuemart? No wait, VM can be extended.
  • Don't upgrade? You'll have to shoehorn all your categories in to a 2 level structure.
  • Add some bloatwear to manage things a different way? Still end up slowing the website down.
  • Go hack mad and waver the pleasure of automatic updates? Oh and the J!1.5/VM1 nightmares starts all over again
  • Close the door to new product suppliers? Sorry we're full! Here's the URL of our competitor
  • Do what twitter does, put an overloaded notice on the front of the site? We can't fit in our site our categories are bursting
  • Scrap multiple categories just pop them all in one and use a Cherry Picker/CustomFields or a big search bar? It works for Google and Amazon
  • Close your website and buy yourself a set of Russian Dolls at leased they have more levels

Seriously though, two levels, this can't be right can it! This is regressive.

What exactly is considered to be the measure of a "large Online Shop"? I mean how do you measure that?

Milbo

lol sorry, but with very low knowledge you can change the deep of the level yourself, there is just an option missing.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

tinfoilball