Search in sources :

Example 1 with ProductOptionValue

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

the class ProductNextGenTest method createOptionsSet.

private void createOptionsSet(MerchantStore store) throws Exception {
    // add a set of option / values for major sizes
    possibleSizes = new ProductOptionSet();
    possibleSizes.setCode("majorSizes");
    possibleSizes.setStore(store);
    possibleSizes.setOption(size);
    List<ProductOptionValue> values = new ArrayList<ProductOptionValue>();
    values.add(nine);
    values.add(ten);
    possibleSizes.setValues(values);
    productOptionSetService.create(possibleSizes);
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) ArrayList(java.util.ArrayList)

Example 2 with ProductOptionValue

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

the class ProductNextGenTest method createOptions.

/**
 * Add possible choices
 * @param product
 * @throws Exception
 */
private void createOptions(Product product) throws Exception {
    /**
     * An attribute can be created dynamicaly but the attached Option and Option value need to exist
     */
    MerchantStore store = product.getMerchantStore();
    Language en = languageService.getByCode("en");
    /**
     * Create size option
     */
    size = new ProductOption();
    size.setMerchantStore(store);
    size.setCode("SHOESIZE");
    size.setProductOptionType(ProductOptionType.Radio.name());
    ProductOptionDescription sizeDescription = new ProductOptionDescription();
    sizeDescription.setLanguage(en);
    sizeDescription.setName("Size");
    sizeDescription.setDescription("Show size");
    sizeDescription.setProductOption(size);
    size.getDescriptions().add(sizeDescription);
    // create option
    productOptionService.saveOrUpdate(size);
    /**
     * Create size values (9, 9.5, 10)
     */
    // option value 9
    nine = new ProductOptionValue();
    nine.setMerchantStore(store);
    nine.setCode("nine");
    ProductOptionValueDescription nineDescription = new ProductOptionValueDescription();
    nineDescription.setLanguage(en);
    nineDescription.setName("9");
    nineDescription.setDescription("Size 9");
    nineDescription.setProductOptionValue(nine);
    nine.getDescriptions().add(nineDescription);
    // create an option value
    productOptionValueService.saveOrUpdate(nine);
    // option value 9.5
    nineHalf = new ProductOptionValue();
    nineHalf.setMerchantStore(store);
    nineHalf.setCode("nineHalf");
    ProductOptionValueDescription nineHalfDescription = new ProductOptionValueDescription();
    nineHalfDescription.setLanguage(en);
    nineHalfDescription.setName("9.5");
    nineHalfDescription.setDescription("Size 9.5");
    nineHalfDescription.setProductOptionValue(nineHalf);
    nineHalf.getDescriptions().add(nineHalfDescription);
    // create an option value
    productOptionValueService.saveOrUpdate(nineHalf);
    // option value 10
    ten = new ProductOptionValue();
    ten.setMerchantStore(store);
    ten.setCode("ten");
    ProductOptionValueDescription tenDescription = new ProductOptionValueDescription();
    tenDescription.setLanguage(en);
    tenDescription.setName("10");
    tenDescription.setDescription("Size 10");
    tenDescription.setProductOptionValue(ten);
    ten.getDescriptions().add(tenDescription);
    // create an option value
    productOptionValueService.saveOrUpdate(ten);
// end options / options values
}
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) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)

Example 3 with ProductOptionValue

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

the class ProductTest method testAttributes.

