Navigation Menu

Skip to content

Commit

Permalink
more work custom fields done
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed Apr 16, 2014
1 parent 3be5470 commit 36c7d5b
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 170 deletions.
33 changes: 6 additions & 27 deletions upload/admin/controller/sale/customer.php
Expand Up @@ -844,37 +844,16 @@ protected function getForm() {
// Custom Fields
$this->load->model('sale/custom_field');


$data['custom_fields'] = array();

// Customer Group
$custom_fields = $this->model_sale_custom_field->getCustomFields();

foreach ($custom_fields as $custom_field) {
if ($custom_field['type'] == 'checkbox') {
$value = array();
} else {
$value = $custom_field['value'];
}

$data['custom_fields'][] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'custom_field_value' => $custom_field['custom_field_value'],
'name' => $custom_field['name'],
'location' => $custom_field['location'],
'type' => $custom_field['type'],
'value' => isset($custom_field_info['custom_field'][$custom_field['location']][$custom_field['custom_field_id']]) ? $custom_field_info['custom_field'][$custom_field['location']][$custom_field['custom_field_id']] : $value
);
}
$data['custom_fields'] = $this->model_sale_custom_field->getCustomFields();

if (isset($this->request->post['custom_field'])) {
$data['customer_custom_field'] = $this->request->post['custom_field'];
$data['account_custom_field'] = $this->request->post['custom_field'];
} elseif (!empty($customer_info)) {
$data['customer_custom_field'] = unserialize($customer_info['custom_field']);
$data['account_custom_field'] = unserialize($customer_info['custom_field']);
} else {
$data['customer_custom_field'] = array();
}

