| | |
| | | <?php |
| | | namespace JVBase\blocks; |
| | | |
| | | use JVBase\managers\CacheManager; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\forms\TaxonomySelector; |
| | | use JVBase\meta\MetaManager; |
| | | use JVBase\meta\Form; |
| | | use JVBase\meta\Meta; |
| | | use JVBase\meta\Render; |
| | | use WP_Block; |
| | | use WP_Query; |
| | | |
| | |
| | | |
| | | class MenuBlock |
| | | { |
| | | protected CacheManager $cache; |
| | | protected Cache $cache; |
| | | protected string $config; |
| | | protected string $type; |
| | | protected string $path = JVB_DIR . '/build/menu'; |
| | |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->cache = CacheManager::for('menu', WEEK_IN_SECONDS); |
| | | $this->cache = Cache::for('menu', WEEK_IN_SECONDS)->connectTo('post', 'menu_item'); |
| | | add_action('init', [ $this, 'registerBlock' ]); |
| | | } |
| | | |
| | |
| | | return ''; |
| | | } |
| | | $key = $this->cache->generateKey($this->params); |
| | | $cache = $this->cache->get($key); |
| | | $cache = false; |
| | | if ($cache) { |
| | | return $cache; |
| | | } |
| | | |
| | | ob_start(); |
| | | $this->renderBlock(); |
| | | $content = ob_get_clean(); |
| | | $this->cache->set($key, $content); |
| | | return $content; |
| | | return $this->cache->remember( |
| | | $key, |
| | | function() { |
| | | ob_start(); |
| | | $this->renderBlock(); |
| | | return ob_get_clean(); |
| | | } |
| | | ); |
| | | } |
| | | |
| | | protected function renderBlock():void |
| | |
| | | protected function getSections():array |
| | | { |
| | | if (!$this->sections) { |
| | | $options = new MetaManager(null, 'options'); |
| | | $sections = $options->getValue('menu_section_order'); |
| | | $options = Meta::forOptions('options'); |
| | | $sections = $options->get('menu_section_order'); |
| | | if (!is_array($sections)) { |
| | | $sections = []; |
| | | } |
| | |
| | | } |
| | | |
| | | protected function renderMenuItem(int $ID, string $slug, string $postType = 'menu_item') { |
| | | $meta = new MetaManager($ID, 'post'); |
| | | $meta = Meta::forPost($ID); |
| | | $values = $meta->getAll([ |
| | | 'post_title', |
| | | '_square_catalog_id', |
| | |
| | | |
| | | ?> |
| | | <div class="menu-item<?= !empty($variations) ? ' variable' : '' ?>" data-section="<?=$slug?>"> |
| | | <div class="header row btw"> |
| | | <div class="header row x-btw"> |
| | | <h3><?= $values['post_title']?></h3> |
| | | <p class="price"><?= $priceRange ?></p> |
| | | </div> |
| | | <div class="description"> |
| | | <?php $meta->render('render', 'post_excerpt')?> |
| | | <?= Render::renderFrom($meta, 'post_excerpt')?> |
| | | </div> |
| | | <div class="info row end"> |
| | | <div class="info row right"> |
| | | <?php |
| | | if (empty($variations)) { |
| | | $meta->render( |
| | | 'form', |
| | | Form::renderFrom($meta, |
| | | $ID.'|cart_quantity', |
| | | [ |
| | | 'type' => 'number', |
| | |
| | | foreach ($variations as $index =>$row) { |
| | | jvbDump($index, 'index'); |
| | | jvbDump($row, 'row'); |
| | | $meta->render( |
| | | 'form', |
| | | Form::renderFrom($meta, |
| | | 'quantity-'.$index, |
| | | [ |
| | | 'type' => 'number', |