This Bundle adds the ability to dynamically inject 'fees' as new Line Items into the Checkout process.
For example, if a 'Handling Fee' is to be charged for orders under $100.
This Bundle takes advantage of OroCommerce's 'Freeform LineItem' feature, where a LineItem can be added to the Checkout without being linked to a Product.
It also supports Fees added as Subtotals against the entire Order.
CreateCheckoutListener
is required to
manually persist/flush the Checkout so that the new line item is saved.NOTE: Adjust instructions as needed for your local environment
Install via Composer
composer require aligent/orocommerce-fees-bundle
Once installed, run platform update to perform the installation:
php bin/console oro:platform:update --env=prod
Note: This Tax Code will apply to the Fee itself.
Oro does not apply taxes to FreeForm Line Items, this configuration is used by
our ContextHandler\FreeFormAwareTaxOrderLineItemHandler
to apply the correct tax.
processing_fee
column to the oro_order
database table (and extends the Oro Order
entity)All configuration is stored in System Configuration (oro_config_value
).
This feature allows OroCommerce to charge an additional percentage for payments made via specific methods.
The percentage can be configured on a per-Method basis, eg:
After installation, visit the System Configuration (or Website Configuration to configure on a per-Website scope).
Each Payment Method will be visible here. Set the Percentage to a value above 0
to charge a processing fee for that method:
If the Customer chooses that method during the Checkout, a processing fee will be calculated and add to the Subtotals:
NOTE: Processing Fees are not currently support by PayPal Express as they are not included in the Subtotal, which causes a payment validation error.
Additionally, the PayPal User Agreement does not allow charging Payment Processing Fees (See #13)
Create a new Bundle (or use an existing one as needed)
Create a new class for the fee (eg MyBundle\Fee\HandlingFeeProvider
).
This new class should extend Aligent\FeesBundle\Fee\AbstractLineItemFee
.
Define a new service for the new fee, and add it to the fee registry:
services:
Acme\MyBundle\Fee\HandlingFeeProvider:
parent: '@Aligent\FeesBundle\Fee\Provider\AbstractLineItemFeeProvider'
tags:
- { name: aligent_fees.fee_provider, priority: 0 }
Create a new Fee Provider Class and implement the applicable methods:
<?php
namespace Acme\MyBundle\Fee\Provider;
use Aligent\FeesBundle\Fee\AbstractLineItemFeeProvider;
use Oro\Bundle\CheckoutBundle\Entity\Checkout;
class HandlingFeeProvider extends AbstractLineItemFeeProvider
{
const NAME = 'fees.handling_fee';
const TYPE = 'handling_fee';
const LABEL = 'acme.my_bundle.fees.handling_fee.label';
const SKU = 'HF001'; // Shouldn't be a real product
const AMOUNT = 10.00;
/**
* Get Fee name
* @return string
*/
public function getName(): string
{
return self::NAME;
}
/**
* Return label key
* @return string
*/
public function getLabel(): string
{
return $this->translator->trans(self::LABEL);
}
/**
* Return SKU of Fee
* @return null|string
*/
public function getSKU(): ?string
{
return self::SKU;
}
/**
* @param Checkout $checkout
* @return float|null
*/
public function getAmount(Checkout $checkout): ?float
{
return self::AMOUNT;
}
/**
* Is the fee Supported by this Entity?
* @param mixed $entity
* @return bool
*/
public function isSupported($entity): bool
{
return ($entity instanceof Checkout);
}
}
Where to look first if something goes wrong
EventListener\CreateCheckoutListener::onStartCheckoutConditionCheck()
injects Fees into the current Checkout as new LineItems.Fee\AbstractFee::getCheckoutLineItem()
builds and generates the Fee Freeform LineItem, including Price/Currency/SKU/Unit/etc.ContextHandler\FreeFormAwareTaxOrderLineItemHandler
decorates the core Oro \Oro\Bundle\TaxBundle\OrderTax\ContextHandler\OrderLineItemHandler
class so that it can support Tax calculations for Freeform Line Items.