VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: razor7 on September 11, 2014, 00:47:08 AM

Title: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: razor7 on September 11, 2014, 00:47:08 AM
Hi, in my test server I have J! 2.5.24 and VM 2.6.10.

First, when registering using VM registration form, I can register without checking the "I agree to the Terms of Service" check box! is that correct?
I expected VM to validate that check and to cancel user registration if user didn't accepted Terms of Service

Second, I have checked Must agree to Terms of Service on EVERY ORDER? and Show Terms of Service on the cart/checkout? in VM configuration, despite having that options enabled, I still can buy things without checking the Terms of Service checkbox at checkout!


My test server is here https://it.mgscreativa.com.ar/j25vm2updt/index.php?option=com_virtuemart&view=user&layout=edit

Thanks!
Title: Re: [BUG] Terms of Service field not validated at all
Post by: razor7 on September 13, 2014, 16:33:30 PM
Hi, after a little debugging in the VM 2.6.10 code I found several bugs in the Terms Of Service mechanism.

First of all, I'm attaching a zip with patched files and a patch file to review the changes.

After analysing the TOS mechanism, I think no user may get registered without accepting TOS, because the agreed user field is set as a core field and can't be edited (ie: you can't set the required state for it). Until a config option like "Must agree to TOS at registration" gets implemented, agreed must be required! at registration.

So first, the "I agree to the Terms of Service" registration field should get a star indicating it's required!
administrator/components/com_virtuemart/models/userfields.php function getCoreFields line 233, agreed should be removed from the array.
Change from this
static function getCoreFields(){
return array( 'name','username', 'email', 'password', 'password2' , 'agreed','language');
}

to this...
static function getCoreFields(){
return array( 'name','username', 'email', 'password', 'password2', 'language');
}


And the agreed form field should be marked as required in its HTML code (form field should be evaluated for "required" mark)
administrator/components/com_virtuemart/models/userfields.php function getUserFieldsFilled line 873
Change from this
case 'agreed':
$_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" name="'
. $_prefix.$_fld->name . '" id="' . $_prefix.$_fld->name . '_field" value="1" '
. ($_return['fields'][$_fld->name]['value'] ? 'checked="checked"' : '') .'/>';
break;

to this...
case 'agreed':
$_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" name="'
. $_prefix.$_fld->name . '" id="' . $_prefix.$_fld->name . '_field" value="1" '
. ($_return['fields'][$_fld->name]['value'] ? 'checked="checked"' : '')
. ($_fld->required ? ' class="required"' : '') . ' />';
break;


Despite agreed form field being marked as required, it needs to get validated at saveData to check if no 'agreed' post variable is sent, that's the case of forced user registration using some kind of method to avoid the form javascript validation
components/com_virtuemart/controllers/user.php funciton saveData line 216
Add theese lines

