use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class OrderBaseTest method setUpCartWithInactiveSku.
public Order setUpCartWithInactiveSku() throws AddToCartException {
Customer customer = customerService.saveCustomer(createNamedCustomer());
Order order = orderService.createNewCartForCustomer(customer);
Product newProduct = addTestProduct("Plastic Crate Should Be Inactive", "Crates");
Category newCategory = newProduct.getDefaultCategory();
order = orderService.addItem(order.getId(), new OrderItemRequestDTO(newProduct.getId(), newProduct.getDefaultSku().getId(), newCategory.getId(), 1), true);
// Make the SKU inactive
newProduct.getDefaultSku().setActiveEndDate(DateUtils.addDays(new Date(), -1));
catalogService.saveSku(newProduct.getDefaultSku());
return order;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class CommonSetupBaseTest method addProductBundle.
public ProductBundle addProductBundle() {
// Create the product
Product p = addTestProduct("bundleproduct1", "bundlecat1");
// Create the sku for the ProductBundle object
Sku bundleSku = catalogService.createSku();
bundleSku.setName(p.getName());
bundleSku.setRetailPrice(new Money(44.99));
bundleSku.setActiveStartDate(p.getActiveStartDate());
bundleSku.setActiveEndDate(p.getActiveEndDate());
bundleSku.setDiscountable(true);
// Create the ProductBundle and associate the sku
ProductBundle bundle = (ProductBundle) catalogService.createProduct(ProductType.BUNDLE);
bundle.setDefaultCategory(p.getDefaultCategory());
bundle.setDefaultSku(bundleSku);
bundle = (ProductBundle) catalogService.saveProduct(bundle);
// Reverse-associate the ProductBundle to the sku (Must be done this way because it's a
// bidirectional OneToOne relationship
// bundleSku.setDefaultProduct(bundle);
// catalogService.saveSku(bundleSku);
// Wrap the product/sku that is part of the bundle in a SkuBundleItem
SkuBundleItem skuBundleItem = new SkuBundleItemImpl();
skuBundleItem.setBundle(bundle);
skuBundleItem.setQuantity(1);
skuBundleItem.setSku(p.getDefaultSku());
// Add the SkuBundleItem to the ProductBundle
bundle.getSkuBundleItems().add(skuBundleItem);
bundle = (ProductBundle) catalogService.saveProduct(bundle);
return bundle;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class OrderTest method testIllegalAddScenarios.
@Test(groups = { "testIllegalAddScenarios" }, dependsOnGroups = { "addItemToOrder" })
@Transactional
public void testIllegalAddScenarios() throws AddToCartException {
Order order = orderService.findOrderById(orderId);
assert order != null;
Product activeProduct = addTestProduct("mug", "cups", true);
Product inactiveProduct = addTestProduct("cup", "cups", false);
// Inactive skus should not be added
OrderItemRequestDTO itemRequest = new OrderItemRequestDTO().setQuantity(1).setSkuId(inactiveProduct.getDefaultSku().getId());
boolean addSuccessful = true;
try {
order = orderService.addItem(orderId, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
}
assert !addSuccessful;
// Products that have SKUs marked as inactive should not be added either
itemRequest = new OrderItemRequestDTO().setQuantity(1).setProductId(inactiveProduct.getId());
addSuccessful = true;
try {
order = orderService.addItem(orderId, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
}
assert !addSuccessful;
// Negative quantities are not allowed
itemRequest = new OrderItemRequestDTO().setQuantity(-1).setSkuId(activeProduct.getDefaultSku().getId());
addSuccessful = true;
try {
order = orderService.addItem(orderId, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
assert e.getCause() instanceof IllegalArgumentException;
}
assert !addSuccessful;
// Order must exist
itemRequest = new OrderItemRequestDTO().setQuantity(1).setSkuId(activeProduct.getDefaultSku().getId());
addSuccessful = true;
try {
order = orderService.addItem(-1L, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
assert e.getCause() instanceof IllegalArgumentException;
}
assert !addSuccessful;
// If a product is provided, it must exist
itemRequest = new OrderItemRequestDTO().setQuantity(1).setProductId(-1L);
addSuccessful = true;
try {
order = orderService.addItem(orderId, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
assert e.getCause() instanceof IllegalArgumentException;
}
assert !addSuccessful;
// The SKU must exist
itemRequest = new OrderItemRequestDTO().setQuantity(1).setSkuId(-1L);
addSuccessful = true;
try {
order = orderService.addItem(orderId, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
assert e.getCause() instanceof IllegalArgumentException;
}
assert !addSuccessful;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class OrderTest method testIllegalUpdateScenarios.
@Test(groups = { "testIllegalUpdateScenarios" }, dependsOnGroups = { "addItemToOrder" })
@Transactional
public void testIllegalUpdateScenarios() throws UpdateCartException, AddToCartException, RemoveFromCartException {
Order order = orderService.findOrderById(orderId);
assert order != null;
Product activeProduct = addTestProduct("mug", "cups", true);
Product inactiveProduct = addTestProduct("cup", "cups", false);
// Inactive skus should not be added
OrderItemRequestDTO itemRequest = new OrderItemRequestDTO().setQuantity(1).setSkuId(activeProduct.getDefaultSku().getId());
boolean addSuccessful = true;
try {
order = orderService.addItem(orderId, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
}
assert addSuccessful;
// should not be able to update to negative quantity
OrderItem item = orderService.findLastMatchingItem(order, activeProduct.getDefaultSku().getId(), activeProduct.getId());
itemRequest = new OrderItemRequestDTO().setQuantity(-3).setOrderItemId(item.getId());
boolean updateSuccessful = true;
try {
orderService.updateItemQuantity(orderId, itemRequest, true);
} catch (UpdateCartException e) {
updateSuccessful = false;
}
assert !updateSuccessful;
// shouldn't be able to update the quantity of a DOI inside of a bundle
ProductBundle bundle = addProductBundle();
itemRequest = new OrderItemRequestDTO().setQuantity(1).setProductId(bundle.getId()).setSkuId(bundle.getDefaultSku().getId());
addSuccessful = true;
try {
order = orderService.addItem(orderId, itemRequest, true);
} catch (AddToCartException e) {
addSuccessful = false;
}
assert addSuccessful;
BundleOrderItem bundleItem = (BundleOrderItem) orderService.findLastMatchingItem(order, bundle.getDefaultSku().getId(), bundle.getId());
// should just be a single DOI inside the bundle
DiscreteOrderItem doi = bundleItem.getDiscreteOrderItems().get(0);
itemRequest = new OrderItemRequestDTO().setQuantity(4).setOrderItemId(doi.getId());
try {
orderService.updateItemQuantity(orderId, itemRequest, true);
} catch (UpdateCartException e) {
updateSuccessful = false;
}
assert !updateSuccessful;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDataProvider method getProduct.
private static Product getProduct(Long id) {
Calendar activeStartCal = Calendar.getInstance();
activeStartCal.add(Calendar.DAY_OF_YEAR, -2);
Product product = new ProductImpl();
Sku defaultSku = new SkuImpl();
defaultSku.setRetailPrice(new Money(BigDecimal.valueOf(15.0)));
defaultSku.setSalePrice(new Money(BigDecimal.valueOf(10.0)));
defaultSku.setActiveStartDate(activeStartCal.getTime());
product.setDefaultSku(defaultSku);
if (id == null) {
defaultSku.setName("productNameTest");
return product;
}
product.setId(id);
defaultSku.setName(id.toString());
defaultSku.setId(id);
return product;
}
Aggregations