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
887c45c5
Commit
887c45c5
authored
Jul 14, 2023
by
liumengfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化批量上传图片接口
parent
9bdab0d2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
0 deletions
+59
-0
app/code/Joshine/Catalog/Api/ProductAttributeMediaGalleryManagementInterface.php
+16
-0
app/code/Joshine/Catalog/Model/Product/Gallery/GalleryManagement.php
+43
-0
No files found.
app/code/Joshine/Catalog/Api/ProductAttributeMediaGalleryManagementInterface.php
View file @
887c45c5
...
...
@@ -43,6 +43,22 @@ interface ProductAttributeMediaGalleryManagementInterface
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface
$entry
);
/**
* Update gallery entry
*
* @param string $sku
* @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\StateException
*/
public
function
update
(
$sku
,
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface
$entry
);
/**
* Retrieve the list of gallery entries associated with given product
*
...
...
app/code/Joshine/Catalog/Model/Product/Gallery/GalleryManagement.php
View file @
887c45c5
...
...
@@ -162,6 +162,49 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal
throw
new
StateException
(
__
(
'The new media gallery entry failed to save.'
));
}
/**
* @inheritdoc
*/
public
function
update
(
$sku
,
ProductAttributeMediaGalleryEntryInterface
$entry
)
{
$product
=
$this
->
productRepository
->
get
(
$sku
,
true
);
$existingMediaGalleryEntries
=
$product
->
getMediaGalleryEntries
();
if
(
$existingMediaGalleryEntries
==
null
)
{
throw
new
NoSuchEntityException
(
__
(
'No image with the provided ID was found. Verify the ID and try again.'
)
);
}
$found
=
false
;
$entryTypes
=
(
array
)
$entry
->
getTypes
();
foreach
(
$existingMediaGalleryEntries
as
$key
=>
$existingEntry
)
{
$existingEntryTypes
=
(
array
)
$existingEntry
->
getTypes
();
$existingEntry
->
setTypes
(
array_diff
(
$existingEntryTypes
,
$entryTypes
));
if
(
$existingEntry
->
getId
()
==
$entry
->
getId
())
{
$found
=
true
;
$existingMediaGalleryEntries
[
$key
]
=
$entry
;
}
}
if
(
!
$found
)
{
throw
new
NoSuchEntityException
(
__
(
'No image with the provided ID was found. Verify the ID and try again.'
)
);
}
$product
=
$this
->
productInterfaceFactory
->
create
();
$product
->
setSku
(
$sku
);
$product
->
setMediaGalleryEntries
(
$existingMediaGalleryEntries
);
try
{
$this
->
productRepository
->
save
(
$product
);
}
catch
(
\Exception
$exception
)
{
throw
new
StateException
(
__
(
"The product can't be saved."
));
}
return
true
;
}
/**
* @inheritdoc
*/
...
...
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