Search in sources :

Example 16 with ProductOptionDescription

use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription in project shopizer by shopizer-ecommerce.

the class ReadableProductMapper method merge.

@Override
public ReadableProduct merge(Product source, ReadableProduct destination, MerchantStore store, Language language) {
    Validate.notNull(source, "Product cannot be null");
    Validate.notNull(destination, "Product destination cannot be null");
    destination.setSku(source.getSku());
    destination.setRefSku(source.getRefSku());
    destination.setId(source.getId());
    destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
    ProductDescription description = null;
    if (source.getDescriptions() != null && source.getDescriptions().size() > 0) {
        for (ProductDescription desc : source.getDescriptions()) {
            if (language != null && desc.getLanguage() != null && desc.getLanguage().getId().intValue() == language.getId().intValue()) {
                description = desc;
                break;
            }
        }
        destination.setId(source.getId());
        destination.setAvailable(source.isAvailable());
        destination.setProductShipeable(source.isProductShipeable());
        ProductSpecification specifications = new ProductSpecification();
        specifications.setHeight(source.getProductHeight());
        specifications.setLength(source.getProductLength());
        specifications.setWeight(source.getProductWeight());
        specifications.setWidth(source.getProductWidth());
        destination.setProductSpecifications(specifications);
        destination.setPreOrder(source.isPreOrder());
        destination.setRefSku(source.getRefSku());
        destination.setSortOrder(source.getSortOrder());
        if (source.getType() != null) {
            ReadableProductType readableType = readableProductTypeMapper.convert(source.getType(), store, language);
            destination.setType(readableType);
        }
        if (source.getDateAvailable() != null) {
            destination.setDateAvailable(DateUtil.formatDate(source.getDateAvailable()));
        }
        if (source.getAuditSection() != null) {
            destination.setCreationDate(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
        }
        destination.setProductVirtual(source.getProductVirtual());
        if (source.getProductReviewCount() != null) {
            destination.setRatingCount(source.getProductReviewCount().intValue());
        }
        if (source.getManufacturer() != null) {
            ReadableManufacturer manufacturer = readableManufacturerMapper.convert(source.getManufacturer(), store, language);
            destination.setManufacturer(manufacturer);
        }
        // images
        Set<ProductImage> images = source.getImages();
        if (CollectionUtils.isNotEmpty(images)) {
            List<ReadableImage> imageList = images.stream().map(i -> this.convertImage(source, i, store)).collect(Collectors.toList());
            destination.setImages(imageList);
        }
        // read only product values
        if (!CollectionUtils.isEmpty(source.getAttributes())) {
            Set<ProductAttribute> attributes = source.getAttributes();
            // split read only and options
            // Map<Long,ReadableProductAttribute> readOnlyAttributes = null;
            Map<Long, ReadableProductProperty> properties = null;
            Map<Long, ReadableProductOption> selectableOptions = null;
            if (!CollectionUtils.isEmpty(attributes)) {
                for (ProductAttribute attribute : attributes) {
                    ReadableProductOption opt = null;
                    ReadableProductAttribute attr = null;
                    ReadableProductProperty property = null;
                    ReadableProductPropertyValue propertyValue = null;
                    ReadableProductOptionValueEntity optValue = new ReadableProductOptionValueEntity();
                    ReadableProductAttributeValue attrValue = new ReadableProductAttributeValue();
                    ProductOptionValue optionValue = attribute.getProductOptionValue();
                    // we need to set readonly attributes only
                    if (attribute.getAttributeDisplayOnly()) {
                        // read only attribute = property
                        property = createProperty(attribute, language);
                        // that is the property
                        ReadableProductOption readableOption = new ReadableProductOption();
                        ReadableProductPropertyValue readableOptionValue = new ReadableProductPropertyValue();
                        readableOption.setCode(attribute.getProductOption().getCode());
                        readableOption.setId(attribute.getProductOption().getId());
                        Set<ProductOptionDescription> podescriptions = attribute.getProductOption().getDescriptions();
                        if (podescriptions != null && podescriptions.size() > 0) {
                            for (ProductOptionDescription optionDescription : podescriptions) {
                                if (optionDescription.getLanguage().getCode().equals(language.getCode())) {
                                    readableOption.setName(optionDescription.getName());
                                }
                            }
                        }
                        property.setProperty(readableOption);
                        Set<ProductOptionValueDescription> povdescriptions = attribute.getProductOptionValue().getDescriptions();
                        readableOptionValue.setId(attribute.getProductOptionValue().getId());
                        if (povdescriptions != null && povdescriptions.size() > 0) {
                            for (ProductOptionValueDescription optionValueDescription : povdescriptions) {
                                if (optionValueDescription.getLanguage().getCode().equals(language.getCode())) {
                                    readableOptionValue.setName(optionValueDescription.getName());
                                }
                            }
                        }
                        property.setPropertyValue(readableOptionValue);
                        destination.getProperties().add(property);
                    }
                    if (selectableOptions != null) {
                        List<ReadableProductOption> options = new ArrayList<ReadableProductOption>(selectableOptions.values());
                        destination.setOptions(options);
                    }
                }
            }
        }
    }
    // availability
    ProductAvailability availability = null;
    for (ProductAvailability a : source.getAvailabilities()) {
        // TODO validate region
        // if(availability.getRegion().equals(Constants.ALL_REGIONS)) {//TODO REL 2.1
        // accept a region
        availability = a;
        destination.setQuantity(availability.getProductQuantity() == null ? 1 : availability.getProductQuantity());
        destination.setQuantityOrderMaximum(availability.getProductQuantityOrderMax() == null ? 1 : availability.getProductQuantityOrderMax());
        destination.setQuantityOrderMinimum(availability.getProductQuantityOrderMin() == null ? 1 : availability.getProductQuantityOrderMin());
        if (availability.getProductQuantity().intValue() > 0 && destination.isAvailable()) {
            destination.setCanBePurchased(true);
        }
    // }
    }
    destination.setSku(source.getSku());
    try {
        FinalPrice price = pricingService.calculateProductPrice(source);
        if (price != null) {
            destination.setFinalPrice(pricingService.getDisplayAmount(price.getFinalPrice(), store));
            destination.setPrice(price.getFinalPrice());
            destination.setOriginalPrice(pricingService.getDisplayAmount(price.getOriginalPrice(), store));
            if (price.isDiscounted()) {
                destination.setDiscounted(true);
            }
            // price appender
            if (availability != null) {
                Set<ProductPrice> prices = availability.getPrices();
                if (!CollectionUtils.isEmpty(prices)) {
                    ReadableProductPrice readableProductPrice = new ReadableProductPrice();
                    readableProductPrice.setDiscounted(destination.isDiscounted());
                    readableProductPrice.setFinalPrice(destination.getFinalPrice());
                    readableProductPrice.setOriginalPrice(destination.getOriginalPrice());
                    Optional<ProductPrice> pr = prices.stream().filter(p -> p.getCode().equals(ProductPrice.DEFAULT_PRICE_CODE)).findFirst();
                    destination.setProductPrice(readableProductPrice);
                    if (pr.isPresent()) {
                        readableProductPrice.setId(pr.get().getId());
                        Optional<ProductPriceDescription> d = pr.get().getDescriptions().stream().filter(desc -> desc.getLanguage().getCode().equals(language.getCode())).findFirst();
                        if (d.isPresent()) {
                            com.salesmanager.shop.model.catalog.product.ProductPriceDescription priceDescription = new com.salesmanager.shop.model.catalog.product.ProductPriceDescription();
                            priceDescription.setLanguage(language.getCode());
                            priceDescription.setId(d.get().getId());
                            priceDescription.setPriceAppender(d.get().getPriceAppender());
                            readableProductPrice.setDescription(priceDescription);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new ConversionRuntimeException("An error while converting product price", e);
    }
    if (source.getProductReviewAvg() != null) {
        double avg = source.getProductReviewAvg().doubleValue();
        double rating = Math.round(avg * 2) / 2.0f;
        destination.setRating(rating);
    }
    if (source.getProductReviewCount() != null) {
        destination.setRatingCount(source.getProductReviewCount().intValue());
    }
    if (description != null) {
        com.salesmanager.shop.model.catalog.product.ProductDescription tragetDescription = populateDescription(description);
        destination.setDescription(tragetDescription);
    }
    if (!CollectionUtils.isEmpty(source.getCategories())) {
        List<ReadableCategory> categoryList = new ArrayList<ReadableCategory>();
        for (Category category : source.getCategories()) {
            ReadableCategory readableCategory = readableCategoryMapper.convert(category, store, language);
            categoryList.add(readableCategory);
        }
        destination.setCategories(categoryList);
    }
    ProductSpecification specifications = new ProductSpecification();
    specifications.setHeight(source.getProductHeight());
    specifications.setLength(source.getProductLength());
    specifications.setWeight(source.getProductWeight());
    specifications.setWidth(source.getProductWidth());
    if (!StringUtils.isBlank(store.getSeizeunitcode())) {
        specifications.setDimensionUnitOfMeasure(DimensionUnitOfMeasure.valueOf(store.getSeizeunitcode().toLowerCase()));
    }
    if (!StringUtils.isBlank(store.getWeightunitcode())) {
        specifications.setWeightUnitOfMeasure(WeightUnitOfMeasure.valueOf(store.getWeightunitcode().toLowerCase()));
    }
    destination.setProductSpecifications(specifications);
    destination.setSortOrder(source.getSortOrder());
    return destination;
}
Also used : ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) DateUtil(com.salesmanager.shop.utils.DateUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ReadableProductAttributeValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttributeValue) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) DimensionUnitOfMeasure(com.salesmanager.shop.model.references.DimensionUnitOfMeasure) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Mapper(com.salesmanager.shop.mapper.Mapper) Product(com.salesmanager.core.model.catalog.product.Product) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) Set(java.util.Set) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Collectors(java.util.stream.Collectors) Category(com.salesmanager.core.model.catalog.category.Category) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) List(java.util.List) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) Optional(java.util.Optional) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ReadableProductPropertyValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductPropertyValue) ReadableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttribute) ReadableProductProperty(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductProperty) WeightUnitOfMeasure(com.salesmanager.shop.model.references.WeightUnitOfMeasure) ReadableProductOption(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductOption) ArrayList(java.util.ArrayList) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ReadableImage(com.salesmanager.shop.model.catalog.product.ReadableImage) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ReadableProductAttributeValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttributeValue) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableProductProperty(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductProperty) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) ReadableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttribute) Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) ReadableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductAttribute) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ProductSpecification(com.salesmanager.shop.model.catalog.product.ProductSpecification) ReadableProductPropertyValue(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductPropertyValue) ReadableProductOption(com.salesmanager.shop.model.catalog.product.attribute.ReadableProductOption) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType)

