use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ValidateAddRequestActivity method validate.
protected ProcessContext<CartOperationRequest> validate(ProcessContext<CartOperationRequest> context) {
CartOperationRequest request = context.getSeedData();
OrderItemRequestDTO orderItemRequestDTO = request.getItemRequest();
Integer orderItemQuantity = orderItemRequestDTO.getQuantity();
if (!hasQuantity(orderItemQuantity)) {
context.stopProcess();
} else if (orderItemQuantity < 0) {
throw new IllegalArgumentException("Quantity cannot be negative");
} else if (request.getOrder() == null) {
throw new IllegalArgumentException("Order is required when adding item to order");
} else {
Product product = determineProduct(orderItemRequestDTO);
Sku sku;
try {
sku = determineSku(product, orderItemRequestDTO.getSkuId(), orderItemRequestDTO.getItemAttributes(), (ActivityMessages) context);
} catch (RequiredAttributeNotProvidedException e) {
if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
// Mark the request as a configuration error and proceed with the add.
orderItemRequestDTO.setHasConfigurationError(Boolean.TRUE);
return context;
}
throw e;
}
addSkuToCart(sku, orderItemRequestDTO, product, request);
if (!hasSameCurrency(orderItemRequestDTO, request, sku)) {
throw new IllegalArgumentException("Cannot have items with differing currencies in one cart");
}
validateIfParentOrderItemExists(orderItemRequestDTO);
}
return context;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDaoTest method createUpSaleValues.
@Test(groups = "createUpSaleValues", dependsOnGroups = "createProducts")
@Rollback(false)
@Transactional
public void createUpSaleValues() {
Product prod1 = savedProducts.get(0);
List<RelatedProduct> upSales = new ArrayList<>();
getRelatedUpSaleProduct(prod1, savedProducts.get(2), upSales);
getRelatedUpSaleProduct(prod1, savedProducts.get(3), upSales);
getRelatedUpSaleProduct(prod1, savedProducts.get(4), upSales);
prod1.setUpSaleProducts(upSales);
prod1 = catalogService.saveProduct(prod1);
assert (prod1.getId() != null);
Product prod2 = savedProducts.get(1);
List<RelatedProduct> upSales2 = new ArrayList<>();
getRelatedUpSaleProduct(prod2, savedProducts.get(5), upSales2);
getRelatedUpSaleProduct(prod2, savedProducts.get(6), upSales2);
prod2.setUpSaleProducts(upSales2);
prod2 = catalogService.saveProduct(prod2);
assert (prod2.getId() != null);
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDaoTest method testReadProductsWithUpSaleValues.
@Test(groups = "testReadProductsWithUpSaleValues", dependsOnGroups = "createUpSaleValues")
@Transactional
public void testReadProductsWithUpSaleValues() {
Product result = productDao.readProductById(savedProducts.get(0).getId());
List<RelatedProduct> related = result.getUpSaleProducts();
assert (related != null);
assert (!related.isEmpty());
assert (related.size() == 2 || related.size() == 3);
for (RelatedProduct rp : related) {
assert (rp instanceof UpSaleProductImpl);
}
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDaoTest method testFeaturedProduct.
@Test(dataProvider = "basicProduct", dataProviderClass = ProductDataProvider.class)
@Transactional
public void testFeaturedProduct(Product product) {
product = catalogService.saveProduct(product);
Long productId = product.getId();
product.setFeaturedProduct(true);
catalogService.saveProduct(product);
Product testProduct = productDao.readProductById(productId);
assert (testProduct.isFeaturedProduct() == true);
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDaoTest method createCrossSaleValues.
@Test(groups = "createCrossSaleValues", dependsOnGroups = "testReadProductsWithUpSaleValues")
@Rollback(false)
@Transactional
public void createCrossSaleValues() {
Product prod1 = savedProducts.get(0);
List<RelatedProduct> crossSale = new ArrayList<>();
getRelatedCrossProduct(prod1, savedProducts.get(2), crossSale);
getRelatedCrossProduct(prod1, savedProducts.get(3), crossSale);
getRelatedCrossProduct(prod1, savedProducts.get(4), crossSale);
prod1.setCrossSaleProducts(crossSale);
prod1 = catalogService.saveProduct(prod1);
assert (prod1.getId() != null);
Product prod2 = savedProducts.get(1);
List<RelatedProduct> crossSale2 = new ArrayList<>();
getRelatedCrossProduct(prod2, savedProducts.get(5), crossSale2);
getRelatedCrossProduct(prod2, savedProducts.get(6), crossSale2);
prod2.setCrossSaleProducts(crossSale2);
prod2 = catalogService.saveProduct(prod2);
assert (prod2.getId() != null);
}
Aggregations