/**
   * HW2110-0019(base product): 381.64 Euro, and HW2200-0561(partner product): 86.80 Euro. The
   * ProductOneToOnePerfectPartnerPromotion will be fired if both of them are in the cart and the
   * price is 700 Euro.
   *
   * <ul>
   *   <li>adds the HW2110-0019 in cart, and tests the total price,
   *   <li>updates with the ProductOneToOnePerfectPartnerPromotion, and checks the total price,
   *   <li>now adds the HW2200-0561, and checks the total price,
   *   <li>updates with the ProductOneToOnePerfectPartnerPromotion that should be fired now, and
   *       checks the total price.
   * </ul>
   */
  @Test
  public void testProductOneToOnePerfectPartnerPromotion() throws CalculationException {
    cart = cartService.getSessionCart();
    cartService.addNewEntry(cart, baseProduct, 1, baseProduct.getUnit());
    modelService.save(cart);
    calculationService.calculate(cart);
    assertEquals(
        "before updatePromotions(ProductOneToOnePerfectPartnerPromotion)",
        381.64d,
        cart.getTotalPrice().doubleValue(),
        0.01);

    promotionGroup = promotionsService.getPromotionGroup("prGroup5");
    final Collection<PromotionGroupModel> promotionGroups = new ArrayList<PromotionGroupModel>();
    promotionGroups.add(promotionGroup);
    promotionsService.updatePromotions(
        promotionGroups, cart, false, AutoApplyMode.APPLY_ALL, AutoApplyMode.APPLY_ALL, new Date());
    modelService.refresh(cart);
    assertEquals("without partner product", 381.64d, cart.getTotalPrice().doubleValue(), 0.01);

    cartService.addNewEntry(cart, partnerProduct, 1, partnerProduct.getUnit());
    modelService.saveAll();
    calculationService.calculate(cart);
    assertEquals(
        "with partner product, but without promotion",
        468.44d,
        cart.getTotalPrice().doubleValue(),
        0.01);

    promotionsService.updatePromotions(
        promotionGroups, cart, false, AutoApplyMode.APPLY_ALL, AutoApplyMode.APPLY_ALL, new Date());
    modelService.refresh(cart);
    assertEquals("with partner product now", 400.00d, cart.getTotalPrice().doubleValue(), 0.01);
  }
  @Test
  public void testReferencesForPurchasedInCategory() {
    final UserModel user = userService.getUserForUID("dejol");
    final CategoryModel category = categoryService.getCategoryForCode("cameras");

    List<ProductModel> result =
        b2bSimpleSuggestionService.getReferencesForPurchasedInCategory(
            category, user, Collections.EMPTY_LIST, false, null);
    Assert.assertEquals(4, result.size());
    result =
        b2bSimpleSuggestionService.getReferencesForPurchasedInCategory(
            category, user, Collections.EMPTY_LIST, false, NumberUtils.INTEGER_ONE);
    Assert.assertEquals(1, result.size());
    result =
        b2bSimpleSuggestionService.getReferencesForPurchasedInCategory(
            category, user, Arrays.asList(ProductReferenceTypeEnum.SIMILAR), false, null);
    Assert.assertEquals(1, result.size());
    result =
        b2bSimpleSuggestionService.getReferencesForPurchasedInCategory(
            category, user, Arrays.asList(ProductReferenceTypeEnum.ACCESSORIES), false, null);
    Assert.assertEquals(2, result.size());
    result =
        b2bSimpleSuggestionService.getReferencesForPurchasedInCategory(
            category, user, Arrays.asList(ProductReferenceTypeEnum.ACCESSORIES), true, null);
    Assert.assertEquals(1, result.size());
    final ProductModel product = result.get(0);
    Assert.assertEquals("adapterDC", product.getCode());
    Assert.assertEquals("adapter", product.getName());
  }
