Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,46 @@ define([
}.bind(this));
},

/**
* Sole owner of the nearby search criteria shape. Requests issued from different components
* must be structurally identical, otherwise they miss each other in locationsCache.
*
* @param {String} searchTerm
* @param {Number} radius
* @param {Number} pageSize
* @returns {Object}
*/
getNearbyLocationsCriteria: function (searchTerm, radius, pageSize) {
var criteria,
// Composite items are skipped - their children carry the salable skus.
productsInfo = _.chain(quote.getItems())
.filter(function (item) {
return item['qty_options'] === undefined || item['qty_options'].length === 0;
})
.map(function (item) {
return {
sku: item.sku
};
})
.value();

criteria = {
extensionAttributes: {
productsInfo: productsInfo
},
pageSize: pageSize
};

if (searchTerm) {
criteria.area = {
radius: radius,
searchTerm: searchTerm
};
}

return criteria;
},

/**
* Get nearby pickup locations based on given search criteria.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ define([
selectedSource,
selectedSourceCode,
nearestLocation,
self = this,
productsInfo = [],
items = quote.getItems();
self = this;

if (!this.isStorePickupSelected()) {
return;
Expand Down Expand Up @@ -279,27 +277,15 @@ define([
pickupLocationsService.selectForShipping(location);
});
} else if (shippingAddress.city && shippingAddress.postcode) {
_.each(items, function (item) {
if (item['qty_options'] === undefined || item['qty_options'].length === 0) {
productsInfo.push(
{
sku: item.sku
}
);
}
});
pickupLocationsService
.getNearbyLocations({
area: {
radius: this.nearbySearchRadius,
searchTerm: shippingAddress.postcode + this.delimiter +
shippingAddress.countryId || this.defaultCountry
},
extensionAttributes: {
productsInfo: productsInfo
},
pageSize: this.nearbySearchLimit
})
.getNearbyLocations(
pickupLocationsService.getNearbyLocationsCriteria(
shippingAddress.postcode + this.delimiter +
(shippingAddress.countryId || this.defaultCountry),
this.nearbySearchRadius,
this.nearbySearchLimit
)
)
.then(function (locations) {
nearestLocation = locations[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ define([
* @returns void
*/
openPopup: function () {
var shippingAddress = quote.shippingAddress(),
var self = this,
shippingAddress = quote.shippingAddress(),
country = shippingAddress.countryId ? shippingAddress.countryId :
this.defaultCountryId,
searchTerm = '';
Expand All @@ -137,7 +138,11 @@ define([
searchTerm = this.getSearchTerm(shippingAddress.postcode, country);
}

this.updateNearbyLocations(searchTerm);
this.updateNearbyLocations(searchTerm).done(function () {
if (searchTerm && !self.searchQuery() && !self.nearbyLocations().length) {
self.updateNearbyLocations('');
}
});
},

/**
Expand All @@ -162,37 +167,16 @@ define([
* @returns {*}
*/
updateNearbyLocations: function (searchQuery) {
var self = this,
productsInfo = [],
items = quote.getItems(),
searchCriteria;

_.each(items, function (item) {
if (item['qty_options'] === undefined || item['qty_options'].length === 0) {
productsInfo.push(
{
sku: item.sku
}
);
}
});

searchCriteria = {
extensionAttributes: {
productsInfo: productsInfo
},
pageSize: this.nearbySearchLimit
};

if (searchQuery) {
searchCriteria.area = {
radius: this.nearbySearchRadius,
searchTerm: searchQuery
};
}
const self = this;

return pickupLocationsService
.getNearbyLocations(searchCriteria)
.getNearbyLocations(
pickupLocationsService.getNearbyLocationsCriteria(
searchQuery,
this.nearbySearchRadius,
this.nearbySearchLimit
)
)
.then(function (locations) {
self.nearbyLocations(locations);
})
Expand Down