Skip to content

Commit 73636a9

Browse files
committed
Fix bug when no keyword association is selected on update
1 parent 450aa32 commit 73636a9

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

Action/Keyword.php

+36-28
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ public function updateKeywordFolderAssociation(KeywordAssociationEvent $event)
6868
->filterByFolderId($folder->getId())
6969
->delete();
7070

71-
// Create all associations to this folder
72-
foreach ($keywordListToSave as $keywordId) {
71+
if ($keywordListToSave !== null) {
72+
// Create all associations to this folder
73+
foreach ($keywordListToSave as $keywordId) {
7374

74-
$keywordFolderAssociation = new FolderAssociatedKeyword();
75-
$keywordFolderAssociation
76-
->setFolderId($folder->getId())
77-
->setKeywordId($keywordId)
78-
->save();
75+
$keywordFolderAssociation = new FolderAssociatedKeyword();
76+
$keywordFolderAssociation
77+
->setFolderId($folder->getId())
78+
->setKeywordId($keywordId)
79+
->save();
7980

81+
}
8082
}
8183

8284
}
@@ -94,15 +96,17 @@ public function updateKeywordContentAssociation(KeywordAssociationEvent $event)
9496
->filterByContentId($content->getId())
9597
->delete();
9698

97-
// Create all associations to this folder
98-
foreach ($keywordListToSave as $keywordId) {
99+
if ($keywordListToSave !== null) {
100+
// Create all associations to this folder
101+
foreach ($keywordListToSave as $keywordId) {
99102

100-
$keywordFolderAssociation = new ContentAssociatedKeyword();
101-
$keywordFolderAssociation
102-
->setContentId($content->getId())
103-
->setKeywordId($keywordId)
104-
->save();
103+
$keywordFolderAssociation = new ContentAssociatedKeyword();
104+
$keywordFolderAssociation
105+
->setContentId($content->getId())
106+
->setKeywordId($keywordId)
107+
->save();
105108

109+
}
106110
}
107111

108112
}
@@ -120,15 +124,17 @@ public function updateKeywordCategoryAssociation(KeywordAssociationEvent $event)
120124
->filterByCategoryId($category->getId())
121125
->delete();
122126

123-
// Create all associations to this category
124-
foreach ($keywordListToSave as $keywordId) {
127+
if ($keywordListToSave !== null) {
128+
// Create all associations to this category
129+
foreach ($keywordListToSave as $keywordId) {
125130

126-
$keywordCategoryAssociation = new CategoryAssociatedKeyword();
127-
$keywordCategoryAssociation
128-
->setCategoryId($category->getId())
129-
->setKeywordId($keywordId)
130-
->save();
131+
$keywordCategoryAssociation = new CategoryAssociatedKeyword();
132+
$keywordCategoryAssociation
133+
->setCategoryId($category->getId())
134+
->setKeywordId($keywordId)
135+
->save();
131136

137+
}
132138
}
133139

134140
}
@@ -146,15 +152,17 @@ public function updateKeywordProductAssociation(KeywordAssociationEvent $event)
146152
->filterByProductId($product->getId())
147153
->delete();
148154

149-
// Create all associations to this folder
150-
foreach ($keywordListToSave as $keywordId) {
155+
if ($keywordListToSave !== null) {
156+
// Create all associations to this folder
157+
foreach ($keywordListToSave as $keywordId) {
151158

152-
$keywordProductAssociation = new ProductAssociatedKeyword();
153-
$keywordProductAssociation
154-
->setProductId($product->getId())
155-
->setKeywordId($keywordId)
156-
->save();
159+
$keywordProductAssociation = new ProductAssociatedKeyword();
160+
$keywordProductAssociation
161+
->setProductId($product->getId())
162+
->setKeywordId($keywordId)
163+
->save();
157164

165+
}
158166
}
159167

160168
}

Config/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<descriptive locale="en_US">
88
<title>Keyword</title>
99
</descriptive>
10-
<version>2.4.2</version>
10+
<version>2.4.3</version>
1111
<author>
1212
<name>Michaël Espeche</name>
1313
<email>mespeche@openstudio.fr</email>

0 commit comments

Comments
 (0)