/** * 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; }
/** * @param string $itemKey * @param string $type * @param int $calledTimes * @dataProvider applySalableProductTypesFilterDataProvider */ public function testApplySalableProductTypesFilter($itemKey, $type, $calledTimes) { $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $productMock->expects($this->any())->method('getTypeId')->will($this->returnValue($type)); $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->setMethods(['__wakeup', 'getProductType'])->getMock(); $orderMock->expects($this->any())->method('getProductType')->will($this->returnValue($type)); $quoteMock = $this->getMockBuilder('Magento\\Sales\\Model\\Quote\\Item')->disableOriginalConstructor()->getMock(); $quoteMock->expects($this->any())->method('getProductType')->will($this->returnValue($type)); $items = ['product' => $productMock, 'order' => $orderMock, 'quote' => $quoteMock, 'other' => 'other']; $collectionMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\Collection\\AbstractCollection')->disableOriginalConstructor()->getMock(); $collectionMock->expects($this->any())->method('getItems')->will($this->returnValue([$items[$itemKey]])); $collectionMock->expects($this->exactly($calledTimes))->method('removeItemByKey'); $this->salesConfigMock->expects($this->any())->method('getAvailableProductTypes')->will($this->returnValue(['validProductType'])); $this->adminHelper->applySalableProductTypesFilter($collectionMock); }