Thank you MC...
I'll try and answer each question and then provide the code.
1. By "going into" create_account.php, are you referring to the module file? - Yes, includes/modules/MY_TEMPLATE/create_account.php.
2. Have you redirected to your "page" that provides the equivalent functionality of create account? - Yes, includes/modules/MY_TEMPLATE/membership_gift_data.php. Instead of redirect, I'm using include in the extra cart action file so the remainder of the "add new product to cart" process is completed.
3. What session value(s) are being set that should be cleared once the purchase is made? - Session values are set for gift_recipient_first_name, gift_recipient_last_name, gift_recipient_street_address, gift_recipient_suburb, gift_recipient_city, gift_recipient_state, gift_recipient_postcode, gift_recipient_country_zone_id, gift_recipient_country_id, gift_recipient_zone_id, gift_recipient_telephone, gift_member_number, and gift_recipient_email_address.
4. What verification is present that the data expected to support moving forwards has been completed? - successfully meeting all the data requirements in membership_gift_data.php after the form is sumitted.
5. Basically what data is still present as part of the recheckout process that wasn't there before and how does it affect your program flow? - the session values mentioned above. The session gift_recipient_first_name is used to bypass going through the process again should additional "add product to cart" for the membership gift product occur.
Now for the code...
Note that the code is a work in progress.
1. extra_cart_action file:
Code:
<?php
global $messageStack;
if ($_GET['action'] == 'add_product') {
if (isset($_POST['products_id']) && $_POST['cart_quantity'] > 0 && $_POST['products_id'] == MEMBERSHIP_PID) {
if (isset($_POST['id'])) {
foreach($_POST['id'] as $option => $value) {
if ($option == GIFT_OPTION_NUMBER && $value == GIFT_VALUE_NUMBER_YES) {
if (!isset($_SESSION['gift_recipient_first_name'])) {
// display recipients additional data form
require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_GIFT_DATA));
}
}
}
}
}
}
2. membership_gift_data.php placed in includes/modules/MY_TEMPLATE/
Code:
<?php
/**
* membership_gift_data.php
* Modified version of includes/modules/febt_store_template/create_account.php
* to capture membership gift recipients data
*
* @package modules
* @copyright Copyright 2003-2016 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: Author: zcwilt Fri Apr 15 Modified in v1.5.5 $
*/
global $db, $messageStack;
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
/**
* Set some defaults
*/
$process = false;
$zone_name = '';
$entry_state_has_zones = '';
$error_state_input = false;
$state = '';
$zone_id = 0;
$error = false;
$member_number_OK = FALSE;
/**
* Process form contents
*/
if (isset($_POST['action']) && ($_POST['action'] == 'process')) {
$process = true;
$gift_antiSpam = isset($_POST['should_be_empty']) ? zen_db_prepare_input($_POST['should_be_empty']) : '';
$gift_firstname = zen_db_prepare_input(zen_sanitize_string($_POST['firstname']));
$gift_lastname = zen_db_prepare_input(zen_sanitize_string($_POST['lastname']));
$gift_email_address = zen_db_prepare_input($_POST['email_address']);
$gift_street_address = zen_db_prepare_input($_POST['street_address']);
if (ACCOUNT_SUBURB == 'true') $gift_suburb = zen_db_prepare_input($_POST['suburb']);
$gift_postcode = zen_db_prepare_input($_POST['postcode']);
$gift_city = zen_db_prepare_input($_POST['city']);
if (ACCOUNT_STATE == 'true') {
$gift_state = zen_db_prepare_input($_POST['state']);
if (isset($_POST['zone_id'])) {
$gift_zone_id = zen_db_prepare_input($_POST['zone_id']);
} else {
$gift_zone_id = false;
}
}
$gift_country = zen_db_prepare_input($_POST['zone_country_id']);
$gift_telephone = zen_db_prepare_input($_POST['telephone']);
if (strlen($gift_firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
$error = true;
$gift_error['firstname'] = 1;
$messageStack->add('membership_gift_data', ENTRY_FIRST_NAME_ERROR);
}
if (strlen($gift_lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
$error = true;
$gift_error['lastname'] = 1;
$messageStack->add('membership_gift_data', ENTRY_LAST_NAME_ERROR);
}
if (strlen($gift_email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
$error = true;
$gift_error['email address'] = 1;
$messageStack->add('membership_gift_data', ENTRY_EMAIL_ADDRESS_ERROR);
} elseif (zen_validate_email($gift_email_address) == false) {
$error = true;
$gift_error['email address validation'] = 1;
$messageStack->add('membership_gift_data', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
}
if (strlen($gift_street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
$error = true;
$gift_error['street address'] = 1;
$messageStack->add('membership_gift_data', ENTRY_STREET_ADDRESS_ERROR);
}
if (strlen($gift_city) < ENTRY_CITY_MIN_LENGTH) {
$error = true;
$gift_error['city'] = 1;
$messageStack->add('membership_gift_data', ENTRY_CITY_ERROR);
}
if (ACCOUNT_STATE == 'true') {
$check_query = "SELECT count(*) AS total
FROM " . TABLE_ZONES . "
WHERE zone_country_id = :zoneCountryID";
$check_query = $db->bindVars($check_query, ':zoneCountryID', $gift_country, 'integer');
$check = $db->Execute($check_query);
$entry_state_has_zones = ($check->fields['total'] > 0);
if ($entry_state_has_zones == true) {
$zone_query = "SELECT distinct zone_id, zone_name, zone_code
FROM " . TABLE_ZONES . "
WHERE zone_country_id = :zoneCountryID
AND " .
((trim($gift_state) != '' && $gift_zone_id == 0) ? "(upper(zone_name) like ':zoneState%' OR upper(zone_code) like '%:zoneState%') OR " : "") .
"zone_id = :zoneID
ORDER BY zone_code ASC, zone_name";
$zone_query = $db->bindVars($zone_query, ':zoneCountryID', $gift_country, 'integer');
$zone_query = $db->bindVars($zone_query, ':zoneState', strtoupper($gift_state), 'noquotestring');
$zone_query = $db->bindVars($zone_query, ':zoneID', $gift_zone_id, 'integer');
$zone = $db->Execute($zone_query);
//look for an exact match on zone ISO code
$found_exact_iso_match = ($zone->RecordCount() == 1);
if ($zone->RecordCount() > 1) {
while (!$zone->EOF && !$found_exact_iso_match) {
if (strtoupper($zone->fields['zone_code']) == strtoupper($gift_state) ) {
$found_exact_iso_match = true;
continue;
}
$zone->MoveNext();
}
}
if ($found_exact_iso_match) {
$gift_zone_id = $zone->fields['zone_id'];
$gift_zone_name = $zone->fields['zone_name'];
} else {
$error = true;
$gift_error['state'] = 1;
$error_state_input = true;
$messageStack->add('membership_gift_data', ENTRY_STATE_ERROR_SELECT);
}
} else {
if (strlen($gift_state) < ENTRY_STATE_MIN_LENGTH) {
$error = true;
$gift_error['state length'] = 1;
$error_state_input = true;
$messageStack->add('membership_gift_data', ENTRY_STATE_ERROR);
}
}
}
if (strlen($gift_postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
$error = true;
$gift_error['postcode'] = 1;
$messageStack->add('membership_gift_data', ENTRY_POST_CODE_ERROR);
}
if ( (is_numeric($gift_country) == false) || ($gift_country < 1) ) {
$error = true;
$gift_error['country'] = 1;
$messageStack->add('membership_gift_data', ENTRY_COUNTRY_ERROR);
}
if (strlen($gift_telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
$error = true;
$gift_error['telephone'] = 1;
$messageStack->add('membership_gift_data', ENTRY_TELEPHONE_NUMBER_ERROR);
}
/*
Add FEBT number and validate against member list
*/
$gift_member_number = zen_db_prepare_input($_POST['member_number']);
$_SESSION['gift_is_member'] = FALSE;
$_SESSION['gift_member_number'] = '';
if ($gift_member_number <> "") {
$gift_febt_number = find_member_number(0, $gift_lastname, $gift_firstname, $gift_street_address, $gift_postcode, $gift_city, $gift_state, $gift_country, $gift_zone_id);
if (substr($gift_febt_number, 0, 3) == "ERR") {
// name and address fail to match any member in febt database
$error = TRUE;
$gift_error['member no match'] = 1;
$messageStack->add('membership_gift_data', ERROR_FEBT_MEMBER_VALIDATION_NAME_OR_ADDRESS_ERROR, 'error');
} else {
// number returned
if ($gift_febt_number !== $gift_member_number) {
// name and address match a member but the number is wrong
$error = TRUE;
$gift_error['wrong member number'] = 1;
$messageStack->add('membership_gift_data', ERROR_FEBT_MEMBER_VALIDATION_NUMBER_ERROR, 'error');
} else {
// customer number, name and address match, set data
$_SESSION['gift_is_member'] = TRUE;
$_SESSION['gift_member_number'] = $gift_member_number;
} // end of number, name and address match
} // end of number returned from find_member_number
} // end of $member_number <> ""
/*
End of FEBT number validation
*/
if ($error == true) {
// hook notifier class
} elseif ($gift_antiSpam != '') {
$messageStack->add_session('header', (defined('ERROR_CREATE_ACCOUNT_SPAM_DETECTED') ? ERROR_CREATE_ACCOUNT_SPAM_DETECTED : 'Thank you, your account request has been submitted for review.'), 'success');
zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
} else {
$_SESSION['gift_recipient_first_name'] = $gift_firstname;
$_SESSION['gift_recipient_last_name'] = $gift_lastname;
$_SESSION['gift_recipient_street_address'] = $gift_street_address;
$_SESSION['gift_recipient_suburb'] = $gift_suburb;
$_SESSION['gift_recipient_city'] = $gift_city;
$_SESSION['gift_recipient_state'] = $gift_state;
$_SESSION['gift_recipient_postcode'] = $gift_postcode;
$_SESSION['gift_recipient_zone_country_id'] = $gift_zone_country_id;
$_SESSION['gift_recipient_country_id'] = $gift_country;
$_SESSION['gift_recipient_zone_id'] = $gift_zone_id;
$_SESSION['gift_recipient_telephone'] = $gift_telephone;
$_SESSION['gift_recipient_email_address'] = $gift_email_address;
// zen_redirect(zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'));
} //endif !error
}
/*
* Set flags for template use:
*/
$selected_country = (isset($_POST['zone_country_id']) && $_POST['zone_country_id'] != '') ? $country : SHOW_CREATE_ACCOUNT_DEFAULT_COUNTRY;
$flag_show_pulldown_states = ((($process == true || $entry_state_has_zones == true) && $zone_name == '') || ACCOUNT_STATE_DRAW_INITIAL_DROPDOWN == 'true' || $error_state_input) ? true : false;
$state = ($flag_show_pulldown_states) ? ($state == '' ? ' ' : $state) : $zone_name;
$state_field_label = ($flag_show_pulldown_states) ? '' : ENTRY_STATE;
3. tpl_membership_gift_data_default.php placed in includes/templates/MY_TEMPLATE/templates/
Code:
<?php
/**
* Page Template
*
* Loaded automatically by index.php?main_page=create_account.<br />
* Displays form to enter membership gift data.
*
* @package templateSystem
* @copyright Copyright 2003-2007 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: tpl_membership_gift_data_default.php febt file $
*/
?>
<div class="centerColumn" id="createAcctDefault">
<h3 id="createAcctDefaultHeading"><?php echo GIFT_FORM_TITLE; ?></h3>
<?php echo zen_draw_form('membership_gift_data', zen_href_link(FILENAME_GIFT_DATA, '', 'SSL'), 'post', 'onsubmit="return check_form(membership_gift_data);"') . zen_draw_hidden_field('action', 'process'); ?>
<fieldset>
<legend><?php echo GIFT_FORM_LEGEND; ?></legend>
<?php require($template->get_template_dir('tpl_modules_membership_gift_data_form.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_membership_gift_data_form.php'); ?>
</fieldset>
<div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_SUBMIT, BUTTON_SUBMIT_ALT); ?></div>
</form>
</div>
4. tpl_modules_membership_gift_data_form.php placed in includes/templates/MY_TEMPLATE/templates/
Code:
<?php
/**
* Page Template
*
* Loaded automatically by index.php?main_page=create_account.<br />
* Displays membership gift data form.
*
* @package templateSystem
* @copyright Copyright 2003-2016 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: rbarbour zcadditions.com Fri Feb 26 00:03:33 2016 -0500 Modified in v1.5.5 $
*/
?>
<fieldset>
<legend><?php echo TABLE_HEADING_ADDRESS_DETAILS; ?></legend>
<label class="inputLabel" for="firstname"><?php echo ENTRY_FIRST_NAME; ?></label>
<?php echo zen_draw_input_field('firstname', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_firstname', '40') . ' id="firstname" placeholder="' . ENTRY_FIRST_NAME_TEXT . '"' . ((int)ENTRY_FIRST_NAME_MIN_LENGTH > 0 ? ' required' : '')); ?>
<br class="clearBoth" />
<label class="inputLabel" for="lastname"><?php echo ENTRY_LAST_NAME; ?></label>
<?php echo zen_draw_input_field('lastname', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_lastname', '40') . ' id="lastname" placeholder="' . ENTRY_LAST_NAME_TEXT . '"'. ((int)ENTRY_LAST_NAME_MIN_LENGTH > 0 ? ' required' : '')); ?>
<br class="clearBoth" />
<label class="inputLabel" for="street-address"><?php echo ENTRY_STREET_ADDRESS; ?></label>
<?php echo zen_draw_input_field('street_address', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_street_address', '40') . ' id="street-address" placeholder="' . ENTRY_STREET_ADDRESS_TEXT . '"'. ((int)ENTRY_STREET_ADDRESS_MIN_LENGTH > 0 ? ' required' : '')); ?>
<br class="clearBoth" />
<?php echo zen_draw_input_field('should_be_empty', '', ' size="40" id="CAAS" style="visibility:hidden; display:none;" autocomplete="off"'); ?>
<?php
if (ACCOUNT_SUBURB == 'true') {
?>
<label class="inputLabel" for="suburb"><?php echo ENTRY_SUBURB; ?></label>
<?php echo zen_draw_input_field('suburb', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_suburb', '40') . ' id="suburb" placeholder="' . ENTRY_SUBURB_TEXT . '"'); ?>
<br class="clearBoth" />
<?php
}
?>
<label class="inputLabel" for="city"><?php echo ENTRY_CITY; ?></label>
<?php echo zen_draw_input_field('city', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_city', '40') . ' id="city" placeholder="' . ENTRY_CITY_TEXT . '"'. ((int)ENTRY_CITY_MIN_LENGTH > 0 ? ' required' : '')); ?>
<br class="clearBoth" />
<?php
if (ACCOUNT_STATE == 'true') {
if ($flag_show_pulldown_states == true) {
?>
<label class="inputLabel" for="stateZone" id="zoneLabel"><?php echo ENTRY_STATE; ?></label>
<?php
echo zen_draw_pull_down_menu('zone_id', zen_prepare_country_zones_pull_down($selected_country), $zone_id, 'id="stateZone"');
if (zen_not_null(ENTRY_STATE_TEXT)) echo ' <span class="alert">' . ENTRY_STATE_TEXT . '</span>';
}
?>
<?php if ($flag_show_pulldown_states == true) { ?>
<br class="clearBoth" id="stBreak" />
<?php } ?>
<label class="inputLabel" for="state" id="stateLabel"><?php echo $state_field_label; ?></label>
<?php
echo zen_draw_input_field('state', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_state', '40') . ' id="state" placeholder="' . ENTRY_STATE_TEXT . '"');
if ($flag_show_pulldown_states == false) {
echo zen_draw_hidden_field('zone_id', $zone_name, ' ');
}
?>
<br class="clearBoth" />
<?php
}
?>
<label class="inputLabel" for="postcode"><?php echo ENTRY_POST_CODE; ?></label>
<?php echo zen_draw_input_field('postcode', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_postcode', '40') . ' id="postcode" placeholder="' . ENTRY_POST_CODE_TEXT . '"' . ((int)ENTRY_POSTCODE_MIN_LENGTH > 0 ? ' required' : '')
); ?>
<br class="clearBoth" />
<label class="inputLabel" for="country"><?php echo ENTRY_COUNTRY; ?></label>
<?php echo zen_get_country_list('zone_country_id', $selected_country, 'id="country" ' . ($flag_show_pulldown_states == true ? 'onchange="update_zone(this.form);"' : '')) . (zen_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="alert">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?>
<br class="clearBoth" />
</fieldset>
<fieldset>
<legend><?php echo TABLE_HEADING_PHONE_FAX_DETAILS; ?></legend>
<label class="inputLabel" for="telephone"><?php echo ENTRY_TELEPHONE_NUMBER; ?></label>
<?php echo zen_draw_input_field('telephone', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_telephone', '40') . ' id="telephone" placeholder="' . ENTRY_TELEPHONE_NUMBER_TEXT . '"' . ((int)ENTRY_TELEPHONE_MIN_LENGTH > 0 ? ' required' : ''), 'tel'); ?>
<br class="clearBoth" />
<label class="inputLabel" for="member_number"><?php echo ENTRY_MEMBER_NUMBER; ?></label>
<?php echo zen_draw_input_field('member_number', $account->fields['customers_member_number'], 'id="member_number"') . (zen_not_null(ENTRY_MEMBER_NUMBER_TEXT) ?
'<span class="alert">' . ENTRY_MEMBER_NUMBER_TEXT . '</span>': ''); ?>
</fieldset>
<fieldset>
<legend><?php echo TABLE_HEADING_LOGIN_DETAILS; ?></legend>
<label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL_ADDRESS; ?></label>
<?php echo zen_draw_input_field('email_address', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_email_address', '40') . ' id="email-address" placeholder="' . ENTRY_EMAIL_ADDRESS_TEXT . '"' . ((int)ENTRY_EMAIL_ADDRESS_MIN_LENGTH > 0 ? ' required' : ''), 'email'); ?>
<br class="clearBoth" />
</fieldset>
5. header_php.php placed in includes/modules/pages/membership_gift_data/
Code:
<?php
/**
* membership_gift_data header_php.php
*
* @package page
* @copyright Copyright 2003-2006 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: header_php.php 4035 2006-07-28 05:49:06Z drbyte $
* febt file
*/
require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
include(DIR_WS_MODULES . zen_get_module_directory(FILENAME_GIFT_DATA));
$breadcrumb->add(NAVBAR_TITLE);
All the javascript files in includes/modules/pages/create_account/ folder were copied and placed in the includes/modules/pages/membership_gift_data folder.
6. There's also a file containing definitions of the constants new to the above files. it's febt_membership_gift_data_definitions and placed in includes/languages/english/extra_definitions.
Code:
<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 The zen-cart developers |
// | |
// | http://www.zen-cart.com/index.php |
// | |
// | Portions Copyright (c) 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.zen-cart.com/license/2_0.txt. |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: febt_membership_gift_data_definitions.php $
//
DEFINE('MEMBERSHIP_PID', '601');
DEFINE('GIFT_OPTION_NUMBER', '26');
DEFINE('GIFT_VALUE_NUMBER_YES', '88');
DEFINE('FILENAME_GIFT_DATA', 'membership_gift_data');
DEFINE('ERROR_GIFT_ERROR', 'Sorry, only one membership gift per order is allowed');
DEFINE('GIFT_FORM_TITLE', 'Please fill out form and click Submit');
DEFINE('GIFT_FORM_LEGEND', 'Membership gift recipients information');
The program flow I want is:
The customer checks a "gift" box on the product info page and clicks the add to cart button. For this product, if the session variable is not set, membership_gift_data.php is "included" through a require statement. The file included is membership_gift_data.php. The $_POST['action'] variable is not "process", so only a few variables are set. Then the form should be drawn using tpl_membership_gift_data_default followed by tpl_membership_gift_data_form.php. The customer fills out the form and clicks submit. Processing goes to membership_gift_data.php after passing through the form_check function and the header file. Now $_POST['action'] is set to "process", and further tests are made on the inputs. If any errors, a message is displayed and the form is drawn again. If no errors, processing returns to the extra_cart_action file and eventually the add product to cart process finishes.
The sequence of files must be set with include statements but I don't know where they are. I guess I could use an include statement to the template file in the first pass-through path in membership_gift_data.php.
Hope all this helps you MC.
Dave
Bookmarks