$data['account_custom_field'] = array();
}
if (isset($this->request->post['newsletter'])) {
$data['newsletter'] = $this->request->post['newsletter'];
} elseif (!empty($customer_info)) {
Expand Down
26 changes: 19 additions & 7 deletions upload/admin/view/template/sale/customer_form.tpl
Expand Up @@ -112,7 +112,7 @@
<select name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-control">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($custom_field['custom_field_value'] as $custom_field_value) { ?>
<?php if ($custom_field_value['custom_field_value_id'] == $custom_field['value']) { ?>
<?php if (isset($account_custom_field[$custom_field['custom_field_id']]) && $custom_field_value['custom_field_value_id'] == $account_custom_field[$custom_field['custom_field_id']]) { ?>
<option value="<?php echo $custom_field_value['custom_field_value_id']; ?>" selected="selected"><?php echo $custom_field_value['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $custom_field_value['custom_field_value_id']; ?>"><?php echo $custom_field_value['name']; ?></option>
Expand All @@ -133,7 +133,7 @@
<div id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>">
<?php foreach ($custom_field['custom_field_value'] as $custom_field_value) { ?>
<div class="radio">
<?php if ($custom_field_value['custom_field_value_id'] == $custom_field['value']) { ?>
<?php if (isset($account_custom_field[$custom_field['custom_field_id']]) && $custom_field_value['custom_field_value_id'] == $account_custom_field[$custom_field['custom_field_id']]) { ?>
<label>
<input type="radio" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" value="<?php echo $custom_field_value['custom_field_value_id']; ?>" checked="checked" />
<?php echo $custom_field_value['name']; ?></label>
Expand All @@ -159,7 +159,7 @@
<div id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>">
<?php foreach ($custom_field['custom_field_value'] as $custom_field_value) { ?>
<div class="checkbox">
<?php if (in_array($custom_field_value['custom_field_value_id'], $custom_field['value'])) { ?>
<?php if (isset($account_custom_field[$custom_field['custom_field_id']]) && in_array($custom_field_value['custom_field_value_id'], $account_custom_field[$custom_field['custom_field_id']])) { ?>
<label>
<input type="checkbox" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>][]" value="<?php echo $custom_field_value['custom_field_value_id']; ?>" checked="checked" />
<?php echo $custom_field_value['name']; ?></label>
Expand Down Expand Up @@ -189,6 +189,8 @@
</div>
</div>
<?php } ?>


<?php if ($custom_field['type'] == 'textarea') { ?>
<div id="custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-group custom-field">
<label class="col-sm-2 control-label" for="input-custom-field<?php echo $custom_field['custom_field_id']; ?>"><?php echo $custom_field['name']; ?></label>
Expand All @@ -200,24 +202,28 @@
</div>
</div>
<?php } ?>


<?php if ($custom_field['type'] == 'file') { ?>
<div id="custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-group custom-field">
<label class="col-sm-2 control-label"><?php echo $custom_field['name']; ?></label>
<div class="col-sm-10">
<button type="button" id="button-custom-field<?php echo $custom_field['custom_field_id']; ?>" class="btn btn-default"><i class="fa fa-upload"></i> <?php echo $button_upload; ?></button>
<input type="hidden" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" value="<?php echo $custom_field['value']; ?>" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>" />
<input type="hidden" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" value="<?php echo (isset($account_custom_field[$custom_field['location']][$custom_field['custom_field_id']]) ? $account_custom_field[$custom_field['location']][$custom_field['custom_field_id']] : $custom_field['value']); ?>" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>" />
<?php if (isset($error_custom_field[$custom_field['custom_field_id']])) { ?>
<div class="text-danger"><?php echo $error_custom_field[$custom_field['custom_field_id']]; ?></div>
<?php } ?>
</div>
</div>
<?php } ?>


<?php if ($custom_field['type'] == 'date') { ?>
<div id="custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-group custom-field">
<label class="col-sm-2 control-label" for="input-custom-field<?php echo $custom_field['custom_field_id']; ?>"><?php echo $custom_field['name']; ?></label>
<div class="col-sm-10">
<div class="input-group date">
<input type="text" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" value="<?php echo $custom_field['value']; ?>" placeholder="<?php echo $custom_field['name']; ?>" data-format="YYYY-MM-DD" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-control" />
<input type="text" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" value="<?php echo (isset($account_custom_field[$custom_field['location']][$custom_field['custom_field_id']]) ? $account_custom_field[$custom_field['location']][$custom_field['custom_field_id']] : $custom_field['value']); ?>" placeholder="<?php echo $custom_field['name']; ?>" data-format="YYYY-MM-DD" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
Expand All @@ -227,12 +233,14 @@
</div>
</div>
<?php } ?>


<?php if ($custom_field['type'] == 'time') { ?>
<div id="custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-group custom-field">
<label class="col-sm-2 control-label" for="input-custom-field<?php echo $custom_field['custom_field_id']; ?>"><?php echo $custom_field['name']; ?></label>
<div class="col-sm-10">
<div class="input-group time">
<input type="text" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" value="<?php echo $custom_field['value']; ?>" placeholder="<?php echo $custom_field['name']; ?>" data-format="HH:mm" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-control" />
<input type="text" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" value="<?php echo (isset($account_custom_field[$custom_field['location']][$custom_field['custom_field_id']]) ? $account_custom_field[$custom_field['location']][$custom_field['custom_field_id']] : $custom_field['value']); ?>" placeholder="<?php echo $custom_field['name']; ?>" data-format="HH:mm" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
Expand All @@ -242,12 +250,14 @@
</div>
</div>
<?php } ?>


<?php if ($custom_field['type'] == 'datetime') { ?>
<div id="custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-group custom-field">
<label class="col-sm-2 control-label" for="input-custom-field<?php echo $custom_field['custom_field_id']; ?>"><?php echo $custom_field['name']; ?></label>
<div class="col-sm-10">
<div class="input-group datetime">
<input type="text" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" value="<?php echo $custom_field['value']; ?>" placeholder="<?php echo $custom_field['name']; ?>" data-format="YYYY-MM-DD HH:mm" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-control" />
<input type="text" name="custom_field[<?php echo $custom_field['location']; ?>][<?php echo $custom_field['custom_field_id']; ?>]" value="<?php echo (isset($account_custom_field[$custom_field['location']][$custom_field['custom_field_id']]) ? $account_custom_field[$custom_field['location']][$custom_field['custom_field_id']] : $custom_field['value']); ?>" placeholder="<?php echo $custom_field['name']; ?>" data-format="YYYY-MM-DD HH:mm" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
</span></div>
Expand All @@ -257,6 +267,8 @@
</div>
</div>
<?php } ?>


<?php } ?>
<?php } ?>
<div class="form-group">
Expand Down
37 changes: 7 additions & 30 deletions upload/catalog/controller/account/address.php
Expand Up @@ -442,40 +442,17 @@ protected function getForm() {
$data['countries'] = $this->model_localisation_country->getCountries();

// Custom fields
$this->load->model('account/custom_field');

$data['custom_fields'] = $this->model_account_custom_field->getCustomFieldsByCustomerGroupId($this->config->get('config_customer_group_id'));

if (isset($this->request->post['custom_field'])) {
$custom_field_info = $this->request->post['custom_field'];
$data['address_custom_field'] = $this->request->post['custom_field'];
} elseif (isset($address_info)) {
$custom_field_info = $address_info['custom_field'];
$data['address_custom_field'] = $address_info['custom_field'];
} else {
$custom_field_info = array();
$data['address_custom_field'] = array();
}

$this->load->model('account/custom_field');

$data['custom_fields'] = array();

// If a post request then get a list of all fields that should have been posted for validation checking.
$custom_fields = $this->model_account_custom_field->getCustomFieldsByCustomerGroupId($this->config->get('config_customer_group_id'));

foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'address') {
if ($custom_field['type'] == 'checkbox') {
$value = array();
} else {
$value = '';
}

$data['custom_fields'][] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'custom_field_value' => $custom_field['custom_field_value'],
'name' => $custom_field['name'],
'type' => $custom_field['type'],
'value' => isset($custom_field_info[$custom_field['custom_field_id']]) ? $custom_field_info[$custom_field['custom_field_id']] : $value,
'required' => $custom_field['required'],
'sort_order' => $custom_field['sort_order']
);
}
}

if (isset($this->request->post['default'])) {
$data['default'] = $this->request->post['default'];
Expand Down
33 changes: 6 additions & 27 deletions upload/catalog/controller/account/edit.php
Expand Up @@ -154,39 +154,18 @@ public function index() {
} else {
$data['fax'] = '';
}

// Custom Fields
$this->load->model('account/custom_field');

$data['custom_fields'] = $this->model_account_custom_field->getCustomFieldsByCustomerGroupId($this->config->get('config_customer_group_id'));

if (isset($this->request->post['custom_field'])) {
$custom_field_info = $this->request->post['custom_field'];
$data['account_custom_field'] = $this->request->post['custom_field'];
} elseif (isset($customer_info)) {
$custom_field_info = unserialize($customer_info['custom_field']);
$data['account_custom_field'] = unserialize($customer_info['custom_field']);
} else {
$custom_field_info = array();
}

$data['custom_fields'] = array();

$custom_fields = $this->model_account_custom_field->getCustomFieldsByCustomerGroupId($this->config->get('config_customer_group_id'));

foreach ($custom_fields as $custom_field) {
if ($custom_field['location'] == 'account') {
if ($custom_field['type'] == 'checkbox') {
$value = array();
} else {
$value = $custom_field['value'];
}

$data['custom_fields'][] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'custom_field_value' => $custom_field['custom_field_value'],
'name' => $custom_field['name'],
'type' => $custom_field['type'],
'value' => isset($custom_field_info[$custom_field['custom_field_id']]) ? $custom_field_info[$custom_field['custom_field_id']] : $value,
'required' => $custom_field['required']
);
}
$data['account_custom_field'] = array();
}

$data['back'] = $this->url->link('account/account', '', 'SSL');
Expand Down
20 changes: 6 additions & 14 deletions upload/catalog/controller/account/register.php
Expand Up @@ -270,24 +270,16 @@ public function index() {
$this->load->model('localisation/country');

$data['countries'] = $this->model_localisation_country->getCountries();

// Custom Fields
$this->load->model('account/custom_field');

$data['custom_fields'] = array();
$data['custom_fields'] = $this->model_account_custom_field->getCustomFields();

$custom_fields = $this->model_account_custom_field->getCustomFields();

foreach ($custom_fields as $custom_field) {
$data['custom_fields'][] = $custom_field;

if (isset($this->request->post[$custom_field['location'] . '_custom_field'])) {
$data['custom_field'][$custom_field['custom_field_id']] = $this->request->post[$custom_field['location'] . '_custom_field'];
} elseif ($custom_field['type'] == 'checkbox') {
$data['custom_field'][$custom_field['custom_field_id']] = array();
} else {
$data['custom_field'][$custom_field['location']][$custom_field['custom_field_id']] = '';
}
if (isset($this->request->post['custom_field'])) {
$data['customer_custom_field'] = $this->request->post['custom_field'];
} else {
$data['customer_custom_field'] = array();
}

if (isset($this->request->post['password'])) {
Expand Down

0 comments on commit 36c7d5b

Please sign in to comment.