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
c5482a8d
Commit
c5482a8d
authored
Feb 09, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : 后台图片上传
parent
4bf54fe8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
120 additions
and
2 deletions
+120
-2
app/code/Joshine/Category/Controller/Adminhtml/Category/Image/Upload.php
+37
-0
app/code/Joshine/Category/Model/Category/DataProvider.php
+15
-0
app/code/Joshine/Category/Setup/UpgradeData.php
+19
-1
app/code/Joshine/Category/etc/adminhtml/di.xml
+21
-0
app/code/Joshine/Category/etc/adminhtml/routes.xml
+8
-0
app/code/Joshine/Category/etc/module.xml
+1
-1
app/code/Joshine/Category/view/adminhtml/ui_component/category_form.xml
+19
-0
No files found.
app/code/Joshine/Category/Controller/Adminhtml/Category/Image/Upload.php
0 → 100644
View file @
c5482a8d
<?php
namespace
Joshine\Category\Controller\Adminhtml\Category\Image
;
use
Magento\Framework\Controller\ResultFactory
;
/**
* Class Upload
*/
class
Upload
extends
\Magento\Backend\App\Action
{
protected
$baseTmpPath
;
protected
$imageUploader
;
public
function
__construct
(
\Magento\Backend\App\Action\Context
$context
,
\Magento\Catalog\Model\ImageUploader
$imageUploader
)
{
$this
->
imageUploader
=
$imageUploader
;
parent
::
__construct
(
$context
);
}
public
function
execute
()
{
try
{
$result
=
$this
->
imageUploader
->
saveFileToTmpDir
(
'menu_image'
);
$result
[
'cookie'
]
=
[
'name'
=>
$this
->
_getSession
()
->
getName
(),
'value'
=>
$this
->
_getSession
()
->
getSessionId
(),
'lifetime'
=>
$this
->
_getSession
()
->
getCookieLifetime
(),
'path'
=>
$this
->
_getSession
()
->
getCookiePath
(),
'domain'
=>
$this
->
_getSession
()
->
getCookieDomain
(),
];
}
catch
(
\Exception
$e
)
{
$result
=
[
'error'
=>
$e
->
getMessage
(),
'errorcode'
=>
$e
->
getCode
()];
}
return
$this
->
resultFactory
->
create
(
ResultFactory
::
TYPE_JSON
)
->
setData
(
$result
);
}
}
\ No newline at end of file
app/code/Joshine/Category/Model/Category/DataProvider.php
0 → 100644
View file @
c5482a8d
<?php
namespace
Joshine\Category\Model\Category
;
class
DataProvider
extends
\Magento\Catalog\Model\Category\DataProvider
{
protected
function
getFieldsMap
()
{
$fields
=
parent
::
getFieldsMap
();
$fields
[
'content'
][]
=
'menu_image'
;
// custom image field
return
$fields
;
}
}
\ No newline at end of file
app/code/Joshine/Category/Setup/UpgradeData.php
View file @
c5482a8d
...
...
@@ -42,11 +42,29 @@ class UpgradeData implements UpgradeDataInterface
$idg
=
$categorySetup
->
getAttributeGroupId
(
$entityTypeId
,
$attributeSetId
,
'Custom Menu'
);
$categorySetup
->
addAttribute
(
\Magento\Catalog\Model\Category
::
ENTITY
,
'menu_image'
,
[
'type'
=>
'varchar'
,
'label'
=>
'badge'
,
'visible_on_front'
=>
true
,
'user_defined'
=>
false
,
'default'
=>
null
,
'group'
=>
'Custom Menu'
,
'input'
=>
'image'
,
'backend'
=>
'Magento\Catalog\Model\Category\Attribute\Backend\Image'
,
'required'
=>
false
,
'sort_order'
=>
70
,
'global'
=>
\Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface
::
SCOPE_STORE
,
]
);
$categorySetup
->
addAttributeToGroup
(
$entityTypeId
,
$attributeSetId
,
$idg
,
'
bad
ge'
,
'
menu_ima
ge'
,
1
);
}
...
...
app/code/Joshine/Category/etc/adminhtml/di.xml
0 → 100644
View file @
c5482a8d
<?xml version="1.0"?>
<config
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"urn:magento:framework:ObjectManager/etc/config.xsd"
>
<type
name=
"Joshine\Category\Controller\Adminhtml\Category\Image\Upload"
>
<arguments>
<argument
name=
"imageUploader"
xsi:type=
"object"
>
Magento\Catalog\CategoryImageUpload
</argument>
</arguments>
</type>
<virtualType
name=
"Magento\Catalog\CategoryImageUpload"
type=
"Magento\Catalog\Model\ImageUploader"
>
<arguments>
<argument
name=
"baseTmpPath"
xsi:type=
"string"
>
catalog/tmp/category
</argument>
<argument
name=
"basePath"
xsi:type=
"string"
>
catalog/category
</argument>
<argument
name=
"allowedExtensions"
xsi:type=
"array"
>
<item
name=
"jpg"
xsi:type=
"string"
>
jpg
</item>
<item
name=
"jpeg"
xsi:type=
"string"
>
jpeg
</item>
<item
name=
"gif"
xsi:type=
"string"
>
gif
</item>
<item
name=
"png"
xsi:type=
"string"
>
png
</item>
</argument>
</arguments>
</virtualType>
</config>
\ No newline at end of file
app/code/Joshine/Category/etc/adminhtml/routes.xml
0 → 100644
View file @
c5482a8d
<config
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"urn:magento:framework:App/etc/routes.xsd"
>
<router
id=
"admin"
>
<route
id=
"categorylist"
frontName=
"categorylist"
>
<module
name=
"Joshine_Category"
before=
"Magento_Backend"
/>
</route>
</router>
</config>
\ No newline at end of file
app/code/Joshine/Category/etc/module.xml
View file @
c5482a8d
...
...
@@ -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.
0
"
/>
<module
name=
"Joshine_Category"
setup_version=
"1.0.
3
"
/>
</config>
app/code/Joshine/Category/view/adminhtml/ui_component/category_form.xml
View file @
c5482a8d
...
...
@@ -19,6 +19,25 @@
</item>
</argument>
</field>
<field
name=
"menu_image"
>
<argument
name=
"data"
xsi:type=
"array"
>
<item
name=
"config"
xsi:type=
"array"
>
<item
name=
"dataType"
xsi:type=
"string"
>
string
</item>
<item
name=
"source"
xsi:type=
"string"
>
category
</item>
<item
name=
"label"
xsi:type=
"string"
translate=
"true"
>
Menu Image
</item>
<item
name=
"visible"
xsi:type=
"boolean"
>
true
</item>
<item
name=
"formElement"
xsi:type=
"string"
>
imageUploader
</item>
<item
name=
"elementTmpl"
xsi:type=
"string"
>
ui/form/element/uploader/uploader
</item>
<item
name=
"previewTmpl"
xsi:type=
"string"
>
Magento_Catalog/image-preview
</item>
<item
name=
"required"
xsi:type=
"boolean"
>
false
</item>
<item
name=
"sortOrder"
xsi:type=
"number"
>
40
</item>
<item
name=
"uploaderConfig"
xsi:type=
"array"
>
<item
name=
"url"
xsi:type=
"url"
path=
"categorylist/category_image/upload"
/>
</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