1

I want to override the item layout in credit memo email template and want to add new column in that. I tried to override that but that item layout in email template is not showing.

Overridden email path:- app/design/frontend/<company_name>/<theme_name>/Magento_Sales/email/creditmemo_new.html

<!-- /** * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ --> <!--@subject {{trans "Credit memo for your %store_name order" store_name=$store.getFrontendName()}} @--> <!--@vars { "var formattedBillingAddress|raw":"Billing Address", "var comment":"Credit Memo Comment", "var creditmemo.increment_id":"Credit Memo Id", "layout handle=\"sales_email_order_creditmemo_items\" creditmemo=$creditmemo order=$order":"Credit Memo Items Grid", "var this.getUrl($store, 'customer/account/')":"Customer Account URL", "var order.getCustomerName()":"Customer Name", "var order.increment_id":"Order Id", "var payment_html|raw":"Payment Details", "var formattedShippingAddress|raw":"Shipping Address", "var order.getShippingDescription()":"Shipping Description", "var order.shipping_description":"Shipping Description" } @--> {{template config_path="design/email/header_template"}} <table> <tr class="email-intro"> <td> <p class="greeting">{{trans "%name," name=$order.getCustomerName()}}</p> <p> {{trans "Thank you for your order from %store_name." store_name=$store.getFrontendName()}} {{trans 'You can check the status of your order by <a href="%account_url">logging into your account</a>.' account_url=$this.getUrl($store,'customer/account/',[_nosid:1]) |raw}} </p> <p> {{trans 'If you have questions about your order, you can email us at <a href="mailto:%store_email">%store_email</a>.' store_email=$store_email |raw}} </p> </td> </tr> <tr class="email-summary"> <td> <h1>{{trans "Your Credit Memo #%creditmemo_id for Order #%order_id" creditmemo_id=$creditmemo.increment_id order_id=$order.increment_id}}</h1> </td> </tr> <tr class="email-information"> <td> {{depend comment}} <table class="message-info"> <tr> <td> {{var comment|escape|nl2br}} </td> </tr> </table> {{/depend}} <table class="order-details"> <tr> <td class="address-details"> <h3>{{trans "Billing Info"}}</h3> <p>{{var formattedBillingAddress|raw}}</p> </td> {{depend order.getIsNotVirtual()}} <td class="address-details"> <h3>{{trans "Shipping Info"}}</h3> <p>{{var formattedShippingAddress|raw}}</p> </td> {{/depend}} </tr> <tr> <td class="method-info"> <h3>{{trans "Payment Method"}}</h3> {{var payment_html|raw}} </td> {{depend order.getIsNotVirtual()}} <td class="method-info"> <h3>{{trans "Shipping Method"}}</h3> <p>{{var order.getShippingDescription()}}</p> </td> {{/depend}} </tr> </table> {{layout handle="sales_email_order_creditmemo_items" creditmemo=$creditmemo order=$order}} </td> </tr> </table> {{template config_path="design/email/footer_template"}} 
10
  • Please try to override this template from Admin. Go to Marketing > Email Templates and add a new one. You can add a new column over there. Commented Mar 6, 2023 at 6:23
  • In email template, only layout handler is called, we cannot add the column in item rederer, it is called through layout sales_email_order_creditmemo_items and in default.phtml file. But somehow that layout is not called in the email. Commented Mar 6, 2023 at 6:32
  • What column and values do you want to add, LMK? I will create a small extension at my localhost then share the code with you! Commented Mar 6, 2023 at 6:50
  • Add any custom product attribute in the column or you can take default product atrribute as well like sku or qty available Commented Mar 6, 2023 at 6:59
  • You want to add a new column in this table right? tinyurl.com/2qfdj73f Can I add the here SKU? Let me know if I am on right track. Commented Mar 6, 2023 at 7:15

2 Answers 2

1

For adding new coloumn in credit memo email. You can do the following things. Just override 2 templates in your custom theme. VERY SIMPLE

I just tried on our local instace it is working as expected.

  1. Copy form vendor/magento/module-sales/view/frontend/templates/email/items/creditmemo/default.phtml to app/design/frontend/Mytheme/navneet/Magento_Sales/templates/email/items/creditmemo/default.phtml

     <?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ ?> <?php $_item = $block->getItem() ?> <?php $_order = $block->getItem()->getOrder(); ?> <tr> <td class="item-info<?= ($block->getItemOptions() ? ' has-extra' : '') ?>"> <p class="product-name"><?= $block->escapeHtml($_item->getName()) ?></p> <p class="sku"><?= $block->escapeHtml(__('SKU')) ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p> <?php if ($block->getItemOptions()) : ?> <dl> <?php foreach ($block->getItemOptions() as $option) : ?> <dt><strong><em><?= $block->escapeHtml($option['label']) ?></em></strong></dt> <dd> <?= /* @noEscape */ nl2br($block->escapeHtml($option['value'])) ?> </dd> <?php endforeach; ?> </dl> <?php endif; ?> <?php $addInfoBlock = $block->getProductAdditionalInformationBlock(); ?> <?php if ($addInfoBlock) :?> <?= $addInfoBlock->setItem($_item->getOrderItem())->toHtml() ?> <?php endif; ?> <?= $block->escapeHtml($_item->getDescription()) ?> </td> <td><?= $block->escapeHtml($block->getSku($_item)) ?></td> <td class="item-qty"><?= (float) $_item->getQty() ?></td> <td class="item-price"> <?= /* @noEscape */ $block->getItemPrice($_item) ?> </td> </tr> 
  2. Copy form vendor/magento/module-sales/view/frontend/templates/email/creditmemo/items.phtml to app/design/frontend/Mytheme/navneet/Magento_Sales/templates/email/creditmemo/items.phtml

     <?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ ?> <?php $_creditmemo = $block->getCreditmemo() ?> <?php $_order = $block->getOrder() ?> <?php if ($_creditmemo && $_order) : ?> <table class="email-items"> <thead> <tr> <th class="item-info"> <?= $block->escapeHtml(__('Items')) ?> </th> <th class="item-info"> <?= $block->escapeHtml(__('SKU')) ?> </th> <th class="item-qty"> <?= $block->escapeHtml(__('Qty')) ?> </th> <th class="item-subtotal"> <?= $block->escapeHtml(__('Subtotal')) ?> </th> </tr> </thead> <?php foreach ($_creditmemo->getAllItems() as $_item) : ?> <?php if (!$_item->getOrderItem()->getParentItem()) : ?> <tbody> <?= $block->getItemHtml($_item) ?> </tbody> <?php endif; ?> <?php endforeach; ?> <tfoot class="order-totals"> <?= $block->getChildHtml('creditmemo_totals') ?> </tfoot> </table> <?php endif; ?> 

