Managing shipments in any eCommerce app is something that may be tricky. There are many shipping providers and each has its own API format you might want to use to export shipping data and request the pickup. To make this process more simple and generic, we decided to create an abstract layer for Sylius platform based applications for this purpose. This plugin allows you to write simple API calls and configuration form for specific shipping provider. The workflow is quite simple - configure a proper data that's needed to export a shipment, like access key or pickup hour, book a courier for an order with one click and get shipping label file if any was received from the API. The implementation limits to writing a shipping provider gateway configuration form, one event listener and webservice access layer.
If you are curious about the details of this plugin, read this blog post.
You can order our support on this page.
We work on amazing eCommerce projects on top of Sylius and other great Symfony based solutions, like eZ Platform, Akeneo or Pimcore. Need some help or additional resources for a project? Write us an email on [email protected] or visit our website! 🚀
We created a demo app with some useful use-cases of the plugin! Visit demo.bitbag.shop to take a look at it.
The admin can be accessed under demo.bitbag.shop/admin link and sylius: sylius
credentials.
If you use Sylius 1.4, you might get a compatibility issue for Pagerfanta. Please read this issue in order to proceed with a workaround.
$ composer require bitbag/shipping-export-plugin
Add plugin dependencies to your config/bundles.php
file:
return [
...
BitBag\SyliusShippingExportPlugin\BitBagSyliusShippingExportPlugin::class => ['all' => true],
];
Import required config in your config/packages/_sylius.yaml
file:
# config/packages/_sylius.yaml
imports:
...
- { resource: "@BitBagSyliusShippingExportPlugin/Resources/config/config.yml" }
Import routing on top of your config/routes.yaml
file:
# config/routes.yaml
bitbag_shipping_export_plugin:
resource: "@BitBagSyliusShippingExportPlugin/Resources/config/routing.yml"
prefix: /admin
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
final class FrankMartinShippingGatewayType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('iban', TextType::class, [
'label' => 'IBAN',
'constraints' => [
new NotBlank([
'message' => 'IBAN number cannot be blank.',
'groups' => 'bitbag',
])
],
])
->add('address', TextType::class, [
'label' => 'Address',
'constraints' => [
new NotBlank([
'message' => 'Address cannot be blank.',
'groups' => 'bitbag',
])
],
])
;
}
}
services:
app.form.type.frank_martin_shipping_gateway:
class: App\Form\Type\FrankMartinShippingGatewayType
tags:
- { name: bitbag.shipping_gateway_configuration_type, type: "frank_martin_shipping_gateway", label: "Transporter Gateway" }
namespace App\EventListener;
use BitBag\ShippingExportPlugin\Event\ExportShipmentEvent;
final class FrankMartinShippingExportEventListener
{
public function exportShipment(ExportShipmentEvent $event): void
{
$shippingExport = $event->getShippingExport();
$shippingGateway = $shippingExport->getShippingGateway();
if ('frank_martin_shipping_gateway' !== $shippingGateway->getCode()) {
return;
}
if (false) {
$event->addErrorFlash(); // Add an error notification
return;
}
$event->addSuccessFlash(); // Add success notification
$event->saveShippingLabel("Some label content received from external API", 'pdf'); // Save label
$event->exportShipment(); // Mark shipment as "Exported"
}
}
services:
app.event_listener.frank_martin_shipping_export:
class: App\EventListener\FrankMartinShippingExportEventListener
tags:
- { name: kernel.event_listener, event: 'bitbag.export_shipment', method: exportShipment }
parameters:
bitbag.shipping_gateway.validation_groups: ['bitbag']
bitbag.shipping_labels_path: '%kernel.root_dir%/../shipping_labels'
$ bin/console debug:container | grep bitbag
$ bin/console debug:container --parameters | grep bitbag
$ composer install
$ cd tests/Application
$ yarn install
$ yarn run gulp
$ bin/console assets:install public -e test
$ bin/console doctrine:schema:create -e test
$ bin/console server:run 127.0.0.1:8080 -d public -e test
$ shipping-export
$ open http://localhost:8080
$ vendor/bin/behat
$ vendor/bin/phpspec run
Learn more about our contribution workflow on http://docs.sylius.org/en/latest/contributing/.