/** * Filter collection by removing not available product types * * @param \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection $collection * @return \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection */ public function applySalableProductTypesFilter($collection) { $productTypes = $this->_salesConfig->getAvailableProductTypes(); foreach ($collection->getItems() as $key => $item) { if ($item instanceof \Magento\Catalog\Model\Product) { $type = $item->getTypeId(); } elseif ($item instanceof \Magento\Sales\Model\Order\Item) { $type = $item->getProductType(); } elseif ($item instanceof \Magento\Quote\Model\Quote\Item) { $type = $item->getProductType(); } else { $type = ''; } if (!in_array($type, $productTypes)) { $collection->removeItemByKey($key); } } return $collection; }