/** * Separate query for product and order data * * @param array $productIds * @return array * @throws \Magento\Framework\Exception\LocalizedException */ protected function getProductData(array $productIds) { $productConnection = $this->productResource->getConnection(); $productAttrName = $this->productResource->getAttribute('name'); $productAttrNameId = (int) $productAttrName->getAttributeId(); $productAttrPrice = $this->productResource->getAttribute('price'); $productAttrPriceId = (int) $productAttrPrice->getAttributeId(); $select = clone $this->productResource->getSelect(); $select->reset(); $select->from(['main_table' => $this->getTable('catalog_product_entity')])->useStraightJoin(true)->joinInner(['product_name' => $productAttrName->getBackend()->getTable()], 'product_name.entity_id = main_table.entity_id' . ' AND product_name.attribute_id = ' . $productAttrNameId . ' AND product_name.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID, ['name' => 'product_name.value'])->joinInner(['product_price' => $productAttrPrice->getBackend()->getTable()], "product_price.entity_id = main_table.entity_id AND product_price.attribute_id = {$productAttrPriceId}", ['price' => new \Zend_Db_Expr('product_price.value')])->where('main_table.entity_id IN (?)', $productIds); $productData = $productConnection->fetchAssoc($select); return $productData; }
/** * Replace WHERE-filtering by HAVING-filtering. * * @param \Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection $subject * @param \Closure $proceed * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection * @param $field * @param null $condition */ public function aroundAddFilter(\Magento\CatalogInventory\Ui\DataProvider\Product\AddQuantityFilterToCollection $subject, \Closure $proceed, \Magento\Catalog\Model\ResourceModel\Product\Collection $collection, $field, $condition = null) { /* skip identical conditions () */ $regKey = print_r($condition, true); if (!isset($this->_regCond[$regKey])) { $conn = $collection->getConnection(); $select = $collection->getSelect(); $equation = $this->_repoModifierProductGFrid->getEquationQty(); $prepared = $conn->prepareSqlCondition($equation, $condition); $select->having($prepared); $this->_regCond[$regKey] = true; } return; }