app/Plugin/DeliveryPlus42/Event/ProductEvent.php line 96

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : DeliveryPlus4
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\DeliveryPlus42\Event;
  12. use Eccube\Event\TemplateEvent;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class ProductEvent implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @return array
  18.      */
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             'Product/list.twig' => 'onTemplateProductList',
  23.             'Product/detail.twig' => 'onTemplateProductDetail',
  24.         ];
  25.     }
  26.     public function onTemplateProductDetail(TemplateEvent $event)
  27.     {
  28.         $parameters $event->getParameters();
  29.         $Product $parameters['Product'];
  30.         $class_categories[$Product->getId()]['__unselected']['#'] = [
  31.             'weight' => '',
  32.             'size' => '',
  33.         ];
  34.         foreach($Product->getProductClasses() as $ProductClass){
  35.             if(!$ProductClass->isVisible())continue;
  36.             $ClassCategory1 $ProductClass->getClassCategory1();
  37.             $ClassCategory2 $ProductClass->getClassCategory2();
  38.             if ($ClassCategory2 && !$ClassCategory2->isVisible()) {
  39.                 continue;
  40.             }
  41.             $class_category_id1 $ClassCategory1 ? (string) $ClassCategory1->getId() : '__unselected2';
  42.             $class_category_id2 $ClassCategory2 ? (string) $ClassCategory2->getId() : '';
  43.             $class_categories[$Product->getId()][$class_category_id1]['#'] = [
  44.                 'weight' => '',
  45.                 'size' => '',
  46.             ];
  47.             $class_categories[$Product->getId()][$class_category_id1]['#'.$class_category_id2] = [
  48.                 'weight' => number_format($ProductClass->getDeliveryplusWeight(),2),
  49.                 'size' => number_format($ProductClass->getDeliveryplusSize(),2),
  50.             ];
  51.         }
  52.         $parameters['DeliveryPlusParams'] = $class_categories;
  53.         $event->setParameters($parameters);
  54.         $twig '@DeliveryPlus42/default/Product/product_js.twig';
  55.         $event->addSnippet($twig);
  56.     }
  57.     public function onTemplateProductList(TemplateEvent $event)
  58.     {
  59.         $parameters $event->getParameters();
  60.         $pagination $parameters['pagination'];
  61.         $class_categories = [];
  62.         foreach($pagination as $Product){
  63.             $class_categories[$Product->getId()]['__unselected']['#'] = [
  64.                 'weight' => '',
  65.                 'size' => '',
  66.             ];
  67.             foreach($Product->getProductClasses() as $ProductClass){
  68.                 if(!$ProductClass->isVisible())continue;
  69.                 $ClassCategory1 $ProductClass->getClassCategory1();
  70.                 $ClassCategory2 $ProductClass->getClassCategory2();
  71.                 if ($ClassCategory2 && !$ClassCategory2->isVisible()) {
  72.                     continue;
  73.                 }
  74.                 $class_category_id1 $ClassCategory1 ? (string) $ClassCategory1->getId() : '__unselected2';
  75.                 $class_category_id2 $ClassCategory2 ? (string) $ClassCategory2->getId() : '';
  76.                 $class_categories[$Product->getId()][$class_category_id1]['#'] = [
  77.                     'weight' => '',
  78.                     'size' => '',
  79.                 ];
  80.                 $class_categories[$Product->getId()][$class_category_id1]['#'.$class_category_id2] = [
  81.                     'weight' => number_format($ProductClass->getDeliveryplusWeight(),2),
  82.                     'size' => number_format($ProductClass->getDeliveryplusSize(),2),
  83.                 ];
  84.             }
  85.         }
  86.         $parameters['DeliveryPlusParams'] = $class_categories;
  87.         $event->setParameters($parameters);
  88.         $twig '@DeliveryPlus42/default/Product/product_js.twig';
  89.         $event->addSnippet($twig);
  90.     }
  91. }