Tabnine Logo
OrderUpdateCommand
Code IndexAdd Tabnine to your IDE (free)

How to use
OrderUpdateCommand
in
io.sphere.sdk.orders.commands

Best Java code snippets using io.sphere.sdk.orders.commands.OrderUpdateCommand (Showing top 20 results out of 315)

origin: io.sphere.sdk.jvm/models

  public static OrderUpdateCommand of(final Versioned<Order> order, final UpdateAction<Order> updateAction) {
    return of(order, asList(updateAction));
  }
}
origin: com.commercetools.sdk.jvm.core/commercetools-models

/**
  Creates a command to update a Order selected by its orderNumber using one update action.
  @param orderNumber the orderNumber of the Order to update, see {@link Order#getOrderNumber()}
  @param version the current version of the Order, see {@link Order#getVersion()}
  @param updateAction the update to perform
  @return the update command for Order
*/
static OrderUpdateCommand ofOrderNumber(final String orderNumber, final Long version, final UpdateAction<Order> updateAction) {
  return ofOrderNumber(orderNumber, version, Collections.singletonList(updateAction));
}
origin: io.sphere.sdk.jvm/models

public static OrderUpdateCommand of(final Versioned<Order> order, final List<? extends UpdateAction<Order>> updateActions) {
  return new OrderUpdateCommand(order, updateActions);
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void referenceExpansion() throws Exception {
  withOrder(client(), order -> {
    assertThat(order.getOrderNumber()).isNull();
    final String orderNumber = randomString();
    final OrderUpdateCommand orderUpdateCommand = OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber)).plusExpansionPaths(m -> m.cart());
    final Order updatedOrder = client().executeBlocking(orderUpdateCommand);
    assertThat(updatedOrder.getCart().getObj()).isNotNull();
    return updatedOrder;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void changeOrderStateByOrderNumber() throws Exception {
  withOrder(client(), order -> {
    assertThat(order.getOrderState()).isEqualTo(OrderState.OPEN);
    final String orderNumber = randomString();
    final Order orderWithOrderNumber = client().executeBlocking(OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber)));
    final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.ofOrderNumber(orderNumber, orderWithOrderNumber.getVersion(),
        ChangeOrderState.of(OrderState.COMPLETE)));
    assertThat(updatedOrder.getOrderState()).isEqualTo(OrderState.COMPLETE);
    return updatedOrder;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void addPayment() {
  withPayment(client(), payment -> {
    withOrder(client(), order -> {
      //add payment
      final OrderUpdateCommand orderUpdateCommand = OrderUpdateCommand.of(order, AddPayment.of(payment))
          .withExpansionPaths(m -> m.paymentInfo().payments());
      final Order orderWithPayment = client().executeBlocking(orderUpdateCommand);
      final Reference<Payment> paymentReference = orderWithPayment.getPaymentInfo().getPayments().get(0);
      assertThat(paymentReference).isEqualTo(payment.toReference());
      assertThat(paymentReference).is(expanded(payment));
      //remove payment
      final Order orderWithoutPayment = client().executeBlocking(OrderUpdateCommand.of(orderWithPayment, RemovePayment.of(payment)));
      assertThat(orderWithoutPayment.getPaymentInfo()).isNull();
      return orderWithoutPayment;
    });
    return payment;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void execution() throws Exception {
  withStateByBuilder(client(), builder -> builder.type(StateType.ORDER_STATE), state -> {
    withFilledCart(client(), cart -> {
      final Order order = client().executeBlocking(OrderFromCartCreateCommand.of(cart));
      final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, TransitionState.of(state))
          .plusExpansionPaths(OrderExpansionModel::state)
          .plusExpansionPaths(OrderExpansionModel::cart)
      );
      assertThat(updatedOrder.getLineItems()).isEqualTo(cart.getLineItems());
      assertThat(updatedOrder.getCustomLineItems()).isEqualTo(cart.getCustomLineItems());
      assertThat(updatedOrder.getCart().getId()).isEqualTo(cart.getId());
      assertThat(updatedOrder.getCart()).is(expanded());
      final Cart orderedCart = updatedOrder.getCart().getObj();
      assertThat(orderedCart).isNotNull();
      assertThat(orderedCart.getId()).isEqualTo(cart.getId());
      assertThat(orderedCart.getCartState()).isEqualTo(CartState.ORDERED);
      assertThat(updatedOrder.getState()).is(expanded());
      //to be able to delete the state transition we have to delete the associated order.
      client().executeBlocking(OrderDeleteCommand.of(updatedOrder));
    });
  });
}
origin: io.sphere.sdk.jvm/sphere-models

  static OrderUpdateCommand of(final Versioned<Order> order, final UpdateAction<Order> updateAction) {
    return of(order, Collections.singletonList(updateAction));
  }
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void changeOrderState() throws Exception {
  withOrder(client(), order -> {
    assertThat(order.getOrderState()).isEqualTo(OrderState.OPEN);
    final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, ChangeOrderState.of(OrderState.COMPLETE)));
    assertThat(updatedOrder.getOrderState()).isEqualTo(OrderState.COMPLETE);
    return updatedOrder;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void testRemoveAddressesToOrderUpdateAction() {
  withFilledCartAndMultipleAddresses(client(), cart -> {
    withCustomer(client(),customer -> {
      withOrder(client(),customer,cart,order -> {
        final List<Address> addresses = order.getItemShippingAddresses();
        final String addressKey = addresses.get(0).getKey();
        final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, RemoveItemShippingAddress.of(addressKey)));
        assertThat(updatedOrder.getItemShippingAddresses()).hasSize(addresses.size() - 1);
        assertThat(updatedOrder.getItemShippingAddresses().stream().filter(address -> addressKey.equals(address.getKey())).collect(Collectors.toList())).isEmpty();
        return updatedOrder;
      });
    });
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void locale() {
  withOrder(client(), order -> {
    assertThat(order.getLocale()).isNull();
    final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, SetLocale.of(Locale.GERMAN)));
    assertThat(updatedOrder.getLocale()).isEqualTo(GERMAN);
    return updatedOrder;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void setReturnPaymentState() throws Exception {
  withOrderAndReturnInfo(client(), (order, returnInfo) -> {
    final ReturnItem returnItem = returnInfo.getItems().get(0);
    final ReturnPaymentState newPaymentState = ReturnPaymentState.REFUNDED;
    assertThat(returnItem.getPaymentState()).isNotEqualTo(newPaymentState);
    final SetReturnPaymentState action = SetReturnPaymentState.of(returnItem, newPaymentState);
    final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, action));
    final ReturnPaymentState updatedPaymentState = updatedOrder.getReturnInfo().get(0).getItems().get(0).getPaymentState();
    assertThat(updatedPaymentState).isEqualTo(newPaymentState);
    return updatedOrder;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void changePaymentState() throws Exception {
  withOrder(client(), order -> {
    final PaymentState newState = PaymentState.PAID;
    assertThat(order.getPaymentState()).isNotEqualTo(newState);
    final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, ChangePaymentState.of(newState)));
    assertThat(updatedOrder.getPaymentState()).isEqualTo(newState);
    return updatedOrder;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void addReturnInfo() throws Exception {
  withOrder(client(), order -> {
    assertThat(order.getReturnInfo()).isEmpty();
    final String lineItemId = order.getLineItems().get(0).getId();
    final List<LineItemReturnItemDraft> items = asList(LineItemReturnItemDraft.of(1L, lineItemId, ReturnShipmentState.RETURNED, "foo bar"));
    final AddReturnInfo action = AddReturnInfo.of(items).withReturnDate(ZonedDateTime_IN_PAST).withReturnTrackingId("trackingId");
    final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, action));
    final ReturnInfo returnInfo = updatedOrder.getReturnInfo().get(0);
    final ReturnItem returnItem = returnInfo.getItems().get(0);
    assertThat(returnItem).isInstanceOf(LineItemReturnItem.class);
    final LineItemReturnItem lineItemReturnItem = (LineItemReturnItem) returnItem;
    assertThat(returnItem.getQuantity()).isEqualTo(1);
    assertThat(lineItemReturnItem.getLineItemId()).isEqualTo(lineItemId);
    assertThat(lineItemReturnItem.getShipmentState()).isEqualTo(ReturnShipmentState.RETURNED);
    assertThat(lineItemReturnItem.getComment()).contains("foo bar");
    assertThat(returnInfo.getReturnDate()).isEqualTo(ZonedDateTime_IN_PAST);
    assertThat(returnInfo.getReturnTrackingId()).contains("trackingId");
    return updatedOrder;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void testAddAddressesToCartUpdateAction() {
  final List<Address> addressList = createAddressArray();
  withFilledCart(client(), cart -> {
    withCustomer(client(),customer -> {
      withOrder(client(),customer,cart,order -> {
        assertThat(order.getItemShippingAddresses()).isEmpty();
        List<UpdateAction<Order>> addAddresses = addressList.stream().map(AddItemShippingAddress::of).collect(Collectors.toList());
        Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order,addAddresses ));
        assertThat(updatedOrder.getItemShippingAddresses()).hasSameSizeAs(addressList);
        return updatedOrder;
      });
    });
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void testDeliveriesAndParcels() {
  withOrder(client(), order -> {
    assertThat(order.getLineItems()).hasSize(1);
    assertThat(order.getShippingInfo().getDeliveries()).isEmpty();
    final LineItem lineItem = order.getLineItems().get(0);
    Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, AddDelivery.of(asList(DeliveryItem.of(lineItem)))));
    assertThat(updatedOrder.getShippingInfo().getDeliveries()).hasSize(1);
    Delivery delivery = updatedOrder.getShippingInfo().getDeliveries().get(0);
    assertThat(delivery.getParcels()).isEmpty();
    final ParcelMeasurements parcelMeasurements = ParcelMeasurements.of(2, 3, 1, 3);
    Order updatedOrder2 = client().executeBlocking(OrderUpdateCommand.of(updatedOrder, AddParcelToDelivery.of(delivery, ParcelDraft.of(parcelMeasurements))));
    assertThat(updatedOrder2.getShippingInfo().getDeliveries().get(0).getParcels()).hasSize(1);
    Parcel parcel = updatedOrder2.getShippingInfo().getDeliveries().get(0).getParcels().get(0);
    assertThat(parcel.getMeasurements()).isEqualTo(parcelMeasurements);
    return updatedOrder2;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void setOrderNumber() throws Exception {
  withOrder(client(), order -> {
    assertThat(order.getOrderNumber()).isNull();
    final String orderNumber = randomString();
    final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber)));
    assertThat(updatedOrder.getOrderNumber()).isEqualTo(orderNumber);
    return updatedOrder;
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void addReturnInfoOfCustomLineItems() throws Exception {
  withOrderOfCustomLineItems(client(), order -> {
    assertThat(order.getReturnInfo()).isEmpty();
    assertThat(order.getCustomLineItems()).isNotEmpty();
    final String customLineItemId = order.getCustomLineItems().get(0).getId();
    final List<CustomLineItemReturnItemDraft> items = asList(CustomLineItemReturnItemDraft.of(1L, customLineItemId, ReturnShipmentState.RETURNED, "foo bar"));
    final AddReturnInfo action = AddReturnInfo.of(items).withReturnDate(ZonedDateTime_IN_PAST).withReturnTrackingId("trackingId");
    final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, action));
    final ReturnInfo returnInfo = updatedOrder.getReturnInfo().get(0);
    final ReturnItem returnItem = returnInfo.getItems().get(0);
    assertThat(returnItem).isInstanceOf(CustomLineItemReturnItem.class);
    final CustomLineItemReturnItem customLineItemReturnItem = (CustomLineItemReturnItem) returnItem;
    assertThat(returnItem.getQuantity()).isEqualTo(1);
    assertThat(customLineItemReturnItem.getCustomLineItemId()).isEqualTo(customLineItemId);
    assertThat(customLineItemReturnItem.getShipmentState()).isEqualTo(ReturnShipmentState.RETURNED);
    assertThat(customLineItemReturnItem.getComment()).contains("foo bar");
    assertThat(returnInfo.getReturnDate()).isEqualTo(ZonedDateTime_IN_PAST);
    assertThat(returnInfo.getReturnTrackingId()).contains("trackingId");
  });
}
origin: commercetools/commercetools-jvm-sdk

@Test
public void testSetCustomLineItemShippingDetails() {
  final List<Address> addressList = createAddressArray();
  
  withOrderOfCustomLineItems(client(),order -> {
    assertThat(order.getItemShippingAddresses()).isEmpty();
    List<UpdateAction<Order>> addAddresses = addressList.stream().map(AddItemShippingAddress::of).collect(Collectors.toList());
    Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order,addAddresses ));
    assertThat(updatedOrder.getItemShippingAddresses()).hasSameSizeAs(addressList);
    assertThat(order.getCustomLineItems()).isNotEmpty();
    final CustomLineItem firstLineItem = updatedOrder.getCustomLineItems().get(0);
    final Long quantity = firstLineItem.getQuantity();
    final List<Address> addresses = updatedOrder.getItemShippingAddresses();
    final Address firstAddress = addresses.get(0);
    final String firstAddressKey = firstAddress.getKey();
    final ItemShippingDetailsDraft itemShippingDetailsDraft = ItemShippingDetailsDraftBuilder.of(Arrays.asList(ItemShippingTargetBuilder.of(firstAddressKey, firstLineItem.getQuantity()).build())).build();
    final Order updatedOrder2 = client().executeBlocking(OrderUpdateCommand.of(updatedOrder, SetCustomLineItemShippingDetails.of(firstLineItem.getId(),itemShippingDetailsDraft)));
    final CustomLineItem updatedLineItem = updatedOrder2.getCustomLineItems().stream().filter(lineItem -> lineItem.getId().equals(firstLineItem.getId())).findAny().get();
    assertThat(updatedLineItem.getShippingDetails().getTargets()).hasSize(1);
    assertThat(updatedLineItem.getShippingDetails().getTargets().get(0).getAddressKey()).isEqualTo(firstAddressKey);
    assertThat(updatedLineItem.getShippingDetails().getTargets().get(0).getQuantity()).isEqualTo(quantity);
  } );
}
origin: commercetools/commercetools-jvm-sdk

  public static void withOrderAndReturnInfo(final BlockingSphereClient client, final BiFunction<Order, ReturnInfo, Order> f) {
    withOrder(client, order -> {
      Assertions.assertThat(order.getReturnInfo()).isEmpty();
      final String lineItemId = order.getLineItems().get(0).getId();
      final List<LineItemReturnItemDraft> items = asList(LineItemReturnItemDraft.of(1L, lineItemId, ReturnShipmentState.RETURNED, "foo bar"));
      final AddReturnInfo action = AddReturnInfo.of(items);
      final AddDelivery addDelivery = AddDelivery.of(asList(DeliveryItem.of(lineItemId, 1)));
      final Order updatedOrder = client.executeBlocking(OrderUpdateCommand.of(order, asList(action, addDelivery)));

      final ReturnInfo returnInfo = updatedOrder.getReturnInfo().get(0);
      return f.apply(updatedOrder, returnInfo);
    });
  }
}
io.sphere.sdk.orders.commandsOrderUpdateCommand

Javadoc

list actions

Most used methods

  • of
    Creates a command to update a Order selected by its ID using several update actions.
  • ofOrderNumber
    Creates a command to update a Order selected by its orderNumber using several update actions.
  • <init>
  • plusExpansionPaths
  • withExpansionPaths

Popular in Java

  • Running tasks concurrently on multiple threads
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • startActivity (Activity)
  • scheduleAtFixedRate (Timer)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now