public static SetShippingMethod of(@Nullable final Referenceable<ShippingMethod> shippingMethod) { return shippingMethod != null ? new SetShippingMethod(shippingMethod.toReference()) : ofRemove(); }
private CompletionStage<Cart> setShippingToCart(final Cart cart, final String shippingMethodId) { final Reference<ShippingMethod> shippingMethodRef = ShippingMethod.referenceOfId(shippingMethodId); final SetShippingMethod setShippingMethod = SetShippingMethod.of(shippingMethodRef); final CartUpdateCommand cmd = CartUpdateCommand.of(cart, setShippingMethod); return executeCartUpdateCommandWithHooks(cmd); } }
public static SetShippingMethod ofRemove() { return new SetShippingMethod(null); } }
@Test public void setShippingMethodById() throws Exception { withShippingMethodForGermany(client(), shippingMethod -> { withCart(client(), createCartWithShippingAddress(client()), cart -> { //add shipping method assertThat(cart.getShippingInfo()).isNull(); final CartUpdateCommand updateCommand = CartUpdateCommand.of(cart, SetShippingMethod.ofId(shippingMethod.getId())) .plusExpansionPaths(m -> m.shippingInfo().shippingMethod().taxCategory()) .plusExpansionPaths(m -> m.shippingInfo().taxCategory()); final Cart cartWithShippingMethod = client().executeBlocking(updateCommand); assertThat(cartWithShippingMethod.getShippingInfo().getShippingMethod()).isEqualTo(shippingMethod.toReference()); assertThat(cartWithShippingMethod.getShippingInfo().getShippingMethod().getObj()) .as("reference expansion shippingMethod") .isEqualTo(shippingMethod); //remove shipping method final Cart cartWithoutShippingMethod = client().executeBlocking(CartUpdateCommand.of(cartWithShippingMethod, SetShippingMethod.ofRemove())); assertThat(cartWithoutShippingMethod.getShippingInfo()).isNull(); return cartWithoutShippingMethod; }); }); }
@Test public void setShippingMethodDoesNotMatchCart() throws Exception { withDynamicShippingMethodForGermany(client(), CartPredicate.of("customer.email=\"john@example.com\""), shippingMethod -> { withCart(client(), createCartWithShippingAddress(client()), cart -> { final CartUpdateCommand updateCommand = CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod)); assertThatThrownBy(() -> client().executeBlocking(updateCommand)).isInstanceOf(ErrorResponseException.class).hasMessageContaining("does not match"); return cart; }); }); }
public static SetShippingMethod ofRemove() { return new SetShippingMethod(null); } }
public static SetShippingMethod of(@Nullable final Referenceable<ShippingMethod> shippingMethod) { return shippingMethod != null ? new SetShippingMethod(shippingMethod.toReference()) : ofRemove(); }
@Test public void setShippingMethodTaxAmount() throws Exception { withShippingMethodForGermany(client(), shippingMethod -> { withCustomLineItemFilledCartWithTaxMode(client(), TaxMode.EXTERNAL_AMOUNT, cart -> { final Cart cartWithShippingMethod = client().executeBlocking(CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod))); assertThat(cartWithShippingMethod.getShippingInfo()).isNotNull(); assertThat(cartWithShippingMethod.getShippingInfo().getTaxedPrice()).isNull(); final ExternalTaxRateDraft taxRate = ExternalTaxRateDraftBuilder .ofAmount(1.0, "Test Tax", CountryCode.DE) .build(); final MonetaryAmount totalGross = MoneyImpl.ofCents(100000, EUR); final ExternalTaxAmountDraftDsl taxAmountDraft = ExternalTaxAmountDraftBuilder .of(totalGross, taxRate) .build(); final SetShippingMethodTaxAmount setShippingMethodTaxAmount = SetShippingMethodTaxAmount.of(taxAmountDraft); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cartWithShippingMethod, setShippingMethodTaxAmount)); final TaxedItemPrice taxedPrice = updatedCart.getShippingInfo().getTaxedPrice(); assertThat(taxedPrice.getTotalGross()).isEqualTo(totalGross); return updatedCart; }); }); }
public static SetShippingMethod ofRemove() { return new SetShippingMethod(null); } }
@Test public void setShippingMethod() throws Exception { withShippingMethodForGermany(client(), shippingMethod -> { withCart(client(), createCartWithShippingAddress(client()), cart -> { //add shipping method assertThat(cart.getShippingInfo()).isNull(); final CartUpdateCommand updateCommand = CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod)) .plusExpansionPaths(m -> m.shippingInfo().shippingMethod().taxCategory()) .plusExpansionPaths(m -> m.shippingInfo().taxCategory()); final Cart cartWithShippingMethod = client().executeBlocking(updateCommand); assertThat(cartWithShippingMethod.getShippingInfo().getShippingMethodState()).isEqualTo(ShippingMethodState.MATCHES_CART); assertThat(cartWithShippingMethod.getShippingInfo().getShippingMethod()).isEqualTo(shippingMethod.toReference()); assertThat(cartWithShippingMethod.getShippingInfo().getShippingMethod().getObj()) .as("reference expansion shippingMethod") .isEqualTo(shippingMethod); assertThat(cartWithShippingMethod.getShippingInfo().getShippingMethod().getObj().getTaxCategory().getObj()) .as("reference expansion taxCategory") .isEqualTo(cartWithShippingMethod.getShippingInfo().getTaxCategory().getObj()) .isNotNull(); //remove shipping method final Cart cartWithoutShippingMethod = client().executeBlocking(CartUpdateCommand.of(cartWithShippingMethod, SetShippingMethod.ofRemove())); assertThat(cartWithoutShippingMethod.getShippingInfo()).isNull(); return cartWithoutShippingMethod; }); }); }
public static SetShippingMethod of(@Nullable final Referenceable<ShippingMethod> shippingMethod) { return shippingMethod != null ? new SetShippingMethod(shippingMethod.toReference()) : ofRemove(); }
withShippingMethodForGermany(client(), shippingMethod -> { withCustomerAndFilledCart(client(), (customer, cart) -> { client().executeBlocking(CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod))); CartDiscountFixtures.withCartDiscount(client(), builder -> builder .value(RelativeCartDiscountValue.of(10000))
public static SetShippingMethod of(final Referenceable<ShippingMethod> shippingMethod) { return new SetShippingMethod(shippingMethod.toReference()); } }
withCustomer(client(), customer -> { withCartHavingDiscountedCustomLineItem(client(),relativeCartDiscountValue, cart -> { client().executeBlocking(CartUpdateCommand.of(cart, Arrays.asList(SetShippingAddress.of(Address.of(CountryCode.DE)),SetShippingMethod.of(shippingMethod)))); withCartDiscount(client(), builder -> builder .value(relativeCartDiscountValue)
@Test public void shippingDiscount() { withShippingMethodForGermany(client(), shippingMethod -> { withCustomerAndFilledCart(client(), (customer, cart) -> { client().executeBlocking(CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod))); CartDiscountFixtures.withCartDiscount(client(), builder -> builder .value(RelativeCartDiscountValue.of(10000)) .target(ShippingCostTarget.of()) .cartPredicate(CartPredicate.of("customer.id =\"" + customer.getId() + "\"")), cartDiscount -> { assertEventually(() -> { final Versioned<Cart> cartVersion = client().executeBlocking(CartByIdGet.of(cart)); final CartUpdateCommand cmd = CartUpdateCommand.of(cartVersion, Recalculate.of().withUpdateProductData(true)) .withExpansionPaths(c -> c.shippingInfo().discountedPrice().includedDiscounts().discount()); final Cart loadedCart = client().executeBlocking(cmd); final DiscountedLineItemPrice discountedPrice = loadedCart.getShippingInfo().getDiscountedPrice(); assertThat(discountedPrice).isNotNull(); final MonetaryAmount value = discountedPrice.getValue(); assertThat(value).isEqualTo(MoneyImpl.of(0, EUR)); final Reference<CartDiscount> discount = discountedPrice.getIncludedDiscounts().get(0).getDiscount(); assertThat(discount.getObj()).isNotNull().isEqualTo(cartDiscount); }); }); final Cart cartToDelete = client().executeBlocking(CartByIdGet.of(cart)); client().executeBlocking(CartDeleteCommand.of(cartToDelete)); }); }); }
@Test public void shippingMethodQuery() throws Exception { withShippingMethodForGermany(client(), shippingMethod -> { withCart(client(), createCartWithShippingAddress(client()), cart -> { final CartUpdateCommand updateCommand = CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod)) .plusExpansionPaths(m -> m.shippingInfo().shippingMethod().taxCategory()) .plusExpansionPaths(m -> m.shippingInfo().taxCategory()); final Cart cartWithShippingMethod = client().executeBlocking(updateCommand); final CartShippingInfo shippingInfo = cartWithShippingMethod.getShippingInfo(); final CartQuery query = CartQuery.of() .plusPredicates(m -> m.id().is(cart.getId())) .plusPredicates(m -> m.shippingInfo().shippingMethodName().is(shippingMethod.getName())) .plusPredicates(m -> m.shippingInfo().price().centAmount().is(MoneyImpl.centAmountOf(shippingInfo.getPrice()))) .plusPredicates(m -> m.shippingInfo().taxRate().name().is(shippingInfo.getTaxRate().getName())) .plusPredicates(m -> m.shippingInfo().taxRate().includedInPrice().is(shippingInfo.getTaxRate().isIncludedInPrice())) .plusPredicates(m -> m.shippingInfo().taxRate().country().is(shippingInfo.getTaxRate().getCountry())) .plusPredicates(m -> m.shippingInfo().shippingMethod().is(shippingMethod)) .plusPredicates(m -> m.shippingInfo().discountedPrice().isNotPresent()); assertThat(client().executeBlocking(query).head().get()).isEqualTo(cartWithShippingMethod); return cartWithShippingMethod; }); }); }