app/Plugin/DeliveryDate42/Event/CsvImportProductExtEvent.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : DeliveryDate4
  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\DeliveryDate42\Event;
  12. use Eccube\Event\EventArgs;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class CsvImportProductExtEvent implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @return array
  18.      */
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             'csvimportproductext.admin.product.csv.import.product.descriptions' => 'hookAdminProductCsvImportProductDescriptions',
  23.             'csvimportproductext.admin.product.csv.import.product.check'=> 'hookAdminProductCsvImportProductCheck',
  24.             'csvimportproductext.admin.product.csv.import.product.process' => 'hookAdminProductCsvImportProductProcess',
  25.         ];
  26.     }
  27.     public function hookAdminProductCsvImportProductDescriptions(EventArgs $event)
  28.     {
  29.         $header $event->getArgument('header');
  30.         $key $event->getArgument('key');
  31.         if($key == trans('deliverydate.common.1')){
  32.             $header['description'] = trans('deliverydate.admin.product.product_csv.delivery_date_description');
  33.             $header['required'] = false;
  34.         }
  35.         $event->setArgument('header',$header);
  36.     }
  37.     public function hookAdminProductCsvImportProductCheck(EventArgs $event)
  38.     {
  39.         $row $event->getArgument('row');
  40.         $lineNo $event->getArgument('lineNo');
  41.         $errors $event->getArgument('errors');
  42.         if(isset($row[trans('deliverydate.common.1')])){
  43.             if($row[trans('deliverydate.common.1')] !== '' && (!is_numeric($row[trans('deliverydate.common.1')]) || $row[trans('deliverydate.common.1')] < 0)){
  44.                 $message trans('admin.common.csv_invalid_greater_than_zero', [
  45.                     '%line%' => $lineNo,
  46.                     '%name%' => trans('deliverydate.common.1'),
  47.                 ]);
  48.                 $errors[] = $message;
  49.             }
  50.         }
  51.         $event->setArgument('errors',$errors);
  52.     }
  53.     public function hookAdminProductCsvImportProductProcess(EventArgs $event)
  54.     {
  55.         $row $event->getArgument('row');
  56.         $ProductClass $event->getArgument('ProductClass');
  57.         if(isset($row[trans('deliverydate.common.1')])){
  58.             if($row[trans('deliverydate.common.1')] != ''){
  59.                 $ProductClass->setDeliveryDateDays($row[trans('deliverydate.common.1')]);
  60.             }else{
  61.                 $ProductClass->setDeliveryDateDays(NULL);
  62.             }
  63.         }
  64.     }
  65. }