Ejemplo n.º 3
0
 @Test
 public void testPrice() throws Exception {
   processFile(productId, "base_product-", new ProductContent());
   TestUtils.disableFileAnalyzer("");
   try {
     final ProductModel product =
         processFile(
             productId,
             "price-",
             new FileContent() {
               @Override
               public void writeContent(final PrintWriter writer) throws IOException {
                 writer.print("1231");
                 writer.print(SEPARATOR);
                 writer.println("EUR");
               }
             });
     Assert.assertEquals(1, product.getEurope1Prices().size());
     final PriceRowModel prize = product.getEurope1Prices().iterator().next();
     Assert.assertEquals("EUR", prize.getCurrency().getIsocode());
     Assert.assertEquals(Double.valueOf(1231), prize.getPrice());
     Assert.assertFalse(prize.getNet().booleanValue());
     Assert.assertEquals("pieces", prize.getUnit().getCode());
     Assert.assertEquals(Integer.valueOf(1), prize.getUnitFactor());
     Assert.assertEquals(Long.valueOf(1), prize.getMinqtd());
     Assert.assertEquals(sequenceId, prize.getSequenceId());
     Assert.assertEquals("Staged", prize.getCatalogVersion().getVersion());
     Assert.assertEquals("apparelProductCatalog", prize.getCatalogVersion().getCatalog().getId());
   } finally {
     TestUtils.enableFileAnalyzer();
   }
 }
  /** {@inheritDoc} */
  @Override
  public Map<String, Collection<Object>> getAssignedVariantAttributes(
      final ProductModel baseProduct) {
    validateParameterNotNullStandardMessage("baseProduct", baseProduct);

    final Map<String, Collection<Object>> result = new HashMap<String, Collection<Object>>();
    final Collection<VariantProductModel> variantModelList = baseProduct.getVariants();
    final List<VariantAttributeDescriptorModel> vadList =
        getVariantAttributesForVariantType(baseProduct.getVariantType());

    // iterate trough all variants to get the qualifier with appropriate values
    for (final VariantProductModel variant : variantModelList) {
      for (final VariantAttributeDescriptorModel item : vadList) {

        Collection values = result.get(item.getQualifier());
        if (values == null) {
          values = new LinkedHashSet();
          result.put(item.getQualifier(), values);
        }

        // there is no chance to read the attribute value in SL, because it"s not a part of the
        // model.
        //	final Object value = variant.getAttributeProvider().getAttribute(item.getQualifier());
        // Currently the jalo-solution has to be used

        values.add(getVariantAttributeValue(variant, item.getQualifier()));
      }
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug(result.size() + " variant attributes with assigned values found");
    }

    return result;
  }
 @Test
 public void searchRestrictionTest() {
   final UserGroupModel group = new UserGroupModel();
   group.setUid("customergroup");
   modelService.save(group);
   // create test user
   final UserModel user = new UserModel();
   user.setUid(TEST_USER);
   // assign user to customergroup
   user.setGroups(Collections.singleton((PrincipalGroupModel) group));
   modelService.save(user);
   // create test catalog
   final CatalogModel catalog = new CatalogModel();
   catalog.setId(TEST_CATALOG);
   modelService.save(catalog);
   // create test catalog version
   final CatalogVersionModel catalogVersion = new CatalogVersionModel();
   catalogVersion.setCatalog(catalog);
   catalogVersion.setVersion(TEST_VERSION);
   modelService.save(catalogVersion);
   // create test product
   final ProductModel product = new ProductModel();
   product.setCode(TEST_PRODUCT);
   product.setCatalogVersion(catalogVersion);
   modelService.save(product);
   // set current user
   userService.setCurrentUser(user);
   // create search restriction
   commonI18NService.setCurrentLanguage(commonI18NService.getLanguage(LANG_EN));
   final Map<String, String[]> params = new HashMap<String, String[]>();
   params.put("customerreview.searchrestrictions.create", new String[] {"true"});
   final SystemSetupContext ctx =
       new SystemSetupContext(params, Type.ESSENTIAL, Process.ALL, "customerreview");
   customerReviewSystemSetup.createSearchRestrictions(ctx);
   // enable search restrictions
   searchRestrictionService.enableSearchRestrictions();
   // make sure that number of customer reviews is 0
   assertEquals(
       INVALID_NUMBER_OF_CUSTOMER_REVIEWS,
       Integer.valueOf(0),
       customerReviewService.getNumberOfReviews(product));
   // create restricted customer review
   createCustomerReview(null, user, product, CustomerReviewApprovalType.PENDING);
   // create valid customer review
   createCustomerReview("headline", user, product, CustomerReviewApprovalType.APPROVED);
   // make sure that number of customer reviews is 1
   assertEquals(
       INVALID_NUMBER_OF_CUSTOMER_REVIEWS,
       Integer.valueOf(1),
       customerReviewService.getNumberOfReviews(product));
   // disable search restrictions
   searchRestrictionService.disableSearchRestrictions();
   // make sure that number of customer reviews is 2
   assertEquals(
       INVALID_NUMBER_OF_CUSTOMER_REVIEWS,
       Integer.valueOf(2),
       customerReviewService.getNumberOfReviews(product));
 }
  /** {@inheritDoc} */
  @Override
  public Collection<VariantProductModel> getVariantProductForAttributeValues(
      final ProductModel baseProduct, final Map<String, Object> filterValues) {
    validateParameterNotNullStandardMessage("baseProduct", baseProduct);

    final Collection<VariantProductModel> result = new ArrayList<VariantProductModel>();
    final List<VariantAttributeDescriptorModel> vadList =
        getVariantAttributesForVariantType(baseProduct.getVariantType());
    final Collection<VariantProductModel> allBaseProductVariants = baseProduct.getVariants();

    if (filterValues == null || filterValues.isEmpty()) {
      // no filter defined - no results.
      if (LOG.isDebugEnabled()) {
        LOG.debug("The filter values haven't been set, no matching variants in cases like this.");
      }
      return result;
    }

    // iterate through all variants and filter those with matching qualifier and values
    for (final VariantProductModel variant : allBaseProductVariants) {
      boolean add = true;
      for (final Iterator<Map.Entry<String, Object>> iterator = filterValues.entrySet().iterator();
          iterator.hasNext(); ) {
        if (!add) {
          break; // the filter element, which has been checked doesn't match, skip checking of
                 // addtional filter elements, go to next variant.
        }
        final Map.Entry entry = iterator.next();
        final String filterKey = (String) entry.getKey();
        final Object filterValue = entry.getValue();
        //	compare the filterKey and filterValue with all attributes (qualifier-value) of the
        // variantType.
        for (final VariantAttributeDescriptorModel attrDesc : vadList) {
          final String qualifier = attrDesc.getQualifier();
          final Object variantAttributeValue = getVariantAttributeValue(variant, qualifier);

          if (!(filterKey.equals(qualifier)
              && (filterValue == variantAttributeValue
                  || (filterValue != null && filterValue.equals(variantAttributeValue))))) {
            add = false;
          } else {
            add =
                true; // the current filter key and values matches for the current variant, go to
                      // next filter-element to check it.
            break;
          }
        }
      }
      if (add) {
        result.add(variant);
      }
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug(result.size() + " matching variants have been found.");
    }
    return result;
  }
  @Override
  public void populate(final ProductModel source, final ProductData target) {
    Assert.notNull(source, "Parameter source cannot be null.");
    Assert.notNull(target, "Parameter target cannot be null.");

    target.setCode(source.getCode());
    target.setName(source.getName());
    target.setUrl(getProductModelUrlResolver().resolve(source));
  }
