VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: SteP[IT] on November 23, 2015, 13:11:40 PM

Title: [SOLVED] Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 23, 2015, 13:11:40 PM
Since few releases (currently using 3.0.12 on J 3.4.5, Firefox 42.0) I noticed an issue in subcategory drop-down list when adding or deleting categories.
If you add a new category or delete an old one, that change doesn't immediately appear into the subcategory drop-down list when adding a new category or modifing an old one. So If i add a category then look for it in drop down, it is not there, and if I delete a category I still find it listed in that dropdown.
I have no cache configured in Joomla (previously set to "PHP alternative" but currently disabled), no cache plugins active... this is weird when adding several categories, I have to modify the db table to assign any new one to it's correct parent, or wait until it will appear after long time
Is there a way to solve it?
Regards
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: GJC Web Design on November 23, 2015, 15:04:57 PM
is it caching?  clear cache?
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 23, 2015, 15:57:12 PM
I wrote in previous post that the cache is NOT activated. I have anyway cleaned that site and the browser cache
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: GJC Web Design on November 23, 2015, 16:14:20 PM
cats are always cached frontend if switched on or off in Joomla config

is the BE the same.?  see if vm cats files are formed in your cache/ folder
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 24, 2015, 08:45:22 AM
I presume it's a cache problem, but this should not be the right way to get category trees in backend: every time I add a new dir, I must look for cache and delete it, or wait until it will expire...
Could please Max help us to look in the right direction to solve this annoing feature?
I don't see any other report about this, so I can't understand if it's a voluntary designed way to work in BE or if it's a misconfiguration of my installation/webserver (latest Apache 2.4.x).
Any help will be really appreciated
Thank you in advance
Regards
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: balai on November 24, 2015, 10:14:30 AM
QuoteI presume it's a cache problem, but this should not be the right way to get category trees in backend: every time I add a new dir, I must look for cache and delete it, or wait until it will expire...
Could please Max help us to look in the right direction to solve this annoing feature?

It is definitely cache.
From my point of view there is no better approach than this.
If the categories are not save into cache then the whole tree has to be re-created every time somebody visits your site.
That means database queries, extra processes, cpu, ram...i.e. time

I don' t know if you are familiar with other systems like Magento.
There everything is cached and for every little change you have to refresh your cache
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: GJC Web Design on November 24, 2015, 10:20:12 AM
perhaps in the getcats function if this is what returns the admin cats

public function getCategories($onlyPublished = true, $parentId = false, $childId = false, $keyword = "", $vendorId = false)

around line 363  \administrator\components\com_virtuemart\models\category.php

$app = JFactory::getApplication ();
      
               if(!isset($cats[$hash]) || $app->isAdmin()){
         $cats[$hash] = $this->_category_tree = $this->exeSortSearchListQuery(0,$select,$joinedTables,$whereString,'GROUP BY virtuemart_category_id',$ordering );
      }

???  not tested in any way
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 24, 2015, 10:32:41 AM
Quote from: balai on November 24, 2015, 10:14:30 AM
Quote
I don' t know if you are familiar with other systems like Magento.
There everything is cached and for every little change you have to refresh your cache

I usually work on Magento too, for more complex sites.
But Magento has the clear cache function specifically forged to that purpose.
In my VM installation, I have ALL site caches OFF. How to clear the BE cat cache in that situation? I can't see any specific VM function to be used for.
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: jenkinhill on November 24, 2015, 10:40:18 AM
I have used this for sites where caching is an issue:  http://extensions.joomla.org/extension/cache-cleaner

It has a useful setting:  Cleans the cache if you save (or apply) something
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 24, 2015, 10:44:11 AM
Thank you jenkinhill, I'll give it a try.
But I suggest Max to consider this tread like a "feature request": VM backend should have it's proper way to clear cache, without the needing of using another extension :)
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: balai on November 24, 2015, 11:30:29 AM
You don't need a 3rd party to clean your cache.
Cache is a joomla component and has it's own section in the joomla backend
System > Clear Cache
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: AH on November 24, 2015, 11:54:53 AM
Exactly - Joomla has this capability built in!
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: jenkinhill on November 24, 2015, 12:12:26 PM
The advantage with the plugin is that you don't have to take any other steps, you just save or apply whatever you are doing and the cache is automatically cleared.
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 24, 2015, 12:24:26 PM
uhm... do you read my post??? I have NO cache activated (no plugin, no joomla configurable cache, NOTHING). I can't simply clear the cache, I HAVE NO CACHE to delete.
Joomla cache is deactivated, template caches and plugin ones too...
It's an admin side problem, for me.
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: GJC Web Design on November 24, 2015, 12:45:16 PM
I wonder if YOU read our posts?

