Add virtual pages from Shopify and panel refresh button
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>
This commit is contained in:
parent
4987c4830f
commit
ade0ed1a67
21 changed files with 570 additions and 41 deletions
46
site/plugins/shopify-refresh-button/index.php
Executable file
46
site/plugins/shopify-refresh-button/index.php
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
<?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()
|
||||
];
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue