Cart fields in Order Emails

If you are runnig Joomla 3.x and Virtuemart 3.x please post to this forum your questions or support tickets about One Page Checkout

Cart fields in Order Emails

Postby admin » Thu Apr 27, 2017 2:23 pm

Dear friends, we just found that cart fields are by default not shown within the customer and vendor order emails and thus we provide a template override code below which will simply display the cart fields for you. The code was tested and developed on VM3.2.2 but it's expected to work on other versions as well.

What are the cart fields
In OPC and in VM the cart fields are shopper fields which are related only to the specific order and not to the user account itself. For this reason OPC resets cart fields on each visit. In opc the field should be marked as "order field" to provide the same logic as VM3 supports with "cart fields". The reason why we provide our own "order fields" is that we had implemented this solution far before Virtuemart did and we provide the solution for VM2 as well. We believe "cart fields" are mis-named in Virtuemart and their functon should be better described as "order fields only" (that is how we call this in OPC configuration): i.e. order related and not customer's account related

Most common cart fields:
- customer note (this is custom rendered by the templates both in OPC and also by the email templates and thus it doesn't need a special code to be added)
- TOS -> this depends on your configuraiton, but generally this is also custom-rendered by both OPC and/or VM's cart and emails

Not-core cart fields:
- desired delivery date : if you provide a shopper field where the customer can choose desired delivery date, this is a good example cart field.
- Social Security Number : in most countries it's not legal (or requires intensive audits) to be able to store SSNs. For this reason OPC provide special configuration options that such field can be only seen by payment methods, but it is not available to rest of the system and it is not stored in the database. SSNs are usually used to process part-payment orders and are required by payment providers (such as Klarna, Quatro, etc.. ) to check the customer reliability.

Email template override that displays the Cart field:



Code: Select all
<?php
/**
*
* Layout for the order email
* shows the chosen adresses of the shopper
* taken from the stored order
*
* @package   VirtueMart
* @subpackage Order
* @author Max Milbers,   Valerie Isaksen
*
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
?>
<table class="html-email" cellspacing="0" cellpadding="0" border="0" width="100%">  <tr  >
   <th width="50%">
       <?php echo vmText::_('COM_VIRTUEMART_USER_FORM_BILLTO_LBL'); ?>
   </th>
   <th width="50%" >
       <?php echo vmText::_('COM_VIRTUEMART_USER_FORM_SHIPTO_LBL'); ?>
   </th>
    </tr>
    <tr>
   <td valign="top" width="50%">

       <?php

       foreach ($this->userfields['fields'] as $field) {
      if (!empty($field['value'])) {
         ?><!-- span class="titles"><?php echo $field['title'] ?></span -->
              <span class="values vm2<?php echo '-' . $field['name'] ?>" ><?php echo $field['value'] ?></span>
         <?php if ($field['name'] != 'title' and $field['name'] != 'first_name' and $field['name'] != 'middle_name' and $field['name'] != 'zip') { ?>
             <br class="clear" />
             <?php
         }
          }
      
       }
       ?>

   </td>
   <td valign="top" width="50%">
       <?php
       foreach ($this->shipmentfields['fields'] as $field) {

      if (!empty($field['value'])) {
             ?><!-- span class="titles"><?php echo $field['title'] ?></span -->
             <span class="values vm2<?php echo '-' . $field['name'] ?>" ><?php echo $field['value'] ?></span>
             <?php if ($field['name'] != 'title' and $field['name'] != 'first_name' and $field['name'] != 'middle_name' and $field['name'] != 'zip') { ?>
                 <br class="clear" />
            <?php
             }
         }
       }

       ?>
   </td>
    </tr>
</table>


<?php
$userFieldsModel = VmModel::getModel('userfields');
$userFieldsCart = $userFieldsModel->getUserFields(
            'cart'
            , array('captcha' => true, 'delimiters' => true) // Ignore these types
            , array('delimiter_userinfo','user_is_vendor' ,'username','password', 'password2', 'agreed', 'address_type', 'customer_note', 'tos', 'comment') // Skips
         );

         $this->userFieldsCart = $userFieldsModel->getUserFieldsFilled(
            $userFieldsCart
            ,$this->orderDetails['details']['BT']
         );

         
         ?><table class="html-email" cellspacing="0" cellpadding="0" border="0" width="100%"> 
         <tr  >
   <th width="50%">
       <?php echo vmText::_('COM_VIRTUEMART_ORDER_INFO'); ?>
   </th>

    </tr>
    <tr>
   <td valign="top" width="100%">

       <?php

       foreach ($this->userFieldsCart['fields'] as $field) {
      if (!empty($field['value'])) {
         ?><!-- span class="titles"><?php echo $field['title'] ?></span -->
              <span class="values vm2<?php echo '-' . $field['name'] ?>" ><?php echo $field['value'] ?></span>
         <?php if ($field['name'] != 'title' and $field['name'] != 'first_name' and $field['name'] != 'middle_name' and $field['name'] != 'zip') { ?>
             <br class="clear" />
             <?php
         }
          }
      
       }
       ?>

   </td>
   
    </tr>
</table>



We chose to display them under BT and ST secton with it's own label of:
COM_VIRTUEMART_ORDER_INFO="Your Order Informations"

if you'd like to use a better label, you can rename it in this file.

To upload the file as a template override, upload it to:
\templates\YOUR TEMPLATE\html\com_virtuemart\invoice\mail_html_shopperaddresses.php

best regards, stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Return to One Page Checkout for Virtuemart 3 on Joomla 3.x

cron