if(empty($data['agreed'])) {
    $msg = JText::_('COM_VIRTUEMART_USER_FORM_BILLTO_TOS_NO');
    vmInfo($msg);
    return $this->redirect(JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscheckout&addrtype=BT',$this->useXHTML,$this->useSSL), $msg);
}


At checkout, the config option "Must agree to Terms of Service on EVERY ORDER?" is not taken into account. Also, if you disable that option, the Agree to TOS check input is still displayed in the view and thats's not right. For that to work properly, theese are the changes that need to be done
administrator/components/com_virtuemart/models/userfields.php function getUserfield line 187 name parameter overrided because of bad logic (IE: agreed gets allways "required" = 0)
Change from this
if (empty($this->_data)) {
$this->_data = $this->getTable('userfields');
if($name !==0){
$this->_data->load($id, $name);
}
$this->_data->load($id);
}

To this...
if (empty($this->_data)) {
$this->_data = $this->getTable('userfields');
if($name !==0){
$this->_data->load($id, $name);
} else {
    $this->_data->load($id);
}
}


Config Parameter agree_to_tos_onorder (Must agree to Terms of Service on EVERY ORDER?) should be evaluated here, because if it's turned on in config by VM administrator, it doesn't matter if the user agreed to TOS, he must agree on every order because of that VM config setting.
components/com_virtuemart/helpers/cart.php function saveAddressInCart line 1255
Change from this
if(!empty($data['agreed'])){
$this->tosAccepted = $data['agreed'];
}

To this...
if(!empty($data['agreed']) && !VmConfig::get('agree_to_tos_onorder',0)){
$this->tosAccepted = $data['agreed'];
}


Terms Of Service Checkbox should be visible in cart only if "Must agree to Terms of Service on EVERY ORDER?" is checked in VM configuration. For this to happen, the string COM_VIRTUEMART_CART_TOS_READ_AND_ACCEPTED should be splitted into two strings just in case the VM administrator wants to show TOS at cart and not require TOS agreement on every order. Theese are the new strings that should be placed in language/en-GB/en-GB.com_virtuemart.ini
COM_VIRTUEMART_CART_TOS_READ="Click here to read terms of service"
COM_VIRTUEMART_CART_TOS_ACCEPT="and check the box to accept them"
The cart view should be changed too
components/com_virtuemart/views/cart/tmpl/default.php arround line 182
Change from this
if ($userFieldsModel->getIfRequired ('agreed')) {
if (!class_exists ('VmHtml')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'html.php');
}
echo VmHtml::checkbox ('tosAccepted', $this->cart->tosAccepted, 1, 0, 'class="terms-of-service"');

if (VmConfig::get ('oncheckout_show_legal_info', 1)) {
?>
<div class="terms-of-service">

<label for="tosAccepted">
<a href="<?php JRoute::('index.php?option=com_virtuemart&view=vendor&layout=tos&virtuemart_vendor_id=1'FALSE?>" class="terms-of-service" id="terms-of-service" rel="facebox"
  target="_blank">
<span class="vmicon vm2-termsofservice-icon"></span>
<?php echo JText::('COM_VIRTUEMART_CART_TOS_READ_AND_ACCEPTED'); ?>
</a>
</label>

<div id="full-tos">
<h2><?php echo JText::('COM_VIRTUEMART_CART_TOS'); ?></h2>
<?php echo $this->cart->vendor->vendor_terms_of_service?>
</div>

</div>
<?php
}
}

To this...
            if(VmConfig::get('agree_to_tos_onorder',0)) {
    if ($userFieldsModel->getIfRequired ('agreed')) {
    if (!class_exists ('VmHtml')) {
    require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'html.php');
    }
    echo VmHtml::checkbox ('tosAccepted', $this->cart->tosAccepted, 1, 0, 'class="terms-of-service"');
    }
}
if (VmConfig::get ('oncheckout_show_legal_info', 1)) {
?>
<div class="terms-of-service">

<label for="tosAccepted">
<a href="<?php JRoute::('index.php?option=com_virtuemart&view=vendor&layout=tos&virtuemart_vendor_id=1'FALSE?>" class="terms-of-service" id="terms-of-service" rel="facebox"
  target="_blank">
<span class="vmicon vm2-termsofservice-icon"></span>
<?php 
                            $tosText 
VmConfig::get('agree_to_tos_onorder',0) ? JText::_('COM_VIRTUEMART_CART_TOS_READ').' '.JText::_('COM_VIRTUEMART_CART_TOS_ACCEPT') : JText::_('COM_VIRTUEMART_CART_TOS_READ');
echo $tosText?>

</a>
</label>

<div id="full-tos">
<h2><?php echo JText::('COM_VIRTUEMART_CART_TOS'); ?></h2>
<?php echo $this->cart->vendor->vendor_terms_of_service?>
</div>

</div>
<?php
}


Well, that's all, hope it gets implemented ASAP.

Best regards!



[attachment cleanup by admin]
Title: Re: [BUG] Terms of Service field not validated at all
Post by: AH on September 13, 2014, 18:42:52 PM
Have you put this into the SVN?

For  consideration and inclusion in next release?
Title: Re: [BUG] Terms of Service field not validated at all
Post by: slammy on September 13, 2014, 21:20:56 PM
thank you! Did test your patch and it´s working! Nice work! The only thing I noticed is that COM_VIRTUEMART_CART_TOS_READ_AND_ACCEPTED is now displayed in english language in my cart-view allthough I have COM_VIRTUEMART_CART_TOS_READ_AND_ACCEPTED in my german language file ...
Title: Re: [BUG] Terms of Service field not validated at all
Post by: razor7 on September 14, 2014, 01:41:39 AM
Quote from: Hutson on September 13, 2014, 18:42:52 PM
Have you put this into the SVN?

For  consideration and inclusion in next release?

Hi Huston!, no, I don't have SVN commits access rights. It would be great that VM source get's switched to GitHub by the way!

PS: Can you tell Milbo about this patch?, I sent him a PM, but just in case...
Title: Re: [BUG] Terms of Service field not validated at all
Post by: razor7 on September 14, 2014, 01:44:52 AM
Quote from: slammy on September 13, 2014, 21:20:56 PM
thank you! Did test your patch and it´s working! Nice work! The only thing I noticed is that COM_VIRTUEMART_CART_TOS_READ_AND_ACCEPTED is now displayed in english language in my cart-view allthough I have COM_VIRTUEMART_CART_TOS_READ_AND_ACCEPTED in my german language file ...

You're welcome!

Regarding the lang string, you may double check your modified view for wrong strings and your lang files. Remember that for this patch to work, two new strings are added, to split the old string containing the TOS string.
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: slammy on September 14, 2014, 11:00:13 AM
Quote
Regarding the lang string, you may double check your modified view for wrong strings and your lang files. Remember that for this patch to work, two new strings are added, to split the old string containing the TOS string.

ah ok, adding the two strings in my language file and it works perfect now - sry I did overread the info in your tutorial, big thx for your fix!!!
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: Milbo on September 15, 2014, 20:53:48 PM
It is a nice fix, but the whole logic got overhauled for vm3 and I wont change it for vm2, because it was all the time that quirky way.
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: AH on September 15, 2014, 20:59:17 PM
Ok so if using VM2 we need to consider applying this patch ourselves.

Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: Milbo on September 15, 2014, 21:13:55 PM
My problem is only, if it changes the behaviour for already running stores. Vm2.6 must be absolutly backward compatible!
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: AH on September 15, 2014, 23:02:52 PM
Milbo

I understand the need to retain backward compatibility

I will have to test this to see what happens in my test version and if it is anything like the report below

Quote
First, when registering using VM registration form, I can register without checking the "I agree to the Terms of Service" check box! is that correct?
I expected VM to validate that check and to cancel user registration if user didn't accepted Terms of Service

Second, I have checked Must agree to Terms of Service on EVERY ORDER? and Show Terms of Service on the cart/checkout? in VM configuration, despite having that options enabled, I still can buy things without checking the Terms of Service checkbox at checkout!

I have bigger issue with the Joomla bind user loophole in VM1.5.26 and VM 1.1.9  so it will take me a few days to get to it.
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: nkamp on October 03, 2014, 20:42:06 PM
Hello,

I have added this changes as well. One time just copying the files over the existing files. And one time I made changes all by my self manually in the files. But it still doesn't work.

Even the TOS link is not working at the checkout. When I click on the link of TOS, at my checkout, then it returns to the home page. I have also tried the OPC of linelabox, but the same issue.
I don't know why it is not working.

I use joomla 2.5.25 with vm 2.6.10.

Nico
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: Shazam0527 on October 03, 2014, 21:35:25 PM
I hope this doesn't come across as stupid but how to Patch this?  Do I use the Upload Package file portion in the Extensions Manager?  When I do that it says it's missing the XML.  How do I patch as I'm having the same issue.  (Sorry I am relatively new to Virtuemart and Joomla)

Thanks in advance,

Jonathan
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: GJC Web Design on October 03, 2014, 21:48:08 PM
just d/L the the file
unzip
in it you will see the files you need to over write on your server

the patch is only for the devs on the SVN

