/** * @return array */ protected function getItems() { $items = []; foreach ($this->helper->getItemCollection() as $item) { $items[] = ['id' => $item->getId(), 'product_url' => $this->productUrl->getUrl($item), 'name' => $this->outputHelper->productAttribute($item, $item->getName(), 'name'), 'remove_url' => $this->helper->getPostDataRemove($item)]; } return $items; }
/** * 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); }
/** * Retrieve is flat enabled flag * Overwrite disable flat for compared item if required EAV resource * * @return bool */ public function isEnabledFlat() { if (!$this->_catalogProductCompare->getAllowUsedFlat()) { return false; } return parent::isEnabledFlat(); }
/** * @return void */ public function testGetExcludeProductIds() { $collection = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Compare\\Item\\Collection')->disableOriginalConstructor()->setMethods(['getEntityId'])->getMock(); $collection->expects($this->once())->method('getEntityId')->willReturn(1); $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getId'])->getMock(); $product->expects($this->once())->method('getId')->willReturn(2); $this->catalogProductHelperMock->expects($this->once())->method('hasItems')->willReturn(true); $this->catalogProductHelperMock->expects($this->once())->method('getItemCollection')->willReturn([$collection]); $this->registryMock->expects($this->any())->method('registry')->willReturn($product); $this->assertEquals([1, 2], $this->compared->getExcludeProductIds()); }
public function testGetPostDataClearList() { //Data $refererUrl = 'home/'; $clearUrl = 'catalog/product_compare/clear'; $postParams = array(\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED => $this->compareHelper->urlEncode($refererUrl)); //Verification $this->request->expects($this->once())->method('getServer')->with('HTTP_REFERER')->will($this->returnValue($refererUrl)); $this->urlBuilder->expects($this->once())->method('getUrl')->with($clearUrl)->will($this->returnValue($clearUrl)); $this->postDataHelper->expects($this->once())->method('getPostData')->with($clearUrl, $postParams)->will($this->returnValue(true)); $this->assertTrue($this->compareHelper->getPostDataClearList()); }
public function testGetAddToCartUrl() { $productId = 42; $isRequestSecure = false; $beforeCompareUrl = 'http://magento.com/compare/before'; $encodedCompareUrl = strtr(base64_encode($beforeCompareUrl), '+/=', '-_,'); $expectedResult = ['product' => $productId, Action::PARAM_NAME_URL_ENCODED => $encodedCompareUrl, '_secure' => $isRequestSecure]; $productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false); $this->catalogSessionMock->expects($this->once())->method('getBeforeCompareUrl')->willReturn($beforeCompareUrl); $productMock->expects($this->once())->method('getId')->willReturn($productId); $this->urlEncoder->expects($this->once())->method('encode')->with($beforeCompareUrl)->willReturn($encodedCompareUrl); $this->request->expects($this->once())->method('isSecure')->willReturn($isRequestSecure); $this->urlBuilder->expects($this->once())->method('getUrl')->with('checkout/cart/add', $expectedResult); $this->compareHelper->getAddToCartUrl($productMock); }
public function testSetGetAllowUsedFlat() { $this->assertTrue($this->_helper->getAllowUsedFlat()); $this->_helper->setAllowUsedFlat(false); $this->assertFalse($this->_helper->getAllowUsedFlat()); }
/** * Customer logout bind process * * @param \Magento\Framework\Event\Observer $observer * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function bindCustomerLogout(\Magento\Framework\Event\Observer $observer = null) { $this->_getResource()->purgeVisitorByCustomer($this); $this->_catalogProductCompare->calculate(true); return $this; }
/** * Retrieve Add Product to Compare Products List URL * * @return string */ public function getAddToCompareUrl() { return $this->_compareProduct->getAddUrl(); }