Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy committed Jul 28, 2022
0 parents commit dfd942e
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Block/CategorySeoText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Webidea24\CategorySeoText\Block;

use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\Framework\View\Element\Template;

class CategorySeoText extends Template
{

/**
* @var Resolver
*/
private $catalogResolver;

public function __construct(
Template\Context $context,
Resolver $resolver,
array $data = []
)
{
parent::__construct($context, $data);
$this->catalogResolver = $resolver;
}

public function toHtml()
{
if (!empty($this->getSeoText())) {
return parent::toHtml();
}

return '';
}

public function getSeoText()
{
return $this->getCurrentCategory()->getData('wi24_seo_text');
}

public function getCurrentCategory(): Category
{
return $this->catalogResolver->get()->getCurrentCategory();
}
}
40 changes: 40 additions & 0 deletions Setup/InstallData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Webidea24\CategorySeoText\Setup;

use Magento\Catalog\Model\Category;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;

class InstallData implements InstallDataInterface
{
/**
* @var EavSetupFactory
*/
private $eavSetupFactory;

public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(Category::ENTITY, 'wi24_seo_text', [
'type' => 'text',
'label' => 'SEO-Text',
'input' => 'textarea',
'visible' => true,
'default' => '',
'required' => false,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'Content',
]);
}
}
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "webidea24/magento2-module-category-seo-text",
"description": "Magento 2 Module: Add easily a seo-text to the category page on footer",
"type": "magento2-module",
"require": {
"magento/framework": "*"
},
"license": [
"MIT"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Webidea24\\CategorySeoText\\": ""
}
}
}
5 changes: 5 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Webidea24_CategorySeoText" setup_version="1.0.0"/>
</config>
5 changes: 5 additions & 0 deletions registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Webidea24_CategorySeoText', __DIR__);
32 changes: 32 additions & 0 deletions view/adminhtml/ui_component/category_form.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="content">
<field name="wi24_seo_text" template="ui/form/field" sortOrder="55" formElement="wysiwyg">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="wysiwygConfigData" xsi:type="array">
<item name="height" xsi:type="string">100px</item>
<item name="add_variables" xsi:type="boolean">false</item>
<item name="add_widgets" xsi:type="boolean">false</item>
<item name="add_images" xsi:type="boolean">true</item>
<item name="add_directives" xsi:type="boolean">true</item>
</item>
<item name="source" xsi:type="string">category</item>
</item>
</argument>
<settings>
<label translate="true">SEO-Text</label>
<notice translate="true">Note: Keyboard shortcut to activate editor help : Alt + 0 (Windows) or &#x2325;0 (MacOS)</notice>
<dataScope>wi24_seo_text</dataScope>
</settings>
<formElements>
<wysiwyg class="Magento\Catalog\Ui\Component\Category\Form\Element\Wysiwyg">
<settings>
<rows>8</rows>
<wysiwyg>true</wysiwyg>
</settings>
</wysiwyg>
</formElements>
</field>
</fieldset>
</form>
9 changes: 9 additions & 0 deletions view/frontend/layout/catalog_category_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Webidea24\CategorySeoText\Block\CategorySeoText" name="category.seo-text" after="category.products" template="Webidea24_CategorySeoText::seo-text.phtml"/>
</referenceContainer>
</body>
</page>
6 changes: 6 additions & 0 deletions view/frontend/templates/seo-text.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
/** @var \Webidea24\CategorySeoText\Block\CategorySeoText $block */
?>
<div class="category-seo-text">
<?= /** @noEscape */$block->getSeoText(); ?>
</div>
5 changes: 5 additions & 0 deletions view/frontend/web/css/source/_module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
& when (@media-common = true) {
.category-seo-text {
margin-top: @indent__base;
}
}

0 comments on commit dfd942e

Please sign in to comment.