Search in sources :

Example 31 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class CategoryTest method testCategory.

/**
 * This method creates multiple products using multiple catalog APIs
 * @throws ServiceException
 */
@Test
public void testCategory() throws Exception {
    Language en = languageService.getByCode("en");
    Language fr = languageService.getByCode("fr");
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    Category materingstuff = new Category();
    materingstuff.setMerchantStore(store);
    materingstuff.setCode("materingstuff");
    CategoryDescription bookEnglishDescription = new CategoryDescription();
    bookEnglishDescription.setName("Book");
    bookEnglishDescription.setCategory(materingstuff);
    bookEnglishDescription.setLanguage(en);
    CategoryDescription bookFrenchDescription = new CategoryDescription();
    bookFrenchDescription.setName("Livre");
    bookFrenchDescription.setCategory(materingstuff);
    bookFrenchDescription.setLanguage(fr);
    Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
    descriptions.add(bookEnglishDescription);
    descriptions.add(bookFrenchDescription);
    materingstuff.setDescriptions(descriptions);
    categoryService.create(materingstuff);
    assertNotNull(materingstuff.getId());
    Long bookId = materingstuff.getId();
    Category fetchedBook = categoryService.getById(bookId, store.getId());
    Assert.assertEquals(2, fetchedBook.getDescriptions().size());
    // Clean up for other tests
    categoryService.delete(materingstuff);
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) Language(com.salesmanager.core.model.reference.language.Language) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 32 with Language

use of com.salesmanager.core.model.reference.language.Language 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 33 with Language

use of com.salesmanager.core.model.reference.language.Language 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 34 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class ProductTest method testCreateRelationShip.

private void testCreateRelationShip(Product product) throws Exception {
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    Language en = languageService.getByCode("en");
    Manufacturer oreilley = manufacturerService.getByCode(store, "oreilley");
    ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
    Category tech = categoryService.getByCode(store, "tech");
    // create new related product
    // PRODUCT 1
    Product related = new Product();
    related.setProductHeight(new BigDecimal(4));
    related.setProductLength(new BigDecimal(3));
    related.setProductWidth(new BigDecimal(1));
    related.setSku("TB67891");
    related.setManufacturer(oreilley);
    related.setType(generalType);
    related.setMerchantStore(store);
    // Product description
    ProductDescription description = new ProductDescription();
    description.setName("Spring 4 in Action");
    description.setLanguage(en);
    description.setProduct(related);
    product.getDescriptions().add(description);
    // add category
    product.getCategories().add(tech);
    // Availability
    ProductAvailability availability = new ProductAvailability();
    availability.setProductDateAvailable(date);
    availability.setProductQuantity(200);
    availability.setRegion("*");
    // associate with product
    availability.setProduct(related);
    // productAvailabilityService.create(availability);
    related.getAvailabilities().add(availability);
    ProductPrice dprice = new ProductPrice();
    dprice.setDefaultPrice(true);
    dprice.setProductPriceAmount(new BigDecimal(39.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);
    related.getAvailabilities().add(availability);
    productService.save(related);
    ProductRelationship relationship = new ProductRelationship();
    relationship.setActive(true);
    relationship.setCode("spring");
    relationship.setProduct(product);
    relationship.setRelatedProduct(related);
    relationship.setStore(store);
    // because relationships are nor joined fetched, make sure you query relationships first, then ad to an existing list
    // so relationship and review are they only objects not joined fetch when querying a product
    // need to do a subsequent query
    List<ProductRelationship> relationships = productRelationshipService.listByProduct(product);
    relationships.add(relationship);
    product.setRelationships(new HashSet<ProductRelationship>(relationships));
    productService.save(product);
}
Also used : 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) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) BigDecimal(java.math.BigDecimal) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)

Example 35 with Language

use of com.salesmanager.core.model.reference.language.Language in project shopizer by shopizer-ecommerce.

the class CustomerTest method createCustomer.

