管理画面の商品マスターでCrawlerを使っているのですが、
eccube.CRITICAL: InvalidArgumentException: The current node list is empty. (uncaught exception)がでて困っています。try〜catchで解決するかと思ったのですがうまく行きません。
別なフックポイントを作成して例外時にそこの処理が通るか確認したのですが、処理が通ってなかったです。
ご教授いただけると助かります。コードは以下のとおりです。
event.yml eccube.event.route.admin_product.exception: - [onAdminException,NORMAL] eccube.event.route.admin_product.response: - [onAdminRenderBefore,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 // Crawlerを使った処理 25 public function onAdminException(FilterResponseEvent $event){ 26 dump(000); 27 } 28 public function onAdminRenderBefore(FilterResponseEvent $event) 29 { 30 //引数eventから 内容を取得する 31 $response = $event->getResponse(); 32 33 // 在庫切れ情報を挿入 34 $addContent = '<span class="icon_stock">在庫なし</span>'; 35 36 // 書き換えhtmlの初期化 37 $html = $response->getContent(); 38 39 // 書き換え処理 40 // Crawlerクラスのhtmlメソッドを確認 41 // try catchで例外がないときにだけ、正常な動作 42 43 try{ 44 $crawler = new Crawler($html); 45 $filter = $crawler->filter('.item_detail > a'); 46 $oldHtml = $filter->html(); 47 $newHtml = $oldHtml . $addContent; 48 49 $html = $crawler->html(); 50 $html = str_replace($oldHtml, $newHtml, $html); 51 52 $response->setContent($html); 53 $event->setResponse($response); 54 }catch(Exception $e){ 55 $e->getMessage(); 56 } 57 } 58 59 public function onRenderProductList(TemplateEvent $event){ 60 61 // twigコードに在庫切れ情報を挿入 62 /*$snipet = 63 '{% set displayed = false %} 64 {% for ProductClass in Product.ProductClasses %} 65 {% if not displayed and ProductClass.StockFind == false %} 66 <span class="icon_stock">在庫なし</span> 67 {% set displayed = true %} 68 {% endif %} 69 {% endfor %}'; 70 71 // 検索する文字 72 $search = '<br>'; 73 $replace = $snipet.$search; 74 // ソース全体から<br>を探し、置き換える 75 $source = str_replace($search, $replace, $event->getSource()); 76 $event->setSource($source);*/ 77 } 78}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。