/** * @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); }