the cats cache is on and there... there is no config for it and the Joomla settings have nothing to do with it

look in your cache folder!  what do u see?  a folder com_virtuemart_cats with cached cats

why are u so stubborn? I suggested a fix.. did u try it?
otherwise Jenks suggested a plugin that puts a button at the top of your admin page where u can dump the cache.. have u tried it?
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 24, 2015, 12:49:26 PM
Keep calm and please DON'T suspect I was referring to you all: it was a reply to the last balai post before my one, indicating me to clear the cache by Joomla function.
My only mystake has been to have NOT quoted him.
Regards
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: AH on November 24, 2015, 13:07:01 PM
Quoteuhm... do you read my post??? I have NO cache activated (no plugin, no joomla configurable cache, NOTHING). I can't simply clear the cache, I HAVE NO CACHE to delete.
Joomla cache is deactivated, template caches and plugin ones too...
It's an admin side problem, for me.

We have read your post and replied with suggestions.

It would help if your next post starts with - "I have tried everything suggested relating to cache and clearing of the same"

;)

Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: balai on November 24, 2015, 13:47:25 PM
Quote from: SteP[IT] on November 24, 2015, 12:49:26 PM
Keep calm and please DON'T suspect I was referring to you all: it was a reply to the last balai post before my one, indicating me to clear the cache by Joomla function.
My only mystake has been to have NOT quoted him.
Regards

What my post differentiates from jenkinhill's and AH's
Please read carefully. I think there is a bunch of posts about a very simple issue which probably you cannot understand.
Either clarify exactly what happens in your system and what does not work from the suggested solutions or you can stop reproducing the same things again and again.
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 24, 2015, 14:43:46 PM
Balai, I have no time and no intention to blame anyone, but I'm still able to read correctly what people writes ;)
In your previous post you suggested to clear the system > cache: some posts before your one I clearly told I already made that without solving my problem. What makes you aware I was not knowing the "very simple solution" you refer to? What was NOT clear in my post? This is the difference between your post ans jenkinhill's and AH's ones. Am I wrong? I'm not so stupid to post here a question that can be solved simply clearing the system cache  ;)
And be sure that I have read all other suggestions: I'm now out of my office and I'll test them asap, when I'll be back to office.
I'll keep you updated about.
Regards
And obviously thank you all for helping me anyway  :D
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: AH on November 24, 2015, 17:45:38 PM
StepIT

Thank you for the update - keep us posted.

In the meantime I  will see what happens on my test version using vm3.0.12 and j 3.4.5
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: lindapowers on November 24, 2015, 17:47:05 PM
We dont use cache either and yes vm categories are cached, where is the issue?

Are you creating categories and subcategories all day? You need to clean them system/clean cache/com_virtuemart_cats and clean cache in your browser. That works for us, but to be honest we don't even clear cache, is done anyway.
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 24, 2015, 18:02:36 PM
For AH:
First update: I have made the suggested change to the \administrator\components\com_virtuemart\models\category.php file on one live site, but not deeply tested it: at a first look, it seems it solved the persistance of wrong listing of changed/deleted cat data in drop down cat list. I have to make further test before say "hurrĂ " :) ..I'll post further update when ready
Regards

For lindapowers:
I have to add/delete new categories/products frequently, and I reported the problem because it arises immediately when adding more categories one after one.
In my case, I have to add nested categories frequently: in that case, the problem arise when adding one category everywhere in the tree, and then adding a further son category to that one. After the first category is added, I can't see it in cat list when adding a son category to it. So to assign the son to its father I must modify the sql table. I have cleaned all available caches, both in Joomla and in browsers, but it doesn't help. I have also tested it in IE an Chrome, having the same issue.
The same happens when deleting a category: it still appears in the drop list after its deletion
But also supposing that cache deletion would work, it's very annoing to delete it every time you add/change/delete one single category: this is why I think that drop down list should not be cached in admin side, or cache should be refreshed after any cat modification (addition, change or deletion)
Title: Re: Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 25, 2015, 08:17:43 AM
Quote from: GJC Web Design on November 24, 2015, 10:20:12 AM
perhaps in the getcats function if this is what returns the admin cats

