0

How can I add special price in email "New order" template?

Product block in email template: {{layout handle="sales_email_order_items" order_id=$order_id area="frontend"}}

This is a product row with price. vendor/magento/module-sales/view/frontend/templates/email/items/price/row.phtml

Now the price is the product of the number of pieces and the final price of the product (qty * final price).

I would like to show the regular price and the special price (result of qty * regular price and result of qty * special price, or just item regular price and special price).

I know how to extend block, make a plugin etc. but I don't know how to get special price from this item.

Anybody help?

Thank you in advance.

2 Answers 2

1

For your requirement, you have to do some work before completed:

Copy special price from product to order item

  • Create new database column to quote_item and sales_order_item
  • Copy special price from product to quote_item when customer have added product to cart.
  • Copy special price from quote_item to order_item when customer submitted order.
  • Update the template vendor/magento/module-sales/view/frontend/templates/email/items/price/row.phtml which allow you render order item information to the order item line.

How to update the row.phtml

  • Create a layout which named sales_email_item_price.xml
  • Reference the block item_price
  • Update the block template by using code block below
<referenceBlock name="item_price">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">yourvendor_module:templatename.phtml</argument>
    </action>
</referenceBlock>
2
  • Thank you for your answear. I think this is correct way. After mentioned steps but adding column (regular_price) to tables (quote_item and sales_order_item), we should to extend item interface and add new method - getRegularPrice() which we can use it for displaying old price in email template (if highest then item price) and e.g. in order view.
    – GieDe
    Commented Nov 24, 2022 at 10:58
  • You shouldn't extend the interface, you should use extension_attribute instead. Because the API won't know your extend.
    – HoangHieu
    Commented Nov 25, 2022 at 5:26
1

Product special price is by default $product->getSpecialPrice().

But as special price has date limits etc so once order is placed we shall not use code like $product->getSpecialPrice() to pull.

Step1 : Populate special price at the time order is placed : https://m.academy/blog/programmatically-add-column-magento-2-sales-order-database-table/

Step 2 : once you have this then you shall get the price in $_item object.

I have not tried the code but logically this shall be the approach.

1
  • Thank you for your answear.
    – GieDe
    Commented Nov 24, 2022 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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