Hi,
I would recommend to have a look at the code of the the PayPal Express plugin where it creates an address based on the data provided by PayPal:
$address = $this->createAddress($vars,$userid);
$addressClass = hikashop_get('class.address');
$addressid = $addressClass->save($address);
function createAddress($vars,$userid) {
if (empty($userid) )
return false;
else {
$db = JFactory::getDBO();
if(!empty($vars['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] ) ) {
$db->setQuery('SELECT zone_namekey FROM `#__hikashop_zone` WHERE zone_code_2 = '.
$db->Quote($vars['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE']).' AND zone_type = \'country\';');
$country = $db->loadResult();
}
if (empty($country) ) {
$db->setQuery('SELECT zone_namekey FROM `#__hikashop_zone` WHERE zone_name_english = '.
$db->Quote($vars['PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME']).' AND zone_type = \'country\';');
$country = $db->loadResult();
if (empty($country))
$country = $vars['PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME'];
}
if (empty($vars['PAYMENTREQUEST_0_SHIPTOSTATE'] ) )
$state = "NULL";
else {
$db->setQuery('SELECT zone_namekey FROM `#__hikashop_zone` WHERE zone_code_2 = '
.$db->Quote($vars['PAYMENTREQUEST_0_SHIPTOSTATE']).' AND zone_type = \'state\';');
$state = $db->loadResult();
if (empty($state) )
$state = $vars['PAYMENTREQUEST_0_SHIPTOSTATE'];
}
$address = new stdClass();
$address->address_user_id = $userid;
$address->address_firstname = $vars['FIRSTNAME'];
$address->address_lastname = $vars['LASTNAME'];
$address->address_street = $vars['PAYMENTREQUEST_0_SHIPTOSTREET'];
$address->address_post_code = $vars['PAYMENTREQUEST_0_SHIPTOZIP'];
$address->address_city = $vars['PAYMENTREQUEST_0_SHIPTOCITY'];
$address->address_state = $state;
$address->address_country = $country;
}
return $address;
}
You can find that in plugins/hikashoppayment/paypalexpress/