Example 17 with ProductOptionDescription

use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription 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));
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) Customer(com.salesmanager.core.model.customer.Customer) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) OrderProductPrice(com.salesmanager.core.model.order.orderproduct.OrderProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Currency(com.salesmanager.core.model.reference.currency.Currency) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) HashSet(java.util.HashSet) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) Order(com.salesmanager.core.model.order.Order) Zone(com.salesmanager.core.model.reference.zone.Zone) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) OrderCriteria(com.salesmanager.core.model.order.OrderCriteria) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) Billing(com.salesmanager.core.model.common.Billing) OrderProductPrice(com.salesmanager.core.model.order.orderproduct.OrderProductPrice) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) Country(com.salesmanager.core.model.reference.country.Country) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) Delivery(com.salesmanager.core.model.common.Delivery) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) OrderList(com.salesmanager.core.model.order.OrderList) OrderTotal(com.salesmanager.core.model.order.OrderTotal) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Test(org.junit.Test)

Example 18 with ProductOptionDescription

use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription 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);
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) Product(com.salesmanager.core.model.catalog.product.Product) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) ShoppingCartAttributeItem(com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) UUID(java.util.UUID) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) HashSet(java.util.HashSet) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) BigDecimal(java.math.BigDecimal) Date(java.util.Date) ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Test(org.junit.Test)

