public final class CustomerSignInCommand extends CommandImpl<CustomerSignInResult>
CustomerCreatePasswordTokenCommand
.
Example for a simple sign in without any carts involved:
withCustomer(client(), customer -> { final CustomerSignInResult result = client().executeBlocking(CustomerSignInCommand.of(customer.getEmail(), PASSWORD)); assertThat(result.getCustomer()).isEqualTo(customer); });
See the test code.
Example for a signin where the customer has a cart and signs in with an anonymous cart
withCustomerCustomerCartAndAnonymousCart(client(), customer -> customersCart -> anonymousCart -> { assertThat(customersCart.getCustomerId()) .as("customersCart belongs to customer") .isEqualTo(customer.getId()); assertThat(anonymousCart.getCustomerId()).as("anonymous cart has no customer").isNull(); assertThat(customersCart.getLineItems().get(0).getProductId()) .as("both carts have the same product variant") .isEqualTo(anonymousCart.getLineItems().get(0).getProductId()); assertThat(customersCart.getLineItems().get(0).getQuantity()) .describedAs("both carts have the same variant in different quantities") .isNotEqualTo(anonymousCart.getLineItems().get(0).getQuantity()); assertThat(customersCart.getLineItems().get(0).getQuantity()).isEqualTo(3); assertThat(anonymousCart.getLineItems().get(0).getQuantity()).isEqualTo(7); final long maxOfBothQuantities = Math.max(customersCart.getLineItems().get(0).getQuantity(), anonymousCart.getLineItems().get(0).getQuantity()); assertThat(maxOfBothQuantities).isEqualTo(7); final CustomerSignInResult result = client().executeBlocking(CustomerSignInCommand .of(customer.getEmail(), PASSWORD, anonymousCart.getId())); final Cart mergeResultCart = result.getCart(); final LineItem mergeResultLineItem = mergeResultCart.getLineItems().get(0); assertThat(mergeResultLineItem.getQuantity()).isEqualTo(maxOfBothQuantities).isEqualTo(7); assertThat(mergeResultLineItem.getProductId()) .describedAs("same product variant as before") .isEqualTo(customersCart.getLineItems().get(0).getProductId()); assertThat(mergeResultCart.getId()).isEqualTo(customersCart.getId()); assertThat(mergeResultCart.getId()).isEqualTo(customersCart.getId()); assertThat(mergeResultCart.getCartState()).isEqualTo(CartState.ACTIVE); final Cart abandonedCart = client().executeBlocking(CartByIdGet.of(anonymousCart.getId())); assertThat(abandonedCart.getCartState()).isEqualTo(CartState.MERGED); });
See the test code.
Example for invalid credentials:
withCustomer(client(), customer -> { assertThatThrownBy(() -> client().executeBlocking(CustomerSignInCommand.of("notpresent@null.europe-west1.gcp.commercetools.com", PASSWORD))) .isInstanceOf(ErrorResponseException.class) .matches(e -> ((ErrorResponseException) e).hasErrorCode(CustomerInvalidCredentials.CODE)); });
See the test code.
Customer
,
CustomerCreatePasswordTokenCommand
deserialize
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
canDeserialize
public static CustomerSignInCommand of(String email, String password)
@Deprecated public static CustomerSignInCommand of(String email, String password, @Nullable String anonymousCartId)
of(String, String, ResourceIdentifier)
insteadpublic static CustomerSignInCommand of(String email, String password, @Nullable ResourceIdentifier<Cart> anonymousCart)
public CustomerSignInCommand withAnonymousId(@Nullable String anonymousId)
public CustomerSignInCommand withAnonymousCart(@Nullable ResourceIdentifier<Cart> anonymousCart)
public CustomerSignInCommand withAnonymousCartSignInMode(@Nullable AnonymousCartSignInMode anonymousCartSignInMode)
public CustomerSignInCommand withUpdateProductData(@Nullable Boolean updateProductData)
protected com.fasterxml.jackson.databind.JavaType jacksonJavaType()
jacksonJavaType
in class CommandImpl<CustomerSignInResult>
public HttpRequestIntent httpRequestIntent()
SphereRequest
public String getEmail()
public String getPassword()
@Deprecated @Nullable public String getAnonymousCartId()
getAnonymousCart()
instead@Nullable public ResourceIdentifier<Cart> getAnonymousCart()
@Nullable public AnonymousCartSignInMode getAnonymousCartSignInMode()