Skip to content

Commit 1a5ab00

Browse files
committed
updated files css and widget
1 parent 9d90b73 commit 1a5ab00

File tree

13 files changed

+208
-92
lines changed

13 files changed

+208
-92
lines changed

Block/AbstractWidget.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
}

Block/Tag/Product/Sidebar.php

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,10 @@
2222
*/
2323

2424
namespace Lof\ProductTags\Block\Tag\Product;
25+
use Lof\ProductTags\Block\AbstractWidget;
2526

26-
class Sidebar extends \Magento\Framework\View\Element\Template
27+
class Sidebar extends AbstractWidget
2728
{
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-
}
4829
public function _toHtml(){
4930
if(!$this->_tagHelper->getGeneralConfig('enabled')) return;
5031
if(!$this->_tagHelper->getGeneralConfig('enable_tag_sidebar')) return;
@@ -54,22 +35,5 @@ public function _toHtml(){
5435
}
5536
return "";
5637
}
57-
function getTagHelper(){
58-
return $this->_tagHelper;
59-
}
60-
public function getTagCollection()
61-
{
62-
if(!$this->_tagcollection){
63-
$limit = $this->_tagHelper->getGeneralConfig('number_tags_sidebar');
64-
$limit = $limit?(int)$limit:10;
65-
$tag = $this->_tagFactory->create();
66-
$collection = $tag->getCollection();
67-
$collection->addFieldToFilter("status", 1);
68-
$collection->setOrder("tag_id","DESC");
69-
$collection->setPageSize($limit);
70-
//$collection->setLimit($limit);
71-
$this->_tagcollection = $collection;
72-
}
73-
return $this->_tagcollection;
74-
}
38+
7539
}

Block/Widget/LofproductTags.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323

2424
namespace Lof\ProductTags\Block\Widget;
2525

26-
use Magento\Framework\View\Element\Template;
26+
use Lof\ProductTags\Block\AbstractWidget;
2727
use Magento\Widget\Block\BlockInterface;
2828

29-
class LofproductTags extends Template implements BlockInterface
29+
class LofproductTags extends AbstractWidget implements BlockInterface
3030
{
3131

3232
protected $_template = "widget/lofproducttags.phtml";
3333

34+
public function _toHtml(){
35+
$_tag_collection = $this->getTagCollection();
36+
if($_tag_collection && $_tag_collection->getSize()){
37+
return parent::_toHtml();
38+
}
39+
}
40+
3441
}

etc/adminhtml/system.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@
2121
<field id="enabled">1</field>
2222
</depends>
2323
</field>
24+
25+
<field id="show_number_products" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
26+
<label>Show number products beside tags</label>
27+
<depends>
28+
<field id="enabled">1</field>
29+
</depends>
30+
</field>
31+
2432
<field id="enable_tag_on_product" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
25-
<label>Enable tags block</label>
33+
<label>Enable tags block on Product Page</label>
2634
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2735
<comment>show/hide product tags on product detail page.</comment>
2836
<depends>
@@ -45,7 +53,7 @@
4553
</field>
4654

4755
<field id="enable_tag_sidebar" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
48-
<label>Enable tag block on sidebar</label>
56+
<label>Enable tag block on Sidebar</label>
4957
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
5058
<comment>show/hide product tags on sidebar position.</comment>
5159
<depends>
@@ -60,12 +68,13 @@
6068
</depends>
6169
</field>
6270
<field id="number_tags_sidebar" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
63-
<label>Limit tags to show on sidebar</label>
71+
<label>Limit tags to show on Sidebar</label>
6472
<depends>
6573
<field id="enabled">1</field>
6674
<field id="enable_tag_sidebar">1</field>
6775
</depends>
6876
</field>
77+
6978
</group>
7079
</section>
7180
</system>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<enabled>1</enabled>
77
<route>tags</route>
88
<enable_tag_on_product>1</enable_tag_on_product>
9+
<show_number_products>1</show_number_products>
910
<product_tag_title>Trending</product_tag_title>
1011
<number_tags>10</number_tags>
1112
<enable_tag_sidebar>1</enable_tag_sidebar>

etc/widget.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?xml version="1.0" ?>
22
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
33
<widget class="Lof\ProductTags\Block\Widget\LofproductTags" id="lof_producttags_lofproducttags">
4-
<label>lofproductTags</label>
5-
<description>lofproductTags</description>
4+
<label>Display Product Tags</label>
5+
<description>Display Product Tags Widget</description>
66
<parameters>
7-
<parameter name="title" sort_order="5" visible="true" xsi:type="text">
8-
<label>title</label>
7+
<parameter name="title" visible="true" xsi:type="text">
8+
<label>Widget Title</label>
9+
</parameter>
10+
<parameter name="number_tags" visible="true" xsi:type="text">
11+
<label>Limit tags to show</label>
12+
</parameter>
13+
<parameter name="show_number_products" xsi:type="select" visible="true" source_model="Magento\Config\Model\Config\Source\Yesno">
14+
<label translate="true">Show Number Of Products</label>
915
</parameter>
1016
</parameters>
1117
</widget>

