@@ -14,15 +14,21 @@ class ProductAttributes implements OptionSourceInterface
1414 private ProductAttributeRepositoryInterface $ productAttributeRepository ;
1515 private SearchCriteriaBuilder $ searchCriteriaBuilder ;
1616 private SortOrderFactory $ sortOrderFactory ;
17+ private bool $ onlyIncludeVisible ;
18+ private bool $ onlyIncludeVisibleOnFront ;
1719
1820 public function __construct (
1921 ProductAttributeRepositoryInterface $ productAttributeRepository ,
2022 SearchCriteriaBuilder $ searchCriteriaBuilder ,
21- SortOrderFactory $ sortOrderFactory
23+ SortOrderFactory $ sortOrderFactory ,
24+ bool $ onlyIncludeVisible = true ,
25+ bool $ onlyIncludeVisibleOnFront = true ,
2226 ) {
2327 $ this ->productAttributeRepository = $ productAttributeRepository ;
2428 $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
2529 $ this ->sortOrderFactory = $ sortOrderFactory ;
30+ $ this ->onlyIncludeVisible = $ onlyIncludeVisible ;
31+ $ this ->onlyIncludeVisibleOnFront = $ onlyIncludeVisibleOnFront ;
2632 }
2733
2834 /**
@@ -32,8 +38,14 @@ public function toOptionArray(): array
3238 {
3339 $ options = [['value ' => '' , 'label ' => '' ]];
3440
35- $ this ->searchCriteriaBuilder ->addFilter ('is_visible ' , 1 );
36- $ this ->searchCriteriaBuilder ->addFilter ('is_visible_on_front ' , 1 );
41+ if ($ this ->onlyIncludeVisible ) {
42+ $ this ->searchCriteriaBuilder ->addFilter ('is_visible ' , 1 );
43+ }
44+
45+ if ($ this ->onlyIncludeVisibleOnFront ) {
46+ $ this ->searchCriteriaBuilder ->addFilter ('is_visible_on_front ' , 1 );
47+ }
48+
3749 $ sortOrder = $ this ->sortOrderFactory ->create (['field ' => 'attribute_code ' , 'direction ' => 'asc ' ]);
3850 $ this ->searchCriteriaBuilder ->addSortOrder ($ sortOrder );
3951 $ searchCriteria = $ this ->searchCriteriaBuilder ->create ();
0 commit comments