예제 #1
30
 /**
  * Generate RSS XML with sales rules data
  *
  * @return string
  */
 protected function _toHtml()
 {
     $storeId = $this->_getStoreId();
     $storeModel = $this->_storeManager->getStore($storeId);
     $websiteId = $storeModel->getWebsiteId();
     $customerGroup = $this->_getCustomerGroupId();
     $now = date('Y-m-d');
     $url = $this->_urlBuilder->getUrl('');
     $newUrl = $this->_urlBuilder->getUrl('rss/catalog/salesrule');
     $title = __('%1 - Discounts and Coupons', $storeModel->getName());
     $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeModel);
     /** @var $rssObject \Magento\Rss\Model\Rss */
     $rssObject = $this->_rssFactory->create();
     $rssObject->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang));
     /** @var $collection \Magento\SalesRule\Model\Resource\Rule\Collection */
     $collection = $this->_collectionFactory->create();
     $collection->addWebsiteGroupDateFilter($websiteId, $customerGroup, $now)->addFieldToFilter('is_rss', 1)->setOrder('from_date', 'desc');
     $collection->load();
     /** @var $ruleModel \Magento\SalesRule\Model\Rule */
     foreach ($collection as $ruleModel) {
         $description = '<table><tr>' . '<td style="text-decoration:none;">' . $ruleModel->getDescription() . '<br/>Discount Start Date: ' . $this->formatDate($ruleModel->getFromDate(), 'medium');
         if ($ruleModel->getToDate()) {
             $description .= '<br/>Discount End Date: ' . $this->formatDate($ruleModel->getToDate(), 'medium');
         }
         if ($ruleModel->getCouponCode()) {
             $description .= '<br/> Coupon Code: ' . $ruleModel->getCouponCode();
         }
         $description .= '</td></tr></table>';
         $rssObject->_addEntry(array('title' => $ruleModel->getName(), 'description' => $description, 'link' => $url));
     }
     return $rssObject->createRssXml();
 }
예제 #2
0
파일: Status.php 프로젝트: aiesh/magento2
 /**
  * @return string
  */
 protected function _toHtml()
 {
     /** @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     $order = $this->_coreRegistry->registry('current_order');
     if (!$order) {
         return '';
     }
     $title = __('Order # %1 Notification(s)', $order->getIncrementId());
     $newUrl = $this->_urlBuilder->getUrl('sales/order/view', array('order_id' => $order->getId()));
     $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'));
     /** @var $resourceModel \Magento\Rss\Model\Resource\Order */
     $resourceModel = $this->_orderFactory->create();
     $results = $resourceModel->getAllCommentCollection($order->getId());
     if ($results) {
         foreach ($results as $result) {
             $urlAppend = 'view';
             $type = $result['entity_type_code'];
             if ($type && $type != 'order') {
                 $urlAppend = $type;
             }
             $type = __(ucwords($type));
             $title = __('Details for %1 #%2', $type, $result['increment_id']);
             $description = '<p>' . __('Notified Date: %1<br/>', $this->formatDate($result['created_at'])) . __('Comment: %1<br/>', $result['comment']) . '</p>';
             $url = $this->_urlBuilder->getUrl('sales/order/' . $urlAppend, array('order_id' => $order->getId()));
             $rssObj->_addEntry(array('title' => $title, 'link' => $url, 'description' => $description));
         }
     }
     $title = __('Order #%1 created at %2', $order->getIncrementId(), $this->formatDate($order->getCreatedAt()));
     $url = $this->_urlBuilder->getUrl('sales/order/view', array('order_id' => $order->getId()));
     $description = '<p>' . __('Current Status: %1<br/>', $order->getStatusLabel()) . __('Total: %1<br/>', $order->formatPrice($order->getGrandTotal())) . '</p>';
     $rssObj->_addEntry(array('title' => $title, 'link' => $url, 'description' => $description));
     return $rssObj->createRssXml();
 }
