use of com.salesmanager.core.model.catalog.product.attribute.ProductOption in project shopizer by shopizer-ecommerce.
the class ReadableShoppingCartMapper method merge.
@Override
public ReadableShoppingCart merge(ShoppingCart source, ReadableShoppingCart destination, MerchantStore store, Language language) {
Validate.notNull(source, "ShoppingCart cannot be null");
Validate.notNull(destination, "ReadableShoppingCart cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
destination.setCode(source.getShoppingCartCode());
int cartQuantity = 0;
destination.setCustomer(source.getCustomerId());
try {
if (!StringUtils.isBlank(source.getPromoCode())) {
// promo valid 1 day
Date promoDateAdded = source.getPromoAdded();
if (promoDateAdded == null) {
promoDateAdded = new Date();
}
Instant instant = promoDateAdded.toInstant();
ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
LocalDate date = zdt.toLocalDate();
// date added < date + 1 day
LocalDate tomorrow = LocalDate.now().plusDays(1);
if (date.isBefore(tomorrow)) {
destination.setPromoCode(source.getPromoCode());
}
}
Set<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> items = source.getLineItems();
if (items != null) {
for (com.salesmanager.core.model.shoppingcart.ShoppingCartItem item : items) {
ReadableShoppingCartItem shoppingCartItem = new ReadableShoppingCartItem();
readableMinimalProductMapper.merge(item.getProduct(), shoppingCartItem, store, language);
// ReadableProductPopulator readableProductPopulator = new
// ReadableProductPopulator();
// readableProductPopulator.setPricingService(pricingService);
// readableProductPopulator.setimageUtils(imageUtils);
// readableProductPopulator.populate(item.getProduct(), shoppingCartItem, store,
// language);
shoppingCartItem.setPrice(item.getItemPrice());
shoppingCartItem.setFinalPrice(pricingService.getDisplayAmount(item.getItemPrice(), store));
shoppingCartItem.setQuantity(item.getQuantity());
cartQuantity = cartQuantity + item.getQuantity();
BigDecimal subTotal = pricingService.calculatePriceQuantity(item.getItemPrice(), item.getQuantity());
// calculate sub total (price * quantity)
shoppingCartItem.setSubTotal(subTotal);
shoppingCartItem.setDisplaySubTotal(pricingService.getDisplayAmount(subTotal, store));
Set<com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem> attributes = item.getAttributes();
if (attributes != null) {
for (com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem attribute : attributes) {
ProductAttribute productAttribute = productAttributeService.getById(attribute.getProductAttributeId());
if (productAttribute == null) {
LOG.warn("Product attribute with ID " + attribute.getId() + " not found, skipping cart attribute " + attribute.getId());
continue;
}
ReadableShoppingCartAttribute cartAttribute = new ReadableShoppingCartAttribute();
cartAttribute.setId(attribute.getId());
ProductOption option = productAttribute.getProductOption();
ProductOptionValue optionValue = productAttribute.getProductOptionValue();
List<ProductOptionDescription> optionDescriptions = option.getDescriptionsSettoList();
List<ProductOptionValueDescription> optionValueDescriptions = optionValue.getDescriptionsSettoList();
String optName = null;
String optValue = null;
if (!CollectionUtils.isEmpty(optionDescriptions) && !CollectionUtils.isEmpty(optionValueDescriptions)) {
optName = optionDescriptions.get(0).getName();
optValue = optionValueDescriptions.get(0).getName();
for (ProductOptionDescription optionDescription : optionDescriptions) {
if (optionDescription.getLanguage() != null && optionDescription.getLanguage().getId().intValue() == language.getId().intValue()) {
optName = optionDescription.getName();
break;
}
}
for (ProductOptionValueDescription optionValueDescription : optionValueDescriptions) {
if (optionValueDescription.getLanguage() != null && optionValueDescription.getLanguage().getId().intValue() == language.getId().intValue()) {
optValue = optionValueDescription.getName();
break;
}
}
}
if (optName != null) {
ReadableShoppingCartAttributeOption attributeOption = new ReadableShoppingCartAttributeOption();
attributeOption.setCode(option.getCode());
attributeOption.setId(option.getId());
attributeOption.setName(optName);
cartAttribute.setOption(attributeOption);
}
if (optValue != null) {
ReadableShoppingCartAttributeOptionValue attributeOptionValue = new ReadableShoppingCartAttributeOptionValue();
attributeOptionValue.setCode(optionValue.getCode());
attributeOptionValue.setId(optionValue.getId());
attributeOptionValue.setName(optValue);
cartAttribute.setOptionValue(attributeOptionValue);
}
shoppingCartItem.getCartItemattributes().add(cartAttribute);
}
}
destination.getProducts().add(shoppingCartItem);
}
}
// Calculate totals using shoppingCartService
// OrderSummary contains ShoppingCart items
OrderSummary summary = new OrderSummary();
List<com.salesmanager.core.model.shoppingcart.ShoppingCartItem> productsList = new ArrayList<com.salesmanager.core.model.shoppingcart.ShoppingCartItem>();
productsList.addAll(source.getLineItems());
summary.setProducts(productsList);
// OrdetTotalSummary contains all calculations
OrderTotalSummary orderSummary = shoppingCartCalculationService.calculate(source, store, language);
if (CollectionUtils.isNotEmpty(orderSummary.getTotals())) {
if (orderSummary.getTotals().stream().filter(t -> Constants.OT_DISCOUNT_TITLE.equals(t.getOrderTotalCode())).count() == 0) {
// no promo coupon applied
destination.setPromoCode(null);
}
List<ReadableOrderTotal> totals = new ArrayList<ReadableOrderTotal>();
for (com.salesmanager.core.model.order.OrderTotal t : orderSummary.getTotals()) {
ReadableOrderTotal total = new ReadableOrderTotal();
total.setCode(t.getOrderTotalCode());
total.setValue(t.getValue());
total.setText(t.getText());
totals.add(total);
}
destination.setTotals(totals);
}
destination.setSubtotal(orderSummary.getSubTotal());
destination.setDisplaySubTotal(pricingService.getDisplayAmount(orderSummary.getSubTotal(), store));
destination.setTotal(orderSummary.getTotal());
destination.setDisplayTotal(pricingService.getDisplayAmount(orderSummary.getTotal(), store));
destination.setQuantity(cartQuantity);
destination.setId(source.getId());
if (source.getOrderId() != null) {
destination.setOrder(source.getOrderId());
}
} catch (Exception e) {
throw new ConversionRuntimeException("An error occured while converting ReadableShoppingCart", e);
}
return destination;
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductOption in project shopizer by shopizer-ecommerce.
the class PersistableProductAttributeMapper method merge.
@Override
public ProductAttribute merge(PersistableProductAttribute source, ProductAttribute destination, MerchantStore store, Language language) {
ProductOption productOption = null;
if (!StringUtils.isBlank(source.getOption().getCode())) {
productOption = productOptionService.getByCode(store, source.getOption().getCode());
} else {
Validate.notNull(source.getOption().getId(), "Product option id is null");
productOption = productOptionService.getById(source.getOption().getId());
}
if (productOption == null) {
throw new ConversionRuntimeException("Product option id " + source.getOption().getId() + " does not exist");
}
ProductOptionValue productOptionValue = null;
if (!StringUtils.isBlank(source.getOptionValue().getCode())) {
productOptionValue = productOptionValueService.getByCode(store, source.getOptionValue().getCode());
} else if (source.getProductId() != null && source.getOptionValue().getId().longValue() > 0) {
productOptionValue = productOptionValueService.getById(source.getOptionValue().getId());
} else {
// ProductOption value is text
productOptionValue = new ProductOptionValue();
productOptionValue.setProductOptionDisplayOnly(true);
productOptionValue.setCode(UUID.randomUUID().toString());
productOptionValue.setMerchantStore(store);
}
if (!CollectionUtils.isEmpty((source.getOptionValue().getDescriptions()))) {
productOptionValue = persistableProductOptionValueMapper.merge(source.getOptionValue(), productOptionValue, store, language);
try {
productOptionValueService.saveOrUpdate(productOptionValue);
} catch (ServiceException e) {
throw new ConversionRuntimeException("Error converting ProductOptionValue", e);
}
}
if (productOptionValue == null && !source.isAttributeDisplayOnly()) {
throw new ConversionRuntimeException("Product option value id " + source.getOptionValue().getId() + " does not exist");
}
if (productOption.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionRuntimeException("Invalid product option id ");
}
if (productOptionValue != null && productOptionValue.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionRuntimeException("Invalid product option value id ");
}
if (source.getProductId() != null && source.getProductId().longValue() > 0) {
Product p = productService.getById(source.getProductId());
if (p == null) {
throw new ConversionRuntimeException("Invalid product id ");
}
destination.setProduct(p);
}
if (destination.getId() != null && destination.getId().longValue() > 0) {
destination.setId(destination.getId());
} else {
destination.setId(null);
}
destination.setProductOption(productOption);
destination.setProductOptionValue(productOptionValue);
destination.setProductAttributePrice(source.getProductAttributePrice());
destination.setProductAttributeWeight(source.getProductAttributeWeight());
destination.setProductAttributePrice(source.getProductAttributePrice());
destination.setAttributeDisplayOnly(source.isAttributeDisplayOnly());
return destination;
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductOption in project shopizer by shopizer-ecommerce.
the class PersistableProductOptionSetMapper method merge.
@Override
public ProductOptionSet merge(PersistableProductOptionSet source, ProductOptionSet destination, MerchantStore store, Language language) {
Validate.notNull(destination, "ProductOptionSet must not be null");
destination.setId(source.getId());
destination.setCode(source.getCode());
destination.setOptionDisplayOnly(source.isReadOnly());
ProductOption option = productOptionService.getById(store, source.getOption());
destination.setOption(option);
if (!CollectionUtils.isEmpty(source.getOptionValues())) {
List<ProductOptionValue> values = source.getOptionValues().stream().map(id -> value(id, store)).collect(Collectors.toList());
destination.setValues(values);
}
if (!CollectionUtils.isEmpty(source.getProductTypes())) {
try {
List<ProductType> types = productTypeService.listProductTypes(source.getProductTypes(), store, language);
Set<ProductType> typesSet = new HashSet<ProductType>(types);
destination.setProductTypes(typesSet);
} catch (ServiceException e) {
throw new ConversionRuntimeException("Error while mpping ProductOptionSet", e);
}
}
return destination;
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductOption in project shopizer by shopizer-ecommerce.
the class OrderTest method getMerchantOrders.
@Test
public void getMerchantOrders() throws ServiceException {
Currency currency = currencyService.getByCode(USD_CURRENCY_CODE);
Country country = countryService.getByCode("US");
Zone zone = zoneService.getByCode("VT");
Language en = languageService.getByCode("en");
MerchantStore merchant = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
/**
* Create a customer *
*/
Customer customer = new Customer();
customer.setMerchantStore(merchant);
customer.setDefaultLanguage(en);
customer.setEmailAddress("email@email.com");
customer.setPassword("-1999");
customer.setNick("My New nick");
customer.setCompany(" Apple");
customer.setGender(CustomerGender.M);
customer.setDateOfBirth(new Date());
Billing billing = new Billing();
billing.setAddress("Billing address");
billing.setCity("Billing city");
billing.setCompany("Billing company");
billing.setCountry(country);
billing.setFirstName("Carl");
billing.setLastName("Samson");
billing.setPostalCode("Billing postal code");
billing.setState("Billing state");
billing.setZone(zone);
Delivery delivery = new Delivery();
delivery.setAddress("Shipping address");
delivery.setCountry(country);
delivery.setZone(zone);
customer.setBilling(billing);
customer.setDelivery(delivery);
customerService.create(customer);
// create a product with attributes
/**
* CATALOG CREATION *
*/
ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
/**
* Create the category
*/
Category shirts = new Category();
shirts.setMerchantStore(merchant);
shirts.setCode("shirts");
CategoryDescription shirtsEnglishDescription = new CategoryDescription();
shirtsEnglishDescription.setName("Shirts");
shirtsEnglishDescription.setCategory(shirts);
shirtsEnglishDescription.setLanguage(en);
Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
descriptions.add(shirtsEnglishDescription);
shirts.setDescriptions(descriptions);
categoryService.create(shirts);
/**
* Create a manufacturer
*/
Manufacturer addidas = new Manufacturer();
addidas.setMerchantStore(merchant);
addidas.setCode("addidas");
ManufacturerDescription addidasDesc = new ManufacturerDescription();
addidasDesc.setLanguage(en);
addidasDesc.setManufacturer(addidas);
addidasDesc.setName("Addidas");
addidas.getDescriptions().add(addidasDesc);
manufacturerService.create(addidas);
/**
* Create an option
*/
ProductOption option = new ProductOption();
option.setMerchantStore(merchant);
option.setCode("color");
option.setProductOptionType(ProductOptionType.Radio.name());
ProductOptionDescription optionDescription = new ProductOptionDescription();
optionDescription.setLanguage(en);
optionDescription.setName("Color");
optionDescription.setDescription("Item color");
optionDescription.setProductOption(option);
option.getDescriptions().add(optionDescription);
productOptionService.saveOrUpdate(option);
/**
* first option value *
*/
ProductOptionValue white = new ProductOptionValue();
white.setMerchantStore(merchant);
white.setCode("white");
ProductOptionValueDescription whiteDescription = new ProductOptionValueDescription();
whiteDescription.setLanguage(en);
whiteDescription.setName("White");
whiteDescription.setDescription("White color");
whiteDescription.setProductOptionValue(white);
white.getDescriptions().add(whiteDescription);
productOptionValueService.saveOrUpdate(white);
ProductOptionValue black = new ProductOptionValue();
black.setMerchantStore(merchant);
black.setCode("black");
/**
* second option value *
*/
ProductOptionValueDescription blackDesc = new ProductOptionValueDescription();
blackDesc.setLanguage(en);
blackDesc.setName("Black");
blackDesc.setDescription("Black color");
blackDesc.setProductOptionValue(black);
black.getDescriptions().add(blackDesc);
productOptionValueService.saveOrUpdate(black);
/**
* Create a complex product
*/
Product product = new Product();
product.setProductHeight(new BigDecimal(4));
product.setProductLength(new BigDecimal(3));
product.setProductWidth(new BigDecimal(1));
product.setSku("TB12345");
product.setManufacturer(addidas);
product.setType(generalType);
product.setMerchantStore(merchant);
// Product description
ProductDescription description = new ProductDescription();
description.setName("Short sleeves shirt");
description.setLanguage(en);
description.setProduct(product);
product.getDescriptions().add(description);
product.getCategories().add(shirts);
// availability
ProductAvailability availability = new ProductAvailability();
availability.setProductDateAvailable(new Date());
availability.setProductQuantity(100);
availability.setRegion("*");
// associate with product
availability.setProduct(product);
// price
ProductPrice dprice = new ProductPrice();
dprice.setDefaultPrice(true);
dprice.setProductPriceAmount(new BigDecimal(29.99));
dprice.setProductAvailability(availability);
ProductPriceDescription dpd = new ProductPriceDescription();
dpd.setName("Base price");
dpd.setProductPrice(dprice);
dpd.setLanguage(en);
dprice.getDescriptions().add(dpd);
availability.getPrices().add(dprice);
product.getAvailabilities().add(availability);
// attributes
// white
ProductAttribute whiteAttribute = new ProductAttribute();
whiteAttribute.setProduct(product);
whiteAttribute.setProductOption(option);
whiteAttribute.setAttributeDefault(true);
// no price variation
whiteAttribute.setProductAttributePrice(new BigDecimal(0));
// no weight variation
whiteAttribute.setProductAttributeWeight(new BigDecimal(0));
whiteAttribute.setProductOption(option);
whiteAttribute.setProductOptionValue(white);
product.getAttributes().add(whiteAttribute);
// black
ProductAttribute blackAttribute = new ProductAttribute();
blackAttribute.setProduct(product);
blackAttribute.setProductOption(option);
// 5 + dollars
blackAttribute.setProductAttributePrice(new BigDecimal(5));
// no weight variation
blackAttribute.setProductAttributeWeight(new BigDecimal(0));
blackAttribute.setProductOption(option);
blackAttribute.setProductOptionValue(black);
product.getAttributes().add(blackAttribute);
productService.create(product);
/**
* Create an order *
*/
Order order = new Order();
/**
* payment details *
*/
CreditCard creditCard = new CreditCard();
creditCard.setCardType(CreditCardType.VISA);
creditCard.setCcCvv("123");
creditCard.setCcExpires("12/30/2020");
creditCard.setCcNumber("123456789");
creditCard.setCcOwner("ccOwner");
order.setCreditCard(creditCard);
/**
* order core attributes *
*/
order.setDatePurchased(new Date());
order.setCurrency(currency);
order.setMerchant(merchant);
order.setLastModified(new Date());
// no price variation because of the currency
order.setCurrencyValue(new BigDecimal(1));
order.setCustomerId(1L);
order.setDelivery(delivery);
order.setIpAddress("ipAddress");
order.setMerchant(merchant);
order.setOrderDateFinished(new Date());
order.setPaymentType(PaymentType.CREDITCARD);
order.setPaymentModuleCode("payment Module Code");
order.setShippingModuleCode("UPS");
order.setStatus(OrderStatus.ORDERED);
order.setCustomerAgreement(true);
order.setConfirmedAddress(true);
order.setTotal(dprice.getProductPriceAmount());
order.setCustomerEmailAddress(customer.getEmailAddress());
order.setBilling(billing);
order.setDelivery(delivery);
/**
* ORDER PRODUCT *
*/
// OrderProduct
OrderProduct oproduct = new OrderProduct();
oproduct.setDownloads(null);
oproduct.setOneTimeCharge(dprice.getProductPriceAmount());
oproduct.setOrder(order);
oproduct.setProductName(description.getName());
oproduct.setProductQuantity(1);
oproduct.setSku(product.getSku());
// set order product price
OrderProductPrice orderProductPrice = new OrderProductPrice();
// default price (same as default product price)
orderProductPrice.setDefaultPrice(true);
orderProductPrice.setOrderProduct(oproduct);
orderProductPrice.setProductPrice(dprice.getProductPriceAmount());
orderProductPrice.setProductPriceCode(ProductPriceType.ONE_TIME.name());
oproduct.getPrices().add(orderProductPrice);
// order product attribute
OrderProductAttribute orderProductAttribute = new OrderProductAttribute();
orderProductAttribute.setOrderProduct(oproduct);
// no extra charge
orderProductAttribute.setProductAttributePrice(new BigDecimal("0.00"));
orderProductAttribute.setProductAttributeName(whiteDescription.getName());
orderProductAttribute.setProductOptionId(option.getId());
orderProductAttribute.setProductOptionValueId(white.getId());
oproduct.getOrderAttributes().add(orderProductAttribute);
order.getOrderProducts().add(oproduct);
/**
* ORDER TOTAL *
*/
OrderTotal subTotal = new OrderTotal();
subTotal.setOrder(order);
subTotal.setOrderTotalCode(Constants.OT_SUBTOTAL_MODULE_CODE);
subTotal.setSortOrder(0);
subTotal.setTitle("Sub Total");
subTotal.setValue(dprice.getProductPriceAmount());
order.getOrderTotal().add(subTotal);
OrderTotal total = new OrderTotal();
total.setOrder(order);
total.setOrderTotalCode(Constants.OT_TOTAL_MODULE_CODE);
total.setSortOrder(1);
total.setTitle("Total");
total.setValue(dprice.getProductPriceAmount());
order.getOrderTotal().add(total);
/**
* ORDER HISTORY *
*/
// create a log entry in order history
OrderStatusHistory history = new OrderStatusHistory();
history.setOrder(order);
history.setDateAdded(new Date());
history.setStatus(OrderStatus.ORDERED);
history.setComments("We received your order");
order.getOrderHistory().add(history);
/**
* CREATE ORDER *
*/
orderService.create(order);
/**
* SEARCH ORDERS *
*/
OrderCriteria criteria = new OrderCriteria();
criteria.setStartIndex(0);
criteria.setMaxCount(10);
OrderList ordserList = orderService.listByStore(merchant, criteria);
Assert.assertNotNull(ordserList);
Assert.assertNotNull("Merchant Orders are null.", ordserList.getOrders());
Assert.assertTrue("Merchant Orders count is not one.", (ordserList.getOrders() != null && ordserList.getOrders().size() == 1));
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductOption in project shopizer by shopizer-ecommerce.
the class ShoppingCartTest method createShoppingCart.
@Test
public void createShoppingCart() throws Exception {
MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
Language en = languageService.getByCode("en");
/**
* CATALOG CREATION *
*/
ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
/**
* Create the category
*/
Category shirts = new Category();
shirts.setMerchantStore(store);
shirts.setCode("shirts");
CategoryDescription shirtsEnglishDescription = new CategoryDescription();
shirtsEnglishDescription.setName("Shirts");
shirtsEnglishDescription.setCategory(shirts);
shirtsEnglishDescription.setLanguage(en);
Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
descriptions.add(shirtsEnglishDescription);
shirts.setDescriptions(descriptions);
categoryService.create(shirts);
/**
* Create a manufacturer
*/
Manufacturer addidas = new Manufacturer();
addidas.setMerchantStore(store);
addidas.setCode("addidas");
ManufacturerDescription addidasDesc = new ManufacturerDescription();
addidasDesc.setLanguage(en);
addidasDesc.setManufacturer(addidas);
addidasDesc.setName("Addidas");
addidas.getDescriptions().add(addidasDesc);
manufacturerService.create(addidas);
/**
* Create an option
*/
ProductOption option = new ProductOption();
option.setMerchantStore(store);
option.setCode("color");
option.setProductOptionType(ProductOptionType.Radio.name());
ProductOptionDescription optionDescription = new ProductOptionDescription();
optionDescription.setLanguage(en);
optionDescription.setName("Color");
optionDescription.setDescription("Item color");
optionDescription.setProductOption(option);
option.getDescriptions().add(optionDescription);
productOptionService.saveOrUpdate(option);
/**
* first option value *
*/
ProductOptionValue white = new ProductOptionValue();
white.setMerchantStore(store);
white.setCode("white");
ProductOptionValueDescription whiteDescription = new ProductOptionValueDescription();
whiteDescription.setLanguage(en);
whiteDescription.setName("White");
whiteDescription.setDescription("White color");
whiteDescription.setProductOptionValue(white);
white.getDescriptions().add(whiteDescription);
productOptionValueService.saveOrUpdate(white);
ProductOptionValue black = new ProductOptionValue();
black.setMerchantStore(store);
black.setCode("black");
/**
* second option value *
*/
ProductOptionValueDescription blackDesc = new ProductOptionValueDescription();
blackDesc.setLanguage(en);
blackDesc.setName("Black");
blackDesc.setDescription("Black color");
blackDesc.setProductOptionValue(black);
black.getDescriptions().add(blackDesc);
productOptionValueService.saveOrUpdate(black);
/**
* Create a complex product
*/
Product product = new Product();
product.setProductHeight(new BigDecimal(4));
product.setProductLength(new BigDecimal(3));
product.setProductWidth(new BigDecimal(1));
product.setSku("XABC12");
product.setManufacturer(addidas);
product.setType(generalType);
product.setMerchantStore(store);
// Product description
ProductDescription description = new ProductDescription();
description.setName("Short sleeves shirt");
description.setLanguage(en);
description.setProduct(product);
product.getDescriptions().add(description);
product.getCategories().add(shirts);
// availability
ProductAvailability availability = new ProductAvailability();
availability.setProductDateAvailable(new Date());
availability.setProductQuantity(100);
availability.setRegion("*");
// associate with product
availability.setProduct(product);
// price
ProductPrice dprice = new ProductPrice();
dprice.setDefaultPrice(true);
dprice.setProductPriceAmount(new BigDecimal(29.99));
dprice.setProductAvailability(availability);
ProductPriceDescription dpd = new ProductPriceDescription();
dpd.setName("Base price");
dpd.setProductPrice(dprice);
dpd.setLanguage(en);
dprice.getDescriptions().add(dpd);
availability.getPrices().add(dprice);
product.getAvailabilities().add(availability);
// attributes
// white
ProductAttribute whiteAttribute = new ProductAttribute();
whiteAttribute.setProduct(product);
whiteAttribute.setProductOption(option);
whiteAttribute.setAttributeDefault(true);
// no price variation
whiteAttribute.setProductAttributePrice(new BigDecimal(0));
// no weight variation
whiteAttribute.setProductAttributeWeight(new BigDecimal(0));
whiteAttribute.setProductOption(option);
whiteAttribute.setProductOptionValue(white);
product.getAttributes().add(whiteAttribute);
// black
ProductAttribute blackAttribute = new ProductAttribute();
blackAttribute.setProduct(product);
blackAttribute.setProductOption(option);
// 5 + dollars
blackAttribute.setProductAttributePrice(new BigDecimal(5));
// no weight variation
blackAttribute.setProductAttributeWeight(new BigDecimal(0));
blackAttribute.setProductOption(option);
blackAttribute.setProductOptionValue(black);
product.getAttributes().add(blackAttribute);
productService.create(product);
/**
* Create Shopping cart *
*/
ShoppingCart shoppingCart = new ShoppingCart();
shoppingCart.setMerchantStore(store);
UUID cartCode = UUID.randomUUID();
shoppingCart.setShoppingCartCode(cartCode.toString());
ShoppingCartItem item = new ShoppingCartItem(shoppingCart, product);
item.setShoppingCart(shoppingCart);
FinalPrice price = pricingService.calculateProductPrice(product);
item.setItemPrice(price.getFinalPrice());
item.setQuantity(1);
/**
* user selects black *
*/
ShoppingCartAttributeItem attributeItem = new ShoppingCartAttributeItem(item, blackAttribute);
item.getAttributes().add(attributeItem);
shoppingCart.getLineItems().add(item);
// create cart
shoppingCartService.create(shoppingCart);
/**
* Retrieve cart *
*/
ShoppingCart retrievedCart = shoppingCartService.getByCode(cartCode.toString(), store);
Assert.assertNotNull(retrievedCart);
/**
* Delete cart *
*/
shoppingCartService.delete(retrievedCart);
/**
* Check if cart has been deleted *
*/
retrievedCart = shoppingCartService.getByCode(cartCode.toString(), store);
Assert.assertNull(retrievedCart);
// Clean up for other tests
categoryService.delete(shirts);
}
Aggregations