Пример #1
0
 /**
  * @return \Magento\Catalog\Model\Resource\Product\Collection
  */
 public function getProductsCollection()
 {
     /* @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, ['qty', 'notify_stock_qty', 'low_stock_date', 'use_config' => 'use_config_notify_stock_qty']);
     $collection->addAttributeToSelect('name', true)->addAttributeToFilter('status', ['in' => $this->productStatus->getVisibleStatusIds()])->setOrder('low_stock_date');
     $this->eventManager->dispatch('rss_catalog_notify_stock_collection_select', ['collection' => $collection]);
     return $collection;
 }
Пример #2
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();
 }