Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
joshine
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
joshine
Commits
f4554fb0
Commit
f4554fb0
authored
Feb 10, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : 动态列设置与展示
parent
d80f7c77
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
222 additions
and
5 deletions
+222
-5
app/code/Joshine/Category/Block/Html/Topmenu.php
+53
-3
app/code/Joshine/Category/Model/Category/Attribute/Source/Columns.php
+47
-0
app/code/Joshine/Category/Plugin/Block/Topmenu.php
+7
-1
app/code/Joshine/Category/Setup/UpgradeData.php
+69
-0
app/code/Joshine/Category/etc/module.xml
+1
-1
app/code/Joshine/Category/view/adminhtml/ui_component/category_form.xml
+45
-0
No files found.
app/code/Joshine/Category/Block/Html/Topmenu.php
View file @
f4554fb0
...
...
@@ -59,6 +59,55 @@ class Topmenu extends JoshineMenu
return
count
(
$colBrakes
)
&&
$colBrakes
[
$counter
][
'colbrake'
];
}
protected
function
_getMenuItemClasses
(
\Magento\Framework\Data\Tree\Node
$item
)
{
$classes
=
[];
$classes
[]
=
'level'
.
$item
->
getLevel
();
$classes
[]
=
$item
->
getPositionClass
();
if
(
$item
->
getIsFirst
())
{
$classes
[]
=
'first'
;
}
if
(
$item
->
getIsActive
())
{
$classes
[]
=
'active'
;
}
elseif
(
$item
->
getHasActive
())
{
$classes
[]
=
'has-active'
;
}
if
(
$item
->
getIsLast
())
{
$classes
[]
=
'last'
;
}
if
(
$item
->
getClass
())
{
$classes
[]
=
$item
->
getClass
();
}
if
(
$item
->
hasChildren
())
{
$classes
[]
=
'parent'
;
}
if
(
$item
->
getLevel
()
!=
0
)
{
$classes
=
$this
->
_getColumns
(
$classes
,
$item
);
}
return
$classes
;
}
private
function
_getColumns
(
$classes
,
$item
)
{
$parentSetMyColumns
=
$item
->
getParent
()
->
getSubmenuColumnsSingle
();
$selfColumns
=
$item
->
getSelfColumns
();
$defaultColumns
=
'4'
;
if
(
$item
->
getLevel
()
>
1
)
{
$defaultColumns
=
'12'
;
}
$columns
=
(
$selfColumns
??
$parentSetMyColumns
)
??
$defaultColumns
;
$classes
[]
=
'joshine-col-lg-'
.
$columns
;
return
$classes
;
}
protected
function
_getHtml
(
Node
$menuTree
,
$childrenWrapClass
,
...
...
@@ -142,14 +191,15 @@ class Topmenu extends JoshineMenu
$colStops
=
$this
->
_columnBrake
(
$child
->
getChildren
(),
$limit
);
}
$name
=
$child
->
getData
(
'name'
);
$sumMenuColumnsTotal
=
$child
->
getSubmenuColumnsTotal
();
$columns
=
$sumMenuColumnsTotal
??
'12'
;
if
(
$childLevel
==
0
)
{
$html
=
"<div class=
\"
level
{
$childLevel
}
{
$childrenWrapClass
}
\"
>"
;
$html
.=
"<div class=
\"
row
\"
>
<ul class=
\"
subchildmenu mega-columns joshine-clearfix joshine-col-lg-
8
\"
>
<ul class=
\"
subchildmenu mega-columns joshine-clearfix joshine-col-lg-
{
$columns
}
\"
>
{
$this
->
_getHtml
(
$child
,
$childrenWrapClass
,
$limit
,
$colStops
)
}
</ul>
<div class=
\"
menu-right-block
\"
>"
.
<div class=
\"
pull-right
\"
>"
.
" "
//$this->getLayout()->createBlock(\Magento\Cms\Block\Block::class)->setBlockId('catpic')
.
"</div>
</div>
...
...
app/code/Joshine/Category/Model/Category/Attribute/Source/Columns.php
0 → 100644
View file @
f4554fb0
<?php
namespace
Joshine\Category\Model\Category\Attribute\Source
;
class
Columns
extends
\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
{
protected
$_optionsData
;
/**
* Constructor
*
* @param array $options
*/
public
function
__construct
(
array
$options
=
[])
{
$this
->
_optionsData
=
$options
;
}
/**
* getAllOptions
*
* @return array
*/
public
function
getAllOptions
()
{
if
(
!
$this
->
_optionsData
)
{
$this
->
_optionsData
=
[
[
'value'
=>
''
,
'label'
=>
'----'
],
[
'value'
=>
'1'
,
'label'
=>
'1-columns'
],
[
'value'
=>
'2'
,
'label'
=>
'2-columns'
],
[
'value'
=>
'3'
,
'label'
=>
'3-columns'
],
[
'value'
=>
'4'
,
'label'
=>
'4-columns'
],
[
'value'
=>
'5'
,
'label'
=>
'5-columns'
],
[
'value'
=>
'6'
,
'label'
=>
'6-columns'
],
[
'value'
=>
'7'
,
'label'
=>
'7-columns'
],
[
'value'
=>
'8'
,
'label'
=>
'8-columns'
],
[
'value'
=>
'9'
,
'label'
=>
'9-columns'
],
[
'value'
=>
'10'
,
'label'
=>
'10-columns'
],
[
'value'
=>
'11'
,
'label'
=>
'11-columns'
],
[
'value'
=>
'12'
,
'label'
=>
'12-columns'
],
];
}
return
$this
->
_optionsData
;
}
}
\ No newline at end of file
app/code/Joshine/Category/Plugin/Block/Topmenu.php
View file @
f4554fb0
...
...
@@ -145,7 +145,10 @@ class Topmenu extends Menu
'id'
=>
'category-node-'
.
$categoryId
,
'url'
=>
$this
->
catalogCategory
->
getCategoryUrl
(
$category
),
'badge'
=>
$category
->
getData
(
'badge'
),
'has_active'
=>
in_array
((
string
)
$categoryId
,
explode
(
'/'
,
(
string
)
$currentCategory
->
getPath
()),
true
),
'submenu_columns_total'
=>
$category
->
getData
(
'submenu_columns_total'
),
'self_columns'
=>
$category
->
getData
(
'self_columns'
),
'submenu_columns_single'
=>
$category
->
getData
(
'submenu_columns_single'
),
'has_active'
=>
in_array
((
string
)
$categoryId
,
explode
(
'/'
,
(
string
)
$currentCategory
->
getPath
()),
true
),
'is_active'
=>
$categoryId
==
$currentCategory
->
getId
(),
'is_category'
=>
true
,
'is_parent_active'
=>
$isParentActive
...
...
@@ -169,6 +172,9 @@ class Topmenu extends Menu
$collection
->
setStoreId
(
$storeId
);
$collection
->
addAttributeToSelect
(
'name'
);
$collection
->
addAttributeToSelect
(
'badge'
);
$collection
->
addAttributeToSelect
(
'submenu_columns_total'
);
$collection
->
addAttributeToSelect
(
'submenu_columns_single'
);
$collection
->
addAttributeToSelect
(
'self_columns'
);
$collection
->
addFieldToFilter
(
'path'
,
[
'like'
=>
'1/'
.
$rootId
.
'/%'
]);
//load only from store root
$collection
->
addAttributeToFilter
(
'include_in_menu'
,
1
);
$collection
->
addIsActiveFilter
();
...
...
app/code/Joshine/Category/Setup/UpgradeData.php
View file @
f4554fb0
...
...
@@ -68,6 +68,75 @@ class UpgradeData implements UpgradeDataInterface
1
);
}
$categorySetup
=
$this
->
categorySetupFactory
->
create
([
'setup'
=>
$setup
]);
$entityTypeId
=
$categorySetup
->
getEntityTypeId
(
\Magento\Catalog\Model\Category
::
ENTITY
);
$attributeSetId
=
$categorySetup
->
getDefaultAttributeSetId
(
$entityTypeId
);
$menu_attributes
=
[
'submenu_columns_total'
=>
[
'type'
=>
'varchar'
,
'label'
=>
'Submenu Columns Total'
,
'input'
=>
'select'
,
'sort_order'
=>
101
,
'source'
=>
'\Joshine\Category\Model\Category\Attribute\Source\Columns'
,
'global'
=>
\Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface
::
SCOPE_STORE
,
'visible_on_front'
=>
true
,
'required'
=>
false
,
'user_defined'
=>
false
,
'default'
=>
null
,
'group'
=>
'Custom Menu'
,
'backend'
=>
''
],
'self_columns'
=>
[
'type'
=>
'varchar'
,
'label'
=>
'self_columns'
,
'input'
=>
'select'
,
'sort_order'
=>
101
,
'source'
=>
'\Joshine\Category\Model\Category\Attribute\Source\Columns'
,
'global'
=>
\Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface
::
SCOPE_STORE
,
'visible_on_front'
=>
true
,
'required'
=>
false
,
'user_defined'
=>
false
,
'default'
=>
null
,
'group'
=>
'Custom Menu'
,
'backend'
=>
''
],
'submenu_columns_single'
=>
[
'type'
=>
'varchar'
,
'label'
=>
'Submenu Columns Single'
,
'input'
=>
'select'
,
'sort_order'
=>
101
,
'source'
=>
'\Joshine\Category\Model\Category\Attribute\Source\Columns'
,
'global'
=>
\Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface
::
SCOPE_STORE
,
'visible_on_front'
=>
true
,
'required'
=>
false
,
'user_defined'
=>
false
,
'default'
=>
null
,
'group'
=>
'Custom Menu'
,
'backend'
=>
''
]
];
foreach
(
$menu_attributes
as
$item
=>
$data
)
{
$categorySetup
->
addAttribute
(
\Magento\Catalog\Model\Category
::
ENTITY
,
$item
,
$data
);
}
$idg
=
$categorySetup
->
getAttributeGroupId
(
$entityTypeId
,
$attributeSetId
,
'Custom Menu'
);
foreach
(
$menu_attributes
as
$item
=>
$data
)
{
$categorySetup
->
addAttributeToGroup
(
$entityTypeId
,
$attributeSetId
,
$idg
,
$item
,
$data
[
'sort_order'
]
);
}
$setup
->
endSetup
();
}
}
app/code/Joshine/Category/etc/module.xml
View file @
f4554fb0
...
...
@@ -6,5 +6,5 @@
*/
-->
<config
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"urn:magento:framework:Module/etc/module.xsd"
>
<module
name=
"Joshine_Category"
setup_version=
"1.
0.3
"
/>
<module
name=
"Joshine_Category"
setup_version=
"1.
1.2
"
/>
</config>
app/code/Joshine/Category/view/adminhtml/ui_component/category_form.xml
View file @
f4554fb0
...
...
@@ -38,6 +38,51 @@
</item>
</argument>
</field>
<field
name=
"submenu_columns_total"
sortOrder=
"300"
>
<argument
name=
"data"
xsi:type=
"array"
>
<item
name=
"options"
xsi:type=
"object"
>
Joshine\Category\Model\Category\Attribute\Source\Columns
</item>
<item
name=
"config"
xsi:type=
"array"
>
<item
name=
"required"
xsi:type=
"boolean"
>
false
</item>
<item
name=
"validation"
xsi:type=
"array"
>
<item
name=
"required-entry"
xsi:type=
"boolean"
>
false
</item>
</item>
<item
name=
"dataType"
xsi:type=
"string"
>
string
</item>
<item
name=
"formElement"
xsi:type=
"string"
>
select
</item>
<item
name=
"label"
translate=
"false"
xsi:type=
"string"
>
Submenu Columns Total
</item>
</item>
</argument>
</field>
<field
name=
"self_columns"
sortOrder=
"300"
>
<argument
name=
"data"
xsi:type=
"array"
>
<item
name=
"options"
xsi:type=
"object"
>
Joshine\Category\Model\Category\Attribute\Source\Columns
</item>
<item
name=
"config"
xsi:type=
"array"
>
<item
name=
"required"
xsi:type=
"boolean"
>
false
</item>
<item
name=
"validation"
xsi:type=
"array"
>
<item
name=
"required-entry"
xsi:type=
"boolean"
>
false
</item>
</item>
<item
name=
"dataType"
xsi:type=
"string"
>
string
</item>
<item
name=
"formElement"
xsi:type=
"string"
>
select
</item>
<item
name=
"label"
translate=
"false"
xsi:type=
"string"
>
Self Columns
</item>
</item>
</argument>
</field>
<field
name=
"submenu_columns_single"
sortOrder=
"300"
>
<argument
name=
"data"
xsi:type=
"array"
>
<item
name=
"options"
xsi:type=
"object"
>
Joshine\Category\Model\Category\Attribute\Source\Columns
</item>
<item
name=
"config"
xsi:type=
"array"
>
<item
name=
"required"
xsi:type=
"boolean"
>
false
</item>
<item
name=
"validation"
xsi:type=
"array"
>
<item
name=
"required-entry"
xsi:type=
"boolean"
>
false
</item>
</item>
<item
name=
"dataType"
xsi:type=
"string"
>
string
</item>
<item
name=
"formElement"
xsi:type=
"string"
>
select
</item>
<item
name=
"label"
translate=
"false"
xsi:type=
"string"
>
Submenu Columns Single(will overwrite by Self Columns)
</item>
</item>
</argument>
</field>
</fieldset>
</form>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment