Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions components/shopware/actions/create-order/create-order.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { parseObject } from "../../common/utils.mjs";
import shopware from "../../shopware.app.mjs";

export default {
key: "shopware-create-order",
name: "Create Order",
description: "Create a new order. [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
shopware,
billingAddressId: {
propDefinition: [
shopware,
"customerAddressId",
],
label: "Billing Address ID",
description: "The ID of the billing address to use for the order",
},
currencyId: {
propDefinition: [
shopware,
"currencyId",
],
},
salesChannelId: {
propDefinition: [
shopware,
"salesChannelId",
],
},
stateId: {
propDefinition: [
shopware,
"stateId",
() => ({
type: "order.state",
}),
],
},
orderDateTime: {
type: "string",
label: "Order Date Time",
description: "The date and time the order was created",
},
priceObject: {
type: "object",
label: "Price Object",
description: "Price object to use for the order. Example: `{ \"netPrice\": 1.00, \"totalPrice\": 1.00, \"positionPrice\": 1.00, \"rawTotal\": 1.00, \"taxStatus\": \"Free\", \"calculatedTaxes\": {}, \"taxRules\": {} }` [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources) for more information.",
},
shippingCostsObject: {
type: "object",
label: "Shipping Costs Object",
description: "Shipping costs object to use for the order. Example: `{ \"unitPrice\": 1.00, \"totalPrice\": 1.00, \"quantity\": 1, \"calculatedTaxes\": {}, \"taxRules\": {} }` [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources) for more information.",
},
currencyObject: {
type: "object",
label: "Currency Object",
description: "Currency object to use for the order. Example: `{ \"factor\": 1.0, \"symbol\": \"€\", \"isoCode\": \"EUR\", \"itemRounding\": { \"decimals\": 2, \"interval\": 1.0, \"roundForNet\": true }, \"totalRounding\": { \"decimals\": 2, \"interval\": 1.0, \"roundForNet\": true } }` [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources) for more information.",
},
currencyFactor: {
type: "string",
label: "Currency Factor",
description: "Rate at which currency is exchanged",
},
itemRounding: {
type: "object",
label: "Item Rounding",
description: "The rounding method to use for the order items",
},
totalRounding: {
type: "object",
label: "Total Rounding",
description: "The rounding method to use for the order total",
},
},
async run({ $ }) {
const { data } = await this.shopware.createOrder({
$,
params: {
_response: "json",
},
data: {
billingAddressId: this.billingAddressId,
currencyId: this.currencyId,
salesChannelId: this.salesChannelId,
stateId: this.stateId,
orderDateTime: this.orderDateTime,
price: parseObject(this.priceObject),
shippingCosts: parseObject(this.shippingCostsObject),
currencyFactor: parseFloat(this.currencyFactor),
currency: parseObject(this.currency),
itemRounding: parseObject(this.itemRounding),
totalRounding: parseObject(this.totalRounding),
},
});

$.export("$summary", `Successfully created order with ID: ${data.id}`);
return data;
},
};
32 changes: 32 additions & 0 deletions components/shopware/actions/get-order/get-order.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import shopware from "../../shopware.app.mjs";

export default {
key: "shopware-get-order",
name: "Get Order",
description: "Get an order by ID. [See the documentation](https://shopware.stoplight.io/docs/admin-api/0b7d9d489b841-search-for-the-order-resources)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
shopware,
orderId: {
propDefinition: [
shopware,
"orderId",
],
},
},
async run({ $ }) {
const { data } = await this.shopware.getOrder({
$,
orderId: this.orderId,
});

$.export("$summary", `Successfully retrieved order with ID: ${data.id}`);
return data;
},
};
38 changes: 38 additions & 0 deletions components/shopware/actions/list-orders/list-orders.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import shopware from "../../shopware.app.mjs";

