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
2549716f
Commit
2549716f
authored
Apr 22, 2023
by
liumengfei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'developer' into production
parents
83905afa
7b798d95
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
0 deletions
+127
-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
app/code/Magento/Sales/Api/Data/OrderItemInterface.php
+9
-0
app/code/Magento/Sales/Model/Order/Item.php
+17
-0
No files found.
app/code/Joshine/Sales/Plugin/OrderRepositoryPlugin.php
0 → 100644
View file @
2549716f
<?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 @
2549716f
...
...
@@ -6,4 +6,7 @@
<type
name=
"\Magento\Sales\Block\Adminhtml\Order\View\Items"
>
<plugin
name=
"order-item-sort"
type=
"Joshine\Sales\Plugin\ItemsSortPlugin"
sortOrder=
"1"
/>
</type>
<type
name=
"\Magento\Sales\Api\OrderRepositoryInterface"
>
<plugin
name=
"add-items-image"
type=
"Joshine\Sales\Plugin\OrderRepositoryPlugin"
/>
</type>
</config>
\ No newline at end of file
app/code/Joshine/Sales/etc/extension_attributes.xml
0 → 100644
View file @
2549716f
<?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
app/code/Magento/Sales/Api/Data/OrderItemInterface.php
View file @
2549716f
...
...
@@ -23,6 +23,10 @@ interface OrderItemInterface extends \Magento\Framework\Api\ExtensibleDataInterf
* Item ID.
*/
const
ITEM_ID
=
'item_id'
;
const
IMAGE
=
'image'
;
/*
* Order ID.
*/
...
...
@@ -1824,4 +1828,9 @@ interface OrderItemInterface extends \Magento\Framework\Api\ExtensibleDataInterf
* @return $this
*/
public
function
setExtensionAttributes
(
\Magento\Sales\Api\Data\OrderItemExtensionInterface
$extensionAttributes
);
/**
* @return string|null
*/
public
function
getImage
();
}
app/code/Magento/Sales/Model/Order/Item.php
View file @
2549716f
...
...
@@ -2415,4 +2415,21 @@ class Item extends AbstractModel implements OrderItemInterface
{
return
$this
->
getQtyToShip
()
>
$this
->
getQtyToCancel
();
}
/**
* @inheritdoc
*/
public
function
getImage
()
{
$product
=
$this
->
productRepository
->
get
(
$this
->
getSku
());
if
(
$product
)
{
if
(
!
$product
->
getData
(
"thumbnail"
))
{
return
"null"
;
}
$objectManager
=
\Magento\Framework\App\ObjectManager
::
getInstance
();
$storeManager
=
$objectManager
->
get
(
'\Magento\Store\Model\StoreManagerInterface'
);
$hostname
=
$storeManager
->
getStore
()
->
getBaseUrl
();
return
$hostname
.
"media/catalog/product/"
.
$product
->
getData
(
'thumbnail'
);
}
return
"null"
;
}
}
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