Example 19 with ProductOptionDescription

use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription in project shopizer by shopizer-ecommerce.

the class CatalogServiceHelper method setToLanguage.

/**
 * Filters descriptions and set the appropriate language
 * @param p
 * @param language
 */
public static void setToLanguage(Product p, int language) {
    Set<ProductAttribute> attributes = p.getAttributes();
    if (attributes != null) {
        for (ProductAttribute attribute : attributes) {
            ProductOption po = attribute.getProductOption();
            Set<ProductOptionDescription> spod = po.getDescriptions();
            if (spod != null) {
                Set<ProductOptionDescription> podDescriptions = new HashSet<ProductOptionDescription>();
                for (ProductOptionDescription pod : spod) {
                    // System.out.println("    ProductOptionDescription : " + pod.getProductOptionName());
                    if (pod.getLanguage().getId() == language) {
                        podDescriptions.add(pod);
                    }
                }
                po.setDescriptions(podDescriptions);
            }
            ProductOptionValue pov = attribute.getProductOptionValue();
            Set<ProductOptionValueDescription> spovd = pov.getDescriptions();
            if (spovd != null) {
                Set<ProductOptionValueDescription> povdDescriptions = new HashSet<>();
                for (ProductOptionValueDescription povd : spovd) {
                    if (povd.getLanguage().getId() == language) {
                        povdDescriptions.add(povd);
                    }
                }
                pov.setDescriptions(povdDescriptions);
            }
        }
    }
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) HashSet(java.util.HashSet) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)

