use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription in project shopizer by shopizer-ecommerce.
the class ReadableProductPopulator method createProperty.
private ReadableProductProperty createProperty(ProductAttribute productAttribute, Language language) {
ReadableProductProperty attr = new ReadableProductProperty();
// attribute of the option
attr.setId(productAttribute.getProductOption().getId());
attr.setType(productAttribute.getProductOption().getProductOptionType());
List<ProductOptionDescription> descriptions = productAttribute.getProductOption().getDescriptionsSettoList();
ReadableProductPropertyValue propertyValue = new ReadableProductPropertyValue();
if (descriptions != null && descriptions.size() > 0) {
for (ProductOptionDescription optionDescription : descriptions) {
com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription productOptionValueDescription = new com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription();
productOptionValueDescription.setId(optionDescription.getId());
productOptionValueDescription.setLanguage(optionDescription.getLanguage().getCode());
productOptionValueDescription.setName(optionDescription.getName());
propertyValue.getValues().add(productOptionValueDescription);
}
}
attr.setCode(productAttribute.getProductOption().getCode());
return attr;
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription 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.ProductOptionDescription in project shopizer by shopizer-ecommerce.
the class PersistableProductOptionMapper method description.
ProductOptionDescription description(com.salesmanager.shop.model.catalog.product.attribute.ProductOptionDescription description) throws Exception {
Validate.notNull(description.getLanguage(), "description.language should not be null");
ProductOptionDescription desc = new ProductOptionDescription();
desc.setId(null);
desc.setDescription(description.getDescription());
desc.setName(description.getName());
if (description.getId() != null && description.getId().longValue() > 0) {
desc.setId(description.getId());
}
Language lang = languageService.getByCode(description.getLanguage());
desc.setLanguage(lang);
return desc;
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription in project shopizer by shopizer-ecommerce.
the class ReadableProductVariationMapper method option.
private ReadableProductOption option(ProductOption option, Language lang) {
ReadableProductOption opt = new ReadableProductOption();
opt.setCode(option.getCode());
opt.setId(option.getId());
opt.setLang(lang.getCode());
opt.setReadOnly(option.isReadOnly());
opt.setType(option.getProductOptionType());
ProductOptionDescription desc = this.optionDescription(option.getDescriptions(), lang);
if (desc != null) {
opt.setName(desc.getName());
}
return opt;
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription in project shopizer by shopizer-ecommerce.
the class ReadableProductMapper method createProperty.
private ReadableProductProperty createProperty(ProductAttribute productAttribute, Language language) {
ReadableProductProperty attr = new ReadableProductProperty();
// attribute of the option
attr.setId(productAttribute.getProductOption().getId());
attr.setType(productAttribute.getProductOption().getProductOptionType());
List<ProductOptionDescription> descriptions = productAttribute.getProductOption().getDescriptionsSettoList();
ReadableProductPropertyValue propertyValue = new ReadableProductPropertyValue();
if (descriptions != null && descriptions.size() > 0) {
for (ProductOptionDescription optionDescription : descriptions) {
com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription productOptionValueDescription = new com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription();
productOptionValueDescription.setId(optionDescription.getId());
productOptionValueDescription.setLanguage(optionDescription.getLanguage().getCode());
productOptionValueDescription.setName(optionDescription.getName());
propertyValue.getValues().add(productOptionValueDescription);
}
}
attr.setCode(productAttribute.getProductOption().getCode());
return attr;
}
Aggregations