app/Plugin/SEOAllOne42/Event.php line 554

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