Ejemplo n.º 8
0
 @Test
 public void testTax() throws Exception {
   processFile(productId, "base_product-", new ProductContent());
   final ProductModel product =
       processFile(
           productId,
           "tax-",
           new FileContent() {
             @Override
             public void writeContent(final PrintWriter writer) throws IOException {
               writer.println("eu-vat-full");
             }
           });
   final ProductTaxGroup taxGroup = product.getEurope1PriceFactory_PTG();
   Assert.assertEquals("eu-vat-full", taxGroup.getCode());
 }
  protected void configure() {
    variantProductSource = new VariantProductSource();

    given(model.getBaseProduct()).willReturn(baseProduct);
    given(baseProduct.getVariants()).willReturn(Sets.newHashSet(variant3));
    given(model.getVariants()).willReturn(Sets.newHashSet(variant1, variant2));
  }
  /** Creates some attachments and assigns them to the test workflow. */
  @Test
  public void testAttachments() {
    final CatalogVersionModel testCv =
        catalogVersionService.getCatalogVersion("DefaultTestCatalog", "Online");
    assertNotNull(testCv);

    final PK workflowPk = testWorkflow.getPk();
    // create product attachment
    final ProductModel product = modelService.create(ProductModel.class);
    product.setCode("abc");

    product.setCatalogVersion(testCv);

    modelService.save(product);
    assertNotNull("Product not null", product);

    final WorkflowItemAttachmentModel attachProduct =
        createAttachment("productTest", product, testWorkflow);
    assertNotNull("Attachment not null", attachProduct);

    // create category attachment
    final CategoryModel category = modelService.create(CategoryModel.class);
    category.setCode("abc");
    category.setCatalogVersion(testCv);
    assertNotNull("Category not null", category);

    final WorkflowItemAttachmentModel attachCategory =
        createAttachment("categoryTest", category, testWorkflow);
    assertNotNull("Attachment not null", attachCategory);

    final WorkflowActionModel action1 = getAction(ACTIONCODES.ACTION1.name());
    action1.setAttachments(
        Arrays.asList(new WorkflowItemAttachmentModel[] {attachProduct, attachCategory}));

    clearCache();

    // check attachments
    final WorkflowModel found = modelService.get(workflowPk);
    assertEquals("Excpected number of attachments", 2, found.getAttachments().size());
    final WorkflowActionModel foundAction = getAction(ACTIONCODES.ACTION1.name());
    assertEquals(
        "Excpected number of attachments of action 1", 2, foundAction.getAttachments().size());
  }
  /**
   * Tests promotion with voucher that has product restriction. (currency is Euro)
   *
   * <ul>
   *   <li>product(HW1230-0001) price = 769.00 --> 2x = 1538.00
   *   <li>product(HW2110-0012) price = 81.08 --> 2x = 162.16
   *   <li>so the cart contains products that cost 1700.16 Euro without promotion/voucher.
   *   <li>redeems the voucher that is 10% discount with product restriction: only valid for
   *       [HW1230-0001]
   *   <li>applies the fixed price promotion that is only valid for [HW1230-0001], and the fixed
   *       price is 500
   *   <li>update promotions, and the total discount should be (500 * 2) * 10% = 100
   *   <li>total price of the cart: (500 * 2 + 81.08 * 2) - 100 = 1062.16
   * </ul>
   */
  @Test
  public void testPromotionWithProductRestrictionVoucher()
      throws CalculationException, JaloPriceFactoryException {
    // PRO-70
    promotionGroup = promotionsService.getPromotionGroup("prGroup20");
    final ProductModel productSony = productService.getProductForCode(catVersion, "HW1230-0001");

    cartService.addNewEntry(cart, productSony, 2, productSony.getUnit());
    cartService.addNewEntry(cart, product1, 2, product1.getUnit());
    modelService.save(cart);
    calculationService.calculate(cart);
    modelService.refresh(cart);
    assertEquals(
        "should be 1700.16 euro without promotion/voucher",
        1700.16,
        cart.getTotalPrice().doubleValue(),
        0.01);

    voucherService.redeemVoucher(restrictionProductVoucher, cart);
    modelService.save(cart);

    final List<PromotionGroupModel> groups = new ArrayList<PromotionGroupModel>();
    groups.add(promotionGroup);
    promotionsService.updatePromotions(
        groups,
        cart,
        false,
        AutoApplyMode.APPLY_ALL,
        AutoApplyMode.APPLY_ALL,
        new java.util.Date());
    modelService.refresh(cart);
    assertEquals(
        "should be 100 euro for fixed price discount",
        100.0,
        cart.getTotalDiscounts().doubleValue(),
        0.01);
    assertEquals(
        "should be 1062.16 euro for total", 1062.16, cart.getTotalPrice().doubleValue(), 0.01);
  }
