Michael Michalak - Drupal and Shopify Developer
https://michalak.world/
enDrupal 8 Commerce 2.x Order Messages
https://michalak.world/article/drupal-8-commerce-2x-order-messages
<span>Drupal 8 Commerce 2.x Order Messages</span>
<span><span>useradmin</span></span>
<span>Fri, 02/01/2019 - 09:32</span>
<div class="primary-image field field--name-field-image field--type-image field--label-above">
<div class="field__label">Image</div>
<div class="field__item"> <img loading="lazy" src="/sites/default/files/default_images/cover.png" width="2010" height="1343" alt="Default blog post image" title="Default blog post image" />
</div>
</div>
<div class="text-content clearfix field field--name-body field--type-text-with-summary field--label-above">
<div class="field__label">Body</div>
<div class="field__item"><p>I'm currently working on a custom feature for Drupal 8 Commerce 2.x, and I decided along the way that I wanted to update orders with messages. Documentation on this topic was so light that I decided to write my own post about it!</p>
<p>Your custom module will need to have a couple of additional files:<br />
- mymodule.commerce_log_categories.yml<br />
- mymodule.commerce_log_templates.yml</p>
<h2><strong>mymodule.commerce_log_categories.yml</strong></h2>
<p>Defines our log categories. e.g.</p>
<pre>
example_categories:
label: Example Categories
entity_type: commerce_order
example_categories_two:
label: Example Categories Two
entity_type: commerce_order</pre>
<h2><strong>mymodule.commerce_log_templates.yml</strong></h2>
<p>This file defines the messages or message templates that will be used and seen on orders.</p>
<pre>
example_status_update
category: example_categories
label: 'Status Update'
template: '<p>Status has been updated.</p>'
example_second_status_update
category: example_categories
label: 'Second Status Update'
template: '<p>Status two has been updated.</p>'
update_example_status
category: example_categories_two
label: 'Order Status Update'
template: '<p> Order Update Status</p>'
update_example_status_two
category: example_categories_two
label: 'Order Status Update Two'
template: '<p> Order Update Status Two</p>'
</pre>
<h2><strong>Creating a Message on Commerce Orders</strong></h2>
<p>Now that we have our categories and message templates defined, we're ready to start adding messages to our orders. </p>
<p>We will need to have the order entity:</p>
<pre>
$log_storage = \Drupal::entityTypeManager()->getStorage('commerce_log');
$log = $log_storage->generate($order, 'update_example_status_two'); //use one of our predefined templates
$log->save();</pre>
<p>And that's it— now we can add messages to our orders in Drupal 8 Commerce 2.x. Go message it up!</p>
<p><strong>Original Post:</strong> https://trail9.com/?q=news/drupal-8-commerce-2x-order-messages</p>
</div>
</div>
<section data-drupal-selector="comments" class="comments">
<h2 class="comments__title">Comments</h2>
<div class="add-comment">
<div class="add-comment__form">
<drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&1=33&2=comment&3=comment" token="SOCxtNpb2aUdz8W91NLOhKstqWZQIwlggK7ehFpqvWc"></drupal-render-placeholder>
</div>
</div>
</section>
<div class="field field--name-field-tags field--type-entity-reference field--label-above field--tags">
<h3 class="field__label field--tags__label">Tags</h3>
<ul class="links field__items field--tags__items">
<li class="field--tags__item"><div>
<h2><a href="/tag/drupal">
<div class="field field--name-name field--type-string field--label-hidden field__item">Drupal</div>
</a></h2>
</div>
</li>
<li class="field--tags__item"><div>
<h2><a href="/tag/drupal-development">
<div class="field field--name-name field--type-string field--label-hidden field__item">Drupal Development</div>
</a></h2>
</div>
</li>
<li class="field--tags__item"><div>
<h2><a href="/tag/drupal-commerce">
<div class="field field--name-name field--type-string field--label-hidden field__item">Drupal Commerce</div>
</a></h2>
</div>
</li>
</ul>
</div>
Fri, 01 Feb 2019 15:32:49 +0000useradmin33 at https://michalak.worldhttps://michalak.world/article/drupal-8-commerce-2x-order-messages#comments