If this is your first visit, check our documentation. To post, register or login.
Forums / Zen Cart Code Suggestions / Add notifier to specials, salemaker, and featured product functions

Add notifier to specials, salemaker, and featured product functions

Started by numinix on 21 Jan 2014, 4:29 AM · Views: 148

Results 1 to 12 of 12
21 Jan 2014, 4:29 AM
#1
numinix avatar

numinix

Totally Zenned

Join Date:
Apr 2007
Location:
Vancouver, Canada
Posts:
1,572
Plugin Contributions:
60

Add notifier to specials, salemaker, and featured product functions

When a special, sale, or featured product is turned on/off automatically, a notifier should run.

I'll use an example for why this is important, other applications will surely exist:

If a store is using disk caching, the change may not take immediate effect until the administrator manually forces the cache to reset. If a notifier existed, it would be possible to create an observer that will execute the cache clearing function automatically.

Other applications may include creating an observer that sends out an email to customers who registered to receive notifications when a sale is activated.

21 Jan 2014, 1:11 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,140
Plugin Contributions:
56

Re: Add notifier to specials, salemaker, and featured product functions

Sounds like a great idea!

26 Aug 2014, 3:26 PM
#3
philou avatar

philou

Zen Follower

Join Date:
Jan 2006
Posts:
165
Plugin Contributions:
1

Re: Add notifier to specials, salemaker, and featured product functions

Hi there,

while developing my ZC plugin BookX which will soon leave the beta stage I find that I have to distribute a few files with my plugin which are ZC core files, simply because I need a notifier hook in the files in order to use the observer feature of ZC.

Couldn't notifiers be added in pretty much every ZC file, be it template / module / page header / etc or would the the overhead be too great?

Specifically I am adding BEGIN and END notifiers to
/common/tpl_tabular_display.php
[ADMIN]/includes/modules/category_product_listing.php
[CATALOG]/includes/modules/product_listing_alpha_sorter.php

If ZC offers this rather powerful observer feature, then it seems a contradiction not to heavily populate the code with notifiers, so the feature can be used?

I feel that distributing ZC core files with my plugin is not a good solution :-)

Best regards,
p.

26 Aug 2014, 5:58 PM
#4
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,904
Plugin Contributions:
23

Re: Add notifier to specials, salemaker, and featured product functions

philou,
Be sure you have a look at http://www.zen-cart.com/downloads.php?do=file&id=1393. A copy is beside me at all times. You may find ways around changing the core files.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

1 Sep 2014, 4:09 PM
#5
s_p_ike avatar

s_p_ike

Zen Follower

Join Date:
Feb 2005
Location:
Italy
Posts:
178
Plugin Contributions:
0

Re: Add notifier to specials, salemaker, and featured product functions

dbltoe, I agree that override allow not to change core files, but the observer / notifier method is much more powerful and the code easier to mantain. If you rely on the override system, you may be forced to update your plugin if one of the files in override get updated even if the part that has been modified doesn't affect your plugin.

Paolo De Dionigi
Co-maintainer of Zen Cart Italia

1 Sep 2014, 9:51 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Add notifier to specials, salemaker, and featured product functions

s_p_ike:

dbltoe, I agree that override allow not to change core files, but the observer / notifier method is much more powerful and the code easier to mantain. If you rely on the override system, you may be forced to update your plugin if one of the files in override get updated even if the part that has been modified doesn't affect your plugin.

Whether intended or not, I understood dbltoe's comment to suggest looking in other places to possibly add or find ways to use the notifier or other system without having to provide say core files to replace existing ones. Or good documentation to identify how/where to insert instead of over writing files...but then again, sometimes you gotta do, what you gotta do.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

2 Sep 2014, 2:59 AM
#7
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,904
Plugin Contributions:
23

Re: Add notifier to specials, salemaker, and featured product functions