view/frontend/layout/default.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Landofcoder
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Landofcoder.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://www.landofcoder.com/license-agreement.html
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category Landofcoder
18+
* @package Lof_ProductTags
19+
* @copyright Copyright (c) 2019 Landofcoder (https://www.landofcoder.com/)
20+
* @license https://www.landofcoder.com/LICENSE-1.0.html
21+
*/
22+
-->
23+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
25+
<head>
26+
<css src="Lof_ProductTags::css/styles.css" />
27+
</head>
28+
</page>

view/frontend/templates/listtags.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
?>
66
<div>
77
<?= $block->getListTags() ?>
8-
<?= __('Hello Lof_ProductTags::listtags.phtml') ?>
98
</div>

view/frontend/templates/tag/product/listProduct.phtml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,21 @@
66
<?php
77
$tags = $this->getTagCollection();
88
$title = $this->getTagHelper()->getGeneralConfig("tag_sidebar_title");
9+
$show_number_products = $this->getTagHelper()->getGeneralConfig("show_number_products");
10+
$show_number_products = $show_number_products?(int)$show_number_products:0;
911
if($tags && $tags->getSize()){
1012
?>
1113
<div class="block block-tags block-product-tags">
12-
<div class="block-title"><h2><?php echo $title; ?></h2></div>
14+
<?php if($title) { ?><div class="block-title"><h2><?php echo $title; ?></h2></div><?php } ?>
1315
<div class="block-content">
14-
<ul style="padding: 0px;" class="list-tags">
16+
<ul class="list-tags list-product-tags">
1517
<?php foreach($tags as $tag): ?>
16-
<li style="list-style-type: none; float: left; margin:5px 10px; border: 1px solid #000000; border-radius: 5px; padding: 5px;"><a href="<?php
17-
echo $this->getTagHelper()->getTagUrl($tag->getIdentifier()); ?>">
18-
<style>
19-
li:hover{
20-
background-color: #e4e4e4;
21-
}
22-
a:hover{
23-
color: black;
24-
text-decoration: none;
25-
}
26-
</style>
18+
<li><a href="<?php echo $this->getTagHelper()->getTagUrl($tag->getIdentifier()); ?>">
2719
<?php
28-
echo $tag->getTagTitle();
20+
echo $tag->getTagTitle();
21+
if($show_number_products){
22+
echo " (".$tag->getNumberProducts().")";
23+
}
2924
?>
3025
</a>
3126
</li>

view/frontend/templates/tag/product/sidebar.phtml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,21 @@
66
<?php
77
$tags = $this->getTagCollection();
88
$title = $this->getTagHelper()->getGeneralConfig("tag_sidebar_title");
9+
$show_number_products = $this->getTagHelper()->getGeneralConfig("show_number_products");
10+
$show_number_products = $show_number_products?(int)$show_number_products:0;
911
if($tags && $tags->getSize()){
1012
?>
1113
<div class="block block-tags block-product-tags">
12-
<div class="block-title"><h2><?php echo $title; ?></h2></div>
14+
<?php if($title) { ?><div class="block-title"><h2><?php echo $title; ?></h2></div><?php } ?>
1315
<div class="block-content">
14-
<ul style="padding: 0px;" class="list-tags">
16+
<ul class="list-tags list-product-tags">
1517
<?php foreach($tags as $tag): ?>
16-
<li style="list-style-type: none; float: left; margin:5px 10px; border: 1px solid #000000; border-radius: 5px; padding: 5px;"><a href="<?php
17-
echo $this->getTagHelper()->getTagUrl($tag->getIdentifier()); ?>">
18-
<style>
19-
li:hover{
20-
background-color: #e4e4e4;
21-
}
22-
a:hover{
23-
color: black;
24-
text-decoration: none;
25-
}
26-
</style>
18+
<li><a href="<?php echo $this->getTagHelper()->getTagUrl($tag->getIdentifier()); ?>">
2719
<?php
2820
echo $tag->getTagTitle();
21+
if($show_number_products){
22+
echo " (".$tag->getNumberProducts().")";
23+
}
2924
?>
3025
</a>
3126
</li>

0 commit comments

Comments
 (0)