Search in sources :

Example 6 with ProductCriteria

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

the class ProductItemsFacadeImpl method listItemsByManufacturer.

@Override
public ReadableProductList listItemsByManufacturer(MerchantStore store, Language language, Long manufacturerId, int startCount, int maxCount) throws Exception {
    ProductCriteria productCriteria = new ProductCriteria();
    productCriteria.setMaxCount(maxCount);
    productCriteria.setStartIndex(startCount);
    productCriteria.setManufacturerId(manufacturerId);
    com.salesmanager.core.model.catalog.product.ProductList products = productService.listByStore(store, language, productCriteria);
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    ReadableProductList productList = new ReadableProductList();
    for (Product product : products.getProducts()) {
        // create new proxy product
        ReadableProduct readProduct = populator.populate(product, new ReadableProduct(), store, language);
        productList.getProducts().add(readProduct);
    }
    productList.setTotalPages(Math.toIntExact(products.getTotalCount()));
    return productList;
}
Also used : ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct)

Example 7 with ProductCriteria

use of com.salesmanager.core.model.catalog.product.ProductCriteria 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

ProductCriteria (com.salesmanager.core.model.catalog.product.ProductCriteria)7 Product (com.salesmanager.core.model.catalog.product.Product)6 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)5 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)5 Category (com.salesmanager.core.model.catalog.category.Category)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)4 Language (com.salesmanager.core.model.reference.language.Language)4 ReadableProductList (com.salesmanager.shop.model.catalog.product.ReadableProductList)3 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 QueryFilter (com.salesmanager.shop.store.model.filter.QueryFilter)2 ArrayList (java.util.ArrayList)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 CategoryService (com.salesmanager.core.business.services.catalog.category.CategoryService)1 PricingService (com.salesmanager.core.business.services.catalog.product.PricingService)1 ProductService (com.salesmanager.core.business.services.catalog.product.ProductService)1 SearchService (com.salesmanager.core.business.services.search.SearchService)1 CoreConfiguration (com.salesmanager.core.business.utils.CoreConfiguration)1 CategoryDescription (com.salesmanager.core.model.catalog.category.CategoryDescription)1