components\com_virtuemart\helpers\cart.php
When a default country is set in the userfield virtuemart_country_id 2.025d
On entry to the Checkout
The process behaves as though the BT address has been completed
Fires the "Accept TOS" message
Sets the shipping value for the default country
The code change responsible for this appears to be :-
/**
* Function Description
*
* @author Max Milbers
* @access public
* @param array $cart the cart to get the products for
* @return array of product objects
*/
// $this->pricesUnformatted = $product_prices;
public function getCartPrices($checkAutomaticSelected=true ) {
if(!class_exists('calculationHelper')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'calculationh.php');
$calculator = calculationHelper::getInstance();
$this->pricesUnformatted = $calculator->getCheckoutPrices($this, $checkAutomaticSelected);
return $this->pricesUnformatted;
}
function prepareAddressDataInCart($type='BT',$new = false){
$userFieldsModel =VmModel::getModel('Userfields');
if($new){
$data = null;
} else {
$data = (object)$this->$type;
}
if($type=='ST'){
$preFix = 'shipto_';
} else {
$preFix = '';
}
$addresstype = $type.'address';
$userFieldsBT = $userFieldsModel->getUserFieldsFor('cart',$type);
$address = $this->$addresstype = $userFieldsModel->getUserFieldsFilled(
$userFieldsBT
,$data
,$preFix
);
//vmdebug('prepareAddressDataInCart',$this->$addresstype);
if(empty($this->$type)){
$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'])){
if(!isset($tmp[$k])){
$tmp[$k] = $address['fields'][$k]['value'];
}
}
}
//$this->$type = $tmp;
}
if(!empty($this->ST) && $type!=='ST'){
$data = (object)$this->ST;
if($new){
$data = null;
}
$userFieldsST = $userFieldsModel->getUserFieldsFor('cart','ST');
$this->STaddress = $userFieldsModel->getUserFieldsFilled(
$userFieldsST
,$data
,$preFix
);
}
}
If I regress the function back to that found in 2.0.24c the checkout performs as expected
/**
* Function Description
*
* @author Max Milbers
* @access public
* @param array $cart the cart to get the products for
* @return array of product objects
*/
// $this->pricesUnformatted = $product_prices;
public function getCartPrices($checkAutomaticSelected=true ) {
if(!class_exists('calculationHelper')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'calculationh.php');
$calculator = calculationHelper::getInstance();
$this->pricesUnformatted = $calculator->getCheckoutPrices($this, $checkAutomaticSelected);
return $this->pricesUnformatted;
}
function prepareAddressDataInCart($type='BT',$new = false){
$userFieldsModel =VmModel::getModel('Userfields');
if($new){
$data = null;
} else {
$data = (object)$this->$type;
}
if($type=='ST'){
$preFix = 'shipto_';
} else {
$preFix = '';
}
$addresstype = $type.'address';
$userFieldsBT = $userFieldsModel->getUserFieldsFor('cart',$type);
$this->$addresstype = $userFieldsModel->getUserFieldsFilled(
$userFieldsBT
,$data
,$preFix
);
//vmdebug('prepareAddressDataInCart',$this->$addresstype);
// if(empty($this->$type)){
// $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'])){
// if(!isset($tmp[$k])){
// $tmp[$k] = $address['fields'][$k]['value'];
// }
//
// }
// }
//$this->$type = $tmp;
// }
if(!empty($this->ST) && $type!=='ST'){
$data = (object)$this->ST;
if($new){
$data = null;
}
$userFieldsST = $userFieldsModel->getUserFieldsFor('cart','ST');
$this->STaddress = $userFieldsModel->getUserFieldsFilled(
$userFieldsST
,$data
,$preFix
);
}
}
Any ideas how to solve this would be helpful
It should set the right shipment yes, it is done for it. But it should not fire directly the TOS. Maybe the only thing you set on "required" is the country? then it would behave like that.
Milbo
Thanks for taking the time to reply.
Setting the shipment is not correct when the address details have not been confirmed?
The default country is set to save some customers time in selecting from a country list. The shipment should not be set unless the BT/Shipping address is completed
Setting only the country as required will allow customers to fail to complete the fields we need (including ZIP and other address fields/phone)
The new code is clearly meant to fix some other issue(unsure as to what), but has introduced this problem.
The TOS does get fired as it looks as the BT virtuemart_country_id is being populated before the address is saved by the customer