Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Chrome tablet not all products are fetched on page load #79

Open
m-zat opened this issue Aug 4, 2021 · 1 comment
Open

On Chrome tablet not all products are fetched on page load #79

m-zat opened this issue Aug 4, 2021 · 1 comment
Labels
Bug Something isn't working

Comments

@m-zat
Copy link

m-zat commented Aug 4, 2021

When opening wepos on a tablet only a limited amount of product is shown and accessible with the search bar.

In order to get all products I need to scroll down until the end of the page.

Would it be possible to preload all products on page load?

@uaibo
Copy link

uaibo commented Sep 12, 2021

I was going to write about the initial products load which is the stupidest thing I've seen in a while on code. I don't know why they did it but loading all the products on page load is very very ameteurish and very inefficient. I have a client who had about 800 products and it would take them minutes of waiting before they can do anything useful with the page.
What if they had 10000 products? Keep waiting all day long, forever?
Why not just search as they type?

I fixed it in my case by editing the searchProduct() method in ProductSearch.vue like the following:

        searchProduct(e) {
            if ( this.serachInput ) {
                if ( this.mode == 'product' ) {

                  wepos.api.get( wepos.rest.root + wepos.rest.posversion + '/products?status=publish&per_page=30&page=1&sku='+this.serachInput )
                  .done( ( response, status, xhr ) => {
                      this.productLoading = false;
                  }).then( ( response, status, xhr ) => {
                      this.searchableProduct = response;
                  });


                  /*
                  this.searchableProduct = this.products.filter( (product) => {
                    if ( product.id.toString().indexOf( this.serachInput ) != -1 ) {
                      return true;
                    } else if ( product.name.toString().toLowerCase().indexOf( this.serachInput.toLowerCase() ) != -1 ) {
                      return true
                    } else if ( product.sku.toString().toLowerCase().indexOf( this.serachInput.toString().toLowerCase() ) != -1 ) {
                      return true
                    } else {
                      return false;
                    }
                  });
                  */

                }
            }
        },

and by commenting this.fetchProducts() in Home.vue as the following:

        fetchProducts() {
            if ( this.page == 1 ) {
                this.productLoading = true;
            }

            if ( ( this.totalPages >= this.page ) ) {
                wepos.api.get( wepos.rest.root + wepos.rest.posversion + '/products?status=publish&per_page=30&page=' + this.page )
                .done( ( response, status, xhr ) => {
                    this.products = this.products.concat( response );
                    this.page += 1;
                    this.totalPages = parseInt( xhr.getResponseHeader('X-WP-TotalPages') );
                    this.productLoading = false;
                }).then( ( response, status, xhr ) => {
                    //this.fetchProducts(); //stop loading all the unnecessary crap!!!!
                });
            } else {
                this.productLoading = false;
            }
        },

now my client can only search by SKU but that's perfectly fine since that's all what they needed.
If you need to be able to search simply by title, then replace the "&sku=" parameter from the API URL with "&s="

@xaviranik xaviranik added the Bug Something isn't working label Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants