/** * Add stock status limitation to catalog product price index select object * * @param \Magento\Framework\DB\Select $select * @param string|Zend_Db_Expr $entityField * @param string|Zend_Db_Expr $websiteField * @return $this */ public function prepareCatalogProductIndexSelect(\Magento\Framework\DB\Select $select, $entityField, $websiteField) { if ($this->_catalogInventoryData->isShowOutOfStock()) { return $this; } $resource = $this->_getResource(); $resource->prepareCatalogProductIndexSelect($select, $entityField, $websiteField); return $this; }
/** * Add products to items and item options * * @return $this */ protected function _assignProducts() { \Magento\Framework\Profiler::start('WISHLIST:' . __METHOD__, array('group' => 'WISHLIST', 'method' => __METHOD__)); $productIds = array(); $this->_productIds = array_merge($this->_productIds, array_keys($productIds)); $attributes = $this->_wishlistConfig->getProductAttributes(); /** @var \Magento\Catalog\Model\Resource\Product\Collection $productCollection */ $productCollection = $this->_productCollectionFactory->create(); if ($this->_productVisible) { $productCollection->setVisibility($this->_productVisibility->getVisibleInSiteIds()); } $productCollection->addPriceData()->addTaxPercents()->addIdFilter($this->_productIds)->addAttributeToSelect($attributes)->addOptionsToResult()->addUrlRewrite(); if ($this->_productSalable) { $productCollection = $this->_adminhtmlSales->applySalableProductTypesFilter($productCollection); } $this->_eventManager->dispatch('wishlist_item_collection_products_after_load', array('product_collection' => $productCollection)); $checkInStock = $this->_productInStock && !$this->_inventoryData->isShowOutOfStock(); foreach ($this as $item) { $product = $productCollection->getItemById($item->getProductId()); if ($product) { if ($checkInStock && !$product->isInStock()) { $this->removeItemByKey($item->getId()); } else { $product->setCustomOptions(array()); $item->setProduct($product); $item->setProductName($product->getName()); $item->setName($product->getName()); $item->setPrice($product->getPrice()); } } else { $item->isDeleted(true); } } \Magento\Framework\Profiler::stop('WISHLIST:' . __METHOD__); return $this; }
public function testIsShowOutOfStock() { $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with($this->equalTo(Data::XML_PATH_SHOW_OUT_OF_STOCK), $this->equalTo(\Magento\Store\Model\ScopeInterface::SCOPE_STORE))->will($this->returnValue(true)); $this->assertTrue($this->data->isShowOutOfStock()); }