public static PriceBuilder of(final Price template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .discounted(template.getDiscounted()); }
public static PriceBuilder of(final Price template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .discounted(template.getDiscounted()); }
/** * Creates a new object initialized with the fields of the template parameter. * * @param template the template * @return a new object initialized from the template */ public static PriceBuilder of(final Price template) { return new PriceBuilder(template.getChannel(), template.getCountry(), template.getCustom(), template.getCustomerGroup(), template.getDiscounted(), template.getId(), template.getTiers(), template.getValidFrom(), template.getValidUntil(), template.getValue()); } }
@Test public void expandedDiscountedPrice() throws Exception { final Product product = SphereJsonUtils.readObjectFromResource("product-with-expanded-discounted-price.json", Product.typeReference()); final Price price = product.getMasterData().getStaged().getMasterVariant().getPrices().get(0); final DiscountedPrice discountedPrice = price.getDiscounted(); final ProductDiscount productDiscount = discountedPrice.getDiscount().getObj(); assertThat(productDiscount.getName().get(Locale.ENGLISH)).isEqualTo("demo product discount"); assertThat(productDiscount.getValue()).isInstanceOf(AbsoluteProductDiscountValue.class); }
public static PriceBuilder of(final Price template) { return of(template.getValue()) .country(template.getCountry()) .customerGroup(template.getCustomerGroup()) .channel(template.getChannel()) .discounted(template.getDiscounted()) .validFrom(template.getValidFrom()) .validUntil(template.getValidUntil()) .id(template.getId()); }
public void setDiscountedPriceWithStaged(final Boolean staged) { final ProductDiscountPredicate predicate = ProductDiscountPredicate.of("1 = 1");//can be used for all products final ProductDiscountDraft productDiscountDraft = ProductDiscountDraft.of(randomSlug(), randomSlug(), predicate, ExternalProductDiscountValue.of(), randomSortOrder(), true); //don't forget that one product discount can be used for multiple products withProductDiscount(client(), productDiscountDraft, externalProductDiscount -> { withProductOfPrices(client(), singletonList(PriceDraft.of(EURO_40)), product -> { final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); final Price originalPrice = publishedProduct.getMasterData().getStaged().getMasterVariant().getPrices().get(0); assertThat(originalPrice.getDiscounted()).isNull(); final String priceId = originalPrice.getId(); final SetDiscountedPrice action = SetDiscountedPrice.of(priceId, DiscountedPrice.of(EURO_5, externalProductDiscount.toReference()), staged); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, action)); final Price stagedPrice = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices().get(0); assertThat(stagedPrice.getValue()).isEqualTo(EURO_40); assertThat(stagedPrice.getDiscounted().getValue()).isEqualTo(EURO_5); assertThat(stagedPrice.getDiscounted().getDiscount()).isEqualTo(externalProductDiscount.toReference()); final Price currentPrice = updatedProduct.getMasterData().getCurrent().getMasterVariant().getPrices().get(0); if (staged) { assertThat(stagedPrice).isNotEqualTo(currentPrice); } else { assertThat(stagedPrice).isEqualTo(currentPrice); } }); }); }
withProductOfPrices(client(), singletonList(PriceDraft.of(EURO_40)), product -> { final Price originalPrice = product.getMasterData().getStaged().getMasterVariant().getPrices().get(0); assertThat(originalPrice.getDiscounted()).isNull(); final Price updatedPrice = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices().get(0); assertThat(updatedPrice.getValue()).isEqualTo(EURO_40); assertThat(updatedPrice.getDiscounted().getValue()).isEqualTo(EURO_5); assertThat(updatedPrice.getDiscounted().getDiscount()).isEqualTo(externalProductDiscount.toReference());
.matches(prices -> prices.stream().anyMatch(price -> price.getDiscounted() != null && price.getDiscounted().getDiscount().getObj() != null));
@Test public void sortByScopedPriceDiscounted() { withProductOfPrices(asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)), product1 -> { withProductOfPrices(asList(PriceDraft.of(EURO_30), PriceDraft.of(EURO_40).withCountry(DE)), product2 -> { final ProductDiscountDraft productDiscountDraft1 = discountDraftOfAbsoluteValue(product1, EURO_5); withProductDiscount(client(), productDiscountDraft1, productDiscount1 -> { assertEventually(s -> { //Products ordered by scopedPriceDiscounted (ascending) final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId()))) .plusSort(m -> m.allVariants().scopedPriceDiscounted().asc()); final PagedSearchResult<ProductProjection> results = client().executeBlocking(search); assertThat(results.getResults()).hasSize(2); s.assertThat(results.getResults()).extracting(ResourceView::getId).containsExactly(product2.getId(), product1.getId()); //Products ordered by scopedPriceDiscounted (descending) final ProductProjectionSearch searchDescending = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId()))) .plusSort(m -> m.allVariants().scopedPriceDiscounted().desc()); final PagedSearchResult<ProductProjection> resultsDescending = client().executeBlocking(searchDescending); assertThat(resultsDescending.getResults()).hasSize(2); s.assertThat(resultsDescending.getResults()).extracting(ResourceView::getId).containsExactly(product1.getId(), product2.getId()); assertThat(resultsDescending.getResults().get(0).getMasterVariant().getPrice().getDiscounted()).isNotNull(); }); }); }); }); }