Skip to content
Snippets Groups Projects
Commit e459cb3c authored by Jonathan Sacksick's avatar Jonathan Sacksick Committed by Jonathan Sacksick
Browse files

Issue #3468080 by ayalon, khiminrm, Lukas von Blarer, vipin.j, Morbus Iff:...

Issue #3468080 by ayalon, khiminrm, Lukas von Blarer, vipin.j, Morbus Iff: Provide a checkout pane for customer comments
parent 9f0599f1
No related branches found
No related tags found
6 merge requests!379Issue #3491248 Validation is breaking the amount number format decimal point,!375Issue #3413020 by czigor: Using a translatable string as a category for field...,!357Issue #2914933: Add service tags to order-related interfaces,!344Resolve #3107602 "Product attributes do not update visually when switching variations",!343Resolve #3107602 "Product attributes do not update visually when switching variations",!342Issue #3476581 by josephr5000: add OrderItemLabelEvent
Pipeline #261978 passed
<?php
namespace Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides the customer comments pane.
*
* @CommerceCheckoutPane(
* id = "customer_comments",
* label = @Translation("Comments"),
* default_step = "_disabled",
* wrapper_element = "fieldset",
* )
*/
class CustomerComments extends CheckoutPaneBase implements CheckoutPaneInterface {
/**
* {@inheritdoc}
*/
public function buildPaneSummary() {
$summary = parent::buildPaneSummary();
if ($comments = $this->order->getCustomerComments()) {
$summary[] = ['#markup' => $comments];
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$pane_form['comments'] = [
'#type' => 'textarea',
'#title' => $this->t('Comments'),
'#title_display' => 'invisible',
'#default_value' => $this->order->getCustomerComments(),
];
return $pane_form;
}
/**
* {@inheritdoc}
*/
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
parent::submitPaneForm($pane_form, $form_state, $complete_form);
if (!empty($form_state->getValue('customer_comments')['comments'])) {
$comment = nl2br(Html::escape($form_state->getValue('customer_comments')['comments']));
$this->order->setCustomerComments($comment);
}
else {
$this->order->set('customer_comments', NULL);
}
}
}
......@@ -64,6 +64,10 @@ commerce_order_admin_comment:
category: commerce_order
label: 'Admin comment'
template: '<p><strong>Admin comment:</strong><br /> {{ comment }}</p>'
commerce_order_from_customer_comment:
category: commerce_order
label: 'Comment from customer'
template: '<p><strong>From customer:</strong><br /> {{ comment|raw }}</p>'
payment_added:
category: commerce_payment
label: 'Payment added'
......
......@@ -44,6 +44,11 @@ class CheckoutEventSubscriber implements EventSubscriberInterface {
public function onCheckoutCompletion(OrderEvent $event) {
$order = $event->getOrder();
$this->logStorage->generate($order, 'checkout_complete')->save();
if ($comments = $order->getCustomerComments()) {
$this->logStorage->generate($order, 'commerce_order_from_customer_comment', [
'comment' => $comments,
])->save();
}
}
}
......@@ -419,5 +419,22 @@ function commerce_order_update_8221() {
}
return "The views.view.commerce_user_orders couldn't be updated as the default path for the title field has been overridden with custom value. Test if rewrite pattern is correct.";
}
/**
* Add the "customer_comments" field to orders.
*/
function commerce_order_update_8222() {
$storage_definition = BaseFieldDefinition::create('string_long')
->setLabel(t('Customer comments'))
->setDisplayOptions('view', [
'type' => 'string',
'label' => 'above',
'settings' => [],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$update_manager = \Drupal::entityDefinitionUpdateManager();
$update_manager->installFieldStorageDefinition('customer_comments', 'commerce_order', 'commerce_order', $storage_definition);
}
......@@ -694,6 +694,21 @@ class Order extends CommerceContentEntityBase implements OrderInterface {
return $date;
}
/**
* {@inheritdoc}
*/
public function getCustomerComments(): ?string {
return $this->get('customer_comments')->value;
}
/**
* {@inheritdoc}
*/
public function setCustomerComments($comments): static {
$this->set('customer_comments', $comments);
return $this;
}
/**
* {@inheritdoc}
*/
......@@ -995,6 +1010,16 @@ class Order extends CommerceContentEntityBase implements OrderInterface {
])
->setDisplayConfigurable('view', TRUE);
$fields['customer_comments'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Customer comments'))
->setDisplayOptions('view', [
'type' => 'string',
'label' => 'above',
'settings' => [],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
......
......@@ -468,4 +468,22 @@ interface OrderInterface extends ContentEntityInterface, EntityAdjustableInterfa
*/
public function getCalculationDate();
/**
* Gets the customer comments.
*
* @return string|null
* The customer comments.
*/
public function getCustomerComments(): ?string;
/**
* Sets the customer comments.
*
* @param string $comments
* The customer comments.
*
* @return $this
*/
public function setCustomerComments(string $comments): static;
}
......@@ -136,6 +136,22 @@
</p>
</td>
</tr>
{% if order_entity.getCustomerComments %}
<tr>
<td>
<table style="width: 100%; padding-top:15px; padding-bottom: 15px; text-align: left; border-top: 1px solid #cccccc; ">
<tbody>
<tr>
<td style="padding-top: 5px; font-weight: bold;">{{ 'Customer comments'|t }}</td>
</tr>
<tr>
<td><p>{{ order_entity.getCustomerComments|raw }}</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
{% endif %}
<tr>
<td>
{% block additional_information %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment