Author Topic: Mis-configured Shopper Fields can prevent User Address from loading  (Read 3967 times)

mbarry

  • Beginner
  • *
  • Posts: 47
Mis-configured Shopper Fields can prevent User Address from loading when a registered user logs in during the checkout phase

Steps
1. Add a product to the cart (should not be logged in at this stage)
2. Display the shopping cart
3. Check under the "Bill to"  title, there may be one or more text entries presented below the title (see attachment ShopperFieldMisconfiguration.jpg)
4. Login via the shopping Cart login or site login form (this is an already registered user with valid BT address data )
5. If condition in step 3. exists, the Address fields will be blank except for the email address. (See attachment ShopperFieldMisconfigurationAfterLogin.jpg)
6. Check Account Maintenance; the Bill To information will be blank

While the conditions for the error to occur are likely to be rare, it has occurred to me and thefore, could to happen to others as they configure their shops.

The conditions are as follows:
  Must be two or more Shopper Fields with Default values set to some value other than zero. (See attachment ShopperFieldConfiguration.jpg)
  Must be a Shopper field that Virtuemart Cart code does not overwrite; these include delimiter and text fields; there maybe others:
      delimiter_userinfo (type = delimiter)
      delimiter_billto (type = delimiter)
      company (type = text)
      tax_exemption_number (type = text)
      Any other "text" or "delimiter" field created by user that is setup with a default value.

Note: default values in any of the key address fields triggers an error message which alerts the user to some type of misconfiguration however,
the error message does not identify that fact that it is a default value in one of the Shopper Fields that triggered the error message.

The below code framgents show how this quirky error can occur.

 
Code: [Select]
public function getUserFieldsFilled($_selection, $_userData = null, $_prefix = ''){  line 738 of administrator/components/com_virtuemart/models/userfields.php



  foreach ($_selection as $_fld) {

$_return['fields'][$_fld->name] = array(
     'name' => $_prefix . $_fld->name
,'value' => (($_userData == null || !array_key_exists($_fld->name, $_userData))  // Debug (Line 763) this line will populate the value field with the "Default" value of the shopper field.
                                                                                                            // The default value is set via the Virtuemart Configuration -> Shopper Fields or could be ported across
                                                                                                           // due the Migration process
? $_fld->default
: @html_entity_decode($_userData[$_fld->name],ENT_COMPAT,'UTF-8'))
,'title' => JText::_($_fld->title)
,'type' => $_fld->type
,'required' => $_fld->required
,'hidden' => false
,'formcode' => ''
,'description' => JText::_($_fld->description)
);





 
Code: [Select]
function prepareAddressDataInCart($type='BT',$new = false){   Line 1406 of components/com_virtuemart/helpers/cart.php



if(empty($this->$type) and $type=='BT'){   // Debug (line 1430) $this->BT is populated here only if it is empty.
$tmp =&$this->$type ;
$tmp = array();
foreach($address['fields'] as $k =>$field){
//vmdebug('prepareAddressDataInCart',$k,$field);
if($k=='virtuemart_country_id'){
if(isset($address['fields'][$k]['virtuemart_country_id']) and !isset($tmp['virtuemart_country_id'])){
$tmp['virtuemart_country_id'] = $address['fields'][$k]['virtuemart_country_id'];
}
} else if($k=='virtuemart_state_id') {
if(isset($address['fields'][$k]['virtuemart_state_id']) and !isset($tmp['virtuemart_state_id'])){
$tmp['virtuemart_state_id'] = $address['fields'][$k]['virtuemart_state_id'];
}
} else if (!empty($address['fields'][$k]['value'])){                 // Debug (line 1443) these lines are populating shopper fields (specifically the fields with type = delimiter or text)
                                                                                                         // where the value is not empty. This occurs on first entry to this function where $address is not empty.
if(!isset($tmp[$k])){
$tmp[$k] = $address['fields'][$k]['value'];
}

}

}



Code: [Select]
function setPreferred() { line 154 of components/com_virtuemart/helpers/cart.php 

$userModel = VmModel::getModel('user');
$user = $userModel->getCurrentUser();

if (empty($this->BT) || (!empty($this->BT) && count($this->BT) <=1) ) {  // Debug (line 159) $this->BT may not be empty, if it has two or more entries the test fails and hence,
                                                                                          // the BT Address fields are never populated in the Shopping cart for Registered users who login via checkout page.
foreach ($user->userInfo as $address) {
if ($address->address_type == 'BT') {
$this->saveAddressInCart((array) $address, $address->address_type,false);
}
}
}


Perhaps some sort of warning message that the BT address fields will not be populated due to default values being set in the Shopper Fields or simply overwrite any existing data anyway.
Or better still, since these Shopper Fields are not likely to be important for Virtuemart itself to function, should there be a case where the default values are preserved and the BT address fields populated anyway.
 


[attachment cleanup by admin]

jshoeks

  • Beginner
  • *
  • Posts: 17
Re: Mis-configured Shopper Fields can prevent User Address from loading
« Reply #1 on: February 26, 2014, 10:47:20 am »
Hi,

i have this problem too on a page...

has tested alot and found out, that does this works.

in components/com_virtuemart/helpers/cart.php
Code: [Select]
public function setPreferred() {

$usermodel = VmModel::getModel('user');
$user = $usermodel->getCurrentUser();

//if (empty($this->BT) || (!empty($this->BT) && count($this->BT) <=1) ) {
foreach ($user->userInfo as $address) {
if ($address->address_type == 'BT') {
$this->saveAddressInCart((array) $address, $address->address_type,false);
}
}
//}
See the two lines i have set // infront of.

I know this is not a good sollution to hack the core files, but its alot better, than the clients complain and its not working.
Please fix this asap in virtuemart

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10070
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Mis-configured Shopper Fields can prevent User Address from loading
« Reply #2 on: February 26, 2014, 11:57:57 am »
I am sorry, I dont understand the error.

If you have a user which is registered on joomla, and there is not vm address data, it is exactly meant that it is prefilled with the default. If you dont want this behaviour, then do not enter a default value.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

mbarry

  • Beginner
  • *
  • Posts: 47
Re: Mis-configured Shopper Fields can prevent User Address from loading
« Reply #3 on: February 28, 2014, 12:23:31 pm »
The issue has nothing to do with the registered user.

The problem occurs for a very specific case when shopper fields are created or modified in the backend.
  Must be two or more Shopper Fields with Default values set to some value other than zero.
  Must be a Shopper field that Virtuemart Cart code does not overwrite; these include delimiter and text fields; there maybe others:
      delimiter_userinfo (type = delimiter)
      delimiter_billto (type = delimiter)
      company (type = text)
      tax_exemption_number (type = text)
 
1. Select an existing a shopper field (or create a new one) that is of type 'delimiter' or 'text'. (Use delimiter_userinfo for this test)
2. Add a value to the default attribute of the shopper field and save the changes.
3. Repeat steps 1 and 2 for another shopper field. (Use company for this test)
4. From the front end add a product to the cart without being logged in.
5. Log into the shop.
6. The error will occur in the cart where the users address does not get displayed.
7. Select Account Maintenance; you will find all the address fields are blank. If shopper field company is displayed, it will display whatever default data was entered in the back end.

Note: I see no particular reason why any of these fields would have a default value however, if two or more fields do (and can happen), then this error will occur.

I have highlighted the code fragments that relates to this problem.

Commenting out the line identified by jswebpilots is exactly the line that causes this problem due to the condition identified above.

For jswebpilots - check that your shopper fields in the backend do not have data in the default attribute. If they do, clear it out and that should fix the problem.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10070
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Mis-configured Shopper Fields can prevent User Address from loading
« Reply #4 on: March 02, 2014, 21:22:11 pm »
I changed this logic anyway a bit in vm2.5.2, please test this version.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

mbarry

  • Beginner
  • *
  • Posts: 47
Re: Mis-configured Shopper Fields can prevent User Address from loading
« Reply #5 on: March 03, 2014, 22:22:30 pm »
Hi Milbo,
where do I find vm2.5.2?
I can find vm2.5.1 released for test on 25 Feb 2014.

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3224
  • VirtueMart Version: 3.8.4
Re: Mis-configured Shopper Fields can prevent User Address from loading
« Reply #6 on: March 04, 2014, 09:42:09 am »
2.5.2 not on  file repository
regards
A

Joomla 3.9.19
php 7.3

jshoeks

  • Beginner
  • *
  • Posts: 17
Re: Mis-configured Shopper Fields can prevent User Address from loading
« Reply #7 on: October 05, 2014, 20:19:59 pm »
I changed this logic anyway a bit in vm2.5.2, please test this version.

not fixed in the latest version still....

still makes same error

Ubie

  • Beginner
  • *
  • Posts: 1
  • A beginner
Re: Mis-configured Shopper Fields can prevent User Address from loading
« Reply #8 on: February 09, 2016, 12:43:59 pm »
I changed this logic anyway a bit in vm2.5.2, please test this version.

not fixed in the latest version still....

Testogen still works like a charm.

This is fixed now though right jshoeks in the latest version? I still need to upgrade.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10070
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Mis-configured Shopper Fields can prevent User Address from loading
« Reply #9 on: February 09, 2016, 23:22:08 pm »
I assume it is fixed, very likely in vm2.6.x and also in vm3.x
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/