Package com.google.code.magja.model.product

Examples of com.google.code.magja.model.product.Product


   * @param mpp
   *            - the attribute map
   * @return Product
   */
  private Product buildProductBasic(Map<String, Object> mpp) {
    Product product = new Product();

    // populate the basic fields
    for (Map.Entry<String, Object> attribute : mpp.entrySet())
      product.set(attribute.getKey(), attribute.getValue());

    return product;
  }
View Full Code Here


   * @throws ServiceException
   */
  private Product buildProduct(Map<String, Object> mpp, boolean dependencies)
      throws ServiceException {

    Product product = buildProductBasic(mpp);

    // product visibility
    if(mpp.get("visibility") != null) {
      Integer visi = new Integer(mpp.get("visibility").toString());
      switch (visi) {
      case 1:
        product.setVisibility(Visibility.NOT_VISIBLE_INDIVIDUALLY);
        break;
      case 2:
        product.setVisibility(Visibility.CATALOG);
        break;
      case 3:
        product.setVisibility(Visibility.SEARCH);
        break;
      case 4:
        product.setVisibility(Visibility.CATALOG_SEARCH);
        break;
      default:
        product.setVisibility(Visibility.CATALOG_SEARCH);
        break;
      }
    }

    // set product type
    if (mpp.get("type") != null) {

      ProductType type = ProductTypeEnum.getTypeOf((String) mpp
          .get("type"));

      if (type == null && dependencies) {
        /*
         * means its a type not covered by the enum, so we have to look
         * in magento api to get this type
         */
        List<ProductType> types = listAllProductTypes();
        for (ProductType productType : types) {
          if (productType.getType().equals((String) mpp.get("type"))) {
            type = productType;
            break;
          }
        }
      }

      if (type != null)
        product.setType(type);
    }

    // set the attributeSet
    if (mpp.get("set") != null && dependencies)
      product.setAttributeSet(getAttributeSet((String) mpp.get("set")));

    // categories - dont get the full tree, only basic info of categories
    if (mpp.get("category_ids") != null) {
      if (dependencies) {
        product.getCategories().addAll(
            getCategoriesBasicInfo((List<Object>) mpp
                .get("category_ids")));
      } else {
        List<Category> categories = new ArrayList<Category>();
        for (Object obj : (List<Object>) mpp.get("category_ids")) {
          Integer id = Integer.parseInt((String) obj);
          categories.add(new Category(id));
        }
        product.setCategories(categories);
      }
    }

    // Inventory
    if (dependencies) {
      Set<Product> products = new HashSet<Product>();
      products.add(product);
      getInventoryInfo(products);
    }

    // medias
    if (dependencies)
      product.setMedias(productMediaRemoteService.listByProduct(product));

    // product links
    if (dependencies)
      product.setLinks(productLinkRemoteService.list(product));

    return product;
  }
View Full Code Here

   * Test method for {@link com.google.code.magja.service.product.ProductRemoteServiceImpl#save(com.google.code.magja.model.product.Product)}.
   */
  @Test
  public void testSave() throws ServiceException {

    Product product = generateProduct();
    service.save(product);

    assertTrue(product.getId() != null);

    // set up the id and sku for use in other methods
    productId = product.getId();
    productSku = product.getSku();
  }
View Full Code Here

  @Test
  public void testGetByIdAndSku() throws ServiceException {

    testSave();

    Product productById = service.getById(productId);
    assertTrue(productById != null);

    Product productBySku = service.getBySku(productSku);
    assertTrue(productBySku != null);

    System.out.println(productById.toString());
  }
View Full Code Here

  @Test
  public void testUpdateInventory() throws ServiceException {

    testSave();

    Product product = new Product();
    product.setId(productId);
    product.setSku(productSku);
    product.setQty(new Double(50));

    service.updateInventory(product);
  }
View Full Code Here

  /**
   * Support method for create a simple product without image
   * @return simple product
   */
  public static Product generateProductWithoutImage() {
    Product product = new Product();
    product.setSku(MagjaStringUtils.randomString(3, 10).toUpperCase());
    product.setName(MagjaStringUtils.randomString(3, 5) + " Product Test");
    product.setShortDescription("this is a short description");
    product.setDescription("this is a description");
    product.setPrice(new Double(230.23));
    product.setCost(new Double(120.22));
    product.setEnabled(true);
    product.setWeight(new Double(0.100));
    Integer[] websites = { 1 };
    product.setWebsites(websites);
   
    product.setVisibility(Visibility.CATALOG_SEARCH);

    // inventory
    product.setQty(new Double(20));
    product.setInStock(true);

    // can use like that too (for the properties not mapped):
    product.set("meta_description", "one two tree");
    product.set("enable_googlecheckout", 1);

    // add category
    List<Category> categorys = new ArrayList<Category>();
    categorys.add(new Category(2));
    product.setCategories(categorys);

    //product.set("options_container", "container2");

    return product;
  }
View Full Code Here

   *
   * @param sku
   * @throws ServiceException
   */
  public void deleteWithEmptyCategory(String sku) throws ServiceException {
    Product product = getBySku(sku);
    List<Category> categories = product.getCategories();

    delete(sku);

    if (categories != null) {
      for (Category category : categories) {
View Full Code Here

        product.setConfigurableProductsData(new HashMap<String, Map<String, Object>>());

      for (ConfigurableProductData prdData : product
          .getConfigurableSubProducts()) {

        Product subprd = prdData.getProduct();

        // only save new simple products
        if (subprd.getId() == null
            && subprd.getType().equals(ProductTypeEnum.SIMPLE.getProductType()))
          this.save(subprd);

        product.getConfigurableProductsData().put(subprd.getId().toString(),
            prdData.serializeToApi());
      }
    }
  }
View Full Code Here

  /**
   * Support method for create a simple product
   * @return simple product
   */
  public static Product generateProduct() {
    Product product = generateProductWithoutImage();
   
    // add media
    try {
      byte[] data = MagjaFileUtils.getBytesFromFileURL("http://code.google.com/images/code_sm.png");
 
      Media image = new Media();
      image.setName("google");
      image.setMime("image/jpeg");
      image.setData(data);
 
      Set<ProductMedia.Type> types = new HashSet<ProductMedia.Type>();
      types.add(ProductMedia.Type.IMAGE);
      types.add(ProductMedia.Type.SMALL_IMAGE);
 
      ProductMedia media = new ProductMedia();
      media.setExclude(false);
      media.setImage(image);
      media.setLabel("Image for Product");
      media.setPosition(1);
      media.setTypes(types);
 
      product.addMedia(media);
    } catch(Exception e) {
      System.err.println("fail to add media to product");
    }

    return product;
View Full Code Here

TOP

Related Classes of com.google.code.magja.model.product.Product

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.