#How would I get the line items from an order/order id to create a fulfillment?

1 messages · Page 1 of 1 (latest)

bronze veldt
#

Second argument { relations: [´items´] }

random gorge
worldly oar
random gorge
# worldly oar Hi could you share the code of how to create the fulfillment automatically after...

Here's what I wrote:

  constructor({ fulfillmentService, orderService, eventBusService }) {
    this.orderService = orderService;
    this.fulfillmentService = fulfillmentService;
    eventBusService.subscribe("order.placed", this.handleOrder);
  }

  handleOrder = async (data) => {
    const order = await this.orderService.retrieve(data.id, {
      relations: ["items"],
    });

    const createdFulfillment = await this.orderService.createFulfillment(
      data.id,
      order.items
    );

  };
}

export default OrderFulfillmentSubscriber;
worldly oar
random gorge
worldly oar
random gorge
worldly oar
worldly oar
#
  handleOrder = async (data) => {
    const order = await this.orderService.retrieve(data.id, {
      relations: ['items'],
    });

    const fulfillmentItems: FulFillmentItemType[] =                order.items.map((item) => ({
      item_id: item.id,
      quantity: item.quantity,
    }));

    await this.orderService.createFulfillment(data.id,       fulfillmentItems);
  };
#

Here is my updated code and it worked

random gorge