Ejemplo n.º 12
0
 @Test
 public void testVariant() throws Exception {
   processFile(
       productId,
       "base_product-",
       new ProductContent() {
         @Override
         public void writeContent(final PrintWriter writer) throws IOException {
           writer.print("ApparelSizeVariantProduct");
           super.writeContent(writer);
         }
       });
   final Long variantId = Long.valueOf(Math.abs((long) random.nextInt()));
   final ProductModel product =
       processFile(
           productId,
           "variant-",
           new FileContent() {
             @Override
             public void writeContent(final PrintWriter writer) throws IOException {
               writer.print(variantId);
               writer.print(SEPARATOR);
               writer.print(SEPARATOR);
               writer.print("black");
               writer.print(SEPARATOR);
               writer.print("L");
             }
           });
   final ApparelSizeVariantProductModel variant =
       (ApparelSizeVariantProductModel) productService.getProductForCode(variantId.toString());
   Assert.assertEquals("ApparelSizeVariantProduct", product.getVariantType().getCode());
   Assert.assertEquals(product, variant.getBaseProduct());
   Assert.assertEquals("black", variant.getStyle(Locale.ENGLISH));
   Assert.assertNull(variant.getStyle(Locale.GERMAN));
   Assert.assertEquals("L", variant.getSize(Locale.ENGLISH));
   Assert.assertNull(variant.getSize(Locale.GERMAN));
 }
