Add a custom attribute variable to the email confirmation template to confirm the order

I have created some custom attributes for my products. I have some that need to be added to the email that the customer receives when he makes the order. Currently, I found that I can edit the mail template in the backend and "app / design / frontend / base / default / template / email / order / items.phtml".

How to access object variables in email templates and what is the correct syntax for custom element attributes?

+4
source share
1 answer

There are several possibilities (this is Magento).

The application template /design/frontend/base/default/template/email/order/items.phtml that you mentioned is a wrapper for all the elements in the order. Individual items are displayed in separate templates. In most cases this is an application / design / frontend / base / default / template / email / order / items / order / default.phtml, but other types of products may use different ones, for example. order items for related products use ... template / bundle / email / order / items / order / default.phtml.

Inside the templates, you do not work with instances of the Mage_Catalog_Model_Product model, but with instances of Mage_Sales_Model_Order_Item . These elements have different attributes, and then product attributes.
If you want your custom product instances to always be available in sales/order_item , you will need to add them to the object.
During the verification process, also set them to the sales/quote_item and copy them to the order items using the appropriate fields in the configuration (see global/fieldsets in Mage / Sales / etc / config.xml for an example.

If products still exist in the catalog, they can be downloaded, including all attributes, using

 $product = Mage::getModel('catalog/product')->load($orderItem->getProductId(); 

Or, to get all product models for all order items at once (a little more efficiently):

 $products = Mage::getResourceModel('catalog/product_collection') ->addIdFilter($orderItems->getColumnValues('product_id')) ->addAttributeToSelect(array('list', 'of', 'your', 'custom', 'attributes')); 

Of course, this will mean additional requests compared to the first decision to add the same attributes to the order item object.
Also keep in mind that once the product is removed, it will no longer load in this way.

+11
source

Source: https://habr.com/ru/post/1396157/


All Articles