use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class PricingTest method testPricing.
@Test(groups = { "testPricing" }, dependsOnGroups = { "testShippingInsert", "createCustomerIdGeneration" })
@Transactional
public void testPricing() throws Exception {
Order order = orderService.createNewCartForCustomer(createCustomer());
customerService.saveCustomer(order.getCustomer());
Country country = new CountryImpl();
country.setAbbreviation("US");
country.setName("United States");
country = countryService.save(country);
ISOCountry isoCountry = new ISOCountryImpl();
isoCountry.setAlpha2("US");
isoCountry.setName("UNITED STATES");
isoCountry = isoService.save(isoCountry);
State state = new StateImpl();
state.setAbbreviation("TX");
state.setName("Texas");
state.setCountry(country);
state = stateService.save(state);
Address address = new AddressImpl();
address.setAddressLine1("123 Test Rd");
address.setCity("Dallas");
address.setFirstName("Jeff");
address.setLastName("Fischer");
address.setPostalCode("75240");
address.setPrimaryPhone("972-978-9067");
address.setState(state);
address.setCountry(country);
address.setIsoCountrySubdivision("US-TX");
address.setIsoCountryAlpha2(isoCountry);
FulfillmentGroup group = new FulfillmentGroupImpl();
group.setAddress(address);
List<FulfillmentGroup> groups = new ArrayList<>();
group.setMethod("standard");
group.setService(ShippingServiceType.BANDED_SHIPPING.getType());
group.setOrder(order);
groups.add(group);
order.setFulfillmentGroups(groups);
Money total = new Money(8.5D);
group.setShippingPrice(total);
{
DiscreteOrderItem item = new DiscreteOrderItemImpl();
Sku sku = new SkuImpl();
sku.setName("Test Sku");
sku.setRetailPrice(new Money(10D));
sku.setDiscountable(true);
SkuFee fee = new SkuFeeImpl();
fee.setFeeType(SkuFeeType.FULFILLMENT);
fee.setName("fee test");
fee.setAmount(new Money(10D));
fee = catalogService.saveSkuFee(fee);
List<SkuFee> fees = new ArrayList<>();
fees.add(fee);
sku.setFees(fees);
sku = catalogService.saveSku(sku);
item.setSku(sku);
item.setQuantity(2);
item.setOrder(order);
item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
order.addOrderItem(item);
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(item);
fgItem.setQuantity(2);
// fgItem.setPrice(new Money(0D));
group.addFulfillmentGroupItem(fgItem);
}
{
DiscreteOrderItem item = new DiscreteOrderItemImpl();
Sku sku = new SkuImpl();
sku.setName("Test Product 2");
sku.setRetailPrice(new Money(20D));
sku.setDiscountable(true);
sku = catalogService.saveSku(sku);
item.setSku(sku);
item.setQuantity(1);
item.setOrder(order);
item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
order.addOrderItem(item);
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(item);
fgItem.setQuantity(1);
// fgItem.setPrice(new Money(0D));
group.addFulfillmentGroupItem(fgItem);
}
order.addOfferCode(createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, null, "discreteOrderItem.sku.name==\"Test Sku\""));
order.addOfferCode(createOfferCode("3 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 3, null, "discreteOrderItem.sku.name!=\"Test Sku\""));
order.addOfferCode(createOfferCode("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, null));
order.setTotalShipping(new Money(0D));
orderService.save(order, true);
assert order.getSubTotal().subtract(order.getOrderAdjustmentsValue()).equals(new Money(31.80D));
assert (order.getTotal().greaterThan(order.getSubTotal()));
// Shipping is not taxable
assert (order.getTotalTax().equals(order.getSubTotal().subtract(order.getOrderAdjustmentsValue()).multiply(0.05D)));
// determine the total cost of the fulfillment group fees
Money fulfillmentGroupFeeTotal = getFulfillmentGroupFeeTotal(order);
assert (order.getTotal().equals(order.getSubTotal().add(order.getTotalTax()).add(order.getTotalShipping()).add(fulfillmentGroupFeeTotal).subtract(order.getOrderAdjustmentsValue())));
}
use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class PricingTest method testShipping.
@Test(groups = { "testShipping" }, dependsOnGroups = { "testShippingInsert", "createCustomerIdGeneration" })
@Transactional
public void testShipping() throws Exception {
Order order = orderService.createNewCartForCustomer(createCustomer());
customerService.saveCustomer(order.getCustomer());
FulfillmentGroup group1 = new FulfillmentGroupImpl();
FulfillmentGroup group2 = new FulfillmentGroupImpl();
// setup group1 - standard
group1.setMethod("standard");
group1.setService(ShippingServiceType.BANDED_SHIPPING.getType());
Country country = new CountryImpl();
country.setAbbreviation("US");
country.setName("United States");
country = countryService.save(country);
ISOCountry isoCountry = new ISOCountryImpl();
isoCountry.setAlpha2("US");
isoCountry.setName("UNITED STATES");
isoCountry = isoService.save(isoCountry);
State state = new StateImpl();
state.setAbbreviation("TX");
state.setName("Texas");
state.setCountry(country);
state = stateService.save(state);
Address address = new AddressImpl();
address.setAddressLine1("123 Test Rd");
address.setCity("Dallas");
address.setFirstName("Jeff");
address.setLastName("Fischer");
address.setPostalCode("75240");
address.setPrimaryPhone("972-978-9067");
address.setState(state);
address.setCountry(country);
address.setIsoCountrySubdivision("US-TX");
address.setIsoCountryAlpha2(isoCountry);
group1.setAddress(address);
group1.setOrder(order);
// setup group2 - truck
group2.setMethod("truck");
group2.setService(ShippingServiceType.BANDED_SHIPPING.getType());
group2.setOrder(order);
List<FulfillmentGroup> groups = new ArrayList<>();
groups.add(group1);
// groups.add(group2);
order.setFulfillmentGroups(groups);
Money total = new Money(8.5D);
group1.setShippingPrice(total);
group2.setShippingPrice(total);
// group1.setTotalTax(new Money(1D));
// group2.setTotalTax(new Money(1D));
order.setSubTotal(total);
order.setTotal(total);
DiscreteOrderItem item = new DiscreteOrderItemImpl();
Sku sku = new SkuImpl();
sku.setRetailPrice(new Money(15D));
sku.setDiscountable(true);
sku.setName("Test Sku");
sku = catalogService.saveSku(sku);
item.setSku(sku);
item.setQuantity(1);
item.setOrder(order);
item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
List<OrderItem> items = new ArrayList<>();
items.add(item);
order.setOrderItems(items);
for (OrderItem orderItem : items) {
FulfillmentGroupItem fgi = new FulfillmentGroupItemImpl();
fgi.setOrderItem(orderItem);
fgi.setQuantity(orderItem.getQuantity());
fgi.setFulfillmentGroup(group1);
// fgi.setRetailPrice(new Money(15D));
group1.addFulfillmentGroupItem(fgi);
}
order.setTotalShipping(new Money(0D));
orderService.save(order, true);
assert (order.getTotal().greaterThan(order.getSubTotal()));
// Shipping price is not taxable
assert (order.getTotalTax().equals(order.getSubTotal().multiply(0.05D)));
assert (order.getTotal().equals(order.getSubTotal().add(order.getTotalTax().add(order.getTotalShipping()))));
}
use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class CatalogTest method testSkus.
@Test
public void testSkus() throws Exception {
Sku sku = new SkuImpl();
String longDescription = "This is a great product that will help the Longhorns win.";
String description = "This is a great product.";
sku.setLongDescription(longDescription);
assert sku.getLongDescription().equals(longDescription);
sku.setDescription(description);
assert sku.getDescription().equals(description);
assert sku.isTaxable() == null;
sku.setTaxable(null);
assert sku.isTaxable() == null;
sku.setTaxable(true);
assert sku.isTaxable() == true;
sku.setTaxable(false);
assert sku.isTaxable() == false;
sku.setDiscountable(null);
assert sku.isDiscountable() == false;
sku.setDiscountable(true);
assert sku.isDiscountable() == true;
sku.setDiscountable(false);
assert sku.isDiscountable() == false;
assert sku.isAvailable() == true;
sku.setAvailable(null);
assert sku.isAvailable() == true;
sku.setAvailable(true);
assert sku.isAvailable() == true;
sku.setAvailable(false);
assert sku.isAvailable() == false;
assert sku.getName() == null;
}
use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class CatalogTest method testCatalog.
@Test(groups = { "testCatalog" })
@Transactional
public void testCatalog() throws Exception {
Category category = new CategoryImpl();
category.setName("Soaps");
category = catalogService.saveCategory(category);
Category category2 = new CategoryImpl();
category2.setName("Towels");
category2 = catalogService.saveCategory(category2);
Category category3 = new CategoryImpl();
category3.setName("SuperCategory");
category3 = catalogService.saveCategory(category3);
CategoryXref temp = new CategoryXrefImpl();
temp.setCategory(category);
temp.setSubCategory(category3);
category3.getAllParentCategoryXrefs().add(temp);
category3 = catalogService.saveCategory(category3);
// Test category hierarchy
Long cat3Id = category3.getId();
category3 = null;
category3 = catalogService.findCategoryById(cat3Id);
category3.getAllParentCategoryXrefs().clear();
CategoryXref temp2 = new CategoryXrefImpl();
temp2.setCategory(category);
temp2.setSubCategory(category3);
category3.getAllParentCategoryXrefs().add(temp2);
CategoryXref temp3 = new CategoryXrefImpl();
temp3.setCategory(category2);
temp3.setSubCategory(category3);
category3.getAllParentCategoryXrefs().add(temp3);
category3 = catalogService.saveCategory(category3);
assert category3.getAllParentCategoryXrefs().size() == 2;
Product newProduct = new ProductImpl();
Sku newDefaultSku = new SkuImpl();
newDefaultSku = catalogService.saveSku(newDefaultSku);
newProduct.setDefaultSku(newDefaultSku);
newProduct.setName("Lavender Soap");
Calendar activeStartCal = Calendar.getInstance();
activeStartCal.add(Calendar.DAY_OF_YEAR, -2);
newProduct.setActiveStartDate(activeStartCal.getTime());
// newProduct.setAllParentCategories(allParentCategories);
newProduct.setDefaultCategory(category);
newProduct.getAllParentCategoryXrefs().clear();
newProduct = catalogService.saveProduct(newProduct);
CategoryProductXref categoryXref = new CategoryProductXrefImpl();
categoryXref.setProduct(newProduct);
categoryXref.setCategory(category);
newProduct.getAllParentCategoryXrefs().add(categoryXref);
CategoryProductXref categoryXref2 = new CategoryProductXrefImpl();
categoryXref2.setProduct(newProduct);
categoryXref2.setCategory(category2);
newProduct.getAllParentCategoryXrefs().add(categoryXref2);
newProduct = catalogService.saveProduct(newProduct);
Long newProductId = newProduct.getId();
Product testProduct = catalogService.findProductById(newProductId);
assert testProduct.getId().equals(testProduct.getId());
Category testCategory = catalogService.findCategoryByName("Soaps");
assert testCategory.getId().equals(category.getId());
testCategory = catalogService.findCategoryById(category.getId());
assert testCategory.getId().equals(category.getId());
Media media = new MediaImpl();
media.setAltText("test");
media.setTitle("large");
media.setUrl("http://myUrl");
category.getCategoryMediaXref().put("large", new CategoryMediaXrefImpl(category, media, "large"));
catalogService.saveCategory(testCategory);
testCategory = catalogService.findCategoryById(category.getId());
assert (testCategory.getCategoryMediaXref().get("large") != null);
List<Category> categories = catalogService.findAllCategories();
assert categories != null && categories.size() == 3;
List<Product> products = catalogService.findAllProducts();
boolean foundProduct = false;
for (Product product : products) {
if (product.getId().equals(newProductId)) {
foundProduct = true;
}
}
assert foundProduct == true;
products = catalogService.findProductsByName(newProduct.getName());
foundProduct = false;
for (Product product : products) {
if (product.getId().equals(newProductId)) {
foundProduct = true;
}
}
assert foundProduct == true;
Sku newSku = new SkuImpl();
newSku.setName("Under Armor T-Shirt -- Red");
newSku.setRetailPrice(new Money(14.99));
newSku.setActiveStartDate(activeStartCal.getTime());
newSku = catalogService.saveSku(newSku);
List<Sku> allSkus = new ArrayList<>();
allSkus.add(newSku);
newProduct.setAdditionalSkus(allSkus);
newProduct = catalogService.saveProduct(newProduct);
Long skuId = newProduct.getSkus().get(0).getId();
Sku testSku = catalogService.findSkuById(skuId);
assert testSku.getId().equals(skuId);
List<Sku> testSkus = catalogService.findAllSkus();
boolean foundSku = false;
for (Sku sku : testSkus) {
if (sku.getId().equals(skuId)) {
foundSku = true;
}
}
assert foundSku == true;
List<Long> skuIds = new ArrayList<>();
skuIds.add(skuId);
testSkus = catalogService.findSkusByIds(skuIds);
foundSku = false;
for (Sku sku : testSkus) {
if (sku.getId().equals(skuId)) {
foundSku = true;
}
}
assert foundSku == true;
}
use of org.broadleafcommerce.core.catalog.domain.SkuImpl in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceTest method createTestOrderWithOfferAndGiftWrap.
private Order createTestOrderWithOfferAndGiftWrap() throws PricingException {
Customer customer = customerService.createCustomerFromId(null);
Order order = orderService.createNewCartForCustomer(customer);
customerService.saveCustomer(order.getCustomer());
createCountry();
createState();
Address address = new AddressImpl();
address.setAddressLine1("123 Test Rd");
address.setCity("Dallas");
address.setFirstName("Jeff");
address.setLastName("Fischer");
address.setPostalCode("75240");
address.setPrimaryPhone("972-978-9067");
address.setState(stateService.findStateByAbbreviation("KY"));
address.setCountry(countryService.findCountryByAbbreviation("US"));
address.setIsoCountrySubdivision("US-KY");
address.setIsoCountryAlpha2(isoService.findISOCountryByAlpha2Code("US"));
FulfillmentGroup group = new FulfillmentGroupImpl();
group.setAddress(address);
group.setIsShippingPriceTaxable(true);
List<FulfillmentGroup> groups = new ArrayList<FulfillmentGroup>();
FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
option.setPrice(new Money("8.50"));
option.setFulfillmentType(FulfillmentType.PHYSICAL_SHIP);
group.setFulfillmentOption(option);
group.setFulfillmentOption(option);
group.setOrder(order);
groups.add(group);
order.setFulfillmentGroups(groups);
Money total = new Money(5D);
group.setRetailShippingPrice(total);
group.setShippingPrice(total);
DiscreteOrderItem item1;
{
item1 = new DiscreteOrderItemImpl();
Sku sku = new SkuImpl();
sku.setName("Test Sku");
sku.setRetailPrice(new Money(10D));
sku.setDiscountable(true);
sku = catalogService.saveSku(sku);
item1.setSku(sku);
item1.setQuantity(2);
item1.setOrder(order);
item1.setOrderItemType(OrderItemType.DISCRETE);
item1 = (DiscreteOrderItem) orderItemService.saveOrderItem(item1);
order.addOrderItem(item1);
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(item1);
fgItem.setQuantity(2);
// fgItem.setPrice(new Money(0D));
group.addFulfillmentGroupItem(fgItem);
}
{
DiscreteOrderItem item = new DiscreteOrderItemImpl();
Sku sku = new SkuImpl();
sku.setName("Test Product 2");
sku.setRetailPrice(new Money(20D));
sku.setDiscountable(true);
sku = catalogService.saveSku(sku);
item.setSku(sku);
item.setQuantity(1);
item.setOrder(order);
item.setOrderItemType(OrderItemType.DISCRETE);
item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
order.addOrderItem(item);
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(item);
fgItem.setQuantity(1);
// fgItem.setPrice(new Money(0D));
group.addFulfillmentGroupItem(fgItem);
}
{
GiftWrapOrderItem item = new GiftWrapOrderItemImpl();
Sku sku = new SkuImpl();
sku.setName("Test GiftWrap");
sku.setRetailPrice(new Money(1D));
sku.setDiscountable(true);
sku = catalogService.saveSku(sku);
item.setSku(sku);
item.setQuantity(1);
item.setOrder(order);
item.getWrappedItems().add(item1);
item.setOrderItemType(OrderItemType.GIFTWRAP);
item = (GiftWrapOrderItem) orderItemService.saveOrderItem(item);
order.addOrderItem(item);
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(item);
fgItem.setQuantity(1);
// fgItem.setPrice(new Money(0D));
group.addFulfillmentGroupItem(fgItem);
}
return order;
}
Aggregations