Thank you very much, it actually works. (Current Virtuemart 3.8.7 10378)
However, I have the custom form and now I cannot retrieve the email to display it in the body of the email itself.
Code Form.php:
<?php
// Check to ensure this file is included in Joomla!
defined ( '_JEXEC' ) or die ( 'Restricted access' );
$min = VmConfig::get('asks_minimum_comment_length', 50);
$max = VmConfig::get('asks_maximum_comment_length', 2000) ;
vmJsApi::JvalideForm();
$document = JFactory::getDocument();
$document->addScriptDeclaration('
jQuery(function($){
$("#askform").validationEngine("attach");
$("#comment").keyup( function () {
var result = $(this).val();
$("#counter").val( result.length );
});
});
');
/* Let's see if we found the product */
if (empty ( $this->product )) {
echo vmText::_ ( 'COM_VIRTUEMART_PRODUCT_NOT_FOUND' );
echo '<br /><br /> ' . $this->continue_link_html;
} else {
$session = JFactory::getSession();
$askQuestionData = $session->get('askquestion', 0, 'vm');
if(!empty($this->login)){
echo $this->login;
}
if(empty($this->login) or VmConfig::get('recommend_unauth',false)){
?>
<div class="ask-a-question-view">
<h1><?php echo vmText::_('COM_VIRTUEMART_PRODUCT_ASK_QUESTION') ?></h1>
<div class="product-summary">
<div class="width70 floatleft">
<h2><?php echo $this->product->product_name ?></h2>
<?php // Product Short Description
if (!empty($this->product->product_s_desc)) { ?>
<div class="short-description">
<?php echo $this->product->product_s_desc ?>
</div>
<?php } // Product Short Description END ?>
</div>
<div class="width30 floatleft center">
<?php // Product Image
echo $this->product->images[0]->displayMediaThumb('class="product-image"',false); ?>
</div>
<div class="clear"></div>
</div>
<div class="form-field">
<form method="post" class="form-validate" action="<?php echo JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$this->product->virtuemart_product_id.'&virtuemart_category_id='.$this->product->virtuemart_category_id.'&tmpl=component') ; ?>" name="askform" id="askform">
<label><?php echo vmText::_('COM_VIRTUEMART_USER_FORM_NAME') ?></label>
<input type="text" class="validate[required,minSize[3],maxSize[64]]" value="<?php echo $this->user->name ? $this->user->name : $askQuestionData['name'] ?>" name="name" id="name" size="30" validation="required name"/>
<br />
<label><?php echo vmText::_('COM_VIRTUEMART_USER_FORM_EMAIL') ?></label>
<input type="text" class="validate[required,custom[email]]" value="<?php echo $this->user->email ? $this->user->email : $askQuestionData['email'] ?>" name="email" id="email" size="30" validation="required email"/>
<br/>
<label><?php echo vmText::_('COM_VIRTUEMART_USER_FORM_TELF') ?></label>
<input type="text" value="<?php echo $this->telf ? $this->telf : $askQuestionData['telf'] ?>" name="telf" id="telf" size="30"/>
<br />
<label><?php echo vmText::_('COM_VIRTUEMART_USER_FORM_PAIS') ?></label>
<input type="text" class="validate[required,minSize[3],maxSize[16]]" value="<?php echo $this->pais ? $this->pais : $askQuestionData['pais'] ?>" name="pais" id="pais" size="30" validation="required pais"/>
<br />
<label><?php echo vmText::_('COM_VIRTUEMART_USER_FORM_CP') ?></label>
<input type="text" class="validate[required,minSize[3],maxSize[6]]" value="<?php echo $this->cpostal ? $this->cpostal : $askQuestionData['cpostal'] ?>" name="cpostal" id="cpostal" size="30" validation="required CP"/>
<br />
<label>
<?php echo vmText::sprintf('COM_VIRTUEMART_ASK_COMMENT', $min, $max); ?>
<br />
<textarea title="<?php echo $ask_comment ?>" class="validate[required,minSize[<?php echo $min ?>],maxSize[<?php echo $max ?>]] field" id="comment" name="comment" rows="8"><?php echo $askQuestionData['comment'] ?></textarea>
</label>
<label><?php echo JText::_('COM_VIRTUEMART_USER_FORM_POLITICADATOS') ?> : <input type="checkbox" class="validate[required]" value="FALSE>" name="proteccionatos" id="protecciondatos" validation="required accept protection data"/> </label>
<label><?php echo JText::_('COM_VIRTUEMART_USER_FORM_RECIBEMAILS') ?> : <input type="checkbox" class="validate[required]" value="FALSE>" name="enviaremails" id="enviaremails" validation="required to accept data processing"/> </label>
<div class="submit">
<div class="width50 floatright right paddingtop">
<?php echo vmText::_('COM_VIRTUEMART_ASK_COUNT') ?>
<input type="text" value="0" size="4" class="counter" id="counter" name="counter" maxlength="4" readonly="readonly" />
</div>
<?php // captcha addition
if(VmConfig::get ('ask_captcha')){
JHTML::_('behavior.framework');
JPluginHelper::importPlugin('captcha');
$dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onInit','dynamic_recaptcha_1');
?>
<div id="dynamic_recaptcha_1"></div>
<?php
}
// end of captcha addition
?>
<input class="highlight-button" type="submit" name="submit_ask" title="<?php echo vmText::_('COM_VIRTUEMART_ASK_SUBMIT') ?>" value="<?php echo vmText::_('COM_VIRTUEMART_ASK_SUBMIT') ?>" />
</div>
<input type="hidden" name="virtuemart_product_id" value="<?php echo JRequest::getInt('virtuemart_product_id',0); ?>" />
<input type="hidden" name="tmpl" value="component" />
<input type="hidden" name="view" value="productdetails" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="virtuemart_category_id" value="<?php echo JRequest::getInt('virtuemart_category_id'); ?>" />
<input type="hidden" name="task" value="mailAskquestion" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
</div>
</div>
<?php
}
} ?>
Code mail_html_question.php
<?php
defined('_JEXEC') or die('');
?>
<html>
<head>
<style type="text/css">
body, td, span, p, th { font-size: 12px; font-family: arial, helvetica, sans-serif; }
table, tr, td { border: 0; background:#fff;}
table.html-email {margin:10px auto;background:#fff; #dad8d8 1px;}
h2 { font-size: 1.6em; font-weight: normal; margin: 0px; padding: 0px; }
img {border: none;}
a {text-decoration: none; color: #000;}
a.product-details, a.product-details:visited {
border: solid #CAC9C9 1px;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
color: #555;
text-decoration: none;
padding: 3px 8px 2px 8px;
}
a.product-details:hover {color:#888;background: #f8f8f8;};
</style>
</head>
<body style="background: #F2F2F2;word-wrap: break-word;">
<div width="100%">
<table style="margin: auto; width: 600px; border: solid #dad8d8 1px" cellpadding="0" cellspacing="0" >
<tr>
<td valign="top" align="center" style="padding: 15px 25px;">
<table border="0" cellpadding="0" cellspacing="0" class="html-email" width="100%">
<tr>
<td align="left" style="border-bottom : 1px solid #dad8d8;">
<span style="font-size: 14px; font-weight: bold">Consulta web de un producto </span><br/>
<br /> <?php echo 'Nombre: ' . $this->user->name ?>
<br /> <?php echo 'PaÃs: ' . $this->pais; ?>
<br /> <?php echo 'CP: ' . $this->cpostal; ?>
<br /> <?php echo 'Telf: ' . $this->telf; ?>
<br /> <?php echo 'eMail: ' . $this->user->email; ?>
<br /><br /><?php echo $this->comment; ?><br /><br />
</td>
</tr>
<tr>
<td align="center" style="border-bottom : 1px solid #dad8d8; padding: 15px;">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<?php
$menuItemID = shopFunctionsF::getMenuItemId(vmLanguage::getLanguage()->getTag());
$product_link = JURI::root().'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->virtuemart_product_id . '&Itemid=' . $menuItemID;
?>
<td width="25%" align="center">
<a href="<?php echo $product_link ?>">
<?php echo $this->product->images[0]->displayMediaThumb('',false,'',true,false,true); ?>
</a>
</td>
<td width="70%" valign="top">
<h2>
<?php echo $this->product->product_name ?>
<?php if ($this->product->product_sku) echo ' ('.vmText::_('COM_VIRTUEMART_PRODUCT_SKU').' '.$this->product->product_sku .')' ; ?>
</h2>
<p style="margin: 25px 0; display:block;"><?php echo $this->product->product_s_desc ?></p>
<a href="<?php echo $product_link ?>" class="product-details"><?php echo vmText::_('COM_VIRTUEMART_PRODUCT_DETAILS') ; ?></a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
And Code view.html.php
<?php
defined ('_JEXEC') or die('Restricted access');
/**
* Product details
*
* @package VirtueMart
* @author Max Milbers
*/
class VirtueMartViewAskquestion extends VmView {
/**
* Collect all data to show on the template
*
* @author Max Milbers
*/
function display ($tpl = NULL) {
$app = JFactory::getApplication();
if(!VmConfig::get('ask_question',false) and !VmConfig::get('askprice',false)){
$app->redirect(JRoute::_('index.php?option=com_virtuemart','Disabled function'));
}
$this->login = '';
if(!VmConfig::get('recommend_unauth',false)){
$user = JFactory::getUser();
if($user->guest){
$this->login = shopFunctionsF::getLoginForm(false);
}
}
$this->show_prices = (int)VmConfig::get ('show_prices', 1);
$document = JFactory::getDocument ();
$mainframe = JFactory::getApplication ();
$pathway = $mainframe->getPathway ();
$task = vRequest::getCmd ('task');
// Load the product
$product_model = VmModel::getModel ('product');
$category_model = VmModel::getModel ('Category');
$virtuemart_product_idArray = vRequest::getInt ('virtuemart_product_id', 0);
if (is_array ($virtuemart_product_idArray)) {
$virtuemart_product_id = $virtuemart_product_idArray[0];
} else {
$virtuemart_product_id = $virtuemart_product_idArray;
}
if (empty($virtuemart_product_id)) {
self::showLastCategory ($tpl);
return;
}
$product = $product_model->getProduct ($virtuemart_product_id);
// Set Canonic link
$format = vRequest::getCmd('format', 'html');
if ($format == 'html') {
$document->addHeadLink (JUri::getInstance()->toString(array('scheme', 'host', 'port')).JRoute::_($product->canonical, FALSE), 'canonical', 'rel', '');
}
// Set the titles
$document->setTitle (vmText::sprintf ('COM_VIRTUEMART_PRODUCT_DETAILS_TITLE', $product->product_name . ' - ' . vmText::_ ('COM_VIRTUEMART_PRODUCT_ASK_QUESTION')));
$this->assignRef ('product', $product);
if (empty($product)) {
self::showLastCategory ($tpl);
return;
}
$product_model->addImages ($product, 1);
// Get the category ID
$virtuemart_category_id = vRequest::getInt ('virtuemart_category_id');
if ($virtuemart_category_id == 0 && !empty($product)) {
if (array_key_exists ('0', $product->categories)) {
$virtuemart_category_id = $product->categories[0];
}
}
shopFunctionsF::setLastVisitedCategoryId ($virtuemart_category_id);
if ($category_model) {
$category = $category_model->getCategory ($virtuemart_category_id);
$this->assignRef ('category', $category);
$pathway->addItem (vmText::_($category->category_name), JRoute::_ ('index.php?option=com_virtuemart&view=category&virtuemart_category_id=' . $virtuemart_category_id, FALSE));
}
$pathway->addItem ($product->product_name, JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id=' . $virtuemart_category_id . '&virtuemart_product_id=' . $product->virtuemart_product_id, FALSE));
// for askquestion
$pathway->addItem (vmText::_ ('COM_VIRTUEMART_PRODUCT_ASK_QUESTION'));
$this->user = JFactory::getUser ();
if ($product->metadesc) {
$document->setDescription ($product->metadesc);
}
if ($product->metakey) {
$document->setMetaData ('keywords', $product->metakey);
}
//We never want that ask a question is indexed
$document->setMetaData('robots','NOINDEX, NOFOLLOW, NOARCHIVE, NOSNIPPET');
if ($mainframe->getCfg ('MetaTitle') == '1') {
$document->setMetaData ('title', $product->product_s_desc); //Maybe better product_name
}
if ($mainframe->getCfg ('MetaAuthor') == '1') {
$document->setMetaData ('author', $product->metaauthor);
}
$this->captcha = shopFunctionsF::renderCaptcha('ask_captcha');
parent::display ($tpl);
}
function renderMailLayout () {
$this->setLayout ('mail_html_question');
$this->comment = vRequest::getString ('comment');
$this->telf = vRequest :: getString ('telf');
$this->pais = vRequest :: getString ('pais');
$this->cpostal = vRequest :: getString ('cpostal');
$this->user = JFactory::getUser ();
if (empty($this->user->id)) {
$fromMail = vRequest::getEmail ('email'); //is sanitized then
$fromName = vRequest::getVar ('name', ''); //is sanitized then
//$fromMail = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromMail);
$fromName = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromName);
$this->user->email = $fromMail;
$this->user->name = $fromName;
}
$virtuemart_product_id = vRequest::getInt ('virtuemart_product_id', 0);
$productModel = VmModel::getModel ('product');
if(empty($this->product)){
$this->product = $productModel->getProduct ($virtuemart_product_id);
}
$productModel->addImages($this->product);
$this->subject = vmText::_ ('COM_VIRTUEMART_QUESTION_ABOUT') . $this->product->product_name;
$vendorModel = VmModel::getModel ('vendor');
$this->vendor = $vendorModel->getVendor ($this->product->virtuemart_vendor_id);
//$this->vendor->vendor_store_name = $fromName;
$vendorModel->addImages ($this->vendor);
$this->vendorEmail = $vendorModel->getVendorEmail($this->vendor->virtuemart_vendor_id);
// in this particular case, overwrite the value for fix the recipient name
$this->vendor->vendor_name = $this->user->get('name');
if (VmConfig::get ('order_mail_html')) {
$tpl = 'mail_html_question';
} else {
$tpl = 'mail_raw_question';
}
$this->setLayout ($tpl);
$this->isMail = true;
parent::display ();
}
public function showLastCategory ($tpl) {
$this->prepareContinueLink();
parent::display ($tpl);
}
}
// pure php no closing tag
I have tried several things without success, it seems that there is some problem sending the variable with $this->user->email;
It only works if I delete the email variable in mail_html_question.php, it must be giving an error but I can't see it.
Can you help me? thanks.