Needs work
Project:
SagePay Form Integration for Drupal Commerce
Version:
7.x-1.0-beta2
Component:
Code
Priority:
Critical
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
7 Oct 2011 at 14:05 UTC
Updated:
2 Feb 2013 at 10:30 UTC
Jump to comment: Most recent file
Comments
Comment #1
phily245 commentedUPDATE: I substituted the following code in on line 439 of commerce_sagepay_form.module and it worked, proving that it is an issue with the single name field.
if(!isset($address['last_name']) || $address['last_name'] == '') {
$address['last_name'] = 'AAA';
}
if(!isset($address['first_name']) || $address['first_name'] == '') {
$address['first_name'] = 'ZZZ';
}
Both $address['first_name'] and $address['last_name'] were empty, proving it was a problem with the single name field not splitting the name into two variables.
Comment #2
phily245 commentedUPDATE: Fixed the file by splitting the single string by whitespaces and creating 2 different name values with support for if there are no whitespaces. Here is the fix (put in on the same line as my last post):
//Explode the name into the words which comprise the name.
$name = explode(" ", $address['name_line']);
//Count the amount of words and -1 so it relates to the $name array.
$name_num_words = sizeof($name) -1;
//If there is only one name in the box, put it in both fields to ensure no SagePay malformation
if ($name_num_words == 0) {
$address['first_name'] = $address['name_line'];
$address['last_name'] = $address['name_line'];
}else{
//Create or empty the $address['first_name'] variable.
$address['first_name'] ='';
//for every word except the last, append the word to the $address['first_name'].
for($i = 0; $i < $name_num_words; ++$i) {
if ($i == $name_num_words) {
break;
}else{
$address['first_name'] = $address['first_name'] . $name[$i] . ' ';
}
}
}
//Declare $address['last_name'] is the last array item in $name.
$address['last_name'] = $name[$name_num_words];
Find the entire patched commerce_sagepay_form.module attached.
Comment #3
ikos commentedHi,
SagePay requires the name as two variables so I added a note in the read me file about how to set up the address field.
It may be possible to check which type of name field an address is using and split the field accordingly. Do you think this would be useful? Right now we just set all sites up using a first name and last name.
Richard
Comment #4
phily245 commentedHi Richard,
I think it will be, as it covers all bases and means the module will be easier to intergrate to a site set up with just one name field. I personally thought altering the sagepay .module file was easier as the code was easier to find and I was more familiar with it as I develop more bespoke e-commerce sites using sagepay than using Drupal commerce modules.
Phil
Comment #5
ikos commentedVariation of this has been committed to the latest dev version.
Comment #7
doliveros commentedHello ikos.
I think the name variation is wrongly set on _commerce_sagepay_form_format_customer_name, line 721 of commerce_sagepay_form.module.
As you can see on:
, the first name value is always set to "Not set", even when the name line is a valid name.
The correct first name validation should be:
Cheers.