/**
  * {@inheritdoc}
  */
 public function getRssData()
 {
     $categoryId = $this->getRequest()->getParam('category_id');
     $storeModel = $this->storeManager->getStore($this->getStoreId());
     $newUrl = $this->rssUrlBuilder->getUrl(['store_id' => $this->getStoreId(), 'type' => 'blog_categories', 'category_id' => $categoryId]);
     $title = __('List Posts 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];
     $limit = 10;
     $count = 0;
     $category = $this->rssModel->create()->load($categoryId);
     $posts = $category->getSelectedPostsCollection();
     $posts->addFieldToFilter('enabled', 1)->setOrder('post_id', 'DESC');
     foreach ($posts as $item) {
         $count++;
         if ($count > $limit) {
             break;
         }
         /** @var $item \Magento\Catalog\Model\Product */
         $item->setAllowedInRss(true);
         $item->setAllowedPriceInRss(true);
         if (!$item->getAllowedInRss()) {
             continue;
         }
         $description = '
             <table><tr>
             <td style="text-decoration:none;"> %s</td>
             </tr></table>
         ';
         $description = sprintf($description, $item->getShortDescription());
         $data['entries'][] = ['title' => $item->getName(), 'link' => $this->helper->getUrlByPost($item), 'description' => $description];
     }
     return $data;
 }
Exemplo n.º 2
0
 /**
  * {@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;
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 public function testGetRssData()
 {
     $this->rssUrlBuilder->expects($this->once())->method('getUrl')->with(['type' => 'new_products', 'store_id' => 1])->will($this->returnValue('http://magento.com/rss/feed/index/type/new_products/store_id/1'));
     $item = $this->getItemMock();
     $this->newProducts->expects($this->once())->method('getProductsCollection')->will($this->returnValue([$item]));
     $this->imageHelper->expects($this->once())->method('init')->with($item, 'thumbnail')->will($this->returnSelf());
     $this->imageHelper->expects($this->once())->method('resize')->with(75, 75)->will($this->returnValue('image_link'));
     $data = ['title' => 'New Products from Store 1', 'description' => 'New Products from Store 1', 'link' => 'http://magento.com/rss/feed/index/type/new_products/store_id/1', 'charset' => 'UTF-8', 'language' => null, '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('<img src="image_link" border="0" align="left" height="75" width="75">', $description);
     $this->assertContains('<td style="text-decoration:none;">Product Description </td>', $description);
 }