Developing Embedded Extensions
You can build customizations on the Extension Point Framework using embedded extensions.
For more information about the differences between embedded extensions and external plugins, see the options for extending the platform documentation.
Creating an Embedded Extension
Open the
ep-commerce
repo in your IDE.Add a new class to the
ext-core
module.note
You can add this class to any package within
com.elasticpath.extensions
.Add the
@Extension
and@XPFEmbedded
annotations to the class.Extend the
XPFExtensionPointImpl
class, and implement the appropriate Extension Point interface.Add the
@XPFAssignment
annotation, specifying the appropriate Extension Point key.Implement the methods required by the Extension Point interface.
important
If you require access to any Elastic Path Commerce services, add a private field and annotate it with
@Autowired
. You can also use@Named
to specify a bean with a specific ID.For example:
package com.elasticpath.extensions.validators; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import javax.inject.Named; import org.pf4j.Extension; import org.springframework.beans.factory.annotation.Autowired; import com.elasticpath.base.common.dto.StructuredErrorMessage; import com.elasticpath.validation.service.ModifierFieldValidationService; import com.elasticpath.xpf.connectivity.context.XPFShoppingItemValidationContext; import com.elasticpath.xpf.connectivity.extension.XPFExtensionPointImpl; import com.elasticpath.xpf.connectivity.extensionpoint.ShoppingItemValidator; /** * Shopping Item Validator that always returns a structured error message. */ @Extension @XPFEmbedded @XPFAssignment(extensionPoint = XPFExtensionPointEnum.VALIDATE_SHOPPING_ITEM_AT_ADD_TO_CART, priority = 100) public class BlockingShoppingItemValidator extends XPFExtensionPointImpl implements ShoppingItemValidator { @Autowired @Named("cachedModifierFieldValidationService") private ModifierFieldValidationService modifierFieldValidationService; @Override public Collection<StructuredErrorMessage> validate(final XPFShoppingItemValidationContext context) { List<StructuredErrorMessage> results = new ArrayList<>(); results.add(new StructuredErrorMessage("block-add-to-cart", "Always block add-to-cart.", new HashMap<>())); return results; } }