This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for products weight and weight-based shipping price strategy
- Loading branch information
Showing
21 changed files
with
289 additions
and
28 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.../src/main/resources/mayoapp/migrations/V0078_0021__add_shipping_column_to_order_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ALTER TABLE purchase_order ADD COLUMN shipping numeric(18,4); | ||
ALTER TABLE purchase_order ADD COLUMN shipping numeric(18,4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
shop/catalog/src/main/java/org/mayocat/shop/catalog/model/WeightUnit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.mayocat.shop.catalog.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
/** | ||
* @version $Id$ | ||
*/ | ||
public enum WeightUnit | ||
{ | ||
KILOGRAM("kg"), | ||
GRAM("g"), | ||
OUNCE("oz"), | ||
POUND("lb"); | ||
|
||
WeightUnit(String smybol) | ||
{ | ||
this.symbol = smybol; | ||
} | ||
|
||
private String symbol; | ||
|
||
public String getSymbol() | ||
{ | ||
return symbol; | ||
} | ||
|
||
@JsonValue | ||
public String toJson() | ||
{ | ||
return getSymbol(); | ||
} | ||
|
||
@JsonCreator | ||
public static WeightUnit fromJson(String text) | ||
{ | ||
for (WeightUnit unit : values()) { | ||
if (unit.getSymbol().equalsIgnoreCase(text)) { | ||
return unit; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...catalog/src/main/resources/mayoapp/migrations/V0078_0022__add_weight_to_product_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE product ADD COLUMN weight numeric; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...in/java/org/mayocat/shop/shipping/strategy/AbstractValueBasedStrategyPriceCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.mayocat.shop.shipping.strategy; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Map; | ||
|
||
import org.mayocat.shop.catalog.model.Purchasable; | ||
import org.mayocat.shop.shipping.StrategyPriceCalculator; | ||
import org.mayocat.shop.shipping.model.Carrier; | ||
import org.mayocat.shop.shipping.model.CarrierRule; | ||
|
||
/** | ||
* @version $Id$ | ||
*/ | ||
public abstract class AbstractValueBasedStrategyPriceCalculator implements StrategyPriceCalculator | ||
{ | ||
@Override | ||
public BigDecimal getPrice(Carrier carrier, Map<Purchasable, Long> items) | ||
{ | ||
BigDecimal price = BigDecimal.ZERO; | ||
BigDecimal value = getValue(items); | ||
|
||
for (CarrierRule rule : carrier.getRules()) { | ||
price = rule.getPrice(); | ||
if (value.compareTo(rule.getUpToValue()) <= 0) { | ||
break; | ||
} | ||
} | ||
|
||
return price; | ||
} | ||
|
||
protected abstract BigDecimal getValue(Map<Purchasable, Long> items); | ||
} |
Oops, something went wrong.