public interface CartCreateCommand extends DraftBasedCreateCommandDsl<Cart,CartDraft,CartCreateCommand>, MetaModelReferenceExpansionDsl<Cart,CartCreateCommand,CartExpansionModel<Cart>>
final CartDraft cartDraft = CartDraft.of(EUR).withCountry(DE); final Cart cart = client().executeBlocking(CartCreateCommand.of(cartDraft)); assertThat(cart.getTotalPrice().getCurrency().getCurrencyCode()).isEqualTo(EUR.getCurrencyCode()); assertThat(cart.getCountry()).isEqualTo(DE); assertThat(cart.getTotalPrice().isZero()).isTrue();
See the test code.
final Address shippingAddress = Address.of(CountryCode.DE).withAdditionalAddressInfo("shipping"); final Address billingAddress = Address.of(CountryCode.DE).withAdditionalAddressInfo("billing"); withCustomer(client(), customer -> { final String customerId = customer.getId(); final String customerEmail = customer.getEmail(); withUpdateableType(client(), type -> { final CustomFieldsDraft customFieldsDraft = CustomFieldsDraft.ofTypeKeyAndObjects(type.getKey(), singletonMap(TypeFixtures.STRING_FIELD_NAME, "foo")); withShippingMethodForGermany(client(), shippingMethod -> { withTaxedProduct(client(), product1 -> { withTaxedProduct(client(), product2 -> { withTaxedProduct(client(), product3 -> { final LineItemDraft lineItemDraft1 = LineItemDraft.of(product1, 1, 15); final LineItemDraft lineItemDraftOfVariantIdentifier = LineItemDraftBuilder.ofVariantIdentifier(product2.getMasterData().getStaged().getMasterVariant().getIdentifier(), 25L).build(); String sku = product3.getMasterData().getStaged().getMasterVariant().getSku(); final LineItemDraft lineItemDraftOfSku = LineItemDraftBuilder.ofSkuVariantIdentifier(BySkuVariantIdentifier.of(sku), 35L).build(); final List<LineItemDraft> lineItems = asList(lineItemDraft1, lineItemDraftOfVariantIdentifier, lineItemDraftOfSku); final List<CustomLineItemDraft> customLineItems = singletonList(CustomLineItemDraft.of(randomSlug(), "foo-bar", EURO_5, product1.getTaxCategory(), 1L, null)); final CartDraft cartDraft = CartDraft.of(EUR) .withCountry(DE) .withLocale(Locale.GERMAN) .withCustomerId(customerId) .withCustomerEmail(customerEmail) .withLineItems(lineItems) .withCustomLineItems(customLineItems) .withBillingAddress(billingAddress) .withShippingAddress(shippingAddress) .withShippingMethod(shippingMethod) .withCustom(customFieldsDraft); final CartCreateCommand cartCreateCommand = CartCreateCommand.of(cartDraft) .plusExpansionPaths(m -> m.lineItems().productType()); final Cart cart = client().executeBlocking(cartCreateCommand); softAssert(s -> { s.assertThat(cart.getCountry()).isEqualTo(DE); s.assertThat(cart.getLocale()).isEqualTo(Locale.GERMAN); s.assertThat(cart.getTotalPrice().getCurrency()).isEqualTo(EUR); s.assertThat(cart.getCurrency()).isEqualTo(EUR); s.assertThat(cart.getCustomerId()).isEqualTo(customerId); s.assertThat(cart.getCustomerEmail()).isEqualTo(customerEmail); s.assertThat(cart.getLineItems()).hasSize(3); final LineItem lineItem1 = cart.getLineItems().get(0); s.assertThat(lineItem1.getProductId()).isEqualTo(product1.getId()); s.assertThat(lineItem1.getQuantity()).isEqualTo(15); s.assertThat(lineItem1.getProductType()).isEqualTo(product1.getProductType()); s.assertThat(lineItem1.getProductType().getObj()).isNotNull(); final LineItem lineItem2 = cart.getLineItems().get(1); s.assertThat(lineItem2.getProductId()).isEqualTo(product2.getId()); s.assertThat(lineItem2.getVariant().getId()).isEqualTo(product2.getMasterData().getStaged().getMasterVariant().getId()); final LineItem lineItem3 = cart.getLineItems().get(2); s.assertThat(lineItem3.getProductId()).isEqualTo(product3.getId()); s.assertThat(lineItem3.getVariant().getId()).isEqualTo(product3.getMasterData().getStaged().getMasterVariant().getId()); s.assertThat(lineItem3.getVariant().getSku()).isEqualTo(product3.getMasterData().getStaged().getMasterVariant().getSku()); s.assertThat(cart.getCustomLineItems().get(0).getSlug()).isEqualTo("foo-bar"); s.assertThat(cart.getBillingAddress()).isEqualTo(billingAddress); s.assertThat(cart.getShippingAddress()).isEqualTo(shippingAddress); s.assertThat(cart.getCustom().getFieldsJsonMap()).isEqualTo(customFieldsDraft.getFields()); }); //cleanup client().executeBlocking(CartDeleteCommand.of(cart)); }); }); }); }); return type; }); });
See the test code.
Modifier and Type | Method and Description |
---|---|
static CartCreateCommand |
of(CartDraft draft)
Creates a command object to create a
Cart . |
getDraft, withDraft
canDeserialize, deserialize, httpRequestIntent
plusExpansionPaths, withExpansionPaths
plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, plusExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths, withExpansionPaths
expansionPaths
static CartCreateCommand of(CartDraft draft)
Cart
.draft
- template to create the new object