public final class SetShippingMethod extends UpdateActionImpl<Cart>
See also CartInStoreUpdateCommand.
withShippingMethodForGermany(client(), shippingMethod -> {
withCart(client(), createCartWithShippingAddress(client()), cart -> {
//add shipping method
assertThat(cart.getShippingInfo()).isNull();
final CartUpdateCommand updateCommand =
CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod.toResourceIdentifier()))
.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;
});
});
See the test code.
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;
});
});
See the test code.
Modifier and Type | Method and Description |
---|---|
ResourceIdentifier<ShippingMethod> |
getShippingMethod() |
static SetShippingMethod |
of(ResourceIdentifier<ShippingMethod> shippingMethod) |
static SetShippingMethod |
ofId(String shippingMethodId) |
static SetShippingMethod |
ofReferencable(Referenceable<ShippingMethod> shippingMethod)
Deprecated.
|
static SetShippingMethod |
ofRemove() |
getAction
@Nullable public ResourceIdentifier<ShippingMethod> getShippingMethod()
@Deprecated public static SetShippingMethod ofReferencable(@Nullable Referenceable<ShippingMethod> shippingMethod)
of(ResourceIdentifier)
public static SetShippingMethod of(@Nullable ResourceIdentifier<ShippingMethod> shippingMethod)
public static SetShippingMethod ofId(@Nullable String shippingMethodId)
public static SetShippingMethod ofRemove()