Capitulo 48 del Módulo 9 Carrito de Compra Android

➜ Preparar el Pedido y enviarlo al Servidor

Preparar y enviar el pedido a la administración Android | Preparar y enviar el pedido a la administración Android

Preparar  y enviar el pedido a la administración Android

btnPedido = findViewById(R.id.btnPedido);

        btnPedido.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //CREAR JSON
                Cursor cursor = dbManager.carritoAll("1");
                if (cursor.moveToFirst()){
                    jsonArray = new JSONArray();
                   
                    do {
                        JSONObject o = new JSONObject();
                        try {
                            o.put("nombre",cursor.getString(cursor.getColumnIndexOrThrow("nombre")));
                            o.put("cantidad",cursor.getString(cursor.getColumnIndexOrThrow("cantidad")));
                            o.put("precio",cursor.getString(cursor.getColumnIndexOrThrow("precio")));
                            o.put("tamano",cursor.getString(cursor.getColumnIndexOrThrow("tamano")));
                            o.put("importe",cursor.getString(cursor.getColumnIndexOrThrow("importe")));
                            o.put("producto_id",cursor.getString(cursor.getColumnIndexOrThrow("producto_id")));
                            jsonArray.put(o);
                           
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }while (cursor.moveToNext());

                 


                    Call<JSONArray> call = RetrofitClient.getApiService().enviarPedido(
                            "Bearer "+_sessionManager.getAccessToken(),
                            jsonArray,
                            _subtotal,
                            _impuesto,
                            _total
                    );
                    call.enqueue(new Callback<JSONArray>() {
                        @Override
                        public void onResponse(Call<JSONArray> call, Response<JSONArray> response) {
                            if (response.isSuccessful()){
                                Log.d("RESPONSE",response.body().toString());

                            }
                        }

                        @Override
                        public void onFailure(Call<JSONArray> call, Throwable t) {
                            t.getMessage();
                        }
                    });


                }

            }
        });

 

 @POST("pedido")
    Call<JSONArray> enviarPedido(
            @Header("Authorization") String access_token,
            @Body JSONArray jsonArray,
            @Query("subtotal") double subtotal,
            @Query("impuesto") double impuesto,
            @Query("total") double total
    );

 


1054 visitas

Descarga el código del proyecto

Descarga el código fuente del proyecto adquiriendo el curso completo

Comprar

¡Qué aprenderás?

tooltip bs-tooltip-top bs-tooltip-end bs-tooltip-bottom bs-tooltip-start show fade tooltip-inner

Codea Applications

México, Colombia, España, Venezuela, Argentina, Bolivia, Perú