Search in sources :

Example 16 with ProductPrice

use of com.salesmanager.core.model.catalog.product.price.ProductPrice 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 17 with ProductPrice

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

the class ProductNextGenTest method createInventory.

/**
 * Manage product inventory
 * @param product
 * @throws Exception
 */
private ProductAvailability createInventory(MerchantStore store, int quantity, BigDecimal price) throws Exception {
    // add inventory
    ProductAvailability availability = new ProductAvailability();
    availability.setProductDateAvailable(date);
    availability.setProductQuantity(quantity);
    availability.setRegion("*");
    availability.setAvailable(true);
    Language en = languageService.getByCode("en");
    ProductPrice dprice = new ProductPrice();
    dprice.setDefaultPrice(true);
    dprice.setProductPriceAmount(price);
    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);
    return availability;
}
Also used : ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Language(com.salesmanager.core.model.reference.language.Language) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)

Example 18 with ProductPrice

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

the class ProductTest method testCreateProduct.

/**
 * This method creates multiple products using multiple catalog APIs
 * @throws ServiceException
 */
@Test
public void testCreateProduct() throws Exception {
    Language en = languageService.getByCode("en");
    Language fr = languageService.getByCode("fr");
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
    Category book = new Category();
    book.setMerchantStore(store);
    book.setCode("book");
    CategoryDescription bookEnglishDescription = new CategoryDescription();
    bookEnglishDescription.setName("Book");
    bookEnglishDescription.setCategory(book);
    bookEnglishDescription.setLanguage(en);
    CategoryDescription bookFrenchDescription = new CategoryDescription();
    bookFrenchDescription.setName("Livre");
    bookFrenchDescription.setCategory(book);
    bookFrenchDescription.setLanguage(fr);
    Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
    descriptions.add(bookEnglishDescription);
    descriptions.add(bookFrenchDescription);
    book.setDescriptions(descriptions);
    categoryService.create(book);
    Category music = new Category();
    music.setMerchantStore(store);
    music.setCode("music");
    CategoryDescription musicEnglishDescription = new CategoryDescription();
    musicEnglishDescription.setName("Music");
    musicEnglishDescription.setCategory(music);
    musicEnglishDescription.setLanguage(en);
    CategoryDescription musicFrenchDescription = new CategoryDescription();
    musicFrenchDescription.setName("Musique");
    musicFrenchDescription.setCategory(music);
    musicFrenchDescription.setLanguage(fr);
    Set<CategoryDescription> descriptions2 = new HashSet<CategoryDescription>();
    descriptions2.add(musicEnglishDescription);
    descriptions2.add(musicFrenchDescription);
    music.setDescriptions(descriptions2);
    categoryService.create(music);
    Category novell = new Category();
    novell.setMerchantStore(store);
    novell.setCode("novell");
    CategoryDescription novellEnglishDescription = new CategoryDescription();
    novellEnglishDescription.setName("Novell");
    novellEnglishDescription.setCategory(novell);
    novellEnglishDescription.setLanguage(en);
    CategoryDescription novellFrenchDescription = new CategoryDescription();
    novellFrenchDescription.setName("Roman");
    novellFrenchDescription.setCategory(novell);
    novellFrenchDescription.setLanguage(fr);
    Set<CategoryDescription> descriptions3 = new HashSet<CategoryDescription>();
    descriptions3.add(novellEnglishDescription);
    descriptions3.add(novellFrenchDescription);
    novell.setDescriptions(descriptions3);
    novell.setParent(book);
    categoryService.create(novell);
    categoryService.addChild(book, novell);
    Category tech = new Category();
    tech.setMerchantStore(store);
    tech.setCode("tech");
    CategoryDescription techEnglishDescription = new CategoryDescription();
    techEnglishDescription.setName("Technology");
    techEnglishDescription.setCategory(tech);
    techEnglishDescription.setLanguage(en);
    CategoryDescription techFrenchDescription = new CategoryDescription();
    techFrenchDescription.setName("Technologie");
    techFrenchDescription.setCategory(tech);
    techFrenchDescription.setLanguage(fr);
    Set<CategoryDescription> descriptions4 = new HashSet<CategoryDescription>();
    descriptions4.add(techFrenchDescription);
    descriptions4.add(techFrenchDescription);
    tech.setDescriptions(descriptions4);
    tech.setParent(book);
    categoryService.create(tech);
    categoryService.addChild(book, tech);
    Category fiction = new Category();
    fiction.setMerchantStore(store);
    fiction.setCode("fiction");
    CategoryDescription fictionEnglishDescription = new CategoryDescription();
    fictionEnglishDescription.setName("Fiction");
    fictionEnglishDescription.setCategory(fiction);
    fictionEnglishDescription.setLanguage(en);
    CategoryDescription fictionFrenchDescription = new CategoryDescription();
    fictionFrenchDescription.setName("Sc Fiction");
    fictionFrenchDescription.setCategory(fiction);
    fictionFrenchDescription.setLanguage(fr);
    Set<CategoryDescription> fictiondescriptions = new HashSet<CategoryDescription>();
    fictiondescriptions.add(fictionEnglishDescription);
    fictiondescriptions.add(fictionFrenchDescription);
    fiction.setDescriptions(fictiondescriptions);
    fiction.setParent(novell);
    categoryService.create(fiction);
    categoryService.addChild(book, fiction);
    Manufacturer oreilley = new Manufacturer();
    oreilley.setMerchantStore(store);
    oreilley.setCode("oreilley");
    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("packed");
    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("novells");
    ManufacturerDescription novellsd = new ManufacturerDescription();
    novellsd.setLanguage(en);
    novellsd.setManufacturer(novells);
    novellsd.setName("Novells publishing");
    novells.getDescriptions().add(novellsd);
    manufacturerService.create(novells);
    // PRODUCT 1
    Product product = new Product();
    product.setProductHeight(new BigDecimal(4));
    product.setProductLength(new BigDecimal(3));
    product.setProductWidth(new BigDecimal(1));
    product.setSku("CT12345");
    product.setManufacturer(oreilley);
    product.setType(generalType);
    product.setMerchantStore(store);
    // Product description
    ProductDescription description = new ProductDescription();
    description.setName("Spring in Action");
    description.setLanguage(en);
    description.setProduct(product);
    product.getDescriptions().add(description);
    // add category
    product.getCategories().add(tech);
    // Availability
    ProductAvailability availability = new ProductAvailability();
    availability.setProductDateAvailable(date);
    availability.setProductQuantity(100);
    availability.setRegion("*");
    // associate with product
    availability.setProduct(product);
    // productAvailabilityService.create(availability);
    product.getAvailabilities().add(availability);
    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);
    /**
     * Create product
     */
    productService.create(product);
    /**
     * Creates a review
     * TODO requires customer
     */
    // testReview(product);
    List<Product> products = productService.listByStore(store);
    System.out.println("Total number of items " + products.size());
    // count products by category
    String lineage = new StringBuilder().append(book.getLineage()).toString();
    List<Category> categories = categoryService.getListByLineage(store, lineage);
    List<Long> ids = new ArrayList<Long>();
    if (categories != null && categories.size() > 0) {
        for (Category c : categories) {
            ids.add(c.getId());
        }
    }
    List<Object[]> objs = categoryService.countProductsByCategories(store, ids);
    for (Object[] ob : objs) {
        Long c = (Long) ob[0];
    // System.out.println("Category " + c.getCode() + " has " + ob[1] + " items");
    }
    // get manufacturer for given categories
    List<Manufacturer> manufacturers = manufacturerService.listByProductsByCategoriesId(store, ids, en);
    // System.out.println("Number of manufacturer for all category " + manufacturers.size());
    // Update product -- get first from the list
    Product updatableProduct = products.get(0);
    // Get first availability, which is the only one created
    ProductAvailability updatableAvailability = updatableProduct.getAvailabilities().iterator().next();
    // Get first price, which is the only one created
    ProductPrice updatablePrice = updatableAvailability.getPrices().iterator().next();
    updatablePrice.setProductPriceAmount(new BigDecimal(19.99));
    // Add a second price
    ProductPrice anotherPrice = new ProductPrice();
    anotherPrice.setCode("eco");
    anotherPrice.setProductPriceAmount(new BigDecimal(1.99));
    anotherPrice.setProductAvailability(updatableAvailability);
    ProductPriceDescription anotherPriceD = new ProductPriceDescription();
    anotherPriceD.setName("Eco price");
    anotherPriceD.setProductPrice(anotherPrice);
    anotherPriceD.setLanguage(en);
    anotherPrice.getDescriptions().add(anotherPriceD);
    updatableAvailability.getPrices().add(anotherPrice);
    // Update product
    productService.update(updatableProduct);
    // go and get products again
    products = productService.listByStore(store);
    updatableProduct = products.get(0);
    // test attributes
    this.testAttributes(updatableProduct);
    // test insert, view image
    testInsertImage(updatableProduct);
    testViewImage(updatableProduct);
    Product refreshed = productService.getByCode("CT12345", en);
    productService.delete(refreshed);
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ArrayList(java.util.ArrayList) Product(com.salesmanager.core.model.catalog.product.Product) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) 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) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) HashSet(java.util.HashSet) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) BigDecimal(java.math.BigDecimal) 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) Test(org.junit.Test)

