Skip to content

Commit

Permalink
Config "Category page" - layout, content width, products per row etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
tangar76 committed Mar 31, 2020
1 parent ddb5938 commit 421ce40
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/ColumnsCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Swissup\ThemeEditorSwissupAbsolute\Block\Adminhtml\System\Config\Form\Field;

class ColumnsCount extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
/**
* Prepare to render
*
* @return void
*/
protected function _prepareToRender()
{
$this->addColumn('width', ['label' => __('Min width, px')]);
$this->addColumn('columns', ['label' => __('Columns')]);
$this->addColumn('spacing', ['label' => __('Spacing, %')]);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add columns exception');
}
}
14 changes: 14 additions & 0 deletions Model/Config/Backend/CategoryColumnsCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Swissup\ThemeEditorSwissupAbsolute\Model\Config\Backend;

class CategoryColumnsCount extends \Swissup\ThemeEditor\Model\Config\Backend\ColumnsCount
{
/**
* {@inheritdoc}
*/
protected function getItemWidthValue($columns, $spacing)
{
return "calc((100% - {$spacing}%) / {$columns})";
}
}
53 changes: 53 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,59 @@
<frontend_model>Swissup\ThemeEditor\Block\Adminhtml\System\Config\Form\Field\Color</frontend_model>
</field>
</group>
<group id="category" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Category Page</label>
<field id="categoryPagePreview" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Preview page layout</label>
<frontend_model>Swissup\ThemeEditorSwissupAbsolute\Block\Adminhtml\System\Config\Form\Field\CategoryPagePreview</frontend_model>
</field>
<field id="page_layout" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Layout</label>
<source_model>Swissup\ThemeEditor\Model\Config\Source\Layout</source_model>
<backend_model>Swissup\ThemeEditorSwissupAbsolute\Model\Config\Backend\CategoryPageLayout</backend_model>
</field>
<field id="list_mode" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Products list mode</label>
<source_model>Magento\Catalog\Model\Config\Source\ListMode</source_model>
<config_path>catalog/frontend/list_mode</config_path>
</field>
<group id="grid" translate="label" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Grid Mode</label>
<field id="per_page_values" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Products per Page Allowed Values</label>
<comment>Comma-separated.</comment>
<validate>validate-per-page-value-list required-entry</validate>
<config_path>catalog/frontend/grid_per_page_values</config_path>
</field>
<field id="per_page" translate="label comment" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Products per Page Default Value</label>
<comment>Must be in the allowed values list</comment>
<validate>validate-per-page-value</validate>
<config_path>catalog/frontend/grid_per_page</config_path>
</field>
<field id="columns_count" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Columns per Row</label>
<comment><![CDATA[<b>Min width</b> - min width of a screen where columns number must be applied.<br /><b>Columns</b> - columns count itself.<br /><b>Spacing</b> - spacing between cells in grid. Play with this value for each width to adjust products in a row.]]></comment>
<frontend_model>Swissup\ThemeEditorSwissupAbsolute\Block\Adminhtml\System\Config\Form\Field\ColumnsCount</frontend_model>
<backend_model>Swissup\ThemeEditorSwissupAbsolute\Model\Config\Backend\CategoryColumnsCount</backend_model>
</field>
</group>
<group id="list" translate="label" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
<label>List Mode</label>
<field id="per_page_values" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Products per Page Allowed Values</label>
<comment>Comma-separated.</comment>
<validate>validate-per-page-value-list required-entry</validate>
<config_path>catalog/frontend/list_per_page_values</config_path>
</field>
<field id="per_page" translate="label comment" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Products per Page Default Value</label>
<comment>Must be in the allowed values list</comment>
<validate>validate-per-page-value</validate>
<config_path>catalog/frontend/list_per_page</config_path>
</field>
</group>
</group>
<include path="Swissup_ThemeEditor::system/head.xml"/>
</section>
</system>
Expand Down
5 changes: 5 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<footerInformationalHeadings_color>#d5e1e9</footerInformationalHeadings_color>
<footerInformationalLinks_color>#d5e1e9</footerInformationalLinks_color>
</fonts>
<category>
<grid>
<columns_count>{"640":{"columns":"3","spacing":"4"},"1024":{"columns":"4","spacing":"6"}}</columns_count>
</grid>
</category>
<css_selector>
<body>body</body>
<footer>.page-footer</footer>
Expand Down
29 changes: 29 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<virtualType name="Swissup\ThemeEditorSwissupAbsolute\Block\Adminhtml\System\Config\Form\Field\CategoryPagePreview" type="Swissup\ThemeEditor\Block\Adminhtml\System\Config\Form\Field\PagePreview">
<arguments>
<argument name="previewData" xsi:type="array">
<item name="template" xsi:type="string">Swissup_ThemeEditor::config/category-page-preview.phtml</item>
<item name="content_width" xsi:type="number">1280</item>
<item name="header_width" xsi:type="number">1280</item>
</argument>
</arguments>
</virtualType>
<virtualType name="Swissup\ThemeEditorSwissupAbsolute\Model\Config\Backend\CategoryPageLayout" type="Swissup\ThemeEditor\Model\Config\Backend\PageLayout">
<arguments>
<argument name="data" xsi:type="array">
<item name="themeCode" xsi:type="string">Swissup/absolute</item>
<item name="handle" xsi:type="string">catalog_category_view</item>
</argument>
</arguments>
</virtualType>
<type name="Swissup\ThemeEditorSwissupAbsolute\Model\Config\Backend\CategoryColumnsCount">
<arguments>
<argument name="data" xsi:type="array">
<item name="themeCode" xsi:type="string">Swissup/absolute</item>
<item name="handle" xsi:type="string">catalog_category_view</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit 421ce40

Please sign in to comment.