Sehr geehrte Damen und Herren,
ich benutze das Plugin Packstation von VIISON GmbH (welche für diese Version keinen Support anbieten). Das Plugin speichert die DHL Packstation in das Feld “Street” und die Kundennummer in das Feld “AdditonalAdressLine1”. Leider bräuchten wir diese anders herum sodass die Kundennummer im Feld “Street” gespeichert wird und die Packstation im Feld “AdditionalAdressLine1”. Leider bin ich selbst noch nicht sehr Erfahren mit der ganzen Programmierung da ich dies derzeit alles anfange zu lernen und würde Sie daher um Hilfe bitten da der Code für mich noch leider zu komplex ist sodass ich vermutlich die Lösung selbst übersehe.
//{namespace name="frontend/viison_packstation/register/shipping_fieldset"}
$(document).ready(function($) {
var configuration = {
snippets: {
postaddressCompany: '{s name="RegisterLabelAdditionalAddressLine1" namespace="frontend/register/shipping_fieldset"}{/s}',
packstationCompany: '{s name="CustomerNumber"}{/s}',
postaddressStreet: '{s name="RegisterShippingPlaceholderStreet" namespace="frontend/register/shipping_fieldset"}{/s}',
packstationStreet: {}, // These snippets are set below due to limitations in minimal-smartyness (no Smarty allowed in keys of associative array)
packstationStreetTitle: {},
customerNumberTitle: '{s name=CustomerNumberTitle}{/s}'
},
countryIdGermany: '{$viisonPackstationCountryIdGermany}'
};
configuration.snippets.packstationStreet['{$viisonPackstationSelectionValues.packstation}'] = '{s name="PackstationNumber"}{/s}';
configuration.snippets.packstationStreet['{$viisonPackstationSelectionValues.postoffice}'] = '{s name="PostofficeNumber"}{/s}';
configuration.snippets.packstationStreetTitle['{$viisonPackstationSelectionValues.packstation}'] = '{s name="PackstationNumberTitle"}{/s}';
configuration.snippets.packstationStreetTitle['{$viisonPackstationSelectionValues.postoffice}'] = '{s name="PostofficeNumberTitle"}{/s}';
var initPackstationAddressForm = function() {
var renderer = function () {
// On the register page, we want to use the fields of the shipping address, choose these specifically
var $street = $('[name="register[shipping][street]"]'),
$additionalAddressLine1 = $('[name="register[shipping][additionalAddressLine1]"]'),
$country = $('[name="register[shipping][country]"]');
if ($street.length === 0) {
// On other pages, only one address exists
$street = $('#street');
$additionalAddressLine1 = $('#additionalAddressLine1');
$country = $('#country');
}
// Add element to avoid a floating/overflow glitch of the following element
$additionalAddressLine1.closest('div').append($('').css({ clear: 'both', margin: 0 }));
var countryOptions;
return {
// Change label of company field and reset it's value if requested
modifyCompany: function (resetValue) {
$additionalAddressLine1.attr('placeholder', configuration.snippets.packstationCompany);
if (resetValue) {
$additionalAddressLine1.val('');
}
$additionalAddressLine1.attr('required', 'required');
$additionalAddressLine1.attr('aria-required', 'true');
$additionalAddressLine1.addClass('is--required');
$additionalAddressLine1.closest('div').removeClass('is--hidden');
{literal}
$additionalAddressLine1.attr('pattern', '\\d{6,10}');
{/literal}
$additionalAddressLine1.attr('title', configuration.snippets.customerNumberTitle);
},
// Restore label of the company field and reset its value
restoreCompany: function () {
$additionalAddressLine1
.val('')
.removeClass('required instyle_success instyle_error')
.unbind('blur');
$additionalAddressLine1.removeAttr('required');
{if !{config name=showAdditionAddressLine1}}
$additionalAddressLine1.closest('div').addClass('is--hidden');
{/if}
$additionalAddressLine1.attr('placeholder', configuration.snippets.postaddressCompany);
$additionalAddressLine1.removeAttr('pattern');
$additionalAddressLine1.removeAttr('title');
},
// Clear and hide department field TODO
modifyDepartment: function () {
$('#department2')
.val('')
.parent()
.hide();
},
// Clear and show department field
restoreDepartment: function () {
$('#department2')
.val('')
.parent()
.show();
},
// In case of packstation or postoffice the street field is used to store the address type and the streetnumber field
// to store the packstation resp. postoffice number. Therefore hide the street field and set it's value according to
// the given address type (value parameter), change label and reset streetnumber if requested.
modifyStreet: function (addressType, value) {
$street.attr('placeholder', configuration.snippets.packstationStreet[addressType]);
$street.val(value);
{literal}
$street.attr('pattern', '\\d{3}');
{/literal}
$street.attr('title', configuration.snippets.packstationStreetTitle[addressType]);
},
// Restore label of street fields, reset fields and show street field
restoreStreet: function () {
$street.val('');
$street.attr('placeholder', configuration.snippets.postaddressStreet);
$street.removeAttr('pattern');
$street.removeAttr('title');
},
// Add listener to packstation selection (radio buttons)
$('input.viison-packstation-radio').on('change', function() {
var value = $(this).val();
// Modify form, if selection has changed
switch (value) {
case '{$viisonPackstationSelectionValues.postaddress}':
renderer.restoreCompany(true);
renderer.restoreDepartment();
renderer.restoreStreet();
renderer.restoreCountrySelection();
break;
case '{$viisonPackstationSelectionValues.packstation}':
renderer.modifyCompany(true);
renderer.modifyDepartment();
renderer.modifyStreet(value, '');
renderer.modifyCountrySelection();
break;
case '{$viisonPackstationSelectionValues.postoffice}':
renderer.modifyCompany(true);
renderer.modifyDepartment();
renderer.modifyStreet(value, '');
renderer.modifyCountrySelection();
break;
}
});
// Check if we are on a page where an address can be edited
if ($('input#street').length > 0) {
// Preselect address type, if current shipping address is packstation or postoffice
var matches = $('input#street').val().match(/(Packstation|Postfiliale)?\s*(.*)/);
var addressType = matches[1];
var street = matches[2];
var radioButton = $('input.viison-packstation-radio[value="' + addressType + '"]');
if (radioButton.length > 0 && (addressType == '{$viisonPackstationSelectionValues.packstation}' || addressType == '{$viisonPackstationSelectionValues.postoffice}')) {
radioButton.prop('checked', 'checked');
renderer.modifyCompany(false);
renderer.modifyDepartment();
renderer.modifyStreet(addressType, street);
renderer.modifyCountrySelection();
}
}
};
initPackstationAddressForm();
$.subscribe('plugin/swAddressEditor/onAfterBindButtonAction', function() {
initPackstationAddressForm();
});
});