VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: idor on February 09, 2018, 16:03:04 PM

Title: Ask about this product - Add field country
Post by: idor on February 09, 2018, 16:03:04 PM
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!
Title: Re: Ask about this product - Add field country
Post by: Studio 42 on February 09, 2018, 17:21:57 PM
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
Title: Re: Ask about this product - Add field country
Post by: idor on February 12, 2018, 19:16:25 PM
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');
?>

Title: Re: Ask about this product - Add field country
Post by: Studio 42 on February 13, 2018, 00:03:31 AM
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.
Title: Re: Ask about this product - Add field country
Post by: idor on February 13, 2018, 17:27:37 PM
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???



Title: Re: Ask about this product - Add field country
Post by: Studio 42 on February 13, 2018, 17:32:53 PM
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);
Title: Re: Ask about this product - Add field country
Post by: idor on February 14, 2018, 16:37:27 PM
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!
Title: Re: Ask about this product - Add field country
Post by: Studio 42 on February 14, 2018, 17:44:11 PM
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
Title: Re: Ask about this product - Add field country
Post by: idor on February 14, 2018, 18:52:00 PM
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!!!
Title: Re: Ask about this product - Add field country
Post by: Studio 42 on February 14, 2018, 22:45:57 PM
$this->user->country do not exist here
Title: Re: Ask about this product - Add field country
Post by: idor on February 15, 2018, 00:20:42 AM
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..
Title: Re: Ask about this product - Add field country
Post by: Studio 42 on February 15, 2018, 01:14:58 AM
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.
Title: Re: Ask about this product - Add field country
Post by: idor on February 15, 2018, 19:42:14 PM
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
Title: Re: Ask about this product - Add field country
Post by: Studio 42 on February 15, 2018, 20:15:33 PM
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
Title: Re: Ask about this product - Add field country
Post by: idor on February 16, 2018, 00:57:23 AM
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?
Title: Re: Ask about this product - Add field country
Post by: idor on February 22, 2018, 14:47:16 PM
I am still in need of this solution.
Cant make it work.

I tried these steps
https://forum.virtuemart.net/index.php?topic=135176.msg470510#msg470510
but with no luck

If I enable the errors to Developer, I get this warning in the email I receive,
Warning: sprintf(): Too few arguments in /....../administrator/components/com_virtuemart/helpers/vmtext.php on line 151
but I do not recieve any values (email, name nor country)

If I change errors to None, I get no email.
Can anyone help me with this?

Thanks!