for opencart3,is it possible to make "address" require when register?
Thanks
my extension:https://www.opencart.com/index.php?rout ... estshop24h
email :support@bestshop24h.com
site:http://www.bestshop24h.com
Go to catalog > controller > checkout > register > save function, by following the same rule as given in address_1 field you can validate address_2 also.
Opencart Expert | sales[at]ost.agency
Skype - manish.osuniverse | Gtalk - manishmt
Extensions for Opencart @ https://www.ost.agency/product/product- ... extensions
ost.agency - ecommerce website design, development and digital company
If you need to find a developer, you should post a request in the OpenCart "Commercial Support" forum, which is checked by a number of OpenCart developers. You can also try checking out the OpenCart "Partners" area.
Make backup of register file from controller, language, template and upload files from attachment.
Or use an text editor to compare with yours and make changes.
You can search by: Start Address to see where I put the code.
LE. In catalog/model/account/customer.php add this line:
Code: Select all
$this->db->query("INSERT INTO " . DB_PREFIX . "address SET customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', company = '" . $this->db->escape($data['company']) . "', address_1 = '" . $this->db->escape($data['address_1']) . "', address_2 = '" . $this->db->escape($data['address_2']) . "', city = '" . $this->db->escape($data['city']) . "', postcode = '" . $this->db->escape($data['postcode']) . "', country_id = '" . (int)$data['country_id'] . "', zone_id = '" . (int)$data['zone_id'] . "', custom_field = '" . $this->db->escape(isset($data['custom_field']['address']) ? json_encode($data['custom_field']['address']) : '') . "'");
Code: Select all
$customer_id = $this->db->getLastId();
Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer
Then, i tried it on a new and clean OC to test, couldn't succeed again.
This problem is really annoying. Customer should select country and add address details while registering in order to see the products' price with tax. If do not enter any country info on register, customer see the products' price without any tax. Terrible.
Don't forget to refresh ocmod modifications, clear theme cache, sass cache.
Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer
Different theme requests goes to extension theme developers.erhangazi84 wrote: ↑Mon May 03, 2021 7:06 pmcan you pls give register.twig code separately? If someone else use a different theme, he should add necessary code manually.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
For Default theme you have above a zip file attached.erhangazi84 wrote: ↑Mon May 03, 2021 7:06 pmcan you pls give register.twig code separately? If someone else use a different theme, he should add necessary code manually.
Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer
Yes, you are right. But we are not dealing with codes everyday. I could find, solved and want to share here.xxvirusxx wrote: ↑Mon May 03, 2021 7:15 pmFor Default theme you have above a zip file attached.erhangazi84 wrote: ↑Mon May 03, 2021 7:06 pmcan you pls give register.twig code separately? If someone else use a different theme, he should add necessary code manually.
I have just installed a new OC, tested this one, and worked fine. And then, installed a theme (Journal and something different), succeeded again. Here is the key issue.
Open your theme catalog/view/theme/your_theme/template/account/register.twig
Find:
Code: Select all
<fieldset>
<legend>{{ text_your_password }}</legend>
Add this code BEFORE the code above:
Code: Select all
<!-- Start Adddress code -->
<fieldset id="address">
<legend>{{ text_your_address }}</legend>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-company">{{ entry_company }}</label>
<div class="col-sm-10">
<input type="text" name="company" value="{{ company }}" placeholder="{{ entry_company }}" id="input-company" class="form-control" />
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-address-1">{{ entry_address_1 }}</label>
<div class="col-sm-10">
<input type="text" name="address_1" value="{{ address_1 }}" placeholder="{{ entry_address_1 }}" id="input-address-1" class="form-control" />
{% if error_address_1 %}
<div class="text-danger">{{ error_address_1 }}</div>
{% endif %}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="input-address-2">{{ entry_address_2 }}</label>
<div class="col-sm-10">
<input type="text" name="address_2" value="{{ address_2 }}" placeholder="{{ entry_address_2 }}" id="input-address-2" class="form-control" />
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-city">{{ entry_city }}</label>
<div class="col-sm-10">
<input type="text" name="city" value="{{ city }}" placeholder="{{ entry_city }}" id="input-city" class="form-control" />
{% if error_city %}
<div class="text-danger">{{ error_city }}</div>
{% endif %}
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-postcode">{{ entry_postcode }}</label>
<div class="col-sm-10">
<input type="text" name="postcode" value="{{ postcode }}" placeholder="{{ entry_postcode }}" id="input-postcode" class="form-control" />
{% if error_postcode %}
<div class="text-danger">{{ error_postcode }}</div>
{% endif %}
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-country">{{ entry_country }}</label>
<div class="col-sm-10">
<select name="country_id" id="input-country" class="form-control">
<option value="">{{ text_select }}</option>
{% for country in countries %}
{% if country.country_id == country_id %}
<option value="{{ country.country_id }}" selected="selected">{{ country.name }}</option>
{% else %}
<option value="{{ country.country_id }}">{{ country.name }}</option>
{% endif %}
{% endfor %}
</select>
{% if error_country %}
<div class="text-danger">{{ error_country }}</div>
{% endif %}
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-zone">{{ entry_zone }}</label>
<div class="col-sm-10">
<select name="zone_id" id="input-zone" class="form-control">
</select>
{% if error_zone %}
<div class="text-danger">{{ error_zone }}</div>
{% endif %}
</div>
</div>
{% for custom_field in custom_fields %}
{% if custom_field.location == 'address' %}
{% if custom_field.type == 'select' %}
<div id="custom-field{{ custom_field.custom_field_id }}" class="form-group custom-field" data-sort="{{ custom_field.sort_order }}">
<label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
<div class="col-sm-10">
<select name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control">
<option value="">{{ text_select }}</option>
{% for custom_field_value in custom_field.custom_field_value %}
{% if register_custom_field[custom_field.location][custom_field.custom_field_id] and custom_field_value.custom_field_value_id == register_custom_field[custom_field.custom_field_id] %}
<option value="{{ custom_field_value.custom_field_value_id }}" selected="selected">{{ custom_field_value.name }}</option>
{% else %}
<option value="{{ custom_field_value.custom_field_value_id }}">{{ custom_field_value.name }}</option>
{% endif %}
{% endfor %}
</select>
{% if error_custom_field[custom_field.custom_field_id] %}
<div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
{% endif %}</div>
</div>
{% endif %}
{% if custom_field.type == 'radio' %}
<div id="custom-field{{ custom_field.custom_field_id }}" class="form-group custom-field" data-sort="{{ custom_field.sort_order }}">
<label class="col-sm-2 control-label">{{ custom_field.name }}</label>
<div class="col-sm-10">
<div> {% for custom_field_value in custom_field.custom_field_value %}
<div class="radio">{% if register_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id == register_custom_field[custom_field.custom_field_id] %}
<label>
<input type="radio" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{{ custom_field_value.custom_field_value_id }}" checked="checked" />
{{ custom_field_value.name }}</label>
{% else %}
<label>
<input type="radio" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{{ custom_field_value.custom_field_value_id }}" />
{{ custom_field_value.name }}</label>
{% endif %} </div>
{% endfor %}</div>
{% if error_custom_field[custom_field.custom_field_id] %}
<div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
{% endif %}</div>
</div>
{% endif %}
{% if custom_field.type == 'checkbox' %}
<div id="custom-field{{ custom_field.custom_field_id }}" class="form-group custom-field" data-sort="{{ custom_field.sort_order }}">
<label class="col-sm-2 control-label">{{ custom_field.name }}</label>
<div class="col-sm-10">
<div> {% for custom_field_value in custom_field.custom_field_value %}
<div class="checkbox">{% if register_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id in register_custom_field[custom_field.custom_field_id] %}
<label>
<input type="checkbox" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}][]" value="{{ custom_field_value.custom_field_value_id }}" checked="checked" />
{{ custom_field_value.name }}</label>
{% else %}
<label>
<input type="checkbox" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}][]" value="{{ custom_field_value.custom_field_value_id }}" />
{{ custom_field_value.name }}</label>
{% endif %} </div>
{% endfor %} </div>
{% if error_custom_field[custom_field.custom_field_id] %}
<div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
{% endif %} </div>
</div>
{% endif %}
{% if custom_field.type == 'text' %}
<div id="custom-field{{ custom_field.custom_field_id }}" class="form-group custom-field" data-sort="{{ custom_field.sort_order }}">
<label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
<div class="col-sm-10">
<input type="text" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if register_custom_field[custom_field.custom_field_id] %}{{ register_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}" placeholder="{{ custom_field.name }}" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control" />
{% if error_custom_field[custom_field.custom_field_id] %}
<div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
{% endif %} </div>
</div>
{% endif %}
{% if custom_field.type == 'textarea' %}
<div id="custom-field{{ custom_field.custom_field_id }}" class="form-group custom-field" data-sort="{{ custom_field.sort_order }}">
<label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
<div class="col-sm-10">
<textarea name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" rows="5" placeholder="{{ custom_field.name }}" id="input-custom-field{{ custom_field.custom_field_id }}" class="form-control">{% if register_custom_field[custom_field.custom_field_id] %}{{ register_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}</textarea>
{% if error_custom_field[custom_field.custom_field_id] %}
<div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
{% endif %} </div>
</div>
{% endif %}
{% if custom_field.type == 'file' %}
<div id="custom-field{{ custom_field.custom_field_id }}" class="form-group custom-field" data-sort="{{ custom_field.sort_order }}">
<label class="col-sm-2 control-label">{{ custom_field.name }}</label>
<div class="col-sm-10">
<button type="button" id="button-custom-field{{ custom_field.custom_field_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default"><i class="fa fa-upload"></i> {{ button_upload }}</button>
<input type="hidden" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if register_custom_field[custom_field.custom_field_id] %} {{ register_custom_field[custom_field.custom_field_id] }} {% endif %}" />
{% if error_custom_field[custom_field.custom_field_id] %}
<div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
{% endif %}</div>
</div>
{% endif %}
{% if custom_field.type == 'date' %}
<div id="custom-field{{ custom_field.custom_field_id }}" class="form-group custom-field" data-sort="{{ custom_field.sort_order }}">
<label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
<div class="col-sm-10">
<div class="input-group date">
<input type="text" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if register_custom_field[custom_field.custom_field_id] %}{{ register_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}" placeholder="{{ custom_field.name }}" data-date-format="YYYY-MM-DD" id="input-custom-field{{ 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>
{% if error_custom_field[custom_field.custom_field_id] %}
<div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
{% endif %} </div>
</div>
{% endif %}
{% if custom_field.type == 'time' %}
<div id="custom-field{{ custom_field.custom_field_id }}" class="form-group custom-field" data-sort="{{ custom_field.sort_order }}">
<label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
<div class="col-sm-10">
<div class="input-group time">
<input type="text" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if register_custom_field[custom_field.custom_field_id] %}{{ register_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}" placeholder="{{ custom_field.name }}" data-date-format="HH:mm" id="input-custom-field{{ 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>
{% if error_custom_field[custom_field.custom_field_id] %}
<div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
{% endif %} </div>
</div>
{% endif %}
{% if custom_field.type == 'datetime' %}
<div id="custom-field{{ custom_field.custom_field_id }}" class="form-group custom-field" data-sort="{{ custom_field.sort_order }}">
<label class="col-sm-2 control-label" for="input-custom-field{{ custom_field.custom_field_id }}">{{ custom_field.name }}</label>
<div class="col-sm-10">
<div class="input-group datetime">
<input type="text" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}]" value="{% if register_custom_field[custom_field.custom_field_id] %}{{ register_custom_field[custom_field.custom_field_id] }}{% else %}{{ custom_field.value }}{% endif %}" placeholder="{{ custom_field.name }}" data-date-format="YYYY-MM-DD HH:mm" id="input-custom-field{{ 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>
{% if error_custom_field[custom_field.custom_field_id] %}
<div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
{% endif %}
</div>
</div>
{% endif %}
{% endif %}
{% endfor %}
</fieldset>
<!-- End Adddress code -->
The extension (or patch) works fine thanks to xxvirusxx
However, if you update your theme near future, pls do not forget to add this code to your updated register.twig file again!
You can check register.tpl from journal3 (2.3.0.2) because it use....
Code: Select all
<div class="form-group <?php if ($j3->settings->get('accountAddressAddress1Field') === 'required'): ?>required ...
Code: Select all
<div class="form-group {% if j3.settings.get('accountAddressAddress1Field') === 'required') == 'required' %}required ....
LE. Maybe someday I will make an ocmod for Default and Journal 3...
Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
another issue: twig file has some javascript code. Need to add before {{ footer }} at the end of all codes.
Let me add here for beginners like me
Find:
Code: Select all
{{ footer }}
Code: Select all
<script type="text/javascript"><!--
// Sort the custom fields
$('#account .form-group[data-sort]').detach().each(function() {
if ($(this).attr('data-sort') >= 0 && $(this).attr('data-sort') <= $('#account .form-group').length) {
$('#account .form-group').eq($(this).attr('data-sort')).before(this);
}
if ($(this).attr('data-sort') > $('#account .form-group').length) {
$('#account .form-group:last').after(this);
}
if ($(this).attr('data-sort') == $('#account .form-group').length) {
$('#account .form-group:last').after(this);
}
if ($(this).attr('data-sort') < -$('#account .form-group').length) {
$('#account .form-group:first').before(this);
}
});
$('#address .form-group[data-sort]').detach().each(function() {
if ($(this).attr('data-sort') >= 0 && $(this).attr('data-sort') <= $('#address .form-group').length) {
$('#address .form-group').eq($(this).attr('data-sort')).before(this);
}
if ($(this).attr('data-sort') > $('#address .form-group').length) {
$('#address .form-group:last').after(this);
}
if ($(this).attr('data-sort') == $('#address .form-group').length) {
$('#address .form-group:last').after(this);
}
if ($(this).attr('data-sort') < -$('#address .form-group').length) {
$('#address .form-group:first').before(this);
}
});
$('input[name=\'customer_group_id\']').on('change', function() {
$.ajax({
url: 'index.php?route=account/register/customfield&customer_group_id=' + this.value,
dataType: 'json',
success: function(json) {
$('.custom-field').hide();
$('.custom-field').removeClass('required');
for (i = 0; i < json.length; i++) {
custom_field = json[i];
$('#custom-field' + custom_field['custom_field_id']).show();
if (custom_field['required']) {
$('#custom-field' + custom_field['custom_field_id']).addClass('required');
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('input[name=\'customer_group_id\']:checked').trigger('change');
//--></script>
<script type="text/javascript"><!--
$('button[id^=\'button-custom-field\']').on('click', function() {
var element = this;
$('#form-upload').remove();
$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" /></form>');
$('#form-upload input[name=\'file\']').trigger('click');
if (typeof timer != 'undefined') {
clearInterval(timer);
}
timer = setInterval(function() {
if ($('#form-upload input[name=\'file\']').val() != '') {
clearInterval(timer);
$.ajax({
url: 'index.php?route=tool/upload',
type: 'post',
dataType: 'json',
data: new FormData($('#form-upload')[0]),
cache: false,
contentType: false,
processData: false,
beforeSend: function() {
$(element).button('loading');
},
complete: function() {
$(element).button('reset');
},
success: function(json) {
$(element).parent().find('.text-danger').remove();
if (json['error']) {
$(node).parent().find('input').after('<div class="text-danger">' + json['error'] + '</div>');
}
if (json['success']) {
alert(json['success']);
$(element).parent().find('input').val(json['code']);
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
}, 500);
});
//--></script>
<script type="text/javascript"><!--
$('.date').datetimepicker({
language: '{{ datepicker }}',
pickTime: false
});
$('.time').datetimepicker({
language: '{{ datepicker }}',
pickDate: false
});
$('.datetime').datetimepicker({
language: '{{ datepicker }}',
pickDate: true,
pickTime: true
});
//--></script>
<script type="text/javascript"><!--
$('select[name=\'country_id\']').on('change', function() {
$.ajax({
url: 'index.php?route=account/account/country&country_id=' + this.value,
dataType: 'json',
beforeSend: function() {
$('select[name=\'country_id\']').prop('disabled', true);
},
complete: function() {
$('select[name=\'country_id\']').prop('disabled', false);
},
success: function(json) {
if (json['postcode_required'] == '1') {
$('input[name=\'postcode\']').parent().addClass('required');
} else {
$('input[name=\'postcode\']').parent().removeClass('required');
}
html = '<option value="">{{ text_select }}</option>';
if (json['zone'] && json['zone'] != '') {
for (i = 0; i < json['zone'].length; i++) {
html += '<option value="' + json['zone'][i]['zone_id'] + '"';
if (json['zone'][i]['zone_id'] == '{{ zone_id }}') {
html += ' selected="selected"';
}
html += '>' + json['zone'][i]['name'] + '</option>';
}
} else {
html += '<option value="0" selected="selected">{{ text_none }}</option>';
}
$('select[name=\'zone_id\']').html(html);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('select[name=\'country_id\']').trigger('change');
//--></script>
I replaced the 3 files in the attachment and although the address information was requested during registration, it didn't store it anywhere. When I edit the customer in the backend, there is no address information in their record.
Ensure MOD security is disabled.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
straightlight wrote: ↑Thu Sep 23, 2021 4:22 amEnsure MOD security is disabled.
Contact your host so that their support staff can do it for you.CJC wrote: ↑Thu Sep 23, 2021 7:00 amThat would be set at the server level and not something I would have access to.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: No registered users and 411 guests