/**
  * Add products to items and item options
  *
  * @return $this
  */
 protected function _assignProducts()
 {
     \Magento\Framework\Profiler::start('WISHLIST:' . __METHOD__, ['group' => 'WISHLIST', 'method' => __METHOD__]);
     $productIds = [];
     $this->_productIds = array_merge($this->_productIds, array_keys($productIds));
     /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
     $productCollection = $this->_productCollectionFactory->create();
     if ($this->_productVisible) {
         $productCollection->setVisibility($this->_productVisibility->getVisibleInSiteIds());
     }
     $productCollection->addPriceData()->addTaxPercents()->addIdFilter($this->_productIds)->addAttributeToSelect('*')->addOptionsToResult()->addUrlRewrite();
     if ($this->_productSalable) {
         $productCollection = $this->_adminhtmlSales->applySalableProductTypesFilter($productCollection);
     }
     $this->_eventManager->dispatch('wishlist_item_collection_products_after_load', ['product_collection' => $productCollection]);
     $checkInStock = $this->_productInStock && !$this->stockConfiguration->isShowOutOfStock();
     foreach ($this as $item) {
         $product = $productCollection->getItemById($item->getProductId());
         if ($product) {
             if ($checkInStock && !$product->isInStock()) {
                 $this->removeItemByKey($item->getId());
             } else {
                 $product->setCustomOptions([]);
                 $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()
 {
     $store = 0;
     $this->scopeConfig->expects($this->once())->method('isSetFlag')->with(\Magento\CatalogInventory\Model\Configuration::XML_PATH_SHOW_OUT_OF_STOCK, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store)->will($this->returnValue(true));
     $this->assertTrue($this->stockConfiguration->isShowOutOfStock());
 }
Beispiel #3
0
 /**
  * Check if Stock configuration allows to display out of stock products
  *
  * @param int $storeId The store Id. Will use current store if null.
  *
  * @return bool
  */
 public function isShowOutOfStock($storeId = null)
 {
     return $this->stockConfiguration->isShowOutOfStock($storeId);
 }