use with caution
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: Shazam0527 on October 03, 2014, 22:00:24 PM
Well crud, yeah that didn't work.  Is there a fix to this issue?  It's utterly dire that they are required to Agree to the TOS for this client.  Without it, this setup is useless.  :(  And I am a HUGE fan of VM :(
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: GJC Web Design on October 03, 2014, 23:16:14 PM
Is it not easier just to write a javascript snippet that disables the checkout button if the box isn't checked?

the above code really seems a sledgehammer to crack a nut
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: bluezeyes on October 06, 2014, 01:40:22 AM
IMHO better to fix the cause of an erroneous behaviour then to try to fix the result of it with javascript, which could break / not been enabled / blocked etc.

Better the VM is working stable on a low level but working then to handover Bugfix-functions on client-side to fix it.

Greets
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: Milbo on October 06, 2014, 10:46:04 AM
The solution is to use VM3 guys.

If we keep all the time to enhance vm2, we can do that for 100s of years. But it implies also that there are constantly changes in the behaviour, which a lot people just notice at bugs (why is my stuff not anylonger working). That is the reason we have major releases in software development.

When I fix bugs again, which I already redesigned in vm3, then there are not enough ressources to write VM3. Furthermore vm2 would become more and more VM3. This is doubled work.

So long there is no problem if you are a bit flexible. If people dont want to use the TOS, then they can set agreed as hidden field on with default =1 and thats it. It is atm mainly a matter of handling and not that something does not work.
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: Shazam0527 on October 06, 2014, 19:46:44 PM
I'd be willing to use VM3, but I can't even find the download for it on the main website..
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: paradise4 on October 08, 2014, 11:07:44 AM
Hi,

I'm using VM 2.6.10 and applied the fix for the "agree-to-tos-bug". Now customers can't register anymore because on saving the bill-to-data, vm redirects to the cart, shows the "you have to agree to the tos"-messager and the data isn't saved.

Any help available on that issue?

Thanks in advance!
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: paradise4 on October 21, 2014, 10:39:02 AM
So you recommend to use the non-stable version 2.9.9 because the stable version contains bugs (like this one, which is a real show-stopper for shops in Germany)??? Come on, you can't be serious!
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: GJC Web Design on October 21, 2014, 10:43:56 AM
I say again->  Is it not easier just to write a javascript snippet that disables the checkout button if the box isn't checked?

that's what I use on VM2.0 if T&C's are required
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: paradise4 on October 22, 2014, 10:42:30 AM
Hi GJC,

I think it would be better to fix the bug, but if you can provide the mentioned snippet, I'd be happy with it :)
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: GJC Web Design on October 22, 2014, 10:48:31 AM
As discussed elsewhere - if the devs keep rebuilding VM2 it becomes VM3 - VM3 is days away..


http://bit.ly/1x7SSAn

Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: dinoide on October 31, 2014, 09:04:56 AM
same problem with 2.9.9.2

nothing TOS in the buying process. (i have activated of course)
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: paradise4 on November 13, 2014, 13:49:20 PM
So "VM 3 is days away" (on: October 22, 2014, 10:48:31 am )?  ;D Rather weeks or months, at least for a stable version where the TOS checkbox is actually being validated, I'm afraid...
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: jenkinhill on November 13, 2014, 15:23:37 PM
Quote from: paradise4 on November 13, 2014, 13:49:20 PM
Rather weeks or months, at least for a stable version where the TOS checkbox is actually being validated, I'm afraid...

So have you been helping to speed the process by contributing a little time to testing the RC versions and reporting any bugs you find in the development forum?  http://forum.virtuemart.net/index.php?board=136.0
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: paradise4 on November 14, 2014, 10:53:12 AM
I'd love to, but at the moment I'm spending a lot of time trying to solve the TOS bug in a proper way (JS isn't as it can be blocked).
By the way, why is the bug marked as [SOLVED] when it isn't?
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: AH on November 14, 2014, 20:12:18 PM
If people are blocking javascript then it is pretty pointless visiting modern e-commerce sites!
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: T.A. Garrison, LLC on January 22, 2015, 20:41:15 PM
I have to add my 2 cents...
I agree that this issues is NOT resolved.
I don't have either of the boxes checked:
Must agree to Terms of Service on EVERY ORDER    
Show Terms of Service on the cart/checkout

Yet, no matter what I do, users are forced to check the box on the front end in order to continue with the checkout.
It's frustrating for "older" customers who frequent my client's site.

This project is Joomla 3.3.6 and VM 3.0.3

I don't want to hack anything or override something that is already part of what's available in admin to control.

Thoughts?

Update:
I actually followed what I'd done in the previous version - followed jenkinhill's process - http://forum.virtuemart.net/index.php?topic=111063.msg372666#msg372666
That same process works in VM3. No I don't have the box and customers are not mandated to check the box.
Title: Re: [BUG] [SOLVED] Terms of Service field not validated at all
Post by: enserk on November 30, 2015, 12:38:59 PM
Hi there, is it possible that that bug is still Insolvenz in the 3.0.10 Version? I have the Same Problem with man Shop...