Example 19 with ProductPrice

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

the class ShoppingCartTest method createShoppingCart.

@Test
public void createShoppingCart() throws Exception {
    MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    Language en = languageService.getByCode("en");
    /**
     * CATALOG CREATION *
     */
    ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
    /**
     * Create the category
     */
    Category shirts = new Category();
    shirts.setMerchantStore(store);
    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(store);
    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(store);
    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(store);
    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(store);
    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("XABC12");
    product.setManufacturer(addidas);
    product.setType(generalType);
    product.setMerchantStore(store);
    // 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 Shopping cart *
     */
    ShoppingCart shoppingCart = new ShoppingCart();
    shoppingCart.setMerchantStore(store);
    UUID cartCode = UUID.randomUUID();
    shoppingCart.setShoppingCartCode(cartCode.toString());
    ShoppingCartItem item = new ShoppingCartItem(shoppingCart, product);
    item.setShoppingCart(shoppingCart);
    FinalPrice price = pricingService.calculateProductPrice(product);
    item.setItemPrice(price.getFinalPrice());
    item.setQuantity(1);
    /**
     * user selects black *
     */
    ShoppingCartAttributeItem attributeItem = new ShoppingCartAttributeItem(item, blackAttribute);
    item.getAttributes().add(attributeItem);
    shoppingCart.getLineItems().add(item);
    // create cart
    shoppingCartService.create(shoppingCart);
    /**
     * Retrieve cart *
     */
    ShoppingCart retrievedCart = shoppingCartService.getByCode(cartCode.toString(), store);
    Assert.assertNotNull(retrievedCart);
    /**
     * Delete cart *
     */
    shoppingCartService.delete(retrievedCart);
    /**
     * Check if cart has been deleted *
     */
    retrievedCart = shoppingCartService.getByCode(cartCode.toString(), store);
    Assert.assertNull(retrievedCart);
    // Clean up for other tests
    categoryService.delete(shirts);
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) Product(com.salesmanager.core.model.catalog.product.Product) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) ShoppingCartAttributeItem(com.salesmanager.core.model.shoppingcart.ShoppingCartAttributeItem) 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) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) UUID(java.util.UUID) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) HashSet(java.util.HashSet) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) BigDecimal(java.math.BigDecimal) Date(java.util.Date) ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Test(org.junit.Test)