@Test
public void createCustomer() throws ServiceException {
    Language en = languageService.getByCode("en");
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    Country country = countryService.getByCode("CA");
    Zone zone = zoneService.getByCode("QC");
    /**
     * Core customer attributes *
     */
    Customer customer = new Customer();
    customer.setMerchantStore(store);
    customer.setEmailAddress("test@test.com");
    customer.setGender(CustomerGender.M);
    customer.setAnonymous(true);
    customer.setCompany("ifactory");
    customer.setDateOfBirth(new Date());
    customer.setNick("My nick");
    customer.setPassword("123456");
    customer.setDefaultLanguage(store.getDefaultLanguage());
    Delivery delivery = new Delivery();
    delivery.setAddress("Shipping address");
    delivery.setCountry(country);
    delivery.setZone(zone);
    Billing billing = new Billing();
    billing.setFirstName("John");
    billing.setLastName("Bossanova");
    billing.setAddress("Billing address");
    billing.setCountry(country);
    billing.setZone(zone);
    customer.setBilling(billing);
    customer.setDelivery(delivery);
    customerService.create(customer);
    customer = customerService.getById(customer.getId());
    // create an option value
    CustomerOptionValue yes = new CustomerOptionValue();
    yes.setCode("yes");
    yes.setMerchantStore(store);
    CustomerOptionValueDescription yesDescription = new CustomerOptionValueDescription();
    yesDescription.setLanguage(en);
    yesDescription.setCustomerOptionValue(yes);
    CustomerOptionValueDescription yes_sir = new CustomerOptionValueDescription();
    yes_sir.setCustomerOptionValue(yes);
    yes_sir.setDescription("Yes sir!");
    yes_sir.setName("Yes sir!");
    yes_sir.setLanguage(en);
    yes.getDescriptions().add(yes_sir);
    // needs to be saved before using it
    customerOptionValueService.create(yes);
    CustomerOptionValue no = new CustomerOptionValue();
    no.setCode("no");
    no.setMerchantStore(store);
    CustomerOptionValueDescription noDescription = new CustomerOptionValueDescription();
    noDescription.setLanguage(en);
    noDescription.setCustomerOptionValue(no);
    CustomerOptionValueDescription no_sir = new CustomerOptionValueDescription();
    no_sir.setCustomerOptionValue(no);
    no_sir.setDescription("Nope!");
    no_sir.setName("Nope!");
    no_sir.setLanguage(en);
    no.getDescriptions().add(no_sir);
    // needs to be saved before using it
    customerOptionValueService.create(no);
    // create a customer option to be used
    CustomerOption subscribedToMailingList = new CustomerOption();
    subscribedToMailingList.setActive(true);
    subscribedToMailingList.setPublicOption(true);
    subscribedToMailingList.setCode("subscribedToMailingList");
    subscribedToMailingList.setMerchantStore(store);
    CustomerOptionDescription mailingListDesciption = new CustomerOptionDescription();
    mailingListDesciption.setName("Subscribed to mailing list");
    mailingListDesciption.setDescription("Subscribed to mailing list");
    mailingListDesciption.setLanguage(en);
    mailingListDesciption.setCustomerOption(subscribedToMailingList);
    Set<CustomerOptionDescription> mailingListDesciptionList = new HashSet<CustomerOptionDescription>();
    mailingListDesciptionList.add(mailingListDesciption);
    subscribedToMailingList.setDescriptions(mailingListDesciptionList);
    customerOptionService.create(subscribedToMailingList);
    // create a customer option to be used
    CustomerOption hasReturnedItems = new CustomerOption();
    hasReturnedItems.setActive(true);
    hasReturnedItems.setPublicOption(true);
    hasReturnedItems.setCode("hasReturnedItems");
    hasReturnedItems.setMerchantStore(store);
    CustomerOptionDescription hasReturnedItemsDesciption = new CustomerOptionDescription();
    hasReturnedItemsDesciption.setName("Has returned items");
    hasReturnedItemsDesciption.setDescription("Has returned items");
    hasReturnedItemsDesciption.setLanguage(en);
    hasReturnedItemsDesciption.setCustomerOption(hasReturnedItems);
    Set<CustomerOptionDescription> hasReturnedItemsList = new HashSet<CustomerOptionDescription>();
    hasReturnedItemsList.add(hasReturnedItemsDesciption);
    hasReturnedItems.setDescriptions(hasReturnedItemsList);
    customerOptionService.create(hasReturnedItems);
    subscribedToMailingList.setSortOrder(3);
    customerOptionService.update(subscribedToMailingList);
    // --
    // now create an option set (association of a customer option with possible customer option values)
    // --
    // possible yes
    CustomerOptionSet mailingListSetYes = new CustomerOptionSet();
    mailingListSetYes.setSortOrder(0);
    mailingListSetYes.setCustomerOption(subscribedToMailingList);
    mailingListSetYes.setCustomerOptionValue(yes);
    customerOptionSetService.create(mailingListSetYes);
    // possible no
    CustomerOptionSet mailingListSetNo = new CustomerOptionSet();
    // mailingListSetNo.setPk(mailingListSetNoId);
    mailingListSetNo.setSortOrder(1);
    mailingListSetNo.setCustomerOption(subscribedToMailingList);
    mailingListSetNo.setCustomerOptionValue(no);
    customerOptionSetService.create(mailingListSetNo);
    // possible has returned items
    CustomerOptionSet hasReturnedItemsYes = new CustomerOptionSet();
    hasReturnedItemsYes.setSortOrder(0);
    hasReturnedItemsYes.setCustomerOption(hasReturnedItems);
    hasReturnedItemsYes.setCustomerOptionValue(yes);
    customerOptionSetService.create(hasReturnedItemsYes);
    subscribedToMailingList.setSortOrder(2);
    customerOptionService.update(subscribedToMailingList);
    CustomerOption option = customerOptionService.getById(subscribedToMailingList.getId());
    option.setSortOrder(4);
    customerOptionService.update(option);
    List<CustomerOptionSet> optionSetList = customerOptionSetService.listByStore(store, en);
    // Assert.assertEquals(3, optionSetList.size());
    System.out.println("Size of options : " + optionSetList.size());
    /**
     * Now create a customer option attribute
     * A customer attribute is a selected customer option set transformed to an
     * attribute for a given customer
     */
    CustomerAttribute customerAttributeMailingList = new CustomerAttribute();
    customerAttributeMailingList.setCustomer(customer);
    customerAttributeMailingList.setCustomerOption(subscribedToMailingList);
    customerAttributeMailingList.setCustomerOptionValue(no);
    customer.getAttributes().add(customerAttributeMailingList);
    customerService.save(customer);
    customerService.delete(customer);
}
Also used : CustomerOptionDescription(com.salesmanager.core.model.customer.attribute.CustomerOptionDescription) Customer(com.salesmanager.core.model.customer.Customer) Zone(com.salesmanager.core.model.reference.zone.Zone) CustomerOptionSet(com.salesmanager.core.model.customer.attribute.CustomerOptionSet) Date(java.util.Date) CustomerOption(com.salesmanager.core.model.customer.attribute.CustomerOption) CustomerOptionValue(com.salesmanager.core.model.customer.attribute.CustomerOptionValue) Language(com.salesmanager.core.model.reference.language.Language) CustomerAttribute(com.salesmanager.core.model.customer.attribute.CustomerAttribute) Billing(com.salesmanager.core.model.common.Billing) Country(com.salesmanager.core.model.reference.country.Country) CustomerOptionValueDescription(com.salesmanager.core.model.customer.attribute.CustomerOptionValueDescription) Delivery(com.salesmanager.core.model.common.Delivery) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Language (com.salesmanager.core.model.reference.language.Language)148 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)115 ArrayList (java.util.ArrayList)58 List (java.util.List)56 ServiceException (com.salesmanager.core.business.exception.ServiceException)55 Collectors (java.util.stream.Collectors)50 Product (com.salesmanager.core.model.catalog.product.Product)45 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)42 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)38 Autowired (org.springframework.beans.factory.annotation.Autowired)35 ConversionException (com.salesmanager.core.business.exception.ConversionException)30 Category (com.salesmanager.core.model.catalog.category.Category)30 Validate (org.apache.commons.lang3.Validate)29 Customer (com.salesmanager.core.model.customer.Customer)28 Optional (java.util.Optional)28 Inject (javax.inject.Inject)28 Service (org.springframework.stereotype.Service)28 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)27 ImageFilePath (com.salesmanager.shop.utils.ImageFilePath)25