// setup the default choice, which represents address in Store Settings
$def_choice = $SC['settings']['Street']." -- ".$SC['settings']['City'].", ".get_field_val("States","Abbreviation","record_number = ".$SC['settings']['State_or_Province']);
// truncate if too long
$def_choice = strlen($def_choice) > 45 ? substr($def_choice,0,45)."..." : $def_choice;
$def_choice .= $SC['settings']['Postal_Code'] ? ", ".$SC['settings']['Postal_Code'] : '';

$options[$def_choice] = 1;

$warehouses = get_records("Locations","*","Warehouse = 1");
foreach($warehouses as $warehouse) {
	if($warehouse['record_number'] != 1) {
		
		// use name if available, else use street address
		$choice_str = $warehouse['Name'] ? $warehouse['Name'] : $warehouse['Street']." -- ".$warehouse[City].", ".get_field_val("States","Abbreviation","record_number = ".$warehouse['State_or_Province']);
		
		// truncate if too long
		$choice_str = strlen($choice_str) > 45 ? substr($choice_str,0,45)."..." : $choice_str;
		
		// add postal code to end
		$choice_str .= $warehouse[Postal_Code] ? ", $warehouse[Postal_Code]" : '';

		$options[$choice_str] = $warehouse['record_number'];
	}
}

// sort by choice
ksort($options);