Skip to content

Commit

Permalink
Merge pull request #33 from two-inc/brtknr/t-14281-fix-issue-with-cus…
Browse files Browse the repository at this point in the history
…tomattributes

T-14281/fix: Issue with customAttributes and sole trader popup message
  • Loading branch information
brtkwr authored Nov 22, 2023
2 parents e1c310c + 68951cc commit 6dbf94a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 41 deletions.
2 changes: 1 addition & 1 deletion bumpver.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpver]
current_version = "1.4.1"
current_version = "1.4.2"
version_pattern = "MAJOR.MINOR.PATCH[-TAGNUM]"
commit_message = "chore: Bump version {old_version} -> {new_version}"
commit = true
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "two-inc/magento2",
"description": "Two B2B BNPL payments extension",
"type": "magento2-module",
"version": "1.4.1",
"version": "1.4.2",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<payment>
<two_payment>
<active>1</active>
<version>1.4.1</version>
<version>1.4.2</version>
<title>Business invoice in 30 days</title>
<mode>sandbox</mode>
<invoice_type>FUNDED_INVOICE</invoice_type>
Expand Down
7 changes: 4 additions & 3 deletions view/frontend/web/js/view/address-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ define([
countrySelector: '#shipping-new-address-form select[name="country_id"]',
companyNameSelector: '#shipping-new-address-form input[name="company"]',
companyIdSelector: '#shipping-new-address-form input[name="custom_attributes[company_id]"]',
telephoneSelector: '#shipping-new-address-form input[name="custom_attributes[two_telephone]"]',
telephoneSelector:
'#shipping-new-address-form input[name="custom_attributes[two_telephone]"]',
shippingTelephoneSelector: '#shipping-new-address-form input[name="telephone"]',
enterDetailsManuallyText: $t('Enter details manually'),
enterDetailsManuallyButton: '#shipping_enter_details_manually',
Expand Down Expand Up @@ -78,8 +79,8 @@ define([
customerData.set('twoCompanyId', twoCompanyId);
customerData.set('twoCompanyName', twoCompanyName);
$('.select2-selection__rendered').text(twoCompanyName);
$(this.companyNameSelector).val(twoCompanyName)
$(this.companyIdSelector).val(twoCompanyId)
$(this.companyNameSelector).val(twoCompanyName);
$(this.companyIdSelector).val(twoCompanyId);
},
enableInternationalTelephone: function () {
var self = this;
Expand Down
78 changes: 43 additions & 35 deletions view/frontend/web/js/view/payment/method-renderer/two_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,14 @@ define([
}
this.registeredOrganisationMode();
this.configureFormValidation();
this.addVerifyEvent();
this.popupMessageListener();
},
fillCompanyName: function (self, companyName) {
const billingAddress = quote.billingAddress();
const fallbackCompanyName =
typeof billingAddress.company == 'string' ? billingAddress.company : '';
typeof billingAddress.company == 'string' ? billingAddress.company : '';
companyName =
typeof companyName == 'string' && companyName
? companyName
: fallbackCompanyName;
typeof companyName == 'string' && companyName ? companyName : fallbackCompanyName;
self.companyName(companyName);
$(self.companyNameSelector).val(companyName);
$('#select2-company_name-container')?.text(companyName);
Expand Down Expand Up @@ -134,24 +132,26 @@ define([
let companyId = '';
let department = '';
let project = '';
address.customAttributes.forEach(function (item) {
console.log(item);
if (item.attribute_code == 'company_id') {
companyId = item.value;
}
if (item.attribute_code == 'company_name') {
companyName = item.value;
}
if (item.attribute_code == 'two_telephone') {
telephone = telephone;
}
if (item.attribute_code == 'project') {
project = item.value;
}
if (item.attribute_code == 'department') {
department = item.value;
}
})
if (Array.isArray(address.customAttributes)) {
address.customAttributes.forEach(function (item) {
console.log(item);
if (item.attribute_code == 'company_id') {
companyId = item.value;
}
if (item.attribute_code == 'company_name') {
companyName = item.value;
}
if (item.attribute_code == 'two_telephone') {
telephone = telephone;
}
if (item.attribute_code == 'project') {
project = item.value;
}
if (item.attribute_code == 'department') {
department = item.value;
}
});
}
if (telephone) self.fillTelephone(self, telephone);
if (companyName) {
self.fillCompanyName(self, companyName);
Expand All @@ -177,16 +177,24 @@ define([
quote.billingAddress.subscribe((address) => this.updateBillingAddress(this, address));
this.updateBillingAddress(this, quote.billingAddress());

customerData.get('twoCompanyName').subscribe((companyName) => this.fillCompanyName(this, companyName));
customerData
.get('twoCompanyName')
.subscribe((companyName) => this.fillCompanyName(this, companyName));
this.fillCompanyName(this, customerData.get('twoCompanyName')());

customerData.get('twoCompanyId').subscribe((companyId) => this.fillCompanyId(this, companyId));
customerData
.get('twoCompanyId')
.subscribe((companyId) => this.fillCompanyId(this, companyId));
this.fillCompanyId(this, customerData.get('twoCompanyId')());

customerData.get('twoTelephone').subscribe((telephone) => this.fillTelephone(this, telephone));
customerData
.get('twoTelephone')
.subscribe((telephone) => this.fillTelephone(this, telephone));
this.fillTelephone(this, customerData.get('twoTelephone')());

customerData.get('twoCountryCode').subscribe((countryCode) => this.fillCountryCode(this, countryCode));
customerData
.get('twoCountryCode')
.subscribe((countryCode) => this.fillCountryCode(this, countryCode));
this.fillCountryCode(this, customerData.get('twoCountryCode')());
},
afterPlaceOrder: function () {
Expand Down Expand Up @@ -647,9 +655,7 @@ define([

openIframe() {
const data = this.getAutofillData();
const URL =
config.popup_url +
`/soletrader/signup?businessToken=${this.delegationToken}&autofillToken=${this.autofillToken}&autofillData=${data}`;
const URL = `${config.popup_url}/soletrader/signup?businessToken=${this.delegationToken}&autofillToken=${this.autofillToken}&autofillData=${data}`;
const windowFeatures =
'location=yes,resizable=yes,scrollbars=yes,status=yes, height=805, width=610';
window.open(URL, '_blank', windowFeatures);
Expand Down Expand Up @@ -719,12 +725,14 @@ define([
.catch(() => this.showErrorMessage(this.soleTraderErrorMessage));
},

addVerifyEvent() {
popupMessageListener() {
window.addEventListener('message', (event) => {
if (event.data === 'ACCEPTED') {
this.getCurrentBuyer();
} else {
this.showErrorMessage(this.soleTraderErrorMessage);
if (this.showSoleTrader() && event.origin == config.popup_url) {
if (event.data == 'ACCEPTED') {
this.getCurrentBuyer();
} else {
this.showErrorMessage(this.soleTraderErrorMessage);
}
}
});
}
Expand Down

0 comments on commit 6dbf94a

Please sign in to comment.