Completed
Pull Request — master (#2110)
by k-yamamura
50:42
created

CsvImportController   D

Complexity

Total Complexity 200

Size/Duplication

Total Lines 1154
Duplicated Lines 19.67 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 70.8%

Importance

Changes 0
Metric Value
dl 227
loc 1154
ccs 388
cts 548
cp 0.708
rs 4.4102
c 0
b 0
f 0
wmc 200
lcom 1
cbo 9

16 Methods

Rating   Name   Duplication   Size   Complexity  
F csvProduct() 59 347 70
D csvCategory() 44 157 26
B csvTemplate() 0 36 4
B render() 0 24 5
B getImportData() 0 39 6
B createProductImage() 0 27 4
C createProductCategory() 9 49 9
C createProductTag() 0 35 7
F createProductClass() 52 136 30
F updateProductClass() 52 141 33
A addErrors() 0 5 1
A getErrors() 0 4 1
A hasErrors() 0 4 1
B getProductCsvHeader() 0 29 1
A getCategoryCsvHeader() 0 9 1
A makeProductCategory() 11 11 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like CsvImportController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use CsvImportController, and based on these observations, apply Extract Interface, too.

1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Controller\Admin\Product;
26
27
use Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Entity\Category;
30
use Eccube\Entity\Product;
31
use Eccube\Entity\ProductCategory;
32
use Eccube\Entity\ProductClass;
33
use Eccube\Entity\ProductImage;
34
use Eccube\Entity\ProductStock;
35
use Eccube\Entity\ProductTag;
36
use Eccube\Exception\CsvImportException;
37
use Eccube\Service\CsvImportService;
38
use Eccube\Util\Str;
39
use Symfony\Component\Filesystem\Filesystem;
40
use Symfony\Component\HttpFoundation\Request;
41
use Symfony\Component\HttpFoundation\StreamedResponse;
42
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
43
44
class CsvImportController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
45
{
46
47
    private $errors = array();
48
49
    private $fileName;
50
51
    private $em;
52
53
    private $productTwig = 'Product/csv_product.twig';
54
55
    private $categoryTwig = 'Product/csv_category.twig';
56
57
58
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
59
     * 商品登録CSVアップロード
60
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
61 3
    public function csvProduct(Application $app, Request $request)
62
    {
63 3
        $form = $app['form.factory']->createBuilder('admin_csv_import')->getForm();
64
65 3
        $headers = $this->getProductCsvHeader();
66
67 3
        if ('POST' === $request->getMethod()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
68
69 3
            $form->handleRequest($request);
70
71 3
            if ($form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
72
73 3
                $formFile = $form['import_file']->getData();
74
75 3
                if (!empty($formFile)) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
76
77 3
                    log_info('商品CSV登録開始');
78
79 3
                    $data = $this->getImportData($app, $formFile);
80 3
                    if ($data === false) {
81
                        $this->addErrors('CSVのフォーマットが一致しません。');
82
                        return $this->render($app, $form, $headers, $this->productTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
83
                    }
84
85 3
                    $keys = array_keys($headers);
86 3
                    $columnHeaders = $data->getColumnHeaders();
87 3
                    if ($keys !== $columnHeaders) {
88
                        $this->addErrors('CSVのフォーマットが一致しません。');
89
                        return $this->render($app, $form, $headers, $this->productTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
90
                    }
91
92 3
                    $size = count($data);
93 3
                    if ($size < 1) {
94
                        $this->addErrors('CSVデータが存在しません。');
95
                        return $this->render($app, $form, $headers, $this->productTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
96
                    }
97
98 3
                    $headerSize = count($keys);
99
100 3
                    $this->em = $app['orm.em'];
101 3
                    $this->em->getConfiguration()->setSQLLogger(null);
102
103 3
                    $this->em->getConnection()->beginTransaction();
104
105 3
                    $BaseInfo = $app['eccube.repository.base_info']->get();
106
107
                    // CSVファイルの登録処理
108 3
                    foreach ($data as $row) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
109
110 3
                        if ($headerSize != count($row)) {
111
                            $this->addErrors(($data->key() + 1) . '行目のCSVフォーマットが一致しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
112
                            return $this->render($app, $form, $headers, $this->productTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
113
                        }
114
115 3
                        if ($row['商品ID'] == '') {
116 2
                            $Product = new Product();
117 2
                            $this->em->persist($Product);
118
                        } else {
119 2
                            if (preg_match('/^\d+$/', $row['商品ID'])) {
120 2
                                $Product = $app['eccube.repository.product']->find($row['商品ID']);
121 2
                                if (!$Product) {
122
                                    $this->addErrors(($data->key() + 1) . '行目の商品IDが存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
123 2
                                    return $this->render($app, $form, $headers, $this->productTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
124
                                }
125
                            } else {
126
                                $this->addErrors(($data->key() + 1) . '行目の商品IDが存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
127
                                return $this->render($app, $form, $headers, $this->productTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
128
                            }
129
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
130
                        }
131
132 3
                        if ($row['公開ステータス(ID)'] == '') {
133
                            $this->addErrors(($data->key() + 1) . '行目の公開ステータス(ID)が設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
134
                        } else {
135 3
                            if (preg_match('/^\d+$/', $row['公開ステータス(ID)'])) {
136 3
                                $Disp = $app['eccube.repository.master.disp']->find($row['公開ステータス(ID)']);
137 3
                                if (!$Disp) {
138
                                    $this->addErrors(($data->key() + 1) . '行目の公開ステータス(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
139
                                } else {
140 3
                                    $Product->setStatus($Disp);
141
                                }
142
                            } else {
143
                                $this->addErrors(($data->key() + 1) . '行目の公開ステータス(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
144
                            }
145
                        }
146
147 3 View Code Duplication
                        if (Str::isBlank($row['商品名'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148
                            $this->addErrors(($data->key() + 1) . '行目の商品名が設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
149
                            return $this->render($app, $form, $headers, $this->productTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
150
                        } else {
151 3
                            $Product->setName(Str::trimAll($row['商品名']));
152
                        }
153
154 3 View Code Duplication
                        if (Str::isNotBlank($row['ショップ用メモ欄'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155 2
                            $Product->setNote(Str::trimAll($row['ショップ用メモ欄']));
156
                        } else {
157 1
                            $Product->setNote(null);
158
                        }
159
160 3 View Code Duplication
                        if (Str::isNotBlank($row['商品説明(一覧)'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
161 3
                            $Product->setDescriptionList(Str::trimAll($row['商品説明(一覧)']));
162
                        } else {
163 1
                            $Product->setDescriptionList(null);
164
                        }
165
166 3 View Code Duplication
                        if (Str::isNotBlank($row['商品説明(詳細)'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
167 3
                            $Product->setDescriptionDetail(Str::trimAll($row['商品説明(詳細)']));
168
                        } else {
169
                            $Product->setDescriptionDetail(null);
170
                        }
171
172 3 View Code Duplication
                        if (Str::isNotBlank($row['検索ワード'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
173 2
                            $Product->setSearchWord(Str::trimAll($row['検索ワード']));
174
                        } else {
175 1
                            $Product->setSearchWord(null);
176
                        }
177
178 3 View Code Duplication
                        if (Str::isNotBlank($row['フリーエリア'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
179 2
                            $Product->setFreeArea(Str::trimAll($row['フリーエリア']));
180
                        } else {
181 1
                            $Product->setFreeArea(null);
182
                        }
183
184 3
                        if ($row['商品削除フラグ'] == '') {
185
                            $Product->setDelFlg(Constant::DISABLED);
186 View Code Duplication
                        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
187 3
                            if ($row['商品削除フラグ'] == (string)Constant::DISABLED || $row['商品削除フラグ'] == (string)Constant::ENABLED) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, a cast statement should be followed by a single space.
Loading history...
188 3
                                $Product->setDelFlg($row['商品削除フラグ']);
189
                            } else {
190
                                $this->addErrors(($data->key() + 1) . '行目の商品削除フラグが設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
191
                                return $this->render($app, $form, $headers, $this->productTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
192
                            }
193
                        }
194
195
                        // 商品画像登録
196 3
                        $this->createProductImage($row, $Product);
197
198 3
                        $this->em->flush($Product);
199
200
                        // 商品カテゴリ登録
201 3
                        $this->createProductCategory($row, $Product, $app, $data);
202
203
                        //タグ登録
204 3
                        $this->createProductTag($row, $Product, $app, $data);
205
206
                        // 商品規格が存在しなければ新規登録
207 3
                        $ProductClasses = $Product->getProductClasses();
208 3
                        if ($ProductClasses->count() < 1) {
209
                            // 規格分類1(ID)がセットされていると規格なし商品、規格あり商品を作成
210 2
                            $ProductClassOrg = $this->createProductClass($row, $Product, $app, $data);
211 2
                            if ($BaseInfo->getOptionProductDeliveryFee() == Constant::ENABLED) {
212
                                if ($row['送料'] != '') {
213
                                    $deliveryFee = str_replace(',', '', $row['送料']);
214
                                    if (preg_match('/^\d+$/', $deliveryFee) && $deliveryFee >= 0) {
215
                                        $ProductClassOrg->setDeliveryFee($deliveryFee);
216
                                    } else {
217
                                        $this->addErrors(($data->key() + 1) . '行目の送料は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
218
                                    }
219
                                }
220
                            }
221
222 2
                            if ($row['規格分類1(ID)'] != '') {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
223
224 1
                                if ($row['規格分類1(ID)'] == $row['規格分類2(ID)']) {
225
                                    $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)と規格分類2(ID)には同じ値を使用できません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
226
                                } else {
227
                                    // 商品規格あり
228
                                    // 企画分類あり商品を作成
229 1
                                    $ProductClass = clone $ProductClassOrg;
230 1
                                    $ProductStock = clone $ProductClassOrg->getProductStock();
231
232
                                    // 規格分類1、規格分類2がnullであるデータの削除フラグを1にセット
233 1
                                    $ProductClassOrg->setDelFlg(Constant::ENABLED);
234
235
                                    // 規格分類1、2をそれぞれセットし作成
236 1
                                    $ClassCategory1 = null;
237 1
                                    if (preg_match('/^\d+$/', $row['規格分類1(ID)'])) {
238 1
                                        $ClassCategory1 = $app['eccube.repository.class_category']->find($row['規格分類1(ID)']);
239 1
                                        if (!$ClassCategory1) {
240
                                            $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
241
                                        } else {
242 1
                                            $ProductClass->setClassCategory1($ClassCategory1);
243
                                        }
244
                                    } else {
245
                                        $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
246
                                    }
247
248 1
                                    if ($row['規格分類2(ID)'] != '') {
249 1
                                        if (preg_match('/^\d+$/', $row['規格分類2(ID)'])) {
250 1
                                            $ClassCategory2 = $app['eccube.repository.class_category']->find($row['規格分類2(ID)']);
251 1 View Code Duplication
                                            if (!$ClassCategory2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
252
                                                $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
253
                                            } else {
254 1
                                                if ($ClassCategory1 &&
255 1
                                                    ($ClassCategory1->getClassName()->getId() == $ClassCategory2->getClassName()->getId())
256
                                                ) {
257
                                                    $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)と規格分類2(ID)の規格名が同じです。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
258
                                                } else {
259 1
                                                    $ProductClass->setClassCategory2($ClassCategory2);
260
                                                }
261
                                            }
262
                                        } else {
263
                                            $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
264
                                        }
265
                                    }
266 1
                                    $ProductClass->setProductStock($ProductStock);
267 1
                                    $ProductStock->setProductClass($ProductClass);
268
269 1
                                    $this->em->persist($ProductClass);
270 1
                                    $this->em->persist($ProductStock);
271
                                }
272
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
273
                            } else {
274 1
                                if ($row['規格分類2(ID)'] != '') {
275 2
                                    $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
276
                                }
277
                            }
278
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
279
                        } else {
280
                            // 商品規格の更新
281
282 2
                            $flag = false;
283 2
                            $classCategoryId1 = $row['規格分類1(ID)'] == '' ? null : $row['規格分類1(ID)'];
284 2
                            $classCategoryId2 = $row['規格分類2(ID)'] == '' ? null : $row['規格分類2(ID)'];
285
286 2
                            foreach ($ProductClasses as $pc) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
287
288 2
                                $classCategory1 = is_null($pc->getClassCategory1()) ? null : $pc->getClassCategory1()->getId();
289 2
                                $classCategory2 = is_null($pc->getClassCategory2()) ? null : $pc->getClassCategory2()->getId();
290
291
                                // 登録されている商品規格を更新
292 2
                                if ($classCategory1 == $classCategoryId1 &&
293 2
                                    $classCategory2 == $classCategoryId2
294
                                ) {
295 1
                                    $this->updateProductClass($row, $Product, $pc, $app, $data);
296
297 1
                                    if ($BaseInfo->getOptionProductDeliveryFee() == Constant::ENABLED) {
298
                                        if ($row['送料'] != '') {
299
                                            $deliveryFee = str_replace(',', '', $row['送料']);
300
                                            if (preg_match('/^\d+$/', $deliveryFee) && $deliveryFee >= 0) {
301
                                                $pc->setDeliveryFee($deliveryFee);
302
                                            } else {
303
                                                $this->addErrors(($data->key() + 1) . '行目の送料は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
304
                                            }
305
                                        }
306
                                    }
307
308 1
                                    $flag = true;
309 2
                                    break;
310
                                }
311
                            }
312
313
                            // 商品規格を登録
314 2
                            if (!$flag) {
315 1
                                $pc = $ProductClasses[0];
316 1
                                if ($pc->getClassCategory1() == null &&
317 1
                                    $pc->getClassCategory2() == null
318
                                ) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
319
320
                                    // 規格分類1、規格分類2がnullであるデータの削除フラグを1にセット
321 1
                                    $pc->setDelFlg(Constant::ENABLED);
322
                                }
323
324 1
                                if ($row['規格分類1(ID)'] == $row['規格分類2(ID)']) {
325
                                    $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)と規格分類2(ID)には同じ値を使用できません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
326
                                } else {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
327
328
                                    // 必ず規格分類1がセットされている
329
                                    // 規格分類1、2をそれぞれセットし作成
330 1
                                    $ClassCategory1 = null;
331 1
                                    if (preg_match('/^\d+$/', $classCategoryId1)) {
332 1
                                        $ClassCategory1 = $app['eccube.repository.class_category']->find($classCategoryId1);
333 1
                                        if (!$ClassCategory1) {
334 1
                                            $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
335
                                        }
336
                                    } else {
337
                                        $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
338
                                    }
339
340 1
                                    $ClassCategory2 = null;
341 1
                                    if ($row['規格分類2(ID)'] != '') {
342 1
                                        if ($pc->getClassCategory1() != null && $pc->getClassCategory2() == null) {
343
                                            $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)は設定できません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
344
                                        } else {
345 1
                                            if (preg_match('/^\d+$/', $classCategoryId2)) {
346 1
                                                $ClassCategory2 = $app['eccube.repository.class_category']->find($classCategoryId2);
347 1 View Code Duplication
                                                if (!$ClassCategory2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
348
                                                    $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
349
                                                } else {
350 1
                                                    if ($ClassCategory1 &&
351 1
                                                        ($ClassCategory1->getClassName()->getId() == $ClassCategory2->getClassName()->getId())
352
                                                    ) {
353 1
                                                        $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)と規格分類2(ID)の規格名が同じです。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
354
                                                    }
355
                                                }
356
                                            } else {
357 1
                                                $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
358
                                            }
359
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
360
                                        }
361
                                    } else {
362
                                        if ($pc->getClassCategory1() != null && $pc->getClassCategory2() != null) {
363
                                            $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)に値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
364
                                        }
365
                                    }
366 1
                                    $ProductClass = $this->createProductClass($row, $Product, $app, $data, $ClassCategory1, $ClassCategory2);
367
368 1
                                    if ($BaseInfo->getOptionProductDeliveryFee() == Constant::ENABLED) {
369
                                        if ($row['送料'] != '') {
370
                                            $deliveryFee = str_replace(',', '', $row['送料']);
371
                                            if (preg_match('/^\d+$/', $deliveryFee) && $deliveryFee >= 0) {
372
                                                $ProductClass->setDeliveryFee($deliveryFee);
373
                                            } else {
374
                                                $this->addErrors(($data->key() + 1) . '行目の送料は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
375
                                            }
376
                                        }
377
                                    }
378
379 1
                                    $Product->addProductClass($ProductClass);
380
                                }
381
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
382
                            }
383
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
384
                        }
385
386
387 3
                        if ($this->hasErrors()) {
388
                            return $this->render($app, $form, $headers, $this->productTwig);
389
                        }
390
391 3
                        $this->em->persist($Product);
392
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
393
                    }
394
395 3
                    $this->em->flush();
396 3
                    $this->em->getConnection()->commit();
397
398 3
                    log_info('商品CSV登録完了');
399
400 3
                    $app->addSuccess('admin.product.csv_import.save.complete', 'admin');
401
                }
402
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
403
            }
404
        }
405
406 3
        return $this->render($app, $form, $headers, $this->productTwig);
407
    }
408
409
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
410
     * カテゴリ登録CSVアップロード
411
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
412 2
    public function csvCategory(Application $app, Request $request)
413
    {
414
415 2
        $form = $app['form.factory']->createBuilder('admin_csv_import')->getForm();
416
417 2
        $headers = $this->getCategoryCsvHeader();
418
419 2
        if ('POST' === $request->getMethod()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
420
421 2
            $form->handleRequest($request);
422
423 2
            if ($form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
424
425 2
                $formFile = $form['import_file']->getData();
426
427 2
                if (!empty($formFile)) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
428
429 2
                    log_info('カテゴリCSV登録開始');
430
431 2
                    $data = $this->getImportData($app, $formFile);
432 2 View Code Duplication
                    if ($data === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
433
                        $this->addErrors('CSVのフォーマットが一致しません。');
434
                        return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
435
                    }
436
437 2
                    $keys = array_keys($headers);
438 2
                    $columnHeaders = $data->getColumnHeaders();
439 2
                    if ($keys !== $columnHeaders) {
440
                        $this->addErrors('CSVのフォーマットが一致しません。');
441
                        return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
442
                    }
443
444 2
                    $size = count($data);
445 2
                    if ($size < 1) {
446
                        $this->addErrors('CSVデータが存在しません。');
447
                        return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
448
                    }
449
450 2
                    $headerSize = count($keys);
451
452 2
                    $this->em = $app['orm.em'];
453 2
                    $this->em->getConfiguration()->setSQLLogger(null);
454
455 2
                    $this->em->getConnection()->beginTransaction();
456
457
                    // CSVファイルの登録処理
458 2
                    foreach ($data as $row) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
459
460 2
                        if ($headerSize != count($row)) {
461
                            $this->addErrors(($data->key() + 1) . '行目のCSVフォーマットが一致しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
462
                            return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
463
                        }
464
465 2
                        if ($row['カテゴリID'] == '') {
466 1
                            $Category = new Category();
467
                        } else {
468 1 View Code Duplication
                            if (!preg_match('/^\d+$/', $row['カテゴリID'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
469
                                $this->addErrors(($data->key() + 1) . '行目のカテゴリIDが存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
470
                                return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
471
                            }
472 1
                            $Category = $app['eccube.repository.category']->find($row['カテゴリID']);
473 1 View Code Duplication
                            if (!$Category) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
474
                                $this->addErrors(($data->key() + 1) . '行目のカテゴリIDが存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
475
                                return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
476
                            }
477 1 View Code Duplication
                            if ($row['カテゴリID'] == $row['親カテゴリID']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
478
                                $this->addErrors(($data->key() + 1) . '行目のカテゴリIDと親カテゴリIDが同じです。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
479
                                return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
480
                            }
481
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
482
                        }
483
484 2 View Code Duplication
                        if (Str::isBlank($row['カテゴリ名'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
485
                            $this->addErrors(($data->key() + 1) . '行目のカテゴリ名が設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
486
                            return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
487
                        } else {
488 2
                            $Category->setName(Str::trimAll($row['カテゴリ名']));
489
                        }
490
491 2
                        if ($row['親カテゴリID'] != '') {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
492
493 1 View Code Duplication
                            if (!preg_match('/^\d+$/', $row['親カテゴリID'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
494
                                $this->addErrors(($data->key() + 1) . '行目の親カテゴリIDが存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
495
                                return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
496
                            }
497
498 1
                            $ParentCategory = $app['eccube.repository.category']->find($row['親カテゴリID']);
499 1 View Code Duplication
                            if (!$ParentCategory) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
500
                                $this->addErrors(($data->key() + 1) . '行目の親カテゴリIDが存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
501 1
                                return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
502
                            }
503
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
504
                        } else {
505 2
                            $ParentCategory = null;
506
                        }
507
508 2
                        $Category->setParent($ParentCategory);
509 2
                        if ($ParentCategory) {
510 1
                            $Category->setLevel($ParentCategory->getLevel() + 1);
511
                        } else {
512 2
                            $Category->setLevel(1);
513
                        }
514
515 2 View Code Duplication
                        if ($app['config']['category_nest_level'] < $Category->getLevel()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
516
                            $this->addErrors(($data->key() + 1) . '行目のカテゴリが最大レベルを超えているため設定できません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
517
                            return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
518
                        }
519
520
                        // カテゴリ削除フラグ対応
521 2
                        if ($row['カテゴリ削除フラグ'] == '') {
522 2
                            $Category->setDelFlg(Constant::DISABLED);
523 2
                            $status = $app['eccube.repository.category']->save($Category);
524
                        } else {
525 1 View Code Duplication
                            if ($row['カテゴリ削除フラグ'] == (string)Constant::DISABLED || $row['カテゴリ削除フラグ'] == (string)Constant::ENABLED) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
As per coding-style, a cast statement should be followed by a single space.
Loading history...
526 1
                                $Category->setDelFlg($row['カテゴリ削除フラグ']);
527
                            } else {
528
                                $this->addErrors(($data->key() + 1) . '行目のカテゴリ削除フラグが設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
529
                                return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
530
                            }
531
532 1
                            if ($row['カテゴリ削除フラグ'] == (string)Constant::ENABLED) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, a cast statement should be followed by a single space.
Loading history...
533
                                $status = $app['eccube.repository.category']->delete($Category);
534
535 View Code Duplication
                                if (!$status) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
536
                                    $this->addErrors(($data->key() + 1) . '行目のカテゴリが、子カテゴリまたは商品が紐付いているため削除できません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
537
                                    return $this->render($app, $form, $headers, $this->categoryTwig);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
538
                                }
539
                            } else {
540 1
                                $status = $app['eccube.repository.category']->save($Category);
541
                            }
542
                        }
543
544 2
                        if (!$status) {
545
                            $this->addErrors(($data->key() + 1) . '行目のカテゴリが設定できません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
546
                        }
547
548 2
                        if ($this->hasErrors()) {
549
                            return $this->render($app, $form, $headers, $this->categoryTwig);
550
                        }
551
552 2
                        $this->em->persist($Category);
553
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
554
                    }
555
556 2
                    $this->em->flush();
557 2
                    $this->em->getConnection()->commit();
558
559 2
                    log_info('カテゴリCSV登録完了');
560
561 2
                    $app->addSuccess('admin.category.csv_import.save.complete', 'admin');
562
                }
563
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
564
            }
565
        }
566
567 2
        return $this->render($app, $form, $headers, $this->categoryTwig);
568
    }
569
570
571
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$type" missing
Loading history...
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
572
     * アップロード用CSV雛形ファイルダウンロード
573
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
574
    public function csvTemplate(Application $app, Request $request, $type)
575
    {
576
        set_time_limit(0);
577
578
        $response = new StreamedResponse();
579
580
        if ($type == 'product') {
581
            $headers = $this->getProductCsvHeader();
582
            $filename = 'product.csv';
583
        } else if ($type == 'category') {
584
            $headers = $this->getCategoryCsvHeader();
585
            $filename = 'category.csv';
586
        } else {
587
            throw new NotFoundHttpException();
588
        }
589
590
        $response->setCallback(function () use ($app, $request, $headers) {
591
592
            // ヘッダ行の出力
593
            $row = array();
594
            foreach ($headers as $key => $value) {
595
                $row[] = mb_convert_encoding($key, $app['config']['csv_export_encoding'], 'UTF-8');
596
            }
597
598
            $fp = fopen('php://output', 'w');
599
            fputcsv($fp, $row, $app['config']['csv_export_separator']);
600
            fclose($fp);
601
602
        });
603
604
        $response->headers->set('Content-Type', 'application/octet-stream');
605
        $response->headers->set('Content-Disposition', 'attachment; filename=' . $filename);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
606
        $response->send();
607
608
        return $response;
609
    }
610
611
612
    /**
613
     * 登録、更新時のエラー画面表示
614
     *
615
     */
616 5
    protected function render($app, $form, $headers, $twig)
617
    {
618
619 5
        if ($this->hasErrors()) {
620
            if ($this->em) {
621
                $this->em->getConnection()->rollback();
622
            }
623
        }
624
625 5
        if (!empty($this->fileName)) {
626
            try {
627 5
                $fs = new Filesystem();
628 5
                $fs->remove($app['config']['csv_temp_realdir'] . '/' . $this->fileName);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
629
            } catch (\Exception $e) {
630
                // エラーが発生しても無視する
631
            }
632
        }
633
634 5
        return $app->render($twig, array(
635 5
            'form' => $form->createView(),
636 5
            'headers' => $headers,
637 5
            'errors' => $this->errors,
638
        ));
639
    }
640
641
642
    /**
643
     * アップロードされたCSVファイルの行ごとの処理
644
     *
645
     * @param $formFile
646
     * @return CsvImportService
647
     */
648 5
    protected function getImportData($app, $formFile)
649
    {
650
        // アップロードされたCSVファイルを一時ディレクトリに保存
651 5
        $this->fileName = 'upload_' . Str::random() . '.' . $formFile->getClientOriginalExtension();
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
652 5
        $formFile->move($app['config']['csv_temp_realdir'], $this->fileName);
653
654 5
        $file = file_get_contents($app['config']['csv_temp_realdir'] . '/' . $this->fileName);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
655
656 5
        if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID >= 70000) {
657
            // Windows 環境の PHP7 の場合はファイルエンコーディングを CP932 に合わせる
658
            // see https://github.com/EC-CUBE/ec-cube/issues/1780
659
            setlocale(LC_ALL, ''); // 既定のロケールに設定
660
            if (mb_detect_encoding($file) === 'UTF-8') { // UTF-8 を検出したら SJIS-win に変換
661
                $file = mb_convert_encoding($file, 'SJIS-win', 'UTF-8');
662
            }
663
        } else {
664
            // アップロードされたファイルがUTF-8以外は文字コード変換を行う
665 5
            $encode = Str::characterEncoding(substr($file, 0, 6));
666 5
            if ($encode != 'UTF-8') {
667 2
                $file = mb_convert_encoding($file, 'UTF-8', $encode);
668
            }
669
        }
670 5
        $file = Str::convertLineFeed($file);
671
672 5
        $tmp = tmpfile();
673 5
        fwrite($tmp, $file);
674 5
        rewind($tmp);
675 5
        $meta = stream_get_meta_data($tmp);
676 5
        $file = new \SplFileObject($meta['uri']);
677
678 5
        set_time_limit(0);
679
680
        // アップロードされたCSVファイルを行ごとに取得
681 5
        $data = new CsvImportService($file, $app['config']['csv_import_delimiter'], $app['config']['csv_import_enclosure']);
682
683 5
        $ret = $data->setHeaderRowNumber(0);
684
685 5
        return ($ret !== false) ? $data : false;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression $ret !== false ? $data : false; of type Eccube\Service\CsvImportService|false adds false to the return on line 685 which is incompatible with the return type documented by Eccube\Controller\Admin\...ntroller::getImportData of type Eccube\Service\CsvImportService. It seems like you forgot to handle an error condition.
Loading history...
686
    }
687
688
689
    /**
690
     * 商品画像の削除、登録
691
     */
692 3
    protected function createProductImage($row, Product $Product)
693
    {
694 3
        if ($row['商品画像'] != '') {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
695
696
            // 画像の削除
697 3
            $ProductImages = $Product->getProductImage();
698 3
            foreach ($ProductImages as $ProductImage) {
699 2
                $Product->removeProductImage($ProductImage);
700 3
                $this->em->remove($ProductImage);
701
            }
702
703
            // 画像の登録
704 3
            $images = explode(',', $row['商品画像']);
705 3
            $rank = 1;
706 3
            foreach ($images as $image) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
707
708 3
                $ProductImage = new ProductImage();
709 3
                $ProductImage->setFileName(Str::trimAll($image));
710 3
                $ProductImage->setProduct($Product);
711 3
                $ProductImage->setRank($rank);
712
713 3
                $Product->addProductImage($ProductImage);
714 3
                $rank++;
715 3
                $this->em->persist($ProductImage);
716
            }
717
        }
718
    }
719
720
721
    /**
722
     * 商品カテゴリの削除、登録
723
     */
724 3
    protected function createProductCategory($row, Product $Product, $app, $data)
725
    {
726
        // カテゴリの削除
727 3
        $ProductCategories = $Product->getProductCategories();
728 3
        foreach ($ProductCategories as $ProductCategory) {
729 2
            $Product->removeProductCategory($ProductCategory);
730 2
            $this->em->remove($ProductCategory);
731 3
            $this->em->flush($ProductCategory);
732
        }
733
734 3
        if ($row['商品カテゴリ(ID)'] == '') {
735
            // 入力されていなければ削除のみ
736
            return;
737
        }
738
739
        // カテゴリの登録
740 3
        $categories = explode(',', $row['商品カテゴリ(ID)']);
741 3
        $rank = 1;
742 3
        $categoriesIdList = array();
743 3
        foreach ($categories as $category) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
744
745 3
            if (preg_match('/^\d+$/', $category)) {
746 3
                $Category = $app['eccube.repository.category']->find($category);
747 3
                if (!$Category) {
748
                    $this->addErrors(($data->key() + 1).'行目の商品カテゴリ(ID)「'.$category.'」が存在しません。');
749
                } else {
750 3 View Code Duplication
                    foreach($Category->getPath() as $ParentCategory){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
751 3
                        if (!isset($categoriesIdList[$ParentCategory->getId()])){
752 3
                            $ProductCategory = $this->makeProductCategory($Product, $ParentCategory, $rank);
753 3
                            $app['orm.em']->persist($ProductCategory);
754 3
                            $rank++;
755 3
                            $Product->addProductCategory($ProductCategory);
756 3
                            $categoriesIdList[$ParentCategory->getId()] = true;
757
                        }
758
                    }
759 3
                    if (!isset($categoriesIdList[$Category->getId()])){
760
                        $ProductCategory = $this->makeProductCategory($Product, $Category, $rank);
761
                        $rank++;
762
                        $this->em->persist($ProductCategory);
763
                        $Product->addProductCategory($ProductCategory);
764 3
                        $categoriesIdList[$Category->getId()] = true;
765
                    }
766
                }
767
            } else {
768 3
                $this->addErrors(($data->key() + 1).'行目の商品カテゴリ(ID)「'.$category.'」が存在しません。');
769
            }
770
        }
771
772
    }
773
774
775
    /**
776
     * タグの登録
777
     *
778
     * @param array $row
779
     * @param Product $Product
780
     * @param Application $app
781
     * @param CsvImportService $data
782
     */
783 3
    protected function createProductTag($row, Product $Product, $app, $data)
784
    {
785
        // タグの削除
786 3
        $ProductTags = $Product->getProductTag();
787 3
        foreach ($ProductTags as $ProductTags) {
788 1
            $Product->removeProductTag($ProductTags);
789 3
            $this->em->remove($ProductTags);
790
        }
791
792 3
        if ($row['タグ(ID)'] == '') {
793
            return;
794
        }
795
796
        // タグの登録
797 3
        $tags = explode(',', $row['タグ(ID)']);
798 3
        foreach ($tags as $tag_id) {
799 3
            $Tag = null;
800 3
            if (preg_match('/^\d+$/', $tag_id)) {
801 3
                $Tag = $app['eccube.repository.master.tag']->find($tag_id);
802 3
                if ($Tag) {
803 3
                    $ProductTags = new ProductTag();
804
                    $ProductTags
805 3
                        ->setProduct($Product)
806 3
                        ->setTag($Tag);
807
808 3
                    $Product->addProductTag($ProductTags);
809
810 3
                    $this->em->persist($ProductTags);
811
                }
812
            }
813 3
            if (!$Tag) {
814 3
                $this->addErrors(($data->key() + 1) . '行目のタグ(ID)「' . $tag_id . '」が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
815
            }
816
        }
817
    }
818
819
820
    /**
821
     * 商品規格分類1、商品規格分類2がnullとなる商品規格情報を作成
822
     */
823 3
    protected function createProductClass($row, Product $Product, $app, $data, $ClassCategory1 = null, $ClassCategory2 = null)
824
    {
825
        // 規格分類1、規格分類2がnullとなる商品を作成
826
827 3
        $ProductClass = new ProductClass();
828 3
        $ProductClass->setProduct($Product);
829
830
831 3 View Code Duplication
        if ($row['商品種別(ID)'] == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
832
            $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
833
        } else {
834 3
            if (preg_match('/^\d+$/', $row['商品種別(ID)'])) {
835 3
                $ProductType = $app['eccube.repository.master.product_type']->find($row['商品種別(ID)']);
836 3
                if (!$ProductType) {
837
                    $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
838
                } else {
839 3
                    $ProductClass->setProductType($ProductType);
840
                }
841
            } else {
842
                $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
843
            }
844
        }
845
846 3
        $ProductClass->setClassCategory1($ClassCategory1);
847 3
        $ProductClass->setClassCategory2($ClassCategory2);
848
849 3
        if ($row['発送日目安(ID)'] != '') {
850 2
            if (preg_match('/^\d+$/', $row['発送日目安(ID)'])) {
851 2
                $DeliveryDate = $app['eccube.repository.delivery_date']->find($row['発送日目安(ID)']);
852 2
                if (!$DeliveryDate) {
853
                    $this->addErrors(($data->key() + 1) . '行目の発送日目安(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
854
                } else {
855 2
                    $ProductClass->setDeliveryDate($DeliveryDate);
856
                }
857
            } else {
858
                $this->addErrors(($data->key() + 1) . '行目の発送日目安(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
859
            }
860
        }
861
862 3 View Code Duplication
        if (Str::isNotBlank($row['商品コード'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
863 2
            $ProductClass->setCode(Str::trimAll($row['商品コード']));
864
        } else {
865 1
            $ProductClass->setCode(null);
866
        }
867
868 3 View Code Duplication
        if ($row['在庫数無制限フラグ'] == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
869
            $this->addErrors(($data->key() + 1) . '行目の在庫数無制限フラグが設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
870
        } else {
871 3
            if ($row['在庫数無制限フラグ'] == (string) Constant::DISABLED) {
872 3
                $ProductClass->setStockUnlimited(Constant::DISABLED);
873
                // 在庫数が設定されていなければエラー
874 3
                if ($row['在庫数'] == '') {
875
                    $this->addErrors(($data->key() + 1) . '行目の在庫数が設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
876
                } else {
877 3
                    $stock = str_replace(',', '', $row['在庫数']);
878 3
                    if (preg_match('/^\d+$/', $stock) && $stock >= 0) {
879 3
                        $ProductClass->setStock($stock);
880
                    } else {
881 3
                        $this->addErrors(($data->key() + 1) . '行目の在庫数は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
882
                    }
883
                }
884
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
885
            } else if ($row['在庫数無制限フラグ'] == (string) Constant::ENABLED) {
886
                $ProductClass->setStockUnlimited(Constant::ENABLED);
887
                $ProductClass->setStock(null);
888
            } else {
889
                $this->addErrors(($data->key() + 1) . '行目の在庫数無制限フラグが設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
890
            }
891
        }
892
893 3
        if ($row['販売制限数'] != '') {
894
            $saleLimit = str_replace(',', '', $row['販売制限数']);
895
            if (preg_match('/^\d+$/', $saleLimit) && $saleLimit >= 0) {
896
                $ProductClass->setSaleLimit($saleLimit);
897
            } else {
898
                $this->addErrors(($data->key() + 1) . '行目の販売制限数は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
899
            }
900
        }
901
902 3
        if ($row['通常価格'] != '') {
903 2
            $price01 = str_replace(',', '', $row['通常価格']);
904 2
            if (preg_match('/^\d+$/', $price01) && $price01 >= 0) {
905 2
                $ProductClass->setPrice01($price01);
906
            } else {
907
                $this->addErrors(($data->key() + 1) . '行目の通常価格は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
908
            }
909
        }
910
911 3
        if ($row['販売価格'] == '') {
912
            $this->addErrors(($data->key() + 1) . '行目の販売価格が設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
913
        } else {
914 3
            $price02 = str_replace(',', '', $row['販売価格']);
915 3
            if (preg_match('/^\d+$/', $price02) && $price02 >= 0) {
916 3
                $ProductClass->setPrice02($price02);
917
            } else {
918
                $this->addErrors(($data->key() + 1) . '行目の販売価格は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
919
            }
920
        }
921
922 3
        if ($row['送料'] != '') {
923 2
            $delivery_fee = str_replace(',', '', $row['送料']);
924 2
            if (preg_match('/^\d+$/', $delivery_fee) && $delivery_fee >= 0) {
925 2
                $ProductClass->setDeliveryFee($delivery_fee);
926
            } else {
927
                $this->addErrors(($data->key() + 1) . '行目の送料は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
928
            }
929
        }
930
931 3 View Code Duplication
        if ($row['商品規格削除フラグ'] == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
932
            $ProductClass->setDelFlg(Constant::DISABLED);
933
        } else {
934 3
            if ($row['商品規格削除フラグ'] == (string) Constant::DISABLED || $row['商品規格削除フラグ'] == (string) Constant::ENABLED) {
935 3
                $ProductClass->setDelFlg($row['商品規格削除フラグ']);
936
            } else {
937
                $this->addErrors(($data->key() + 1) . '行目の商品規格削除フラグが設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
938
            }
939
        }
940
941 3
        $Product->addProductClass($ProductClass);
942 3
        $ProductStock = new ProductStock();
943 3
        $ProductClass->setProductStock($ProductStock);
944 3
        $ProductStock->setProductClass($ProductClass);
945
946 3
        if (!$ProductClass->getStockUnlimited()) {
947 3
            $ProductStock->setStock($ProductClass->getStock());
948
        } else {
949
            // 在庫無制限時はnullを設定
950
            $ProductStock->setStock(null);
951
        }
952
953 3
        $this->em->persist($ProductClass);
954 3
        $this->em->persist($ProductStock);
955
956 3
        return $ProductClass;
957
958
    }
959
960
961
    /**
962
     * 商品規格情報を更新
963
     */
964 1
    protected function updateProductClass($row, Product $Product, ProductClass $ProductClass, $app, $data)
965
    {
966
967 1
        $ProductClass->setProduct($Product);
968
969 1 View Code Duplication
        if ($row['商品種別(ID)'] == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
970
            $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
971
        } else {
972 1
            if (preg_match('/^\d+$/', $row['商品種別(ID)'])) {
973 1
                $ProductType = $app['eccube.repository.master.product_type']->find($row['商品種別(ID)']);
974 1
                if (!$ProductType) {
975
                    $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
976
                } else {
977 1
                    $ProductClass->setProductType($ProductType);
978
                }
979
            } else {
980
                $this->addErrors(($data->key() + 1) . '行目の商品種別(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
981
            }
982
        }
983
984
        // 規格分類1、2をそれぞれセットし作成
985 1
        if ($row['規格分類1(ID)'] != '') {
986 1
            if (preg_match('/^\d+$/', $row['規格分類1(ID)'])) {
987 1
                $ClassCategory = $app['eccube.repository.class_category']->find($row['規格分類1(ID)']);
988 1
                if (!$ClassCategory) {
989
                    $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
990
                } else {
991 1
                    $ProductClass->setClassCategory1($ClassCategory);
992
                }
993
            } else {
994
                $this->addErrors(($data->key() + 1) . '行目の規格分類1(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
995
            }
996
        }
997
998 1
        if ($row['規格分類2(ID)'] != '') {
999 1
            if (preg_match('/^\d+$/', $row['規格分類2(ID)'])) {
1000 1
                $ClassCategory = $app['eccube.repository.class_category']->find($row['規格分類2(ID)']);
1001 1
                if (!$ClassCategory) {
1002
                    $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1003
                } else {
1004 1
                    $ProductClass->setClassCategory2($ClassCategory);
1005
                }
1006
            } else {
1007
                $this->addErrors(($data->key() + 1) . '行目の規格分類2(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1008
            }
1009
        }
1010
1011 1
        if ($row['発送日目安(ID)'] != '') {
1012
            if (preg_match('/^\d+$/', $row['発送日目安(ID)'])) {
1013
                $DeliveryDate = $app['eccube.repository.delivery_date']->find($row['発送日目安(ID)']);
1014
                if (!$DeliveryDate) {
1015
                    $this->addErrors(($data->key() + 1) . '行目の発送日目安(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1016
                } else {
1017
                    $ProductClass->setDeliveryDate($DeliveryDate);
1018
                }
1019
            } else {
1020
                $this->addErrors(($data->key() + 1) . '行目の発送日目安(ID)が存在しません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1021
            }
1022
        }
1023
1024 1 View Code Duplication
        if (Str::isNotBlank($row['商品コード'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1025 1
            $ProductClass->setCode(Str::trimAll($row['商品コード']));
1026
        } else {
1027
            $ProductClass->setCode(null);
1028
        }
1029
1030 1 View Code Duplication
        if ($row['在庫数無制限フラグ'] == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1031
            $this->addErrors(($data->key() + 1) . '行目の在庫数無制限フラグが設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1032
        } else {
1033 1
            if ($row['在庫数無制限フラグ'] == (string) Constant::DISABLED) {
1034 1
                $ProductClass->setStockUnlimited(Constant::DISABLED);
1035
                // 在庫数が設定されていなければエラー
1036 1
                if ($row['在庫数'] == '') {
1037
                    $this->addErrors(($data->key() + 1) . '行目の在庫数が設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1038
                } else {
1039 1
                    $stock = str_replace(',', '', $row['在庫数']);
1040 1
                    if (preg_match('/^\d+$/', $stock) && $stock >= 0) {
1041 1
                        $ProductClass->setStock($row['在庫数']);
1042
                    } else {
1043 1
                        $this->addErrors(($data->key() + 1) . '行目の在庫数は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1044
                    }
1045
                }
1046
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
1047 1
            } else if ($row['在庫数無制限フラグ'] == (string) Constant::ENABLED) {
1048 1
                $ProductClass->setStockUnlimited(Constant::ENABLED);
1049 1
                $ProductClass->setStock(null);
1050
            } else {
1051
                $this->addErrors(($data->key() + 1) . '行目の在庫数無制限フラグが設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1052
            }
1053
        }
1054
1055 1
        if ($row['販売制限数'] != '') {
1056 1
            $saleLimit = str_replace(',', '', $row['販売制限数']);
1057 1
            if (preg_match('/^\d+$/', $saleLimit) && $saleLimit >= 0) {
1058 1
                $ProductClass->setSaleLimit($saleLimit);
1059
            } else {
1060
                $this->addErrors(($data->key() + 1) . '行目の販売制限数は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1061
            }
1062
        }
1063
1064 1
        if ($row['通常価格'] != '') {
1065 1
            $price01 = str_replace(',', '', $row['通常価格']);
1066 1
            if (preg_match('/^\d+$/', $price01) && $price01 >= 0) {
1067 1
                $ProductClass->setPrice01($price01);
1068
            } else {
1069
                $this->addErrors(($data->key() + 1) . '行目の通常価格は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1070
            }
1071
        }
1072
1073 1
        if ($row['販売価格'] == '') {
1074
            $this->addErrors(($data->key() + 1) . '行目の販売価格が設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1075
        } else {
1076 1
            $price02 = str_replace(',', '', $row['販売価格']);
1077 1
            if (preg_match('/^\d+$/', $price02) && $price02 >= 0) {
1078 1
                $ProductClass->setPrice02($price02);
1079
            } else {
1080
                $this->addErrors(($data->key() + 1) . '行目の販売価格は0以上の数値を設定してください。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1081
            }
1082
        }
1083
1084 1 View Code Duplication
        if ($row['商品規格削除フラグ'] == '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1085
            $ProductClass->setDelFlg(Constant::DISABLED);
1086
        } else {
1087 1
            if ($row['商品規格削除フラグ'] == (string) Constant::DISABLED || $row['商品規格削除フラグ'] == (string) Constant::ENABLED) {
1088 1
                $ProductClass->setDelFlg($row['商品規格削除フラグ']);
1089
            } else {
1090
                $this->addErrors(($data->key() + 1) . '行目の商品規格削除フラグが設定されていません。');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1091
            }
1092
        }
1093
1094 1
        $ProductStock = $ProductClass->getProductStock();
1095
1096 1
        if (!$ProductClass->getStockUnlimited()) {
1097 1
            $ProductStock->setStock($ProductClass->getStock());
1098
        } else {
1099
            // 在庫無制限時はnullを設定
1100 1
            $ProductStock->setStock(null);
1101
        }
1102
1103 1
        return $ProductClass;
1104
    }
1105
1106
    /**
1107
     * 登録、更新時のエラー画面表示
1108
     *
1109
     */
1110
    protected function addErrors($message)
1111
    {
1112
        $e = new CsvImportException($message);
1113
        $this->errors[] = $e;
1114
    }
1115
1116
    /**
1117
     * @return array
1118
     */
1119 5
    protected function getErrors()
1120
    {
1121 5
        return $this->errors;
1122
    }
1123
1124
    /**
1125
     *
1126
     * @return boolean
1127
     */
1128 5
    protected function hasErrors()
1129
    {
1130 5
        return count($this->getErrors()) > 0;
1131
    }
1132
1133
    /**
1134
     * 商品登録CSVヘッダー定義
1135
     */
1136 3
    private function getProductCsvHeader()
1137
    {
1138
        return array(
1139 3
            '商品ID' => 'id',
1140
            '公開ステータス(ID)' => 'status',
1141
            '商品名' => 'name',
1142
            'ショップ用メモ欄' => 'note',
1143
            '商品説明(一覧)' => 'description_list',
1144
            '商品説明(詳細)' => 'description_detail',
1145
            '検索ワード' => 'search_word',
1146
            'フリーエリア' => 'free_area',
1147
            '商品削除フラグ' => 'product_del_flg',
1148
            '商品画像' => 'product_image',
1149
            '商品カテゴリ(ID)' => 'product_category',
1150
            'タグ(ID)' => 'product_tag',
1151
            '商品種別(ID)' => 'product_type',
1152
            '規格分類1(ID)' => 'class_category1',
1153
            '規格分類2(ID)' => 'class_category2',
1154
            '発送日目安(ID)' => 'deliveryFee',
1155
            '商品コード' => 'product_code',
1156
            '在庫数' => 'stock',
1157
            '在庫数無制限フラグ' => 'stock_unlimited',
1158
            '販売制限数' => 'sale_limit',
1159
            '通常価格' => 'price01',
1160
            '販売価格' => 'price02',
1161
            '送料' => 'delivery_fee',
1162
            '商品規格削除フラグ' => 'product_class_del_flg',
1163
        );
1164
    }
1165
1166
1167
    /**
1168
     * カテゴリCSVヘッダー定義
1169
     */
1170 2
    private function getCategoryCsvHeader()
1171
    {
1172
        return array(
1173 2
            'カテゴリID' => 'id',
1174
            'カテゴリ名' => 'category_name',
1175
            '親カテゴリID' => 'parent_category_id',
1176
            'カテゴリ削除フラグ' => 'category_del_flg',
1177
        );
1178
    }
1179
    
0 ignored issues
show
introduced by
Please trim any trailing whitespace
Loading history...
1180
        /**
1181
     * ProductCategory作成
1182
     * @param \Eccube\Entity\Product $Product
1183
     * @param \Eccube\Entity\Category $Category
1184
     * @return ProductCategory
1185
     */
1186 3 View Code Duplication
    private function makeProductCategory($Product, $Category, $rank)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1187
    {
1188 3
        $ProductCategory = new ProductCategory();
1189 3
        $ProductCategory->setProduct($Product);
1190 3
        $ProductCategory->setProductId($Product->getId());
1191 3
        $ProductCategory->setCategory($Category);
1192 3
        $ProductCategory->setCategoryId($Category->getId());
1193 3
        $ProductCategory->setRank($rank);
1194
        
0 ignored issues
show
introduced by
Please trim any trailing whitespace
Loading history...
1195 3
        return $ProductCategory;
1196
    }
1197
}
1198