app/Plugin/SEOAllOne42/Event.php line 1426

Open in your IDE?
  1. <?php
  2. namespace Plugin\SEOAllOne42;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Psr\Container\ContainerInterface;
  5. use Symfony\Component\Form\FormEvents;
  6. use Symfony\Component\Form\FormEvent;
  7. use Symfony\Component\Form\FormError;
  8. use Eccube\Common\EccubeConfig;
  9. use Eccube\Event\TemplateEvent;
  10. use Eccube\Event\EventArgs;
  11. use Eccube\Repository\PageRepository;
  12. use Eccube\Entity\Product;
  13. use Eccube\Entity\Category;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  16. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  17. use Plugin\SEOAllOne42\Entity\SEOAllOneDefault;
  18. use Plugin\SEOAllOne42\Entity\SEOAllOneProduct;
  19. use Plugin\SEOAllOne42\Entity\SEOAllOneCategory;
  20. use Plugin\SEOAllOne42\Entity\Config;
  21. use Plugin\SEOAllOne42\Repository\SEOAllOneDefaultRepository;
  22. use Plugin\SEOAllOne42\Repository\SEOAllOneProductRepository;
  23. use Plugin\SEOAllOne42\Repository\SEOAllOneCategoryRepository;
  24. use Plugin\SEOAllOne42\Repository\ConfigRepository;
  25. use Plugin\SEOAllOne42\Form\Type\Admin\SEOAllOneCategoryType;
  26. use Plugin\SEOAllOne42\Util\Util;
  27. use Symfony\Component\Validator\Constraints\NotBlank;
  28. use Symfony\Component\Validator\Constraints as Assert;
  29. use Twig\Environment;
  30. class Event implements EventSubscriberInterface
  31. {
  32.     const CONTENT_FOOTER_TAG  '<!-- レイアウト設定 -->';
  33.     const PRODUCT_NAME "##product.name##";
  34.     const PRODUCT_NAME_PATTERN "/##(((?!#).)*)(product.name)(((?!#).)*)##/u";
  35.     const PRODUCT_PRICE01 "##product.list_price##";
  36.     const PRODUCT_PRICE01_PATTERN "/##(((?!#).)*)(product\.list_price)(((?!#).)*)##/u";
  37.     const PRODUCT_PRICE02 "##product.sell_price##";
  38.     const PRODUCT_PRICE02_PATTERN "/##(((?!#).)*)(product.sell_price)(((?!#).)*)##/u";
  39.     const PRODUCT_CATEGORY "##product.category##";
  40.     const PRODUCT_CATEGORY_PATTERN "/##(((?!#).)*)(product\\.category)(((?!#).)*)##/u";
  41.     const CATEGORY_NAME "##category.name##";
  42.     const CATEGORY_PARENTNAME "##category.parentname##";
  43.     const CATEGORY_PARENTNAME_WITH_PARENTHESES "##(category.parentname)##";
  44.     const CATEGORY_NAME_PATTERN "/##(((?!#).)*)(category\.name)(((?!#).)*)##/u";
  45.     const CATEGORY_PARENTNAME_PATTERN "/##(((?!#).)*)(category\.parentname)(((?!#).)*)##/u";
  46.     
  47.     public function __construct(
  48.         //ContainerInterface $container,
  49.         EccubeConfig    $eccubeConfig,
  50.         SEOAllOneDefaultRepository $seoAllOneDefaultRepository,
  51.         SEOAllOneProductRepository $seoAllOneProductRepository,
  52.         SEOAllOneCategoryRepository $seoAllOneCategoryRepository,
  53.         PageRepository $pageRepository,
  54.         ConfigRepository $configRepository,
  55.         Environment $twig
  56.     )
  57.     {
  58.         global $kernel;
  59.         $this->container $kernel->getContainer();
  60.         $this->eccubeConfig $eccubeConfig;
  61.         $this->seoAllOneDefaultRepository $seoAllOneDefaultRepository;
  62.         $this->seoAllOneProductRepository $seoAllOneProductRepository;
  63.         $this->seoAllOneCategoryRepository $seoAllOneCategoryRepository;
  64.         $this->pageRepository $pageRepository;
  65.         $this->configRepository $configRepository;
  66.         $this->product_detail_help_text '※上記title、description、keywordではプレースホルダーが使用可能です。使用可能なプレースホルダーは 'self::PRODUCT_NAME.'(商品名),'self::PRODUCT_PRICE01 .'(定価), ' self::PRODUCT_PRICE02 '(販売価格), ' self::CATEGORY_NAME .'(カテゴリ名)、' .self::CATEGORY_PARENTNAME .'(親カテゴリ名)です。このうち、定価とカテゴリ名と親カテゴリ名に関しては、データが存在しない場合、##で囲った中に書いたものは全て空白になります。例えば 'self::CATEGORY_PARENTNAME_WITH_PARENTHESES .' と記載すると、親カテゴリ名が存在しないとき##内の()も併せて空白になります。';
  67.         $this->product_detail_help_text_og '※上記og:title、og:descriptionではプレースホルダーが使用可能です。使用可能なプレースホルダーは 'self::PRODUCT_NAME.'(商品名),'self::PRODUCT_PRICE01 .'(定価), ' self::PRODUCT_PRICE02 '(販売価格), ' self::CATEGORY_NAME .'(カテゴリ名)、' .self::CATEGORY_PARENTNAME .'(親カテゴリ名)です。このうち、定価とカテゴリ名と親カテゴリ名に関しては、データが存在しない場合、##で囲った中に書いたものは全て空白になります。例えば 'self::CATEGORY_PARENTNAME_WITH_PARENTHESES .' と記載すると、親カテゴリ名が存在しないとき##内の()も併せて空白になります。';
  68.         $this->product_category_help_text '※上記title、description、keywordではプレースホルダーが使用可能です。使用可能なプレースホルダーは 'self::CATEGORY_NAME.'(カテゴリ名),'self::CATEGORY_PARENTNAME .'(親カテゴリ名), です。このうち、親カテゴリ名に関しては、データが存在しない場合、##で囲った中に書いたものは全て空白になります。例えば 'self::CATEGORY_PARENTNAME_WITH_PARENTHESES .' と記載すると、親カテゴリ名が存在しないとき##内の()も併せて空白になります。';
  69.         $this->product_category_help_text_og '※上記og:title、og:descriptionではプレースホルダーが使用可能です。使用可能なプレースホルダーは 'self::CATEGORY_NAME.'(カテゴリ名),'self::CATEGORY_PARENTNAME .'(親カテゴリ名), です。このうち、親カテゴリ名に関しては、データが存在しない場合、##で囲った中に書いたものは全て空白になります。例えば 'self::CATEGORY_PARENTNAME_WITH_PARENTHESES .' と記載すると、親カテゴリ名が存在しないとき##内の()も併せて空白になります。';
  70.         $this->ogp_tooltips '空白の場合は自動的に最適化表示されます';
  71.         $router $kernel->getContainer()->get('router');
  72.         $this->util = new Util($router$twig);
  73.         
  74.         $this->twig $twig;
  75.     }
  76.     /**
  77.      * @return array
  78.      */
  79.     public static function getSubscribedEvents()
  80.     {
  81.         return [
  82.             'admin.content.page.edit.initialize' => 'onAdminContentPageEditInitialize',
  83.             '@admin/Content/page_edit.twig'  => 'onAdminContentTwig',
  84.             'admin.content.page.edit.complete'  => 'onAdminContentPageEditComplete',
  85.             'admin.content.page.delete.complete'    => 'onAdminContentPageDeleteComplete',
  86.             'front.product.detail.initialize'   => 'onFrontProductDetailInitalize',
  87.             'Product/list.twig' => 'onProductListTwig',
  88.             'admin.product.edit.initialize' => 'onAdminProductEditInitialize',
  89.             '@admin/Product/product.twig'   => 'onAdminProductTwig',
  90.             'admin.product.edit.complete'   => 'onAdminProductEditComplete',
  91.             'admin.product.delete.complete' => 'onAdminProductDeleteComplete',
  92.             'admin.product.category.index.complete'     => 'onAdminProductCategoryIndexComplete',
  93.             'admin.product.category.delete.complete'    => 'onAdminProductCategoryDeleteComplete',
  94.             '@admin/Product/category.twig'  => 'onAdminProductCategoryTwig',
  95.             'index.twig'    => 'onIndexTwig',
  96.             'Product/detail.twig' => 'onFrontProductDetailTwig',
  97.             'front.product.index.search' => 'onFrontProductIndexInitialize',
  98.             '@admin/Store/plugin.twig' => 'onAdminStorePluginIndexTwig'
  99.         ];
  100.     }
  101.     public function onAdminContentPageEditInitialize(EventArgs $event)
  102.     {
  103.         $Config $this->configRepository->findOneBy([]);
  104.         $Page $event->getArgument('Page');
  105.         if ($Page->getUrl() != 'homepage' && $Page->getUrl() != 'product_detail' && $Page->getUrl() != 'product_list')
  106.         {
  107.             return;
  108.         }
  109.         $seo_data $this->seoAllOneDefaultRepository->findOneby(array('Page' => $Page));
  110.         if (!$seo_data || !$seo_data->getOGType()) {
  111.             $seo_data = new SEOAllOneDefault();
  112.             if ($Page->getUrl() == 'homepage')
  113.             {
  114.                 $seo_data->setOGType('website');
  115.             }
  116.             elseif ($Page->getUrl() == 'product_detail')
  117.             {
  118.                 $seo_data->setOGType('product');
  119.             }
  120.             else
  121.             {
  122.                 $seo_data->setOGType('article');
  123.             }
  124.         }
  125.         if($Page->getUrl() == 'product_detail' || $Page->getUrl() == 'product_list') {
  126.             $seoallone_title_opt = array(
  127.                 'required'  => false,
  128.                 'label' => 'Title',
  129.                 'mapped'    => false,
  130.                 'data'  => $seo_data->getTitle()
  131.             );
  132.     
  133.             $seoallone_description_opt = array(
  134.                 'required'  => false,
  135.                 'label' => 'Description',
  136.                 'mapped'    => false,
  137.                 'data'  => $seo_data->getDescription()
  138.             );
  139.     
  140.             $seoallone_keyword_opt = array(
  141.                 'required'  => false,
  142.                 'label' => 'Keyword',
  143.                 'mapped'    => false,
  144.                 'data'  => $seo_data->getKeyword()
  145.             );
  146.     
  147.             $seoallone_author_opt = array(
  148.                 'required'  => false,
  149.                 'label' => 'Author',
  150.                 'mapped'    => false,
  151.                 'data'  => $seo_data->getAuthor()
  152.             );
  153.     
  154.             $seoallone_canonical_opt = array(
  155.                 'required'  => false,
  156.                 'label' => 'Canonical',
  157.                 'mapped'    => false,
  158.                 'data'  => $seo_data->getCanonical()
  159.             );
  160.         }
  161.         $seoallone_ogp_title_opt = array(
  162.             'required'  => false,
  163.             'label' => 'og:title',
  164.             'mapped'    => false,
  165.             'data'  => $seo_data->getOGTitle()
  166.         );
  167.         $seoallone_ogp_description_opt = array(
  168.             'required'  => false,
  169.             'label' => 'og:description',
  170.             'mapped'    => false,
  171.             'data'  => $seo_data->getOGDescription()
  172.         );
  173.         $seoallone_ogp_url_opt = array(
  174.             'required'  => false,
  175.             'label' => 'og:url',
  176.             'mapped'    => false,
  177.             'data'  => $seo_data->getOGUrl()
  178.         );
  179.         $seoallone_ogp_type_opt = array(
  180.             'required'  => false,
  181.             'label' => 'og:type',
  182.             'mapped'    => false,
  183.             'data'  => $seo_data->getOGType(),
  184.             'choices'   => [
  185.                 // ''          => '',
  186.                 'website'   => 'website',
  187.                 'product'   => 'product',
  188.                 'article'   => 'article',
  189.                 'blog'      => 'blog'
  190.             ],
  191.             'placeholder' => false
  192.         );
  193.         if ($Page->getUrl() == 'product_detail')
  194.         {
  195.             $seoallone_keyword_opt['help'] = $this->product_detail_help_text;
  196.             $seoallone_ogp_description_opt['help'] = $this->product_detail_help_text_og;
  197.         }
  198.         if ($Page->getUrl() == 'product_list')
  199.         {
  200.             $seoallone_keyword_opt['help'] = $this->product_category_help_text;
  201.             $seoallone_ogp_description_opt['help'] = $this->product_category_help_text_og;
  202.         }
  203.         $builder $event->getArgument('builder');
  204.         $builder
  205.         ->add('seoallone_ogp_title'TextType::class, $seoallone_ogp_title_opt)
  206.         ->add('seoallone_ogp_description'TextType::class, $seoallone_ogp_description_opt)
  207.         ->add('seoallone_ogp_url'TextType::class, $seoallone_ogp_url_opt)
  208.         ->add('seoallone_ogp_type'ChoiceType::class, $seoallone_ogp_type_opt);
  209.         if($Page->getUrl() == 'product_detail' || $Page->getUrl() == 'product_list') {
  210.             $builder
  211.             ->add('seoallone_title'TextType::class, $seoallone_title_opt)
  212.             ->add('seoallone_author'TextType::class, $seoallone_author_opt)
  213.             ->add('seoallone_description'TextType::class, $seoallone_description_opt)
  214.             ->add('seoallone_keyword'TextType::class, $seoallone_keyword_opt)
  215.             ->add('seoallone_canonical'TextType::class, $seoallone_canonical_opt);
  216.         }
  217.     }
  218.     public function onAdminContentTwig(TemplateEvent $event)
  219.     {
  220.         $Config $this->configRepository->findOneBy([]);
  221.         $parameters $event->getParameters();
  222.         $page_id $parameters['page_id'];
  223.         if ($page_id != && $page_id != && $page_id != 3)
  224.         {
  225.             return;
  226.         }
  227.         $source $event->getSource();
  228.         $snippet_seo $this->twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/admin/seoallone_default_form.twig');
  229.         if (strpos($sourceself::CONTENT_FOOTER_TAG)) {
  230.             $search_tag self::CONTENT_FOOTER_TAG;
  231.             $replace_layout $snippet_seo->getCode().$search_tag;
  232.             $source str_replace($search_tag$replace_layout$source);
  233.             $event->setSource($source);
  234.         }
  235.     }
  236.     public function onAdminContentPageEditComplete(EventArgs $event)
  237.     {
  238.         $Config $this->configRepository->findOneBy([]);
  239.         if ($Config->getSitemapFlg() == 1)
  240.         {
  241.             $this->util->generateSitemap($this->eccubeConfig);
  242.         }
  243.         $form $event->getArgument('form');
  244.         $Page $event->getArgument('Page');
  245.         if ($Page->getUrl() != 'homepage' && $Page->getUrl() != 'product_detail' && $Page->getUrl() != 'product_list')
  246.         {
  247.             return;
  248.         }
  249.         $em $this->container->get('doctrine.orm.entity_manager');
  250.         $seoallone_default $this->seoAllOneDefaultRepository->findOneby(array('Page' => $Page));
  251.         if (!$seoallone_default) {
  252.             $seoallone_default = new SEOAllOneDefault();
  253.         }
  254.         else
  255.         {
  256.             $seoallone_default->setUpdateDate(new \DateTime());
  257.         }
  258.         if ($Page->getUrl() == 'product_detail' || $Page->getUrl() == 'product_list')
  259.         {
  260.             $seo_title          $form['seoallone_title']->getData();
  261.             $seo_author         $form['seoallone_author']->getData();
  262.             $seo_description    $form['seoallone_description']->getData();
  263.             $seo_keyword        $form['seoallone_keyword']->getData();
  264.             $seo_canonical      $form['seoallone_canonical']->getData();
  265.         }
  266.         $ogp_title         $form['seoallone_ogp_title']->getData();
  267.         $ogp_description    $form['seoallone_ogp_description']->getData();
  268.         $ogp_url        $form['seoallone_ogp_url']->getData();
  269.         $ogp_type      $form['seoallone_ogp_type']->getData();
  270.         
  271.         if ($Page->getUrl() == 'product_detail' || $Page->getUrl() == 'product_list')
  272.         {
  273.             $seoallone_default->setTitle($seo_title);
  274.             $seoallone_default->setAuthor($seo_author);
  275.             $seoallone_default->setDescription($seo_description);
  276.             $seoallone_default->setKeyword($seo_keyword);
  277.             $seoallone_default->setCanonical($seo_canonical);
  278.         }
  279.         $seoallone_default->setOGTitle($ogp_title);
  280.         $seoallone_default->setOGDescription($ogp_description);
  281.         $seoallone_default->setOGUrl($ogp_url);
  282.         $seoallone_default->setOGType($ogp_type);
  283.         $seoallone_default->setPage($Page);
  284.         $seoallone_default->setDelFlg(0);
  285.         $em->persist($seoallone_default);
  286.         $em->flush($seoallone_default);
  287.     }
  288.     /**
  289.      * @param EventArgs $event
  290.      * @return mixed
  291.      * @throws Exception\RedirectException
  292.      */
  293.     public function onFrontProductDetailInitalize(EventArgs $event)
  294.     {
  295.         $PageProductDetail $this->pageRepository->findOneBy(array('url' => 'product_detail'));
  296.         $Config $this->configRepository->findOneBy([]);
  297.         if (!$PageProductDetail)
  298.         {
  299.             return;
  300.         }
  301.         $Product $event->getArgument('Product');
  302.         $json_category = array();
  303.         foreach ($Product['ProductCategories'] as $key1 => $ProductCategory) {
  304.             $category_str '';
  305.             foreach ($ProductCategory['Category']['path'] as $key2 => $Category) {
  306.                 $category_str .= $Category['name'] . "/";
  307.             }
  308.             $json_category[] = trim($category_str'/');
  309.         }
  310.         $Product->json_category $json_category;
  311.         
  312.         $default_seo_parameter $this->seoAllOneDefaultRepository->findOneby(array('Page' => $PageProductDetail));
  313.         $individual_seo_parameter $this->seoAllOneProductRepository->findOneBy(array('Product' => $Product));
  314.         if (!$default_seo_parameter && !$individual_seo_parameter)
  315.         {
  316.             return;
  317.         }
  318.         $Product->seo_title null;
  319.         $Product->seo_another null;
  320.         $Product->seo_description null;
  321.         $Product->seo_keywords null;
  322.         $Product->seo_canonical null;
  323.         $Product->og_title null;
  324.         $Product->og_description null;
  325.         $Product->og_site_name null;
  326.         $Product->og_type null;
  327.         $Product->og_url null;
  328.         $Product->og_image null;
  329.         $Product->noindex_flg null;
  330.         $Product->og_image_metatag true;
  331.         $Product->global_id null;
  332.         $Product->global_id_type null;    
  333.         $Product->valid_price_until null;        
  334.         $Config $this->configRepository->findOneBy([]);
  335.         if ($default_seo_parameter)
  336.         {
  337.             $Product->seo_title $default_seo_parameter->getTitle();
  338.             $Product->seo_another $default_seo_parameter->getAuthor();
  339.             $Product->seo_description $default_seo_parameter->getDescription();
  340.             $Product->seo_keywords $default_seo_parameter->getKeyword();
  341.             $Product->seo_canonical $default_seo_parameter->getCanonical();
  342.             $Product->og_title   $default_seo_parameter->getOGTitle();
  343.             $Product->og_description  $default_seo_parameter->getOGDescription();
  344.             $Product->og_type  $default_seo_parameter->getOGType();
  345.             $Product->og_url  $default_seo_parameter->getOGUrl();
  346.             $Product->og_image  $default_seo_parameter->getOGImage();
  347.         }
  348.         
  349.         if ($Config->getGlobalIdFlg()) {
  350.             $Product->global_id_type $Config->getValidPriceFlg();
  351.         }
  352.         
  353.         if ($Config->getValidPriceFlg() && $Config->getValidPriceMonth()) {
  354.             $valid_price_month = (int)$Config->getValidPriceMonth();
  355.             $Product->valid_price_until date('Y-m-d'strtotime("+{$valid_price_month} months"strtotime(date('Y-m-d'))));
  356.         } 
  357.         
  358.         if ($individual_seo_parameter)
  359.         {
  360.             if ($individual_seo_parameter->getRedirectUrl() != '')
  361.             {
  362.                 $response $individual_seo_parameter->getRedirectUrl();
  363.                 // redirect using exception
  364.                 throw new Exception\RedirectException(
  365.                     new \Symfony\Component\HttpFoundation\RedirectResponse(
  366.                         $response301
  367.                     ),
  368.                     '',
  369.                     301
  370.                 );
  371.             }
  372.             if ($individual_seo_parameter->getNoindexFlg()) {
  373.                 $Product->noindex_flg $individual_seo_parameter->getNoindexFlg();
  374.             }
  375.             if ($individual_seo_parameter->getTitle()) {
  376.                 $Product->seo_title $individual_seo_parameter->getTitle();
  377.             } 
  378.             if ($individual_seo_parameter->getAuthor()) {
  379.                 $Product->seo_another $individual_seo_parameter->getAuthor();
  380.             } 
  381.             if ($individual_seo_parameter->getDescription()) {
  382.                 $Product->seo_description $individual_seo_parameter->getDescription();
  383.             } 
  384.             if ($individual_seo_parameter->getKeyword()) {
  385.                 $Product->seo_keywords $individual_seo_parameter->getKeyword();
  386.             } 
  387.             if ($individual_seo_parameter->getCanonical()) {
  388.                 $Product->seo_canonical $individual_seo_parameter->getCanonical();
  389.             }
  390.             else
  391.             {
  392.                 $Product->seo_canonical $this->container->get('router')->generate('product_detail', ['id' => $Product->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  393.             } 
  394.             if ($individual_seo_parameter->getOGTitle()) {
  395.                 $Product->og_title $individual_seo_parameter->getOGTitle();
  396.             } else if($individual_seo_parameter->getTitle()) {
  397.                 $Product->og_title $individual_seo_parameter->getTitle();
  398.             }
  399.             if ($individual_seo_parameter->getOGDescription()) {
  400.                 $Product->og_description $individual_seo_parameter->getOGDescription();
  401.             } else if($individual_seo_parameter->getDescription()) {
  402.                 $Product->og_description $individual_seo_parameter->getDescription();
  403.             }
  404.             if ($individual_seo_parameter->getOGSiteName()) {
  405.                 $Product->og_site_name $individual_seo_parameter->getOGSiteName();
  406.             } 
  407.             if ($individual_seo_parameter->getOGType()) {
  408.                 $Product->og_type $individual_seo_parameter->getOGType();
  409.             } 
  410.             if ($individual_seo_parameter->getOGUrl()) {
  411.                 $Product->og_url $individual_seo_parameter->getOGUrl();
  412.             } 
  413.             if ($individual_seo_parameter->getOGImage()) {
  414.                 $Product->og_image $individual_seo_parameter->getOGImage();
  415.             } 
  416.             if ($Config->getGlobalIdFlg()) {
  417.                 $global_id_type '';
  418.                 if ($individual_seo_parameter->getUpdatedFlg()) {
  419.                     $global_id_type $individual_seo_parameter->getGlobalIdType();
  420.                     if (!$individual_seo_parameter->getGlobalId()){
  421.                         $Product->global_id $Product->getCodeMin();
  422.                     } else {
  423.                         $Product->global_id $individual_seo_parameter->getGlobalId();
  424.                     }
  425.                 } else {
  426.                     $global_id_type $Config->getGlobalIdType();
  427.                     $Product->global_id $Product->getCodeMin();
  428.                 }
  429.                 
  430.                 if ($global_id_type == 1) {
  431.                     $Product->global_id_type 'gtin';
  432.                 } elseif ($global_id_type == 1) {
  433.                     $Product->global_id_type 'gtin';
  434.                 } elseif ($global_id_type == 2) {
  435.                     $Product->global_id_type 'gtin8';
  436.                 } elseif ($global_id_type == 3) {
  437.                     $Product->global_id_type 'gtin13';
  438.                 } elseif ($global_id_type == 4) {
  439.                     $Product->global_id_type 'gtin14';
  440.                 }                 
  441.             } 
  442.             
  443.             if ($Config->getValidPriceFlg()) {
  444.                 $valid_price_month $individual_seo_parameter->getValidPriceMonth();
  445.                 if ($valid_price_month) {
  446.                     $Product->valid_price_until date('Y-m-d'strtotime("+{$valid_price_month} months"strtotime(date('Y-m-d'))));
  447.                 }
  448.             } 
  449.         } else {
  450.             if ($Config->getGlobalIdFlg()) {
  451.                 $global_id_type $Config->getGlobalIdType();
  452.                 if ($global_id_type == 1) {
  453.                     $Product->global_id_type 'gtin';
  454.                 } elseif ($global_id_type == 1) {
  455.                     $Product->global_id_type 'gtin';
  456.                 } elseif ($global_id_type == 2) {
  457.                     $Product->global_id_type 'gtin8';
  458.                 } elseif ($global_id_type == 3) {
  459.                     $Product->global_id_type 'gtin13';
  460.                 } elseif ($global_id_type == 4) {
  461.                     $Product->global_id_type 'gtin14';
  462.                 } 
  463.                 $Product->global_id $Product->getCodeMin();
  464.             }
  465.         }
  466.         $Product $this->readyPlaceholderProduct($Product);
  467.         $meta_tags $PageProductDetail->getMetaTags();
  468.         if ($meta_tags) {
  469.             $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:title"[^>]+(\/)?>/m'''$meta_tags);
  470.             if ($Product->og_description || $Product->seo_description || $PageProductDetail->getDescription()) {
  471.                 $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:description"[^>]+(\/)?>/m'''$meta_tags);
  472.             }
  473.             $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:url"[^>]+(\/)?>/m'''$meta_tags);
  474.             if($Product->og_image || $Product->getMainListImage()) {
  475.                 $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:image"[^>]+(\/)?>/m'''$meta_tags);
  476.                 $Product->og_image_metatag false;
  477.             } 
  478.             if( $Product->og_image_metatag == true && !preg_match('/(<(\s)*)meta(\s)*(name|property)="og:image"[^>]+(\/)?>/m'$meta_tags$matches)) {
  479.                 $Product->og_image_metatag false;
  480.             }
  481.             
  482.             $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:type"[^>]+(\/)?>/m'''$meta_tags);
  483.             $meta_tags str_replace("\r\n\r\n"""$meta_tags);
  484.             $meta_tags str_replace("\n\r\n\r"""$meta_tags);
  485.         } else {
  486.             $Product->og_image_metatag false;
  487.         }
  488.         $PageProductDetail->setMetaTags($meta_tags);
  489.         
  490.     }
  491.     
  492.     public function onProductListTwig(TemplateEvent $event)
  493.     {
  494.         $requestStack $this->container->get('request_stack');
  495.         $request $requestStack->getMainRequest();
  496.         $parameters $event->getParameters();
  497.         $strApiJsonParame "";
  498.         if ($request->getMethod() === 'GET') {
  499.             $all $request->query->all();
  500.             if (array_key_exists('pageno'$all) && $all['pageno'] == 0) {
  501.                 $all['pageno'] = 1;
  502.             }
  503.             $strApiJsonParame "?" http_build_query($all);
  504.         }
  505.         $event->setParameter('strApiJsonParame'$strApiJsonParame);
  506.         $parameters['strApiJsonParame'] = $strApiJsonParame;
  507.         $this->readyPagination($parameters);
  508.         $Config $this->configRepository->findOneBy([]);
  509.         $parameters['SEOAllOneConfig'] = $Config;
  510.         $event->setParameter('SEOAllOneConfig'$Config);
  511.         // if ($Config->getRichSnippetFlg() == 1)
  512.         // {
  513.         //     $json_breadcrumb_twig = '@SEOAllOne42/json-ld-breadcrumb.twig';
  514.         //     $event->addSnippet($json_breadcrumb_twig);
  515.         // }
  516.         if (!isset($parameters['Category']) || $parameters['Category'] == NULL)
  517.         {
  518.             $seo_title = !empty($parameters['title'])? $parameters['title'] : '';
  519.             $seo_subtitle = !empty($parameters['subtitle'])? $parameters['subtitle'] : '';
  520.             $seo_link_prev = !empty($parameters['seo_link_prev'])? $parameters['seo_link_prev'] : '';
  521.             $seo_link_next = !empty($parameters['seo_link_next'])? $parameters['seo_link_next'] : '';
  522.             $request->attributes->set('seo_title'$seo_title);
  523.             $request->attributes->set('seo_subtitle'$seo_subtitle);
  524.             $request->attributes->set('seo_link_prev'$seo_link_prev);
  525.             $request->attributes->set('seo_link_next'$seo_link_next);
  526.             
  527.             // Fix bug canonical in product_list page
  528.             $parameters['Category'] = New Category();
  529.             // return;
  530.         }
  531.         $PageProductCategory $this->pageRepository->findOneBy(array('url' => 'product_list'));
  532.         if (!$PageProductCategory)
  533.         {
  534.             return;
  535.         }
  536.         if(is_null($Config)) {
  537.             return;
  538.         }
  539.         $Category $parameters['Category'];
  540.         $default_seo_parameter $this->seoAllOneDefaultRepository->findOneby(array('Page' => $PageProductCategory));
  541.         $individual_seo_parameter $this->seoAllOneCategoryRepository->findOneBy(array('Category' => $Category));
  542.         if (!$default_seo_parameter && !$individual_seo_parameter)
  543.         {
  544.             return;
  545.         }
  546.         $Category->seo_title null;
  547.         $Category->seo_another null;
  548.         $Category->seo_description null;
  549.         $Category->seo_keywords null;
  550.         $Category->seo_canonical null;
  551.         $Category->og_title null;
  552.         $Category->og_description null;
  553.         $Category->og_site_name null;
  554.         $Category->og_type null;
  555.         $Category->og_url null;
  556.         $Category->og_image null;
  557.         $Category->og_image_metatag true;
  558.         if ($default_seo_parameter)
  559.         {
  560.             $Category->seo_title $default_seo_parameter->getTitle();
  561.             $Category->seo_another $default_seo_parameter->getAuthor();
  562.             $Category->seo_description $default_seo_parameter->getDescription();
  563.             $Category->seo_keywords $default_seo_parameter->getKeyword();
  564.             $Category->seo_canonical $default_seo_parameter->getCanonical();
  565.             $Category->og_title   $default_seo_parameter->getOGTitle();
  566.             $Category->og_description  $default_seo_parameter->getOGDescription();
  567.             $Category->og_site_name  $default_seo_parameter->getOGSiteName();
  568.             $Category->og_type  $default_seo_parameter->getOGType();
  569.             $Category->og_url  $default_seo_parameter->getOGUrl();
  570.             $Category->og_image  $default_seo_parameter->getOGImage();
  571.         }
  572.         
  573.         if ($individual_seo_parameter)
  574.         {
  575.             if ($individual_seo_parameter->getTitle()) {
  576.                 $Category->seo_title $individual_seo_parameter->getTitle();
  577.             } 
  578.             if ($individual_seo_parameter->getAuthor()) {
  579.                 $Category->seo_another $individual_seo_parameter->getAuthor();
  580.             } 
  581.             if ($individual_seo_parameter->getDescription()) {
  582.                 $Category->seo_description $individual_seo_parameter->getDescription();
  583.             } 
  584.             if ($individual_seo_parameter->getKeyword()) {
  585.                 $Category->seo_keywords $individual_seo_parameter->getKeyword();
  586.             } 
  587.             if ($individual_seo_parameter->getCanonical()) {
  588.                 $Category->seo_canonical $individual_seo_parameter->getCanonical();
  589.             } else{
  590.                 $Category->seo_canonical $this->container->get('router')->generate('product_list', ['category_id' => $Category->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  591.             }
  592.             if($all['pageno'] > 1) {
  593.                 $Category->seo_canonical .= "&pageno=".$all['pageno'];
  594.             }
  595.             if ($individual_seo_parameter->getOGTitle()) {
  596.                 $Category->og_title $individual_seo_parameter->getOGTitle();
  597.             } else if ($individual_seo_parameter->getTitle()) {
  598.                 $Category->og_title $individual_seo_parameter->getTitle();
  599.             }
  600.             if ($individual_seo_parameter->getOGDescription()) {
  601.                 $Category->og_description $individual_seo_parameter->getOGDescription();
  602.             } else if ($individual_seo_parameter->getDescription()) {
  603.                 $Category->og_description $individual_seo_parameter->getDescription();
  604.             }
  605.             if ($individual_seo_parameter->getOGSiteName()) {
  606.                 $Category->og_site_name $individual_seo_parameter->getOGSiteName();
  607.             } 
  608.             if ($individual_seo_parameter->getOGType()) {
  609.                 $Category->og_type $individual_seo_parameter->getOGType();
  610.             } 
  611.             if ($individual_seo_parameter->getOGUrl()) {
  612.                 $Category->og_url $individual_seo_parameter->getOGUrl();
  613.             } 
  614.             if ($individual_seo_parameter->getOGImage()) {
  615.                 $Category->og_image $individual_seo_parameter->getOGImage();
  616.             } 
  617.         }
  618.         
  619.         // title, description for all product list page
  620.         if (!$Category->getId()) {
  621.             $Category->seo_title 'すべての商品一覧';
  622.             $Category->seo_description 'すべての商品一覧ページです。';
  623.         }
  624.         
  625.         $Category $this->readyPlaceholderCategory($Category);
  626.         
  627.         $meta_tags $PageProductCategory->getMetaTags();
  628.         if ($meta_tags) {
  629.             $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:title"[^>]+(\/)?>/m'''$meta_tags);
  630.             if ($Category->og_description || $Category->seo_description || $PageProductCategory->getDescription()) {
  631.                 $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:description"[^>]+(\/)?>/m'''$meta_tags);
  632.             }
  633.             $paginationData $parameters['pagination']->getPaginationData();
  634.             if ($Category->og_image) {
  635.                 $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:image"[^>]+(\/)?>/m'''$meta_tags);
  636.                 $Category->og_image_metatag false;
  637.             } else if ($paginationData['totalCount'] >= 1) {
  638.                 foreach($parameters['pagination'] as $Product) {
  639.                     if($Product->getMainListImage()) {
  640.                         $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:image"[^>]+(\/)?>/m'''$meta_tags);
  641.                         $Category->og_image_metatag false;
  642.                         break;
  643.                     }
  644.                 }
  645.             } 
  646.             
  647.             if($Category->og_image_metatag == true && !preg_match('/(<(\s)*)meta(\s)*(name|property)="og:image"[^>]+(\/)?>/m'$meta_tags$matches)) {
  648.                 $Category->og_image_metatag false;
  649.             }
  650.             
  651.             $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:url"[^>]+(\/)?>/m'''$meta_tags);
  652.             $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:type"[^>]+(\/)?>/m'''$meta_tags);
  653.             $meta_tags str_replace("\r\n\r\n"""$meta_tags);
  654.             $meta_tags str_replace("\n\r\n\r"""$meta_tags);
  655.         } else {
  656.             $Category->og_image_metatag false;
  657.         }
  658.         $event->setParameters($parameters);
  659.         $PageProductCategory->setMetaTags($meta_tags);
  660.         
  661.         $request->attributes->set('seo_Category'$Category);
  662.         $seo_title = !empty($parameters['title'])? $parameters['title'] : '';
  663.         $seo_subtitle = !empty($parameters['subtitle'])? $parameters['subtitle'] : '';
  664.         $seo_link_prev = !empty($parameters['seo_link_prev'])? $parameters['seo_link_prev'] : '';
  665.         $seo_link_next = !empty($parameters['seo_link_next'])? $parameters['seo_link_next'] : '';
  666.         $request->attributes->set('seo_title'$seo_title);
  667.         $request->attributes->set('seo_subtitle'$seo_subtitle);
  668.         $request->attributes->set('seo_link_prev'$seo_link_prev);
  669.         $request->attributes->set('seo_link_next'$seo_link_next);
  670.         
  671.     }
  672.     public function onAdminProductEditInitialize(EventArgs $event)
  673.     {
  674.         $Config $this->configRepository->findOneBy([]);
  675.         $Product $event->getArgument('Product');
  676.         $seo_parameter $this->seoAllOneProductRepository->findOneby(array('Product' => $Product));
  677.         if (!$seo_parameter) {
  678.             $seo_parameter = new SEOAllOneProduct();
  679.         }
  680.         
  681.         if(!$seo_parameter->getOGType()) {
  682.             $seo_parameter->setOGType('product');
  683.         }
  684.         $builder $event->getArgument('builder');
  685.         $builder->add(
  686.             'seoallone_title',
  687.             TextType::class,
  688.             array(
  689.                 'required' => false,
  690.                 'label'    => '(SEO All One) Title',
  691.                 'mapped'   => false,
  692.                 'data'     => $seo_parameter->getTitle(),
  693.                 'eccube_form_options'  => array(
  694.                     'auto_render'   => true
  695.                 ),
  696.                 'help'      => ''
  697.             )
  698.         );
  699.         $builder->add(
  700.             'seoallone_description',
  701.             TextType::class,
  702.             array(
  703.                 'required' => false,
  704.                 'label'    => '(SEO All One) Description',
  705.                 'mapped'   => false,
  706.                 'data'     => $seo_parameter->getDescription(),
  707.                 'eccube_form_options'  => array(
  708.                     'auto_render'   => true
  709.                 ),
  710.                 'help'      => ''
  711.             )
  712.         );
  713.         $builder->add(
  714.             'seoallone_keyword',
  715.             TextType::class,
  716.             array(
  717.                 'required' => false,
  718.                 'label'    => '(SEO All One) Keyword',
  719.                 'mapped'   => false,
  720.                 'data'     => $seo_parameter->getKeyword(),
  721.                 'eccube_form_options'  => array(
  722.                     'auto_render'   => true
  723.                 ),
  724.                 'help'      => $this->product_detail_help_text,
  725.             )
  726.         );
  727.         $builder->add(
  728.             'seoallone_author',
  729.             TextType::class,
  730.             array(
  731.                 'required' => false,
  732.                 'label'    => '(SEO All One) Author',
  733.                 'mapped'   => false,
  734.                 'data'     => $seo_parameter->getAuthor(),
  735.                 'eccube_form_options'  => array(
  736.                     'auto_render'   => true
  737.                 )
  738.             )
  739.         );
  740.         $builder->add(
  741.             'seoallone_canonical',
  742.             TextType::class,
  743.             array(
  744.                 'required' => false,
  745.                 'label'    => '(SEO All One) Canonical',
  746.                 'mapped'   => false,
  747.                 'data'     => $seo_parameter->getCanonical(),
  748.                 'eccube_form_options'  => array(
  749.                     'auto_render'   => true
  750.                 ),
  751.                 'help'  => '※空欄の場合は現在のURLがそのままcanonicalに表示されます。'
  752.             )
  753.         );
  754.         //ogp
  755.         $builder->add(
  756.             'seoallone_ogp_site_name',
  757.             TextType::class,
  758.             array(
  759.                 'required' => false,
  760.                 'label'    => '(SEO All One) og:site_name',
  761.                 'mapped'   => false,
  762.                 'data'     => $seo_parameter->getOGSiteName(),
  763.                 // 'eccube_form_options'  => array(
  764.                 //     'auto_render'   => true
  765.                 // ),
  766.             )
  767.         );
  768.         $builder->add(
  769.             'seoallone_ogp_title',
  770.             TextType::class,
  771.             array(
  772.                 'required' => false,
  773.                 'label'    => '(SEO All One) og:title',
  774.                 'mapped'   => false,
  775.                 'data'     => $seo_parameter->getOGTitle(),
  776.                 'eccube_form_options'  => array(
  777.                     'auto_render'   => true,
  778.                     'tooltips' => $this->ogp_tooltips
  779.                 ),
  780.                 'help' => ''
  781.                 )
  782.         );
  783.         
  784.         $builder->add(
  785.             'seoallone_ogp_description',
  786.             TextType::class,
  787.             array(
  788.                 'required' => false,
  789.                 'label'    => '(SEO All One) og:description',
  790.                 'mapped'   => false,
  791.                 'data'     => $seo_parameter->getOGDescription(),
  792.                 'eccube_form_options'  => array(
  793.                     'auto_render'   => true,
  794.                     'tooltips' => $this->ogp_tooltips
  795.                 ),
  796.                 'help' => $this->product_detail_help_text_og
  797.             )
  798.         );
  799.         
  800.         $builder->add(
  801.             'seoallone_ogp_type',
  802.             ChoiceType::class,
  803.             array(
  804.                 'required' => false,
  805.                 'label'    => '(SEO All One) og:type',
  806.                 'mapped'   => false,
  807.                 'data'  => $seo_parameter->getOGType(),
  808.                 'choices'   => [
  809.                     // ''          => '',
  810.                     'website'   => 'website',
  811.                     'product'   => 'product',
  812.                     'article'   => 'article',
  813.                     'blog'      => 'blog'
  814.                 ],
  815.                 'placeholder' => false,
  816.                 'eccube_form_options'  => array(
  817.                     'auto_render'   => true
  818.                 ),
  819.             )
  820.         );
  821.         $builder->add(
  822.             'seoallone_ogp_url',
  823.             TextType::class,
  824.             array(
  825.                 'required' => false,
  826.                 'label'    => '(SEO All One) og:url',
  827.                 'mapped'   => false,
  828.                 'data'     => $seo_parameter->getOGUrl(),
  829.                 'eccube_form_options'  => array(
  830.                     'auto_render'   => true
  831.                 ),
  832.             )
  833.         );
  834.         $builder->add(
  835.             'seoallone_ogp_image',
  836.             TextType::class,
  837.             array(
  838.                 'required' => false,
  839.                 'label'    => '(SEO All One) og:image',
  840.                 'mapped'   => false,
  841.                 'data'     => $seo_parameter->getOGImage(),
  842.                 'eccube_form_options'  => array(
  843.                     'auto_render'   => true
  844.                 ),
  845.             )
  846.         );
  847.         
  848.         $builder->add(
  849.             'seoallone_noindex',
  850.             ChoiceType::class,
  851.             array(
  852.                 'required' => false,
  853.                 'label'    => '(SEO All One) noindex設定',
  854.                 'mapped'   => false,
  855.                 'data'      => $seo_parameter->getNoindexFlg(),
  856.                 'choices'   => [
  857.                     'noindexをつける' => 1,
  858.                     'noindexをつけない' => 0,
  859.                 ],
  860.                 'placeholder' => false,
  861.                 'eccube_form_options'  => array(
  862.                     'auto_render'   => true
  863.                 ),
  864.                 'expanded' => true,
  865.             )
  866.         );
  867.         $builder->add(
  868.             'seoallone_redirect_url',
  869.             TextType::class,
  870.             array(
  871.                 'required'  => false,
  872.                 'label'     => '(SEO All One) リダイレクトURL',
  873.                 'mapped'    => false,
  874.                 'data'      => $seo_parameter->getRedirectUrl(),
  875.                 'eccube_form_options'  => array(
  876.                     'auto_render'   => TRUE
  877.                 ),
  878.                 'help'  => '※こちらにURLを指定すると、詳細ページで301リダイレクトが発生するようになり、一覧ページにはこの商品は表示されません。'
  879.             )
  880.         );
  881.         if ($Config->getGlobalIdFlg()) {
  882.             $global_id_type $Config->getGlobalIdType();
  883.             $updated_flg $seo_parameter->getUpdatedFlg();
  884.             
  885.             if($seo_parameter->getGlobalIdType()) {
  886.                 $global_id_type $seo_parameter->getGlobalIdType();
  887.             }
  888.             $builder->add(
  889.                 'seoallone_global_id_type',
  890.                 ChoiceType::class,
  891.                 array(
  892.                     'required' => false,
  893.                     'label'    => '(SEO All One) バーコード種類',
  894.                     'choices'   => [
  895.                         'GTIN' => '1',
  896.                         'GTIN-8' => '2',
  897.                         'GTIN-13 (JAN)' => '3',
  898.                         'GTIN-14' => '4',
  899.                         'ISBN' => '5',
  900.                         'MPN' => '6'
  901.                     ],
  902.                     'mapped'   => false,
  903.                     'data'     => $global_id_type,
  904.                     'placeholder' => false,
  905.                     'eccube_form_options'  => array(
  906.                         'auto_render'   => true
  907.                     )
  908.                 )
  909.             );
  910.             
  911. //            $globalId = '';            
  912. //            if (!$updated_flg) { // in case has not updated, set product code for global id at default
  913. //                $globalId = $Product->getCodeMin();
  914. //            } else {
  915. //                $globalId = $seo_parameter->getGlobalId();
  916. //            }
  917. //            if ($_POST) {
  918. //                $globalId = $seo_parameter->getGlobalId();
  919. //            }
  920.             
  921.             $builder->add(
  922.                 'seoallone_global_id',
  923.                 TextType::class,
  924.                 array(
  925.                     'required' => false,
  926.                     'label'    => '(SEO All One) 固有商品 ID',
  927.                     'mapped'   => false,
  928.                     'data'     => $seo_parameter->getGlobalId(),
  929.                     'eccube_form_options'  => array(
  930.                         'auto_render'   => true
  931.                     ),
  932.                 )
  933.             );
  934.         }
  935.         if ($Config->getValidPriceFlg()) {
  936.             $valid_price_month = (int)$Config->getValidPriceMonth();
  937.             if ($valid_price_month==0) {
  938.                 $valid_price_month "";
  939.             }
  940.             if($seo_parameter->getValidPriceMonth() && $seo_parameter->getValidPriceMonth()!=$valid_price_month) {
  941.                 $valid_price_month $seo_parameter->getValidPriceMonth();
  942.             }
  943.             $builder->add(
  944.                 'seoallone_valid_price_month',
  945.                 TextType::class,
  946.                 array(
  947.                     'required' => false,
  948.                     'label'    => '(SEO All One) priceValidUntil',
  949.                     'mapped'   => false,
  950.                     'data'     => $valid_price_month,
  951.                     'eccube_form_options'  => array(
  952.                         'auto_render'   => true
  953.                     ),
  954.                     'attr' => ['style' => 'width: 100px; display: inline'],
  955.                     'constraints' => [
  956.                         new Assert\GreaterThan(0),
  957.                         new Assert\Regex([
  958.                             'pattern' => "/^\d+$/u",
  959.                             'message' => 'form_error.numeric_only',
  960.                         ])
  961.                     ],
  962.                     'label_format' => ' ヶ月',
  963.                     'help' => '※Googleの価格の有効期限情報です。基本的には変更する必要はありません。'
  964.                 )
  965.             );
  966.             
  967.             
  968.         }
  969.     }
  970.     public function onAdminProductTwig(TemplateEvent $event)
  971.     {
  972.         $Config $this->configRepository->findOneBy([]);
  973.        
  974.         $twig $this->twig;
  975.         $search_code $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/admin/seoallone_search_form_1.twig');
  976.         $replace_code $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/admin/seoallone_search_form_2.twig');
  977.         $source $event->getSource();
  978.         if (strpos($sourcestr_replace("\r"''$search_code->getCode())))
  979.         {
  980.             $view_src str_replace(str_replace("\r"''$search_code->getCode()), $replace_code->getCode(), $source);
  981.             $event->setSource($view_src);
  982.             return;
  983.         }
  984.         $search_code $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/admin/seoallone_search_form_1_1.twig');
  985.         $replace_code $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/admin/seoallone_search_form_2_1.twig');
  986.         if (strpos($sourcestr_replace("\r"''$search_code->getCode())))
  987.         {
  988.             $view_src str_replace(str_replace("\r"''$search_code->getCode()), $replace_code->getCode(), $source);
  989.             $event->setSource($view_src);
  990.             return;
  991.         }
  992.     }
  993.     
  994.     public function onAdminProductEditComplete(EventArgs $event)
  995.     {
  996.         $Config $this->configRepository->findOneBy([]);
  997.         $form $event->getArgument('form');
  998.         $Product $event->getArgument('Product');
  999.         $seoallone_product $this->seoAllOneProductRepository->findOneby(array('Product' => $Product));
  1000.         if (!$seoallone_product) {
  1001.             $seoallone_product = new SEOAllOneProduct();
  1002.         } else {
  1003.             //中間テーブルにデータが有る時
  1004.             $seoallone_product->setUpdateDate(new \DateTime());
  1005.         }
  1006.         
  1007.         $em $this->container->get('doctrine.orm.entity_manager');
  1008.         $seo_title          $form['seoallone_title']->getData();
  1009.         $seo_author         $form['seoallone_author']->getData();
  1010.         $seo_description    $form['seoallone_description']->getData();
  1011.         $seo_keyword        $form['seoallone_keyword']->getData();
  1012.         $seo_canonical      $form['seoallone_canonical']->getData();
  1013.         $ogp_site_name      $form['seoallone_ogp_site_name']->getData();
  1014.         $ogp_title          $form['seoallone_ogp_title']->getData();
  1015.         $ogp_description    $form['seoallone_ogp_description']->getData();
  1016.         $ogp_url            $form['seoallone_ogp_url']->getData();
  1017.         $ogp_type           $form['seoallone_ogp_type']->getData();
  1018.         $ogp_image          $form['seoallone_ogp_image']->getData();
  1019.         $seoallone_product->setTitle($seo_title);
  1020.         $seoallone_product->setAuthor($seo_author);
  1021.         $seoallone_product->setDescription($seo_description);
  1022.         $seoallone_product->setKeyword($seo_keyword);
  1023.         $seoallone_product->setCanonical($seo_canonical);
  1024.         $seoallone_product->setOGSiteName($ogp_site_name);
  1025.         $seoallone_product->setOGTitle($ogp_title);
  1026.         $seoallone_product->setOGDescription($ogp_description);
  1027.         $seoallone_product->setOGUrl($ogp_url);
  1028.         $seoallone_product->setOGType($ogp_type);
  1029.         $seoallone_product->setOGImage($ogp_image);
  1030.         $seoallone_product->setUpdatedFlg(1);
  1031.         
  1032.         $global_id_type 0;
  1033.         if ($Config->getGlobalIdFlg()) {
  1034.             $global_id_type $form['seoallone_global_id_type']->getData();
  1035.             $global_id $form['seoallone_global_id']->getData();
  1036.             $seoallone_product->setGlobalId($global_id);
  1037.         }
  1038.         $seoallone_product->setGlobalIdType($global_id_type);
  1039.         
  1040.         $valid_price_month 0;
  1041.         if ($Config->getValidPriceFlg()) {
  1042.             $valid_price_month = (int)$form['seoallone_valid_price_month']->getData();
  1043.         }
  1044.         $seoallone_product->setValidPriceMonth($valid_price_month);
  1045.         $noindex_flg $form['seoallone_noindex']->getData();
  1046.         $seoallone_product->setNoindexFlg($noindex_flg);
  1047.         $redirect_url       $form['seoallone_redirect_url']->getData();
  1048.         $seoallone_product->setRedirectUrl($redirect_url);
  1049.         $seoallone_product->setProduct($Product);
  1050.         $seoallone_product->setDelFlg(0);
  1051.         
  1052.         
  1053.         $em->persist($seoallone_product);
  1054.         $em->flush($seoallone_product);
  1055.         
  1056.         if ($Config->getSitemapFlg() == 1)
  1057.         {
  1058.             $this->util->generateSitemap($this->eccubeConfig);
  1059.         }
  1060.     }
  1061.     public function onAdminProductCategoryIndexComplete(EventArgs $event)
  1062.     {
  1063.         $Config $this->configRepository->findOneBy([]);
  1064.         
  1065.         if ($Config->getSitemapFlg() == 1)
  1066.         {
  1067.             $this->util->generateSitemap($this->eccubeConfig);
  1068.         }
  1069.         if ($event->hasArgument('editForm'))
  1070.         {
  1071.             $form $event->getArgument('editForm');
  1072.         }
  1073.         else
  1074.         {
  1075.             $form $event->getArgument('form');
  1076.         }
  1077.         $Parent $event->getArgument('Parent');
  1078.         $TargetCategory $event->getArgument('TargetCategory');
  1079.         $category_seo $this->seoAllOneCategoryRepository->findOneBy(array('Category' => $TargetCategory));
  1080.         if (!$category_seo) {
  1081.             $category_seo = new SEOAllOneCategory();
  1082.         } else {
  1083.             //中間テーブルにデータが有る時
  1084.             $category_seo->setUpdateDate(new \DateTime());
  1085.         }
  1086.         
  1087.         $em $this->container->get('doctrine.orm.entity_manager');
  1088.         // 入力を取り出す
  1089.         $seo_title $form['seoallone_title']->getData();
  1090.         $seo_author $form['seoallone_author']->getData();
  1091.         $seo_description $form['seoallone_description']->getData();
  1092.         $seo_keyword $form['seoallone_keyword']->getData();
  1093.         $seo_canonical $form['seoallone_canonical']->getData();
  1094.         $ogp_site_name          $form['seoallone_ogp_site_name']->getData();
  1095.         $ogp_title         $form['seoallone_ogp_title']->getData();
  1096.         $ogp_description    $form['seoallone_ogp_description']->getData();
  1097.         $ogp_url        $form['seoallone_ogp_url']->getData();
  1098.         $ogp_type      $form['seoallone_ogp_type']->getData();
  1099.         $ogp_image      $form['seoallone_ogp_image']->getData();
  1100.         
  1101.         //入力値セット
  1102.         $category_seo->setTitle($seo_title);
  1103.         $category_seo->setAuthor($seo_author);
  1104.         $category_seo->setDescription($seo_description);
  1105.         $category_seo->setKeyword($seo_keyword);
  1106.         $category_seo->setCanonical($seo_canonical);
  1107.         $category_seo->setOGSiteName($ogp_site_name);
  1108.         $category_seo->setOGTitle($ogp_title);
  1109.         $category_seo->setOGDescription($ogp_description);
  1110.         $category_seo->setOGUrl($ogp_url);
  1111.         $category_seo->setOGType($ogp_type);
  1112.         $category_seo->setOGImage($ogp_image);
  1113.         $category_seo->setCategory($TargetCategory);
  1114.         $category_seo->setDelFlg(0);
  1115.         
  1116.         // DB更新
  1117.         $em->persist($category_seo);
  1118.         $em->flush($category_seo);
  1119.     }
  1120.     private function readyPlaceholderProduct(Product $Product)
  1121.     {
  1122.         $categories $Product->getProductCategories();
  1123.         $category_name '';
  1124.         $category_name_parent '';
  1125.         if($categories && isset($categories[0]) && $categories[0]) {
  1126.             $firstCategory $categories[0];
  1127.             $parentCategory $this->_getCategoryMostParent($firstCategory->getCategory());
  1128.             $category_name $firstCategory->getCategory()->getName();
  1129.             if($parentCategory) {
  1130.                 $category_name_parent $parentCategory->getName();
  1131.             }
  1132.         }
  1133.         //@##ADD 2022-10-21
  1134.         $product_category '';
  1135.         if($categories) {
  1136.             foreach($categories as $category) {
  1137.                 $parentCategory $this->_getCategoryMostParent($category->getCategory());
  1138.                 if($parentCategory) {
  1139.                     if($parentCategory->getId() == || $parentCategory->getId() == 3) {
  1140.                         $product_category $category->getCategory()->getName();
  1141.                         break;
  1142.                     }
  1143.                 }
  1144.             }
  1145.         }
  1146.         //@##ADD END 2022-10-21
  1147.         $title $Product->seo_title;
  1148.         if (isset($Product->seo_title) && $Product->seo_title != '')
  1149.         {
  1150.             
  1151.             $title preg_replace(self::PRODUCT_NAME_PATTERN'${1}' $Product->getName() . '${4}'$title);
  1152.             $title preg_replace(self::PRODUCT_PRICE01_PATTERNis_null($Product->getPrice01Min()) ? '' '${1}' sprintf('%s'number_format($Product->getPrice01IncTaxMin())) . '${4}'$title);
  1153.             $title preg_replace(self::PRODUCT_PRICE02_PATTERNsprintf('%s''${1}' number_format($Product->getPrice02IncTaxMin())) . '${4}'$title);
  1154.             $title preg_replace(self::CATEGORY_NAME_PATTERN$category_name '${1}'.$category_name.'${4}' ''$title);
  1155.             $title preg_replace(self::CATEGORY_PARENTNAME_PATTERN$category_name_parent '${1}'.$category_name_parent.'${4}' ''$title);
  1156.             $title preg_replace(self::PRODUCT_CATEGORY_PATTERN$product_category '${1}'.$product_category.'${4}' ''$title);
  1157.         }
  1158.         
  1159.         $og_title $Product->og_title;
  1160.         if (isset($Product->og_title) && $Product->og_title != '')
  1161.         {
  1162.             $og_title preg_replace(self::PRODUCT_NAME_PATTERN'${1}' $Product->getName() . '${4}'$og_title);
  1163.             $og_title preg_replace(self::PRODUCT_PRICE01_PATTERNis_null($Product->getPrice01Min()) ? '' '${1}' sprintf('%s'number_format($Product->getPrice01IncTaxMin())) . '${4}'$og_title);
  1164.             $og_title preg_replace(self::PRODUCT_PRICE02_PATTERNsprintf('%s''${1}' number_format($Product->getPrice02IncTaxMin())) . '${4}'$og_title);
  1165.             $og_title preg_replace(self::CATEGORY_NAME_PATTERN$category_name '${1}'.$category_name.'${4}' ''$og_title);
  1166.             $og_title preg_replace(self::CATEGORY_PARENTNAME_PATTERN$category_name_parent '${1}'.$category_name_parent.'${4}' ''$og_title);
  1167.         }
  1168.         $description $Product->seo_description;
  1169.         if (isset($Product->seo_description) && $Product->seo_description != '')
  1170.         {
  1171.             $description preg_replace(self::PRODUCT_NAME_PATTERN'${1}' $Product->getName() . '${4}'$description);
  1172.             $description preg_replace(self::PRODUCT_PRICE01_PATTERNis_null($Product->getPrice01Min()) ? '' '${1}' sprintf('%s'number_format($Product->getPrice01IncTaxMin())) . '${4}'$description);
  1173.             $description preg_replace(self::PRODUCT_PRICE02_PATTERNsprintf('%s''${1}' number_format($Product->getPrice02IncTaxMin())) . '${4}'$description);
  1174.             $description preg_replace(self::CATEGORY_NAME_PATTERN$category_name '${1}'.$category_name.'${4}' ''$description);
  1175.             $description preg_replace(self::CATEGORY_PARENTNAME_PATTERN$category_name_parent '${1}'.$category_name_parent.'${4}' ''$description);
  1176.             $description preg_replace(self::PRODUCT_CATEGORY_PATTERN$product_category '${1}'.$product_category.'${4}' ''$description);
  1177.         }
  1178.         $og_description $Product->og_description;
  1179.         if (isset($Product->og_description) && $Product->og_description != '')
  1180.         {
  1181.             $og_description preg_replace(self::PRODUCT_NAME_PATTERN'${1}' $Product->getName() . '${4}'$og_description);
  1182.             $og_description preg_replace(self::PRODUCT_PRICE01_PATTERNis_null($Product->getPrice01Min()) ? '' '${1}' sprintf('%s'number_format($Product->getPrice01IncTaxMin())) . '${4}'$og_description);
  1183.             $og_description preg_replace(self::PRODUCT_PRICE02_PATTERNsprintf('%s''${1}' number_format($Product->getPrice02IncTaxMin())) . '${4}'$og_description);
  1184.             $og_description preg_replace(self::CATEGORY_NAME_PATTERN$category_name '${1}'.$category_name.'${4}' ''$og_description);
  1185.             $og_description preg_replace(self::CATEGORY_PARENTNAME_PATTERN$category_name_parent '${1}'.$category_name_parent.'${4}' ''$og_description);
  1186.         }
  1187.         $keyword $Product->seo_keywords;
  1188.         
  1189.         if (isset($Product->seo_keywords) && $Product->seo_keywords != '')
  1190.         {
  1191.             $keyword preg_replace(self::PRODUCT_NAME_PATTERN'${1}' $Product->getName() . '${4}'$keyword);
  1192.             $keyword preg_replace(self::PRODUCT_PRICE01_PATTERNis_null($Product->getPrice01Min()) ? '' '${1}' sprintf('%s'number_format($Product->getPrice01IncTaxMin())) . '${4}'$keyword);
  1193.             $keyword preg_replace(self::PRODUCT_PRICE02_PATTERNsprintf('%s''${1}' number_format($Product->getPrice02IncTaxMin())) . '${4}'$keyword);
  1194.             $keyword preg_replace(self::CATEGORY_NAME_PATTERN$category_name '${1}'.$category_name.'${4}' ''$keyword);
  1195.             $keyword preg_replace(self::CATEGORY_PARENTNAME_PATTERN$category_name_parent '${1}'.$category_name_parent.'${4}' ''$keyword);
  1196.             $keyword preg_replace(self::PRODUCT_CATEGORY_PATTERN$product_category '${1}'.$product_category.'${4}' ''$keyword);
  1197.         }
  1198.         $Product->seo_title $title;
  1199.         $Product->og_title $og_title;
  1200.         $Product->seo_description $description;
  1201.         $Product->og_description $og_description;
  1202.         $Product->seo_keywords $keyword;
  1203.         return $Product;
  1204.     }
  1205.     private function readyPlaceholderCategory(Category $Category)
  1206.     {
  1207.         $CategoryMostParent $this->_getCategoryMostParent($Category);
  1208.         $categoryMostParentName '';
  1209.         if(!is_null($CategoryMostParent)) {
  1210.             $categoryMostParentName $CategoryMostParent->getName();
  1211.         }
  1212.         $title $Category->seo_title;
  1213.         if (isset($Category->seo_title) && $Category->seo_title != '')
  1214.         {
  1215.             $title preg_replace(self::CATEGORY_NAME_PATTERN$Category->getName(), $title);
  1216.             $title preg_replace(self::CATEGORY_PARENTNAME_PATTERN$categoryMostParentName '${1}'.$categoryMostParentName.'${4}' ''$title);
  1217.         }
  1218.         $description $Category->seo_description;
  1219.         if (isset($Category->seo_description) && $Category->seo_description != '')
  1220.         {
  1221.             $description preg_replace(self::CATEGORY_NAME_PATTERN$Category->getName(), $description);
  1222.             $description preg_replace(self::CATEGORY_PARENTNAME_PATTERN$categoryMostParentName '${1}'.$categoryMostParentName.'${4}' ''$description);
  1223.         }
  1224.         $keyword $Category->seo_keywords;
  1225.         if (isset($Category->seo_keywords) && $Category->seo_keywords != '')
  1226.         {
  1227.             $keyword preg_replace(self::CATEGORY_NAME_PATTERN$Category->getName(), $keyword);
  1228.             $keyword preg_replace(self::CATEGORY_PARENTNAME_PATTERN$categoryMostParentName '${1}'.$categoryMostParentName.'${4}' ''$keyword);
  1229.         }
  1230.         $Category->seo_title $title;
  1231.         $Category->seo_description $description;
  1232.         $Category->seo_keywords $keyword;
  1233.         
  1234.         $og_title $Category->og_title;
  1235.         if (isset($Category->og_title) && $Category->og_title != '')
  1236.         {
  1237.             $og_title preg_replace(self::CATEGORY_NAME_PATTERN$Category->getName(), $og_title);
  1238.             $og_title preg_replace(self::CATEGORY_PARENTNAME_PATTERN$categoryMostParentName '${1}'.$categoryMostParentName.'${4}' ''$og_title);
  1239.         }
  1240.         $og_description $Category->og_description;
  1241.         if (isset($Category->og_description) && $Category->og_description != '')
  1242.         {
  1243.             $og_description preg_replace(self::CATEGORY_NAME_PATTERN$Category->getName(), $og_description);
  1244.             $og_description preg_replace(self::CATEGORY_PARENTNAME_PATTERN$categoryMostParentName '${1}'.$categoryMostParentName.'${4}' ''$og_description);
  1245.         }
  1246.         $Category->og_title $og_title;
  1247.         $Category->og_description $og_description;
  1248.         return $Category;
  1249.     }
  1250.     public function onAdminProductCategoryTwig(TemplateEvent $event)
  1251.     {
  1252.         $Config $this->configRepository->findOneBy([]);
  1253.         $twig $this->twig;
  1254.         $source $event->getSource();
  1255.         $view_src '';
  1256.         $search_code_1 $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/admin/seoallone_search_form_3.twig');
  1257.         $replace_code_1 $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/admin/seoallone_search_form_5.twig');
  1258.         if (strpos($sourcestr_replace("\r"''$search_code_1->getCode())))
  1259.         {
  1260.             $view_src str_replace(str_replace("\r"''$search_code_1->getCode()), $replace_code_1->getCode(), $source);
  1261.         }
  1262.         $search_code_2 $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/admin/seoallone_search_form_4.twig');
  1263.         $replace_code_2 $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/admin/seoallone_search_form_6.twig');
  1264.         if (strpos($sourcestr_replace("\r"''$search_code_2->getCode())))
  1265.         {
  1266.             $view_src str_replace(str_replace("\r"''$search_code_2->getCode()), $replace_code_2->getCode(), $view_src);
  1267.         }
  1268.         if ($view_src) {
  1269.             $event->setSource($view_src);
  1270.         }
  1271.     }
  1272.     public function onIndexTwig(TemplateEvent $event)
  1273.     {
  1274.         $PageHomepage $this->pageRepository->findOneBy(array('url' => 'homepage'));
  1275.         $parameters $event->getParameters();
  1276.         if (!$PageHomepage)
  1277.         {
  1278.             return;
  1279.         }
  1280.         $Config $this->configRepository->findOneBy([]);
  1281.         $event->setParameter('SEOAllOneConfig'$Config);
  1282.         $parameters['SEOAllOneConfig'] = $Config;
  1283.         $default_seo_parameter $this->seoAllOneDefaultRepository->findOneby(array('Page' => $PageHomepage));
  1284.         if (!$default_seo_parameter) {
  1285.             //タグ設定されていない時
  1286.             return;
  1287.         }
  1288.         if (is_null($Config))
  1289.         {
  1290.             return;
  1291.         }
  1292.         
  1293.         $parameters['seoallone_title'] = $default_seo_parameter->getTitle();
  1294.         $parameters['seoallone_description'] = $default_seo_parameter->getDescription();
  1295.         $parameters['seoallone_keyword'] = $default_seo_parameter->getKeyword();
  1296.         $parameters['seoallone_author'] = $default_seo_parameter->getAuthor();
  1297.         $parameters['seoallone_canonical'] = $default_seo_parameter->getCanonical();
  1298.         $parameters['seoallone_og_site_name'] = $default_seo_parameter->getOGSiteName();
  1299.         $parameters['seoallone_og_title'] = $default_seo_parameter->getOGTitle();
  1300.         $parameters['seoallone_og_description'] = $default_seo_parameter->getOGDescription();
  1301.         $parameters['seoallone_og_url'] = $default_seo_parameter->getOGUrl();
  1302.         $parameters['seoallone_og_type'] = $default_seo_parameter->getOGType();
  1303.         $parameters['seoallone_og_image'] = $default_seo_parameter->getOGImage();
  1304.         $event->setParameters($parameters);
  1305.         $meta_tags $PageHomepage->getMetaTags();
  1306.        
  1307.         if ($meta_tags) {
  1308.             $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:title"[^>]+(\/)?>/m'''$meta_tags);
  1309.             if ($parameters['seoallone_og_description'] || $parameters['seoallone_description'] || $PageHomepage->getDescription()) {
  1310.                 $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:description"[^>]+(\/)?>/m'''$meta_tags);
  1311.             }
  1312.             $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:url"[^>]+(\/)?>/m'''$meta_tags);
  1313.             if ($parameters['seoallone_og_image']) {
  1314.                 $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:image"[^>]+(\/)?>/m'''$meta_tags);
  1315.             }
  1316.             $meta_tags preg_replace('/(<(\s)*)meta(\s)*(name|property)="og:type"[^>]+(\/)?>/m'''$meta_tags);
  1317.             $meta_tags str_replace("\r\n\r\n"""$meta_tags);
  1318.             $meta_tags str_replace("\n\r\n\r"""$meta_tags);
  1319.         }
  1320.         $PageHomepage->setMetaTags($meta_tags);
  1321.     }
  1322.     public function onFrontProductDetailTwig(TemplateEvent $event)
  1323.     {
  1324.         $requestStack $this->container->get('request_stack');
  1325.         $request $requestStack->getMainRequest();
  1326.         $parameters $event->getParameters();
  1327.         
  1328.         $Config $this->configRepository->findOneBy([]);
  1329.         $event->setParameter('SEOAllOneConfig'$Config);
  1330.         $parameters['SEOAllOneConfig'] = $Config;
  1331.         $seo_title = !empty($parameters['title'])? $parameters['title'] : '';
  1332.         $seo_subtitle = !empty($parameters['subtitle'])? $parameters['subtitle'] : '';
  1333.         $request->attributes->set('seo_title'$seo_title);
  1334.         $request->attributes->set('seo_subtitle'$seo_subtitle);
  1335.         if ($Config->getSnsFlg() == 1) {
  1336.             $event->addSnippet('@SEOAllOne42/social_button.twig');
  1337.             
  1338.             $parameters['facebook_flg'] = $Config->getFacebookFlg();
  1339.             $parameters['twitter_flg'] = $Config->getTwitterFlg();
  1340.             $parameters['line_flg'] = $Config->getLineFlg();
  1341.             $event->setParameters($parameters);
  1342.         }
  1343.         
  1344.         if ($Config->getRichSnippetFlg() == 1)
  1345.         {
  1346.             $event->addSnippet('@SEOAllOne42/json-ld.twig');
  1347.         }
  1348.         // remove default json schema
  1349.         // pattern for eccube 4.0, 4.1, 4.2
  1350.         $twig $this->twig;
  1351.         $search_code $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/json-ld-search.twig');
  1352.         $replace_code "";
  1353.         
  1354.         $source $event->getSource();    
  1355.         if (strpos($sourcestr_replace("\r"''$search_code->getCode())))
  1356.         {
  1357.             $view_src str_replace(str_replace("\r"''$search_code->getCode()), $replace_code$source);
  1358.             $event->setSource($view_src);
  1359.         }
  1360.         
  1361.         // pattern for eccube 4.3
  1362.         $twig $this->twig;
  1363.         $search_code $twig->getLoader()->getSourceContext('SEOAllOne42/Resource/template/json-ld-search2.twig');
  1364.         $replace_code "";
  1365.         
  1366.         $source $event->getSource();    
  1367.         if (strpos($sourcestr_replace("\r"''$search_code->getCode())))
  1368.         {
  1369.             $view_src str_replace(str_replace("\r"''$search_code->getCode()), $replace_code$source);
  1370.             $event->setSource($view_src);
  1371.         }
  1372.     }
  1373.     private function readyPagination(&$parameters)
  1374.     {
  1375.         // $parameters = $event->getParameters();
  1376.         $paginationData $parameters['pagination']->getPaginationData();
  1377.         $link_prev NULL;
  1378.         $link_next NULL;
  1379.         $Config $this->configRepository->findOneBy([]);
  1380.         if ($Config->getPaginationFlg() == 1)
  1381.         {
  1382.             $requestStack $this->container->get('request_stack');
  1383.             $request $requestStack->getMainRequest();
  1384.             if ($request->getMethod() === 'GET') {
  1385.                 $all $request->query->all();
  1386.                 if (array_key_exists('pageno'$all) && $all['pageno'] == 0) {
  1387.                     $all['pageno'] = 1;
  1388.                 }
  1389.             }
  1390.             if ($paginationData['numItemsPerPage'] >= $paginationData['totalCount'])
  1391.             {
  1392.                 $link_next NULL;
  1393.                 $link_prev NULL;
  1394.             }
  1395.             else
  1396.             {
  1397.                 if ($paginationData['current'] == $paginationData['first'])
  1398.                 {
  1399.                     $link_prev NULL;
  1400.                     $all['pageno'] =$paginationData['next'];
  1401.                     $link_next '?' http_build_query($all);
  1402.                 }
  1403.                 elseif ($paginationData['current'] == $paginationData['last'])
  1404.                 {
  1405.                     $link_next NULL;
  1406.                     $all['pageno'] =$paginationData['previous'];
  1407.                     $link_prev '?' http_build_query($all);
  1408.                 }
  1409.                 else
  1410.                 {
  1411.                     $all['pageno'] =$paginationData['previous'];
  1412.                     $link_prev '?' http_build_query($all);
  1413.                     $all['pageno'] =$paginationData['next'];
  1414.                     $link_next '?' http_build_query($all);
  1415.                 }
  1416.             }
  1417.         }
  1418.         
  1419.         $parameters['seo_link_prev'] = $link_prev;
  1420.         $parameters['seo_link_next'] = $link_next;
  1421.         // $event->setParameters($parameters);
  1422.     }
  1423.     public function onFrontProductIndexInitialize(EventArgs $event)
  1424.     {
  1425.         $Config $this->configRepository->findOneBy([]);
  1426.         $SEOProducts $this->seoAllOneProductRepository->findAll();
  1427.         $ids = [];
  1428.         if ($SEOProducts)
  1429.         {
  1430.             foreach($SEOProducts as $SEOProduct)
  1431.             {
  1432.                 if ($SEOProduct->getRedirectUrl() != '')
  1433.                 {
  1434.                     $ids[] = $SEOProduct->getProduct()->getId();
  1435.                 }
  1436.             }
  1437.         }
  1438.         if ($ids)
  1439.         {
  1440.             $qb $event->getArgument('qb');
  1441.             foreach($ids as $id)
  1442.             {
  1443.                 $qb->andWhere('p.id != '.$id);
  1444.             }
  1445.             $event->setArgument('qb'$qb);
  1446.         }
  1447.     }
  1448.     public function onAdminProductDeleteComplete(EventArgs $event)
  1449.     {
  1450.         $Config $this->configRepository->findOneBy([]);
  1451.         if ($Config->getSitemapFlg() == 1)
  1452.         {
  1453.             $this->util->generateSitemap($this->eccubeConfig);
  1454.         }
  1455.     }
  1456.     public function onAdminContentPageDeleteComplete(EventArgs $event)
  1457.     {
  1458.         $Config $this->configRepository->findOneBy([]);
  1459.         if ($Config->getSitemapFlg() == 1)
  1460.         {
  1461.             $this->util->generateSitemap($this->eccubeConfig);
  1462.         }
  1463.     }
  1464.     public function onAdminProductCategoryDeleteComplete(EventArgs $event)
  1465.     {
  1466.         $Config $this->configRepository->findOneBy([]);
  1467.         if ($Config->getSitemapFlg() == 1)
  1468.         {
  1469.             $this->util->generateSitemap($this->eccubeConfig);
  1470.         }
  1471.     }
  1472.     private function _getCategoryMostParent(Category $Category) {
  1473.         if($Category->getHierarchy() == 1) {
  1474.             return NULL;
  1475.         }
  1476.         $parents $Category->getParents();
  1477.         if(isset($parents[0]) && trim($parents[0]->getName()) != trim($Category->getName())) {
  1478.             return $parents[0];
  1479.         }
  1480.         return NULL;
  1481.     }
  1482.     
  1483.     public function onAdminStorePluginIndexTwig(TemplateEvent $event)
  1484.     {
  1485.         $em $this->container->get('doctrine.orm.entity_manager');
  1486.         $conn $em->getConnection();
  1487.         
  1488.         $driver '';
  1489.         $conn $em->getConnection();
  1490.         $params $conn->getParams();
  1491.         if (isset($params['driver'])){
  1492.             $driver $params['driver'];
  1493.         }
  1494.         
  1495.         // used in case upgrade plugin - make `shop_name_top_flg` column in case does not exist
  1496.         if ($driver == 'pdo_mysql') {
  1497.             // shop_name_top_flg
  1498.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_config` LIKE 'shop_name_top_flg'");
  1499.             $cnt $stmt->fetchAll();
  1500.             if (!$cnt) {
  1501.                 $stmt $conn->executeQuery("ALTER TABLE `plg_seoallone_config` ADD COLUMN `shop_name_top_flg` INT(1) DEFAULT '1' AFTER `line_flg`");
  1502.             }
  1503.             
  1504.             // shop_name_product_flg
  1505.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_config` LIKE 'shop_name_product_flg'");
  1506.             $cnt $stmt->fetchAll();
  1507.             if (!$cnt) {
  1508.                 $stmt $conn->executeQuery("ALTER TABLE `plg_seoallone_config` ADD COLUMN `shop_name_product_flg` INT(1) DEFAULT '1' AFTER `line_flg`");
  1509.             }
  1510.             
  1511.             // global_id_flg
  1512.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_config` LIKE 'global_id_flg'");
  1513.             $cnt $stmt->fetchAll();
  1514.             if (!$cnt) {
  1515.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN global_id_flg TINYINT NOT NULL DEFAULT 0");                    
  1516.             }
  1517.             
  1518.             // global_id_type
  1519.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_config` LIKE 'global_id_type'");
  1520.             $cnt $stmt->fetchAll();
  1521.             if (!$cnt) {
  1522.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN global_id_type INT DEFAULT 3");                
  1523.             }
  1524.             
  1525.             // valid_price_flg
  1526.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_config` LIKE 'valid_price_flg'");
  1527.             $cnt $stmt->fetchAll();
  1528.             if (!$cnt) {
  1529.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN valid_price_flg TINYINT NOT NULL DEFAULT 0");                
  1530.             }            
  1531.             
  1532.             // valid_price_month
  1533.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_config` LIKE 'valid_price_month'");
  1534.             $cnt $stmt->fetchAll();
  1535.             if (!$cnt) {
  1536.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN valid_price_month INT DEFAULT 0");            
  1537.             }
  1538.             
  1539.             // canonical_flg
  1540.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_config` LIKE 'canonical_flg'");
  1541.             $cnt $stmt->fetchAll();
  1542.             if (!$cnt) {
  1543.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN canonical_flg TINYINT NOT NULL DEFAULT 1");                
  1544.             }        
  1545.             
  1546.             // global_id_type for product
  1547.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_product` LIKE 'global_id_type'");
  1548.             $cnt $stmt->fetchAll();
  1549.             if (!$cnt) {
  1550.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN global_id_type INT DEFAULT 3");                
  1551.             }
  1552.             
  1553.             // global_id for product
  1554.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_product` LIKE 'global_id'");
  1555.             $cnt $stmt->fetchAll();
  1556.             if (!$cnt) {
  1557.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN global_id VARCHAR(255) DEFAULT NULL");                
  1558.             }            
  1559.             
  1560.             // valid_price_month for product
  1561.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_product` LIKE 'valid_price_month'");
  1562.             $cnt $stmt->fetchAll();
  1563.             if (!$cnt) {
  1564.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN valid_price_month INT DEFAULT 0");            
  1565.             }        
  1566.             
  1567.             // valid_price_flg for product
  1568.             $stmt $conn->executeQuery("SHOW COLUMNS FROM `plg_seoallone_product` LIKE 'updated_flg'");
  1569.             $cnt $stmt->fetchAll();
  1570.             if (!$cnt) {
  1571.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN updated_flg TINYINT NOT NULL DEFAULT 0");                
  1572.             }        
  1573.         } elseif ($driver == 'pdo_pgsql') {
  1574.             // shop_name_top_flg
  1575.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_config' and column_name='shop_name_top_flg'");
  1576.             $cnt $stmt->fetchAll();
  1577.             if (!$cnt) {
  1578.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN shop_name_top_flg boolean NOT NULL DEFAULT TRUE");
  1579.             }
  1580.             
  1581.             // shop_name_product_flg
  1582.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_config' and column_name='shop_name_product_flg'");
  1583.             $cnt $stmt->fetchAll();
  1584.             if (!$cnt) {
  1585.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN shop_name_product_flg boolean NOT NULL DEFAULT TRUE");
  1586.             }
  1587.             
  1588.             // global_id_flg
  1589.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_config' and column_name='global_id_flg'");
  1590.             $cnt $stmt->fetchAll();
  1591.             if (!$cnt) {
  1592.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN global_id_flg boolean NOT NULL DEFAULT FALSE");                    
  1593.             }
  1594.             
  1595.             // global_id_type
  1596.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_config' and column_name='global_id_type'");
  1597.             $cnt $stmt->fetchAll();
  1598.             if (!$cnt) {
  1599.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN global_id_type INT DEFAULT 3");                
  1600.             }
  1601.             
  1602.             // valid_price_flg
  1603.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_config' and column_name='valid_price_flg'");
  1604.             $cnt $stmt->fetchAll();
  1605.             if (!$cnt) {
  1606.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN valid_price_flg boolean NOT NULL DEFAULT FALSE");                
  1607.             }            
  1608.             
  1609.             // valid_price_month
  1610.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_config' and column_name='valid_price_month'");
  1611.             $cnt $stmt->fetchAll();
  1612.             if (!$cnt) {
  1613.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN valid_price_month INT DEFAULT 0");            
  1614.             }        
  1615.             
  1616.             // canonical_flg
  1617.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_config' and column_name='canonical_flg'");
  1618.             $cnt $stmt->fetchAll();
  1619.             if (!$cnt) {
  1620.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN canonical_flg boolean NOT NULL DEFAULT TRUE");
  1621.             }
  1622.             
  1623.             // global_id_type for product
  1624.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_product' and column_name='global_id_type'");
  1625.             $cnt $stmt->fetchAll();
  1626.             if (!$cnt) {
  1627.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN global_id_type INT DEFAULT 3");                
  1628.             }
  1629.             
  1630.             // global_id for product
  1631.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_product' and column_name='global_id'");
  1632.             $cnt $stmt->fetchAll();
  1633.             if (!$cnt) {
  1634.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN global_id VARCHAR(255) DEFAULT NULL");                
  1635.             }            
  1636.             
  1637.             // valid_price_month
  1638.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_product' and column_name='valid_price_month'");
  1639.             $cnt $stmt->fetchAll();
  1640.             if (!$cnt) {
  1641.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN valid_price_month INT DEFAULT 0");            
  1642.             }    
  1643.             
  1644.             // updated_flg
  1645.             $stmt $conn->executeQuery("SELECT column_name FROM information_schema.columns WHERE table_name='plg_seoallone_product' and column_name='updated_flg'");
  1646.             $cnt $stmt->fetchAll();
  1647.             if (!$cnt) {
  1648.                 $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN updated_flg boolean NOT NULL DEFAULT FALSE");                
  1649.             }        
  1650.         } elseif ($driver == 'pdo_sqlite') {
  1651.             // shop_name_top_flg
  1652.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_config)");
  1653.             $res $stmt->fetchAll();
  1654.             if ($res) {
  1655.                 $shop_name_top_flg_exist FALSE;
  1656.                 foreach ($res as $item) {
  1657.                     if ($item['name'] == 'shop_name_top_flg'){
  1658.                         $shop_name_top_flg_exist TRUE;
  1659.                         break;
  1660.                     }
  1661.                 }
  1662.                 if (!$shop_name_top_flg_exist) {
  1663.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN shop_name_top_flg TINYINT NOT NULL DEFAULT 1");
  1664.                 }                
  1665.             }                
  1666.             
  1667.             // shop_name_product_flg
  1668.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_config)");
  1669.             $res $stmt->fetchAll();
  1670.             if ($res) {
  1671.                 $shop_name_product_flg_exist FALSE;
  1672.                 foreach ($res as $item) {
  1673.                     if ($item['name'] == 'shop_name_product_flg'){
  1674.                         $shop_name_product_flg_exist TRUE;
  1675.                         break;
  1676.                     }
  1677.                 }
  1678.                 if (!$shop_name_product_flg_exist) {
  1679.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN shop_name_product_flg TINYINT NOT NULL DEFAULT 1");
  1680.                 }                
  1681.             }        
  1682.             
  1683.             // global_id_flg
  1684.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_config)");
  1685.             $res $stmt->fetchAll();
  1686.             if ($res) {
  1687.                 $global_id_flg_exist FALSE;
  1688.                 foreach ($res as $item) {
  1689.                     if ($item['name'] == 'global_id_flg'){
  1690.                         $global_id_flg_exist TRUE;
  1691.                         break;
  1692.                     }
  1693.                 }
  1694.                 if (!$global_id_flg_exist) {
  1695.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN global_id_flg TINYINT NOT NULL DEFAULT 0");
  1696.                 }                
  1697.             }
  1698.             
  1699.             // global_id_type
  1700.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_config)");
  1701.             $res $stmt->fetchAll();
  1702.             if ($res) {
  1703.                 $global_id_type_exist FALSE;
  1704.                 foreach ($res as $item) {
  1705.                     if ($item['name'] == 'global_id_type'){
  1706.                         $global_id_type_exist TRUE;
  1707.                         break;
  1708.                     }
  1709.                 }
  1710.                 if (!$global_id_type_exist) {
  1711.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN global_id_type INT DEFAULT 3");
  1712.                 }                
  1713.             }
  1714.             
  1715.             // valid_price_flg
  1716.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_config)");
  1717.             $res $stmt->fetchAll();
  1718.             if ($res) {
  1719.                 $valid_price_flg_exist FALSE;
  1720.                 foreach ($res as $item) {
  1721.                     if ($item['name'] == 'valid_price_flg'){
  1722.                         $valid_price_flg_exist TRUE;
  1723.                         break;
  1724.                     }
  1725.                 }
  1726.                 if (!$valid_price_flg_exist) {
  1727.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN valid_price_flg TINYINT NOT NULL DEFAULT 0");
  1728.                 }                
  1729.             }            
  1730.             
  1731.             // valid_price_month
  1732.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_config)");
  1733.             $res $stmt->fetchAll();
  1734.             if ($res) {
  1735.                 $valid_price_month_exist FALSE;
  1736.                 foreach ($res as $item) {
  1737.                     if ($item['name'] == 'valid_price_month'){
  1738.                         $valid_price_month_exist TRUE;
  1739.                         break;
  1740.                     }
  1741.                 }
  1742.                 if (!$valid_price_month_exist) {
  1743.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN valid_price_month INT DEFAULT 0");
  1744.                 }                
  1745.             }        
  1746.             
  1747.             // canonical_flg
  1748.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_config)");
  1749.             $res $stmt->fetchAll();
  1750.             if ($res) {
  1751.                 $canonical_flg_exist FALSE;
  1752.                 foreach ($res as $item) {
  1753.                     if ($item['name'] == 'canonical_flg'){
  1754.                         $canonical_flg_exist TRUE;
  1755.                         break;
  1756.                     }
  1757.                 }
  1758.                 if (!$canonical_flg_exist) {
  1759.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_config ADD COLUMN canonical_flg TINYINT NOT NULL DEFAULT 1");
  1760.                 }                
  1761.             }    
  1762.             
  1763.             // global_id_type for product
  1764.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_product)");
  1765.             $res $stmt->fetchAll();
  1766.             if ($res) {
  1767.                 $global_id_type_exist FALSE;
  1768.                 foreach ($res as $item) {
  1769.                     if ($item['name'] == 'global_id_type'){
  1770.                         $global_id_type_exist TRUE;
  1771.                         break;
  1772.                     }
  1773.                 }
  1774.                 if (!$global_id_type_exist) {
  1775.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN global_id_type INT DEFAULT 3");
  1776.                 }                
  1777.             }        
  1778.             
  1779.             // global_id for product
  1780.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_product)");
  1781.             $res $stmt->fetchAll();
  1782.             if ($res) {
  1783.                 $global_id_exist FALSE;
  1784.                 foreach ($res as $item) {
  1785.                     if ($item['name'] == 'global_id'){
  1786.                         $global_id_exist TRUE;
  1787.                         break;
  1788.                     }
  1789.                 }
  1790.                 if (!$global_id_exist) {
  1791.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN global_id VARCHAR(255) DEFAULT NULL");
  1792.                 }                
  1793.             }                
  1794.             
  1795.             // valid_price_month for product
  1796.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_product)");
  1797.             $res $stmt->fetchAll();
  1798.             if ($res) {
  1799.                 $valid_price_month_exist FALSE;
  1800.                 foreach ($res as $item) {
  1801.                     if ($item['name'] == 'valid_price_month'){
  1802.                         $valid_price_month_exist TRUE;
  1803.                         break;
  1804.                     }
  1805.                 }
  1806.                 if (!$valid_price_month_exist) {
  1807.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN valid_price_month INT DEFAULT 0");
  1808.                 }                
  1809.             }    
  1810.             
  1811.             // valid_price_flg
  1812.             $stmt $conn->executeQuery("PRAGMA table_info(plg_seoallone_product)");
  1813.             $res $stmt->fetchAll();
  1814.             if ($res) {
  1815.                 $updated_flg_exist FALSE;
  1816.                 foreach ($res as $item) {
  1817.                     if ($item['name'] == 'updated_flg'){
  1818.                         $updated_flg_exist TRUE;
  1819.                         break;
  1820.                     }
  1821.                 }
  1822.                 if (!$updated_flg_exist) {
  1823.                     $stmt $conn->executeQuery("ALTER TABLE plg_seoallone_product ADD COLUMN updated_flg TINYINT NOT NULL DEFAULT 0");
  1824.                 }                
  1825.             }    
  1826.         }
  1827.     }
  1828. }