index-shop/site/plugins/shopify-refresh-button/index.php

47 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?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()
];
}
}
]
]
]);