Example #1
0
 /**
  * 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();
 }
Example #2
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();
 }
Example #3
0
 /**
  * @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();
 }
 /**
  * Additional function to break up mocks initialization
  *
  * @return void
  */
 protected function addMocks()
 {
     $resIteratorcallback = function () {
         $arguments = func_get_args();
         $arguments[2]['results'] = [['use_special' => false, 'price' => 10, 'final_price' => 20]];
     };
     $this->storeMock->expects($this->once())->method('getWebsiteId')->will($this->returnValue(0));
     $this->storeMock->expects($this->once())->method('getFrontendName')->will($this->returnValue('store name'));
     $this->catalogHelperMock->expects($this->once())->method('canApplyMsrp')->will($this->returnValue(false));
     $this->resourceIteratorMock->expects($this->once())->method('walk')->will($this->returnCallback($resIteratorcallback));
     $this->imageHelperMock->expects($this->once())->method('init')->will($this->returnSelf());
 }
Example #5
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();
 }
Example #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();
 }
Example #7
0
 /**
  * Get array of product ids which are matched by rule
  *
  * @return array
  */
 public function getMatchingProductIds()
 {
     if (is_null($this->_productIds)) {
         $this->_productIds = array();
         $this->setCollectedAttributes(array());
         if ($this->getWebsiteIds()) {
             /** @var $productCollection \Magento\Catalog\Model\Resource\Product\Collection */
             $productCollection = $this->_productCollectionFactory->create();
             $productCollection->addWebsiteFilter($this->getWebsiteIds());
             if ($this->_productsFilter) {
                 $productCollection->addIdFilter($this->_productsFilter);
             }
             $this->getConditions()->collectValidatedAttributes($productCollection);
             $this->_resourceIterator->walk($productCollection->getSelect(), array(array($this, 'callbackValidateProduct')), array('attributes' => $this->getCollectedAttributes(), 'product' => $this->_productFactory->create()));
         }
     }
     return $this->_productIds;
 }
Example #8
0
 /**
  * @expectedException \Magento\Framework\Model\Exception
  */
 public function testWalkException()
 {
     $this->_model->walk('test', array(array($this, 'walkCallback')));
 }
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  */
 public function testWalkException()
 {
     $this->_model->walk('test', [[$this, 'walkCallback']]);
 }