app/Plugin/DeliveryPlus42/Event/CsvImportProductExtEvent.php line 75

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\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('deliveryplus.common.1')){
  32.             $header['description'] = trans('deliveryplus.admin.product.product_csv.weight_description');
  33.             $header['required'] = false;
  34.         }
  35.         if($key == trans('deliveryplus.common.2')){
  36.             $header['description'] = trans('deliveryplus.admin.product.product_csv.size_description');
  37.             $header['required'] = false;
  38.         }
  39.         $event->setArgument('header',$header);
  40.     }
  41.     public function hookAdminProductCsvImportProductCheck(EventArgs $event)
  42.     {
  43.         $row $event->getArgument('row');
  44.         $lineNo $event->getArgument('lineNo');
  45.         $errors $event->getArgument('errors');
  46.         if(isset($row[trans('deliveryplus.common.1')])){
  47.             if($row[trans('deliveryplus.common.1')] !== '' && (!is_numeric($row[trans('deliveryplus.common.1')]) || $row[trans('deliveryplus.common.1')] < 0)){
  48.                 $message trans('admin.common.csv_invalid_greater_than_zero', [
  49.                     '%line%' => $lineNo,
  50.                     '%name%' => trans('deliveryplus.common.1'),
  51.                 ]);
  52.                 $errors[] = $message;
  53.             }
  54.         }
  55.         if(isset($row[trans('deliveryplus.common.2')])){
  56.             if($row[trans('deliveryplus.common.2')] !== '' && (!is_numeric($row[trans('deliveryplus.common.2')]) || $row[trans('deliveryplus.common.2')] < 0)){
  57.                 $message trans('admin.common.csv_invalid_greater_than_zero', [
  58.                     '%line%' => $lineNo,
  59.                     '%name%' => trans('deliveryplus.common.2'),
  60.                 ]);
  61.                 $errors[] = $message;
  62.             }
  63.         }
  64.         $event->setArgument('errors',$errors);
  65.     }
  66.     public function hookAdminProductCsvImportProductProcess(EventArgs $event)
  67.     {
  68.         $row $event->getArgument('row');
  69.         $ProductClass $event->getArgument('ProductClass');
  70.         if(isset($row[trans('deliveryplus.common.1')])){
  71.             if($row[trans('deliveryplus.common.1')] != ''){
  72.                 $ProductClass->setDeliveryplusWeight($row[trans('deliveryplus.common.1')]);
  73.             }else{
  74.                 $ProductClass->setDeliveryplusWeight(NULL);
  75.             }
  76.         }
  77.         if(isset($row[trans('deliveryplus.common.2')])){
  78.             if($row[trans('deliveryplus.common.2')] != ''){
  79.                 $ProductClass->setDeliveryplusSize($row[trans('deliveryplus.common.2')]);
  80.             }else{
  81.                 $ProductClass->setDeliveryplusSize(NULL);
  82.             }
  83.         }
  84.     }
  85. }