app/Plugin/DeliveryFreeProduct42/Event/CsvImportProductExtEvent.php line 28

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