Search in sources :

Example 36 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore 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 37 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore 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 38 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class UserServicesImpl method createDefaultAdmin.

public void createDefaultAdmin() throws Exception {
    MerchantStore store = merchantStoreService.getByCode(MerchantStore.DEFAULT_STORE);
    String password = passwordEncoder.encode(DEFAULT_INITIAL_PASSWORD);
    List<Group> groups = groupService.listGroup(GroupType.ADMIN);
    // creation of the super admin admin:password)
    com.salesmanager.core.model.user.User user = new com.salesmanager.core.model.user.User("admin@shopizer.com", password, "admin@shopizer.com");
    user.setFirstName("Administrator");
    user.setLastName("User");
    for (Group group : groups) {
        if (group.getGroupName().equals(Constants.GROUP_SUPERADMIN) || group.getGroupName().equals(Constants.GROUP_ADMIN)) {
            user.getGroups().add(group);
        }
    }
    user.setMerchantStore(store);
    userService.create(user);
}
Also used : Group(com.salesmanager.core.model.user.Group) User(org.springframework.security.core.userdetails.User) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Example 39 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore in project shopizer by shopizer-ecommerce.

the class ContentFolderTest method addFolder.

@Ignore
public void addFolder() {
    MerchantStore store;
    try {
        store = super.merchantService.getByCode("DEFAULT");
        String folderName = "newFolder";
        Optional<String> path = Optional.ofNullable(null);
        // add folder to root
        contentService.addFolder(store, path, folderName);
    // add new folder to newFolder
    } catch (ServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Ignore(org.junit.Ignore)

Example 40 with MerchantStore

use of com.salesmanager.core.model.merchant.MerchantStore 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

MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)171 Language (com.salesmanager.core.model.reference.language.Language)123 ServiceException (com.salesmanager.core.business.exception.ServiceException)72 List (java.util.List)65 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)62 ArrayList (java.util.ArrayList)61 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)60 Collectors (java.util.stream.Collectors)60 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)52 Autowired (org.springframework.beans.factory.annotation.Autowired)46 Product (com.salesmanager.core.model.catalog.product.Product)43 Service (org.springframework.stereotype.Service)37 Optional (java.util.Optional)35 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)35 Customer (com.salesmanager.core.model.customer.Customer)33 Logger (org.slf4j.Logger)33 LoggerFactory (org.slf4j.LoggerFactory)33 Inject (javax.inject.Inject)32 Validate (org.apache.commons.lang3.Validate)30 ConversionException (com.salesmanager.core.business.exception.ConversionException)27