• Stars
    star
    29
  • Rank 860,307 (Top 17 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Shipping export management architecture for Sylius based apps.

BitBag SyliusShippingExportPlugin


Slack Support

At BitBag we do believe in open source. However, we are able to do it just because of our awesome clients, who are kind enough to share some parts of our work with the community. Therefore, if you feel like there is a possibility for us to work together, feel free to reach out. You will find out more about our professional services, technologies, and contact details at https://bitbag.io/.

Like what we do? Want to join us? Check out our job listings on our career page. Not familiar with Symfony & Sylius yet, but still want to start with us? Join our academy!

Table of Content


Overview


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.

Installation

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 in your config/routes.yaml file:

# config/routes.yaml

bitbag_shipping_export_plugin:
    resource: "@BitBagSyliusShippingExportPlugin/Resources/config/routing.yml"
    prefix: /admin

Usage

Adding shipping export configuration form

<?php

declare(strict_types=1);

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',
                    ]),
                ],
            ])
        ;
    }
}

Service definition

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" }

Adding shipping export event listener

<?php

declare(strict_types=1);

namespace App\EventListener;

use BitBag\SyliusShippingExportPlugin\Entity\ShippingExportInterface;
use Doctrine\Persistence\ObjectManager;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\RequestStack;
use Webmozart\Assert\Assert;

final class FrankMartinShippingExportEventListener
{
    /** @var RequestStack */
    private $requestStack;

    /** @var Filesystem */
    private $filesystem;

    /** @var ObjectManager */
    private $shippingExportManager;

    /** @var string */
    private $shippingLabelsPath;

    public function __construct(
        RequestStack $requestStack,
        Filesystem $filesystem,
        ObjectManager $shippingExportManager,
        string $shippingLabelsPath
    ) {
        $this->requestStack = $requestStack;
        $this->filesystem = $filesystem;
        $this->shippingExportManager = $shippingExportManager;
        $this->shippingLabelsPath = $shippingLabelsPath;
    }

    public function exportShipment(ResourceControllerEvent $event): void
    {
        /** @var ShippingExportInterface $shippingExport */
        $shippingExport = $event->getSubject();
        Assert::isInstanceOf($shippingExport, ShippingExportInterface::class);

        $shippingGateway = $shippingExport->getShippingGateway();
        Assert::notNull($shippingGateway);

        if ('frank_martin_shipping_gateway' !== $shippingGateway->getCode()) {
            return;
        }

        $session = $this->requestStack->getSession();
        $flashBag = $session->getBag('flashes');

        if (false) {
            $flashBag->add('error', 'bitbag.ui.shipping_export_error'); // Add an error notification

            return;
        }

        $flashBag->add('success', 'bitbag.ui.shipment_data_has_been_exported'); // Add success notification
        $this->saveShippingLabel($shippingExport, 'Some label content received from external API', 'pdf'); // Save label
        $this->markShipmentAsExported($shippingExport); // Mark shipment as "Exported"
    }

    public function saveShippingLabel(
        ShippingExportInterface $shippingExport,
        string $labelContent,
        string $labelExtension
    ): void {
        $labelPath = $this->shippingLabelsPath
            . '/' . $this->getFilename($shippingExport)
            . '.' . $labelExtension;

        $this->filesystem->dumpFile($labelPath, $labelContent);
        $shippingExport->setLabelPath($labelPath);

        $this->shippingExportManager->persist($shippingExport);
        $this->shippingExportManager->flush();
    }

    private function getFilename(ShippingExportInterface $shippingExport): string
    {
        $shipment = $shippingExport->getShipment();
        Assert::notNull($shipment);

        $order = $shipment->getOrder();
        Assert::notNull($order);

        $orderNumber = $order->getNumber();

        $shipmentId = $shipment->getId();

        return implode(
            '_',
            [
                $shipmentId,
                preg_replace('~[^A-Za-z0-9]~', '', $orderNumber),
            ]
        );
    }

    private function markShipmentAsExported(ShippingExportInterface $shippingExport): void
    {
        $shippingExport->setState(ShippingExportInterface::STATE_EXPORTED);
        $shippingExport->setExportedAt(new \DateTime());

        $this->shippingExportManager->persist($shippingExport);
        $this->shippingExportManager->flush();
    }
}

Service definition

services:
    app.event_listener.frank_martin_shipping_export:
        class: App\EventListener\FrankMartinShippingExportEventListener
        arguments:
            - '@request_stack'
            - '@filesystem'
            - '@bitbag.manager.shipping_export'
            - '%bitbag.shipping_labels_path%'
        tags:
            - { name: kernel.event_listener, event: 'bitbag.shipping_export.export_shipment', method: exportShipment }

Plugin parameters

parameters:
    bitbag.shipping_gateway.validation_groups: ['bitbag']
    bitbag.shipping_labels_path: '%kernel.project_dir%/shipping_labels'