private void testAttributes(Product product) throws Exception {
    /**
     * An attribute can be created dynamicaly but the attached Option and Option value need to exist
     */
    MerchantStore store = product.getMerchantStore();
    Language en = languageService.getByCode("en");
    /**
     * Create size option
     */
    ProductOption color = new ProductOption();
    color.setMerchantStore(store);
    color.setCode("COLOR");
    color.setProductOptionType(ProductOptionType.Radio.name());
    ProductOptionDescription optionDescription = new ProductOptionDescription();
    optionDescription.setLanguage(en);
    optionDescription.setName("Color");
    optionDescription.setDescription("Color of an item");
    optionDescription.setProductOption(color);
    color.getDescriptions().add(optionDescription);
    // create option
    productOptionService.saveOrUpdate(color);
    /**
     * Create size option
     */
    ProductOption size = new ProductOption();
    size.setMerchantStore(store);
    size.setCode("SIZE");
    size.setProductOptionType(ProductOptionType.Radio.name());
    ProductOptionDescription sizeDescription = new ProductOptionDescription();
    sizeDescription.setLanguage(en);
    sizeDescription.setName("Size");
    sizeDescription.setDescription("Size of an item");
    sizeDescription.setProductOption(size);
    size.getDescriptions().add(sizeDescription);
    // create option
    productOptionService.saveOrUpdate(size);
    // option value
    ProductOptionValue red = new ProductOptionValue();
    red.setMerchantStore(store);
    red.setCode("red");
    ProductOptionValueDescription redDescription = new ProductOptionValueDescription();
    redDescription.setLanguage(en);
    redDescription.setName("Red");
    redDescription.setDescription("Red color");
    redDescription.setProductOptionValue(red);
    red.getDescriptions().add(redDescription);
    // create an option value
    productOptionValueService.saveOrUpdate(red);
    // another option value
    ProductOptionValue blue = new ProductOptionValue();
    blue.setMerchantStore(store);
    blue.setCode("blue");
    ProductOptionValueDescription blueDescription = new ProductOptionValueDescription();
    blueDescription.setLanguage(en);
    blueDescription.setName("Blue");
    blueDescription.setDescription("Color blue");
    blueDescription.setProductOptionValue(blue);
    blue.getDescriptions().add(blueDescription);
    // create another option value
    productOptionValueService.saveOrUpdate(blue);
    // option value
    ProductOptionValue small = new ProductOptionValue();
    small.setMerchantStore(store);
    small.setCode("small");
    ProductOptionValueDescription smallDescription = new ProductOptionValueDescription();
    smallDescription.setLanguage(en);
    smallDescription.setName("Small");
    smallDescription.setDescription("Small size");
    smallDescription.setProductOptionValue(small);
    small.getDescriptions().add(smallDescription);
    // create an option value
    productOptionValueService.saveOrUpdate(small);
    // another option value
    ProductOptionValue medium = new ProductOptionValue();
    medium.setMerchantStore(store);
    medium.setCode("medium");
    ProductOptionValueDescription mediumDescription = new ProductOptionValueDescription();
    mediumDescription.setLanguage(en);
    mediumDescription.setName("Medium");
    mediumDescription.setDescription("Medium size");
    mediumDescription.setProductOptionValue(medium);
    medium.getDescriptions().add(mediumDescription);
    // create another option value
    productOptionValueService.saveOrUpdate(medium);
    ProductAttribute color_blue = new ProductAttribute();
    color_blue.setProduct(product);
    color_blue.setProductOption(color);
    color_blue.setAttributeDefault(true);
    // no price variation
    color_blue.setProductAttributePrice(new BigDecimal(0));
    // weight variation
    color_blue.setProductAttributeWeight(new BigDecimal(1));
    color_blue.setProductOptionValue(blue);
    productAttributeService.create(color_blue);
    product.getAttributes().add(color_blue);
    /**
     * create attributes *
     */
    // attributes
    ProductAttribute color_red = new ProductAttribute();
    color_red.setProduct(product);
    color_red.setProductOption(color);
    color_red.setAttributeDefault(true);
    // no price variation
    color_red.setProductAttributePrice(new BigDecimal(0));
    // weight variation
    color_red.setProductAttributeWeight(new BigDecimal(1));
    color_red.setProductOptionValue(red);
    productAttributeService.create(color_red);
    product.getAttributes().add(color_red);
    ProductAttribute smallAttr = new ProductAttribute();
    smallAttr.setProduct(product);
    smallAttr.setProductOption(size);
    smallAttr.setAttributeDefault(true);
    // no price variation
    smallAttr.setProductAttributePrice(new BigDecimal(0));
    // weight variation
    smallAttr.setProductAttributeWeight(new BigDecimal(1));
    smallAttr.setProductOptionValue(small);
    productAttributeService.create(smallAttr);
    product.getAttributes().add(smallAttr);
    productService.update(product);
    /**
     * get options facets
     */
    List<ProductAttribute> attributes = productAttributeService.getProductAttributesByCategoryLineage(store, product.getCategories().iterator().next().getLineage(), en);
    Assert.assertTrue((long) attributes.size() > 0);
}
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) Language(com.salesmanager.core.model.reference.language.Language) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) BigDecimal(java.math.BigDecimal) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)

Example 4 with ProductOptionValue

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

the class ProductOptionFacadeImpl method getOptionValue.

@Override
public ReadableProductOptionValueEntity getOptionValue(Long optionValueId, MerchantStore store, Language language) {
    Validate.notNull(optionValueId, "OptionValue id cannot be null");
    Validate.notNull(store, "Store cannot be null");
    ProductOptionValue optionValue = productOptionValueService.getById(store, optionValueId);
    if (optionValue == null) {
        throw new ResourceNotFoundException("OptionValue id [" + optionValueId + "] not found");
    }
    return readableOptionValueMapper.convert(optionValue, store, language);
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 5 with ProductOptionValue

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

the class ProductOptionFacadeImpl method saveOptionValue.

@Override
public ReadableProductOptionValueEntity saveOptionValue(PersistableProductOptionValue optionValue, MerchantStore store, Language language) {
    Validate.notNull(optionValue, "Option value code must not be null");
    Validate.notNull(store, "Store code must not be null");
    ProductOptionValue value = new ProductOptionValue();
    if (optionValue.getId() != null && optionValue.getId().longValue() > 0) {
        value = productOptionValueService.getById(store, optionValue.getId());
        if (value == null) {
            throw new ResourceNotFoundException("ProductOptionValue [" + optionValue.getId() + "] does not exists for store [" + store.getCode() + "]");
        }
    }
    value = persistableOptionValueMapper.merge(optionValue, value, store, language);
    try {
        productOptionValueService.saveOrUpdate(value);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while saving option value", e);
    }
    ProductOptionValue optValue = productOptionValueService.getById(store, value.getId());
    // convert to readable
    ReadableProductOptionValueEntity readableProductOptionValue = new ReadableProductOptionValueEntity();
    readableProductOptionValue = readableOptionValueMapper.merge(optValue, readableProductOptionValue, store, language);
    return readableProductOptionValue;
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)21 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)10 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)10 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)10 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 Language (com.salesmanager.core.model.reference.language.Language)9 ProductOptionDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription)8 PersistableProductOptionValue (com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue)8 Product (com.salesmanager.core.model.catalog.product.Product)7 ServiceException (com.salesmanager.core.business.exception.ServiceException)6 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)5 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)5 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Category (com.salesmanager.core.model.catalog.category.Category)4 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)4 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)4 ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)4 ProductPriceDescription (com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)4