Search in sources :

Example 16 with ProductAttribute

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;
}
Also used : CartModificationException(com.salesmanager.shop.model.shoppingcart.CartModificationException) ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ShoppingCartDataPopulator(com.salesmanager.shop.populator.shoppingCart.ShoppingCartDataPopulator) ArrayList(java.util.ArrayList) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice)

Example 17 with ProductAttribute

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);
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)

Example 18 with ProductAttribute

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);
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)

Example 19 with ProductAttribute

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;
}
Also used : Product(com.salesmanager.core.model.catalog.product.Product) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) ConversionException(org.apache.commons.beanutils.ConversionException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ShoppingCartAttribute(com.salesmanager.shop.model.shoppingcart.ShoppingCartAttribute) ShoppingCartItem(com.salesmanager.shop.model.shoppingcart.ShoppingCartItem) HashSet(java.util.HashSet)

Example 20 with ProductAttribute

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;
}
Also used : ArrayList(java.util.ArrayList) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) Product(com.salesmanager.core.model.catalog.product.Product) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails) BigDecimal(java.math.BigDecimal)

Aggregations

ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)41 Product (com.salesmanager.core.model.catalog.product.Product)25 ArrayList (java.util.ArrayList)20 Language (com.salesmanager.core.model.reference.language.Language)18 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)16 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)15 ServiceException (com.salesmanager.core.business.exception.ServiceException)13 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)12 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)12 BigDecimal (java.math.BigDecimal)12 HashSet (java.util.HashSet)12 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)11 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)11 List (java.util.List)11 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)10 Date (java.util.Date)10 Category (com.salesmanager.core.model.catalog.category.Category)9 ProductOptionDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription)9 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)9 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)8