From a58a2e7ca4700d3e23341fde767060a4c2c704a3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 30 Aug 2026 21:04:37 +0000
Subject: [PATCH] =Minor tweaks to MenuBlock.php
---
inc/blocks/MenuBlock.php | 67 +++++++++++++++++++++++++++------
1 files changed, 55 insertions(+), 12 deletions(-)
diff --git a/inc/blocks/MenuBlock.php b/inc/blocks/MenuBlock.php
index dd69c46..264e41e 100644
--- a/inc/blocks/MenuBlock.php
+++ b/inc/blocks/MenuBlock.php
@@ -32,7 +32,6 @@
public function __construct()
{
$this->cache = Cache::for('menu', 'post', WEEK_IN_SECONDS);
- $this->cache->flush();
if (Site::hasIntegration('square')) {
$this->base = '_square_';
} else if (Site::hasIntegration('helcim')) {
@@ -40,6 +39,7 @@
}
add_action('init', [ $this, 'registerBlock' ]);
add_action('save_post', [$this, 'flushCache'], 10, 2);
+ add_action('wp_footer', [$this, 'renderGallery']);
}
public function flushCache(int $postID, WP_Post $post):void
@@ -147,11 +147,7 @@
protected function getSections():array
{
if (!$this->sections) {
- $sections = Options::get('menu_section_order');
- if (!is_array($sections)) {
- $sections = [];
- }
- $this->sections = $sections;
+ $this->sections = aneb_menu_sections();
}
return $this->sections;
@@ -215,20 +211,58 @@
$excerpt = get_the_excerpt($ID);
$isVariable = !empty($fields['variations']??[]);
- $variations = $isVariable ? array_map('floatval', array_column($fields['variations'], 'price')) : [];
- $priceRange = $isVariable ?
- (jvbCurrency(min($variations)).' - '.jvbCurrency(max($variations))) :
- jvbCurrency($fields['_price']??'');
+
+ $priceRange = jvbCurrency($fields['price']);
+ if ($isVariable) {
+ $prices = array_map('floatval', array_column($fields['variations'], 'price'));
+ $min = min($prices);
+ $max = max($prices);
+ $priceRange = $min===$max ? jvbCurrency($min) : jvbCurrency($min) .' - '.jvbCurrency($max);
+
+ }
+
// if (!$isVariable) {
// jvbDump($fields, 'Fields');
// }
+// jvbDump(get_post_thumbnail_id($ID), 'thumbnail');
+// $product = wc_get_product($ID);
+// jvbDump($product->get_image_id(), 'product image');
+// jvbDump($product->get_gallery_image_ids(), 'Gallery images');
+ if ($fields['post_title'] === 'Breakfast Poutine') {
+// jvbDump($ID);
+// jvbDump($fields);
+ }
+
+ $gallery = '';
+ if (!empty($fields['gallery_image_ids'])) {
+ $gallery = implode(array_map(function($id) use ($fields){
+ $id = absint($id);
+ $caption = wp_get_attachment_caption($id);
+ return sprintf(
+ '<figure>%s<figcaption>%s</figcaption></figure>',
+ jvbFormatImage($id,'tiny','medium',true,'menu'),
+ empty($caption) ? $fields['post_title'] : $caption
+ );
+ }, $fields['gallery_image_ids']));
+ }
+
+ $caption = '';
+ if (!empty($fields['image_id'])) {
+ $caption = wp_get_attachment_caption((int)$fields['image_id']);
+ $caption = empty($caption) ? $fields['post_title'] : $caption;
+ }
+
$out = sprintf(
'<div id="%s" class="menu-item%s" data-section="%s" data-label="%s" data-id="%s">
<div class="header row x-btw">
- <h3>%s</h3>
- <p class="price">%s</p>
+ <figure>%s<figcaption>%s</figcaption></figure>
+ <div class="text row x-btw">
+ <h3>%s</h3>
+ <p class="price">%s</p>
+ </div>
</div>
+ <div class="gallery row%s">%s</div>
<div class="description">%s</div>
<div class="info col right">',
sanitize_title($fields['post_title']),
@@ -236,8 +270,12 @@
$slug,
$fields['post_title'],
$ID,
+ !empty($fields['image_id']) ? jvbFormatImage((int)$fields['image_id'],'tiny','medium',true,'menu') : '',
+ $caption,
$fields['post_title'],
$priceRange,
+ empty($gallery) ? '' : ' has',
+ $gallery,
$excerpt
);
@@ -455,4 +493,9 @@
}
echo jvbOnThisPage(array_keys($this->details));
}
+
+ public function renderGallery():void
+ {
+ jvbRenderGallery();
+ }
}
--
Gitblit v1.10.0