Skip to content

Commit f1916af

Browse files
authored
Merge pull request #12 from landofcoder/feature3
Feature3
2 parents b373a34 + 48783c0 commit f1916af

File tree

6 files changed

+76
-12
lines changed

6 files changed

+76
-12
lines changed

Block/Tag/View.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,47 @@
2525

2626
class View extends \Magento\Framework\View\Element\Template
2727
{
28+
protected $resultPageFactory;
29+
30+
protected $_tagFactory;
31+
32+
protected $_tagcollection;
33+
34+
protected $_tagHelper;
2835

29-
/**
30-
* Constructor
31-
*
32-
* @param \Magento\Framework\View\Element\Template\Context $context
33-
* @param array $data
34-
*/
3536
public function __construct(
3637
\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,
3741
array $data = []
3842
) {
43+
$this->resultPageFactory = $resultPageFactory;
44+
$this->_tagFactory = $tagFactory;
45+
$this->_tagHelper = $tagdata;
3946
parent::__construct($context, $data);
4047
}
48+
public function _toHtml(){
49+
if(!$this->_tagHelper->getGeneralConfig('enabled')) return;
50+
if(!$this->_tagHelper->getGeneralConfig('enable_tag_on_product')) return;
51+
return parent::_toHtml();
52+
}
53+
function getTagHelper(){
54+
return $this->_tagHelper;
55+
}
56+
public function getTagCollection()
57+
{
58+
if(!$this->_tagcollection){
59+
$limit = $this->_tagHelper->getGeneralConfig('number_tags');
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;
70+
}
4171
}

Model/ResourceModel/Tag/Collection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
2727
{
28+
protected $_idFieldName = 'tag_id';
29+
protected $_eventPrefix = 'lof_producttags_tag_collection';
30+
protected $_eventObject = 'tag_collection';
2831

2932
/**
3033
* Define resource model

Setup/InstallData.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
* SOFTWARE.
2222
*/
23-
2423
namespace Lof\ProductTags\Setup;
25-
2624
use Magento\Framework\Setup\InstallDataInterface;
2725
use Magento\Framework\Setup\ModuleContextInterface;
2826
use Magento\Framework\Setup\ModuleDataSetupInterface;
29-
3027
class InstallData implements InstallDataInterface
3128
{
32-
3329
/**
3430
* {@inheritdoc}
3531
*/
@@ -39,4 +35,4 @@ public function install(
3935
) {
4036
//Your install script
4137
}
42-
}
38+
}

etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@
6969
</group>
7070
</section>
7171
</system>
72-
</config>
72+
</config>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" ?>
2+
<page layout="2column-left" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
3+
<body>
4+
<referenceContainer name="product.info.main">
5+
<block class="Lof\ProductTags\Block\Tag\View" name="tag.view" template="Lof_ProductTags::tag/product/tags.phtml"/>
6+
</referenceContainer>
7+
</body>
8+
</page>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* @var $block \Lof\ProductTags\Block\Tag\Product\ListProduct
4+
*/
5+
?>
6+
<?php
7+
$tags = $this->getTagCollection();
8+
$title = $this->getTagHelper()->getGeneralConfig("product_tag_title");
9+
if($tags && $tags->getSize()){
10+
?>
11+
<div class="block block-tags block-product-tags">
12+
<div class="block-title"><h2><?php echo $title; ?></h2></div>
13+
<div class="block-content">
14+
<ul class="list-tags">
15+
<?php foreach($tags as $tag): ?>
16+
<li><a href="<?php echo $tag->getIdentifier(); ?>">
17+
<?php
18+
echo $tag->getTagTitle();
19+
?>
20+
</li>
21+
<?php endforeach; ?>
22+
</ul>
23+
</div>
24+
</div>
25+
<?php
26+
}
27+
?>

0 commit comments

Comments
 (0)