3 replies [Last post]
KingAndy's picture
Offline
Joined: 04/01/2009
Juice: 95
Was this information Helpful?

Let me start with a declaration of bias: I don't like the way CIF files work. It makes me feel dirty. I don't feel we should rely on CIF authors getting SQL INSERT statements right. It's dangerous, it's unsecure and it's easily broken by changes to table structure. Not to put too fine a point on it, it is un-Drupal.

I'd much rather see something akin to the hook_schema concept; the CIF file should declare a data structure, which is injected into the appropriate tables by an internal Ubercart function. Something like this:

<?php
function belize_uc_country() {
 
 
$country['country'] = array(
   
'country_id' => 116,
   
'country_name' => 'Belize',
   
'country_iso_code_2' => 'BZ',
   
'country_iso_code_3' => 'BLZ',
   
'version' => 1,
  );
 
 
$country['zones'] = array(
   
'BZ' => 'Belize',
   
'CY' => 'Cayo',
   
'CZL' => 'Corozal',
   
'OW' => 'Orange Walk',
   
'SC' => 'Stann Creek',
   
'TOL' => 'Toledo',
  );
 
 
$country['address_format'] = "!company\r\n!first_name !last_name\r\n!street1\r\n!street2"
  
."\r\n!city !zone_code !postal_code\r\n!country_name_if";
 
  return
$country;
}
?>

(Using Belize as an example because it has blessedly few zones. I stripped the Zones array down to a KEY=>value array, because I don't see the point of repeating the country_id over and over, and once you're down to two values you may as well. Also it makes semantic sense.)

Then whatever process imports the countries would run like so (after drawing the data structure into a variable called $country):

<?php
  $country_data
= $country['country'];
 
db_write_record('uc_countries', $country_data );
 
 
$zone_data = array('zone_country_id' => $country['country']['country_id']);
  foreach (
$country['zones'] as $zone_code => $zone_name) {
   
$zone_data ['zone_code'] = $zone_code;
   
$zone_data ['zone_name'] = $zone_name;
   
db_write_record('uc_zones', $zone_data );
  }
 
 
uc_set_address_format($country['country']['country_id'], $country['country']['address_format']);
?>

I know such a major rewrite to the dozens of .CIFs already produced is an unappealing prospect, but I think it's something that does need to be looked at because the current process is outmoded and frightening.

If this, or something like it, has already been suggested - please point me to the discussion! It's hard to find such a thing among all the talk about what CIF files are available Eye-wink

japerry@drupal.org's picture
Offline
Bug FinderGetting busy with the Ubercode.Not Kulvik
Joined: 08/08/2007
Juice: 248
Re: Overhaul CIF file system

I talked a little to Ryan about this a while ago. I don't believe the country data should be in php/drupal at all. Rather, this should be in an XML document.

What would be really nice is if there exists a common XML document that defines all the countries, and use that to build a country list in ubercart. Many other systems have done this, so it has to exist. ...

In ubercore, I don't think ubercart should manage countries at all. There are other drupal modules that handle this. One such example is the geonames module: http://drupal.org/project/geonames

KingAndy's picture
Offline
Joined: 04/01/2009
Juice: 95
"Rather, this should be in

"Rather, this should be in an XML document."

I can see the appeal - and agree it seems likely that there would be a publically-available data file in some generic format (though it would be unlikely to include the address formats).

I think PHP arrays still make more sense in my head though, if only because they slip so neatly into drupal_write_record()...

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Overhaul CIF file system

Good thoughts, Andy. Will bookmark this for the future. I'm with you on not liking the way it works / doesn't work. Sticking out tongue