export default {
key: "shopware-list-orders",
name: "List Orders",
description: "List all orders. [See the documentation](https://shopware.stoplight.io/docs/admin-api/f95b395c5ae73-list-with-basic-information-of-order-resources)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
shopware,
maxResults: {
type: "integer",
label: "Max Results",
description: "The maximum number of orders to return",
default: 100,
optional: true,
},
},
async run({ $ }) {
const orders = this.shopware.paginate({
$,
fn: this.shopware.listOrders,
maxResults: this.maxResults,
});

const data = [];
for await (const order of orders) {
data.push(order);
}
$.export("$summary", `Successfully retrieved ${data.length} orders`);
return data;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import shopware from "../../shopware.app.mjs";

export default {
key: "shopware-list-payment-methods",
name: "List Payment Methods",
description: "List all payment methods. [See the documentation](https://shopware.stoplight.io/docs/admin-api/0ffc5a34d40e4-list-with-basic-information-of-payment-method-resources)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
shopware,
maxResults: {
type: "integer",
label: "Max Results",
description: "The maximum number of payment methods to return",
default: 100,
optional: true,
},
},
async run({ $ }) {
const response = this.shopware.paginate({
$,
fn: this.shopware.listPaymentMethods,
maxResults: this.maxResults,
});

const data = [];
for await (const paymentMethod of response) {
data.push(paymentMethod);
}

$.export("$summary", `Successfully retrieved ${data.length} payment methods`);
return data;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import shopware from "../../shopware.app.mjs";

export default {
key: "shopware-list-shipping-methods",
name: "List Shipping Methods",
description: "List all shipping methods. [See the documentation](https://shopware.stoplight.io/docs/admin-api/7d33c6b3c151d-list-with-basic-information-of-shipping-method-resources)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
shopware,
maxResults: {
type: "integer",
label: "Max Results",
description: "The maximum number of shipping methods to return",
default: 100,
optional: true,
},
},
async run({ $ }) {
const response = this.shopware.paginate({
$,
fn: this.shopware.listShippingMethods,
maxResults: this.maxResults,
});

const data = [];
for await (const shippingMethod of response) {
data.push(shippingMethod);
}

$.export("$summary", `Successfully retrieved ${data.length} shipping methods`);
return data;
},
};
95 changes: 95 additions & 0 deletions components/shopware/actions/update-order/update-order.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { parseObject } from "../../common/utils.mjs";
import shopware from "../../shopware.app.mjs";

export default {
key: "shopware-update-order",
name: "Update Order",
description: "Partially update information about a Order resource. [See the documentation](https://shopware.stoplight.io/docs/admin-api/3cc867261ff28-partially-update-information-about-a-order-resource)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
shopware,
orderId: {
propDefinition: [
shopware,
"orderId",
],
},
tagIds: {
propDefinition: [
shopware,
"tagIds",
],
withLabel: true,
optional: true,
},
ruleIds: {
propDefinition: [
shopware,
"ruleIds",
],
optional: true,
},
orderNumber: {
type: "string",
label: "Order Number",
description: "Unique number associated with every order",
optional: true,
},
affiliateCode: {
type: "string",
label: "Affiliate Code",
description: "An affiliate code is an identification option with which website operators can mark outgoing links",
optional: true,
},
campaignCode: {
type: "string",
label: "Campaign Code",
description: "A campaign code is the globally unique identifier for a campaign",
optional: true,
},
customerComment: {
type: "string",
label: "Customer Comment",
description: "Comments given by comments",
optional: true,
},
internalComment: {
type: "string",
label: "Internal Comment",
description: "Comments given by the internal user",
optional: true,
},
},
async run({ $ }) {
const data = await this.shopware.updateOrder({
$,
orderId: this.orderId,
params: {
_response: "json",
},
data: {
tags: parseObject(this.tagIds)?.map(({
value, label,
}) => ({
id: value,
name: label,
})),
rules: parseObject(this.ruleIds),
orderNumber: this.orderNumber,
affiliateCode: this.affiliateCode,
campaignCode: this.campaignCode,
customerComment: this.customerComment,
internalComment: this.internalComment,
},
});

$.export("$summary", `Successfully retrieved order with ID: ${this.orderId}`);
return data;
},
};
1 change: 1 addition & 0 deletions components/shopware/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const LIMIT = 100;
24 changes: 24 additions & 0 deletions components/shopware/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
Loading
Loading