예제 #3
0
 /**
  * @return string
  */
 protected function _toHtml()
 {
     $storeId = $this->_getStoreId();
     $storeModel = $this->_storeManager->getStore($storeId);
     $newUrl = $this->_urlBuilder->getUrl('rss/catalog/new/store_id/' . $storeId);
     $title = __('New Products from %1', $storeModel->getFrontendName());
     $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeModel);
     /** @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang));
     /** @var $product \Magento\Catalog\Model\Product */
     $product = $this->_productFactory->create();
     $todayStartOfDayDate = $this->_localeDate->date()->setTime('00:00:00')->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
     $todayEndOfDayDate = $this->_localeDate->date()->setTime('23:59:59')->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
     /** @var $products \Magento\Catalog\Model\Resource\Product\Collection */
     $products = $product->getCollection();
     $products->setStoreId($storeId);
     $products->addStoreFilter()->addAttributeToFilter('news_from_date', array('or' => array(0 => array('date' => true, 'to' => $todayEndOfDayDate), 1 => array('is' => new \Zend_Db_Expr('null')))), 'left')->addAttributeToFilter('news_to_date', array('or' => array(0 => array('date' => true, 'from' => $todayStartOfDayDate), 1 => array('is' => new \Zend_Db_Expr('null')))), 'left')->addAttributeToFilter(array(array('attribute' => 'news_from_date', 'is' => new \Zend_Db_Expr('not null')), array('attribute' => 'news_to_date', 'is' => new \Zend_Db_Expr('not null'))))->addAttributeToSort('news_from_date', 'desc')->addAttributeToSelect(array('name', 'short_description', 'description'), 'inner')->addAttributeToSelect(array('price', 'special_price', 'special_from_date', 'special_to_date', 'msrp_enabled', 'msrp_display_actual_price_type', 'msrp', 'thumbnail'), 'left')->applyFrontendPriceLimitations();
     $products->setVisibility($this->_visibility->getVisibleInCatalogIds());
     /*
     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($products->getSelect(), array(array($this, 'addNewItemXmlCallback')), array('rssObj' => $rssObj, 'product' => $product));
     return $rssObj->createRssXml();
 }
예제 #4
0
파일: Review.php 프로젝트: aiesh/magento2
 /**
  * Render XML response
  *
  * @return string
  */
 protected function _toHtml()
 {
     $newUrl = $this->getUrl('rss/catalog/review', array('_secure' => true, '_nosecret' => true));
     $title = __('Pending product review(s)');
     /** @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'));
     /** @var $reviewModel \Magento\Review\Model\Review */
     $reviewModel = $this->_reviewFactory->create();
     $collection = $reviewModel->getProductCollection()->addStatusFilter($reviewModel->getPendingStatus())->addAttributeToSelect('name', 'inner')->setDateOrder();
     $this->_eventManager->dispatch('rss_catalog_review_collection_select', array('collection' => $collection));
     $this->_resourceIterator->walk($collection->getSelect(), array(array($this, 'addReviewItemXmlCallback')), array('rssObj' => $rssObj, 'reviewModel' => $reviewModel));
     return $rssObj->createRssXml();
 }
예제 #5
0
파일: NewOrder.php 프로젝트: aiesh/magento2
 /**
  * @return string
  */
 protected function _toHtml()
 {
     /** @var $order \Magento\Sales\Model\Order */
     $order = $this->_orderFactory->create();
     $passDate = $this->_dateTime->formatDate(mktime(0, 0, 0, date('m'), date('d') - 7));
     $newUrl = $this->getUrl('rss/order/new', array('_secure' => true, '_nosecret' => true));
     $title = __('New Orders');
     /** @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'));
     /** @var $collection \Magento\Sales\Model\Resource\Order\Collection */
     $collection = $order->getCollection();
     $collection->addAttributeToFilter('created_at', array('date' => true, 'from' => $passDate))->addAttributeToSort('created_at', 'desc');
     $detailBlock = $this->_layout->getBlockSingleton('Magento\\Rss\\Block\\Order\\Details');
     $this->_eventManager->dispatch('rss_order_new_collection_select', array('collection' => $collection));
     $this->_resourceIterator->walk($collection->getSelect(), array(array($this, 'addNewOrderXmlCallback')), array('rssObj' => $rssObj, 'order' => $order, 'detailBlock' => $detailBlock));
     return $rssObj->createRssXml();
 }
예제 #6
0
 /**
  * Render RSS
  *
  * @return string
  */
 protected function _toHtml()
 {
     $newUrl = $this->getUrl('rss/catalog/notifystock', array('_secure' => true, '_nosecret' => true));
     $title = __('Low Stock Products');
     /** @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'));
     $globalNotifyStockQty = (double) $this->_scopeConfig->getValue(\Magento\CatalogInventory\Model\Stock\Item::XML_PATH_NOTIFY_STOCK_QTY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     /* @var $product \Magento\Catalog\Model\Product */
     $product = $this->_productFactory->create();
     /* @var $collection \Magento\Catalog\Model\Resource\Product\Collection */
     $collection = $product->getCollection();
     /** @var $resourceStock \Magento\CatalogInventory\Model\Resource\Stock */
     $resourceStock = $this->_stockFactory->create();
     $resourceStock->addLowStockFilter($collection, array('qty', 'notify_stock_qty', 'low_stock_date', 'use_config' => 'use_config_notify_stock_qty'));
     $collection->addAttributeToSelect('name', true)->addAttributeToFilter('status', array('in' => $this->_productStatus->getVisibleStatusIds()))->setOrder('low_stock_date');
     $this->_eventManager->dispatch('rss_catalog_notify_stock_collection_select', array('collection' => $collection));
     /*
     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($collection->getSelect(), array(array($this, 'addNotifyItemXmlCallback')), array('rssObj' => $rssObj, 'product' => $product, 'globalQty' => $globalNotifyStockQty));
     return $rssObj->createRssXml();
 }
예제 #7
0
파일: Special.php 프로젝트: aiesh/magento2
 /**
  * @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();
 }
예제 #8
0
 /**
  * Render block HTML
  *
  * @return string
  */
 protected function _toHtml()
 {
     /* @var $rssObj \Magento\Rss\Model\Rss */
     $rssObj = $this->_rssFactory->create();
     if ($this->_getWishlist()->getId()) {
         $newUrl = $this->_urlBuilder->getUrl('wishlist/shared/index', array('code' => $this->_getWishlist()->getSharingCode()));
         $title = $this->_getTitle();
         $lang = $this->_scopeConfig->getValue('general/locale/code', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
         $rssObj->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8', 'language' => $lang));
         /** @var $wishlistItem \Magento\Wishlist\Model\Item */
         foreach ($this->getWishlistItems() as $wishlistItem) {
             /* @var $product \Magento\Catalog\Model\Product */
             $product = $wishlistItem->getProduct();
             $productUrl = $this->getProductUrl($product);
             $product->setAllowedInRss(true);
             $product->setAllowedPriceInRss(true);
             $product->setProductUrl($productUrl);
             $args = array('product' => $product);
             $this->_eventManager->dispatch('rss_wishlist_xml_callback', $args);
             if (!$product->getAllowedInRss()) {
                 continue;
             }
             /** @var $outputHelper \Magento\Catalog\Helper\Output */
             $outputHelper = $this->_outputHelper;
             $description = '<table><tr><td><a href="' . $productUrl . '"><img src="' . $this->_imageHelper->init($product, 'thumbnail')->resize(75, 75) . '" border="0" align="left" height="75" width="75"></a></td>' . '<td style="text-decoration:none;">' . $outputHelper->productAttribute($product, $product->getShortDescription(), 'short_description') . '<p>';
             if ($product->getAllowedPriceInRss()) {
                 $description .= $this->getProductPrice($product);
             }
             $description .= '</p>';
             if ($this->hasDescription($product)) {
                 $description .= '<p>' . __('Comment:') . ' ' . $outputHelper->productAttribute($product, $product->getDescription(), 'description') . '<p>';
             }
             $description .= '</td></tr></table>';
             $rssObj->_addEntry(array('title' => $outputHelper->productAttribute($product, $product->getName(), 'name'), 'link' => $productUrl, 'description' => $description));
         }
     } else {
         $rssObj->_addHeader(array('title' => __('We cannot retrieve the wish list.'), 'description' => __('We cannot retrieve the wish list.'), 'link' => $this->_urlBuilder->getUrl(), 'charset' => 'UTF-8'));
     }
     return $rssObj->createRssXml();
 }
예제 #9
0
파일: Category.php 프로젝트: aiesh/magento2
 /**
  * @return string
  */
 protected function _toHtml()
 {
     $categoryId = $this->getRequest()->getParam('cid');
     $storeId = $this->_getStoreId();
     /** @var $rssModel \Magento\Rss\Model\Rss */
     $rssModel = $this->_rssFactory->create();
     if ($categoryId) {
         $category = $this->_categoryFactory->create();
         $category->load($categoryId);
         if ($category && $category->getId()) {
             /** @var $layer \Magento\Catalog\Model\Layer */
             $layer = $this->_catalogLayer->setStore($storeId);
             //want to load all products no matter anchor or not
             $category->setIsAnchor(true);
             $newUrl = $category->getUrl();
             $title = $category->getName();
             $rssModel->_addHeader(array('title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'));
             $_collection = $category->getCollection();
             $_collection->addAttributeToSelect('url_key')->addAttributeToSelect('name')->addAttributeToSelect('is_anchor')->addAttributeToFilter('is_active', 1)->addIdFilter($category->getChildren())->load();
             /** @var $productCollection \Magento\Catalog\Model\Resource\Product\Collection */
             $productCollection = $this->_collectionFactory->create();
             $currentCategory = $layer->setCurrentCategory($category);
             $layer->prepareProductCollection($productCollection);
             $productCollection->addCountToCategories($_collection);
             $category->getProductCollection()->setStoreId($storeId);
             /*
             only load latest 50 products
             */
             $_productCollection = $currentCategory->getProductCollection()->addAttributeToSort('updated_at', 'desc')->setVisibility($this->_visibility->getVisibleInCatalogIds())->setCurPage(1)->setPageSize(50);
             if ($_productCollection->getSize() > 0) {
                 $args = array('rssObj' => $rssModel);
                 foreach ($_productCollection as $_product) {
                     $args['product'] = $_product;
                     $this->addNewItemXmlCallback($args);
                 }
             }
         }
     }
     return $rssModel->createRssXml();
 }