<?php
/*
* Plugin Name : DeliveryFreeProduct
*
* Copyright (C) 2016 BraTech Co., Ltd. All Rights Reserved.
* http://www.bratech.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\DeliveryFreeProduct42\Event;
use Eccube\Event\EventArgs;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CsvImportProductExtEvent implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'csvimportproductext.admin.product.csv.import.product.descriptions' => 'hookAdminProductCsvImportProductDescriptions',
'csvimportproductext.admin.product.csv.import.product.check'=> 'hookAdminProductCsvImportProductCheck',
'csvimportproductext.admin.product.csv.import.product.process' => 'hookAdminProductCsvImportProductProcess',
];
}
public function hookAdminProductCsvImportProductDescriptions(EventArgs $event)
{
$header = $event->getArgument('header');
$key = $event->getArgument('key');
if($key == trans('delivery_free_product.product.csv.title')){
$header['description'] = trans('delivery_free_product.admin.product.product_csv.delivery_free_flag_description');
$header['required'] = false;
}
$event->setArgument('header',$header);
}
public function hookAdminProductCsvImportProductCheck(EventArgs $event)
{
$row = $event->getArgument('row');
$lineNo = $event->getArgument('lineNo');
$errors = $event->getArgument('errors');
if(isset($row[trans('delivery_free_product.product.csv.title')])){
if($row[trans('delivery_free_product.product.csv.title')] !== '' && $row[trans('delivery_free_product.product.csv.title')] != 0 && $row[trans('delivery_free_product.product.csv.title')] != 1){
$message = trans('delivery_free_product.product.product_csv.not_correct', [
'%line%' => $lineNo,
'%name%' => trans('delivery_free_product.product.csv.title'),
]);
$errors[] = $message;
}
}
$event->setArgument('errors',$errors);
}
public function hookAdminProductCsvImportProductProcess(EventArgs $event)
{
$row = $event->getArgument('row');
$ProductClass = $event->getArgument('ProductClass');
if(isset($row[trans('delivery_free_product.product.csv.title')])){
$Product = $ProductClass->getProduct();
if($row[trans('delivery_free_product.product.csv.title')] == 1){
$Product->setPlgDeliveryfreeproduct(1);
}else{
$Product->setPlgDeliveryfreeproduct(0);
}
}
}
}