Skip to content

Commit ef60dd9

Browse files
authored
Merge pull request #314 from edgars1337/post-collection-improvement
improving fragment in post collection
2 parents 6437c09 + 2e28251 commit ef60dd9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Model/ResourceModel/Post/Collection.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,14 @@ protected function _construct()
8383
*/
8484
public function addFieldToFilter($field, $condition = null)
8585
{
86-
/* NEED TO IMPROVE THIS CODE */
87-
if (is_array($field) && count($field) > 1) {
88-
return parent::addFieldToFilter($field, $condition);
89-
}
90-
91-
if (is_array($field) && count($field) == 1) {
92-
$field = $field[0];
93-
if (isset($condition[0])) {
94-
$condition = $condition[0];
86+
if (is_array($field)) {
87+
if (count($field) > 1) {
88+
return parent::addFieldToFilter($field, $condition);
89+
} elseif (count($field) === 1) {
90+
$field = $field[0];
91+
$condition = $condition[0] ?? $condition;
9592
}
9693
}
97-
/* END NEED TO IMPROVE */
9894

9995
if ($field === 'store_id' || $field === 'store_ids') {
10096
return $this->addStoreFilter($condition);
@@ -158,7 +154,7 @@ public function addStoreFilter($store, $withAdmin = true)
158154
}
159155
return $this;
160156
}
161-
157+
162158
/**
163159
* Add "include in recent" filter to collection
164160
* @return $this
@@ -167,7 +163,7 @@ public function addRecentFilter()
167163
{
168164
return $this->addFieldToFilter('include_in_recent', 1);
169165
}
170-
166+
171167
/**
172168
* Add posts filter to collection
173169
* @param array|int|string $category

0 commit comments

Comments
 (0)