Needs review
Project:
Commerce Core
Version:
3.x-dev
Component:
Log
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Mar 2022 at 14:05 UTC
Updated:
6 Jul 2026 at 16:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
vipin.j commentedThe patch is based on #141 with:
- Core version requirement now matches with 8.x-2.29 release.
- Improve presentation of comments added.
- Applies missed coding standards.
Comment #4
morbus iffInterface review.
Regarding the new checkout pane (customer-checkout-pane-4.png):
Regarding the admin interface (order-adminterface-4.png):
Some other hiccups:
And, finally, to @rszrama:
I agree that this patch currently merges two different functionalities: the ability for admins to add comments to an order that a customer sees ("here's your shipping number!", "this has been delayed!", "your preorder has been canceled!", "I refunded your shipping. Thanks!", etc.), and the ability for customers to add data for administrators (for clarity, I'll call these "checkout comments").
I need both in my sites. I half-agree that "checkout comments" COULD be implemented (more flexibly) by a custom field. For example, if I'm selling school books and I need to know what school you go to, I'd add a "School" custom field, absolutely. And, sure, I suppose I could add a generic "Checkout comments" field too, but now we're splitting a single mentality ("order comments") into two separate implementations (the log-based "admin comments" and "customer-facing comments", and then a field-based "checkout comments").
For me, the "compromise" is what you've already suggested: the default "Order comments" checkout pane (provided by this patch) should be disabled by default. This will then allow the user to choose the merged all-in-a-log functionality for generic comments, while still allowing them to create custom-order-fields ("School name:") for more controlled pieces of operable data.
Comment #5
morbus iffMy suggestion above:
I'm thinking we can expand on this to support both approaches.
What would be nice for the most flexibility is some way for the themer/site owner to decide if they want the entire order receipt (i.e., what the suggested defaults above are) or if they only want to send comments (i.e., what patch #2 does with emailed-comment-4.png does). My thought here is that whenever an admin chooses to email the customer with an order comment, a new variable is added to the order receipt template called "is_emailed_comment" (or something). This would then allow a themer/site owner to customize their own commerce receipt template to NOT send the non-comment parts of the commerce receipt, something like:
This allows Commerce to support both approaches: full order receipts with comments (i.e. what I think the defaults should be) and "only comments emailed" (i.e., what patch #2 does with emailed-comment-4.png does). But it'd do it all with the existing commerce receipt template, not a new template (like patch #2 does).
Comment #6
vipin.j commentedThe previous patch added #2 was based on #141 which was way different then the last commit 12cb8ca by @mglaman
This patch is refined version of #141 as the requirements of this issue is now fulfilled by extending the functionality from commit 12cb8ca
Comment #8
morbus iffPatch 6 (P6) makes some substantial changes to the original patch 2 (P2).
commerce-order-receipt.html.twigfor the email, which now supports showing order comments if they exist. A new twig file has been added calledcommerce-log-order-comments.html.twigwhich, by default, is just a copy of that existing order receipt. With this new twig file, it's possible to move your comments to the top of the email or to reproduce the behavior of P2 (by wiping out everything else and using only the first array item of theorder_commentsvariable).To push back on a @rszrama suggestion: If the checkout pane just has a textarea in it, I don't see why its wrapper element should be a fieldset. Can we not just make this a container div? That's been implemented in this patch (customer-checkout-pane-6.png), and I don't like it. Primarily, every other place that a comment form item appears, they look "better" in a fieldset. On customer-checkout-pane-review-6.png, it looks "better" because all the other data is in a fieldset, on order-adminterface-6.png a fieldset is used for the comment because we've got radios, etc. I'm thinking that we should continue to use a fieldset, named "Comments", but leave the textfield unlabeled (similar to order-adminterface-6.png).
For those using P2 in prod, there are potentially breaking changes:
Comment #9
vipin.j commentedFixes testbot errors generated with patch #6
Comment #10
bobburns commented#9 works great - badly needed missing feature. I had to install manually - and I am guessing it will soon be committed to Commerce Core
It is disabled by default
Enable after patching at /admin/commerce/config/checkout-flows/manage/default?destination=/admin/commerce/config/checkout-flows
a.k.a /admin/commerce/config/checkout-flows
Comment #11
ayalon commentedThanks for the initiative and creating a new issue.
The new patch does not apply to Commerce 2.30 because commerce_log.install File was extended.
Attached an updated patch.
Comment #12
vipin.j commentedHere is another refined version of #9 patch. Contains improvements and noticeable bug fixes.
Comment #13
vipin.j commentedDue to the recent 8.x-2.x-dev version upgrade with #12, which now causing patch application failure on production release.
the issue was with the file
modules/log/commerce_log.install, So I removed the snippet which does Drupal role permission grant withhook_install()Alternatively we can take care of permission grant with Drupal configurations.
Hope this new patch will be helpful.
Comment #14
morbus iffReminder ping for review.
Comment #15
jsacksick commentedWe'll try to review this while in Prague.
Comment #16
rinasek commentedComment #17
jsacksick commentedHaven't really had time to do a proper review, but the first thing I'm noticing is the checkout pane defined, which should be defined by the commerce_log module rather than defining it from commerce_checkout and have all bunch of checks to ensure commerce_log is enabled.
Also what's done from the OrderReceiptMail could be done via a hook_preprocess_HOOK() implemented by commerce_log, so once again we don't have to check if commerce_log is enabled etc.
Is there a reason for the unrelated test changes too?
Comment #18
vipin.j commented@jsacksick, Thanks for your response.
We've moved the CustomerCommentsPane class to commerce_log now, as per your valuable suggestion.
But we have
OrderReceiptMail::getOrderComments()method's dependency across commerce_log and commerce_order modules, as the callback for the same placed in 3 files. moving withhook_preprocess_HOOKwill result in duplication of code statements.Still, I have attached the re-rolled and updated patch, Kindly review.
And yeah, we were facing test case failures while patch submission, which made us to fix them.
Comment #19
abx commentedWill this patch has a chance to get merged? Or should I continue looking for other method?
Thanks,
Comment #20
vipin.j commentedThe patch #18 is re-rolled with updates for release ^2.35 compatibility.
Comment #21
vipin.j commentedSmall tweak in the patch to remove one of the WCAG 2.1 issue.
Comment #22
luksakThis needs a re-roll.
Comment #23
luksakOk, here is a re-roll.
Comment #24
luksakSorry, I forgot to add the new files.
Comment #25
abx commentedTested #24 with latest dev and works.
Thanks,
Comment #26
nags338228 commentedHi,
I patched with https://www.drupal.org/project/commerce/issues/3267366 and https://www.drupal.org/project/commerce/issues/2908196 this issue and merged both of it.
The #25 patch contains Comment form in user order page for the user along with permissions + comment form for admin with radio buttons and sending email functionality.
It would be great if anyone can test it please?
Thanks !!
Comment #27
vipin.j commentedFrom patch #6 we are carrying a deprecated statement which has fixed with the issue #3336658
Re-rolling patch #24 to fix this issue in the patch.
Comment #28
poker10 commentedI think that a possibility to add customer-facing order comments is an important feature, so +1 from me and hopefully we will see this in Drupal Commerce soon. As it was mentioned in the referenced issue (#3166853: How to Add Order Comment and also Allow to notify customer via email?), each other eshop system has such comments (magento, ubercart, prestashop, opencart).
Comment #29
khiminrm commentedI've tested patch from #27.
It works.
But I've noticed one bug:
When add comment and go to review page,
on review page click on Edit near the Comments section
then the page with previous checkout step is opened and the Comment input field is empty.
Adding new comment in this case and submitting checkout step form again will save the comment as new log.
So there are two comment logs.
I haven't time to look into code and check if it's possible to load already created comment log yet.
Maybe it should be fixed?
Comment #30
khiminrm commentedI've fixed the bug from the previous comment.
Comment #31
khiminrm commentedAdded one more small fix to render a customer comment on the order review page with new lines (if there any in the comment) and not '
' instead.
Comment #32
poker10 commentedThanks for working on this. I have quickly checked the patch and writing a few points.
1. I think there are some unrelated changes, or at least not explained:
2. Regarding the templates - I think it would be a little weird to display it this way. As far as I understand, we can have only one comment of type "From customer". Maybe it should be out of foreach to not cause a confusion. Then we should have a foreach just for "To customer" comments and there would be no need to write "Comment to customer" for each row. This is the related code:
3. Why are we changing the comment output from
{{ comment }}to{{ comment|raw }}(and even for the existing admin comments)? Personally I think that comments should be only plaintext and I do not see a reason for this change. It can probably open some vulnerabilities if not handled correctly.4. As this patch is pretty large, I think it would be great if we can move it to MR instead, so that reviews/comments/progress is easier and more transparent.
Comment #33
khiminrm commentedAdded small fix for the cases if the customer comment contains apostrophes and when we go back to edit the comment, so wouldn't have
'instead of'.Comment #34
khiminrm commentedOne more small fix to remove the
<br />on edit a commentComment #36
vipin.j commentedRe-rolling patch from #34 for release commerce 8.x-2.39
Comment #37
jsacksick commentedA bit of scope creep here, I'll probably create a separate issue to focus on the checkout pane in checkout as this is a bit hard to review.
The patch here for example dispatches an event on pane submission, but the user could go back and edit the comment?
I haven't tested the patch manually, but it doesn't seem that editing the comment is supported.
I'm thinking we should store the comment in the order data for example, and only record the log on checkout completion / order placement.
Comment #38
jsacksick commentedCreated #3468080: Provide a checkout pane for customer comments.
Comment #39
vipin.j commentedHere is the updated patch from the reference of #36, after the changes introduced & committed from #38 into Commerce Core.
Comment #40
cjd4001 commentedI'm getting following error after installing patch 39 (previous patches not patching with my version of commerce 2.40.0 and drupal 10.3.6
TypeError: Drupal\commerce_log\EventSubscriber\OrderEventSubscriber::__construct(): Argument #2 ($order_receipt_mail) must be of type Drupal\commerce_order\Mail\OrderReceiptMailInterface, Drupal\symfony_mailer\MailManagerReplacement given, called in /home/[workingdir]/core/lib/Drupal/Component/DependencyInjection/Container.php on line 261 in Drupal\commerce_log\EventSubscriber\OrderEventSubscriber->__construct() (line 40 of /home/[workingdir]/modules/contrib/commerce/modules/log/src/EventSubscriber/OrderEventSubscriber.php).
any help / pointers gratefully received as client strongly relies on this functionality which has stopped working since upgrades.
Comment #41
vipin.j commentedRe rolling patch #39 for Commerce Core '3.0.x' compatibility.
Comment #42
c_archer commentedPatch #41 no longer applied against the latest version 3.3.2
Comment #43
khiminrm commentedRe-rolled the patch for the latest 3.x.
Please, test.
Comment #44
jsacksick commentedComment #46
khiminrm commentedCreated patch with the latest fixes in new MR for 3.x
Comment #47
khiminrm commentedComment #48
jsacksick commentedI reviewed this quickly today and I find it impractical that we'd resend the order receipt each time. Also, what about "from customer comments"? For a few releases now, we have a "customer_comments" field.
We've discussed the idea of implementing this feature from contrib instead (via the commerce_email module), but this alternate approach requires further research.
Comment #49
morbus iff@jsacksick: Could you explain what you find impractical a bit more? The order receipt is *not* sent "each time" - it is ONLY sent if the admin has checked "Notify the customer". The order receipt template is used so the customer knows exactly what order, and products, are being commented on. The goal is the customer should have all the info they need *in this singular email* without having to check previous emails or having to return to the site.
> For a few releases now, we have an "customer_comments" field.
This field is used for comments *from the customer to the admin*. This patch is *the other way* - from the admin to the customer, by way of documentation on the order. We wouldn't want to reuse the customer_comments field for that (nor is that customer comments field currently exposed in the UI after the order is placed, for either the customer or the admin).
commerce_email feels like a bit of a weird place to put this, since that's all about reacting to _existing events_ with _automated emails_, and this particular action is an admin manually adding an order comment that they may or may not consider important enough to email the customer about.
Comment #50
jsacksick commentedYes, I know, but the MR adds a new from customer event:
This new event isn't fired anywhere.
Yes, what I meant by "each" time, is each time a new comment is added from the admin and "Notify the customer" is checked.
I hear the point about keeping the comment in context, just questioning whether this is really the best thing to do, or we could simply have a new template that says "A new comment was added to your order #xxxx" or something, with a link to the customer order view page or wherever the customer can reply.
The commerce_email approach was briefly discussed, we aren't entirely sure it will work yet.
Comment #51
morbus iffAh. Huh. It appears to be used less as an event and more as a log type ID, to determine which comment is which ("from customer" vs. "to customer") and to differentiate between those two in the theme layer. For our internal purposes, AFAIK, we don't use it as an event either.
Some comments on this:
Comment #53
vmarchukAdded a static patch compatible with version 3.3.4, as MR 637 is no longer applicable.