Skip to content

Commit

Permalink
CET-461/feat: Support new company search in Netherlands
Browse files Browse the repository at this point in the history
  • Loading branch information
brtkwr committed Oct 2, 2024
1 parent 9dab7c3 commit e9ba15e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 71 deletions.
4 changes: 2 additions & 2 deletions Api/Config/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public function getWeightUnit(?int $storeId = null): string;
public function getUrls(string $route, ?array $params = []): string;

/**
* Get search host urls
* Get search host url
*
* @return array
*/
public function getSearchHostUrls(): array;
public function getSearchHostUrl(): array;

/**
* Get checkout API url
Expand Down
10 changes: 4 additions & 6 deletions Model/Config/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,11 @@ public function getUrls(string $route, ?array $params = []): string
/**
* @inheritDoc
*/
public function getSearchHostUrls(): array
public function getSearchHostUrl(): array
{
return [
'gb' => 'https://gb.search.two.inc',
'no' => 'https://no.search.two.inc',
'se' => 'https://se.search.two.inc'
];
$mode = $mode ?: $this->getMode();
$prefix = $mode == 'production' ? 'search' : ('search.' . $mode);
return sprintf(self::URL_TEMPLATE, $prefix);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(
public function getConfig(): array
{
$companySearchConfig = [
'searchHosts' => $this->configRepository->getSearchHostUrls(),
'searchHost' => $this->configRepository->getSearchHostUrl(),
'searchLimit' => 50,
];

Expand Down
54 changes: 16 additions & 38 deletions view/frontend/web/js/view/address-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ define([
const countryCode = $(this.countrySelector).val().toLowerCase();
customerData.set('countryCode', countryCode);
let field = $(this.companyNameSelector).closest('.field');
if (countryCode in config.companySearchConfig.searchHosts) {
field.show();
} else {
field.hide();
this.setCompanyData();
}
field.show();
},
setCompanyData: function (companyId = '', companyName = '') {
console.debug({ logger: 'addressAutocomplete.setCompanyData', companyId, companyName });
Expand Down Expand Up @@ -88,22 +83,15 @@ define([
dataType: 'json',
delay: 400,
url: function (params) {
var searchHosts = config.companySearchConfig.searchHosts,
selectedCountryCode = $(self.countrySelector).val(),
searchHost = '';
if (selectedCountryCode.toLowerCase() in searchHosts) {
searchHost = searchHosts[selectedCountryCode.toLowerCase()];
}
params.page = params.page || 1;
return (
searchHost +
'/search?limit=' +
searchLimit +
'&offset=' +
(params.page - 1) * searchLimit +
'&q=' +
unescape(params.term)
);
const queryParams = new URLSearchParams({
country: $(self.countrySelector).val(),
limit: searchLimit,
offset: ((params.page || 1) - 1) * searchLimit,
q: unescape(params.term)
});
return `${
config.companySearchConfig.searchHost
}/companies/v1/company?${queryParams.toString()}`;
},
processResults: function (response, params) {
var items = [];
Expand All @@ -113,8 +101,8 @@ define([
items.push({
id: item.name,
text: item.name,
html: `${item.highlight} (${item.id})`,
companyId: item.id
html: `${item.highlight} (${item.national_identifier.id})`,
companyId: item.national_identifier.id
});
}
}
Expand Down Expand Up @@ -154,22 +142,12 @@ define([
$('.select2-selection__rendered').text(selectedItem.id);
self.setCompanyData(selectedItem.companyId, selectedItem.text);
if (self.isAddressSearchEnabled) {
let countryId = $(self.countrySelector).val();
if (
_.indexOf(
self.supportedCountryCodes,
countryId.toLowerCase()
) != -1
) {
const companyId = selectedItem.companyId;
const countryCode = $(self.countrySelector).val().toLowerCase();
if (_.indexOf(self.supportedCountryCodes, countryCode) != -1) {
const addressResponse = $.ajax({
dataType: 'json',
url:
config.checkoutApiUrl +
'/v1/' +
countryId.toUpperCase() +
'/company/' +
selectedItem.companyId +
'/address'
url: `${config.checkoutApiUrl}/v1/${countryCode}/company/${companyId}/address`
});
addressResponse.done(function (response) {
if (response.address) {
Expand Down
42 changes: 18 additions & 24 deletions view/frontend/web/js/view/payment/method-renderer/two_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,13 @@ define([

console.debug({ logger: 'twoPayment.placeOrderIntent', orderIntentRequestBody });

const queryParams = new URLSearchParams({
client: config.orderIntentConfig.extensionPlatformName,
client_v: config.orderIntentConfig.extensionDBVersion
});

return $.ajax({
url:
config.checkoutApiUrl +
'/v1/order_intent?' +
'client=' +
config.orderIntentConfig.extensionPlatformName +
'&client_v=' +
config.orderIntentConfig.extensionDBVersion,
url: `${config.checkoutApiUrl}/v1/order_intent?${queryParams.toString()}`,
type: 'POST',
global: true,
contentType: 'application/json',
Expand Down Expand Up @@ -427,20 +426,15 @@ define([
dataType: 'json',
delay: 400,
url: function (params) {
var searchHosts = config.companySearchConfig.searchHosts,
billingAddress = quote.billingAddress(),
searchHost = searchHosts[self.countryCode()];
if (!searchHost) return;
params.page = params.page || 1;
return (
searchHost +
'/search?limit=' +
searchLimit +
'&offset=' +
(params.page - 1) * searchLimit +
'&q=' +
unescape(params.term)
);
const queryParams = new URLSearchParams({
country: self.countryCode(),
limit: searchLimit,
offset: ((params.page || 1) - 1) * searchLimit,
q: unescape(params.term)
});
return `${
config.companySearchConfig.searchHost
}/companies/v1/company?${queryParams.toString()}`;
},
processResults: function (response, params) {
var items = [];
Expand All @@ -450,8 +444,8 @@ define([
items.push({
id: item.name,
text: item.name,
html: `${item.highlight} (${item.id})`,
companyId: item.id
html: `${item.highlight} (${item.national_identifier.id})`,
companyId: item.national_identifier.id
});
}
}
Expand Down Expand Up @@ -635,7 +629,7 @@ define([
},

getCurrentBuyer() {
const URL = config.checkoutApiUrl + '/autofill/v1/buyer/current';
const URL = `${config.checkoutApiUrl}/autofill/v1/buyer/current`;
const OPTIONS = {
credentials: 'include',
headers: {
Expand Down

0 comments on commit e9ba15e

Please sign in to comment.