<?php
/*
* Plugin Name : DeliveryPlus4
*
* Copyright (C) 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\DeliveryPlus42\Event;
use Eccube\Event\EventArgs;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CsvImportProductExtEvent implements EventSubscriberInterface
{
/**
* @return array
*/
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('deliveryplus.common.1')){
$header['description'] = trans('deliveryplus.admin.product.product_csv.weight_description');
$header['required'] = false;
}
if($key == trans('deliveryplus.common.2')){
$header['description'] = trans('deliveryplus.admin.product.product_csv.size_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('deliveryplus.common.1')])){
if($row[trans('deliveryplus.common.1')] !== '' && (!is_numeric($row[trans('deliveryplus.common.1')]) || $row[trans('deliveryplus.common.1')] < 0)){
$message = trans('admin.common.csv_invalid_greater_than_zero', [
'%line%' => $lineNo,
'%name%' => trans('deliveryplus.common.1'),
]);
$errors[] = $message;
}
}
if(isset($row[trans('deliveryplus.common.2')])){
if($row[trans('deliveryplus.common.2')] !== '' && (!is_numeric($row[trans('deliveryplus.common.2')]) || $row[trans('deliveryplus.common.2')] < 0)){
$message = trans('admin.common.csv_invalid_greater_than_zero', [
'%line%' => $lineNo,
'%name%' => trans('deliveryplus.common.2'),
]);
$errors[] = $message;
}
}
$event->setArgument('errors',$errors);
}
public function hookAdminProductCsvImportProductProcess(EventArgs $event)
{
$row = $event->getArgument('row');
$ProductClass = $event->getArgument('ProductClass');
if(isset($row[trans('deliveryplus.common.1')])){
if($row[trans('deliveryplus.common.1')] != ''){
$ProductClass->setDeliveryplusWeight($row[trans('deliveryplus.common.1')]);
}else{
$ProductClass->setDeliveryplusWeight(NULL);
}
}
if(isset($row[trans('deliveryplus.common.2')])){
if($row[trans('deliveryplus.common.2')] != ''){
$ProductClass->setDeliveryplusSize($row[trans('deliveryplus.common.2')]);
}else{
$ProductClass->setDeliveryplusSize(NULL);
}
}
}
}