/** * Build index query * * @param RequestInterface $request * @return Select */ public function build(RequestInterface $request) { $searchIndexTable = $this->scopeResolver->resolve($request->getIndex(), $request->getDimensions()); $select = $this->resource->getConnection()->select()->from(['search_index' => $searchIndexTable], ['entity_id' => 'entity_id'])->joinLeft(['cea' => $this->resource->getTableName('catalog_eav_attribute')], 'search_index.attribute_id = cea.attribute_id', []); $select = $this->tableMapper->addTables($select, $request); $select = $this->processDimensions($request, $select); $isShowOutOfStock = $this->config->isSetFlag('cataloginventory/options/show_out_of_stock', ScopeInterface::SCOPE_STORE); if ($isShowOutOfStock === false) { $select->joinLeft(['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')], 'search_index.entity_id = stock_index.product_id' . $this->resource->getConnection()->quoteInto(' AND stock_index.website_id = ?', $this->storeManager->getWebsite()->getId()), []); $select->where('stock_index.stock_status = ?', 1); } return $select; }
public function testAddBoolFilterWithBoolFiltersInside() { $this->createAttributeMock('must1', null, null, 101, 'select', 0); $this->createAttributeMock('should1', null, null, 102, 'select', 1); $this->createAttributeMock('mustNot1', null, null, 103, 'select', 2); $query = $this->createFilterQuery($this->createBoolFilter([$this->createBoolFilter([$this->createTermFilter('must1')], [], [])], [$this->createBoolFilter([$this->createTermFilter('should1')], [], [])], [$this->createBoolFilter([$this->createTermFilter('mustNot1')], [], [])])); $this->request->expects($this->once())->method('getQuery')->willReturn($query); $this->select->expects($this->at(0))->method('joinLeft')->with(['must1_filter' => 'prefix_catalog_product_index_eav'], 'search_index.entity_id = must1_filter.entity_id' . ' AND must1_filter.attribute_id = 101' . ' AND must1_filter.store_id = 2514', [])->willReturnSelf(); $this->select->expects($this->at(1))->method('joinLeft')->with(['should1_filter' => 'prefix_catalog_product_index_eav'], 'search_index.entity_id = should1_filter.entity_id' . ' AND should1_filter.attribute_id = 102' . ' AND should1_filter.store_id = 2514', [])->willReturnSelf(); $this->select->expects($this->at(2))->method('joinLeft')->with(['mustNot1_filter' => 'prefix_catalog_product_index_eav'], 'search_index.entity_id = mustNot1_filter.entity_id' . ' AND mustNot1_filter.attribute_id = 103' . ' AND mustNot1_filter.store_id = 2514', [])->willReturnSelf(); $select = $this->target->addTables($this->select, $this->request); $this->assertEquals($this->select, $select, 'Returned results isn\'t equal to passed select'); }