Specifically I am adding BEGIN and END notifiers to
/common/tpl_tabular_display.php
[ADMIN]/includes/modules/category_product_listing.php
[CATALOG]/includes/modules/product_listing_alpha_sorter.phpAssuming (I know) that the first line should be includes/templates/_CUSTOM/common/tpl_tabular_display.php, let's talk about it first. It must go to other than the template_default or it will be lost with any template. Therefore it technically requires an override.
We do not have admin file override capability as yet so the second file will have to be an overwrite vs override. Make sure the changes are clearly marked so they can be found later if needed.
The third file would again be under an override folder of includes/modules/CUSTOM/product_listing_alpha_sorter.php. It would be the core file properly edited with the new information clearly marked.
As Zen Cart currently stands (1.5.#), that is the recommended way to build a mod.
The link I posted also points out the areas that you can even add observers and actions without touching core files. It's not as simple as "look for a classic folder and that shows an area that can be overridden." There are several folders that can be overridden that make no mention of "classic."

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

2 Sep 2014, 8:04 AM
#8
s_p_ike avatar

s_p_ike

Zen Follower

Join Date:
Feb 2005
Location:
Italy
Posts:
178
Plugin Contributions:
0

Re: Add notifier to specials, salemaker, and featured product functions

I understand the point and I technically agree, but the suggestion is to place more notifier, even in those files that may be override (this is my thought), since with those notifier in place you don't need to override them and don't need to take care of those files in your plugin.
About the link you posted, thank you. I thought was just a matter of overrides so I didn't checked. Now I looked at it and it's useful, especially when you have to introduce someone to Zen Cart development.

Paolo De Dionigi
Co-maintainer of Zen Cart Italia

9 Sep 2014, 10:37 PM
#9
philou avatar

philou

Zen Follower

Join Date:
Jan 2006
Posts:
165
Plugin Contributions:
1

Re: Add notifier to specials, salemaker, and featured product functions

Many thanks for your comments. I shall look in more depth at dbltoes link, to see if it will give me some ideas of how to implement my observers without having to insert my own notifier hooks.

I think I have a pretty good understanding of the override system, but I want to avoid overrides wherever I can in my plugin. It is not very user friendly and also easy to introduce errors, when users have to manually edit / override files. My point was, that a powerful feature like the observer system seems to be crippled if there aren't enough notifier hooks in the code. Unless it is a big overhead, why not place at least BEGIN and END notifiers in most files, and maybe some in the middle like BEGIN_BUILD_QUERY and END_BUILD_QUERY.

I have also noticed that a file where I needed a notifier had changed from ZC 1.5.0 to 1.5.3, so which modified file do I include in my plugin distribution or base my modification instructions on? I remember when I started as a newbie on ZC, I was never that happy having to modify all these files for an add-on to work.

Anyway, observers have already made my add-on much cleaner than it would have been just with overrides, so I'm already happy about that :)

p.

16 May 2016, 3:57 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Add notifier to specials, salemaker, and featured product functions

FYI, a lot of these improvements were included in v1.5.5

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

17 May 2016, 8:13 AM
#11
s_p_ike avatar

s_p_ike

Zen Follower

Join Date:
Feb 2005
Location:
Italy
Posts:
178
Plugin Contributions:
0

Re: Add notifier to specials, salemaker, and featured product functions

I forgot this thread, now with last reply by DrByte, I was notified, so I re-read it again and I focused on the sentence by Numinix about disk caching. On a very customized site, I managed to use Redis to store products informations in json format. We could bring in as many notifiers as we wanted, but we choose another approach since the problem would have been to modify a lot of files both in backend and frontend, with the risk to forget something. So we simply moved the check from the application level to db level, by using trigger on tables containing data used to populate the json. These triggers simply put the product id, language_id and action (update, insert, delete) of the product affected in a new table. Then there's a cron that execute a script around every 2 minutes which 'processes' this table, populates with json another new table which serve as intermediate step (fallback too, in case of Redis failure), updates Redis and then empties the first table.
This way no matter what cause a change, it's triggered.

Paolo De Dionigi
Co-maintainer of Zen Cart Italia

17 May 2016, 10:04 AM
#12
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Add notifier to specials, salemaker, and featured product functions

So, if understood correctly, I believe the issue documented in github related to this thread was left open to see if the additional notifiers requested to support bookx would be addressed or still needed incorporation. Are you saying then that there is no further need for the originally requested notifiers? (yes I can read and understand what has been written, but it is best to get a straight answer rather than assume. :))

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...