Skip to content

Commit 937013c

Browse files
Merge branch 'feature/support-nondefault-product-types'
2 parents a626af1 + 4ce383c commit 937013c

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

Helper/Source.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magmodules\Channable\Helper;
88

9+
use Magento\Catalog\Model\Product\TypeFactory;
910
use Magento\Framework\App\Helper\AbstractHelper;
1011
use Magento\Framework\App\Helper\Context;
1112
use Magento\Framework\Exception\NoSuchEntityException;
@@ -94,6 +95,10 @@ class Source extends AbstractHelper
9495
* @var InventorySource
9596
*/
9697
private $inventorySource;
98+
/**
99+
* @var TypeFactory
100+
*/
101+
private $typeFactory;
97102
/**
98103
* @var
99104
*/
@@ -105,11 +110,13 @@ public function __construct(
105110
General $generalHelper,
106111
Product $productHelper,
107112
InventorySource $inventorySource,
113+
TypeFactory $typeFactory,
108114
Item $itemHelper
109115
) {
110116
$this->generalHelper = $generalHelper;
111117
$this->productHelper = $productHelper;
112118
$this->itemHelper = $itemHelper;
119+
$this->typeFactory = $typeFactory;
113120
$this->storeManager = $storeManager;
114121
$this->inventorySource = $inventorySource;
115122
parent::__construct($context);
@@ -174,21 +181,28 @@ public function getStoreId($storeId = null)
174181
return $this->storeId;
175182
}
176183

184+
private function getAllProductTypeIds(): array
185+
{
186+
$typeInstance = $this->typeFactory->create();
187+
return array_keys($typeInstance->getOptionArray());
188+
}
189+
177190
/**
178191
* @param $type
179192
*
180193
* @return array
181194
*/
182-
public function getProductFilters($type)
195+
public function getProductFilters($type): array
183196
{
184-
$filters = [];
185-
$filters['type_id'] = ['simple', 'downloadable', 'virtual', 'giftcard'];
186-
$filters['relations'] = [];
187-
$filters['exclude_parents'] = [];
188-
$filters['nonvisible'] = [];
189-
$filters['parent_attributes'] = [];
190-
$filters['image'] = [];
191-
$filters['link'] = [];
197+
$filters = [
198+
'type_id' => array_diff($this->getAllProductTypeIds(), ['configurable', 'bundle', 'grouped']),
199+
'relations' => [],
200+
'exclude_parents' => [],
201+
'nonvisible' => [],
202+
'parent_attributes' => [],
203+
'image' => [],
204+
'link' => [],
205+
];
192206

193207
$configurabale = $this->getStoreValue(self::XPATH_CONFIGURABLE);
194208
switch ($configurabale) {

0 commit comments

Comments
 (0)