Create a custom type of filter based on the checkbox

  • Posts: 148
  • Thank you received: 21
  • Hikashop Business
1 year 2 months ago #349209

Hi,

I am trying to create a custom filter type.
This would be a copy of the 'checkbox' filter with some differences in the display (hidden option values by default, unless you click on the 'category').

I don't know if it's possible, but I had started to try by following the documentation that explains how to use the overrides.
I've made some progress (creating the filter with this new type in the backend seems ok) and I have created these files :
\administrator\templates\atum\html\com_hikashop\administrator\classes\filter.override.php
\administrator\templates\atum\html\com_hikashop\administrator\types\filter.override.php

My question is about the override in the 'classes' folder:
I have tried these classes without result:
class hikashopFilterClassOverride extends hikashopClass {
class hikashopFilterClassOverride extends hikashopFilterClass {

1) I understand that the 'displayFilter()' function is used, but is it possible to override it?
Because whatever I do, I pass in the function defined here: (~l.382)
\administrator\components\com_hikashop\classes\filter.php

Other question:
In this file, we have the code (~l.384):

$classType = 'hikashop'.ucfirst($filter->filter_type).'Class';
$class = new $classType();
$html = $class->display($filter, $divName, $parent, $datas);
2) Is there a way to call a class defined in the '\classes\filter.override.php' file ?
At the end I had tried to define/override these classes unsuccessfully:
class hikashopFilterClassOverride extends hikashopClass {
class hikashopRadiocustomClass extends hikashopFilterClass{
class hikashopCheckboxcustomClass extends hikashopRadiocustomClass{

Thanks in advance for your answer.

Please Log in or Create an account to join the conversation.

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
1 year 2 months ago #349211

Hi,

The main problem is the fact that you've placed an override file in your backend template, but not in your frontend template.
So your override is taken into account in the backend but ignored in the frontend.
What you could do is place a file in \templates\YOUR_TEMPLATE\html\com_hikashop\administrator\classes\filter.override.php
which would just include_once the file \administrator\templates\atum\html\com_hikashop\administrator\classes\filter.override.php
so that your main override would be used on both the frontend and the backend.

Then, in your override, you can even include_once the default file of HikaShop so that you could extend the default classes.
(and of course you need to add the type in the types file override to be able to select it in the backend)

The following user(s) said Thank You: FDBI

Please Log in or Create an account to join the conversation.

