@Override public List<ProductVariant> getVariants() { return productData.getVariants(); }
@Override public List<ProductVariant> getVariants() { return productData.getVariants(); }
@Override public List<ProductVariant> getVariants() { return productData.getVariants(); }
@Override public List<ProductVariant> getVariants() { return productData.getVariants(); }
@Override public List<ProductVariant> getVariants() { return productData.getVariants(); }
assertThat(product.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final ProductVariant variant = productWithVariant.getMasterData().getStaged().getVariants().get(0); assertThat(productWithVariant.getMasterData().hasStagedChanges()).isEqualTo(staged); assertThat(variant.getId()).isEqualTo(2); assertThat(productWithoutVariant.getMasterData().getStaged().getVariants()).isEmpty();
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 revertStagedVariantChanges() 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(); final Product revertedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithoutVariant,RevertStagedVariantChanges.of(variant.getId()))); assertThat(revertedProduct.getMasterData().getStaged().getVariants()).isNotEmpty(); assertThat(revertedProduct.getMasterData().hasStagedChanges()).isFalse(); return productWithoutVariant; }); }
@Test public void expandVariants() { CustomerGroupFixtures.withB2cCustomerGroup(client(), customerGroup -> ProductFixtures.withProductType(client(), randomString(), productType -> withProduct(client(), new VariantsCottonTShirtProductDraftSupplier(productType, randomString(), customerGroup), product -> { final PagedQueryResult<Product> result = client().executeBlocking(ProductQuery.of() .withPredicates(m -> m.id().is(product.getId())) .withExpansionPaths(m -> m.masterData().staged().variants().prices().customerGroup()) .withLimit(1L)); final Price priceWithCustomerGroup = result.head().get().getMasterData().getStaged().getVariants().get(0).getPrices().stream() .filter(price -> Objects.equals(price.getCustomerGroup(), customerGroup.toReference())) .findFirst().get(); assertThat(priceWithCustomerGroup.getCustomerGroup().getObj()).isNotNull().isEqualTo(customerGroup); }) ) ); }
assertThat(product.getMasterData().getStaged().getVariants()).isEmpty(); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final ProductVariant variant = productWithVariant.getMasterData().getStaged().getVariants().get(0); assertThat(productWithVariant.getMasterData().hasStagedChanges()).isTrue(); assertThat(variant.getId()).isEqualTo(2); assertThat(productWithoutVariant.getMasterData().getStaged().getVariants()).isEmpty();
final ProductVariant variant = productWithVariant.getMasterData().getStaged().getVariants().get(0);