get product > 100
guilherme-oliveria opened this issue · 3 comments
guilherme-oliveria commented
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 commented
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 commented
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 commented
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