Describe your bug or feature request.
We currently have no checkout pane for allowing the customer to add comments. Work was done as part of #3267366: Add customer-facing order comments but due to the amount of changes introduced, I prefer to work on a simpler version focusing on the checkout pane only for now.
The checkout pane should be disabled by default (we can use customer_comments as its ID, just like in the issue linked), we should leverage the commerce_log module, but only record a log on checkout completion (Or we can use the existing order subscriber from commerce_log, reacting to the place post transition). Then we can have an event subscriber in commerce_log checking that the order data key is not empty and log a message to the activity log.
Additionally, we need changes to the order receipt to include the comments so in short we need:
- A new log template
- A new order base field "customer_comments"
- A new checkout pane (ID: "customer_comments"), message should be stored in the order data array.
- An event subscriber in commerce_log (preferably reacting to checkout completion, since that happens prior to the order place post transition, and the place post transition is used for sending the receipt. We can either do that, or have the log subscriber run before the order receipt subscriber.
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | order-comments.png | 15.67 KB | jsacksick |
| #11 | order-receipt-with-comments.png | 40.89 KB | jsacksick |
Issue fork commerce-3468080
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jsacksick commentedComment #3
jsacksick commentedComment #4
jsacksick commentedComment #5
jsacksick commentedComment #6
rszrama commentedAgreed re: reacting to checkout completion; makes more logical sense, too.
Let's also remember to have the event subscriber delete the message out of the order data array when it's transferred... unless, would it be easier to keep it in the data array to also be able to define an order comments token / theme template variable to make it easier to include in emails and user interfaces?
Comment #7
jsacksick commentedThe token could use the generated logs, but wondering whether storing the comment in an actual separate field doesn't make this easier?
That makes it less custom, and easier to print in Twig template without additional magic / logic required...
But not 100% sure the field is the right solution either, it does simplify the code / logic for sure.
Comment #8
jsacksick commentedI initially extracted code from #3267366: Add customer-facing order comments, but I'm having second thoughts about the approach.
With the current approach, there is no way to have customer comments in checkout without the commerce_log module enabled... I don't think we must require commerce_log for that?
The checkout pane is provided by the commerce_log module. Then, if we want to include the comments in the order receipt, we need to have conditional logic based on whether the commerce_log module is installed...
There was a method added to the OrderReceiptMail:
I don't think we have to do it this way, we could implement a
hook_preprocess_HOOK()from the commerce_log module.So I think we have several options:
Comment #9
jsacksick commentedConsidering this is a checkout feature, I think the checkout module should be responsible for providing it, so I'm thinking of:
Thoughts?
Comment #11
jsacksick commentedAfter discussing this with @rszrama on Slack, decided to implement the original approach.
The MR is a simplified version of the changes from #3267366: Add customer-facing order comments with several adjustments:
The MR focuses on the checkout pane, generating the log on checkout completion as well as outputting the customer comments in the order receipt (see the attached screenshot).
In the event we're adding "to customer" comments, the current approach might not be flexible enough but I'm not sure (especially the template part).
I removed the log date from the order receipt template, and I'm not looping on logs since there is supposed to be only one customer comment.
At the same time, and maybe I'm missing something, I don't really understand in which context an admin would leave comments to a customer from the admin, PRIOR to the order being placed?
Comment #17
jsacksick commentedCrediting
Comment #18
jsacksick commentedActually, after rediscussing this with @rszrama, it might make more sense to implement a solution that is more aligned with my comment #9.
But now thinking we should stick to "customer_comments", to support Headless and setting a comment via JSONAPI for example.
In this case, the field could be defined as a base field from the order module directly I suppose?
Comment #19
rszrama commentedYeah, really sorry for jerking you around on this. The maximum utility approach is actually to store the value in a field that can be more easily embedded / used in other contexts. I'd propose
customer_commentsprovided bycommerce_order, with the Checkout module providing a checkout pane for populating this field and an event subscriber for recording the contents of this field at checkout completion to the order log. This provides some auditability while still permitting the field to be used for other purposes.If a headless site then wants to populate this field through some other means, or if the field is made editable or whatever, then those use cases would be responsible for their own event subscribers that write the contents of the field to the log at their own consequential times.
Additionally, since we're still copying this into the activity stream, we can still also use it in concert with some theoretical log message emailing system in the future, in a view of comment related logs, etc.
Comment #20
abx commentedIt looks like the same issue tries to fix 2 separate problems.
1. The one that jsacksick talked about in this issue, to allow customer to leave a note while checking out. It's a one time thing.
2. Another one is to use to communicate with customer via Log / Email. Let's say if I would like to notify customer that this item is out of stock, I can just send an email to customer from the order page. I also have a log to check if we already send something to customer. Also, it's the way for store admin to send to customer, not the other way around.
Actually, I also prefer the way Ubercart works, it divides comments into 2 types order comment and admin comment. That way, we can know exactly which information we send to customer, which one is only note between store admin.
I created an issue long time ago for the second problem here (To Compare what other E-Commerce has but not in Drupal Commerce) -> https://www.drupal.org/project/commerce/issues/3166853
Comment #21
jsacksick commentedThe second problem isn't addressed here, the point of this issue is to focus on customer comments, left during checkout.
The goal was to split the changes into smaller chunks so this can more easily get in.
Comment #22
abx commentedThanks jsacksick, I forgot to read the title.. Just followed from the old issue and think that this tries to fix that old issue.
Comment #23
jsacksick commentedWanted to point out, after discussing this internally, that an alternative to this would be to use https://www.drupal.org/project/commerce_checkout_order_fields.
Comment #24
jsacksick commentedComment #25
jsacksick commentedOk, we now have a base "customer_comments" field, it is used in the order receipt. The log module is still logging the message in the activity log. The pane is provided by commerce_checkout, and the field can be added to the order view (it's currently output under "Other").
I'm wondering if this should be 3.x only or whether I should backport this change to 2.x, this affects the update hook number ofc, so we have to make a decision.
Comment #26
jsacksick commented@rszrama: Last thing... Should we use plural or singular? "customer_comments" might suggest the field cardinality is multiple...
So the question is: "customer_comment" vs "customer_comments", for the field / checkout pane ID as well as the order receipt.
Comment #27
jsacksick commentedComment #30
jsacksick commentedComment #31
morbus iff@jsacksick: Does this contain the ability for an admin to communicate back to the customer via comments? (I've been, and still remain, on a holiday as I'm doing the college move-in thing for a kid, so haven't had a chance to follow along with this recent flurry of dev.)
EDIT: Looks like this was answered in #20 - it doesn't, so @vipin.j, we'll have to reroll to get that back in somehow on top of jsacksick's layer, and hope his layer supports that concept. [And that means that we'd have to change the Commerce template to support two different comment systems now? The checkout-only customer comment system and then the already-existing admin-order-comment but-intended-for-end-user system.]
Comment #32
jsacksick commented@morbu iff: Yes only customer comments in checkout, and the comment is logged in the activity log. I tried simplifying this as much as possible so we could get at least part of the functionality in. The other issue kind of derailed with events / templates as well as commerce_log code in the multiple modules (OrderReceipt fetching implicitly depending on commerce_log etc)...
I didn't like the fact that commerce_log had to be installed in order to get the checkout pane for example...
Just FYI, I kept the same template ID for the log as in the original patch (commerce_order_from_customer_comment).
We can always find a way to merge the two functionalities together somehow, but let's connect on Slack whenever you have a moment, or perhaps this is something we could discuss in Barcelona, in case you're travelingt to Drupalcon.