Skip to content

Commit

Permalink
Merge pull request #2946 from Flyingmana/bugfix/load-more-in-search-n…
Browse files Browse the repository at this point in the history
…ot-working

avoid increase of start property of Search when function runs in parallel
  • Loading branch information
patzick committed May 27, 2019
2 parents ca7a770 + 5bdf05f commit f6ea923
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use event bus to emit 'application-after-init' event (#2852)
- Validation of fields 'company name' and 'tax' in checkout doesn't work correctly - @dimasch (#2741)
- Fixed wrong price displayed in instant checkout module - @vishal-7037 (#2884)
- Fixed Load more in Search Results not working when typed to fast - @Flyingmana (#2659, #2946)
- Subscribe button responsive - @exlo89, @webdiver, @przemyslawspaczek (#2886)

### Changed / Improved
Expand Down
10 changes: 6 additions & 4 deletions core/modules/catalog/components/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export const Search = {
makeSearch () {
if (this.search !== '' && this.search !== undefined) {
let query = this.buildSearchQuery(this.search)
this.start = 0
let startValue = 0;
this.start = startValue
this.readMore = true
this.$store.dispatch('product/list', { query, start: this.start, size: this.size, updateState: false }).then(resp => {
this.products = resp.items
this.start = this.start + this.size
this.start = startValue + this.size
this.emptyResults = resp.items.length < 1
}).catch((err) => {
Logger.error(err, 'components-search')()
Expand All @@ -61,14 +62,15 @@ export const Search = {
seeMore () {
if (this.search !== '' && this.search !== undefined) {
let query = this.buildSearchQuery(this.search)
this.$store.dispatch('product/list', { query, start: this.start, size: this.size, updateState: false }).then((resp) => {
let startValue = this.start;
this.$store.dispatch('product/list', { query, start: startValue, size: this.size, updateState: false }).then((resp) => {
let page = Math.floor(resp.total / this.size)
let exceeed = resp.total - this.size * page
if (resp.start === resp.total - exceeed) {
this.readMore = false
}
this.products = this.products.concat(resp.items)
this.start = this.start + this.size
this.start = startValue + this.size
this.emptyResults = this.products.length < 1
}).catch((err) => {
Logger.error(err, 'components-search')()
Expand Down

0 comments on commit f6ea923

Please sign in to comment.