Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Riina Antikainen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit cc094030
authored
Dec 16, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enforce product limits in user shop
1 parent
f01b1260
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
27 deletions
code/moya-web/src/main/java/fi/codecrew/moya/web/helper/ProductShopItemHelper.java
code/moya-web/src/main/java/fi/codecrew/moya/web/helper/ProductShopItemHelper.java
View file @
cc09403
...
@@ -43,28 +43,27 @@ public class ProductShopItemHelper extends GenericCDIView {
...
@@ -43,28 +43,27 @@ public class ProductShopItemHelper extends GenericCDIView {
@EJB
@EJB
private
DiscountBeanLocal
discountBean
;
private
DiscountBeanLocal
discountBean
;
public
void
updateProductShopItemCount
(
ProductShopItem
item
)
{
public
void
updateProductShopItemCount
(
ProductShopItem
item
)
{
// Discounts or overridden price, you cannot get both
// Discounts or overridden price, you cannot get both
if
(
item
.
isOverrideUnitPrice
())
{
if
(
item
.
isOverrideUnitPrice
())
{
item
.
setInternalPrice
(
item
.
getOverriddenUnitPrice
().
multiply
(
item
.
getCount
()));
item
.
setInternalPrice
(
item
.
getOverriddenUnitPrice
().
multiply
(
item
.
getCount
()));
}
else
{
}
else
{
item
.
setInternalPrice
(
item
.
getProduct
().
getPrice
().
abs
().
multiply
(
item
.
getCount
()));
item
.
setInternalPrice
(
item
.
getProduct
().
getPrice
().
abs
().
multiply
(
item
.
getCount
()));
item
.
setInternalDiscounts
(
discountBean
.
getActiveDiscountsByProduct
(
item
.
getProduct
(),
item
.
getCount
(),
Calendar
.
getInstance
(),
item
.
getUser
()));
item
.
setInternalDiscounts
(
discountBean
.
getActiveDiscountsByProduct
(
item
.
getProduct
(),
item
.
getCount
(),
Calendar
.
getInstance
(),
item
.
getUser
()));
item
.
setInternalDiscountValues
(
new
HashMap
<
Integer
,
BigDecimal
>());
item
.
setInternalDiscountValues
(
new
HashMap
<
Integer
,
BigDecimal
>());
for
(
Discount
d
:
item
.
getDiscounts
())
{
BigDecimal
newprice
=
item
.
getPrice
().
multiply
(
d
.
getPercentage
());
item
.
getInternalDiscountValues
().
put
(
d
.
getId
(),
item
.
getPrice
().
subtract
(
newprice
));
item
.
setInternalPrice
(
newprice
);
}
}
for
(
Discount
d
:
item
.
getDiscounts
())
{
BigDecimal
newprice
=
item
.
getPrice
().
multiply
(
d
.
getPercentage
());
item
.
getInternalDiscountValues
().
put
(
d
.
getId
(),
item
.
getPrice
().
subtract
(
newprice
));
item
.
setInternalPrice
(
newprice
);
}
}
}
}
public
void
setProductShopItemCount
(
ProductShopItem
item
,
BigDecimal
count
)
{
public
void
setProductShopItemCount
(
ProductShopItem
item
,
BigDecimal
count
)
{
...
@@ -73,24 +72,27 @@ public class ProductShopItemHelper extends GenericCDIView {
...
@@ -73,24 +72,27 @@ public class ProductShopItemHelper extends GenericCDIView {
count
=
BigDecimal
.
ZERO
;
count
=
BigDecimal
.
ZERO
;
}
}
item
.
setCount
(
count
);
item
.
setCount
(
count
);
updateProductShopItemCount
(
item
);
updateProductShopItemCount
(
item
);
}
}
public
boolean
updateProductShopItemLimit
(
ProductShopItem
item
,
BigDecimal
limitValue
)
{
public
boolean
updateProductShopItemLimit
(
ProductShopItem
item
,
BigDecimal
limitValue
)
{
BigDecimal
productsLeft
=
null
;
if
(
limitValue
!=
null
&&
limitValue
.
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
if
(
limitValue
!=
null
)
{
{
productsLeft
=
limitValue
.
subtract
(
item
.
getCount
());
this
.
setProductShopItemCount
(
item
,
item
.
getCount
().
add
(
limitValue
));
if
(
productsLeft
.
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
{
this
.
setProductShopItemCount
(
item
,
limitValue
);
if
(
item
.
getCount
().
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
{
if
(
item
.
getCount
().
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
{
this
.
setProductShopItemCount
(
item
,
BigDecimal
.
ZERO
);
this
.
setProductShopItemCount
(
item
,
BigDecimal
.
ZERO
);
}
item
.
setLimit
(
BigDecimal
.
ZERO
);
return
true
;
}
}
item
.
setLimit
(
BigDecimal
.
ZERO
);
return
true
;
}
}
item
.
setLimit
(
limitValue
);
item
.
setLimit
(
productsLeft
);
return
false
;
return
false
;
}
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment