Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Decorate a class isVisible method or delete the class view

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 07-23-2020, 07:55 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #2  
Old 07-24-2020, 02:21 AM
 
memoto memoto is offline
 

X-Cart team
  
Join Date: Feb 2018
Posts: 246
 

Default 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.
__________________
X-Cart Team
Reply With Quote
  #3  
Old 07-24-2020, 04:19 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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?
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #4  
Old 07-30-2020, 10:04 AM
 
memoto memoto is offline
 

X-Cart team
  
Join Date: Feb 2018
Posts: 246
 

Default 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
__________________
X-Cart Team
Reply With Quote

The following user thanks memoto for this useful post:
cflsystems (07-30-2020)
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:37 AM.

   

 
X-Cart forums © 2001-2020