/** * Retrieve Exclude Product Ids List for Collection * * @return array */ public function getExcludeProductIds() { $productIds = []; if ($this->_productCompare->hasItems()) { foreach ($this->_productCompare->getItemCollection() as $_item) { $productIds[] = $_item->getEntityId(); } } if ($this->_registry->registry('current_product')) { $productIds[] = $this->_registry->registry('current_product')->getId(); } return array_unique($productIds); }
/** * calculate() * getItemCount() * hasItems() * @magentoDataFixture Magento/Catalog/_files/multiple_products.php */ public function testCalculate() { /** @var \Magento\Catalog\Model\Session $session */ $session = $this->_objectManager->get('Magento\\Catalog\\Model\\Session'); try { $session->unsCatalogCompareItemsCount(); $this->assertFalse($this->_helper->hasItems()); $this->assertEquals(0, $session->getCatalogCompareItemsCount()); $this->_populateCompareList(); $this->_helper->calculate(); $this->assertEquals(2, $session->getCatalogCompareItemsCount()); $this->assertTrue($this->_helper->hasItems()); $session->unsCatalogCompareItemsCount(); } catch (\Exception $e) { $session->unsCatalogCompareItemsCount(); throw $e; } }