管理画面の「検索」ボタンを押した時にcontrollerでDOM要素を取得して、
狙った箇所に「在庫切れ」の表示を表示させたいです。
DOM要素を取得するにはCrowlerを使うという検討はつけたのですが、どのタイミングでDOMを取得できるのかが
わかりません。なのでフックポイントをいくつか書いています。以下がそのコードです。
event.yml admin.product.index.search: - [onAdminProduct2, NORMAL] eccube.event.render.product_list.before: - [onRenderProductListBefore, NORMAL] Admin/Product/index.twig: - [onRenderProductList, NORMAL]
php
1<?php 2namespace Plugin\StockControll; 3 4use Eccube\Application; 5use Eccube\Common\Constant; 6use Eccube\Entity\Category; 7use Eccube\Event\EventArgs; 8use Eccube\Event\TemplateEvent; 9use Plugin\CategoryContent\Entity\CategoryContent; 10use Symfony\Component\Form\FormInterface; 11use Symfony\Component\HttpKernel\Event\FilterResponseEvent; 12use Symfony\Component\DomCrawler\Crawler; 13 14class StockControllEvent 15{ 16 /** @var \Eccube\Application $app */ 17 private $app; 18 19 public function __construct($app) 20 { 21 $this->app = $app; 22 } 23 24 public function onAdminProduct2(EventArgs $event) 25 { 26 /*$app = $this->app; 27 28 // requestとresponseを取得 29 $request = $event->getRequest(); 30 $response = $event->getResponse(); 31 32 $crawler = new Crawler($response->getContent()); 33 $html = $this->getHtml($crawler);*/ 34 } 35 36 public function onRenderProductListBefore(FilterResponseEvent $event){ 37 38 } 39 40 public function onRenderProductList(TemplateEvent $event){ 41 // twigコードに在庫切れ情報を挿入 42 $snipet = 43 '{% set displayed = false %} 44 {% for ProductClass in Product.ProductClasses %} 45 {% if not displayed and ProductClass.StockFind == false %} 46 <span class="icon_stock">在庫なし</span> 47 {% set displayed = true %} 48 {% endif %} 49 {% endfor %}'; 50 51 //$search = '<span id="result_list__code--{{ Product.id }}">'; 52 $search = '<br>'; 53 $replace = $snipet.$search; 54 $source = str_replace($search, $replace, $event->getSource()); 55 $event->setSource($source); 56 } 57}
EC-CUBEのフォーラムを参考にしたのですが、うまくいきませんでした。
自分がやろうとしていることは実現可能かどうかも怪しいです。
わかる方ご教授お願いいたします。