Example 20 with ProductPrice

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

the class ProductFacadeImpl method update.

@Override
public void update(Long productId, LightPersistableProduct product, MerchantStore merchant, Language language) {
    // Get product
    Product modified = productService.findOne(productId, merchant);
    // Update product with minimal set
    modified.setAvailable(product.isAvailable());
    for (ProductAvailability availability : modified.getAvailabilities()) {
        availability.setProductQuantity(product.getQuantity());
        if (!StringUtils.isBlank(product.getPrice())) {
            // set default price
            for (ProductPrice price : availability.getPrices()) {
                if (price.isDefaultPrice()) {
                    try {
                        price.setProductPriceAmount(pricingService.getAmount(product.getPrice()));
                    } catch (ServiceException e) {
                        throw new ServiceRuntimeException("Invalid product price format");
                    }
                }
            }
        }
    }
    try {
        productService.save(modified);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot update product ", e);
    }
}
Also used : ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ServiceException(com.salesmanager.core.business.exception.ServiceException) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ProductPrice (com.salesmanager.core.model.catalog.product.price.ProductPrice)20 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)17 Product (com.salesmanager.core.model.catalog.product.Product)12 ProductPriceDescription (com.salesmanager.core.model.catalog.product.price.ProductPriceDescription)12 Language (com.salesmanager.core.model.reference.language.Language)11 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)10 Category (com.salesmanager.core.model.catalog.category.Category)9 ProductType (com.salesmanager.core.model.catalog.product.type.ProductType)9 Date (java.util.Date)9 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)8 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)8 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)7 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)7 HashSet (java.util.HashSet)7 ConversionException (com.salesmanager.core.business.exception.ConversionException)6 ServiceException (com.salesmanager.core.business.exception.ServiceException)5 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)5 PersistableProduct (com.salesmanager.shop.model.catalog.product.PersistableProduct)5 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)5