use of com.salesmanager.core.model.catalog.product.attribute.ProductAttribute in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method updateCartItem.
@Override
public ShoppingCartData updateCartItem(final Long itemID, final String cartId, final long newQuantity, final MerchantStore store, final Language language) throws Exception {
if (newQuantity < 1) {
throw new CartModificationException("Quantity must not be less than one");
}
if (StringUtils.isNotBlank(cartId)) {
ShoppingCart cartModel = getCartModel(cartId, store);
if (cartModel != null) {
com.salesmanager.core.model.shoppingcart.ShoppingCartItem entryToUpdate = getEntryToUpdate(itemID.longValue(), cartModel);
if (entryToUpdate == null) {
throw new CartModificationException("Unknown entry number.");
}
entryToUpdate.getProduct();
LOG.info("Updating cart entry quantity to" + newQuantity);
entryToUpdate.setQuantity((int) newQuantity);
List<ProductAttribute> productAttributes = new ArrayList<ProductAttribute>();
productAttributes.addAll(entryToUpdate.getProduct().getAttributes());
final FinalPrice finalPrice = productPriceUtils.getFinalProductPrice(entryToUpdate.getProduct(), productAttributes);
entryToUpdate.setItemPrice(finalPrice.getFinalPrice());
shoppingCartService.saveOrUpdate(cartModel);
LOG.info("Cart entry updated with desired quantity");
ShoppingCartDataPopulator shoppingCartDataPopulator = new ShoppingCartDataPopulator();
shoppingCartDataPopulator.setShoppingCartCalculationService(shoppingCartCalculationService);
shoppingCartDataPopulator.setPricingService(pricingService);
shoppingCartDataPopulator.setimageUtils(imageUtils);
return shoppingCartDataPopulator.populate(cartModel, store, language);
}
}
return null;
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductAttribute in project shopizer by shopizer-ecommerce.
the class ProductOptionServiceImpl method delete.
@Override
public void delete(ProductOption entity) throws ServiceException {
// remove all attributes having this option
List<ProductAttribute> attributes = productAttributeService.getByOptionId(entity.getMerchantStore(), entity.getId());
for (ProductAttribute attribute : attributes) {
productAttributeService.delete(attribute);
}
ProductOption option = this.getById(entity.getId());
// remove option
super.delete(option);
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductAttribute in project shopizer by shopizer-ecommerce.
the class ProductOptionValueServiceImpl method delete.
public void delete(ProductOptionValue entity) throws ServiceException {
// remove all attributes having this option
List<ProductAttribute> attributes = productAttributeService.getByOptionValueId(entity.getMerchantStore(), entity.getId());
for (ProductAttribute attribute : attributes) {
productAttributeService.delete(attribute);
}
ProductOptionValue option = getById(entity.getId());
// remove option
super.delete(option);
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductAttribute in project shopizer by shopizer-ecommerce.
the class ShoppingCartModelPopulator method createCartItem.
private com.salesmanager.core.model.shoppingcart.ShoppingCartItem createCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCart cart, ShoppingCartItem shoppingCartItem, MerchantStore store) throws Exception {
Product product = productService.getById(shoppingCartItem.getProductId());
if (product == null) {
throw new Exception("Item with id " + shoppingCartItem.getProductId() + " does not exist");
}
if (product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new Exception("Item with id " + shoppingCartItem.getProductId() + " does not belong to merchant " + store.getId());
}
com.salesmanager.core.model.shoppingcart.ShoppingCartItem item = new com.salesmanager.core.model.shoppingcart.ShoppingCartItem(cart, product);
item.setQuantity(shoppingCartItem.getQuantity());
item.setItemPrice(shoppingCartItem.getProductPrice());
item.setShoppingCart(cart);
// attributes
List<ShoppingCartAttribute> cartAttributes = shoppingCartItem.getShoppingCartAttributes();
if (!CollectionUtils.isEmpty(cartAttributes)) {
Set<com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem> newAttributes = new HashSet<com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem>();
for (ShoppingCartAttribute attribute : cartAttributes) {
ProductAttribute productAttribute = productAttributeService.getById(attribute.getAttributeId());
if (productAttribute != null && productAttribute.getProduct().getId().longValue() == product.getId().longValue()) {
com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem attributeItem = new com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem(item, productAttribute);
if (attribute.getAttributeId() > 0) {
attributeItem.setId(attribute.getId());
}
item.addAttributes(attributeItem);
// newAttributes.add( attributeItem );
}
}
// item.setAttributes( newAttributes );
}
return item;
}
use of com.salesmanager.core.model.catalog.product.attribute.ProductAttribute in project shopizer by shopizer-ecommerce.
the class PackingBox method getItemPackagesDetails.
@Override
public List<PackageDetails> getItemPackagesDetails(List<ShippingProduct> products, MerchantStore store) throws ServiceException {
List<PackageDetails> packages = new ArrayList<PackageDetails>();
for (ShippingProduct shippingProduct : products) {
Product product = shippingProduct.getProduct();
if (product.isProductVirtual()) {
continue;
}
// BigDecimal weight = product.getProductWeight();
Set<ProductAttribute> attributes = product.getAttributes();
// set attributes values
BigDecimal w = product.getProductWeight();
BigDecimal h = product.getProductHeight();
BigDecimal l = product.getProductLength();
BigDecimal wd = product.getProductWidth();
if (w == null) {
w = new BigDecimal(defaultWeight);
}
if (h == null) {
h = new BigDecimal(defaultHeight);
}
if (l == null) {
l = new BigDecimal(defaultLength);
}
if (wd == null) {
wd = new BigDecimal(defaultWidth);
}
if (attributes != null && attributes.size() > 0) {
for (ProductAttribute attribute : attributes) {
if (attribute.getAttributeAdditionalWeight() != null && attribute.getProductAttributeWeight() != null) {
w = w.add(attribute.getProductAttributeWeight());
}
}
}
if (shippingProduct.getQuantity() == 1) {
PackageDetails detail = new PackageDetails();
detail.setShippingHeight(h.doubleValue());
detail.setShippingLength(l.doubleValue());
detail.setShippingWeight(w.doubleValue());
detail.setShippingWidth(wd.doubleValue());
detail.setShippingQuantity(shippingProduct.getQuantity());
String description = "item";
if (product.getDescriptions().size() > 0) {
description = product.getDescriptions().iterator().next().getName();
}
detail.setItemName(description);
packages.add(detail);
} else if (shippingProduct.getQuantity() > 1) {
for (int i = 0; i < shippingProduct.getQuantity(); i++) {
PackageDetails detail = new PackageDetails();
detail.setShippingHeight(h.doubleValue());
detail.setShippingLength(l.doubleValue());
detail.setShippingWeight(w.doubleValue());
detail.setShippingWidth(wd.doubleValue());
// issue seperate shipping
detail.setShippingQuantity(1);
String description = "item";
if (product.getDescriptions().size() > 0) {
description = product.getDescriptions().iterator().next().getName();
}
detail.setItemName(description);
packages.add(detail);
}
}
}
return packages;
}
Aggregations