Merge pull request #4 from agility/product-search-patch

Updated product search url
This commit is contained in:
joshua 2021-10-18 15:07:49 -04:00 committed by GitHub
commit 649c78938f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -251,6 +251,31 @@ var ChooseProductCustomField = function () {
$pnl = $(".product-picker-field", options.$elem); $pnl = $(".product-picker-field", options.$elem);
var websiteName = ContentManager.ViewModels.Navigation.currentWebsite()
var searchAPIUrl = ""
ContentManager.DashboardDataAccess.GetAllDigitalChannelsWithDomains(websiteName,
function (channels) {
for (var channel in channels) {
var channelObj = channels[channel]
for (var i = 0; i < channelObj.length; i++) {
var domain = channelObj[i]
if (domain.IsPreviewDomain) {
//calculate the url to search for products by using the preview url...
var searchUrl = domain.DomainUrl
if (searchUrl.lastIndexOf("/") == searchUrl.length - 1) {
searchUrl = searchUrl.substring(0, searchUrl.length - 1)
}
searchAPIUrl = searchUrl + "/api/search-products"
break;
}
}
}
//bind our viewmodel to this //bind our viewmodel to this
var viewModel = function () { var viewModel = function () {
@ -265,7 +290,7 @@ var ChooseProductCustomField = function () {
/// </param> /// </param>
var self = this; var self = this;
ContentManager.DataAccess.GetPreviewUrl()
self.ajaxRequest = null; self.ajaxRequest = null;
@ -285,6 +310,7 @@ var ChooseProductCustomField = function () {
}; };
self.ajaxRequest = null; self.ajaxRequest = null;
self.select2 = { self.select2 = {
label: 'Product', label: 'Product',
readOnly: false, readOnly: false,
@ -307,8 +333,7 @@ var ChooseProductCustomField = function () {
}, },
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "https://nextjs-commerce-agility-cms.vercel.app/api/search-products", url: searchAPIUrl,
//url: "http://localhost:3000/api/search-products",
dataType: 'json', dataType: 'json',
type: "get", type: "get",
quietMillis: 250, quietMillis: 250,
@ -388,6 +413,7 @@ var ChooseProductCustomField = function () {
} }
ko.applyBindings(viewModel, $pnl.get(0)); ko.applyBindings(viewModel, $pnl.get(0));
})
} }
} }