/** * {@inheritdoc} */ public function getRssData() { $storeModel = $this->storeManager->getStore($this->getStoreId()); $newUrl = $this->rssUrlBuilder->getUrl(['store_id' => $this->getStoreId(), 'type' => 'new_products']); $title = __('New Products from %1', $storeModel->getFrontendName()); $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeModel); $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang]; foreach ($this->rssModel->getProductsCollection($this->getStoreId()) as $item) { /** @var $item \Magento\Catalog\Model\Product */ $item->setAllowedInRss(true); $item->setAllowedPriceInRss(true); $this->_eventManager->dispatch('rss_catalog_new_xml_callback', ['row' => $item->getData(), 'product' => $item]); if (!$item->getAllowedInRss()) { continue; } $allowedPriceInRss = $item->getAllowedPriceInRss(); $description = ' <table><tr> <td><a href="%s"><img src="%s" border="0" align="left" height="75" width="75"></a></td> <td style="text-decoration:none;">%s %s</td> </tr></table> '; $description = sprintf($description, $item->getProductUrl(), $this->imageHelper->init($item, 'thumbnail')->resize(75, 75), $item->getDescription(), $allowedPriceInRss ? $this->renderPriceHtml($item) : ''); $data['entries'][] = ['title' => $item->getName(), 'link' => $item->getProductUrl(), 'description' => $description]; } return $data; }
public function testGetProductsCollection() { /** @var \DateTime|\PHPUnit_Framework_MockObject_MockObject $dateObject */ $dateObject = $this->getMock('DateTime'); $dateObject->expects($this->any())->method('setTime')->will($this->returnSelf()); $dateObject->expects($this->any())->method('format')->will($this->returnValue(date(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT))); $this->timezone->expects($this->exactly(2))->method('date')->will($this->returnValue($dateObject)); /** @var \Magento\Catalog\Model\Resource\Product\Collection $productCollection */ $productCollection = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Collection', [], [], '', false); $this->product->expects($this->once())->method('getResourceCollection')->will($this->returnValue($productCollection)); $storeId = 1; $productCollection->expects($this->once())->method('setStoreId')->with($storeId); $productCollection->expects($this->once())->method('addStoreFilter')->will($this->returnSelf()); $productCollection->expects($this->any())->method('addAttributeToFilter')->will($this->returnSelf()); $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollection->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf()); $productCollection->expects($this->once())->method('applyFrontendPriceLimitations')->will($this->returnSelf()); $visibleIds = [1, 3]; $this->visibility->expects($this->once())->method('getVisibleInCatalogIds')->will($this->returnValue($visibleIds)); $productCollection->expects($this->once())->method('setVisibility')->with($visibleIds)->will($this->returnSelf()); $products = $this->newProducts->getProductsCollection($storeId); $this->assertEquals($productCollection, $products); }