Sylius Digital Download: Extending
Extending Sylius Digital Download: replaceable services, custom payment check, customizing the email, Twig hooks, events and a note on stability.
Sylius Digital Download: Extending
This documentation always describes the latest published version.
Replaceable services
Every business service of the plugin is bound to the container via an interface. You replace a service by pointing the interface to a service of your own in your app.
| Interface | Default class | Purpose |
|---|---|---|
Mmd\SyliusDigitalDownloadPlugin\Service\DownloadFileUploaderInterface |
DownloadFileUploader |
Validates uploads and writes them to the storage |
Mmd\SyliusDigitalDownloadPlugin\Service\DownloadGrantIssuerInterface |
DownloadGrantIssuer |
Creates the links of a paid order |
Mmd\SyliusDigitalDownloadPlugin\Service\DownloadGrantRevokerInterface |
DownloadGrantRevoker |
Blocks the links of an order |
Mmd\SyliusDigitalDownloadPlugin\Service\DownloadSettingsProviderInterface |
DownloadSettingsProvider |
Provides the settings (database before YAML default) |
Mmd\SyliusDigitalDownloadPlugin\Service\DownloadTokenGeneratorInterface |
DownloadTokenGenerator |
Generates the token |
Mmd\SyliusDigitalDownloadPlugin\Service\OrderPaymentCheckerInterface |
OrderPaymentChecker |
Decides whether an order is fully paid |
Mmd\SyliusDigitalDownloadPlugin\Email\DownloadReadyNotifierInterface |
DownloadReadyNotifier |
Sends the email with the links |
Mmd\SyliusDigitalDownloadPlugin\Repository\DownloadFileRepositoryInterface |
DownloadFileRepository |
Access to the files |
Mmd\SyliusDigitalDownloadPlugin\Repository\DownloadGrantRepositoryInterface |
DownloadGrantRepository |
Access to the links |
You do not replace the storage via an interface, but via the storage setting (see Configuration).
Example: custom payment check
Do you want to release links already on a down payment? Replace the check with a class of your own:
namespace App\Download;
use Mmd\SyliusDigitalDownloadPlugin\Service\OrderPaymentCheckerInterface;
use Sylius\Component\Core\Model\OrderInterface;
final class DepositPaymentChecker implements OrderPaymentCheckerInterface
{
public function isFullyPaid(OrderInterface $order): bool
{
// your own rule
}
}
# config/services.yaml
services:
App\Download\DepositPaymentChecker: ~
Mmd\SyliusDigitalDownloadPlugin\Service\OrderPaymentCheckerInterface: '@App\Download\DepositPaymentChecker'
The route
/downloads/{token}accepts only tokens of exactly 64 lowercase letters and digits, and the database column is 64 characters long. A customDownloadTokenGeneratorInterfacemust deliver exactly this format, otherwise the links do not work.
Customizing the email
The email is a regular Sylius mailer entry with the code mmd_digital_download_ready:
sylius_mailer:
emails:
mmd_digital_download_ready:
subject: mmd_sylius_digital_download.email.subject
template: '@MmdSyliusDigitalDownloadPlugin/email/download_ready.html.twig'
Two ways to customize it:
- Change the text: Override the translation keys
mmd_sylius_digital_download.email.*in your own translation files (domainmessages). - Change the layout: Place the template at
templates/bundles/MmdSyliusDigitalDownloadPlugin/email/download_ready.html.twigin your app. The template hasorder,grants,channelandlocaleCodeavailable.
Twig
The two functions mmd_download_grants and mmd_download_blocked_reason and the hook for the customer account are described under Storefront. For the admin page, there are the hooks sylius_admin.product_variant.update.content.form.sections and sylius_admin.product_variant.create.content.form.sections, through which the plugin shows the "Digital download" section.
Events and tags
The plugin dispatches no events of its own and ships no compiler pass. It listens to three events:
| Event | Purpose |
|---|---|
workflow.sylius_payment.completed.complete |
Create links and send the email |
workflow.sylius_payment.completed.refund |
Block links if the order is no longer fully paid |
sylius.menu.admin.main |
Menu entry in the admin |
To react to a paid order yourself, hook into the same workflow event of the payment.
Stability
The plugin gives no formal backward compatibility guarantee for its interfaces. Pin the version in your composer.json and re-read the interfaces you have replaced before every update.