Search in sources :

Example 11 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer in project shopizer by shopizer-ecommerce.

the class ManufacturerFacadeImpl method manufacturerExist.

@Override
public boolean manufacturerExist(MerchantStore store, String manufacturerCode) {
    Validate.notNull(store, "Store must not be null");
    Validate.notNull(manufacturerCode, "Manufacturer code must not be null");
    boolean exists = false;
    Manufacturer manufacturer = manufacturerService.getByCode(store, manufacturerCode);
    if (manufacturer != null) {
        exists = true;
    }
    return exists;
}
Also used : Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)

Example 12 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer in project shopizer by shopizer-ecommerce.

the class PersistableProductDefinitionMapper method merge.

@Override
public Product merge(PersistableProductDefinition source, Product destination, MerchantStore store, Language language) {
    Validate.notNull(destination, "Product must not be null");
    try {
        // core properties
        destination.setSku(source.getIdentifier());
        destination.setAvailable(source.isVisible());
        destination.setDateAvailable(new Date());
        destination.setRefSku(source.getIdentifier());
        if (source.getId() != null && source.getId().longValue() == 0) {
            destination.setId(null);
        } else {
            destination.setId(source.getId());
        }
        // MANUFACTURER
        if (!StringUtils.isBlank(source.getManufacturer())) {
            Manufacturer manufacturer = manufacturerService.getByCode(store, source.getManufacturer());
            if (manufacturer == null) {
                throw new ConversionException("Manufacturer [" + source.getManufacturer() + "] does not exist");
            }
            destination.setManufacturer(manufacturer);
        }
        // PRODUCT TYPE
        if (!StringUtils.isBlank(source.getType())) {
            ProductType type = productTypeService.getByCode(source.getType(), store, language);
            if (type == null) {
                throw new ConversionException("Product type [" + source.getType() + "] does not exist");
            }
            destination.setType(type);
        }
        if (!StringUtils.isBlank(source.getDateAvailable())) {
            destination.setDateAvailable(DateUtil.getDate(source.getDateAvailable()));
        }
        destination.setMerchantStore(store);
        List<Language> languages = new ArrayList<Language>();
        Set<ProductDescription> descriptions = new HashSet<ProductDescription>();
        if (!CollectionUtils.isEmpty(source.getDescriptions())) {
            for (com.salesmanager.shop.model.catalog.product.ProductDescription description : source.getDescriptions()) {
                ProductDescription productDescription = new ProductDescription();
                Language lang = languageService.getByCode(description.getLanguage());
                if (lang == null) {
                    throw new ConversionException("Language code " + description.getLanguage() + " is invalid, use ISO code (en, fr ...)");
                }
                if (!CollectionUtils.isEmpty(destination.getDescriptions())) {
                    for (ProductDescription desc : destination.getDescriptions()) {
                        if (desc.getLanguage().getCode().equals(description.getLanguage())) {
                            productDescription = desc;
                            break;
                        }
                    }
                }
                productDescription.setProduct(destination);
                productDescription.setDescription(description.getDescription());
                productDescription.setProductHighlight(description.getHighlights());
                productDescription.setName(description.getName());
                productDescription.setSeUrl(description.getFriendlyUrl());
                productDescription.setMetatagKeywords(description.getKeyWords());
                productDescription.setMetatagDescription(description.getMetaDescription());
                productDescription.setTitle(description.getTitle());
                languages.add(lang);
                productDescription.setLanguage(lang);
                descriptions.add(productDescription);
            }
        }
        if (descriptions.size() > 0) {
            destination.setDescriptions(descriptions);
        }
        // if(source.getRating() != null) {
        // destination.setProductReviewAvg(new BigDecimal(source.getRating()));
        // }
        // destination.setProductReviewCount(source.getRatingCount());
        /**
         * Product definition
         */
        ProductAvailability productAvailability = null;
        ProductPrice defaultPrice = null;
        if (!CollectionUtils.isEmpty(destination.getAvailabilities())) {
            for (ProductAvailability avail : destination.getAvailabilities()) {
                Set<ProductPrice> prices = avail.getPrices();
                for (ProductPrice p : prices) {
                    if (p.isDefaultPrice()) {
                        if (productAvailability == null) {
                            productAvailability = avail;
                            defaultPrice = p;
                            productAvailability.setProductQuantity(source.getQuantity());
                            productAvailability.setProductStatus(source.isCanBePurchased());
                            p.setProductPriceAmount(source.getPrice());
                            break;
                        }
                    }
                }
            }
        }
        if (productAvailability == null) {
            // create with default values
            productAvailability = new ProductAvailability(destination, store);
            destination.getAvailabilities().add(productAvailability);
            productAvailability.setProductQuantity(source.getQuantity());
            productAvailability.setProductQuantityOrderMin(1);
            productAvailability.setProductQuantityOrderMax(1);
            productAvailability.setRegion(Constants.ALL_REGIONS);
            productAvailability.setAvailable(Boolean.valueOf(destination.isAvailable()));
            productAvailability.setProductStatus(source.isCanBePurchased());
        }
        if (defaultPrice == null) {
            BigDecimal defaultPriceAmount = new BigDecimal(0);
            if (source.getPrice() != null) {
                defaultPriceAmount = source.getPrice();
            }
            defaultPrice = new ProductPrice();
            defaultPrice.setDefaultPrice(true);
            defaultPrice.setProductPriceAmount(defaultPriceAmount);
            defaultPrice.setCode(ProductPriceEntity.DEFAULT_PRICE_CODE);
            defaultPrice.setProductAvailability(productAvailability);
            productAvailability.getPrices().add(defaultPrice);
            for (Language lang : languages) {
                ProductPriceDescription ppd = new ProductPriceDescription();
                ppd.setProductPrice(defaultPrice);
                ppd.setLanguage(lang);
                ppd.setName(ProductPriceDescription.DEFAULT_PRICE_DESCRIPTION);
                defaultPrice.getDescriptions().add(ppd);
            }
        }
        if (source.getProductSpecifications() != null) {
            destination.setProductHeight(source.getProductSpecifications().getHeight());
            destination.setProductLength(source.getProductSpecifications().getLength());
            destination.setProductWeight(source.getProductSpecifications().getWeight());
            destination.setProductWidth(source.getProductSpecifications().getWidth());
            if (source.getProductSpecifications().getManufacturer() != null) {
                Manufacturer manuf = null;
                if (!StringUtils.isBlank(source.getProductSpecifications().getManufacturer())) {
                    manuf = manufacturerService.getByCode(store, source.getProductSpecifications().getManufacturer());
                }
                if (manuf == null) {
                    throw new ConversionException("Invalid manufacturer id");
                }
                if (manuf != null) {
                    if (manuf.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                        throw new ConversionException("Invalid manufacturer id");
                    }
                    destination.setManufacturer(manuf);
                }
            }
        }
        destination.setSortOrder(source.getSortOrder());
        destination.setProductVirtual(source.isVirtual());
        destination.setProductShipeable(source.isShipeable());
        // attributes
        if (source.getProperties() != null) {
            for (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute attr : source.getProperties()) {
                ProductAttribute attribute = persistableProductAttributeMapper.convert(attr, store, language);
                attribute.setProduct(destination);
                destination.getAttributes().add(attribute);
            }
        }
        // categories
        if (!CollectionUtils.isEmpty(source.getCategories())) {
            for (com.salesmanager.shop.model.catalog.category.Category categ : source.getCategories()) {
                Category c = null;
                if (!StringUtils.isBlank(categ.getCode())) {
                    c = categoryService.getByCode(store, categ.getCode());
                } else {
                    Validate.notNull(categ.getId(), "Category id nust not be null");
                    c = categoryService.getById(categ.getId(), store.getId());
                }
                if (c == null) {
                    throw new ConversionException("Category id " + categ.getId() + " does not exist");
                }
                if (c.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Invalid category id");
                }
                destination.getCategories().add(c);
            }
        }
        return destination;
    } catch (Exception e) {
        throw new ConversionRuntimeException("Error converting product mapper", e);
    }
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ArrayList(java.util.ArrayList) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) 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) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) HashSet(java.util.HashSet) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) Date(java.util.Date) BigDecimal(java.math.BigDecimal) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription)

