1

I am facing issue in order update.

Presently when i create an order enter image description here

We have Email order confirmation checked by default.

But similarly for order update/ create invoice/ create shipment enter image description here

I need this to be checked by default as the orders may be updated/ shipment may be created from other source for my store.

0

To make the "Notify Customer by Email" checkbox checked by default, you need to add checked="checked" in the phtml template.

You can override the template file in your custom module as follows:

app/code/Anshu/Custom/view/adminhtml/layout/sales_order_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="left">
            <referenceBlock name="order_tab_info">
                <block class="Magento\Sales\Block\Adminhtml\Order\View\History" name="order_history" template="Anshu_Custom::order/view/history.phtml"/>
            </referenceBlock>
        </referenceContainer>
    </body>
</page>

app/code/Anshu/Custom/view/adminhtml/templates/order/view/history.phtml

<?php
// @codingStandardsIgnoreFile
?>
<div id="order_history_block" class="edit-order-comments">
    <?php if ($block->canAddComment()):?>
        <div class="order-history-block" id="history_form">

            <div class="admin__field">
                <label for="history_status" class="admin__field-label"><?= /* @noEscape */ __('Status') ?></label>
                <div class="admin__field-control">
                    <select name="history[status]" id="history_status" class="admin__control-select">
                        <?php foreach ($block->getStatuses() as $_code => $_label): ?>
                            <option value="<?= $block->escapeHtml($_code) ?>"<?php if ($_code == $block->getOrder()->getStatus()): ?> selected="selected"<?php endif; ?>><?= $block->escapeHtml($_label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>

            <div class="admin__field">
                <label for="history_comment" class="admin__field-label">
                    <?= /* @noEscape */ __('Comment') ?>
                </label>
                <div class="admin__field-control">
                    <textarea name="history[comment]"
                              rows="3"
                              cols="5"
                              id="history_comment"
                              class="admin__control-textarea"></textarea>
                </div>
            </div>

            <div class="admin__field">
                <div class="order-history-comments-options">
                    <div class="admin__field admin__field-option">
                        <?php if ($block->canSendCommentEmail()): ?>
                            <input name="history[is_customer_notified]"
                                   type="checkbox"
                                   id="history_notify"
                                   class="admin__control-checkbox"
                                   checked="checked"
                                   value="1" />
                            <label class="admin__field-label" for="history_notify">
                                <?= /* @noEscape */ __('Notify Customer by Email') ?>
                            </label>
                        <?php endif; ?>
                    </div>

                    <div class="admin__field admin__field-option">
                        <input name="history[is_visible_on_front]"
                               type="checkbox"
                               id="history_visible"
                               class="admin__control-checkbox"
                               value="1" />
                        <label class="admin__field-label" for="history_visible">
                            <?= /* @noEscape */ __('Visible on Storefront') ?>
                        </label>
                    </div>
                </div>

                <div class="order-history-comments-actions">
                    <?= $block->getChildHtml('submit_button') ?>
                </div>
            </div>
        </div>
    <?php endif;?>

    <ul class="note-list">
        <?php foreach ($block->getOrder()->getStatusHistoryCollection(true) as $_item): ?>
            <li class="note-list-item">
                <span class="note-list-date"><?= /* @noEscape */ $block->formatDate($_item->getCreatedAt(), \IntlDateFormatter::MEDIUM) ?></span>
                <span class="note-list-time"><?= /* @noEscape */ $block->formatTime($_item->getCreatedAt(), \IntlDateFormatter::MEDIUM) ?></span>
                <span class="note-list-status"><?= $block->escapeHtml($_item->getStatusLabel()) ?></span>
                <span class="note-list-customer">
                <?= /* @noEscape */ __('Customer') ?>
                    <?php if ($block->isCustomerNotificationNotApplicable($_item)): ?>
                        <span class="note-list-customer-notapplicable"><?= /* @noEscape */ __('Notification Not Applicable') ?></span>
                    <?php elseif ($_item->getIsCustomerNotified()): ?>
                        <span class="note-list-customer-notified"><?= /* @noEscape */ __('Notified') ?></span>
                    <?php else: ?>
                        <span class="note-list-customer-not-notified"><?= /* @noEscape */ __('Not Notified') ?></span>
                    <?php endif; ?>
            </span>
                <?php if ($_item->getComment()): ?>
                    <div class="note-list-comment"><?= $block->escapeHtml($_item->getComment(), ['b', 'br', 'strong', 'i', 'u', 'a']) ?></div>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
    <script>
        require(['prototype'], function(){

            if($('order_status'))$('order_status').update('<?= $block->escapeJs($block->escapeHtml($block->getOrder()->getStatusLabel())) ?>');

        });
    </script>
</div>

Here Anshu is the namespace and Custom is the module name.

0

I used the guidelines here and it worked. Note, it's important to make such customization in a child theme instead of magento core obviously.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.