/** * @return string */ public function getRssData() { $newUrl = $this->rssUrlBuilder->getUrl(['type' => 'special_products', 'store_id' => $this->getStoreId()]); $title = __('%1 - Special Products', $this->storeManager->getStore()->getFrontendName()); $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); $data = ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang]; $currentDate = (new \DateTime())->setTime(0, 0, 0); foreach ($this->rssModel->getProductsCollection($this->getStoreId(), $this->getCustomerGroupId()) as $item) { /** @var $item \Magento\Catalog\Model\Product */ $item->setAllowedInRss(true); $item->setAllowedPriceInRss(true); $this->_eventManager->dispatch('rss_catalog_special_xml_callback', ['row' => $item->getData(), 'product' => $item]); if (!$item->getAllowedInRss()) { continue; } $item->setUseSpecial(false); if ($item->getSpecialToDate() && $item->getFinalPrice() <= $item->getSpecialPrice() && $item->getAllowedPriceInRss()) { if ($currentDate->format('Y-m-d') <= $item->getSpecialToDate()) { $item->setUseSpecial(true); } } $data['entries'][] = $this->getEntryData($item); } return $data; }
public function testGetProductsCollection() { $storeId = 1; $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->storeManager->expects($this->once())->method('getStore')->with($storeId)->will($this->returnValue($store)); $websiteId = 1; $store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId)); /** @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)); $customerGroupId = 1; $productCollection->expects($this->once())->method('addPriceDataFieldFilter')->will($this->returnSelf()); $productCollection->expects($this->once())->method('addPriceData')->with($storeId, $customerGroupId)->will($this->returnSelf()); $productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollection->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf()); $products = $this->special->getProductsCollection($storeId, $customerGroupId); $this->assertEquals($productCollection, $products); }
public function testGetRssData() { $this->rssUrlBuilder->expects($this->once())->method('getUrl')->with(['type' => 'special_products', 'store_id' => 1])->will($this->returnValue('http://magento.com/rss/feed/index/type/special_products/store_id/1')); $item = $this->getItemMock(); $this->rssModel->expects($this->once())->method('getProductsCollection')->will($this->returnValue([$item])); $this->msrpHelper->expects($this->once())->method('canApplyMsrp')->will($this->returnValue(false)); $this->localeDate->expects($this->once())->method('formatDateTime')->will($this->returnValue(date('Y-m-d'))); $this->priceCurrency->expects($this->any())->method('convertAndFormat')->will($this->returnArgument(0)); $this->imageHelper->expects($this->once())->method('init')->with($item, 'rss_thumbnail')->will($this->returnSelf()); $this->imageHelper->expects($this->once())->method('getUrl')->will($this->returnValue('image_link')); $this->outputHelper->expects($this->once())->method('productAttribute')->will($this->returnValue('')); $data = ['title' => 'Store 1 - Special Products', 'description' => 'Store 1 - Special Products', 'link' => 'http://magento.com/rss/feed/index/type/special_products/store_id/1', 'charset' => 'UTF-8', 'language' => 'en_US', 'entries' => [['title' => 'Product Name', 'link' => 'http://magento.com/product-name.html']]]; $rssData = $this->block->getRssData(); $description = $rssData['entries'][0]['description']; unset($rssData['entries'][0]['description']); $this->assertEquals($data, $rssData); $this->assertContains('<a href="http://magento.com/product-name.html"><', $description); $this->assertContains(sprintf('<p>Price: Special Price: 10<br />Special Expires On: %s</p>', date('Y-m-d')), $description); $this->assertContains('<img src="image_link" alt="" border="0" align="left" height="75" width="75" />', $description); }