From 0fe3442963f7598c12d8dc2da6dc4f8baa6bfb1a Mon Sep 17 00:00:00 2001 From: Timoteo Date: Mon, 3 Apr 2023 08:14:25 -0300 Subject: [PATCH] Commit --- app/Controllers/ProductController.php | 47 +++++++++++++++++++++++++++ coffeecode_woo.php | 17 ++++++++++ 2 files changed, 64 insertions(+) create mode 100644 app/Controllers/ProductController.php create mode 100644 coffeecode_woo.php diff --git a/app/Controllers/ProductController.php b/app/Controllers/ProductController.php new file mode 100644 index 0000000..4c4468a --- /dev/null +++ b/app/Controllers/ProductController.php @@ -0,0 +1,47 @@ + true, + 'version' => 'wc/v3', + ] + ); + + // Query para buscar produtos + $products = $woocommerce->get('products', [ + 'per_page' => 5, + 'page' => (int) $_GET['paged'] ?: 1, + 'orderby' => 'price', + 'order' => 'asc', + ]); + + // Formatar produtos + $formatted_products = array_map(function($product) { + return [ + 'id' => $product->id, + 'title' => $product->name, + 'description' => $product->short_description, + 'price' => $product->price, + 'type' => $product->type, + 'imageUrl' => $product->images[0]->src, + 'productLink' => $product->permalink, + ]; + }, $products); + + // Retornar produtos como JSON + wp_send_json($formatted_products); + } + +} +?> \ No newline at end of file diff --git a/coffeecode_woo.php b/coffeecode_woo.php new file mode 100644 index 0000000..1c75afa --- /dev/null +++ b/coffeecode_woo.php @@ -0,0 +1,17 @@ +get( '/products', [ProductController::class, 'index'] ); + } ); + +} ); + +?> \ No newline at end of file