Ejemplo n.º 13
0
 @Test
 public void testMerchandise() throws Exception {
   processFile(productId, "base_product-", new ProductContent());
   final ProductModel product =
       processFile(
           productId,
           "merchandise-",
           new FileContent() {
             @Override
             public void writeContent(final PrintWriter writer) throws IOException {
               writer.print("CROSSELLING");
               writer.print(SEPARATOR);
               writer.println(productId);
             }
           });
   Assert.assertEquals(1, product.getProductReferences().size());
   final ProductReferenceModel ref = product.getProductReferences().iterator().next();
   Assert.assertEquals("CROSSELLING", ref.getReferenceType().getCode());
   Assert.assertEquals(productId.toString(), ref.getTarget().getCode());
   Assert.assertEquals(Boolean.TRUE, ref.getActive());
   Assert.assertEquals(Boolean.FALSE, ref.getPreselected());
   Assert.assertEquals(product, ref.getSource());
   Assert.assertEquals(product, ref.getTarget());
 }
Ejemplo n.º 14
0
 @Test
 public void testMedia() throws Exception {
   processFile(productId, "base_product-", new ProductContent());
   final ProductModel product =
       processFile(
           productId,
           "media-",
           new FileContent() {
             @Override
             public void writeContent(final PrintWriter writer) throws IOException {
               writer.println("test.jpg");
             }
           });
   verifyMedia(product.getPicture(), "300Wx300H");
   verifyMedia(product.getThumbnail(), "96Wx96H");
   verifyMedia(product.getThumbnails().iterator().next(), "96Wx96H");
   verifyMedia(product.getDetail().iterator().next(), "1200Wx1200H");
   for (final MediaModel media : product.getOthers()) {
     if ("515Wx515H".equals(media.getMediaFormat().getQualifier())) {
       verifyMedia(media, "515Wx515H");
     } else if ("96Wx96H".equals(media.getMediaFormat().getQualifier())) {
       verifyMedia(media, "96Wx96H");
     } else {
       verifyMedia(media, "30Wx30H");
     }
   }
   verifyMedia(product.getNormal().iterator().next(), "300Wx300H");
   final MediaContainerModel container = product.getGalleryImages().iterator().next();
   final Set<String> formats = new HashSet<String>();
   formats.add("30Wx30H");
   formats.add("65Wx65H");
   formats.add("96Wx96H");
   formats.add("300Wx300H");
   formats.add("515Wx515H");
   formats.add("1200Wx1200H");
   final Set<String> containerFormats = new HashSet<String>();
   for (final MediaModel media : container.getMedias()) {
     containerFormats.add(media.getMediaFormat().getQualifier());
   }
   Assert.assertEquals(formats, containerFormats);
   Assert.assertEquals("Staged", container.getCatalogVersion().getVersion());
   Assert.assertEquals(
       "apparelProductCatalog", container.getCatalogVersion().getCatalog().getId());
 }
  /**
   * Puts two products in the cart, applies one 10% product promotion, and redeems
   *
   * <ul>
   *   <li>1. one voucher without free shipping or
   *   <li>2. one voucher with free shipping or
   *   <li>3. two vouchers, one with free shipping and the other one without.
   * </ul>
   */
  @Test
  public void testPromotionWithVoucher() throws JaloPriceFactoryException {
    // PRO-64
    promotionGroup = promotionsService.getPromotionGroup("prGroup10");
    final List<PromotionGroupModel> groups = new ArrayList<PromotionGroupModel>();
    groups.add(promotionGroup);

    cartService.addNewEntry(cart, product1, 2, product1.getUnit());
    deliveryModeDhl = deliveryModeService.getDeliveryModeForCode("dhl");
    cart.setDeliveryMode(deliveryModeDhl);
    cart.setDeliveryAddress(user.getDefaultShipmentAddress());

    /**
     * General information:
     *
     * <ul>
     *   <li>product(HW2110-0012) price = 81.08 --> 2x = 162.16, delivery cost 8.0, totally 170.16
     *   <li>applied 10% ProductPercentageDiscountPromotion, 162.16 * 0.9 = 145.94
     * </ul>
     *
     * Three different situations with vouchers:
     *
     * <ul>
     *   <li>1. 5% voucher without free shipping, 145.94 * 0.95 = 138.64, delivery cost 8.0, totally
     *       146.64
     *   <li>2. 20% voucher with free shipping, 145.94 * 0.8 = 116.75, free shipping, totally 116.75
     *   <li>3. both the vouchers above, 145.94 * (1 - 0.05 - 0.20) = 109.45, free shipping, totally
     *       109.45
     * </ul>
     */
    applyVouchersAndPromotions(new String[] {voucherCode}, groups, 146.64);

    applyVouchersAndPromotions(new String[] {freeShippingVoucherCode}, groups, 116.75);

    applyVouchersAndPromotions(new String[] {voucherCode, freeShippingVoucherCode}, groups, 109.45);
  }
Ejemplo n.º 16
0
 @Test
 public void testBasicProduct() throws Exception {
   final ProductModel product = processFile(productId, "base_product-", new ProductContent());
   Assert.assertEquals("name", product.getName(Locale.ENGLISH));
   Assert.assertNull("name", product.getName(Locale.GERMAN));
   Assert.assertEquals("description", product.getDescription(Locale.ENGLISH));
   Assert.assertNull("description", product.getDescription(Locale.GERMAN));
   Assert.assertEquals("ean", product.getEan());
   Assert.assertEquals("manufacturer", product.getManufacturerName());
   Assert.assertEquals("manufacturerAID", product.getManufacturerAID());
   Assert.assertEquals("pieces", product.getUnit().getName());
   Assert.assertEquals("approved", product.getApprovalStatus().getCode());
   Assert.assertEquals("eu-vat-half", product.getEurope1PriceFactory_PTG().getCode());
   Assert.assertEquals(sequenceId, product.getSequenceId());
   Assert.assertEquals("Staged", product.getCatalogVersion().getVersion());
   Assert.assertEquals("apparelProductCatalog", product.getCatalogVersion().getCatalog().getId());
 }