/** * 商品一覧画面にカテゴリコンテンツを表示する. * * @param TemplateEvent $event */ public function onRenderProductList(TemplateEvent $event) { log_info('CategoryContent Product/list.twig start'); $parameters = $event->getParameters(); // カテゴリIDがない場合、レンダリングしない if (!$parameters['Category']) { return; } // 登録がない、もしくは空で登録されている場合、レンダリングをしない $Category = $parameters['Category']; $CategoryContent = $this->app['eccube.plugin.category_content.repository.category_content']->find($Category->getId()); if (!$CategoryContent || $CategoryContent->getContent() == '') { return; } // twigコードにカテゴリコンテンツを挿入 $snipet = $this->app['twig']->getLoader()->getSource('CategoryContent/Resource/template/default/category_content.twig'); $sourceOrigin = $event->getSource(); $search = self::CATEGORY_CONTENT_TAG; if (strpos($sourceOrigin, $search)) { // タグの位置に挿入する場合 log_info('Render category content with ', array('CATEGORY_CONTENT_TAG' => $search)); $replace = $search . $snipet; } else { // Elementを探して挿入する場合 $search = '<div id="result_info_box"'; $replace = $snipet . $search; } $source = str_replace($search, $replace, $sourceOrigin); $event->setSource($source); // twigパラメータにカテゴリコンテンツを追加 $parameters['PluginCategoryContent'] = $CategoryContent; $event->setParameters($parameters); log_info('CategoryContent Product/list.twig end'); }
/** * Parameter test */ public function testParameter() { $templateEvent = new TemplateEvent(null, null); $this->assertSame(array(), $templateEvent->getParameters()); $parameter = array('id' => 1); // set parameter $templateEvent->setParameters($parameter); $this->assertSame($parameter, $templateEvent->getParameters()); }
/** * Event for new hook point. * * @param TemplateEvent $event */ public function onAdminOrderIndexRender(TemplateEvent $event) { log_info('Event: Order pdf hook into the order search render start.'); /** * @var \Twig_Environment $twig */ $twig = $this->app['twig']; $twigAppend = $twig->getLoader()->getSource('OrderPdf/Resource/template/admin/order_pdf_menu.twig'); /** * @var string twig template */ $twigSource = $event->getSource(); $twigSource = $this->renderPosition($twigSource, $twigAppend); $event->setSource($twigSource); log_info('Event: Order pdf hook into the order search render end.'); }
/** * 商品一覧画面にカテゴリコンテンツを表示する. * * @param TemplateEvent $event */ public function onRenderProductList(TemplateEvent $event) { $parameters = $event->getParameters(); // カテゴリIDがない場合、レンダリングしない if (is_null($parameters['Category'])) { return; } // 登録がない、もしくは空で登録されている場合、レンダリングをしない $Category = $parameters['Category']; $CategoryContent = $this->app['category_content.repository.category_content']->find($Category->getId()); if (is_null($CategoryContent) || $CategoryContent->getContent() == '') { return; } // twigコードにカテゴリコンテンツを挿入 $snipet = '<div class="row">{{ CategoryContent.content | raw }}</div>'; $search = '<div id="result_info_box"'; $replace = $snipet . $search; $source = str_replace($search, $replace, $event->getSource()); $event->setSource($source); // twigパラメータにカテゴリコンテンツを追加 $parameters['CategoryContent'] = $CategoryContent; $event->setParameters($parameters); }
/** * New event function on version >= 3.0.9 (new hook point) * Product detail render (front). * * @param TemplateEvent $event */ public function onRenderProductDetail(TemplateEvent $event) { log_info('Event: product maker hook into the product detail start.'); $parameters = $event->getParameters(); /** * @var Product $Product */ $Product = $parameters['Product']; if (!$Product) { return; } /** * @var ProductMakerRepository $repository */ $repository = $this->app['eccube.plugin.maker.repository.product_maker']; /** * @var ProductMaker $ProductMaker */ $ProductMaker = $repository->find($Product); if (!$ProductMaker) { log_info('Event: product maker not found.', array('Product id' => $Product->getId())); return; } $Maker = $ProductMaker->getMaker(); if (!$Maker) { log_info('Event: maker not found.', array('Product maker id' => $ProductMaker->getId())); // 商品メーカーマスタにデータが存在しないまたは削除されていれば無視する return; } /** * @var \Twig_Environment $twig */ $twig = $this->app['twig']; $twigAppend = $twig->getLoader()->getSource('Maker/Resource/template/default/maker.twig'); /** * @var string $twigSource twig template. */ $twigSource = $event->getSource(); $twigSource = $this->renderPosition($twigSource, $twigAppend, $this->makerTag); $event->setSource($twigSource); $parameters['maker_name'] = $ProductMaker->getMaker()->getName(); $parameters['maker_url'] = $ProductMaker->getMakerUrl(); $event->setParameters($parameters); log_info('Event: product maker render success.', array('Product id' => $ProductMaker->getId())); log_info('Event: product maker hook into the product detail end.'); }
/** * new hookpoint for render RelatedProduct form. * * @param TemplateEvent $event */ public function onRenderAdminProduct(TemplateEvent $event) { log_info('RelatedProduct trigger onRenderAdminProduct start'); $app = $this->app; $parameters = $event->getParameters(); $Product = $parameters['Product']; $RelatedProducts = $this->createRelatedProductData($Product); // twigコードを挿入 $snipet = $app['twig']->getLoader()->getSource('RelatedProduct/Resource/template/admin/related_product.twig'); $modal = $app['twig']->getLoader()->getSource('RelatedProduct/Resource/template/admin/modal.twig'); //add related product to product edit $search = '<div id="detail_box__footer" class="row hidden-xs hidden-sm">'; $source = $event->getSource(); $replace = $snipet . $search; $source = str_replace($search, $replace, $source); $event->setSource($source . $modal); //set parameter for twig files $parameters['RelatedProducts'] = $RelatedProducts; $event->setParameters($parameters); log_info('RelatedProduct trigger onRenderAdminProduct finish'); }