Author Topic: Fatal Error after installation/update VM2.0.24b: Using $this when not in object  (Read 11615 times)


  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 26091
  • Always on vacation
    • Jenkin Hill Internet
Fatal error: Using $this when not in object context in **\[site path]\administrator\components\com_virtuemart\models\category.php on line 121

The error indicates that the aio component has not been updated, as you must update the modules, too.
Alternatively you are using overrides which need updating. The following is from the liveupdate info on how to update mod_virtuemart_category.php if it is included in your 3rd party module:

Please search for
JFactory::getCache and delete this line. If you are unsure about this, you can skip this step.
Search also for
$cache->call( array( 'VirtueMartModelCategory', 'getChildCategoryList' ),$vendorId, $category->virtuemart_category_id );
and replace it by
VmModel::getModel('category')->getChildCategoryList($vendorId, $category->virtuemart_category_id );

Be aware it can be also $child instead of $category. the part behind getChildCategoryList stays the same. This change enhances in some stores drastically the speed. For more information or if you need help, you may read here

Jenkin Hill Internet,
Keswick, Lake District

Unsolicited PMs/emails will be ignored.

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Currently using VM3.2.3.9614 on Joomla 3.7.4 PHP 7.0.22

Testing VM3.2.3.9614 on J!3.7.4


  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9178
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Thank you jenkinhill,

I found an easier solution, so that no one has to edit his files. The file is attached. This file is included since 2.0.24C

The reason for this trouble are not the template overrides. We have two effects here with the same cause. I did not expect that soo many people still use the categories view or just copied the vm module instead just to provide another layout.

Be sure that you updated also your VirtueMart AIO, if you still have trouble, read on.

What we did is just to exchange the calls using the cache and implemented the usement of the cache directly in the model. The advantage is that 3rd party developers do not have to think anylonger about caching, it is just done for them. But there is a problem, when the old method is used for the new function.

The error comes due category MODULES and the view categories!
In case of the module, we only changed the call in the mod_virtuemart_category.php. the layouts should still work. The problem is that people/3rd party devs copied the whole module to create their own.
The other problem is that we declared the view "categorieS" as obsolete. So our change is not done for the categories view, which is still used. To be prepared for the future, use the category view instead. If you want to know how to get the categories view with the category view, please read here

I created a new category model, which is checking in the function if it is called as cached or if it should call the cache itself. We will remove this legacy for vm2.1 then. Therefore I post here the explanation how to adjust your old code. To underline, you do not need to change any core code, except the view.htm.php of the categories view, if you still want to use it. But we strongly recommended to use the category view with the categories layout.

1. Find the affected files. Search for JFactory::getCache('_virtuemart') or JFactory::getCache('com_virtuemart') or JFactory::getCache('com_virtuemart','callback') in your category modules and overrides.

2. Delete $cache = JFactory::getCache('com_virtuemart','callback'); , usually it is just one line. A dirty 3rd party dev may wrote more stuff behind the ; then let that stay

3. In the same file in which you found the getCache() is the cache used, usually like this

this $categories = $cache->call( array( 'VirtueMartModelCategory', 'getChildCategoryList' ),$vendorId, $category->virtuemart_category_id );

change it to $categories= VmModel::getModel('category')->getChildCategoryList($vendorId, $category->virtuemart_category_id );

sometimes it is written that way $childs = $cache->call( array( 'VirtueMartModelCategory', 'getChildCategoryList' ),$virtuemart_vendor_id,$child->virtuemart_category_id

Then use of course the other parameters.
$childs = VmModel::getModel('category')->getChildCategoryList($virtuemart_vendor_id, $child->virtuemart_category_id );
But the pattern is always the same.

or totally abstract:

$x =  $cache->call( array( 'VirtueMartModelCategory', 'getChildCategoryList' ),$param1, $param2 );


$x= VmModel::getModel('category')->getChildCategoryList($param1, $param2 );

Be aware you do not need todo this now. In case you bought a template or a module it is very likely that the 3rd party developer provides a patch for upcoming versions, so long just use the attached file, remove the suffix ".txt" and copy it to /administrator/components/com_virtuemart/models

[attachment cleanup by admin]
I should fix your bug, please support the VirtueMart project and become a member
Extensions approved by the core team: