Skip to content

Commit 4b37c06

Browse files
authored
Merge pull request #5 from landofcoder/develop
Develop
2 parents 1ba421a + cf09e13 commit 4b37c06

File tree

9 files changed

+166
-18
lines changed

9 files changed

+166
-18
lines changed

Controller/Router.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace Lof\ProductTags\Controller;
3+
class Router implements \Magento\Framework\App\RouterInterface
4+
{
5+
protected $actionFactory;
6+
protected $helperData;
7+
protected $_response;
8+
public function __construct(
9+
\Magento\Framework\App\ActionFactory $actionFactory,
10+
\Magento\Framework\App\ResponseInterface $response,
11+
\Lof\ProductTags\Helper\Data $helperData
12+
) {
13+
$this->actionFactory = $actionFactory;
14+
$this->helperData = $helperData;
15+
$this->_response = $response;
16+
}
17+
public function match(\Magento\Framework\App\RequestInterface $request)
18+
{
19+
$identifier = trim($request->getPathInfo(), '/');
20+
if($this->helperData->getGeneralConfig('enable') == 1){
21+
$url = $this->helperData->getGeneralConfig('route');
22+
if($url){
23+
if(strpos($identifier, $url) !== false) {
24+
$request->setModuleName('lofproducttags')-> //module name
25+
setControllerName('tag')-> //controller name
26+
setActionName('view'); //action name
27+
}
28+
29+
}
30+
}
31+
else {
32+
return false;
33+
}
34+
35+
return $this->actionFactory->create(
36+
'Magento\Framework\App\Action\Forward',
37+
['request' => $request]
38+
);
39+
}
40+
}

Controller/Tag/Index.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Lof\ProductTags\Controller\Adminhtml\Tag;
4+
5+
class Index extends \Magento\Backend\App\Action
6+
{
7+
protected $resultPageFactory = false;
8+
9+
public function __construct(
10+
\Magento\Backend\App\Action\Context $context,
11+
\Magento\Framework\View\Result\PageFactory $resultPageFactory
12+
)
13+
{
14+
parent::__construct($context);
15+
$this->resultPageFactory = $resultPageFactory;
16+
}
17+
18+
public function execute()
19+
{
20+
$resultPage = $this->resultPageFactory->create();
21+
$resultPage->getConfig()->getTitle()->prepend((__('Posts')));
22+
23+
return $resultPage;
24+
}
25+
26+
27+
}

Helper/Data.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
namespace Lof\ProductTags\Helper;
2525

26+
use Magento\Framework\App\Config\ScopeConfigInterface;
27+
use Magento\Store\Model\ScopeInterface;
28+
use Magento\Framework\App\Helper\Context;
2629
use Magento\Framework\App\Helper\AbstractHelper;
2730

