1

In my controller file:

$vars = array('product_name' => $data['productname'],
                'sku' => $data['sku'],
                'qty' => $data['qty'],
                'customprice' => $model1->getInquiryPrice(),
                'options' => $option,

                );



echo "<pre>"; print_r($vars); die;

Output:



Array
(
    [product_name] => testing demo custom image
    [sku] => demo
    [qty] => 2
    [customprice] => 34.0000
    [options] => Array
        (
            [color] => red
            [length] => 12
        )

)

Email template file (inquiry.html):

Path: app/locale/en_US/template/email/inquiry.html

 <table border="1" style="max-width:100%">

                             <tr class="action-content">

                                <th>Product Name</th>
                                <th>Sku</th>
                                <th>Quantity</th>
                                <th>Price</th>
                                <th>options</th>

                              </tr>

                              <tr class="action-content">

                                <td>{{var product_name}}</td>
                                <td>{{var sku}}</td>
                                <td>{{var qty}}</td>
                                <td>{{var customprice}} </td>
                                 <td>{{var options}}</td>

                              </tr>
</table>

var product_name,var sku,var qty, var customprice is showing the correct output, but var options is not showing correct output in email template file.

Output:



                             

                                Product Name
                                Sku
                                Quantity
                                Price
                                options

                              

                              

                                testing demo custom image
                                demo
                                2
                                23.0000 
                                Array

                              

  • 1
    You have to pass array with key like, color1=> red, color2=>green and after you can access {{var options.color1}} and {{var options.color2}} – Rakesh Jesadiya Dec 14 '16 at 5:11
  • please show hot to set $option in your file? – Rakesh Jesadiya Dec 14 '16 at 6:00
2

I would suggest to pass options as a string.

$allOptions = implode(", ", $option);
$vars = array('product_name' => $data['productname'],
            'sku' => $data['sku'],
            'qty' => $data['qty'],
            'customprice' => $model1->getInquiryPrice(),
            'options' => $allOptions,

            );

Now in email template:

{{var options}} should give you green, red

UPDATE

If your $option will always give data in Color, Length format then you can add like this:

$allOptions = "Color: ". $option[0]. " & Length: ". $option[1];

Rest is the same.

UPDATE 2

If key is diff then go to foreach

$allOptions = null;
foreach($option as $key => $opt){
   $allOptions .= $key . ": ". $opt. " \n"; 
}
| improve this answer | |
  • yes, it is working , but how to show key ? like color: red & length: 12 – Magento 2 Learner Dec 14 '16 at 5:55
  • Check my update. – Adarsh Khatri Dec 14 '16 at 6:00
  • No, it is not always give same data, So how will i know which keys to use, because each time no. of elements in array can differ. & thanks for your effort – Magento 2 Learner Dec 14 '16 at 6:07
  • Then, you can achieve this from foreach. Check my update. – Adarsh Khatri Dec 14 '16 at 7:44

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.