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
378d145a
Commit
378d145a
authored
May 01, 2020
by
gdlcf88
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved product purchasable check, related to: #18
parent
eb75fb8a
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
195 additions
and
53 deletions
+195
-53
Order.cs
...op.Orders/src/EasyAbp.EShop.Orders.Domain/Orders/Order.cs
+3
-0
IProductAppService.cs
...cts/EasyAbp/EShop/Products/Products/IProductAppService.cs
+3
-2
ProductAppService.cs
...tion/EasyAbp/EShop/Products/Products/ProductAppService.cs
+6
-5
CheckProductPurchasableResult.cs
.../EShop/Products/Products/CheckProductPurchasableResult.cs
+17
-0
GetProductPurchasableStatusResult.cs
...op/Products/Products/GetProductPurchasableStatusResult.cs
+0
-9
ProductPurchasableStatus.cs
...syAbp/EShop/Products/Products/ProductPurchasableStatus.cs
+0
-8
BasicProductPurchasableCheckHandler.cs
.../Products/Products/BasicProductPurchasableCheckHandler.cs
+51
-0
DefaultProductInventoryProvider.cs
...Shop/Products/Products/DefaultProductInventoryProvider.cs
+22
-0
IProductInventoryProvider.cs
...yAbp/EShop/Products/Products/IProductInventoryProvider.cs
+12
-0
IProductManager.cs
...Domain/EasyAbp/EShop/Products/Products/IProductManager.cs
+16
-0
IProductPurchasableCheckHandler.cs
...Shop/Products/Products/IProductPurchasableCheckHandler.cs
+12
-0
ProductManager.cs
....Domain/EasyAbp/EShop/Products/Products/ProductManager.cs
+40
-0
ProductPurchasableCheckHandlerMissingPropertyException.cs
...ProductPurchasableCheckHandlerMissingPropertyException.cs
+13
-0
ProductPurchasableStatusProvider.cs
...hop/Products/Products/ProductPurchasableStatusProvider.cs
+0
-29
No files found.
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/Orders/Order.cs
View file @
378d145a
using
System
;
using
System.Collections.Generic
;
using
EasyAbp.EShop.Stores.Stores
;
using
JetBrains.Annotations
;
using
Volo.Abp.Domain.Entities.Auditing
;
...
...
@@ -40,5 +41,7 @@ namespace EasyAbp.EShop.Orders.Orders
[
CanBeNull
]
public
virtual
string
StaffRemark
{
get
;
protected
set
;
}
public
virtual
List
<
OrderLine
>
OrderLines
{
get
;
protected
set
;
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/IProductAppService.cs
View file @
378d145a
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
EasyAbp.EShop.Products.Products.Dtos
;
using
Volo.Abp.Application.Dtos
;
using
Volo.Abp.Application.Services
;
namespace
EasyAbp.EShop.Products.Products
...
...
@@ -24,6 +24,7 @@ namespace EasyAbp.EShop.Products.Products
Task
<
ProductDto
>
DeleteSkuAsync
(
Guid
productId
,
Guid
productSkuId
,
Guid
storeId
);
Task
<
GetProductPurchasableStatusResult
>
GetPurchasableStatusAsync
(
Guid
productId
,
Guid
productSkuId
,
Guid
storeId
);
Task
<
CheckProductPurchasableResult
>
CheckPurchasableAsync
(
Guid
productId
,
Guid
productSkuId
,
Guid
storeId
,
Dictionary
<
string
,
object
>
extraProperties
);
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs
View file @
378d145a
...
...
@@ -24,20 +24,20 @@ namespace EasyAbp.EShop.Products.Products
protected
override
string
GetPolicyName
{
get
;
set
;
}
=
null
;
protected
override
string
GetListPolicyName
{
get
;
set
;
}
=
null
;
private
readonly
IProduct
PurchasableStatusProvider
_productPurchasableStatusProvid
er
;
private
readonly
IProduct
Manager
_productManag
er
;
private
readonly
IAttributeOptionIdsSerializer
_attributeOptionIdsSerializer
;
private
readonly
IProductStoreRepository
_productStoreRepository
;
private
readonly
IProductCategoryRepository
_productCategoryRepository
;
private
readonly
IProductRepository
_repository
;
public
ProductAppService
(
IProduct
PurchasableStatusProvider
productPurchasableStatusProvid
er
,
IProduct
Manager
productManag
er
,
IAttributeOptionIdsSerializer
attributeOptionIdsSerializer
,
IProductStoreRepository
productStoreRepository
,
IProductCategoryRepository
productCategoryRepository
,
IProductRepository
repository
)
:
base
(
repository
)
{
_product
PurchasableStatusProvider
=
productPurchasableStatusProvid
er
;
_product
Manager
=
productManag
er
;
_attributeOptionIdsSerializer
=
attributeOptionIdsSerializer
;
_productStoreRepository
=
productStoreRepository
;
_productCategoryRepository
=
productCategoryRepository
;
...
...
@@ -354,13 +354,14 @@ namespace EasyAbp.EShop.Products.Products
return
ObjectMapper
.
Map
<
Product
,
ProductDto
>(
product
);
}
public
async
Task
<
GetProductPurchasableStatusResult
>
GetPurchasableStatusAsync
(
Guid
productId
,
Guid
productSkuId
,
Guid
storeId
)
public
async
Task
<
CheckProductPurchasableResult
>
CheckPurchasableAsync
(
Guid
productId
,
Guid
productSkuId
,
Guid
storeId
,
Dictionary
<
string
,
object
>
extraProperties
)
{
var
product
=
await
_repository
.
GetAsync
(
productId
);
var
productSku
=
product
.
ProductSkus
.
Single
(
sku
=>
sku
.
Id
==
productSkuId
);
return
await
_product
PurchasableStatusProvider
.
GetPurchasableStatusAsync
(
product
,
productSku
,
storeId
);
return
await
_product
Manager
.
GetPurchasableStatusAsync
(
product
,
productSku
,
storeId
,
extraProperties
);
}
protected
virtual
async
Task
UpdateProductCategoriesAsync
(
Guid
productId
,
IEnumerable
<
Guid
>
categoryIds
)
...
...
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/CheckProductPurchasableResult.cs
0 → 100644
View file @
378d145a
namespace
EasyAbp.EShop.Products.Products
{
public
class
CheckProductPurchasableResult
{
public
bool
IsPurchasable
{
get
;
set
;
}
public
string
Reason
{
get
;
set
;
}
public
CheckProductPurchasableResult
(
bool
isPurchasable
,
string
reason
=
null
)
{
IsPurchasable
=
isPurchasable
;
Reason
=
reason
;
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/GetProductPurchasableStatusResult.cs
deleted
100644 → 0
View file @
eb75fb8a
namespace
EasyAbp.EShop.Products.Products
{
public
class
GetProductPurchasableStatusResult
{
public
ProductPurchasableStatus
PurchasableStatus
{
get
;
set
;
}
public
string
Reason
{
get
;
set
;
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/ProductPurchasableStatus.cs
deleted
100644 → 0
View file @
eb75fb8a
namespace
EasyAbp.EShop.Products.Products
{
public
enum
ProductPurchasableStatus
{
CanBePurchased
=
1
,
CanNotBePurchased
=
2
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/BasicProductPurchasableCheckHandler.cs
0 → 100644
View file @
378d145a
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
Volo.Abp.DependencyInjection
;
namespace
EasyAbp.EShop.Products.Products
{
public
class
BasicProductPurchasableCheckHandler
:
IProductPurchasableCheckHandler
,
ITransientDependency
{
private
readonly
IProductInventoryProvider
_productInventoryProvider
;
public
BasicProductPurchasableCheckHandler
(
IProductInventoryProvider
productInventoryProvider
)
{
_productInventoryProvider
=
productInventoryProvider
;
}
public
async
Task
<
CheckProductPurchasableResult
>
CheckAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
Dictionary
<
string
,
object
>
extraProperties
)
{
if
(!
await
IsProductPublishedAsync
(
product
))
{
return
new
CheckProductPurchasableResult
(
false
,
"Unpublished project"
);
}
if
(!
await
IsInventorySufficientAsync
(
product
,
productSku
,
storeId
,
extraProperties
))
{
return
new
CheckProductPurchasableResult
(
false
,
"Insufficient inventory"
);
}
return
new
CheckProductPurchasableResult
(
true
);
}
protected
virtual
Task
<
bool
>
IsProductPublishedAsync
(
Product
product
)
{
return
Task
.
FromResult
(
product
.
IsPublished
);
}
protected
virtual
async
Task
<
bool
>
IsInventorySufficientAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
Dictionary
<
string
,
object
>
extraProperties
)
{
if
(!
extraProperties
.
TryGetValue
(
"Quantity"
,
out
var
quantity
))
{
throw
new
ProductPurchasableCheckHandlerMissingPropertyException
(
nameof
(
BasicProductPurchasableCheckHandler
),
"Quantity"
);
}
return
await
_productInventoryProvider
.
IsInventorySufficientAsync
(
product
,
productSku
,
storeId
,
Convert
.
ToInt32
(
quantity
));
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/DefaultProductInventoryProvider.cs
0 → 100644
View file @
378d145a
using
System
;
using
System.Threading.Tasks
;
using
Volo.Abp.DependencyInjection
;
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
)
{
var
inventory
=
await
GetInventoryAsync
(
product
,
productSku
,
storeId
);
return
product
.
InventoryStrategy
==
InventoryStrategy
.
NoNeed
||
inventory
-
quantity
>=
0
;
}
public
virtual
Task
<
int
>
GetInventoryAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
)
{
return
Task
.
FromResult
(
productSku
.
Inventory
);
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProductInventoryProvider.cs
0 → 100644
View file @
378d145a
using
System
;
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
);
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProduct
PurchasableStatusProvid
er.cs
→
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProduct
Manag
er.cs
View file @
378d145a
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
Volo.Abp.Domain.Services
;
namespace
EasyAbp.EShop.Products.Products
{
public
interface
IProduct
PurchasableStatusProvider
public
interface
IProduct
Manager
:
IDomainService
{
Task
CheckPurchasableAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
);
Task
CheckPurchasableAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
Dictionary
<
string
,
object
>
extraProperties
);
Task
<
GetProductPurchasableStatus
Result
>
GetPurchasableStatusAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
);
Task
<
CheckProductPurchasable
Result
>
GetPurchasableStatusAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
Dictionary
<
string
,
object
>
extraProperties
);
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/IProductPurchasableCheckHandler.cs
0 → 100644
View file @
378d145a
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
namespace
EasyAbp.EShop.Products.Products
{
public
interface
IProductPurchasableCheckHandler
{
Task
<
CheckProductPurchasableResult
>
CheckAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
Dictionary
<
string
,
object
>
extraProperties
);
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductManager.cs
0 → 100644
View file @
378d145a
using
System
;
using
System.Collections.Generic
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.DependencyInjection
;
using
Volo.Abp.Domain.Services
;
namespace
EasyAbp.EShop.Products.Products
{
public
class
ProductManager
:
DomainService
,
IProductManager
{
public
async
Task
CheckPurchasableAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
Dictionary
<
string
,
object
>
extraProperties
)
{
var
result
=
await
GetPurchasableStatusAsync
(
product
,
productSku
,
storeId
,
extraProperties
);
if
(!
result
.
IsPurchasable
)
{
throw
new
ProductIsNotPurchasableException
(
product
.
Id
,
result
.
Reason
);
}
}
public
async
Task
<
CheckProductPurchasableResult
>
GetPurchasableStatusAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
,
Dictionary
<
string
,
object
>
extraProperties
)
{
var
handlers
=
ServiceProvider
.
GetServices
<
IProductPurchasableCheckHandler
>();
foreach
(
var
handler
in
handlers
)
{
var
result
=
await
handler
.
CheckAsync
(
product
,
productSku
,
storeId
,
extraProperties
);
if
(!
result
.
IsPurchasable
)
{
return
result
;
}
}
return
new
CheckProductPurchasableResult
(
true
);
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductPurchasableCheckHandlerMissingPropertyException.cs
0 → 100644
View file @
378d145a
using
System
;
using
Volo.Abp
;
namespace
EasyAbp.EShop.Products.Products
{
public
class
ProductPurchasableCheckHandlerMissingPropertyException
:
BusinessException
{
public
ProductPurchasableCheckHandlerMissingPropertyException
(
string
handlerName
,
string
propertyKey
)
:
base
(
message
:
$"The
{
handlerName
}
is missing extra property:
{
propertyKey
}
"
)
{
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductPurchasableStatusProvider.cs
deleted
100644 → 0
View file @
eb75fb8a
using
System
;
using
System.Threading.Tasks
;
using
Volo.Abp.DependencyInjection
;
namespace
EasyAbp.EShop.Products.Products
{
public
class
ProductPurchasableStatusProvider
:
IProductPurchasableStatusProvider
,
ITransientDependency
{
public
async
Task
CheckPurchasableAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
)
{
var
result
=
await
GetPurchasableStatusAsync
(
product
,
productSku
,
storeId
);
if
(
result
.
PurchasableStatus
!=
ProductPurchasableStatus
.
CanBePurchased
)
{
throw
new
ProductIsNotPurchasableException
(
product
.
Id
,
result
.
Reason
);
}
}
public
async
Task
<
GetProductPurchasableStatusResult
>
GetPurchasableStatusAsync
(
Product
product
,
ProductSku
productSku
,
Guid
storeId
)
{
// Todo: Determine whether the product can be purchased.
return
new
GetProductPurchasableStatusResult
{
PurchasableStatus
=
ProductPurchasableStatus
.
CanBePurchased
,
Reason
=
null
};
}
}
}
\ 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