|
25 | 25 |
|
26 | 26 | class ListProduct extends \Magento\Framework\View\Element\Template |
27 | 27 | { |
| 28 | + protected $resultPageFactory; |
| 29 | + |
| 30 | + protected $_tagFactory; |
| 31 | + |
| 32 | + protected $_tagcollection; |
| 33 | + |
| 34 | + protected $_tagHelper; |
28 | 35 |
|
29 | | - /** |
30 | | - * Constructor |
31 | | - * |
32 | | - * @param \Magento\Framework\View\Element\Template\Context $context |
33 | | - * @param array $data |
34 | | - */ |
35 | 36 | public function __construct( |
36 | 37 | \Magento\Framework\View\Element\Template\Context $context, |
| 38 | + \Magento\Framework\View\Result\PageFactory $resultPageFactory, |
| 39 | + \Lof\ProductTags\Model\TagFactory $tagFactory, |
| 40 | + \Lof\ProductTags\Helper\Data $tagdata, |
37 | 41 | array $data = [] |
38 | 42 | ) { |
| 43 | + $this->resultPageFactory = $resultPageFactory; |
| 44 | + $this->_tagFactory = $tagFactory; |
| 45 | + $this->_tagHelper = $tagdata; |
39 | 46 | parent::__construct($context, $data); |
40 | 47 | } |
41 | | - |
42 | | - /** |
43 | | - * @return string |
44 | | - */ |
45 | | - public function getListProducts() |
| 48 | + public function _toHtml(){ |
| 49 | + if(!$this->_tagHelper->getGeneralConfig('enabled')) return; |
| 50 | + if(!$this->_tagHelper->getGeneralConfig('enable_tag_sidebar')) return; |
| 51 | + return parent::_toHtml(); |
| 52 | + } |
| 53 | + function getTagHelper(){ |
| 54 | + return $this->_tagHelper; |
| 55 | + } |
| 56 | + public function getTagCollection() |
46 | 57 | { |
47 | | - //Your block code |
48 | | - return __('Hello Developer! This how to get the storename: %1 and this is the way to build a url: %2', $this->_storeManager->getStore()->getName(), $this->getUrl('contacts')); |
| 58 | + if(!$this->_tagcollection){ |
| 59 | + $limit = $this->_tagHelper->getGeneralConfig('number_tags_sidebar'); |
| 60 | + $limit = $limit?(int)$limit:10; |
| 61 | + $tag = $this->_tagFactory->create(); |
| 62 | + $collection = $tag->getCollection(); |
| 63 | + $collection->addFieldToFilter("status", 1); |
| 64 | + $collection->setOrder("tag_id","DESC"); |
| 65 | + $collection->setPageSize($limit); |
| 66 | + //$collection->setLimit($limit); |
| 67 | + $this->_tagcollection = $collection; |
| 68 | + } |
| 69 | + return $this->_tagcollection; |
49 | 70 | } |
50 | 71 | } |
0 commit comments