/** * Additional function to process forming description for wishlist item * * @param \Magento\Wishlist\Model\Wishlist $wishlistModelMock * @param array $staticArgs * @return string */ protected function processWishlistItemDescription($wishlistModelMock, $staticArgs) { $imgThumbSrc = 'http://source-for-thumbnail'; $priceHtmlForTest = '<div class="price">Price is 10 for example</div>'; $productDescription = 'Product description'; $productShortDescription = 'Product short description'; $wishlistItem = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false); $wishlistItemsCollection = [$wishlistItem]; $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getAllowedInRss', 'getAllowedPriceInRss', 'getDescription', 'getShortDescription', 'getName', 'getVisibleInSiteVisibilities', 'getUrlModel', '__wakeup'], [], '', false); $urlModelMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Url', [], [], '', false); $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', true, true, true, ['getBlock']); $wishlistModelMock->expects($this->once())->method('getItemCollection')->will($this->returnValue($wishlistItemsCollection)); $wishlistItem->expects($this->once())->method('getProduct')->will($this->returnValue($productMock)); $productMock->expects($this->once())->method('getUrlModel')->will($this->returnValue($urlModelMock)); $productMock->expects($this->once())->method('getAllowedPriceInRss')->will($this->returnValue($urlModelMock)); $urlModelMock->expects($this->once())->method('getUrl')->will($this->returnValue($staticArgs['productUrl'])); $productMock->expects($this->once())->method('getName')->will($this->returnValue($staticArgs['productName'])); $productMock->expects($this->once())->method('getAllowedInRss')->will($this->returnValue(true)); $productMock->expects($this->once())->method('getVisibleInSiteVisibilities')->will($this->returnValue(true)); $this->imageHelperMock->expects($this->once())->method('init')->will($this->returnSelf()); $this->imageHelperMock->expects($this->once())->method('resize')->will($this->returnValue($imgThumbSrc)); $priceRendererMock = $this->getMock('Magento\\Framework\\Pricing\\Render', ['render'], [], '', false); $layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($priceRendererMock)); $priceRendererMock->expects($this->once())->method('render')->will($this->returnValue($priceHtmlForTest)); $productMock->expects($this->any())->method('getDescription')->will($this->returnValue($productDescription)); $productMock->expects($this->any())->method('getShortDescription')->will($this->returnValue($productShortDescription)); $this->catalogOutputMock->expects($this->any())->method('productAttribute')->will($this->returnArgument(1)); $this->block->setLayout($layoutMock); $description = '<table><tr><td><a href="' . $staticArgs['productUrl'] . '"><img src="' . $imgThumbSrc . '" border="0" align="left" height="75" width="75"></a></td><td style="text-decoration:none;">' . $productShortDescription . '<p>' . $priceHtmlForTest . '</p><p>Comment: ' . $productDescription . '<p>' . '</td></tr></table>'; return $description; }
/** * 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; }
public function testGetProductPriceHtmlBlockExists() { $price = 10.0; $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock(); $renderBlockMock = $this->getMockBuilder('Magento\\Framework\\Pricing\\Render')->disableOriginalConstructor()->getMock(); $renderBlockMock->expects($this->once())->method('render')->with('wishlist_configured_price', $productMock, ['zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST])->willReturn($price); $this->layoutMock->expects($this->once())->method('getBlock')->with('product.price.render.default')->willReturn($renderBlockMock); $this->assertEquals($price, $this->model->getProductPriceHtml($productMock)); }
/** * @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(); }
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); }
/** * @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]; }
public function testProcess() { $this->_helper->addHandler('sampleProcessor', $this); $this->assertStringStartsWith(__CLASS__, $this->_helper->process('sampleProcessor', uniqid(), [])); }