wishlistHelper = $wishlistHelper; $this->wishlistBlock = $wishlistBlock; $this->outputHelper = $outputHelper; $this->imageHelper = $imageHelper; $this->urlBuilder = $urlBuilder; $this->scopeConfig = $scopeConfig; $this->eventManager = $eventManager; $this->customerFactory = $customerFactory; $this->layout = $layout; $this->request = $request; } /** * Check if RSS feed allowed * * @return mixed */ public function isAllowed() { return (bool)$this->scopeConfig->getValue( 'rss/wishlist/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } /** * 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 = '' . '
' . $this->outputHelper->productAttribute( $product, $product->getShortDescription(), 'short_description' ) . '

'; if ($product->getAllowedPriceInRss()) { $description .= $this->getProductPriceHtml($product); } $description .= '

'; if (trim($product->getDescription()) != '') { $description .= '

' . __('Comment:') . ' ' . $this->outputHelper->productAttribute( $product, $product->getDescription(), 'description' ) . '

'; } $description .= '

'; $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; } /** * @return string */ public function getCacheKey() { return 'rss_wishlist_data'; } /** * @return int */ public function getCacheLifetime() { return 60; } /** * Get data for Header section of RSS feed * * @return array */ public function getHeader() { $customerId = $this->getWishlist()->getCustomerId(); $customer = $this->customerFactory->create()->load($customerId); $title = __('%1\'s Wishlist', $customer->getName()); $newUrl = $this->urlBuilder->getUrl( 'wishlist/shared/index', ['code' => $this->getWishlist()->getSharingCode()] ); return ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8']; } /** * Retrieve Wishlist model * * @return \Magento\Wishlist\Model\Wishlist */ protected function getWishlist() { $wishlist = $this->wishlistHelper->getWishlist(); return $wishlist; } /** * Return HTML block with product price * * @param \Magento\Catalog\Model\Product $product * @return string */ public function getProductPriceHtml(\Magento\Catalog\Model\Product $product) { $price = ''; /** @var \Magento\Framework\Pricing\Render $priceRender */ $priceRender = $this->layout->getBlock('product.price.render.default'); if (!$priceRender) { $priceRender = $this->layout->createBlock( 'Magento\Framework\Pricing\Render', 'product.price.render.default', ['data' => ['price_render_handle' => 'catalog_product_prices']] ); } if ($priceRender) { $price = $priceRender->render( 'wishlist_configured_price', $product, ['zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST] ); } return $price; } /** * @return array */ public function getFeeds() { return []; } /** * {@inheritdoc} */ public function isAuthRequired() { if ($this->request->getParam('sharing_code') == $this->getWishlist()->getSharingCode()) { return false; } return true; } }