2831
class Data extends AbstractHelper
@@ -31,17 +34,26 @@ class Data extends AbstractHelper
3134
/**
3235
* @param \Magento\Framework\App\Helper\Context $context
3336
*/
34-
public function __construct(
35-
\Magento\Framework\App\Helper\Context $context
36-
) {
37+
38+
protected $scopeConfig;
39+
const XML_PATH_TAG = 'lofproductags/';
40+
public function __construct(Context $context,ScopeConfigInterface $scopeConfig)
41+
{
3742
parent::__construct($context);
43+
$this->scopeConfig=$scopeConfig;
3844
}
3945

4046
/**
4147
* @return bool
4248
*/
43-
public function isEnabled()
44-
{
45-
return true;
49+
public function getConfigValue($field, $storeId = null)
50+
{
51+
return $this->scopeConfig->getValue(
52+
$field, ScopeInterface::SCOPE_STORE, $storeId
53+
);
4654
}
55+
public function getGeneralConfig($code, $storeId = null)
56+
{
57+
return $this->getConfigValue(self::XML_PATH_TAG .'general/'. $code, $storeId);
58+
}
4759
}

etc/adminhtml/menu.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?xml version="1.0" ?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
33
<menu>
4-
<add id="Lof::top_level" module="Lof_ProductTags" resource="Magento_Backend::content" sortOrder="9999" title="Lof"/>
5-
<add action="lofproducttags/tags/index" id="Lof_ProductTags::tags_index" module="Lof_ProductTags" parent="Lof::top_level" resource="Lof_ProductTags::tags_index" sortOrder="9999" title="tags index"/>
6-
<add action="lof_producttags/tag/index" id="Lof_ProductTags::lof_producttags_tag" module="Lof_ProductTags" parent="Lof::top_level" resource="Magento_Backend::content" sortOrder="9999" title="Tag"/>
4+
<add id="Lof_ProductTags::producttags" module="Lof_ProductTags" parent="Magento_Catalog::inventory" resource="Lof_ProductTags::lofproducttags" action="lofproducttags/tag/index" sortOrder="9999" title="Product Tags"/>
75
</menu>
86
</config>

etc/adminhtml/routes.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44
<route frontName="lofproducttags" id="lofproducttags">
55
<module before="Magento_Backend" name="Lof_ProductTags"/>
66
</route>
7-
<route frontName="lof_producttags" id="lof_producttags">
8-
<module before="Magento_Backend" name="Lof_ProductTags"/>
9-
</route>
107
</router>
118
</config>

etc/adminhtml/system.xml

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,64 @@
1010
<resource>Lof_ProductTags::config_lof_producttags</resource>
1111
<group id="general" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
1212
<label>general</label>
13-
<field id="enabled" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label" type="select">
14-
<label>enabled</label>
15-
<comment/>
16-
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
17-
</field>
13+
<field id="enabled" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
14+
<label>Enable</label>
15+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
16+
</field>
17+
<field id="route" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
18+
<label>Route</label>
19+
<comment>This text will change your url.</comment>
20+
<depends>
21+
<field id ="enabled">1</field>
22+
</depends>
23+
</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>
26+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
27+
<comment>show/hide product tags on product detail page.</comment>
28+
<depends>
29+
<field id ="enabled">1</field>
30+
</depends>
31+
</field>
32+
<field id="product_tag_title" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
33+
<label>Product Tags Block Title</label>
34+
<depends>
35+
<field id ="enabled">1</field>
36+
<field id ="enable_tag_on_product">1</field>
37+
</depends>
38+
</field>
39+
<field id="number_tags" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
40+
<label>Limit tags to show</label>
41+
<depends>
42+
<field id ="enabled">1</field>
43+
<field id ="enable_tag_on_product">1</field>
44+
</depends>
45+
</field>
46+
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>
49+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
50+
<comment>show/hide product tags on sidebar position.</comment>
51+
<depends>
52+
<field id ="enabled">1</field>
53+
</depends>
54+
</field>
55+
<field id="tag_sidebar_title" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
56+
<label>Sidebar Tags Block Title</label>
57+
<depends>
58+
<field id ="enabled">1</field>
59+
<field id ="enable_tag_sidebar">1</field>
60+
</depends>
61+
</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>
64+
<depends>
65+
<field id ="enabled">1</field>
66+
<field id ="enable_tag_sidebar">1</field>
67+
</depends>
68+
</field>
1869
</group>
70+
<!-- <resource>Lof_ProductTags::lof_producttags</resource> -->
1971
</section>
2072
</system>
2173
</config>

etc/config.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
<default>
44
<lofproductags>
55
<general>
6-
<enabled/>
6+
<enabled>1</enabled>
7+
<route>tags</route>
8+
<enable_tag_on_product>1</enable_tag_on_product>
9+
<product_tag_title>Trending</product_tag_title>
10+
<number_tags>10</number_tags>
11+
<enable_tag_sidebar>1</enable_tag_sidebar>
12+
<tag_sidebar_title>Product Tags</tag_sidebar_title>
13+
<number_tags_sidebar>20</number_tags_sidebar>
714
</general>
815
</lofproductags>
916
</default>

etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
</argument>
1919
</arguments>
2020
</type>
21+
2122
</config>

etc/frontend/di.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3+
<type name="Magento\Framework\App\RouterList">
4+
<arguments>
5+
<argument name="routerList" xsi:type="array">
6+
<item name="producttags" xsi:type="array">
7+
<item name="class" xsi:type="string">Lof\ProductTags\Controller\Router</item>
8+
<item name="disable" xsi:type="boolean">false</item>
9+
<item name="sortOrder" xsi:type="string">50</item>
10+
</item>
11+
</argument>
12+
</arguments>
13+
</type>
14+
</config>

0 commit comments

Comments
 (0)