Skip to content

2317 - add woocommerce component #2694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
921 changes: 921 additions & 0 deletions docs/content/docs/reference/components/woocommerce.mdx

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions server/apps/server-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ dependencies {
implementation(project(":server:libs:modules:components:webflow"))
implementation(project(":server:libs:modules:components:webhook"))
implementation(project(":server:libs:modules:components:whatsapp"))
implementation(project(":server:libs:modules:components:woocommerce"))
implementation(project(":server:libs:modules:components:xero"))
implementation(project(":server:libs:modules:components:xlsx-file"))
implementation(project(":server:libs:modules:components:xml-file"))
Expand Down
1 change: 1 addition & 0 deletions server/ee/apps/worker-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ dependencies {
implementation(project(":server:libs:modules:components:webflow"))
implementation(project(":server:libs:modules:components:webhook"))
implementation(project(":server:libs:modules:components:whatsapp"))
implementation(project(":server:libs:modules:components:woocommerce"))
implementation(project(":server:libs:modules:components:xero"))
implementation(project(":server:libs:modules:components:xlsx-file"))
implementation(project(":server:libs:modules:components:xml-file"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2025 ByteChef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.woocommerce;

import static com.bytechef.component.definition.ComponentDsl.component;
import static com.bytechef.component.definition.ComponentDsl.tool;

import com.bytechef.component.ComponentHandler;
import com.bytechef.component.definition.ComponentCategory;
import com.bytechef.component.definition.ComponentDefinition;
import com.bytechef.component.woocommerce.action.WoocommerceCreateCouponAction;
import com.bytechef.component.woocommerce.action.WoocommerceCreateCustomerAction;
import com.bytechef.component.woocommerce.action.WoocommerceCreateOrderAction;
import com.bytechef.component.woocommerce.action.WoocommerceCreateProductAction;
import com.bytechef.component.woocommerce.connection.WoocommerceConnection;
import com.bytechef.component.woocommerce.trigger.WoocommerceNewCouponTrigger;
import com.bytechef.component.woocommerce.trigger.WoocommerceNewOrderTrigger;
import com.google.auto.service.AutoService;

/**
* @author Marija Horvat
*/
@AutoService(ComponentHandler.class)
public class WoocommerceComponentHandler implements ComponentHandler {

private static final ComponentDefinition COMPONENT_DEFINITION = component("woocommerce")
.title("WooCommerce")
.description(
"WooCommerce is a e-commerce plugin for WordPress that allows you to turn a standard WordPress website " +
"into a fully functional online store.")
.icon("path:assets/woocommerce.svg")
.categories(ComponentCategory.E_COMMERCE)
.customAction(true)
.connection(WoocommerceConnection.CONNECTION_DEFINITION)
.actions(
WoocommerceCreateCouponAction.ACTION_DEFINITION,
WoocommerceCreateCustomerAction.ACTION_DEFINITION,
WoocommerceCreateOrderAction.ACTION_DEFINITION,
WoocommerceCreateProductAction.ACTION_DEFINITION)
.clusterElements(
tool(WoocommerceCreateCouponAction.ACTION_DEFINITION),
tool(WoocommerceCreateCustomerAction.ACTION_DEFINITION),
tool(WoocommerceCreateOrderAction.ACTION_DEFINITION),
tool(WoocommerceCreateProductAction.ACTION_DEFINITION))
.triggers(
WoocommerceNewOrderTrigger.TRIGGER_DEFINITION,
WoocommerceNewCouponTrigger.TRIGGER_DEFINITION);

@Override
public ComponentDefinition getDefinition() {
return COMPONENT_DEFINITION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright 2025 ByteChef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.woocommerce.action;

import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.array;
import static com.bytechef.component.definition.ComponentDsl.bool;
import static com.bytechef.component.definition.ComponentDsl.dateTime;
import static com.bytechef.component.definition.ComponentDsl.integer;
import static com.bytechef.component.definition.ComponentDsl.option;
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
import static com.bytechef.component.definition.ComponentDsl.string;
import static com.bytechef.component.definition.Context.Http.ResponseType;
import static com.bytechef.component.definition.Context.Http.responseType;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.AMOUNT;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.CODE;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.COUPON_OUTPUT_PROPERTY;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.DATE_EXPIRES;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.DESCRIPTION;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.DISCOUNT_TYPE;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.EXCLUDE_SALE_ITEMS;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.INDIVIDUAL_USE;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.MAXIMUM_AMOUNT;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.MINIMUM_AMOUNT;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.PRODUCT_IDS;

import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.Context;
import com.bytechef.component.definition.Context.Http.Body;
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.woocommerce.util.WoocommerceUtils;

/**
* @author Marija Horvat
*/
public class WoocommerceCreateCouponAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("createCoupon")
.title("Create Coupon")
.description("Create a new coupon.")
.properties(
string(CODE)
.label("Code")
.description("Coupon code.")
.required(true),
string(AMOUNT)
.label("Amount")
.description("The amount of discount. Should always be numeric, even if setting a percentage.")
.required(true),
string(DISCOUNT_TYPE)
.label("Discount Type")
.description("Determines the type of discount that will be applied.")
.options(
option("Percent", "percent"),
option("Fixed_cart", "fixed_cart"),
option("Fixed_product", "fixed_product"))
.required(true),
string(DESCRIPTION)
.label("Description")
.description("Coupon description.")
.required(false),
dateTime(DATE_EXPIRES)
.label("Date Expires")
.description("The date the coupon expires, in the site's timezone.")
.required(false),
bool(INDIVIDUAL_USE)
.label("Individual Use")
.description(
"If true, the coupon can only be used individually. Other applied coupons will be removed from " +
"the cart.")
.required(false),
array(PRODUCT_IDS)
.label("Product Ids")
.description("List of product IDs the coupon can be used on.")
.required(false)
.options((ActionOptionsFunction<String>) WoocommerceUtils::getProductIdOptions)
.items(integer()),
bool(EXCLUDE_SALE_ITEMS)
.label("Exclude Sale Items")
.description("If true, this coupon will not be applied to items that have sale prices.")
.required(false),
string(MINIMUM_AMOUNT)
.label("Minimum Amount")
.description("Minimum order amount that needs to be in the cart before coupon applies.")
.required(false),
string(MAXIMUM_AMOUNT)
.label("Maximum Amount")
.description("Maximum order amount allowed when using the coupon.")
.required(false))
.output(outputSchema(COUPON_OUTPUT_PROPERTY))
.perform(WoocommerceCreateCouponAction::perform);

private WoocommerceCreateCouponAction() {
}

public static Object perform(Parameters inputParameters, Parameters conectionParameters, Context context) {
return context.http(http -> http.post("/coupons"))
.body(
Body.of(
CODE, inputParameters.getRequiredString(CODE),
AMOUNT, inputParameters.getRequiredString(AMOUNT),
DISCOUNT_TYPE, inputParameters.getRequiredString(DISCOUNT_TYPE),
DESCRIPTION, inputParameters.getString(DESCRIPTION),
DATE_EXPIRES, inputParameters.getDate(DATE_EXPIRES),
INDIVIDUAL_USE, inputParameters.getBoolean(INDIVIDUAL_USE),
PRODUCT_IDS, inputParameters.getList(PRODUCT_IDS),
EXCLUDE_SALE_ITEMS, inputParameters.getBoolean(EXCLUDE_SALE_ITEMS),
MINIMUM_AMOUNT, inputParameters.getString(MINIMUM_AMOUNT),
MAXIMUM_AMOUNT, inputParameters.getString(MAXIMUM_AMOUNT)))
.configuration(responseType(ResponseType.JSON))
.execute()
.getBody();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* Copyright 2025 ByteChef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.woocommerce.action;

import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.object;
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
import static com.bytechef.component.definition.ComponentDsl.string;
import static com.bytechef.component.definition.Context.Http.ResponseType;
import static com.bytechef.component.definition.Context.Http.responseType;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.ADDRESS_1;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.ADDRESS_2;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.BILLING;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.CITY;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.COMPANY;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.COUNTRY;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.CUSTOMER_OUTPUT_PROPERTY;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.EMAIL;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.FIRST_NAME;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.LAST_NAME;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.PHONE;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.POSTCODE;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.SHIPPING;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.STATE;
import static com.bytechef.component.woocommerce.constants.WoocommerceConstants.USERNAME;

import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import com.bytechef.component.definition.Context;
import com.bytechef.component.definition.Context.Http;
import com.bytechef.component.definition.Parameters;

/**
* @author Marija Horvat
*/
public class WoocommerceCreateCustomerAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("createCustomer")
.title("Create Customer")
.description("Create a new customer.")
.properties(
string(EMAIL)
.label("Email")
.description("The email address for the customer.")
.required(true),
string(FIRST_NAME)
.label("First Name")
.description("Customer first name.")
.required(true),
string(LAST_NAME)
.label("Last Name")
.description("Customer last name.")
.required(true),
string(USERNAME)
.label("Username")
.description("Customer login name.")
.required(true),
object(BILLING)
.label("Billing")
.description("List of billing address data.")
.required(false)
.properties(
string(FIRST_NAME)
.label("First Name")
.description("First name."),
string(LAST_NAME)
.label("Last Name")
.description("Last name."),
string(COMPANY)
.label("Company")
.description("Company name."),
string(ADDRESS_1)
.label("Address 1")
.description("Address line 1."),
string(ADDRESS_2)
.label("Address 2")
.description("Address line 2."),
string(CITY)
.label("City")
.description("City name."),
string(STATE)
.label("State")
.description("ISO code or name of the state, province or district."),
string(POSTCODE)
.label("Postcode")
.description("Postal code."),
string(COUNTRY)
.label("Country")
.description("ISO code of the country."),
string(EMAIL)
.label("Email")
.description("Email address."),
string(PHONE)
.label("Phone")
.description("Phone number.")),
object(SHIPPING)
.label("Shipping")
.description("List of shipping address data.")
.required(false)
.properties(
string(FIRST_NAME)
.label("First Name")
.description("First name."),
string(LAST_NAME)
.label("Last Name")
.description("Last name."),
string(COMPANY)
.label("Company")
.description("Company name."),
string(ADDRESS_1)
.label("Address 1")
.description("Address line 1."),
string(ADDRESS_2)
.label("Address 2")
.description("Address line 2."),
string(CITY)
.label("City")
.description("City name."),
string(STATE)
.label("State")
.description("ISO code or name of the state, province or district."),
string(POSTCODE)
.label("Postcode")
.description("Postal code."),
string(COUNTRY)
.label("Country")
.description("ISO code of the country."),
string(PHONE)
.label("Phone")
.description("Phone number.")))
.output(outputSchema(CUSTOMER_OUTPUT_PROPERTY))
.perform(WoocommerceCreateCustomerAction::perform);

private WoocommerceCreateCustomerAction() {
}

public static Object perform(Parameters inputParameters, Parameters conectionParameters, Context context) {
return context.http(http -> http.post("/customers"))
.body(
Http.Body.of(
EMAIL, inputParameters.getRequiredString(EMAIL),
FIRST_NAME, inputParameters.getRequiredString(FIRST_NAME),
LAST_NAME, inputParameters.getRequiredString(LAST_NAME),
USERNAME, inputParameters.getRequiredString(USERNAME),
BILLING, inputParameters.getMap(BILLING),
SHIPPING, inputParameters.getMap(SHIPPING)))
.configuration(responseType(ResponseType.JSON))
.execute()
.getBody();
}
}
Loading