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

get product > 100 #21

Open
guilherme-oliveria opened this issue Aug 23, 2019 · 3 comments
Open

get product > 100 #21

guilherme-oliveria opened this issue Aug 23, 2019 · 3 comments

Comments

@guilherme-oliveria
Copy link

guilherme-oliveria commented Aug 23, 2019

	Object resultado = wooCommerce.getAll(EndpointBaseType.PRODUCTS.getValue(), integracao.getUrl());

     	@Override
	@SuppressWarnings("all")
    public List getAll(String endpointBase, String urlHost) {
		Integer OAUTH_PAGE = 1;
		String privado  = "private" ,  publico="publish", concluido ="completed",pendente="pending", cancelado="cancelled",aguardando ="on-hold" ;
		
		List listaFinal = new ArrayList<>();
		if(endpointBase.equals("products")){
	                listaFinal = allProduct(listaFinal, endpointBase, OAUTH_PAGE, publico,urlHost);
	                listaFinal = allProduct(listaFinal, endpointBase, OAUTH_PAGE, privado,urlHost);
		}else if(endpointBase.equals("orders")){
			listaFinal = allProduct(listaFinal, endpointBase, OAUTH_PAGE, concluido, urlHost);
			listaFinal = allProduct(listaFinal, endpointBase, OAUTH_PAGE, cancelado);
			listaFinal = allProduct(listaFinal, endpointBase, OAUTH_PAGE, pendente);
			listaFinal = allProduct(listaFinal, endpointBase, OAUTH_PAGE, aguardando);
		}else{
			client.getAll(metGetAll(endpointBase, OAUTH_PAGE,publico),urlHost);
		}
		
        return  listaFinal;
        
    }

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public List allProduct(List listaFinal,String endpointBase, Integer OAUTH_PAGE,String status , String urlHost) {
		List urlAll = client.getAll(metGetAll(endpointBase, OAUTH_PAGE, status),urlHost) ;
	        listaFinal.addAll(urlAll);
	    	 while(urlAll !=null) {
        		OAUTH_PAGE ++;
        		try{
        			urlAll = client.getAll(metGetAll(endpointBase, OAUTH_PAGE,status),urlHost);

        			if(urlAll!=null && urlAll.size() == 0){
						urlAll = null;
						break;

        			}
					listaFinal.addAll(urlAll);
        		}catch(Exception e){
        			try{
						urlAll = client.getAll(metGetAll(endpointBase, OAUTH_PAGE,status),urlHost);

						if(urlAll!=null && urlAll.size() == 0){
							urlAll = null;
							break;

						}
						listaFinal.addAll(urlAll);
					}catch(Exception e2){
        				e2.printStackTrace();
					}
        		}
        	}

	     	 return  listaFinal;
	}
	public String metGetAll(String endpointBase, Integer OAUTH_PER_PAGE, String status ) { 
		String url = String.format(API_URL_FORMAT, config.getUrl(), endpointBase);
                String signature = OauthSignature.getAsQueryStringAll(config, url, HttpMethod.GET, OAUTH_PER_PAGE, status);
                String securedUrl = String.format(URL_SECURED_FORMAT, url, signature);
        return securedUrl;
	}

I accept improvement suggestion, because I work with 6000 products and I need to update them daily.

@omandryk
Copy link
Collaborator

Hi @guilherme-oliveria , could you please explain what do you mean? Recently I've merged a pull request which adds batch operations. Will it help you?

@guilherme-oliveria
Copy link
Author

how is your new commit not found, because this way passing the "OAUTH_PAGE" inside the "while" I can get all my 6000 products

@guilherme-oliveria
Copy link
Author

guilherme-oliveria commented Aug 24, 2019

sorry, but in woocomerc new 3.7 can you register product images?
I have this problem because my URLs have "?" because I pass parameter to java,
they all end with ".jpg",
woocommerce/woocommerce#24484

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants