Hi Stramm
I may suggest an addition for definition of a shipping address. in the original implementation, the fields are all blank if the user wants to define a shipping address the first time.
Normally the personal data stays the same and only some address parts change. So it would be, from my point of view, good if the user data from the billing address will be used as prefill for the shipping address.
Therefor I added some lines to the cpgHTML.class.php file inside the function edit_address().
Maybe you want to takeover this for the original version:
//FCA 20121228
//if no shipping address exists, prefill with billing address
if(empty($prefill)){
$prefill = cpgDB::fetchRow("SELECT sid, title, surename, lastname, street, city, zip, state, phone, country FROM {$CONFIG['TABLE_CS_ADDRESS']} WHERE type ='0' AND user_id ='" . USER_ID . "' ");
}
complete function:
// -----------------------------------------------------------------------------------------
// EDIT/ ADD ADDRESS --- atm used for shipping address
// -----------------------------------------------------------------------------------------
function edit_address()
{
global $CONFIG;
global $lang_cs_profile, $lang_common, $lang_cs_cart, $lang_cs_error, $icon_array, $cpg_udb, $user_id, $cpgshop;
if (!is_object($cpgshop)) $cpgshop = new cpgShop();
// check no item and logged in
cpgTool::check_enabled();
cpgTool::check_cart($cpgshop);
cpgTool::check_user();
// delete shipping address
$task = cpgTool::get_var('task');
if ($task == 'delsph') {
$result = cpgDB::runQuery("DELETE FROM `{$CONFIG['TABLE_CS_ADDRESS']}` WHERE type = '1' AND user_id = '" . USER_ID . "' LIMIT 1;");
if ($result) {
msg_box($lang_cs_cart['success'], $lang_cs_cart['shipping_adr_deleted'], "<span class=\"button button_normalfont\">" . $lang_common['continue'] . "</span>", "index.php?file=cpgshop/cpgshop_cart&page=verify_address", 'success');
}
} else {
// shipping or billing address
if (cpgTool::post_var('type') == false) {
$type = cpgTool::get_var('type');
} else {
$type = cpgTool::post_var('type');
}
if (!$type) $type = '0'; //get/post don't like 0 so we set to 0 if null
if (UDB_INTEGRATION == 'coppermine' && $type == 0) {
$prefill = $cpg_udb->get_user_infos(USER_ID);
} else {
$prefill = cpgDB::fetchRow("SELECT sid, title, surename, lastname, street, city, zip, state, phone, country FROM {$CONFIG['TABLE_CS_ADDRESS']} WHERE type ='" . $type . "' AND user_id ='" . USER_ID . "' ");
//FCA 20121228
//if no shipping address exists, prefill with billing address
if(empty($prefill)){
$prefill = cpgDB::fetchRow("SELECT sid, title, surename, lastname, street, city, zip, state, phone, country FROM {$CONFIG['TABLE_CS_ADDRESS']} WHERE type ='0' AND user_id ='" . USER_ID . "' ");
}
}
$required = cpgTool::required_fields();
foreach($prefill as $key => $data) {
if ($key == 'country') {
$data = cpgTool::country_by_code($data);
}
if ($key == 'title') {
$data = $lang_cs_profile["$data"];
}
if ($required[$key] == 1) {
$lang_cs_profile[$key] .= "<span class=\"smallfont\"> *</span>";
}
}
$def_array = cpgTool::profile_definition_array();
$form_data[] = array('select', 'title', $icon_array['blank'] . $lang_cs_profile['title'], cpgTool::profile_titles());
foreach ($def_array as $key) {
if ($key == 'country' || $key == 'title') continue;
$form_data[] = array('input', $key, $icon_array['blank'] . $lang_cs_profile["$key"], 255);
}
$form_data[] = array('select', 'country', $icon_array['blank'] . $lang_cs_profile['country'], cpgTool::countries());
$form_data[] = array('hidden', 'type', $type);
echo <<<EOT
<form name="cpgform" id="cpgform" method="post" action="index.php?file=cpgshop/cpgshop_cart&page=edit_address&type={$type}" onsubmit="return checkRegisterFormSubmit();">
EOT;
starttable($CONFIG['picture_table_width'], $lang_cs_profile[$type], 2);
HTMLelement::edit_address_form($form_data, $prefill);
endtable();
echo <<<EOT
</form>
EOT;
}
return;
}