News:

Looking for documentation? Take a look on our wiki

Main Menu

Ask about this product - Add field country

Started by idor, February 09, 2018, 16:03:04 PM

Previous topic - Next topic

idor

Hello,
I am using
VirtueMart 3.2.12
Joomla 3.8.5

I need to add a new text field (Country) in the pop up form, when the users clicks the "ask a question about this product".
After some research I modified these files with overrides:

/html/com_virtuemart/askquestion/form.php
/html/com_virtuemart/askquestion/mail_raw_question.php
/html/com_virtuemart/askquestion/mail_html_question.php
/html/com_virtuemart/askquestion/view.html.php

The problem I have is that the value of the country field isn´t recieved in the email I get.

What I am not sure if the view.html.php file has to go in the same folder with other files, as in the core files all other files are inside a tmpl folder..

The modifications I did is:
/html/com_virtuemart/askquestion/form.php LINE 68
I  added
<div class="form-group">
<label for="country"><?php echo vmText::_('COM_VIRTUEMART_USER_FORM_COUNTRY'?></label>
<input type="text" class="form-control validate[required,minSize[3],maxSize[64]]" value="<?php echo $this->user->country $this->user->country $askQuestionData['country'?>" name="country" id="country" size="30" validation="required country" placeholder="<?php echo vmText::_('COM_VIRTUEMART_USER_FORM_COUNTRY'?>"/>
</div>



/html/com_virtuemart/askquestion/mail_raw_question.php LINE 8
I changed
echo vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $this->user->name, $this->user->email) . "\n";
to this
echo vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $this->user->country, $this->user->name, $this->user->email) . "\n";

/html/com_virtuemart/askquestion/mail_html_question.php LINE 53
I changed this:
<span style="font-size: 14px; font-weight: bold"><?php echo vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM'$this->user->name$this->user->email); ?></span>

to this:
<span style="font-size: 14px; font-weight: bold"><?php echo vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM'$this->user->country$this->user->name$this->user->email); ?></span>


/html/com_virtuemart/askquestion/view.html.php LINE 166
I added
         $fromCountry = vRequest::getVar ('country');


When I have development errors enabled in the country field I see:
<br /><b>Notice</b>:  Undefined property: Joomla\CMS\User\User::$country in <b>........../html/com_virtuemart/askquestion/form.php</b> on line <b>70</b><br />

Don´t know if anything has to do with this..

Thank you in advance!

Studio 42

First, you should never change the virtuemart files but do an override in template
See https://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core
$this->user->country is unknow, because it's not set by VM.
So you should use $fromCountry = vRequest::getVar ('country'); directly in the mail_html_question.php

idor

Hello, thank you for your answer.
I added $fromCountry = vRequest::getVar ('country');
in the mail_html_question.php but now I recieve no email..
Is there a specific line I have to add it?

I placed it at the beggining of the file. Before the php closing tag.


<?php
defined('_JEXEC') or die('');
/**
* Renders the email for ask a question
   * @package   VirtueMart
   * @subpackage product details
   * @author Maik K�nnemann
   * @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2014 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.
* @version $Id$
*/
$fromCountry = vRequest::getVar ('country');
?>


Studio 42

Activate PHP error reporting in Joomla
But you use vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $this->user->country, $this->user->name, $this->user->email);
and need to use $fromCountry , but COM_VIRTUEMART_QUESTION_MAIL_FROM have only 2 strings for sprintf, so you can not use it, you have to modify the language Key too.

idor

I am not sure what changes do I have to do..
Is it OK with the changes I have made untill my post?

The
$fromCountry = vRequest::getVar ('country');
has to replace something in the file mail_html_question.php
or simple adding this line at the begining its OK?

The language key, I suppose you mean this: COM_VIRTUEMART_QUESTION_MAIL_FROM="A question was asked by %s (%s)"
how do I have to modify it?
I tried this
COM_VIRTUEMART_QUESTION_MAIL_FROM="A question was asked by %s (%s), %s"
and the mail I get now shows
Warning: sprintf(): Too few arguments in ......./administrator/components/com_virtuemart/helpers/vmtext.php on line 151
LINE 151 has
return call_user_func_array('sprintf', $args);

