Exemple #1
0
 /**
  * Get RSS feed items
  *
  * @return array
  */
 public function getRssData()
 {
     $wishlist = $this->getWishlist();
     if ($wishlist->getId()) {
         $data = $this->getHeader();
         /** @var $wishlistItem \Magento\Wishlist\Model\Item */
         foreach ($wishlist->getItemCollection() as $wishlistItem) {
             /* @var $product \Magento\Catalog\Model\Product */
             $product = $wishlistItem->getProduct();
             $productUrl = $this->wishlistBlock->getProductUrl($product, ['_rss' => true]);
             $product->setAllowedInRss(true);
             $product->setAllowedPriceInRss(true);
             $product->setProductUrl($productUrl);
             $args = ['product' => $product];
             $this->eventManager->dispatch('rss_wishlist_xml_callback', $args);
             if (!$product->getAllowedInRss()) {
                 continue;
             }
             $description = '<table><tr><td><a href="' . $productUrl . '"><img src="' . $this->imageHelper->init($product, 'rss_thumbnail')->getUrl() . '" border="0" align="left" height="75" width="75"></a></td>' . '<td style="text-decoration:none;">' . $this->outputHelper->productAttribute($product, $product->getShortDescription(), 'short_description') . '<p>';
             if ($product->getAllowedPriceInRss()) {
                 $description .= $this->getProductPriceHtml($product);
             }
             $description .= '</p>';
             if (trim($product->getDescription()) != '') {
                 $description .= '<p>' . __('Comment:') . ' ' . $this->outputHelper->productAttribute($product, $product->getDescription(), 'description') . '<p>';
             }
             $description .= '</td></tr></table>';
             $data['entries'][] = ['title' => $product->getName(), 'link' => $productUrl, 'description' => $description];
         }
     } else {
         $data = ['title' => __('We cannot retrieve the Wish List.'), 'description' => __('We cannot retrieve the Wish List.'), 'link' => $this->urlBuilder->getUrl(), 'charset' => 'UTF-8'];
     }
     return $data;
 }
Exemple #2
0
 /**
  * @return string
  */
 protected function _toHtml()
 {
     //store id is store view id
     $storeId = $this->_getStoreId();
     $websiteId = $this->_storeManager->getStore($storeId)->getWebsiteId();
     //customer group id
     $customerGroupId = $this->_getCustomerGroupId();
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $this->_productFactory->create();
     $product->setStoreId($storeId);
     $specials = $product->getResourceCollection()->addPriceDataFieldFilter('%s < %s', array('final_price', 'price'))->addPriceData($customerGroupId, $websiteId)->addAttributeToSelect(array('name', 'short_description', 'description', 'price', 'thumbnail', 'special_price', 'special_to_date', 'msrp_enabled', 'msrp_display_actual_price_type', 'msrp'), 'left')->addAttributeToSort('name', 'asc');
     $newUrl = $this->_urlBuilder->getUrl('rss/catalog/special/store_id/' . $storeId);
     $title = __('%1 - Special Products', $this->_storeManager->getStore()->getFrontendName());
     $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     /** @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang));
     $results = array();
     /*
     using resource iterator to load the data one by one
     instead of loading all at the same time. loading all data at the same time can cause the big memory allocation.
     */
     $this->_resourceIterator->walk($specials->getSelect(), array(array($this, 'addSpecialXmlCallback')), array('rssObj' => $rssObj, 'results' => &$results));
     if (sizeof($results) > 0) {
         foreach ($results as $result) {
             // render a row for RSS feed
             $product->setData($result);
             $html = sprintf('<table><tr>' . '<td><a href="%s"><img src="%s" alt="" border="0" align="left" height="75" width="75" /></a></td>' . '<td style="text-decoration:none;">%s', $product->getProductUrl(), $this->_imageHelper->init($product, 'thumbnail')->resize(75, 75), $this->_outputHelper->productAttribute($product, $product->getDescription(), 'description'));
             // add price data if needed
             if ($product->getAllowedPriceInRss()) {
                 if ($this->_catalogData->canApplyMsrp($product)) {
                     $html .= '<br/><a href="' . $product->getProductUrl() . '">' . __('Click for price') . '</a>';
                 } else {
                     $special = '';
                     if ($result['use_special']) {
                         $special = '<br />' . __('Special Expires On: %1', $this->formatDate($result['special_to_date'], \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM));
                     }
                     $html .= sprintf('<p>%s %s%s</p>', __('Price: %1', $this->_priceCurrency->convertAndFormat($result['price'])), __('Special Price: %1', $this->_priceCurrency->convertAndFormat($result['final_price'])), $special);
                 }
             }
             $html .= '</td></tr></table>';
             $rssObj->_addEntry(array('title' => $product->getName(), 'link' => $product->getProductUrl(), 'description' => $html));
         }
     }
     return $rssObj->createRssXml();
 }
 /**
  * @param \Magento\Catalog\Model\Product $item
  * @return array
  */
 protected function getEntryData(\Magento\Catalog\Model\Product $item)
 {
     $description = '
         <table><tr>
             <td><a href="%s"><img src="%s" alt="" border="0" align="left" height="75" width="75" /></a></td>
             <td style="text-decoration:none;">%s %s</td>
         </tr></table>
     ';
     $specialPrice = '';
     if ($item->getAllowedPriceInRss()) {
         if ($this->msrpHelper->canApplyMsrp($item)) {
             $specialPrice = '<br/><a href="' . $item->getProductUrl() . '">' . __('Click for price') . '</a>';
         } else {
             $special = '';
             if ($item->getUseSpecial()) {
                 $special = '<br />' . __('Special Expires On: %1', $this->formatDate($item->getSpecialToDate(), \IntlDateFormatter::MEDIUM));
             }
             $specialPrice = sprintf('<p>%s %s%s</p>', __('Price: %1', $this->priceCurrency->convertAndFormat($item->getPrice())), __('Special Price: %1', $this->priceCurrency->convertAndFormat($item->getFinalPrice())), $special);
         }
     }
     $description = sprintf($description, $item->getProductUrl(), $this->imageHelper->init($item, 'rss_thumbnail')->getUrl(), $this->outputHelper->productAttribute($item, $item->getDescription(), 'description'), $specialPrice);
     return ['title' => $item->getName(), 'link' => $item->getProductUrl(), 'description' => $description];
 }