bitbag / shipping-export-plugin
Shipping data export environment for Sylius platform applications
Installs: 103 693
Dependents: 16
Suggesters: 0
Security: 0
Stars: 30
Watchers: 9
Forks: 29
Open Issues: 1
Type:sylius-plugin
Requires
- php: ^8.0
- doctrine/dbal: ^2.7 || ^3.0
- sylius/sylius: ~1.12.0 || ~1.13.0
Requires (Dev)
- behat/behat: ^3.7
- behat/mink-selenium2-driver: ~1.6.0
- bitbag/coding-standard: ^3.0
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.8
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- phpspec/phpspec: ^7.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.8.1
- phpstan/phpstan-doctrine: 1.3.69
- phpstan/phpstan-strict-rules: ^1.3.0
- phpstan/phpstan-webmozart-assert: ^1.2.0
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- sylius-labs/coding-standard: ^4.0
- symfony/browser-kit: ^5.4 || ^6.0
- symfony/debug-bundle: ^5.4 || ^6.0
- symfony/dotenv: ^5.4 || ^6.0
- symfony/intl: ^5.4 || ^6.0
- symfony/web-profiler-bundle: ^5.4 || ^6.0
- symfony/webpack-encore-bundle: ^1.15
Conflicts
- doctrine/persistence: <3.0
- dev-master
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.0.1
- v2.0.0
- v1.7.0
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0
- dev-OP-401
- dev-OP-514
- dev-OP-502
- dev-fix/op-311-fix-grid-sorting
- dev-op264_fix
- dev-InstallationProcedures
- dev-feature/slack-notifications
- dev-feature/OP-121
- dev-OPSRC-496/Add_bitbag_coding_standard_to_every_plugin
- dev-OPSRC-602/fix-symfony-flex
This package is auto-updated.
Last update: 2024-12-16 10:12:31 UTC
README
BitBag SyliusShippingExportPlugin
We want to impact many unique eCommerce projects and build our brand recognition worldwide, so we are heavily involved in creating open-source solutions, especially for Sylius. We have already created over 35 extensions, which have been downloaded almost 2 million times.
You can find more information about our eCommerce services and technologies on our website: https://bitbag.io/. We have also created a unique service dedicated to creating plugins: https://bitbag.io/services/sylius-plugin-development.
Do you like our work? Would you like to join us? Check out the “Career” tab: https://bitbag.io/pl/kariera.
About us
BitBag is a software house that implements tailor-made eCommerce platforms with the entire infrastructure—from creating eCommerce platforms to implementing PIM and CMS systems to developing custom eCommerce applications, specialist B2B solutions, and migrations from other platforms.
We actively participate in Sylius's development. We have already completed over 150 projects, cooperating with clients from all over the world, including smaller enterprises and large international companies. We have completed projects for such important brands as Mytheresa, Foodspring, Planeta Huerto (Carrefour Group), Albeco, Mollie, and ArtNight.
We have a 70-person team of experts: business analysts and eCommerce consultants, developers, project managers, and QA testers.
Our services:
- B2B and B2C eCommerce platform implementations
- Multi-vendor marketplace platform implementations
- eCommerce migrations
- Sylius plugin development
- Sylius consulting
- Project maintenance and long-term support
- PIM and CMS implementations
Some numbers from BitBag regarding Sylius:
- 70 experts on board
- +150 projects delivered on top of Sylius,
- 30 countries of BitBag’s customers,
- 7 years in the Sylius ecosystem.
- +35 plugins created for Sylius
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 simpler and generic, we created an abstract layer for Sylius platform-based applications. This plugin allows you to write simple API calls and configuration forms for specific shipping providers. The workflow is quite simple - configure the 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 a 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 a web service access layer.
Installation
For the full installation guide, please go here.
Requirements
We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.
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
Functionalities
All main functionalities of the plugin are described here.
Demo
We created a demo app with some useful use-cases of plugins! Visit http://demo.sylius.com/ to take a look at it.
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:
- Sylius Documentation
- Sylius Contribution Guide
- Sylius Online Course
- Sylius Shipping Export Plugin Blog
License
This plugin's source code is completely free and released under the terms of the MIT license.
Contact and Support
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! Contact us or send us an e-mail to hello@bitbag.io with your question(s).
Community
We invite you to chat with us & other users on Sylius Slack for online communication.