aligent / orocommerce-announcement-bundle

Site-wide announcement banners in OroCommerce
GNU General Public License v3.0
1 stars 0 forks source link

Re-display Alerts when new Announcements are added #9

Open chrisaligent opened 2 years ago

chrisaligent commented 2 years ago

At the moment only a single hideAlert session variable is used to determine whether an announcement has been closed/dismissed by the User. Upon clicking the Close button, this session variable is set:

sessionStorage.setItem('hideAlert', true);

However this means that if the current Announcement was dismissed one day, if a new Announcement is added the next day it won't be displayed to the Customer because hideAlert already equals true. NOTE: sessionStorage lasts until the user's browser is closed.

The simplest workaround to this is to add a unique identifier to the hideAlert session variable, potentially the Content Block ID as there's (currently) no unique ID for individual Announcements.

This would require changes to the Layout DataProvider to inject the Content Block ID into the template and make it available via a data-js selector. The Javascript can then be modified to access this ID and use it in place of hideAlert. e.g.: hideAlert-27.

This relies on a new Content Block being created for each new Announcement instead of editing the copy of the an old Content Block, but this shouldn't be an issue.

chrisaligent commented 2 years ago

An alternative approach might be (in the Layout DataProvider) generate a hash of the content itself and return this as the Unique Identifier. However this means that the variable name would change even if only tiny changes are made to the Content Block content, and the Announcement would be displayed to all Customers again.