Skip to content

Commit 23747b1

Browse files
authored
Merge pull request #44 from landofcoder/develop
Develop
2 parents 482bc6d + f664ff8 commit 23747b1

27 files changed

+244
-123
lines changed

Api/Data/TagProductLinkInterface.php

100644100755
File mode changed.

Block/AbstractWidget.php

+78
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/Adminhtml/Tags/Edit/DeleteButton.php

100644100755
File mode changed.

Block/Tag/Product/Sidebar.php

+3-39
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

+9-2
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
}

Controller/Adminhtml/Tag/Delete.php

100644100755
File mode changed.

Controller/Adminhtml/Tag/MassDelete.php

100644100755
File mode changed.

Controller/Adminhtml/Tag/Save.php

100644100755
File mode changed.

Controller/Router.php

+9
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ public function __construct(
2727
}
2828
public function match(\Magento\Framework\App\RequestInterface $request)
2929
{
30+
die("Awetae");
3031
if (!$this->dispatched) {
32+
3133
$identifier = trim($request->getPathInfo(), '/');
3234
$origUrlKey = $identifier;
3335
$condition = new DataObject(['url_key' => $identifier, 'continue' => true]);
3436
$this->eventManager->dispatch(
3537
'lof_producttags_controller_router_match_before',
3638
['router' => $this, 'condition' => $condition]
3739
);
40+
3841
$urlKey = $condition->getUrlKey();
3942
if ($condition->getRedirectUrl()) {
4043
$this->response->setRedirect($condition->getRedirectUrl());
@@ -74,6 +77,12 @@ public function match(\Magento\Framework\App\RequestInterface $request)
7477

7578
}
7679
}
80+
$request->setDispatched(true);
81+
$this->dispatched = true;
82+
return $this->actionFactory->create(
83+
'Magento\Framework\App\Action\Forward',
84+
['request' => $request]
85+
);
7786
}
7887
}
7988
}

Model/Data/TagProductLink.php

100644100755
File mode changed.

Model/ResourceModel/AbstractCollection.php

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function __construct(
5959
protected function performAfterLoad($tableName, $linkField)
6060
{
6161
$linkedIds = $this->getColumnValues($linkField);
62+
6263
if (count($linkedIds)) {
6364
$connection = $this->getConnection();
6465
$select = $connection->select()->from(['product_tag_store' => $this->getTable($tableName)])

Model/ResourceModel/Tag/Grid/Collection.php

100644100755
File mode changed.

Samples/Lof_product_tags_sample.json

+1-1
Large diffs are not rendered by default.

Setup/InstallSchema.php

+16-21
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,18 @@ public function install(
115115
->setComment('Product Tags Table')
116116
->setOption('type', 'InnoDB')
117117
->setOption('charset', 'utf8');
118-
$installer->getConnection()->createTable($table);
119-
$installer->getConnection()->addIndex(
120-
$installer->getTable('lof_producttags_tag'),
121-
$setup->getIdxName(
122-
$installer->getTable('lof_producttags_tag'),
123-
['tag_title','identifier','tag_description'],
124-
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
125-
),
126-
['tag_title','identifier','tag_description'],
127-
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
128-
);
118+
119+
$installer->getConnection()->createTable($table);
120+
$installer->getConnection()->addIndex(
121+
$installer->getTable('lof_producttags_tag'),
122+
$setup->getIdxName(
123+
$installer->getTable('lof_producttags_tag'),
124+
['tag_title','identifier','tag_description'],
125+
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
126+
),
127+
['tag_title','identifier','tag_description'],
128+
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
129+
);
129130
}
130131
//Create lof_producttags_product table
131132
if (!$installer->tableExists('lof_producttags_product')) {
@@ -137,10 +138,8 @@ public function install(
137138
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
138139
null,
139140
[
140-
'identity' => false,
141141
'unsigned' => true,
142-
'nullable' => false,
143-
'foreign' => true
142+
'nullable' => false
144143
],
145144
'Tag ID'
146145
)
@@ -149,10 +148,9 @@ public function install(
149148
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
150149
null,
151150
[
152-
'identity' => true,
153151
'unsigned' => true,
154152
'nullable' => false,
155-
'primary' => true
153+
'default' => '0'
156154
],
157155
'Product ID'
158156
)
@@ -178,10 +176,8 @@ public function install(
178176
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
179177
null,
180178
[
181-
'identity' => false,
182179
'unsigned' => true,
183-
'nullable' => false,
184-
'foreign' => true
180+
'nullable' => false
185181
],
186182
'Tag ID'
187183
)
@@ -190,10 +186,9 @@ public function install(
190186
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
191187
null,
192188
[
193-
'identity' => true,
194189
'unsigned' => true,
195190
'nullable' => false,
196-
'primary' => true
191+
'default' => '0'
197192
],
198193
'Store ID'
199194
)

Ui/Component/DataProvider.php

100644100755
File mode changed.

etc/adminhtml/system.xml

+19-10
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,67 @@
1414
<label>Enable</label>
1515
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1616
</field>
17-
<field id="route" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
17+
<field id="route" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
1818
<label>Route</label>
1919
<comment>This text will change your url.</comment>
2020
<depends>
2121
<field id="enabled">1</field>
2222
</depends>
2323
</field>
24-
<field id="enable_tag_on_product" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
25-
<label>Enable tags block</label>
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+
32+
<field id="enable_tag_on_product" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
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>
2937
<field id="enabled">1</field>
3038
</depends>
3139
</field>
32-
<field id="product_tag_title" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
40+
<field id="product_tag_title" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
3341
<label>Product Tags Block Title</label>
3442
<depends>
3543
<field id="enabled">1</field>
3644
<field id="enable_tag_on_product">1</field>
3745
</depends>
3846
</field>
39-
<field id="number_tags" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
47+
<field id="number_tags" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
4048
<label>Limit tags to show</label>
4149
<depends>
4250
<field id="enabled">1</field>
4351
<field id="enable_tag_on_product">1</field>
4452
</depends>
4553
</field>
4654

47-
<field id="enable_tag_sidebar" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
48-
<label>Enable tag block on sidebar</label>
55+
<field id="enable_tag_sidebar" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
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>
5260
<field id="enabled">1</field>
5361
</depends>
5462
</field>
55-
<field id="tag_sidebar_title" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
63+
<field id="tag_sidebar_title" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
5664
<label>Sidebar Tags Block Title</label>
5765
<depends>
5866
<field id="enabled">1</field>
5967
<field id="enable_tag_sidebar">1</field>
6068
</depends>
6169
</field>
62-
<field id="number_tags_sidebar" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
63-
<label>Limit tags to show on sidebar</label>
70+
<field id="number_tags_sidebar" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
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

+1
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/frontend/di.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<item name="producttags" xsi:type="array">
77
<item name="class" xsi:type="string">Lof\ProductTags\Controller\Router</item>
88
<item name="disable" xsi:type="boolean">false</item>
9-
<item name="sortOrder" xsi:type="string">50</item>
9+
<item name="sortOrder" xsi:type="string">60</item>
1010
</item>
1111
</argument>
1212
</arguments>

etc/frontend/routes.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
33
<router id="standard">
44
<route frontName="lofproducttags" id="lofproducttags">
5-
<module name="Lof_ProductTags"/>
5+
<module name="Lof_ProductTags" before="Magento_Backend" />
66
</route>
77
</router>
88
</config>

0 commit comments

Comments
 (0)