Closed pmackay closed 8 years ago
One thought could be to use https://github.com/kevinrutherford/event_bus (or are there any similar gems?) to handle broadcasting events such as order cycle finished to other parts of OFN. If some similar "action" framework could be designed, a simple "rules" engine might then be built to say "when event X happens, and condition Y is met, do Z".
I had a chat with @oeoeaio about this, and we came up with a few thoughts.
When an order cycle closes, it'd be nice to show a different interface to the admin when they edit that order cycle. Instead of providing them with all the options, we could just give them two buttons - "Reopen / extend" and "Send producer notification emails".
There's a question of how to store the notification settings. I'd prefer not to add extra fields to the OrderCycle and Enterprise models, since this would mix notification concerns with those models and violate SRP. Instead, we could use the Spree Preferences system, described here: http://guides.spreecommerce.com/developer/preferences.html .
It'd be great to have editable email templates for these notifications and others in the system. But it's probably out of scope for this feature. However, it could easily be retrofitted when we get something built.
It'd be best to have the email task running in a background job. I've had a look, and it looks like DelayedJob
would be the best library to get started with, using explicit job classes rather than the .delay
syntax. This is something I could set up if you need a hand.
I like the idea of using event bus or something similar. We wouldn't necessarily need to jump straight to building a rules engine, but could just use a class that listens to an order cycle closing event.
I'm not quite sure what you're specifying for point 5. Could you elaborate on that one?
@RohanM I think (5) was that a few emails to some producers need to list each specific order from each customer, rather than the aggregate total the producer needs to provide. For cases where some preparation is needed or stuff like that.
@RohanM was looking at background processing and found Sidekiq. Sounds like to might be a more effective choice than delayedjob?
http://blog.statuspage.io/kicking-ass-with-sidekiq
Or would you favour delayedjob as it doesn't require redis?
Looking at the email content, I have this so far:
Dear #{@producer.name},
We now have all the consumer orders for the food drop on #{@ready_for - check field name]
MESSAGE FIELD: Please deliver to Stroud Valley Community School, Castle Street, Stroud, GL5 2HP between 9:30am and 10:30am unless this is not convenient then please contact me on <phone>.
NB If you have to arrange a different delivery day and time, the school has requested that you do not
come on site during drop off/pick up times (8:45-9:15 and 15:00-15:30)
REPORT SECTION: Here is a summary of the orders for your products:
[insert report content]
MESSAGE FIELD: Please confirm that you have got this email.
Please send me an invoice for this amount so we can send you payment.
CONTACT INFO: [This below could either be included in message field, or could be adapted from the auto generation in the order confirmation email e.g. just print name, phone and email of contact person]
If you need to phone on the day please call #{@coordinator.phone}.
Thanks and best wishes - #{@coordinator.name}
Issues I have:
Not sure how to represent the drop off day and time in an order cycle.
There are some quite specific details in the text. How to best define this as a template in code? 3 possible options:
Around point 5, could we avoid adding more configuration by sending both reports (per-customer and aggregate numbers) to all producers? It'd be nice to keep the complexity down if that would work.
I had a look into Sidekiq, and that article makes some good points. However, I don't think they apply to our situation. Here's a summary of my thoughts:
.delay
syntax.Because of those reasons, I'm inclined to go with DJ over Sidekiq.
the drop off day and time in an order cycle can be pulled from the field set against outgoing Distributor. This is different from the information needed by a producer though e.g. the time the food is needed could actually be the day before, and the time would definitely be earlier. We don't currently have fields for this, but Rohan is about to send through an idea . .
It looks like we'll want some way to edit the template. Depending on a few details below, my inclination would be to go with total editing of the template, using mustache or similar (not erb since it allows execution of Ruby code).
I suspect we'll need different templates per enterprise. Then in the order cycle, you'd be able to choose from two options:
In the scenario where all food is dropped at the coordinating enterprise's location, emails could be sent to producers using the coordinator enterprise's template.
In the scenario where food is dropped to each hub in the order cycle, emails could be sent to producers where the report is broken down by hub enterprise, since each of those will be a separate drop-off. In that case, maybe we use the template from each hub enterprise in turn to provide drop-off locations etc.
That's still feeling a bit fuzzy to me (there's a few details I'm not sure about), but may be a good starting point for discussion.
@RohanM does that imply adding a new multi-line field to Enterprise?
Would it make sense to define Notifications as a separate entity, similar to Fees, Payment methods, Shipping methods on an Enterprise view? Not another Enterprise field but associated with it? Although presumably they would still need to be specific to an Enterprise, rather than general and selected to be used by an Enterprise?
maybe - I think will be good to check this one with @oeoeaio as he's starting work on an Enterprise 'preferences pane' this week - where Enterprises can record some options. could be that notifications, emails messages etc are part of this interface?
When testing this I have created a new ("July") order cycle on staging 2 which includes 6 producers. I made sure the producer emails were coming to me and put in a test order which included products for just 2 producers (Days Cottage and Jessies Ladies). When I click on ‘NOTIFY PRODUCERS’ it all looks good but then when the emails come through I get 6 emails all coming to ‘Nick’s test producer’ which is the first producer on the list of 6 producers on that order cycle. None of the emails have any product details (see example below).
When I changed the email address for Days Cottage to Carol’s email and pressed the ‘NOTIFY PRODUCERS’ button again, I still got 6 blank emails to ‘Nick’s testing producer’ and no email to Carol.
I have now received 18 emails all exactly like the one below, even though i only did the ‘NOTIFY PRODUCERS’ process twice
Please let me know if I am doing something wrong or if there is anything else I can try
Thanks Nick
-----Original Message----- From: admin@openfoodweb.org [mailto:admin@openfoodweb.org] Sent: 13 July 2015 12:13 To: nick@stroudco.org.uk Cc: nick@stroudco.org.uk Subject: [Staging 2] Order cycle report
Dear Nick testing producer,
We now have all the consumer orders for next food drop. Please drop off your delivery at . Please deliver to Stroud Valley Community School, Stroud, GL5 2HP during the regular delivery time. If this is not convenient then please call 1453840037. Note: If you have to arrange a different delivery day and time, it is requested that you do not come on site during drop off/pick up times.
Here is a summary of the orders for your products:
Please confirm that you have got this email. Please send me an invoice for this amount so we can send you payment. If you need to phone on the day please call 1453840037.
Thanks and best wishes - Stroudco
Just to let you know I am still receiving emails of this blank order summary. So far I have received 38 of them. They come through in batches every 3-5 hours. Curious!
As a workaround to #406 there was talk on todays Skype for StroudCo to have two Hubs with the same order cycle. One hub with an outgoing fee of 12% that is hidden unless you are a member with the link; and one with 15% that is for public use.
Reports can handle this and integrate data into a single report. If the emails could handle this as well it would make for a possible work around.
Before seriously considering implementing this I would suggest a spike to see how much work it is. It would only be a workaround for now with no long term use (though that's not to say it wouldn't be a useful feature later). So if easy it might be worthwhile and if difficult it's probably not worth it.
Hi everyone,
I've picked up this branch and done a bit of work on it. I noticed that producers whose products haven't been ordered still receive an email, so I've changed that so an email will only be sent if there are orders to that producer.
@NickWeir63, I wasn't able to reproduce the problems you were having, though. I've put the current version on https://staging1.openfood.com.au/ . Could you experiment and see if you can find any problems?
Thanks @RohanM I edited the email addresses for a couple of the stroudco producers on staging1 - please check that I amended them in the correct place (see screenshot below)..............
.........then submitted a couple of orders for products from these producers. I received a confirmation email to the hub (See below) but no confirmation email as a shopper and none as a producer
Hi Nick Weir, Well done! You have a new order for Stroudco!
Order confirmation #R186654850 Nick Weir nick@nickweir.co.uk 441453840037 Item Qty Price Veal (1kg) Cotswold Veal 2 $22.40 Apple Juice (1L) Days Cottage 2 $1.58 Subtotal: $23.97 Shipping: $2.00 Total: $25.97
NOT PAID Payment summary Paying via: Cash on Collection Pay when you pick up
Home Delivery Delivery on:
Delivery address: Nick Weir 44 Bisley Road, Stroud, GL5 1HF, Tasmania 441453840037
Hi @NickWeir63,
That looks like the right place to edit the producer emails. Just checking if you edited the order cycle and clicked the "Notify Producers" button? No emails will be sent to producers until that button is pressed.
Thanks @RohanM - that was it. When I clicked notify producers i did receive all the correct emails to the correct addresses with the correct quantities, However the email did not have any details under the heading "Detailed Orders Breakdown" see below Other than that it is looking great -thanks
Dear Days Cottage,
We now have all the consumer orders for next food drop. Please drop off your delivery at . Please deliver to Stroud Valley Community School, Stroud, GL5 2HP during the regular delivery time. If this is not convenient then please call 1453840037. Note: If you have to arrange a different delivery day and time, it is requested that you do not come on site during drop off/pick up times.
Here is a summary of the orders for your products:
Days Cottage Apple Juice 1L (QTY: 7) @ $0.70 = $2.80 COPY OF Days Cottage COPY OF Apple Juice 1L (QTY: 4) @ $0.70 = $2.80
Please confirm that you have got this email. Please send me an invoice for this amount so we can send you payment. If you need to phone on the day please call 1453840037.
Thanks and best wishes - Stroudco
It would appear that 'detailed orders breakdown’ has not been done. I understood that our task for this was to code review / bug fix and merge - not necessarily build/enhance feature. How important is this detailed orders breakdown? Can we just remove the title for now and you / someone can come back and do it when resources permit?
and/or we could put a link / message to the appropriate report for them to login and see if they need the detailed breakdown by customer? or something?
On 19 Oct 2015, at 6:32 pm, Nick Weir notifications@github.com wrote:
Thanks @RohanM https://github.com/RohanM - that was it. When I clicked notify producers i did receive all the correct emails to the correct addresses with the correct quantities, However the email did not have any details under the heading "Detailed Orders Breakdown" see below Other than that it is looking great -thanks
Dear Days Cottage,
We now have all the consumer orders for next food drop. Please drop off your delivery at . Please deliver to Stroud Valley Community School, Stroud, GL5 2HP during the regular delivery time. If this is not convenient then please call 1453840037. Note: If you have to arrange a different delivery day and time, it is requested that you do not come on site during drop off/pick up times.
Orders summary
Here is a summary of the orders for your products:
Days Cottage Apple Juice 1L (QTY: 7) @ $0.70 = $2.80 COPY OF Days Cottage COPY OF Apple Juice 1L (QTY: 4) @ $0.70 = $2.80
Detailed orders breakdown
Please confirm that you have got this email. Please send me an invoice for this amount so we can send you payment. If you need to phone on the day please call 1453840037.
Thanks and best wishes - Stroudco
— Reply to this email directly or view it on GitHub https://github.com/openfoodfoundation/openfoodnetwork/issues/275#issuecomment-149127189.
OK we can live without the detailed orders breakdown on the email but yes it would be great if we could replace the title with something like please login to your account if you need to see a detailed breakdown of this order by customer. Thanks
Hi @NickWeir63, I've amended that heading, so that part of the email now looks like this:
Orders summary
==============
Here is a summary of the orders for your products:
ABC Enterprise 2 Product #1 - 4790 1g (QTY: 2) @ $10.00 = $10.00
Details
=======
For a detailed orders breakdown, please log into your account.
Please confirm that you have received this email.
Please send me an invoice for this amount so we can send you payment.
If you need to phone on the day please call .
Thanks and best wishes - Enterprise 1
Does that look good to you? If so, I'll consider this feature ready (as an initial version) and merge this branch.
Thanks @RohanM - yes that looks ideal. Do we close this or move it to backlog?
Note: Some further discussion and simplification in PR #302
I just put a test order through staging 2 and then 'notified producers' and the email came through perfectly. Thanks very much
1) Idea is to add subtabs to the OrderCycle tab: New Order Cycle and Manage Order Cycle.
2) Within Manage Order Cycle, manual option to send email to Single or All producers.
3) Option within producers to have email notification of orders (default to no)
4) Option to automate this upon orders closing (default to no)
5) Option within producers to have email specifying per customer order.
Summary should include:
Tasks