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
954f812e
Commit
954f812e
authored
Apr 30, 2020
by
gdlcf88
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limitations of ProductAttribute and ProductAttributeOption modifications, close #12
parent
41d11105
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
10 deletions
+108
-10
ProductAppService.cs
...tion/EasyAbp/EShop/Products/Products/ProductAppService.cs
+40
-10
ProductAttributeOptionsDeletionFailedException.cs
...roducts/ProductAttributeOptionsDeletionFailedException.cs
+13
-0
ProductAttributesModificationFailedException.cs
.../Products/ProductAttributesModificationFailedException.cs
+13
-0
AttributeOptionIdsSerializer.cs
...p/EShop/Products/Products/AttributeOptionIdsSerializer.cs
+27
-0
IAttributeOptionIdsSerializer.cs
.../EShop/Products/Products/IAttributeOptionIdsSerializer.cs
+15
-0
No files found.
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs
View file @
954f812e
...
@@ -24,18 +24,18 @@ namespace EasyAbp.EShop.Products.Products
...
@@ -24,18 +24,18 @@ namespace EasyAbp.EShop.Products.Products
protected
override
string
GetPolicyName
{
get
;
set
;
}
=
null
;
protected
override
string
GetPolicyName
{
get
;
set
;
}
=
null
;
protected
override
string
GetListPolicyName
{
get
;
set
;
}
=
null
;
protected
override
string
GetListPolicyName
{
get
;
set
;
}
=
null
;
private
readonly
I
SerializedAttributeOptionIdsFormatter
_serializedAttributeOptionIdsFormatt
er
;
private
readonly
I
AttributeOptionIdsSerializer
_attributeOptionIdsSerializ
er
;
private
readonly
IProductStoreRepository
_productStoreRepository
;
private
readonly
IProductStoreRepository
_productStoreRepository
;
private
readonly
IProductCategoryRepository
_productCategoryRepository
;
private
readonly
IProductCategoryRepository
_productCategoryRepository
;
private
readonly
IProductRepository
_repository
;
private
readonly
IProductRepository
_repository
;
public
ProductAppService
(
public
ProductAppService
(
I
SerializedAttributeOptionIdsFormatter
serializedAttributeOptionIdsFormatt
er
,
I
AttributeOptionIdsSerializer
attributeOptionIdsSerializ
er
,
IProductStoreRepository
productStoreRepository
,
IProductStoreRepository
productStoreRepository
,
IProductCategoryRepository
productCategoryRepository
,
IProductCategoryRepository
productCategoryRepository
,
IProductRepository
repository
)
:
base
(
repository
)
IProductRepository
repository
)
:
base
(
repository
)
{
{
_
serializedAttributeOptionIdsFormatter
=
serializedAttributeOptionIdsFormatt
er
;
_
attributeOptionIdsSerializer
=
attributeOptionIdsSerializ
er
;
_productStoreRepository
=
productStoreRepository
;
_productStoreRepository
=
productStoreRepository
;
_productCategoryRepository
=
productCategoryRepository
;
_productCategoryRepository
=
productCategoryRepository
;
_repository
=
repository
;
_repository
=
repository
;
...
@@ -125,12 +125,29 @@ namespace EasyAbp.EShop.Products.Products
...
@@ -125,12 +125,29 @@ namespace EasyAbp.EShop.Products.Products
protected
virtual
async
Task
UpdateProductAttributesAsync
(
Product
product
,
CreateUpdateProductDto
input
)
protected
virtual
async
Task
UpdateProductAttributesAsync
(
Product
product
,
CreateUpdateProductDto
input
)
{
{
var
isProductSkusEmpty
=
product
.
ProductSkus
.
IsNullOrEmpty
();
var
usedAttributeOptionIds
=
new
HashSet
<
Guid
>();
foreach
(
var
serializedAttributeOptionIds
in
product
.
ProductSkus
.
Select
(
sku
=>
sku
.
SerializedAttributeOptionIds
))
{
foreach
(
var
attributeOptionId
in
await
_attributeOptionIdsSerializer
.
DeserializeAsync
(
serializedAttributeOptionIds
))
{
usedAttributeOptionIds
.
Add
(
attributeOptionId
);
}
}
foreach
(
var
attributeDto
in
input
.
ProductAttributes
)
foreach
(
var
attributeDto
in
input
.
ProductAttributes
)
{
{
var
attribute
=
product
.
ProductAttributes
.
FirstOrDefault
(
a
=>
a
.
DisplayName
==
attributeDto
.
DisplayName
);
var
attribute
=
product
.
ProductAttributes
.
FirstOrDefault
(
a
=>
a
.
DisplayName
==
attributeDto
.
DisplayName
);
if
(
attribute
==
null
)
if
(
attribute
==
null
)
{
{
if
(!
isProductSkusEmpty
)
{
throw
new
ProductAttributesModificationFailedException
();
}
attribute
=
new
ProductAttribute
(
GuidGenerator
.
Create
(),
attribute
=
new
ProductAttribute
(
GuidGenerator
.
Create
(),
attributeDto
.
DisplayName
,
attributeDto
.
Description
);
attributeDto
.
DisplayName
,
attributeDto
.
Description
);
...
@@ -150,16 +167,29 @@ namespace EasyAbp.EShop.Products.Products
...
@@ -150,16 +167,29 @@ namespace EasyAbp.EShop.Products.Products
}
}
}
}
var
exceptOptionNames
=
attribute
.
ProductAttributeOptions
.
Select
(
o
=>
o
.
DisplayName
)
var
removedOptionNames
=
attribute
.
ProductAttributeOptions
.
Select
(
o
=>
o
.
DisplayName
)
.
Except
(
attributeDto
.
ProductAttributeOptions
.
Select
(
o
=>
o
.
DisplayName
));
.
Except
(
attributeDto
.
ProductAttributeOptions
.
Select
(
o
=>
o
.
DisplayName
)).
ToList
();
if
(!
isProductSkusEmpty
&&
removedOptionNames
.
Any
()
&&
usedAttributeOptionIds
.
Intersect
(
attribute
.
ProductAttributeOptions
.
Where
(
option
=>
removedOptionNames
.
Contains
(
option
.
DisplayName
))
.
Select
(
option
=>
option
.
Id
)).
Any
())
{
throw
new
ProductAttributeOptionsDeletionFailedException
();
}
attribute
.
ProductAttributeOptions
.
RemoveAll
(
o
=>
except
OptionNames
.
Contains
(
o
.
DisplayName
));
attribute
.
ProductAttributeOptions
.
RemoveAll
(
o
=>
removed
OptionNames
.
Contains
(
o
.
DisplayName
));
}
}
var
except
AttributeNames
=
product
.
ProductAttributes
.
Select
(
a
=>
a
.
DisplayName
)
var
removed
AttributeNames
=
product
.
ProductAttributes
.
Select
(
a
=>
a
.
DisplayName
)
.
Except
(
input
.
ProductAttributes
.
Select
(
a
=>
a
.
DisplayName
));
.
Except
(
input
.
ProductAttributes
.
Select
(
a
=>
a
.
DisplayName
))
.
ToList
()
;
product
.
ProductAttributes
.
RemoveAll
(
a
=>
exceptAttributeNames
.
Contains
(
a
.
DisplayName
));
if
(!
isProductSkusEmpty
&&
removedAttributeNames
.
Any
())
{
throw
new
ProductAttributesModificationFailedException
();
}
product
.
ProductAttributes
.
RemoveAll
(
a
=>
removedAttributeNames
.
Contains
(
a
.
DisplayName
));
}
}
[
Obsolete
(
"Should use DeleteAsync(Guid id, Guid storeId)"
)]
[
Obsolete
(
"Should use DeleteAsync(Guid id, Guid storeId)"
)]
...
@@ -257,7 +287,7 @@ namespace EasyAbp.EShop.Products.Products
...
@@ -257,7 +287,7 @@ namespace EasyAbp.EShop.Products.Products
CheckProductIsNotStatic
(
product
);
CheckProductIsNotStatic
(
product
);
input
.
SerializedAttributeOptionIds
=
input
.
SerializedAttributeOptionIds
=
await
_
serializedAttributeOptionIdsFormatter
.
Parse
Async
(
input
.
SerializedAttributeOptionIds
);
await
_
attributeOptionIdsSerializer
.
Format
Async
(
input
.
SerializedAttributeOptionIds
);
await
CheckSkuAttributeOptionsAsync
(
product
,
input
.
SerializedAttributeOptionIds
);
await
CheckSkuAttributeOptionsAsync
(
product
,
input
.
SerializedAttributeOptionIds
);
...
...
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAttributeOptionsDeletionFailedException.cs
0 → 100644
View file @
954f812e
using
System
;
using
Volo.Abp
;
namespace
EasyAbp.EShop.Products.Products
{
public
class
ProductAttributeOptionsDeletionFailedException
:
BusinessException
{
public
ProductAttributeOptionsDeletionFailedException
()
:
base
(
message
:
"Should ensure there are no SKUs using the attribute option which you want to delete."
)
{
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAttributesModificationFailedException.cs
0 → 100644
View file @
954f812e
using
System
;
using
Volo.Abp
;
namespace
EasyAbp.EShop.Products.Products
{
public
class
ProductAttributesModificationFailedException
:
BusinessException
{
public
ProductAttributesModificationFailedException
()
:
base
(
message
:
"Should ensure SKUs are empty if you want to modify attributes of a product."
)
{
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/
SerializedAttributeOptionIdsFormatt
er.cs
→
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/
AttributeOptionIdsSerializ
er.cs
View file @
954f812e
...
@@ -7,16 +7,21 @@ using Volo.Abp.DependencyInjection;
...
@@ -7,16 +7,21 @@ using Volo.Abp.DependencyInjection;
namespace
EasyAbp.EShop.Products.Products
namespace
EasyAbp.EShop.Products.Products
{
{
public
class
SerializedAttributeOptionIdsFormatter
:
ISerializedAttributeOptionIdsFormatt
er
,
ITransientDependency
public
class
AttributeOptionIdsSerializer
:
IAttributeOptionIdsSerializ
er
,
ITransientDependency
{
{
public
async
Task
<
string
>
Parse
Async
(
string
serializedAttributeOptionIds
)
public
async
Task
<
string
>
Format
Async
(
string
serializedAttributeOptionIds
)
{
{
return
await
ParseAsync
(
JsonConvert
.
DeserializeObject
<
IEnumerable
<
Guid
>>
(
serializedAttributeOptionIds
));
return
await
SerializeAsync
(
await
DeserializeAsync
(
serializedAttributeOptionIds
));
}
}
public
Task
<
string
>
Pars
eAsync
(
IEnumerable
<
Guid
>
attributeOptionIds
)
public
Task
<
string
>
Serializ
eAsync
(
IEnumerable
<
Guid
>
attributeOptionIds
)
{
{
return
Task
.
FromResult
(
JsonConvert
.
SerializeObject
(
attributeOptionIds
.
OrderBy
(
x
=>
x
)));
return
Task
.
FromResult
(
JsonConvert
.
SerializeObject
(
attributeOptionIds
.
OrderBy
(
x
=>
x
)));
}
}
public
Task
<
IEnumerable
<
Guid
>>
DeserializeAsync
(
string
serializedAttributeOptionIds
)
{
return
Task
.
FromResult
(
JsonConvert
.
DeserializeObject
<
IEnumerable
<
Guid
>>(
serializedAttributeOptionIds
));
}
}
}
}
}
\ No newline at end of file
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/I
SerializedAttributeOptionIdsFormatt
er.cs
→
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/I
AttributeOptionIdsSerializ
er.cs
View file @
954f812e
...
@@ -4,10 +4,12 @@ using System.Threading.Tasks;
...
@@ -4,10 +4,12 @@ using System.Threading.Tasks;
namespace
EasyAbp.EShop.Products.Products
namespace
EasyAbp.EShop.Products.Products
{
{
public
interface
I
SerializedAttributeOptionIdsFormatt
er
public
interface
I
AttributeOptionIdsSerializ
er
{
{
Task
<
string
>
Parse
Async
(
string
serializedAttributeOptionIds
);
Task
<
string
>
Format
Async
(
string
serializedAttributeOptionIds
);
Task
<
string
>
ParseAsync
(
IEnumerable
<
Guid
>
attributeOptionIds
);
Task
<
string
>
SerializeAsync
(
IEnumerable
<
Guid
>
attributeOptionIds
);
Task
<
IEnumerable
<
Guid
>>
DeserializeAsync
(
string
serializedAttributeOptionIds
);
}
}
}
}
\ 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