|  | 
|  | 1 | +import app from "../../americommerce.app.mjs"; | 
|  | 2 | + | 
|  | 3 | +export default { | 
|  | 4 | +  key: "americommerce-change-order-status", | 
|  | 5 | +  name: "Change Order Status", | 
|  | 6 | +  description: "Changes the status of an existing order. Specify the order ID and the new status to update the order.", | 
|  | 7 | +  version: "0.0.1", | 
|  | 8 | +  type: "action", | 
|  | 9 | +  props: { | 
|  | 10 | +    app, | 
|  | 11 | +    orderStatusId: { | 
|  | 12 | +      optional: false, | 
|  | 13 | +      propDefinition: [ | 
|  | 14 | +        app, | 
|  | 15 | +        "orderStatusId", | 
|  | 16 | +      ], | 
|  | 17 | +    }, | 
|  | 18 | +    name: { | 
|  | 19 | +      type: "string", | 
|  | 20 | +      label: "Name", | 
|  | 21 | +      description: "The name of the order status.", | 
|  | 22 | +      optional: true, | 
|  | 23 | +    }, | 
|  | 24 | +    isOpen: { | 
|  | 25 | +      type: "boolean", | 
|  | 26 | +      label: "Is Open", | 
|  | 27 | +      description: "Indicates whether the order status is open.", | 
|  | 28 | +      optional: true, | 
|  | 29 | +    }, | 
|  | 30 | +    isDeclined: { | 
|  | 31 | +      type: "boolean", | 
|  | 32 | +      label: "Is Declined", | 
|  | 33 | +      description: "Indicates whether the order status is declined.", | 
|  | 34 | +      optional: true, | 
|  | 35 | +    }, | 
|  | 36 | +    isCancelled: { | 
|  | 37 | +      type: "boolean", | 
|  | 38 | +      label: "Is Cancelled", | 
|  | 39 | +      description: "Indicates whether the order status is cancelled.", | 
|  | 40 | +      optional: true, | 
|  | 41 | +    }, | 
|  | 42 | +    isShipped: { | 
|  | 43 | +      type: "boolean", | 
|  | 44 | +      label: "Is Shipped", | 
|  | 45 | +      description: "Indicates whether the order status is shipped.", | 
|  | 46 | +      optional: true, | 
|  | 47 | +    }, | 
|  | 48 | +    color: { | 
|  | 49 | +      type: "string", | 
|  | 50 | +      label: "Color", | 
|  | 51 | +      description: "The color of the order status.", | 
|  | 52 | +      optional: true, | 
|  | 53 | +    }, | 
|  | 54 | +    emailTemplateId: { | 
|  | 55 | +      propDefinition: [ | 
|  | 56 | +        app, | 
|  | 57 | +        "emailTemplateId", | 
|  | 58 | +      ], | 
|  | 59 | +    }, | 
|  | 60 | +    isFullyRefunded: { | 
|  | 61 | +      type: "boolean", | 
|  | 62 | +      label: "Is Fully Refunded", | 
|  | 63 | +      description: "Indicates whether the order status is fully refunded.", | 
|  | 64 | +      optional: true, | 
|  | 65 | +    }, | 
|  | 66 | +    isPartiallyRefunded: { | 
|  | 67 | +      type: "boolean", | 
|  | 68 | +      label: "Is Partially Refunded", | 
|  | 69 | +      description: "Indicates whether the order status is partially refunded.", | 
|  | 70 | +      optional: true, | 
|  | 71 | +    }, | 
|  | 72 | +    isQuoteStatus: { | 
|  | 73 | +      type: "boolean", | 
|  | 74 | +      label: "Is Quote Status", | 
|  | 75 | +      description: "Indicates whether the order status is a quote status.", | 
|  | 76 | +      optional: true, | 
|  | 77 | +    }, | 
|  | 78 | +    isPartiallyShipped: { | 
|  | 79 | +      type: "boolean", | 
|  | 80 | +      label: "Is Partially Shipped", | 
|  | 81 | +      description: "Indicates whether the order status is partially shipped.", | 
|  | 82 | +      optional: true, | 
|  | 83 | +    }, | 
|  | 84 | +  }, | 
|  | 85 | +  methods: { | 
|  | 86 | +    changeOrderStatus({ | 
|  | 87 | +      orderStatusId, ...args | 
|  | 88 | +    } = {}) { | 
|  | 89 | +      return this.app.put({ | 
|  | 90 | +        path: `/order_statuses/${orderStatusId}`, | 
|  | 91 | +        ...args, | 
|  | 92 | +      }); | 
|  | 93 | +    }, | 
|  | 94 | +  }, | 
|  | 95 | +  async run({ $ }) { | 
|  | 96 | +    const { | 
|  | 97 | +      changeOrderStatus, | 
|  | 98 | +      orderStatusId, | 
|  | 99 | +      name, | 
|  | 100 | +      isOpen, | 
|  | 101 | +      isDeclined, | 
|  | 102 | +      isCancelled, | 
|  | 103 | +      isShipped, | 
|  | 104 | +      color, | 
|  | 105 | +      emailTemplateId, | 
|  | 106 | +      isFullyRefunded, | 
|  | 107 | +      isPartiallyRefunded, | 
|  | 108 | +      isQuoteStatus, | 
|  | 109 | +      isPartiallyShipped, | 
|  | 110 | +    } = this; | 
|  | 111 | + | 
|  | 112 | +    const response = await changeOrderStatus({ | 
|  | 113 | +      $, | 
|  | 114 | +      orderStatusId, | 
|  | 115 | +      data: { | 
|  | 116 | +        name, | 
|  | 117 | +        is_open: isOpen, | 
|  | 118 | +        is_declined: isDeclined, | 
|  | 119 | +        is_cancelled: isCancelled, | 
|  | 120 | +        is_shipped: isShipped, | 
|  | 121 | +        color, | 
|  | 122 | +        email_template_id: emailTemplateId, | 
|  | 123 | +        is_fully_refunded: isFullyRefunded, | 
|  | 124 | +        is_partially_refunded: isPartiallyRefunded, | 
|  | 125 | +        is_quote_status: isQuoteStatus, | 
|  | 126 | +        is_partially_shipped: isPartiallyShipped, | 
|  | 127 | +      }, | 
|  | 128 | +    }); | 
|  | 129 | +    $.export("$summary", `Successfully changed the order status with ID \`${response.id}\`.`); | 
|  | 130 | +    return response; | 
|  | 131 | +  }, | 
|  | 132 | +}; | 
0 commit comments