- Issue created by @jsacksick
- 🇺🇸United States rszrama
Agreed 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?
- 🇮🇱Israel jsacksick
The 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.
- 🇮🇱Israel jsacksick
I initially extracted code from ✨ Add customer-facing order comments Active , 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:
/** * Get customer viewable order comments. * * @param \Drupal\commerce_order\Entity\OrderInterface $order * The order entity. * * @return array * The order comments. */ public function getOrderComments(OrderInterface $order): array { $orderComments = []; if (\Drupal::moduleHandler()->moduleExists('commerce_log')) { $logStorage = \Drupal::entityTypeManager()->getStorage('commerce_log'); /** @var \Drupal\commerce_log\Entity\LogInterface $logEntry */ foreach (array_reverse($logStorage->loadMultipleByEntity($order)) as $logEntry) { if ($logEntry->getTemplateId() === 'commerce_order_to_customer_comment') { $orderComments[$logEntry->id()]['type'] = OrderCommentEvent::ORDER_TO_CUSTOMER_COMMENT; $orderComments[$logEntry->id()]['date'] = $logEntry->getCreatedTime(); $orderComments[$logEntry->id()]['comment'] = $logEntry->getParams()['comment']; }<ol> <li></li> </ol> elseif ($logEntry->getTemplateId() === 'commerce_order_from_customer_comment') { $orderComments[$logEntry->id()]['type'] = OrderCommentEvent::ORDER_FROM_CUSTOMER_COMMENT; $orderComments[$logEntry->id()]['date'] = $logEntry->getCreatedTime(); $orderComments[$logEntry->id()]['comment'] = $logEntry->getParams()['comment']; } } } return $orderComments; }
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:
- Perhaps we should move the checkout pane to the checkout module?
- The order receipt is looping on order comments, but if we have a single pane and ignore admin comments, I don't think this is necessary and we should just focus on the order comments entered in checkout?
- Maybe we should define an actual base field for the customer comments after all? My problem with the current approach is that the order receipt is updated only if the commerce_log module is enabled, so if I define the checkout pane from the checkout module, then there is an inconsistency, we may expose a pane and not do anything with the comment entered...
- 🇮🇱Israel jsacksick
Considering this is a checkout feature, I think the checkout module should be responsible for providing it, so I'm thinking of:
- A new base field provided by the checkout module ("checkout_comments")
- Commerce log could still record a log on checkout completion
- The pane manipulates the field
- The order receipt simply outputs the field value? Though the patch from ✨ Add customer-facing order comments Active also includes a date, which wouldn't be possible if we don't rely on the logs for the order receipt...
Thoughts?
- Merge request !313Issue #3468080 by jsacksick: Provide a checkout pane for customer comments. → (Merged) created by jsacksick
- Status changed to Needs review
3 months ago 12:42pm 21 August 2024 - 🇮🇱Israel jsacksick
After discussing this with @rszrama on Slack, decided to implement the original approach.
The MR is a simplified version of the changes from ✨ Add customer-facing order comments Active with several adjustments:- No "to customer" log template
- The order receipt simply outputs the order_comments variable, the HTML is coming from a new template/theme function "commerce_log_order_receipt_customer_comments" provided by the commerce_log module
- I removed all the commerce_log code that was added to the OrderReceipt email, all that logic now lives in a preprocess within the commerce_log module (commerce_log_preprocess_commerce_order_receipt)
- There is no custom event, no custom permission.
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?
- 🇨ðŸ‡Switzerland Lukas von Blarer
jsacksick → credited Lukas von Blarer → .
- 🇮🇱Israel jsacksick
Actually, after rediscussing this with @rszrama, it might make more sense to implement a solution that is more aligned with my comment #9.
- Status changed to Needs work
3 months ago 1:30pm 21 August 2024 - 🇺🇸United States rszrama
Yeah, 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_comments
provided 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.
It 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 💬 How to Add Order Comment and also Allow to notify customer via email? Active
- 🇮🇱Israel jsacksick
The 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. Thanks jsacksick, I forgot to read the title.. Just followed from the old issue and think that this tries to fix that old issue.
- 🇮🇱Israel jsacksick
Wanted 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 → .
- Status changed to Needs review
3 months ago 10:06am 22 August 2024 - 🇮🇱Israel jsacksick
Ok, 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.
- 🇮🇱Israel jsacksick
@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.
-
jsacksick →
committed 042e8f1d on 3.0.x
Issue #3468080 by ayalon, khiminrm, Lukas von Blarer, vipin.j, Morbus...
-
jsacksick →
committed 042e8f1d on 3.0.x
-
jsacksick →
committed e459cb3c on 8.x-2.x
Issue #3468080 by ayalon, khiminrm, Lukas von Blarer, vipin.j, Morbus...
-
jsacksick →
committed e459cb3c on 8.x-2.x
- Status changed to Fixed
3 months ago 2:51pm 22 August 2024 - 🇺🇸United States 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 moving doing the college move-in thing for a kid, so haven't had a chance to follow along with this recent flurry of dev.)
- 🇮🇱Israel jsacksick
@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 can 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 logs etc etc)... The other patch had multiple issues.
Automatically closed - issue fixed for 2 weeks with no activity.