Skip to content

Commit 5c698ef

Browse files
authored
Merge pull request #57 from integer-net/fix-category-attributes
Fix category attributes
2 parents 986b3c4 + 6217dad commit 5c698ef

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* integer_net Magento Module
4+
*
5+
* @copyright Copyright (c) 2018 integer_net GmbH (http://www.integer-net.de/)
6+
* @author Andreas von Studnitz <[email protected]>
7+
*/
8+
9+
namespace IntegerNet\Solr\Plugin;
10+
11+
use Magento\Eav\Model\Config as EavConfig;
12+
13+
class CategoryDataProviderPlugin
14+
{
15+
/**
16+
* @var EavConfig
17+
*/
18+
private $eavConfig;
19+
20+
public function __construct(
21+
EavConfig $eavConfig
22+
) {
23+
$this->eavConfig = $eavConfig;
24+
}
25+
26+
public function afterPrepareMeta(\Magento\Catalog\Model\Category\DataProvider $subject, $result)
27+
{
28+
$meta = $result;
29+
$meta = array_replace_recursive($meta, $this->prepareFieldsMeta(
30+
$this->getFieldsMap(),
31+
$subject->getAttributesMeta($this->eavConfig->getEntityType('catalog_category'))
32+
));
33+
return $meta;
34+
}
35+
36+
private function prepareFieldsMeta($fieldsMap, $fieldsMeta)
37+
{
38+
$result = [];
39+
foreach ($fieldsMap as $fieldSet => $fields) {
40+
foreach ($fields as $field) {
41+
if (isset($fieldsMeta[$field])) {
42+
$result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $fieldsMeta[$field];
43+
}
44+
}
45+
}
46+
return $result;
47+
}
48+
49+
private function getFieldsMap()
50+
{
51+
return [
52+
'solr' => [
53+
'solr_exclude',
54+
'solr_exclude_children',
55+
'solr_remove_filters',
56+
'solr_boost',
57+
]
58+
];
59+
}
60+
}

main/src/etc/adminhtml/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<plugin name="search_weight_as_text" type="IntegerNet\Solr\Plugin\FrontTabPlugin" sortOrder="-10" />
66
</type>
77

8+
<!-- Necessary for full functionality of category attributes -->
9+
<!-- See See https://github.com/magento/magento2/issues/13440#issuecomment-392744685 -->
10+
<type name="Magento\Catalog\Model\Category\DataProvider">
11+
<plugin name="integernet_solr" type="IntegerNet\Solr\Plugin\CategoryDataProviderPlugin" />
12+
</type>
13+
814
<!-- Bugfix: Always use the frontend URL model for categories -->
915
<!-- necessary for autosuggest cache, to generate the right store urls -->
1016
<type name="Magento\Catalog\Model\Category">

0 commit comments

Comments
 (0)