/** * Action to remove a price * @param price the price to remove including an ID * @return action */ public static RemovePrice of(final Price price) { return of(Optional.ofNullable(price.getId()).orElseThrow(() -> new IllegalArgumentException("Expected price with ID."))); }
public static ChangePrice of(final Price oldPrice, final PriceDraft price) { final String priceId = Optional.ofNullable(oldPrice.getId()) .orElseThrow(() -> new IllegalArgumentException("The old price should have an ID: " + oldPrice)); return of(priceId, price); }
public static ChangePrice of(final Price oldPrice, final PriceDraft price, @Nullable final Boolean staged) { final String priceId = Optional.ofNullable(oldPrice.getId()) .orElseThrow(() -> new IllegalArgumentException("The old price should have an ID: " + oldPrice)); return of(priceId, price, staged); }
public static ChangePrice of(final Price oldPrice, final PriceDraft price, @Nullable final Boolean staged) { final String priceId = Optional.ofNullable(oldPrice.getId()) .orElseThrow(() -> new IllegalArgumentException("The old price should have an ID: " + oldPrice)); return of(priceId, price, staged); }
public static RemovePrice of(final Price price, @Nullable final Boolean staged) { return of(Optional.ofNullable(price.getId()).orElseThrow(() -> new IllegalArgumentException("Expected price with ID.")), staged); }
public static RemovePrice of(final Price price, @Nullable final Boolean staged) { return of(Optional.ofNullable(price.getId()).orElseThrow(() -> new IllegalArgumentException("Expected price with ID.")), staged); }
@Test public void equalsIgnoreId() { final String jsonAsString = "{\n" + " \"id\": \"foo-id\",\n" + " \"value\": {\n" + " \"currencyCode\": \"EUR\",\n" + " \"centAmount\": 2800\n" + " }\n" + " }"; final Price price1 = SphereJsonUtils.readObject(jsonAsString, Price.class); final Price price2 = SphereJsonUtils.readObject(jsonAsString.replace("foo-id", "bar-id"), Price.class); assertThat(price1.getId()).isEqualTo("foo-id"); assertThat(price2.getId()).isEqualTo("bar-id"); assertThat(price1).isNotEqualTo(price2); assertThat(price1.equalsIgnoreId(price2)).isTrue(); } }
/** * 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()); } }
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 setProductPriceCustomTypeAndsetProductPriceCustomFieldWithStaged(final Boolean staged) { withUpdateableType(client(), type -> { withUpdateableProduct(client(), product -> { final ProductUpdateCommand command = ProductUpdateCommand.of(product, AddPrice.ofVariantId(1, PriceDraft.of(MoneyImpl.of(123, EUR)), false)); final Product productWithPrice = client().executeBlocking(command); assertThat(productWithPrice.getMasterData().hasStagedChanges()).isFalse(); final String priceId = getFirstPrice(productWithPrice).getId(); final UpdateAction<Product> updateAction = SetProductPriceCustomType. ofTypeIdAndObjects(type.getId(), STRING_FIELD_NAME, "a value", priceId, staged); final ProductUpdateCommand productUpdateCommand = ProductUpdateCommand.of(productWithPrice, updateAction); final Product updatedProduct = client().executeBlocking(productUpdateCommand); final Price price = getFirstPrice(updatedProduct); assertThat(price.getCustom().getFieldAsString(STRING_FIELD_NAME)) .isEqualTo("a value"); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); final Product updated2 = client().executeBlocking(ProductUpdateCommand.of(updatedProduct, SetProductPriceCustomField.ofObject(STRING_FIELD_NAME, "a new value", priceId, staged))); assertThat(getFirstPrice(updated2).getCustom().getFieldAsString(STRING_FIELD_NAME)) .isEqualTo("a new value"); assertThat(updated2.getMasterData().hasStagedChanges()).isEqualTo(staged); return updated2; }); return type; }); }
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); } }); }); }
assertThat(originalPrice.getDiscounted()).isNull(); final String priceId = originalPrice.getId(); final SetDiscountedPrice action = SetDiscountedPrice.of(priceId, DiscountedPrice.of(EURO_5, externalProductDiscount.toReference()));
@Test public void setProductPriceCustomTypeAndsetProductPriceCustomField() { withUpdateableType(client(), type -> { withUpdateablePricedProduct(client(), product -> { final String priceId = getFirstPrice(product).getId(); final UpdateAction<Product> updateAction = SetProductPriceCustomType. ofTypeIdAndObjects(type.getId(), STRING_FIELD_NAME, "a value", priceId); final ProductUpdateCommand productUpdateCommand = ProductUpdateCommand.of(product, updateAction); final Product updatedProduct = client().executeBlocking(productUpdateCommand); final Price price = getFirstPrice(updatedProduct); assertThat(price.getCustom().getFieldAsString(STRING_FIELD_NAME)) .isEqualTo("a value"); final Product updated2 = client().executeBlocking(ProductUpdateCommand.of(updatedProduct, SetProductPriceCustomField.ofObject(STRING_FIELD_NAME, "a new value", priceId))); assertThat(getFirstPrice(updated2).getCustom().getFieldAsString(STRING_FIELD_NAME)) .isEqualTo("a new value"); return updated2; }); return type; }); }
@Test public void lineItemModel() throws Exception { withFilledCart(client(), cart -> { final LineItem lineItem = cart.getLineItems().get(0); final String englishName = lineItem.getName().get(Locale.ENGLISH); final Price price = lineItem.getPrice(); final Long centAmount = price.getValue().query(MonetaryQueries.convertMinorPart()); final ItemState itemState = lineItem.getState().stream().findFirst().get(); final CartQuery query = CartQuery.of() .withLimit(1L) .withPredicates(m -> m.lineItems().id().is(lineItem.getId()) .and(m.lineItems().quantity().is(lineItem.getQuantity())) .and(m.lineItems().productId().is(lineItem.getProductId())) .and(m.lineItems().name().locale(ENGLISH).is(englishName)) .and(m.lineItems().variant().sku().is(lineItem.getVariant().getSku())) .and(m.lineItems().price().discounted().isNotPresent()) .and(m.lineItems().price().id().is(price.getId())) .and(m.lineItems().price().value().centAmount().is(centAmount)) .and(m.lineItems().price().country().is(price.getCountry())) .and(m.lineItems().state().quantity().is(itemState.getQuantity())) .and(m.lineItems().state().state().is(itemState.getState())) ); final CartQuery cartQuery = query.plusPredicates(m -> m.id().is(cart.getId())); final Cart loadedCart = client().executeBlocking(cartQuery).head().get(); assertThat(loadedCart.getId()).isEqualTo(cart.getId()); }); }