Here is the screenshot at my local instance credit memo email template:

New Column SKU added:

enter image description here

0
0

You need to override this file vendor/magento/module-sales/view/frontend/templates/email/creditmemo/items.phtml in your theme app/design/frontend/Vendor/Theme/Magento_Sales/email/creditmemo/items.phtml

Update a code

<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ ?> <?php $_creditmemo = $block->getCreditmemo() ?> <?php $_order = $block->getOrder() ?> <?php if ($_creditmemo && $_order) : ?> <table class="email-items"> <thead> <tr> <th class="item-info"> <?= $block->escapeHtml(__('Items')) ?> </th> <th class="item-qty"> <?= $block->escapeHtml(__('Qty')) ?> </th> <th class="item-subtotal"> <?= $block->escapeHtml(__('Subtotal')) ?> </th> </tr> </thead> <?php foreach ($_creditmemo->getAllItems() as $_item) : ?> <?php if (!$_item->getOrderItem()->getParentItem()) : ?> <tbody> <?= $block->getItemHtml($_item) ?> </tbody> <?php endif; ?> <?php endforeach; ?> <tfoot class="order-totals"> <?= $block->getChildHtml('creditmemo_totals') ?> </tfoot> </table> <?php endif; ?> 

To

<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ ?> <?php $_creditmemo = $block->getCreditmemo() ?> <?php $_order = $block->getOrder() ?> <?php if ($_creditmemo && $_order) : ?> <table class="email-items"> <thead> <tr> <th class="item-sku" style="width: 90px; padding: 15px 0;border-top:1px solid #d1d1d1;color: #000;text-align:left; "> <?= $block->escapeHtml(__('Sku')) ?> </th> <th class="item-info"> <?= $block->escapeHtml(__('Items')) ?> </th> <th class="item-qty"> <?= $block->escapeHtml(__('Qty')) ?> </th> <th class="item-subtotal"> <?= $block->escapeHtml(__('Subtotal')) ?> </th> </tr> </thead> <?php foreach ($_creditmemo->getAllItems() as $_item) : ?> <?php if (!$_item->getOrderItem()->getParentItem()) : ?> <tbody> <tr> <td class="sku" style="border-top:1px solid #d1d1d1;vertical-align: middle;padding: 10px 10px;"> <p class="sku"><?= 'testqygyt'.$block->escapeHtml($_item->getSku()) ?></p> </td> </tr> <?= $block->getItemHtml($_item) ?> </tbody> <?php endif; ?> <?php endforeach; ?> <tfoot class="order-totals"> <?= $block->getChildHtml('creditmemo_totals') ?> </tfoot> </table> <?php endif; ?> 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.