public function getCategories($onlyPublished = true, $parentId = false, $childId = false, $keyword = "", $vendorId = false)

around line 363  \administrator\components\com_virtuemart\models\category.php

$app = JFactory::getApplication ();
      
               if(!isset($cats[$hash]) || $app->isAdmin()){
         $cats[$hash] = $this->_category_tree = $this->exeSortSearchListQuery(0,$select,$joinedTables,$whereString,'GROUP BY virtuemart_category_id',$ordering );
      }

???  not tested in any way

I can confirm that, after this patch, it seems to works now as expected: there is no more any delay in displaying recently added cat in drop down. I can now add a cat and then see it immediately in dropdown when adding a new son to it.

May be it could be revised (if necessary) and then added to the next VM build?

Thank you all for your support
Regards
Title: Re: [SOLVED] Subcategory list drop-down not updated when adding or deleting category
Post by: AH on November 25, 2015, 09:54:11 AM
Stepit

Thanks for taking the time to test and respond. 

I have asked the devs if this is the best solution and might be considered for future updates.
Title: Re: [SOLVED] Subcategory list drop-down not updated when adding or deleting category
Post by: Milbo on November 25, 2015, 10:29:42 AM
The question is different.

First: The category tree is always cached by the joomla cache regardless your config of the joomla cache.
Second: The cache should be deleted automatically, when
- The config is stored
- category created, deleted, moved

There was a thread about this already. So the question is only:

Why does the deletion of the cache not work! What is wrong with

$cache = JFactory::getCache('com_virtuemart_cats','callback');
$cache->clean();


and if someone comes with a solution, please remind, we need a j2.5 and j3 solution.

https://forum.virtuemart.net/index.php?topic=129548.msg450023#msg450023

Title: Re: [SOLVED] Subcategory list drop-down not updated when adding or deleting category
Post by: SteP[IT] on November 25, 2015, 10:58:55 AM
Hi Milbo
After your post, I have looked at the code you underlined.
I see that code is activated ONLY when the condition if($useCache) is true.
But in my case I have no cache set up in my website (neither Joomla or any other kind of plugin driven cache)...
So I moved upper those 2 line of code, out of the "if" statment, and obviously it now also works in my case too.
Being them inside the if is strictly required?
Title: Re: [SOLVED] Subcategory list drop-down not updated when adding or deleting category
Post by: Milbo on November 25, 2015, 13:08:52 PM
cant find anything there. You look for the function which creates the cache.

It is not a solution for me to disable a feature. We do not call that a fix, it is a remove.

Maybe the error is completly different, how about this?


$this->clearCategoryRelatedCaches();


and the function is

public function clearCategoryRelatedCaches(){
$cache = JFactory::getCache();
$cache->clean('com_virtuemart_cats');
$cache->clean('mod_virtuemart_product');
$cache->clean('mod_virtuemart_category');
}
Title: Re: [SOLVED] Subcategory list drop-down not updated when adding or deleting category
Post by: Studio 42 on November 25, 2015, 22:41:24 PM
Hi devs.
If you need a full working solution, copy the com_cache model function getCache and add it as an helper or how you want.
This is exactly the same system from Joomla 2.5 to Joomla 3.4.5 !
I had send sometime a derived code, but seems this was not working always, but i'm sure that this function is working for any Joomla release with cache active or not!
You loose more time to answer in the Forum as copy/paste this Joomla core code ;)
Title: Re: [SOLVED] Subcategory list drop-down not updated when adding or deleting category
Post by: Studio 42 on November 25, 2015, 22:49:34 PM
For SteP[IT],
I know you have tested to clean cache.
But i had some customer simply forgot to check the files to remove or dont pushed the "delete" button and was wonderign that the cache was not clearer.
This is because in Wordpress you don't need to press the "delete" button ;)