Skip to content

get product > 100 #21

Description

@guilherme-oliveria
	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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions