Tax Calculation
Overview
As of Elastic Path Commerce 8.4, all tax calculations are now handled by extensions in the Tax Calculator Extension Point. There are many advantages to this approach as described in External Plugins.
By default, the embedded ElasticPathTaxCalculator
extension is used, which determines taxes using the internal Elastic Path tax tables. However, this can be overridden by custom or pre-built plugins. For a list of available supported plugins, see Supported Accelerators.
For information about how to create a custom tax calculation plugin, see Developing External Plugins, Configuring and Deploying External Plugins, and the Tax Calculator Extension Point.
Upgrading Pre-8.4 plugins to the Extension Point Framework
To start, follow the Developing External Plugins instructions to create a basic External Plugin framework. Change the default extension class that the archetype created so it implements TaxCalculator
.
Next, review your existing tax calculation plugin class, which should extend AbstractTaxProviderPluginSPI
. This class will have an implementation of the public TaxedItemContainer calculate(final TaxableItemContainer container, final TaxOperationResolvers taxOperationResolvers)
method. Copy this implementation to your new Extension Point Framework extension class. The signature of your calculate
method will need to be changed to public XPFTaxedItems calculate(final XPFTaxCalculationContext context)
. All of the data available from the old TaxableItemContainer
will now be available in XPFTaxCalculationContext
, as shown in the table below:
TaxableItemContainer field | XPFTaxCalculationContext equivalent |
---|---|
getTaxOperationContext().getCurrency() | getCurrency() |
getTaxOperationContext().getCustomerCode() | getCustomer().getSharedId() |
getTaxOperationContext().getCustomerBusinessNumber() | getCustomer().getAttributeValueByKey("CP_BUSINESS_NUMBER", null) |
getTaxOperationContext().getJournalType() | getJournalType() |
getTaxOperationContext().getDocumentId() | getDocumentId() |
getTaxOperationContext().getTaxOverrideContext() | getTaxOverride() |
getTaxOperationContext().getTaxExemption() | getTaxExemptionId() |
getTaxOperationContext().getItems() | getTaxableItems() |
getTaxOperationContext().getStoreCode() | getStore().getCode() |
getTaxOperationContext().getOriginAddress() | getOriginAddress() |
getTaxOperationContext().getDestinationAddress() | getDestinationAddress() |
getTaxOperationContext().isTaxInclusive() | isTaxInclusive() |
getTaxOperationContext().getOrderNumber() | No equivalent. |
getTaxOperationContext().getTransactionType() | No equivalent. |
getTaxOperationContext().getItemObjectType() | No equivalent. |
getTaxOperationContext().getShippingItemReferenceId() | No equivalent. |
getTaxOperationContext().getFieldValue(key) | No equivalent. |
getTaxOperationContext().setFieldValue(key, value) | No equivalent. |
getTaxOperationContext().getFields() | No equivalent. |
getTaxOperationContext().setFields(map) | No equivalent. |
TaxableItem field | XPFTaxableShoppingItem equivalent |
---|---|
getItemGuid() | getGuid() . |
getItemCode() | getSkuCode() |
getTaxablePrice() | getTaxablePrice() |
getTaxCode() | getTaxabilityCode() |
getQuantity() | getQuantity() |
getCurrency() | Available in XPFTaxCalculationContext . |
isTaxCodeActive() | No equivalent. |
getFieldValue() | No equivalent. |
getFields() | No equivalent. |
getItemDescription() | No equivalent. |
For more information about the new Extension Point Framework classes, see XPFTaxCalculationContext and XPFTaxableShoppingItem.
Your extension will need to create new XPFTaxedItem
objects. These are similar to the existing TaxedItem
objects, as shown in the table below:
XPFTaxedItem field | TaxedItem equivalent | Notes |
---|---|---|
setTaxableItem(taxableItem) | setTaxableItem() | Set this to the TaxableItem object passed in from XPFTaxCalculationContext . |
setTaxRecords(taxRecords) | setTaxRecords() |
XPFTaxRecord field | TaxRecord equivalent |
---|---|
setTaxCode(taxCode) | setTaxCode() |
setTaxName(taxName) | setTaxName(taxName) |
setTaxRate(taxRate) | setTaxRate(taxRate) |
setTaxJurisdiction(taxRate) | setTaxJurisdiction(taxRate) |
setTaxRegion(taxRegion) | setTaxRegion(taxRegion) |
setTaxValue(taxValue) | setTaxValue(taxValue) |
For more information about the new Extension Point Framework classes, see XPFTaxedItem and XPFTaxRecord.