Skip to content

Commit

Permalink
refactor level to hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
dotani1111 committed Nov 15, 2024
1 parent 85d0c5b commit d4c2dcd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/config/eccube/packages/eccube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ parameters:
eccube_id_max_len: 50
eccube_id_min_len: 4
eccube_int_len: 9 # 最大値で制御したい
eccube_category_nest_level: 5
eccube_category_nest_hierarchy: 5
eccube_lltext_len: 99999
eccube_ltext_len: 3000
eccube_max_total_fee: 9999999999
Expand Down
2 changes: 1 addition & 1 deletion src/Eccube/Controller/Admin/Product/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function index(Request $request, CacheUtil $cacheUtil, $parent_id = null,
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($this->eccubeConfig['eccube_category_nest_level'] < $TargetCategory->getHierarchy()) {
if ($this->eccubeConfig['eccube_category_nest_hierarchy'] < $TargetCategory->getHierarchy()) {
throw new BadRequestHttpException();
}
log_info('カテゴリ登録開始', [$id]);
Expand Down
12 changes: 6 additions & 6 deletions src/Eccube/Controller/Admin/Product/CsvImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,24 +811,24 @@ public function csvCategory(Request $request, CacheUtil $cacheUtil)
}
$Category->setParent($ParentCategory);

// Level
// hierarchy
if (isset($row['階層']) && StringUtil::isNotBlank($row['階層'])) {
if ($ParentCategory == null && $row['階層'] != 1) {
$this->addErrors(($data->key() + 1).'行目の親カテゴリIDが存在しません。');

return $this->renderWithError($form, $headers);
}
$level = StringUtil::trimAll($row['階層']);
$hierarchy = StringUtil::trimAll($row['階層']);
} else {
$level = 1;
$hierarchy = 1;
if ($ParentCategory) {
$level = $ParentCategory->getHierarchy() + 1;
$hierarchy = $ParentCategory->getHierarchy() + 1;
}
}

$Category->setHierarchy($level);
$Category->setHierarchy($hierarchy);

if ($this->eccubeConfig['eccube_category_nest_level'] < $Category->getHierarchy()) {
if ($this->eccubeConfig['eccube_category_nest_hierarchy'] < $Category->getHierarchy()) {
$this->addErrors(($data->key() + 1).'行目のカテゴリが最大レベルを超えているため設定できません。');

return $this->renderWithError($form, $headers);
Expand Down
2 changes: 1 addition & 1 deletion src/Eccube/Resource/doctrine/import_csv/ja/dtb_csv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
"200","5",,"Eccube\\Entity\\Category","sort_no",,"表示ランク","2","1","2017-03-07 10:14:00","2017-03-07 10:14:00","csv"
"201","5",,"Eccube\\Entity\\Category","name",,"カテゴリ名","3","1","2017-03-07 10:14:00","2017-03-07 10:14:00","csv"
"202","5",,"Eccube\\Entity\\Category","Parent","id","親カテゴリID","4","1","2017-03-07 10:14:00","2017-03-07 10:14:00","csv"
"203","5",,"Eccube\\Entity\\Category","level",,"階層","5","1","2017-03-07 10:14:00","2017-03-07 10:14:00","csv"
"203","5",,"Eccube\\Entity\\Category","hierarchy",,"階層","5","1","2017-03-07 10:14:00","2017-03-07 10:14:00","csv"
"204","1",,"Eccube\\Entity\\ProductClass","TaxRule","tax_rate","税率","31","0","2017-03-07 10:14:00","2017-03-07 10:14:00","csv"
"205","2",,"Eccube\\Entity\\Customer","point",,"ポイント","33","1","2017-03-07 10:14:00","2017-03-07 10:14:00","csv"
"206","1",,"Eccube\\Entity\\ProductClass","visible",,"商品規格表示フラグ","32","0","2022-11-24 00:00:00","2022-11-24 00:00:00","csv"
Expand Down
8 changes: 4 additions & 4 deletions src/Eccube/Resource/template/admin/Product/category.twig
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ file that was distributed with this source code.
<form role="form" name="form1" id="form1" method="post"
action="{% if TargetCategory.id %}{{ path('admin_product_category_edit', {id: TargetCategory.id}) }}{% elseif Parent %}{{ url('admin_product_category_show', {'parent_id': Parent.id}) }}{% else %}{{ url('admin_product_category') }}{% endif %}"
enctype="multipart/form-data">
{% if TargetCategory.hierarchy <= eccube_config.eccube_category_nest_level %}
{% if TargetCategory.hierarchy <= eccube_config.eccube_category_nest_hierarchy %}
{{ form_widget(form._token) }}
<div class="row mb-3">
<div class="col-auto">
Expand Down Expand Up @@ -312,9 +312,9 @@ file that was distributed with this source code.
</div>
</div>

{% macro tree(Category, TargetId, level, Ids) %}
{% macro tree(Category, TargetId, hierarchy, Ids) %}
{% import _self as selfMacro %}
{% set level = level + 1 %}
{% set hierarchy = hierarchy + 1 %}
<li>
<label {% if (Category.children|length > 0) and (Category.id not in Ids) %}class="collapsed"
{% endif %}data-bs-toggle="collapse"
Expand All @@ -328,7 +328,7 @@ file that was distributed with this source code.
<ul class="collapse list-unstyled {% if Category.id in Ids %}show{% endif %}"
id="directory_category{{ Category.id }}">
{% for ChildCategory in Category.children %}
{{ selfMacro.tree(ChildCategory, TargetId, level, Ids) }}
{{ selfMacro.tree(ChildCategory, TargetId, hierarchy, Ids) }}
{% endfor %}
</ul>
{% endif %}
Expand Down

0 comments on commit d4c2dcd

Please sign in to comment.