Example 20 with ProductOptionDescription

use of com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription in project shopizer by shopizer-ecommerce.

the class ShopProductController method createAttribute.

private Attribute createAttribute(ProductAttribute productAttribute, Language language) {
    Attribute attribute = new Attribute();
    // attribute of the option
    attribute.setId(productAttribute.getProductOption().getId());
    attribute.setType(productAttribute.getProductOption().getProductOptionType());
    List<ProductOptionDescription> descriptions = productAttribute.getProductOption().getDescriptionsSettoList();
    ProductOptionDescription description = null;
    if (descriptions != null && descriptions.size() > 0) {
        description = descriptions.get(0);
        if (descriptions.size() > 1) {
            for (ProductOptionDescription optionDescription : descriptions) {
                if (optionDescription.getLanguage().getId().intValue() == language.getId().intValue()) {
                    description = optionDescription;
                    break;
                }
            }
        }
    }
    if (description == null) {
        return null;
    }
    attribute.setType(productAttribute.getProductOption().getProductOptionType());
    attribute.setLanguage(language.getCode());
    attribute.setName(description.getName());
    attribute.setCode(productAttribute.getProductOption().getCode());
    return attribute;
}
Also used : ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Attribute(com.salesmanager.shop.store.model.catalog.Attribute)

Aggregations

ProductOptionDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription)20 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)12 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)9 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)8 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)8 Language (com.salesmanager.core.model.reference.language.Language)8 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)7 ArrayList (java.util.ArrayList)6 Category (com.salesmanager.core.model.catalog.category.Category)5 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)5 ReadableProductOption (com.salesmanager.shop.model.catalog.product.attribute.ReadableProductOption)5 Product (com.salesmanager.core.model.catalog.product.Product)4 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)4 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)4 ProductPriceDescription (com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)4 ReadableProductProperty (com.salesmanager.shop.model.catalog.product.attribute.ReadableProductProperty)4 ReadableProductPropertyValue (com.salesmanager.shop.model.catalog.product.attribute.ReadableProductPropertyValue)4 BigDecimal (java.math.BigDecimal)4 ProductImage (com.salesmanager.core.model.catalog.product.image.ProductImage)3 ManufacturerDescription (com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription)3