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
3182a8bb
Commit
3182a8bb
authored
Apr 21, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : order rest api 添加商图片url
parent
6d95f0b6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
0 deletions
+101
-0
app/code/Joshine/Sales/Plugin/OrderRepositoryPlugin.php
+89
-0
app/code/Joshine/Sales/etc/di.xml
+4
-0
app/code/Joshine/Sales/etc/extension_attributes.xml
+8
-0
No files found.
app/code/Joshine/Sales/Plugin/OrderRepositoryPlugin.php
0 → 100644
View file @
3182a8bb
<?php
namespace
Joshine\Sales\Plugin
;
use
Magento\Catalog\Model\ProductFactory
;
use
Magento\Sales\Api\Data\OrderInterface
;
use
Magento\Sales\Api\Data\OrderItemExtensionFactory
;
use
Magento\Sales\Api\Data\OrderItemExtensionInterface
;
use
Magento\Sales\Api\OrderRepositoryInterface
;
use
Magento\Sales\Api\Data\OrderItemInterface
;
use
Magento\Sales\Api\Data\OrderItemSearchResultInterface
;
use
Magento\Sales\Api\OrderItemRepositoryInterface
;
use
Magento\Catalog\Helper\Image
;
/**
* Class OrderItemRepositoryPlugin
*/
class
OrderRepositoryPlugin
{
/**
* Order feedback field name
*/
const
FIELD_NAME
=
'image_url'
;
/**
* @var OrderItemExtensionFactory
*/
private
$orderItemExtensionFactory
;
/**
* @var OrderRepositoryInterface
*/
private
$orderRepository
;
/**
* @var \Magento\Sales\Api\ProductRepositoryInterfaceFactory
*/
private
$productRepository
;
/**
* @var \Magento\Catalog\Api\ProductRepositoryInterface
*/
private
$_productRepository
;
/**
* @var Image
*/
private
$imageHelper
;
/**
* @var ProductFactory
*/
private
$productFactory
;
public
function
__construct
(
OrderRepositoryInterface
$orderRepository
,
\Magento\Sales\Api\Data\OrderItemExtensionFactory
$orderItemExtensionFactory
,
\Magento\Catalog\Api\ProductRepositoryInterface
$productRepository
,
\Magento\Catalog\Helper\Image
$imageHelper
,
ProductFactory
$productFactory
)
{
$this
->
orderItemExtensionFactory
=
$orderItemExtensionFactory
;
$this
->
orderRepository
=
$orderRepository
;
$this
->
_productRepository
=
$productRepository
;
$this
->
imageHelper
=
$imageHelper
;
$this
->
productFactory
=
$productFactory
;
}
public
function
afterGet
(
OrderRepositoryInterface
$subject
,
OrderInterface
$quote
)
{
return
$this
->
setAttributeValue
(
$quote
);
}
private
function
setAttributeValue
(
$quote
)
{
foreach
(
$quote
->
getItems
()
as
$item
)
{
$extensionAttributes
=
$item
->
getExtensionAttributes
();
if
(
$extensionAttributes
===
null
)
{
$extensionAttributes
=
$this
->
orderItemExtensionFactory
->
create
();
}
$extensionAttributes
->
setImage
(
"null"
);
$product
=
$this
->
_productRepository
->
get
(
$item
->
getSku
());
if
(
$product
)
{
$objectManager
=
\Magento\Framework\App\ObjectManager
::
getInstance
();
$storeManager
=
$objectManager
->
get
(
'\Magento\Store\Model\StoreManagerInterface'
);
$hostname
=
$storeManager
->
getStore
()
->
getBaseUrl
();
$extensionAttributes
->
setImage
(
$hostname
.
"media/catalog/product/"
.
$product
->
getData
(
'thumbnail'
));
}
}
return
$quote
;
}
}
\ No newline at end of file
app/code/Joshine/Sales/etc/di.xml
View file @
3182a8bb
...
@@ -6,4 +6,7 @@
...
@@ -6,4 +6,7 @@
<type
name=
"\Magento\Sales\Block\Adminhtml\Order\View\Items"
>
<type
name=
"\Magento\Sales\Block\Adminhtml\Order\View\Items"
>
<plugin
name=
"order-item-sort"
type=
"Joshine\Sales\Plugin\ItemsSortPlugin"
sortOrder=
"1"
/>
<plugin
name=
"order-item-sort"
type=
"Joshine\Sales\Plugin\ItemsSortPlugin"
sortOrder=
"1"
/>
</type>
</type>
<type
name=
"\Magento\Sales\Api\OrderRepositoryInterface"
>
<plugin
name=
"add-items-image"
type=
"Joshine\Sales\Plugin\OrderRepositoryPlugin"
/>
</type>
</config>
</config>
\ No newline at end of file
app/code/Joshine/Sales/etc/extension_attributes.xml
0 → 100644
View file @
3182a8bb
<?xml version="1.0"?>
<config
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"urn:magento:framework:Api/etc/extension_attributes.xsd"
>
<extension_attributes
for=
"Magento\Sales\Api\Data\OrderItemInterface"
>
<attribute
code=
"image"
type=
"string"
/>
</extension_attributes>
</config>
\ No newline at end of file
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