diff --git a/modules/ecomzone.zip b/modules/ecomzone.zip deleted file mode 100644 index 9413eae..0000000 Binary files a/modules/ecomzone.zip and /dev/null differ diff --git a/modules/ecomzone/classes/EcomZoneAPI.php b/modules/ecomzone/classes/EcomZoneAPI.php index 8a86064..69cd30c 100644 --- a/modules/ecomzone/classes/EcomZoneAPI.php +++ b/modules/ecomzone/classes/EcomZoneAPI.php @@ -130,11 +130,32 @@ class EcomZoneAPI } } - public function getCatalog($perPage = 10) + public function getCatalog($perPage = 1000) { $this->checkRateLimit(); $url = $this->apiUrl . '/catalog'; - return $this->makeRequest('GET', $url, ['per_page' => $perPage]); + $allProducts = []; + $currentPage = 1; + + do { + $params = [ + 'per_page' => $perPage, + 'page' => $currentPage + ]; + + $response = $this->makeRequest('GET', $url, $params); + + if (isset($response['data']) && is_array($response['data'])) { + $allProducts = array_merge($allProducts, $response['data']); + } + + $currentPage++; + // Check if there's a next page + $hasNextPage = isset($response['next_page_url']) && $response['next_page_url'] !== null; + + } while ($hasNextPage); + + return ['data' => $allProducts]; } public function getProduct($sku) diff --git a/modules/ecomzone/ecomzone.php b/modules/ecomzone/ecomzone.php index a07fa86..b9f775f 100644 --- a/modules/ecomzone/ecomzone.php +++ b/modules/ecomzone/ecomzone.php @@ -76,20 +76,32 @@ class EcomZone extends Module try { $debugOutput .= "Starting product fetch...\n"; - // Get first 10 products for testing - $catalog = $this->api->getCatalog(10); + // Get all products + $catalog = $this->api->getCatalog(1000); if (isset($catalog['data']) && is_array($catalog['data'])) { - foreach ($catalog['data'] as $product) { + $debugOutput .= sprintf("Fetching all products...\n"); + $totalProducts = count($catalog['data']); + + // Show first 5 products as preview + for ($i = 0; $i < min(5, $totalProducts); $i++) { + $product = $catalog['data'][$i]; $debugOutput .= sprintf( - "Found product: %s - %s (Price: %s EUR, Stock: %s)\n", + "Product %d/%d: %s - %s (Price: %s EUR, Stock: %s)\n", + $i + 1, + $totalProducts, $product['sku'], $product['product_name'], $product['product_price'], $product['stock'] ); } - $debugOutput .= sprintf("\nTotal products fetched: %d\n", count($catalog['data'])); + + if ($totalProducts > 5) { + $debugOutput .= "...\n"; // Indicate there are more products + } + + $debugOutput .= sprintf("\nTotal products fetched: %d\n", $totalProducts); } else { $debugOutput .= "No products found or invalid response format\n"; } diff --git a/modules/vancho-ecomzone.zip b/modules/vancho-ecomzone.zip new file mode 100644 index 0000000..e824b85 Binary files /dev/null and b/modules/vancho-ecomzone.zip differ