X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Decorate a class isVisible method or delete the class view (https://forum.x-cart.com/showthread.php?t=77926)

cflsystems 07-23-2020 07:55 AM

Decorate a class isVisible method or delete the class view
 
I hope XC tech or someone else who faced this before can shed some light.


Here is the scenario.
There is a 3rd party Module A that adds block of html to a page. Nothing special - it extends the AView class and uses ListChild in the class to place the html block on the page
Now I need to stop this from showing the html block. So I have custom module and will have code to do this. Possible actions:

1. I can edit the template itself with the template editor and comment out the code. However I try to stay away from this. And doing it this way the class will still execute and the code will run. I don't want that. Also since this is related to the custom module it has to work only if that module is active which is not the case if template is modified through the template editor.

2. I can decorate the class from Module A and set its visible property to false.

3. OR I can use moveClassesInLists method in Main.php and delete the view for this class and list.


The question is which solution is better - 2 or 3?


With #2 I have to decorate the 3rd party class. But with this the class and its code will not run.

With #3 there is no decoration of the 3rd party module so all the code is contained within my custom module and runs conditionally anyway. However I think in this case the code from the 3rd party module View class will still run but the html block won't show because the view is deleted from the list.

So which one is better?
Both 2 and 3 work just fine and the end result is as expected. Which one though is faster and with less overhead to the cart in general. Anyone?


I am leaning more towards #2

memoto 07-24-2020 02:21 AM

Re: Decorate a class isVisible method or delete the class view
 
Reposting the dev team reply:
The #2 is "more correct" from the point of architecture. As it will allow next module to enable the template back.
The #3 is "faster" as the page will be loaded faster due to exclusion of one template. However, the time you gain with this method is extremely small and won't be much more efficient in comparison with #2.
You can use both methods, up to you.

cflsystems 07-24-2020 04:19 AM

Re: Decorate a class isVisible method or delete the class view
 
That's good info thanks.
I guess I got it wrong RE #3 - so the list view is build before anything else? And whether class runs or not depends on if it's included in the list view or not?


In case you missed that - the ListChild directive is on the class not on the template.


What if I have to do this with say 10 classes from 2-3 different modules? Is #3 going to give me more benefits?
Also to consider with 10 classes and using #2 I'll have to create 10 new files to decorate, with #3 is few lines of code in one file which exists anyway.


Judgment call on per case basis?

memoto 07-30-2020 10:04 AM

Re: Decorate a class isVisible method or delete the class view
 
I am sorry for the delay with answer.

Yes, in case of 10 classes the #3 is much better as it will solve the speed case.

As for the "template" word I used - sorry, I meant classes of course :)


All times are GMT -8. The time now is 11:55 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.