next to implement automatic refetch via cron
This commit is contained in:
parent
2eef682859
commit
77f8d034aa
Binary file not shown.
@ -130,11 +130,32 @@ class EcomZoneAPI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCatalog($perPage = 10)
|
public function getCatalog($perPage = 1000)
|
||||||
{
|
{
|
||||||
$this->checkRateLimit();
|
$this->checkRateLimit();
|
||||||
$url = $this->apiUrl . '/catalog';
|
$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)
|
public function getProduct($sku)
|
||||||
|
|||||||
@ -76,20 +76,32 @@ class EcomZone extends Module
|
|||||||
try {
|
try {
|
||||||
$debugOutput .= "Starting product fetch...\n";
|
$debugOutput .= "Starting product fetch...\n";
|
||||||
|
|
||||||
// Get first 10 products for testing
|
// Get all products
|
||||||
$catalog = $this->api->getCatalog(10);
|
$catalog = $this->api->getCatalog(1000);
|
||||||
|
|
||||||
if (isset($catalog['data']) && is_array($catalog['data'])) {
|
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(
|
$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['sku'],
|
||||||
$product['product_name'],
|
$product['product_name'],
|
||||||
$product['product_price'],
|
$product['product_price'],
|
||||||
$product['stock']
|
$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 {
|
} else {
|
||||||
$debugOutput .= "No products found or invalid response format\n";
|
$debugOutput .= "No products found or invalid response format\n";
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
modules/vancho-ecomzone.zip
Normal file
BIN
modules/vancho-ecomzone.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user