@Test public void sortByCurrentScopedPrice() { final List<PriceDraft> prices1 = asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)); final List<PriceDraft> prices2 = asList(PriceDraft.of(EURO_30), PriceDraft.of(EURO_40).withCountry(DE)); final SortExpression<ProductProjection> sortExpression = ProductProjectionSearchModel.of().sort().allVariants().scopedPrice().currentValue().centAmount().asc(); sortCheck(prices1, prices2, sortExpression); }
@Test public void sortByValueScopedPrice() { final List<PriceDraft> prices1 = asList(PriceDraft.of(EURO_20), PriceDraft.of(EURO_30).withCountry(DE)); final List<PriceDraft> prices2 = asList(PriceDraft.of(EURO_30), PriceDraft.of(EURO_40).withCountry(DE)); final SortExpression<ProductProjection> sortExpression = ProductProjectionSearchModel.of().sort().allVariants().scopedPrice().value().centAmount().asc(); sortCheck(prices1, prices2, sortExpression); }
private void setPricesByVariantIdWithStaged(final Boolean staged) { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(123, EUR)); final PriceDraft priceDraft2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(DE); final List<PriceDraft> expectedPriceList = asList(priceDraft, priceDraft2); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.ofVariantId(1, expectedPriceList, staged))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); List<PriceDraft> draftPricesList = prices.stream().map(PriceDraft::of).collect(toList()); assertThat(draftPricesList).containsOnly(priceDraft, priceDraft2); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void setPricesWithAlreadyExisting() { final PriceDraft expectedPrice1 = PriceDraft.of(MoneyImpl.of(123, EUR)); final PriceDraft expectedPrice2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(CountryCode.DE); final List<PriceDraft> expectedPriceList = asList(expectedPrice1, expectedPrice2); withUpdateablePricedProduct(client(), expectedPrice1, product -> { Price oldPrice = product.getMasterData().getStaged().getMasterVariant().getPrices().get(0); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.of(1, expectedPriceList))); final List<Price> newPrices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(newPrices).hasSize(2); assertThat(newPrices).doesNotContain(oldPrice); List<PriceDraft> draftPricesList = newPrices.stream().map(PriceDraft::of).collect(toList()); assertThat(draftPricesList).contains(expectedPrice1, expectedPrice2); return updatedProduct; }); }
@Test public void setPricesByVariantId() throws Exception { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(123, EUR)); final PriceDraft priceDraft2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(DE); final List<PriceDraft> expectedPriceList = asList(priceDraft, priceDraft2); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.ofVariantId(1, expectedPriceList))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); List<PriceDraft> draftPricesList = prices.stream().map(PriceDraft::of).collect(toList()); assertThat(draftPricesList).containsOnly(priceDraft, priceDraft2); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
@Test public void canExpandCustomerGroupOfPrices() throws Exception { withCustomerGroup(client(), customerGroup -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withCustomerGroup(customerGroup), product -> { final ExpansionPath<Product> expansionPath = ProductExpansionModel.of().masterData().staged().masterVariant().prices().customerGroup().expansionPaths().get(0); final Query<Product> query = query(product).withExpansionPaths(expansionPath); final List<Price> prices = client().executeBlocking(query).head().get().getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getCustomerGroup()).map(customerGroupReference -> customerGroupReference.getObj() != null).orElse(false))) .isTrue(); return product; }); } ); }
public void setPricesBySkuWithStaged(final Boolean staged) { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(123, EUR)); final PriceDraft priceDraft2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(DE); final List<PriceDraft> expectedPriceList = asList(priceDraft, priceDraft2); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.ofSku(sku, expectedPriceList, staged))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); List<PriceDraft> draftPricesList = prices.stream().map(PriceDraft::of).collect(toList()); assertThat(draftPricesList).containsOnly(priceDraft, priceDraft2); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void canExpandChannelOfPrices() throws Exception { ChannelFixtures.withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withChannel(channel), product -> { final ExpansionPath<Product> expansionPath = ProductExpansionModel.of().masterData().staged().masterVariant().prices().channel().expansionPaths().get(0); final Query<Product> query = query(product).withExpansionPaths(expansionPath); final List<Price> prices = client().executeBlocking(query).head().get().getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getChannel()).map(channelRef -> channelRef.getObj() != null).orElse(false))) .isTrue(); return product; }); }); }
@Test public void expandCustomerGroupInPrice() throws Exception { withCustomerGroup(client(), customerGroup -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withCustomerGroup(customerGroup), product -> { final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(product.getId())) .withExpansionPaths(m -> m.masterVariant().prices().customerGroup()); final List<Price> prices = client().executeBlocking(query).head().get().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getCustomerGroup()).map(customerGroupReference -> customerGroupReference.getObj() != null).orElse(false))) .isTrue(); return product; }); } ); }
@Test public void expandChannelInPrice() throws Exception { ChannelFixtures.withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withChannel(channel), product -> { final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(product.getId())) .withExpansionPaths(m -> m.masterVariant().prices().channel()); final List<Price> prices = client().executeBlocking(query).head().get().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getChannel()).map(channelRef -> channelRef.getObj() != null).orElse(false))) .isTrue(); return product; }); }); }
@Test public void setPricesBySku() throws Exception { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(123, EUR)); final PriceDraft priceDraft2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(DE); final List<PriceDraft> expectedPriceList = asList(priceDraft, priceDraft2); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.ofSku(sku, expectedPriceList))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); List<PriceDraft> draftPricesList = prices.stream().map(PriceDraft::of).collect(toList()); assertThat(draftPricesList).containsOnly(priceDraft, priceDraft2); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
@Test public void setPrices() throws Exception { final PriceDraft expectedPrice1 = PriceDraft.of(MoneyImpl.of(123, EUR)); final PriceDraft expectedPrice2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(DE); final List<PriceTier> tiers = Arrays.asList(PriceTierBuilder.of(10, EURO_1).build()); final PriceDraft expectedPriceWithTiers = PriceDraftBuilder.of(MoneyImpl.of(123, EUR)) .country(CountryCode.AT) .tiers(tiers) .build(); final List<PriceDraft> expectedPriceList = asList(expectedPrice1, expectedPrice2, expectedPriceWithTiers); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.of(1, expectedPriceList))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); List<PriceDraft> draftPricesList = prices.stream().map(PriceDraft::of).collect(toList()); assertThat(draftPricesList).containsOnly(expectedPrice1, expectedPrice2, expectedPriceWithTiers); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
private static void withTaxedAndPricedProduct(final BlockingSphereClient client, final long centAmount, final double taxRate, final boolean taxIncluded, final Consumer<Product> operator) { final List<TaxRateDraft> taxRateDrafts = singletonList(TaxRateDraftBuilder.of(randomKey(), taxRate, taxIncluded, CountryCode.DE).build()); final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraft.of(randomString(), taxRateDrafts); withTaxCategory(client, taxCategoryDraft, taxCategory -> withProduct(client, product -> { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.ofCents(centAmount, EUR)).withCountry(DE); final ProductUpdateCommand setPricesCmd = ProductUpdateCommand.of(product, asList( AddPrice.of(MASTER_VARIANT_ID, priceDraft), SetTaxCategory.of(taxCategory), Publish.of())); final Product productWithPrice = client.executeBlocking(setPricesCmd); operator.accept(productWithPrice); }) ); } }
@Test public void filterByValueCentAmountAndCountry() { 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 ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId()))) .plusQueryFilters(m -> m.allVariants().scopedPrice().value() .centAmount().isLessThanOrEqualTo(3000L)); assertEventually(() -> { final PagedSearchResult<ProductProjection> result = client().executeBlocking(search); assertThat(result.getResults()).extracting(ResourceView::getId) .as("product1 with small price included").contains(product1.getId()) .as("product2 is expensive in the scope, not included").doesNotContain(product2.getId()); final ProductVariant masterVariant = result.getResults().get(0).getMasterVariant(); final Price price = masterVariant.getPrice(); assertThat(price).as("price").isNotNull(); assertThat(price.getValue()).isEqualTo(EURO_30); assertThat(masterVariant.getScopedPrice()).isNotNull(); assertThat(masterVariant.getScopedPrice().getValue()).as("scopedPrice").isEqualTo(EURO_30); }); }); }); }
private void removeVariantBySkuWithStaged(final Boolean staged) { final NamedAttributeAccess<MonetaryAmount> moneyAttribute = AttributeAccess.ofMoney().ofName(MONEY_ATTRIBUTE_NAME); final AttributeDraft moneyAttributeValue = AttributeDraft.of(moneyAttribute, EURO_10); final NamedAttributeAccess<LocalizedEnumValue> colorAttribute = Colors.ATTRIBUTE; final LocalizedEnumValue color = Colors.RED; final AttributeDraft colorAttributeValue = AttributeDraft.of(colorAttribute, color); final NamedAttributeAccess<EnumValue> sizeAttribute = Sizes.ATTRIBUTE; final AttributeDraft sizeValue = AttributeDraft.of(sizeAttribute, Sizes.M); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final PriceDraft price = PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE); final List<PriceDraft> prices = asList(price); final List<AttributeDraft> attributeValues = asList(moneyAttributeValue, colorAttributeValue, sizeValue); final ProductUpdateCommand addVariantCommand = ProductUpdateCommand.of(product, AddVariant.of(attributeValues, prices, randomKey(), false)); final Product productWithVariant = client().executeBlocking(addVariantCommand); final ProductVariant variant = productWithVariant.getMasterData().getStaged().getVariants().get(0); assertThat(productWithVariant.getMasterData().hasStagedChanges()).isFalse(); final Product productWithoutVariant = client().executeBlocking(ProductUpdateCommand.of(productWithVariant, RemoveVariant.ofSku(variant.getSku(), staged))); assertThat(productWithoutVariant.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(productWithoutVariant.getMasterData().hasStagedChanges()).isEqualTo(staged); return productWithoutVariant; }); }
private void removeVariantByIdWithStaged(final Boolean staged) { final NamedAttributeAccess<MonetaryAmount> moneyAttribute = AttributeAccess.ofMoney().ofName(MONEY_ATTRIBUTE_NAME); final AttributeDraft moneyAttributeValue = AttributeDraft.of(moneyAttribute, EURO_10); final NamedAttributeAccess<LocalizedEnumValue> colorAttribute = Colors.ATTRIBUTE; final LocalizedEnumValue color = Colors.RED; final AttributeDraft colorAttributeValue = AttributeDraft.of(colorAttribute, color); final NamedAttributeAccess<EnumValue> sizeAttribute = Sizes.ATTRIBUTE; final AttributeDraft sizeValue = AttributeDraft.of(sizeAttribute, Sizes.M); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final PriceDraft price = PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE); final List<PriceDraft> prices = asList(price); final List<AttributeDraft> attributeValues = asList(moneyAttributeValue, colorAttributeValue, sizeValue); final ProductUpdateCommand addVariantCommand = ProductUpdateCommand.of(product, AddVariant.of(attributeValues, prices, randomKey(), false)); final Product productWithVariant = client().executeBlocking(addVariantCommand); final ProductVariant variant = productWithVariant.getMasterData().getStaged().getVariants().get(0); assertThat(productWithVariant.getMasterData().hasStagedChanges()).isFalse(); final Product productWithoutVariant = client().executeBlocking(ProductUpdateCommand.of(productWithVariant, RemoveVariant.ofVariantId(variant.getId(), staged))); assertThat(productWithoutVariant.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(productWithoutVariant.getMasterData().hasStagedChanges()).isEqualTo(staged); return productWithoutVariant; }); }
@Test public void removeVariantById() throws Exception { final NamedAttributeAccess<MonetaryAmount> moneyAttribute = AttributeAccess.ofMoney().ofName(MONEY_ATTRIBUTE_NAME); final AttributeDraft moneyAttributeValue = AttributeDraft.of(moneyAttribute, EURO_10); final NamedAttributeAccess<LocalizedEnumValue> colorAttribute = Colors.ATTRIBUTE; final LocalizedEnumValue color = Colors.RED; final AttributeDraft colorAttributeValue = AttributeDraft.of(colorAttribute, color); final NamedAttributeAccess<EnumValue> sizeAttribute = Sizes.ATTRIBUTE; final AttributeDraft sizeValue = AttributeDraft.of(sizeAttribute, Sizes.M); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final PriceDraft price = PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE); final List<PriceDraft> prices = asList(price); final List<AttributeDraft> attributeValues = asList(moneyAttributeValue, colorAttributeValue, sizeValue); final ProductUpdateCommand addVariantCommand = ProductUpdateCommand.of(product, AddVariant.of(attributeValues, prices, randomKey(), false)); final Product productWithVariant = client().executeBlocking(addVariantCommand); final ProductVariant variant = productWithVariant.getMasterData().getStaged().getVariants().get(0); assertThat(productWithVariant.getMasterData().hasStagedChanges()).isFalse(); final Product productWithoutVariant = client().executeBlocking(ProductUpdateCommand.of(productWithVariant, RemoveVariant.ofVariantId(variant.getId()))); assertThat(productWithoutVariant.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(productWithoutVariant.getMasterData().hasStagedChanges()).isTrue(); return productWithoutVariant; }); }
@Test public void removeVariantBySku() throws Exception { final NamedAttributeAccess<MonetaryAmount> moneyAttribute = AttributeAccess.ofMoney().ofName(MONEY_ATTRIBUTE_NAME); final AttributeDraft moneyAttributeValue = AttributeDraft.of(moneyAttribute, EURO_10); final NamedAttributeAccess<LocalizedEnumValue> colorAttribute = Colors.ATTRIBUTE; final LocalizedEnumValue color = Colors.RED; final AttributeDraft colorAttributeValue = AttributeDraft.of(colorAttribute, color); final NamedAttributeAccess<EnumValue> sizeAttribute = Sizes.ATTRIBUTE; final AttributeDraft sizeValue = AttributeDraft.of(sizeAttribute, Sizes.M); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final PriceDraft price = PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE); final List<PriceDraft> prices = asList(price); final List<AttributeDraft> attributeValues = asList(moneyAttributeValue, colorAttributeValue, sizeValue); final ProductUpdateCommand addVariantCommand = ProductUpdateCommand.of(product, AddVariant.of(attributeValues, prices, randomKey(), false)); final Product productWithVariant = client().executeBlocking(addVariantCommand); final ProductVariant variant = productWithVariant.getMasterData().getStaged().getVariants().get(0); assertThat(productWithVariant.getMasterData().hasStagedChanges()).isFalse(); final Product productWithoutVariant = client().executeBlocking(ProductUpdateCommand.of(productWithVariant, RemoveVariant.ofSku(variant.getSku()))); assertThat(productWithoutVariant.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(productWithoutVariant.getMasterData().hasStagedChanges()).isTrue(); return productWithoutVariant; }); }
@Test public void facetSearchByScopedPriceDiscounted() { 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 -> { withProductOfPrices(asList(PriceDraft.of(EURO_40), PriceDraft.of(EURO_25).withCountry(DE)), product3 -> { final ProductDiscountDraft productDiscountDraft1 = discountDraftOfAbsoluteValue(product1, EURO_5); withProductDiscount(client(), productDiscountDraft1, productDiscount1 -> { assertEventually(s -> { final TermFacetExpression<ProductProjection> facetExpression = ProductProjectionSearchModel.of() .facet().allVariants().scopedPriceDiscounted().allTerms(); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .withPriceSelection(PriceSelection.of(EUR).withPriceCountry(DE)) .plusQueryFilters(m -> m.id().isIn(asList(product1.getId(), product2.getId(), product3.getId()))) .withFacets(facetExpression); final PagedSearchResult<ProductProjection> results = client().executeBlocking(search); assertThat(results.getResults()).hasSize(3); final List<TermStats> termStats = results.getFacetResult(facetExpression).getTerms(); s.assertThat(termStats).containsOnly( TermStats.of(BOOL_TRUE, 1L), TermStats.of(BOOL_FALSE, 2L)); }); }); }); }); }); }
@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(); }); }); }); }); }