Activate PHP errors? You mean Error reporting in configuration? I have this in development mode..

All changed files are override, but what if I change the key language?
How do I override en-GB.com_virtuemart.ini? Where to copy this file in my template folder???




Studio 42

vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $this->user->country, $this->user->name, $this->user->email);
Should be
vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $fromCountry , $this->user->name, $this->user->email);

idor

OK done! what next? Country value isn´t recieved in the mail.

What about the key language??

The language key (COM_VIRTUEMART_QUESTION_MAIL_FROM="A question was asked by %s (%s)")
how do I have to modify it?
I tried this
COM_VIRTUEMART_QUESTION_MAIL_FROM="A question was asked by %s (%s), %s"
and the mail I get now shows
Warning: sprintf(): Too few arguments in ......./administrator/components/com_virtuemart/helpers/vmtext.php on line 151
LINE 151 has
return call_user_func_array('sprintf', $args);

Activate PHP errors? You mean Error reporting in configuration? I have this in development mode..

All changed files are override, but what if I change the key language?
How do I override en-GB.com_virtuemart.ini? Where to copy this file in my template folder???

thank you!

Studio 42

COM_VIRTUEMART_QUESTION_MAIL_FROM="A question was asked by %s (%s), %s"
Should work.
You can use Joomla language overide in back-end to add this values.
But do not forget to overide all languages in Front-end
You should try this in PHP:
var_dump($fromCountry , $this->user->name, $this->user->email); jexit();
So you can see if all is set correctly

idor

This var_dump($fromCountry , $this->user->name, $this->user->email); jexit();
in which file???

I believe there is something wrong firstly with my form.php file.
I get this error when openning the form.
<br /><b>Notice</b>:  Undefined property: Joomla\CMS\User\User::$country in <b>...../....../templates/vp_merchant/layouts/refresa/html/com_virtuemart/askquestion/form.php</b> on line <b>70</b><br />

and in line 70 I had added this:
<input type="text" class="form-control validate[required,minSize[3],maxSize[64]]" value="<?php echo $this->user->country $fromCountry $askQuestionData['country'?>" name="country" id="country" size="30" validation="required country" placeholder="<?php echo vmText::_('COM_VIRTUEMART_USER_FORM_COUNTRY'?>"/>


The language overrides is done! Perfect and thank you!!!

Studio 42


idor

OK YES there is a progress!!!
The <br /><b>Notice</b>:  Undefined property: Joomla\CMS\User\User::$country in <b>........../html/com_virtuemart/askquestion/form.php</b> on line <b>70</b><br />
disappeared when I replaced $this->user->country with $fromCountry

The key language is changed like this:
COM_VIRTUEMART_QUESTION_MAIL_FROM="A question was asked by %s (%s), %s"

BUT no data is recieved now in the mail, nor email, nor name.
Warning: sprintf(): Too few arguments in ....../administrator/components/com_virtuemart/helpers/vmtext.php on line 151
I think we are close, but dont know what is causing this problem..

Studio 42

before /html/com_virtuemart/askquestion/mail_html_question.php LINE 53
var_dump($fromCountry , $this->user->name, $this->user->email); jexit();
So you can see if the value are set or not.

idor

I see no difference adding this line.
Where should I see a change?
In the form everything is the same
and the email I get shows again
Warning: sprintf(): Too few arguments in ..../.../administrator/components/com_virtuemart/helpers/vmtext.php on line 151

Studio 42

Sorry, i cannot give you more help, it's to many time to explain you all.
Check the PHP doc how to dump var or Vmdebug to check your values

idor

OK it is no need to explain.
Thank your as far for your help untill now... The fact is, as you have probably understoond, that I am not familiar with PHP.
I thought copy and paste the code from the other fields would work, but seams it is not as simple.. ..at least for me.
Maybe if I attach the files you could make the changes for me?
I suppose for you would be simple, is´nt it? or am I asking too much?