| | |
| | | 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')) { |
| | |
| | | } |
| | | 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 |
| | |
| | | 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; |
| | |
| | | |
| | | $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']), |
| | |
| | | $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 |
| | | ); |
| | | |
| | |
| | | } |
| | | echo jvbOnThisPage(array_keys($this->details)); |
| | | } |
| | | |
| | | public function renderGallery():void |
| | | { |
| | | jvbRenderGallery(); |
| | | } |
| | | } |