| | |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->cache = Cache::for('menu', WEEK_IN_SECONDS)->connect('post'); |
| | | $this->cache = Cache::for('menu', 'post', WEEK_IN_SECONDS); |
| | | if (Site::hasIntegration('square')) { |
| | | $this->base = '_square_'; |
| | | } else if (Site::hasIntegration('helcim')) { |
| | |
| | | |
| | | protected function buildParams():void |
| | | { |
| | | if (is_post_type_archive(BASE.'menu_item')) { |
| | | // if (is_post_type_archive(BASE.'menu_item') || |
| | | if (is_post_type_archive('product') || |
| | | (function_exists('is_shop') && is_shop())) { |
| | | $this->params = ['all']; |
| | | } elseif (is_tax(BASE.'section')) { |
| | | // } elseif (is_tax(BASE.'section')) { |
| | | } elseif (is_tax('product_cat')) { |
| | | $this->params = []; |
| | | } else { |
| | | $this->params = []; |
| | |
| | | return ''; |
| | | } |
| | | jvbInlineStyles('forms'); |
| | | $key = $this->cache->generateKey($this->params); |
| | | $this->cache->flush(); |
| | | return $this->cache->remember( |
| | | $key, |
| | | $this->params, |
| | | function() { |
| | | ob_start(); |
| | | $this->renderBlock(); |
| | |
| | | <?php |
| | | $sections = $this->getSections(); |
| | | foreach ($sections as $section) { |
| | | if (!jvbTermHasPosts($section['id'], BASE.'section')) { |
| | | // if (!jvbTermHasPosts($section['id'], BASE.'section')) { |
| | | if (!jvbTermHasPosts($section['id'], 'product_cat')) { |
| | | continue; |
| | | } |
| | | ?> |
| | |
| | | { |
| | | $sections = $this->getSections(); |
| | | foreach ($sections as $section) { |
| | | if($section['name'] === 'Uncategorized') { |
| | | continue; |
| | | } |
| | | $items = new WP_Query([ |
| | | 'post_type' => BASE.'menu_item', |
| | | 'post_type' => 'product', |
| | | // 'post_type' => BASE.'menu_item', |
| | | 'order' => 'ASC', |
| | | 'posts_per_page' => -1, |
| | | 'tax_query' => [ |
| | | [ |
| | | 'taxonomy' => BASE.'section', |
| | | 'taxonomy' => 'product_cat', |
| | | // 'taxonomy' => BASE.'section', |
| | | 'terms' => (int) $section['id'], |
| | | ] |
| | | ], |
| | |
| | | } |
| | | } |
| | | |
| | | protected function renderMenuItem(int $ID, string $slug, string $postType = 'menu_item') { |
| | | /** |
| | | * Renders from WooCommerce product |
| | | * @param int $ID |
| | | * @param string $slug |
| | | * @param string $postType |
| | | * @return void |
| | | */ |
| | | protected function renderMenuItem(int $ID, string $slug, string $postType = 'product'):void { |
| | | $meta = Meta::forPost($ID); |
| | | |
| | | $fields = $meta->getAll(); |
| | | |
| | | // jvbDump($fields, 'Fields'); |
| | | |
| | | $excerpt = get_the_excerpt($ID); |
| | | $isVariable = !empty($fields['variations']??[]); |
| | | $variations = $isVariable ? array_map('floatval', array_column($fields['variations'], 'price')) : []; |
| | | $priceRange = $isVariable ? |
| | | (min($variations).' - '.max($variations)) : |
| | | $fields['_price']??''; |
| | | |
| | | $out = sprintf( |
| | | '<div 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> |
| | | </div> |
| | | <div class="description">%s</div> |
| | | <div class="info col right">', |
| | | $isVariable ? ' variable' : '', |
| | | $slug, |
| | | $fields['post_title'], |
| | | $ID, |
| | | $fields['post_title'], |
| | | $priceRange, |
| | | $excerpt |
| | | ); |
| | | |
| | | if (!empty($fields['variations']??[])) { |
| | | foreach ($fields['variations'] as $index => $row) { |
| | | $out .= sprintf( |
| | | '<div class="row right nowrap"> |
| | | <div> |
| | | <h4>%s — %s</h4> |
| | | %s |
| | | </div>', //Note: we had 3 %s%s%s before the last </div> last time. This was to add optional ingredients or preparation time duration, not default in WooCommerce |
| | | $row['title'], |
| | | jvbCurrency($row['price']), |
| | | empty($row['description']) ? '' : wpautop($row['description']), |
| | | ); |
| | | |
| | | $out .= Form::render( |
| | | $row['id'], |
| | | '', |
| | | [ |
| | | 'type' => 'quantity', |
| | | 'label' => $row['title'], |
| | | 'min' => 0, |
| | | 'max' => 30, |
| | | 'data' => [ |
| | | 'price' => $row['price'], |
| | | 'id' => $row['id'], |
| | | 'sku' => $row['sku'], |
| | | 'name' => $row['title'], |
| | | 'add-to-cart' => '' |
| | | ], |
| | | 'add' => 'Add 1 '.$row['title'].' to cart', |
| | | 'remove' => 'Remove 1 '.$row['title']. ' from cart', |
| | | ] |
| | | ); |
| | | $out .= '</div>'; |
| | | } |
| | | } else { |
| | | $out .= Form::render( |
| | | $ID, |
| | | '', |
| | | [ |
| | | 'type' => 'quantity', |
| | | 'label' => 'Add to Order', |
| | | 'min' => 0, |
| | | 'max' => 30, |
| | | 'step' => 1, |
| | | 'data' => [ |
| | | 'price' => $fields['_price'], |
| | | 'id' => $ID, |
| | | 'name' => $fields['post_title'], |
| | | 'step' => 1, |
| | | 'add-to-cart' => '', |
| | | ], |
| | | 'add' => 'Add 1 '.$fields['post_title'].' to cart', |
| | | 'remove' => 'Remove 1 '.$fields['title']. ' from cart', |
| | | ] |
| | | ); |
| | | } |
| | | |
| | | $out .= '</div></div>'; |
| | | |
| | | echo $out; |
| | | |
| | | } |
| | | /** |
| | | protected function renderMenuItemOLD(int $ID, string $slug, string $postType = 'menu_item') { |
| | | $meta = Meta::forPost($ID); |
| | | $fields = $meta->getAll(); |
| | | $values = $meta->getAll([ |
| | |
| | | $prices[] = (float) $row[$this->base.'price']; |
| | | } |
| | | } |
| | | if (!empty($prices)) { |
| | | if (!empty($prices) && (min($prices) !== max($prices))) { |
| | | $priceRange = jvbCurrency(min($prices)).' - '.jvbCurrency(max($prices)); |
| | | } elseif (!empty($prices)) { |
| | | $priceRange = jvbCurrency(max($prices)); |
| | | } |
| | | } |
| | | |
| | |
| | | if (empty($variations)) { |
| | | echo Form::render( |
| | | $ID.'|cart_quantity', |
| | | '', |
| | | [ |
| | | 'type' => 'quantity', |
| | | 'label' => 'Add to Order', |
| | |
| | | |
| | | </div> |
| | | <?php |
| | | } |
| | | } **/ |
| | | |
| | | |
| | | |
| | | protected function renderOnThisPage():void |