Example 13 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer 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 14 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer in project shopizer by shopizer-ecommerce.

the class ManufacturerTest method testManufacturer.

/**
 * This method creates multiple products using multiple catalog APIs
 * @throws ServiceException
 */
@Test
public void testManufacturer() throws Exception {
    Language en = languageService.getByCode("en");
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    Manufacturer oreilley = new Manufacturer();
    oreilley.setMerchantStore(store);
    oreilley.setCode("oreilley2");
    ManufacturerDescription oreilleyd = new ManufacturerDescription();
    oreilleyd.setLanguage(en);
    oreilleyd.setName("O\'reilley");
    oreilleyd.setManufacturer(oreilley);
    oreilley.getDescriptions().add(oreilleyd);
    manufacturerService.create(oreilley);
    Manufacturer packed = new Manufacturer();
    packed.setMerchantStore(store);
    packed.setCode("packed2");
    ManufacturerDescription packedd = new ManufacturerDescription();
    packedd.setLanguage(en);
    packedd.setManufacturer(packed);
    packedd.setName("Packed publishing");
    packed.getDescriptions().add(packedd);
    manufacturerService.create(packed);
    Manufacturer novells = new Manufacturer();
    novells.setMerchantStore(store);
    novells.setCode("novells2");
    ManufacturerDescription novellsd = new ManufacturerDescription();
    novellsd.setLanguage(en);
    novellsd.setManufacturer(novells);
    novellsd.setName("Novells publishing");
    novells.getDescriptions().add(novellsd);
    manufacturerService.create(novells);
    // query pageable category
    Page<Manufacturer> pageable = manufacturerService.listByStore(store, en, 0, 5);
    Assert.isTrue(pageable.getSize() > 0, "4 manufacturers");
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Test(org.junit.Test)

Example 15 with Manufacturer

use of com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer in project shopizer by shopizer-ecommerce.

the class ProductNextGenTest method testCreateProduct.

/**
 * This method creates single product with variants using multiple catalog APIs
 * @throws ServiceException
 */
@Test
public void testCreateProduct() throws Exception {
    Language en = languageService.getByCode("en");
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
    /**
     * Category
     */
    Category shoes = new Category();
    shoes.setMerchantStore(store);
    shoes.setCode("shoes");
    CategoryDescription shoesDescription = new CategoryDescription();
    shoesDescription.setName("Shoes");
    shoesDescription.setCategory(shoes);
    shoesDescription.setLanguage(en);
    Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
    descriptions.add(shoesDescription);
    shoes.setDescriptions(descriptions);
    categoryService.create(shoes);
    // 
    /**
     * Manufacturer / Brand
     */
    Manufacturer brown = new Manufacturer();
    brown.setMerchantStore(store);
    brown.setCode("brown");
    ManufacturerDescription brownd = new ManufacturerDescription();
    brownd.setLanguage(en);
    brownd.setName("Brown's");
    brownd.setManufacturer(brown);
    brown.getDescriptions().add(brownd);
    manufacturerService.create(brown);
    // 
    // PRODUCT
    // -- non variable informations
    Product summerShoes = new Product();
    summerShoes.setProductHeight(new BigDecimal(3));
    // average
    summerShoes.setProductLength(new BigDecimal(9));
    summerShoes.setProductWidth(new BigDecimal(4));
    summerShoes.setSku("BR12345");
    summerShoes.setManufacturer(brown);
    summerShoes.setType(generalType);
    summerShoes.setMerchantStore(store);
    // is available
    summerShoes.setAvailable(true);
    // Product description
    ProductDescription description = new ProductDescription();
    description.setName("Summer shoes");
    description.setLanguage(en);
    description.setProduct(summerShoes);
    summerShoes.getDescriptions().add(description);
    // add product to shoes category
    summerShoes.getCategories().add(shoes);
    // -- end non variable informations
    // --- add attributes to the product (size)
    createOptions(summerShoes);
    // --- options set
    /**
     * Option Set facilitates product attributes creation for redundant product creation
     * it offers a list of possible options and options values administrator can create in order
     * to easily create attributes
     */
    createOptionsSet(store);
    // --- create attributes (available options)
    /**
     * Add options to product
     * Those are attributes
     */
    ProductAttribute size_nine = new ProductAttribute();
    size_nine.setProduct(summerShoes);
    size_nine.setProductOption(size);
    size_nine.setAttributeDefault(true);
    // no price variation
    size_nine.setProductAttributePrice(new BigDecimal(0));
    // no weight variation
    size_nine.setProductAttributeWeight(new BigDecimal(0));
    size_nine.setProductOptionValue(nine);
    summerShoes.getAttributes().add(size_nine);
    ProductAttribute size_nine_half = new ProductAttribute();
    size_nine_half.setProduct(summerShoes);
    size_nine_half.setProductOption(size);
    // no price variation
    size_nine_half.setProductAttributePrice(new BigDecimal(0));
    // weight variation
    size_nine_half.setProductAttributeWeight(new BigDecimal(0));
    size_nine_half.setProductOptionValue(nineHalf);
    summerShoes.getAttributes().add(size_nine_half);
    ProductAttribute size_ten = new ProductAttribute();
    size_ten.setProduct(summerShoes);
    size_ten.setProductOption(size);
    // no price variation
    size_ten.setProductAttributePrice(new BigDecimal(0));
    // weight variation
    size_ten.setProductAttributeWeight(new BigDecimal(0));
    size_ten.setProductOptionValue(ten);
    summerShoes.getAttributes().add(size_ten);
    // ---- variable informations - inventory - variants - prices
    ProductAvailability availability = createInventory(store, 100, new BigDecimal("99.99"));
    summerShoes.getAvailabilities().add(availability);
    // ---- add available sizes
    // DEFAULT (total quantity of 100 distributed)
    // TODO use pre 3.0 variation
    // 40 of 9
    /*	    ProductVariant size_nine_DEFAULT = new ProductVariant();
	    size_nine_DEFAULT.setAttribute(size_nine);
	    size_nine_DEFAULT.setProductQuantity(40);
	    size_nine_DEFAULT.setProductAvailability(availability);*/
    // availability.getVariants().add(size_nine_DEFAULT);
    // 30 of 9.5
    /*	    ProductVariant size_nine_half_DEFAULT = new ProductVariant();
	    size_nine_half_DEFAULT.setAttribute(size_nine_half);
	    size_nine_half_DEFAULT.setProductQuantity(30);
	    size_nine_half_DEFAULT.setProductAvailability(availability);*/
    // availability.getVariants().add(size_nine_half_DEFAULT);
    // 30 of ten
    /*	    ProductVariant size_ten_DEFAULT = new ProductVariant();
	    size_ten_DEFAULT.setAttribute(size_nine_half);
	    size_ten_DEFAULT.setProductQuantity(30);
	    size_ten_DEFAULT.setProductAvailability(availability);*/
    // availability.getVariants().add(size_ten_DEFAULT);
    // inventory for store DEFAULT and product summerShoes
    availability.setProduct(summerShoes);
    availability.setMerchantStore(store);
    /**
     * Create product
     */
    productService.create(summerShoes);
    // ObjectMapper mapper = new ObjectMapper();
    // Converting the Object to JSONString
    // String jsonString = mapper.writeValueAsString(summerShoes);
    // System.out.println(jsonString);
    Product p = productService.getById(summerShoes.getId());
    assertNotNull(p);
    // List<ProductAvailability> avs = p.getAvailabilities().stream().filter(a -> !a.getVariants().isEmpty()).collect(Collectors.toList());
    // assertThat(avs, not(empty()));
    // test product list service
    // list products per category
    // list 5 items
    ProductCriteria productCriteria = new ProductCriteria();
    productCriteria.setCategoryIds(Stream.of(shoes.getId()).collect(Collectors.toList()));
    Page<Product> listByCategory = productService.listByStore(store, en, productCriteria, 0, 5);
    List<Product> productsByCategory = listByCategory.getContent();
    assertThat(productsByCategory, not(empty()));
    // list products per color attribute
    Page<Product> listByOptionValue = productService.listByStore(store, en, productCriteria, 0, 5);
    productCriteria = new ProductCriteria();
    productCriteria.setOptionValueIds(Stream.of(nineHalf.getId()).collect(Collectors.toList()));
    List<Product> productsByOption = listByOptionValue.getContent();
    assertThat(productsByOption, not(empty()));
}
Also used : ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) Category(com.salesmanager.core.model.catalog.category.Category) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) Product(com.salesmanager.core.model.catalog.product.Product) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) BigDecimal(java.math.BigDecimal) 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) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)17 Language (com.salesmanager.core.model.reference.language.Language)12 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)10 Category (com.salesmanager.core.model.catalog.category.Category)9 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)8 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)8 ProductType (com.salesmanager.core.model.catalog.product.type.ProductType)8 ArrayList (java.util.ArrayList)8 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)7 ProductPriceDescription (com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)7 ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)7 BigDecimal (java.math.BigDecimal)7 HashSet (java.util.HashSet)7 Product (com.salesmanager.core.model.catalog.product.Product)6 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)6 ManufacturerDescription (com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription)6 PersistableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer)5 ReadableManufacturerPopulator (com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator)5 Date (java.util.Date)5 Test (org.junit.Test)5