|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright (c) 2019 Landofcoder |
| 4 | + * |
| 5 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | + * of this software and associated documentation files (the "Software"), to deal |
| 7 | + * in the Software without restriction, including without limitation the rights |
| 8 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | + * copies of the Software, and to permit persons to whom the Software is |
| 10 | + * furnished to do so, subject to the following conditions: |
| 11 | + * |
| 12 | + * The above copyright notice and this permission notice shall be included in all |
| 13 | + * copies or substantial portions of the Software. |
| 14 | + * |
| 15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | + * SOFTWARE. |
| 22 | + */ |
| 23 | + |
| 24 | +namespace Lof\ProductTags\Block; |
| 25 | + |
| 26 | +class AbstractWidget extends \Magento\Framework\View\Element\Template |
| 27 | +{ |
| 28 | + protected $resultPageFactory; |
| 29 | + |
| 30 | + protected $_tagFactory; |
| 31 | + |
| 32 | + protected $_tagcollection; |
| 33 | + |
| 34 | + protected $_tagHelper; |
| 35 | + |
| 36 | + public function __construct( |
| 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, |
| 41 | + array $data = [] |
| 42 | + ) { |
| 43 | + $this->resultPageFactory = $resultPageFactory; |
| 44 | + $this->_tagFactory = $tagFactory; |
| 45 | + $this->_tagHelper = $tagdata; |
| 46 | + parent::__construct($context, $data); |
| 47 | + } |
| 48 | + |
| 49 | + function getLimit(){ |
| 50 | + $default_limit = $this->_tagHelper->getGeneralConfig('number_tags_sidebar'); |
| 51 | + if($this->hasData("number_tags")){ |
| 52 | + $limit = (int)$this->getData("number_tags"); |
| 53 | + }else { |
| 54 | + $limit = $default_limit; |
| 55 | + } |
| 56 | + $limit = $limit?(int)$limit:10; |
| 57 | + return $limit; |
| 58 | + } |
| 59 | + |
| 60 | + function getTagHelper(){ |
| 61 | + return $this->_tagHelper; |
| 62 | + } |
| 63 | + |
| 64 | + public function getTagCollection() |
| 65 | + { |
| 66 | + if(!$this->_tagcollection){ |
| 67 | + $limit = $this->getLimit(); |
| 68 | + $tag = $this->_tagFactory->create(); |
| 69 | + $collection = $tag->getCollection(); |
| 70 | + $collection->addFieldToFilter("status", 1); |
| 71 | + $collection->setOrder("tag_id","DESC"); |
| 72 | + $collection->setPageSize($limit); |
| 73 | + //$collection->setLimit($limit); |
| 74 | + $this->_tagcollection = $collection; |
| 75 | + } |
| 76 | + return $this->_tagcollection; |
| 77 | + } |
| 78 | +} |
0 commit comments