This simplifies product management by eliminating manual Kirby page creation. Products are now automatically loaded as virtual pages from the Shopify API. Changes: - Add virtual pages via page.children:after hook - Create shopify.php helper with caching (60min TTL) - Add shopify-refresh panel plugin for cache management - Remove manual product content files (now virtual) - Update site.yml blueprint to show refresh button - Fix cache implementation to use get/set pattern Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
46 lines
1.3 KiB
PHP
Executable file
46 lines
1.3 KiB
PHP
Executable file
<?php
|
|
|
|
Kirby::plugin('index/shopify-refresh-button', [
|
|
'fields' => [
|
|
'shopify-refresh' => [
|
|
'props' => [
|
|
'products' => function() {
|
|
return getShopifyProducts();
|
|
}
|
|
],
|
|
]
|
|
],
|
|
'routes' => [
|
|
[
|
|
'pattern' => 'shopify/refresh-cache.json',
|
|
'method' => 'POST',
|
|
'action' => function() {
|
|
if (!kirby()->user()) {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Unauthorized'
|
|
];
|
|
}
|
|
|
|
try {
|
|
kirby()->cache('shopify')->flush();
|
|
|
|
$products = fetchShopifyProducts();
|
|
|
|
return [
|
|
'status' => 'success',
|
|
'message' => 'Cache Shopify rafraîchi avec succès',
|
|
'count' => count($products),
|
|
'products' => $products
|
|
];
|
|
} catch (\Throwable $e) {
|
|
return [
|
|
'status' => 'error',
|
|
'message' => 'Erreur lors du rafraîchissement du cache',
|
|
'details' => $e->getMessage()
|
|
];
|
|
}
|
|
}
|
|
]
|
|
]
|
|
]);
|