  • Posts: 148
  • Thank you received: 21
  • Hikashop Business
1 year 2 months ago #349282

Hi,

I was able to make progress thanks to you.

I had misunderstood the documentation about the paths (especially the one containing the folder 'administrator' but for the frontend: templates/YOUR_TEMPLATE/html/com_hikashop/admnistrator/XXXX/yyy.override.php
Sorry about that.

By the way, I think there is a small mistake in the documentation (It says 'adminstrator' instead of 'administrator').

It seems to work fine except for one class (hikashopFilterTypeClassOverride)..
In the file : \administrator\templates\atum\html\com_hikashop\administrator\classes\filter.override.php


Note: I added an 'include_once' here '\templates\YOUR_TEMPLATE\html\com_hikashop\administrator\classes\filter.override.php'

Maybe I'm not naming it correctly, I think it's a stupid mistake on my side, but I can't see where...
If you ever see what I did wrong directly, with fresh eyes, I'm interested !
Am I naming it wrong because I have to do it differently as there is a capital letter in the words 'Filter' and 'Type' ?

Please Log in or Create an account to join the conversation.

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
1 year 2 months ago #349283

Hi,

Thanks for pointing out the typo.

Regarding hikashopFilterTypeClass, overriding it depends on how you go about it.
For example, you have your class hikashopRadiocustomClass, which extends hikashopRadioClass
However, in the core filter.php file, the class hikashopRadioClass extends from hikashopFilterTypeClass
So it won't use your override class. And you can't have it use hikashopFilterTypeClassOverride from the override file with an "extends".
What you should do is make your override class as a Trait. That way, you can override the methods from hikashopFilterTypeClass in your custom classes:
www.php.net/manual/en/language.oop5.traits.php

The following user(s) said Thank You: FDBI

Please Log in or Create an account to join the conversation.

  • Posts: 148
  • Thank you received: 21
  • Hikashop Business
1 year 2 months ago #349296

Indeed, I had a problem with this relationship: 'the class hikashopRadioClass extends from hikashopFilterTypeClass'

I managed to do what I wanted and understood a lot of things with your help.

Once again, big thanks to you !

Please Log in or Create an account to join the conversation.

  • Posts: 148
  • Thank you received: 21
  • Hikashop Business
1 year 1 month ago #349449

Hi,

Sorry to bother you again with this (hopefully for the last time), but I tried to override the 'hikashopInStockCheckboxClass', to change the appearance of the 'in stock' filter, without success.

I wanted to override the 'display' function :



I added in the '\administrator\templates\atum\html\com_hikashop\administrator\classes\filter.override.php' file :

The file '\templates\r_shopin\html\com_hikashop\administrator\classes\filter.override.php' has an include of the previous one.

But this override is never called.
Do you have any idea what I am doing wrong (again...)?

Thanks in advance.

Last edit: 1 year 1 month ago by FDBI.

Please Log in or Create an account to join the conversation.

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
1 year 1 month ago #349452

Hi,

Only the main class, hikashopFilterClass can be overridden like that with the Override postfix added to it.
That's because the hikashop_get function which is used everywhere to load the file and instantiate the class in it has some code to check for the override class/file.
The type classes don't have that mechanism.
If you want to override them, you need to create a new type, like you did before with the radiocustom type.

The following user(s) said Thank You: FDBI

Please Log in or Create an account to join the conversation.

  • Posts: 148
  • Thank you received: 21
  • Hikashop Business
1 year 1 month ago #349476

Hi,

Ok thanks, I understand better

To be sure I understand, in 'filter.php', only the 'hikashopFilterClass' class would be overridable?
Not the others, even if it's a class that directly 'extends' the 'hikashopClass' class, like the 'hikashopFilterTypeClass' class ?

Please Log in or Create an account to join the conversation.

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
1 year 1 month ago #349477

Hi,

Yes. However, for the type classes, you can create new types and extend from the original types so that's a way to circumvent the limitation.

The following user(s) said Thank You: FDBI

Please Log in or Create an account to join the conversation.

  • Posts: 148
  • Thank you received: 21
  • Hikashop Business
1 year 1 month ago #349487

Noted.

Thanks to you I have made progress and I think I am very close to the end.

EDIT : I think I have identified the last problem (in the spoiler): I need to find out how to override the addFilter() function of the 'hikashopFilterTypeClass' class. I will look for a solution.

EDIT2 : Problem solved ! Thank you for your help.

Warning: Spoiler! [ Click to expand ]

Last edit: 1 year 1 month ago by FDBI. Reason: Problem solved !

Please Log in or Create an account to join the conversation.

  • Posts: 148
  • Thank you received: 21
  • Hikashop Business
1 year 1 month ago #349509

Hi,

It's me again, but I think I have a problem that is not related to what I did, but to the filters:
My filters work fine except for one category where when I change the value of a filter I get errors

This message contains confidential information

I think I have a problem with the Javascript.
If I refresh the page, everything goes back to normal.

This message contains confidential information


I removed my custom 'instock' checkbox for this category.

Note: When it bugs, a 'Search' filter appears. This filter exists (it's the one used above the menu), but it shouldn't be displayed here (if/else condition in the PHP code of the view).
My hypothesis is that the JS code breaks something that then breaks the PHP code.

Thanks in advance for your help.

Please Log in or Create an account to join the conversation.

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
1 year 1 month ago #349512

Hi,

Hard to say. Activate the "debug" setting of the Joomla configuration and the error message will display the full error message with the file where the problem is and the line number.
That should help understand what's going on.

The following user(s) said Thank You: FDBI

Please Log in or Create an account to join the conversation.

  • Posts: 148
  • Thank you received: 21
  • Hikashop Business
1 year 1 month ago #349524

Done, sorry.
Indeed, I should have started with that.



With these new informations, I tried to disabled the 'Hikashop Google Analytics 4 Plugin'.
Filter works properly in this case, even in this category.

In my live site, I have no problem (Hikashop Business 4.6.1).
In my local and test sites, I have the 'Hikashop Business 4.7.1'.

Perhaps an error that may occur in some cases between the new version of Hikashop and the plugin.

Maybe I had a too old version of the plugin, I don't know when it has been updated the last time.

So, I updated the plugin, but the problem remains:


EDIT: 'Hikashop - Google Analytics 4' debug is enabled.

Last edit: 1 year 1 month ago by FDBI. Reason: 'Hikashop - Google Analytics 4' debug is enabled.

Please Log in or Create an account to join the conversation.

  • Posts: 81504
  • Thank you received: 13064
  • MODERATOR
1 year 1 month ago #349528

Hi,

That's a problem which should be corrected in the GA4 plugin. I've made a patch in the plugin which should be the problem. Please update it again.

The following user(s) said Thank You: FDBI

Please Log in or Create an account to join the conversation.

  • Posts: 148
  • Thank you received: 21
  • Hikashop Business
1 year 1 month ago #349551

Hi,

With this latest version the problem seems to be gone.

Thank you !

Please Log in or Create an account to join the conversation.

Time to create page: 0.082 seconds
Powered by Kunena Forum