Author Topic: Ask about this product - Add field country  (Read 902 times)

dkaneloglou

  • Beginner
  • *
  • Posts: 29
Ask about this product - Add field country
« 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
Code: [Select]
<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
Code: [Select]
echo vmText::sprintf('COM_VIRTUEMART_QUESTION_MAIL_FROM', $this->user->name, $this->user->email) . "\n";to this
Code: [Select]
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:
Code: [Select]
<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:
Code: [Select]
<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:
Code: [Select]
<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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2974
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Ask about this product - Add field country
« Reply #1 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

dkaneloglou

  • Beginner
  • *
  • Posts: 29
Re: Ask about this product - Add field country
« Reply #2 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');
 ?>


Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2974
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Ask about this product - Add field country
« Reply #3 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.

dkaneloglou

  • Beginner
  • *
  • Posts: 29
Re: Ask about this product - Add field country
« Reply #4 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???




Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2974
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Ask about this product - Add field country
« Reply #5 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);

dkaneloglou

  • Beginner
  • *
  • Posts: 29
Re: Ask about this product - Add field country
« Reply #6 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!
 

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2974
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Ask about this product - Add field country
« Reply #7 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

dkaneloglou

  • Beginner
  • *
  • Posts: 29
Re: Ask about this product - Add field country
« Reply #8 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.
Code: [Select]
<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:
Code: [Select]
<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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2974
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Ask about this product - Add field country
« Reply #9 on: February 14, 2018, 22:45:57 pm »
$this->user->country do not exist here

dkaneloglou

  • Beginner
  • *
  • Posts: 29
Re: Ask about this product - Add field country
« Reply #10 on: February 15, 2018, 00:20:42 am »
OK YES there is a progress!!!
The
Code: [Select]
<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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2974
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Ask about this product - Add field country
« Reply #11 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.

dkaneloglou

  • Beginner
  • *
  • Posts: 29
Re: Ask about this product - Add field country
« Reply #12 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

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2974
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Ask about this product - Add field country
« Reply #13 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

dkaneloglou

  • Beginner
  • *
  • Posts: 29
Re: Ask about this product - Add field country
« Reply #14 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?