Jake Vanderwerf
7 days ago 46d681c6b825d21b3f698d793c4e630c687d90ad
inc/blocks/MenuBlock.php
@@ -1,9 +1,11 @@
<?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;
@@ -13,7 +15,7 @@
class MenuBlock
{
    protected CacheManager $cache;
    protected Cache $cache;
    protected string $config;
    protected string $type;
    protected string $path = JVB_DIR . '/build/menu';
@@ -27,7 +29,7 @@
    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' ]);
    }
@@ -57,17 +59,14 @@
         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
@@ -107,8 +106,8 @@
   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 = [];
         }
@@ -156,7 +155,7 @@
    }
   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',
@@ -195,18 +194,17 @@
      ?>
      <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',
@@ -230,8 +228,7 @@
               foreach ($variations as $index =>$row) {
                  jvbDump($index, 'index');
                  jvbDump($row, 'row');
                  $meta->render(
                     'form',
                  Form::renderFrom($meta,
                     'quantity-'.$index,
                     [
                        'type'   => 'number',