Available services you can decorate and forms you can extend

$ bin/console debug:container | grep bitbag

Parameters you can override in your parameters.yml(.dist) file

$ bin/console debug:container --parameters | grep bitbag

Testing

$ composer install
$ APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon
$ cd tests/Application
$ yarn install
$ yarn run gulp
$ bin/console assets:install public -e test
$ bin/console doctrine:schema:create -e test
$ shipping-export
$ open http://localhost:8080
$ vendor/bin/behat
$ vendor/bin/phpspec run
$ vendor/bin/phpstan analyse -c phpstan.neon -l max src/
$ vendor/bin/ecs check src

We are here to help

This open-source plugin was developed to help the Sylius community. If you have any additional questions, would like help with installing or configuring the plugin, or need any assistance with your Sylius project - let us know!

Read more about BitBag Sylius Shipping Export Plugin

About us


BitBag is a company of people who love what they do and do it right. We fulfill the eCommerce technology stack with Sylius, Shopware, Akeneo, and Pimcore for PIM, eZ Platform for CMS, and VueStorefront for PWA. Our goal is to provide real digital transformation with an agile solution that scales with the clientsโ€™ needs. Our main area of expertise includes eCommerce consulting and development for B2C, B2B, and Multi-vendor Marketplaces.
We are advisers in the first place. We start each project with a diagnosis of problems, and an analysis of the needs and goals that the client wants to achieve.
We build unforgettable, consistent digital customer journeys on top of the best technologies. Based on a detailed analysis of the goals and needs of a given organization, we create dedicated systems and applications that let businesses grow.
Our team is fluent in Polish, English, German and, French. That is why our cooperation with clients from all over the world is smooth.

Some numbers from BitBag regarding Sylius:

  • 50+ experts including consultants, UI/UX designers, Sylius trained front-end and back-end developers,
  • 120+ projects delivered on top of Sylius,
  • 25+ countries of BitBagโ€™s customers,
  • 4+ years in the Sylius ecosystem.

Our services:

  • Business audit/Consulting in the field of strategy development,
  • Data/shop migration,
  • Headless eCommerce,
  • Personalized software development,
  • Project maintenance and long term support,
  • Technical support.

Key clients: Mollie, Guave, P24, Folkstar, i-LUNCH, Elvi Project, WestCoast Gifts.


If you need some help with Sylius development, don't be hesitated to contact us directly. You can fill the form on this site or send us an e-mail at [email protected]!


Community


For online communication, we invite you to chat with us & other users on Sylius Slack.

Demo Sylius Shop


We created a demo app with some useful use-cases of plugins! Visit sylius-demo.bitbag.io to take a look at it. The admin can be accessed under sylius-demo.bitbag.io/admin/login link and bitbag: bitbag credentials. Plugins that we have used in the demo:

BitBag's Plugin GitHub Sylius' Store
ACL Plugin Private. Available after the purchasing. https://plugins.sylius.com/plugin/access-control-layer-plugin/
Braintree Plugin https://github.com/BitBagCommerce/SyliusBraintreePlugin https://plugins.sylius.com/plugin/braintree-plugin/
CMS Plugin https://github.com/BitBagCommerce/SyliusCmsPlugin https://plugins.sylius.com/plugin/cmsplugin/
Elasticsearch Plugin https://github.com/BitBagCommerce/SyliusElasticsearchPlugin https://plugins.sylius.com/plugin/2004/
Mailchimp Plugin https://github.com/BitBagCommerce/SyliusMailChimpPlugin https://plugins.sylius.com/plugin/mailchimp/
Multisafepay Plugin https://github.com/BitBagCommerce/SyliusMultiSafepayPlugin
Wishlist Plugin https://github.com/BitBagCommerce/SyliusWishlistPlugin https://plugins.sylius.com/plugin/wishlist-plugin/
Sylius' Plugin GitHub Sylius' Store
Admin Order Creation Plugin https://github.com/Sylius/AdminOrderCreationPlugin https://plugins.sylius.com/plugin/admin-order-creation-plugin/
Invoicing Plugin https://github.com/Sylius/InvoicingPlugin https://plugins.sylius.com/plugin/invoicing-plugin/
Refund Plugin https://github.com/Sylius/RefundPlugin https://plugins.sylius.com/plugin/refund-plugin/

If you need an overview of Sylius' capabilities, schedule a consultation with our expert.

Additional resources for developers


To learn more about our contribution workflow and more, we encourage you to use the following resources:

License


This plugin's source code is completely free and released under the terms of the MIT license.

Contact


If you want to contact us, the best way is to fill the form on our website or send us an e-mail to [email protected] with your question(s). We guarantee that we answer as soon as we can!

More Repositories

1

SyliusCmsPlugin

Content management system for eCommerce apps created on Sylius platform. Built with Sylius code quality, flexibility, BDD.
PHP
221
star
2

OpenMarketplace

Open-source Multi-Vendor Marketplace platform based on Sylius and Symfony.
PHP
176
star
3

SyliusElasticsearchPlugin

Elasticsearch integration for Sylius apps.
PHP
119
star
4

SyliusWishlistPlugin

This plugin allows you to integrate wishlist features with Sylius platform app.
PHP
61
star
5

SyliusMolliePlugin

Sylius Mollie payment gateway integration.
PHP
55
star
6

SyliusVueStorefrontPlugin

Sylius plugin integrating Sylius with Vue Storefront
PHP
45
star
7

SyliusMailChimpPlugin

Simple MailChimp integration with Sylius eCommerce framework.
PHP
42
star
8

BitBagBible

BitBag coding standards that rock!
36
star
9

SyliusPayUPlugin

PayU payment plugin for Sylius applications.
PHP
23
star
10

SyliusInvoicingPlugin

This plugin enables generating invoices in Sylius platform application.
PHP
22
star
11

SyliusPrzelewy24Plugin

This plugin allows you to integrate Przelewy24 payments in your Sylius instance.
PHP
18
star
12

SyliusProductBundlePlugin

This plugin allows you to create new products by bundling existing products together.
PHP
18
star
13

SyliusAdyenPlugin_old

Sylius Adyen payments integration.
PHP
17
star
14

SyliusVueStorefront2Plugin

SyliusVueStorefront2Plugin provides everything you need to integrate your Sylius back-end with Vue Storefront 2.
PHP
17
star
15

SyliusMercanetBnpParibasPlugin

BnpParibas Mercanet payment gateway for Sylius based applications.
PHP
15
star
16

SyliusAdyenPlugin

Development environment for the new version of the Adyen Plugin
PHP
11
star
17

SyliusDHL24PlShippingExportPlugin

DHL Shipping export plugin for Sylius platform applications.
PHP
9
star
18

SyliusBraintreePlugin

Sylius Braintree payment gateway integration.
PHP
8
star
19

SyliusBonusPointsPlugin

The plugin extends Sylius with simple bonus points loyalty program and applies special actions for users depending on the points score.
PHP
7
star
20

SyliusAmazonPayPlugin

This plugin allows you to integrate AmazonPay payments in your Sylius instance.
PHP
7
star
21

SyliusRawHtml

Starting point for Sylius shop template development with HTML structure adjusted to Behat elements definition.
HTML
6
star
22

SyliusCrossSellingPlugin

The plugin adds a new section, โ€œRelated Productsโ€ to the product page. Displays products that were purchased with the current product recently, and if there is not enough data, displays products with the same taxons.
PHP
6
star
23

SyliusSuluPlugin

Sylius integration with Sulu cms
PHP
5
star
24

ShopwareInPostPlugin

This plugin allows you to integrate InPost with Shopware
PHP
4
star
25

SyliusCoinbasePlugin

Sylius Coinbase integration
PHP
4
star
26

SyliusMailTemplatePlugin

Sylius MailTemplate allows us to customize any email handled by Sylius Mailer. When an email is sent the plugin tries to figure out if custom template for the kind of email exists, if yes it replaces the default email with our custom one.
JavaScript
4
star
27

SyliusBDD

This repository was created for the BitBagBlog tutorial about BDD workflow in Sylius eCommerce framework.
PHP
4
star
28

SyliusShippingSubscriptionPlugin

Virtual product - subscription for free shipping
PHP
3
star
29

SyliusVueStorefront2Frontend

Front-end part of SyliusVueStorefront2 integration
Vue
3
star
30

SyliusInPostPlugin

A dedicated solution for shipment management fully integrated with InPost operator. It allows to export orders via API and generate a shipping label(s) in response.
PHP
3
star
31

SyliusPocztaPolskaShippingExportPlugin

PHP
2
star
32

SyliusProductAttributeGroupsPlugin

Plugin allows you to create groups which can be associated with product attributes.
PHP
2
star
33

SyliusBlacklistPlugin

This plugin allows counteracting suspicious behavior in eCommerce by blocking the possibility of purchases using automatic rules or manual analysis of customer behavior.
PHP
2
star
34

coding-standard

PHP
1
star
35

BitBagShopwareAppSystemBundle

PHP
1
star
36

pp-client

Poczta Polska SOAP client
PHP
1
star
37

SyliusDPDPlShippingExportPlugin

PHP
1
star
38

SyliusAgreementPlugin

PHP
1
star
39

SyliusBannerPlugin

Banner management plugin
PHP
1
star
40

SyliusSmashPromotionPlugin

PHP
1
star
41

BitBagShopwareOrlenPaczkaPlugin

Integration with the Polish Post Office, Orlen pick-up point
PHP
1
star
42

SyliusMulticartPlugin

PHP
1
star