Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
EShop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
EShop
Commits
cc89701d
Commit
cc89701d
authored
May 06, 2020
by
gdlcf88
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close #26: Use IProductInventoryProvider to get real inventories
parent
1ddc25c9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
24 deletions
+54
-24
ProductAppService.cs
...tion/EasyAbp/EShop/Products/Products/ProductAppService.cs
+30
-9
DefaultProductInventoryProvider.cs
...Shop/Products/Products/DefaultProductInventoryProvider.cs
+14
-8
IProductInventoryProvider.cs
...yAbp/EShop/Products/Products/IProductInventoryProvider.cs
+3
-2
ProductManager.cs
....Domain/EasyAbp/EShop/Products/Products/ProductManager.cs
+7
-5
No files found.
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs
View file @
cc89701d
...
...
@@ -25,6 +25,7 @@ namespace EasyAbp.EShop.Products.Products
protected
override
string
GetListPolicyName
{
get
;
set
;
}
=
null
;
private
readonly
IProductManager
_productManager
;
private
readonly
IProductInventoryProvider
_productInventoryProvider
;
private
readonly
IAttributeOptionIdsSerializer
_attributeOptionIdsSerializer
;
private
readonly
IProductStoreRepository
_productStoreRepository
;
private
readonly
IProductCategoryRepository
_productCategoryRepository
;
...
...
@@ -32,12 +33,14 @@ namespace EasyAbp.EShop.Products.Products
public
ProductAppService
(
IProductManager
productManager
,
IProductInventoryProvider
productInventoryProvider
,
IAttributeOptionIdsSerializer
attributeOptionIdsSerializer
,
IProductStoreRepository
productStoreRepository
,
IProductCategoryRepository
productCategoryRepository
,
IProductRepository
repository
)
:
base
(
repository
)
{
_productManager
=
productManager
;
_productInventoryProvider
=
productInventoryProvider
;
_attributeOptionIdsSerializer
=
attributeOptionIdsSerializer
;
_productStoreRepository
=
productStoreRepository
;
_productCategoryRepository
=
productCategoryRepository
;
...
...
@@ -211,21 +214,37 @@ namespace EasyAbp.EShop.Products.Products
public
virtual
async
Task
<
ProductDto
>
GetAsync
(
Guid
id
,
Guid
storeId
)
{
var
dto
=
await
base
.
GetAsync
(
id
);
await
CheckGetPolicyAsync
(
);
var
product
=
await
GetEntityByIdAsync
(
id
);
var
dto
=
MapToGetOutputDto
(
product
);
if
(!
dto
.
IsPublished
)
{
await
CheckStoreIsProductOwnerAsync
(
id
,
storeId
);
}
// Todo: get real inventory.
await
LoadRealInventoriesAsync
(
product
,
dto
,
storeId
);
dto
.
CategoryIds
=
(
await
_productCategoryRepository
.
GetListByProductIdAsync
(
dto
.
Id
))
.
Select
(
x
=>
x
.
CategoryId
).
ToList
();
return
dto
;
}
protected
virtual
async
Task
<
ProductDto
>
LoadRealInventoriesAsync
(
Product
product
,
ProductDto
productDto
,
Guid
storeId
)
{
var
inventoryDict
=
await
_productInventoryProvider
.
GetInventoryDictionaryAsync
(
product
,
storeId
);
foreach
(
var
productSkuDto
in
productDto
.
ProductSkus
)
{
productSkuDto
.
Inventory
=
inventoryDict
[
productSkuDto
.
Id
];
}
return
productDto
;
}
public
override
async
Task
<
PagedResultDto
<
ProductDto
>>
GetListAsync
(
GetProductListDto
input
)
{
await
CheckGetListPolicyAsync
();
...
...
@@ -250,14 +269,16 @@ namespace EasyAbp.EShop.Products.Products
query
=
ApplySorting
(
query
,
input
);
query
=
ApplyPaging
(
query
,
input
);
var
entitie
s
=
await
AsyncQueryableExecuter
.
ToListAsync
(
query
);
var
product
s
=
await
AsyncQueryableExecuter
.
ToListAsync
(
query
);
// Todo: get real inventory.
var
items
=
new
List
<
ProductDto
>();
foreach
(
var
product
in
products
)
{
items
.
Add
(
await
LoadRealInventoriesAsync
(
product
,
MapToGetListOutputDto
(
product
),
input
.
StoreId
));
}
return
new
PagedResultDto
<
ProductDto
>(
totalCount
,
entities
.
Select
(
MapToGetListOutputDto
).
ToList
()
);
return
new
PagedResultDto
<
ProductDto
>(
totalCount
,
items
);
}
public
async
Task
DeleteAsync
(
Guid
id
,
Guid
storeId
)
...
...
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/DefaultProductInventoryProvider.cs
View file @
cc89701d
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
Volo.Abp.DependencyInjection
;
...
...
@@ -7,24 +8,29 @@ namespace EasyAbp.EShop.Products.Products
[
Dependency
(
TryRegister
=
true
)]
public
class
DefaultProductInventoryProvider
:
IProductInventoryProvider
,
ITransientDependency
{
public
virtual
async
Task
<
bool
>
IsInventorySufficientAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
public
virtual
Task
<
int
>
GetInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
)
{
var
inventory
=
await
GetInventoryAsync
(
product
,
productSku
,
storeId
);
return
product
.
InventoryStrategy
==
InventoryStrategy
.
NoNeed
||
inventory
-
quantity
>=
0
;
return
Task
.
FromResult
(
productSku
.
Inventory
);
}
public
virtual
Task
<
int
>
GetInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
)
public
virtual
Task
<
Dictionary
<
Guid
,
int
>>
GetInventoryDictionaryAsync
(
Product
product
,
Guid
storeId
)
{
return
Task
.
FromResult
(
productSku
.
Inventory
);
var
dict
=
new
Dictionary
<
Guid
,
int
>();
foreach
(
var
productSku
in
product
.
ProductSkus
)
{
dict
[
productSku
.
Id
]
=
productSku
.
Inventory
;
}
return
Task
.
FromResult
(
dict
);
}
public
Task
<
bool
>
TryIncreaseInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
public
virtual
Task
<
bool
>
TryIncreaseInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
{
return
Task
.
FromResult
(
productSku
.
TryIncreaseInventory
(
quantity
));
}
public
Task
<
bool
>
TryReduceInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
public
virtual
Task
<
bool
>
TryReduceInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
{
return
Task
.
FromResult
(
productSku
.
TryReduceInventory
(
quantity
));
}
...
...
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProductInventoryProvider.cs
View file @
cc89701d
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
namespace
EasyAbp.EShop.Products.Products
{
public
interface
IProductInventoryProvider
{
Task
<
bool
>
IsInventorySufficientAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
);
Task
<
int
>
GetInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
);
Task
<
Dictionary
<
Guid
,
int
>>
GetInventoryDictionaryAsync
(
Product
product
,
Guid
storeId
);
Task
<
bool
>
TryIncreaseInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
);
...
...
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductManager.cs
View file @
cc89701d
...
...
@@ -16,22 +16,24 @@ namespace EasyAbp.EShop.Products.Products
_productInventoryProvider
=
productInventoryProvider
;
}
public
async
Task
<
bool
>
IsInventorySufficientAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
public
virtual
async
Task
<
bool
>
IsInventorySufficientAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
{
return
await
_productInventoryProvider
.
IsInventorySufficientAsync
(
product
,
productSku
,
storeId
,
quantity
);
var
inventory
=
await
_productInventoryProvider
.
GetInventoryAsync
(
product
,
productSku
,
storeId
);
return
product
.
InventoryStrategy
==
InventoryStrategy
.
NoNeed
||
inventory
-
quantity
>=
0
;
}
public
async
Task
<
int
>
GetInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
)
public
virtual
async
Task
<
int
>
GetInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
)
{
return
await
_productInventoryProvider
.
GetInventoryAsync
(
product
,
productSku
,
storeId
);
}
public
async
Task
<
bool
>
TryIncreaseInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
public
virtual
async
Task
<
bool
>
TryIncreaseInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
{
return
await
_productInventoryProvider
.
TryIncreaseInventoryAsync
(
product
,
productSku
,
storeId
,
quantity
);
}
public
async
Task
<
bool
>
TryReduceInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
public
virtual
async
Task
<
bool
>
TryReduceInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
int
quantity
)
{
return
await
_productInventoryProvider
.
TryReduceInventoryAsync
(
product
,
productSku
,
storeId
,
quantity
);
}
...
...
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