aligent / orocommerce-announcement-bundle

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

Ability to configure multiple Announcements for different scenarios #12

Open chrisaligent opened 2 years ago

chrisaligent commented 2 years ago

Currently it's only possible to have a single Announcement running at a time.

So it's not possible to have different Announcements for Guests vs Logged-In Customers, or a specific Customer Group.

It should be possible to setup multiple announcements with different criteria, essentially making the current Configuration settings part of a Configuration Collection. The Layout DataProvider can load the configuration and determine which Announcements to display to the current Customer.

However this presents a challenge, if the DataProvider returns multiple applicable Announcements then it will break the template.

So, a decision needs to first be made as to whether we should:

chrisaligent commented 2 years ago

I was fairly easily able to prototype a Slider for announcements, although this would require additional frontend development to finish off. Recording 2022-08-16 at 16 42 37

Rather than using System Configuration for these Announcements, they may be best moved to a new Entity (ie AligentAnnouncement).

Each Announcement should include:

(Later, additional settings can be added, e.g. #10, #11 ).

We may also be able to add more announcement positions in future, such as "top of page", "below nav menu", "in checkout", "in category/webcatalog node", "above shipping methods", "above payment methods", etc.

The System Configuration can be used for:

The "Background colour" setting would instead become part of the WYSIWYG content itself, eg: 2022-08-16_17-14 2022-08-16_17-14_1

(This would allow us to render previews in the admin panel if needed)

Potential Development Tasks

chrisaligent commented 2 years ago

Progress Update

I have completed adding the new AligentAnnouncement Entity. Instead of using startDate and endDate, I have used the Oro ScheduleIntervalInterface on a linked entity called AligentAnnouncementSchedule, which will let us use a filtration service to filter to active Announcements. I have also used Oro scopes (Oro\Bundle\ScopeBundle\Entity\Scope) to restrict to Customer, CustomerGroup, and/or Website (if on Enterprise Edition). This should allow Oro to do most of the heavy lifting here.

Additionally the Announcements are now Organization-scoped as is Oro best practice. Changes pushed to https://github.com/aligent/orocommerce-announcement-bundle/tree/feature/multiple-announcement-boilerplate

Proceeding to work on CRUD UI as this will determine how much effort may be needed to use Scopes/Schedules.

chrisaligent commented 2 years ago

Progress Update

I now have scheduled Announcements working. I have tested this by adding multiple Schedules to an Announcement: 2022-08-23_17-00 I loaded the page at 4:56pm and the announcement was visible. At 4:47pm it disappeared. It reappeared at 5:01pm. I changed my User Configuration to a different timezone and confirmed that the Schedule updated to match my local time (from 4:57pm to 5:27pm), which confirms that schedules are being stored/managed in UTC: 2022-08-23_16-59

Multiple Announcements are displayed as expected: Recording 2022-08-23 at 16 57 41

However, Scopes are unreliable. Oro doesn't seem to like setting multiple Scopes, only the first Scope appears to be used. So setting an Announcement to be visible by multiple Customer Groups does not work (ie "x OR y" instead of "x AND y"). So this will take additional effort to resolve, I'm unsure how this works in other parts of the Oro codebase (eg Pages, Promotions etc).