composer require arobases/sylius-transporter-label-generation-plugin
<?php
# config/bundles.php
return [
Arobases\SyliusTransporterLabelGenerationPlugin\ArobasesSyliusTransporterLabelGenerationPlugin::class => ['all' => true],
];
# config/routes.yaml
arobases_sylius_transporter_label_generation_admin:
resource: "@ArobasesSyliusTransporterLabelGenerationPlugin/Resources/config/admin_routing.yml"
prefix: /admin
# config/packages/arobases_sylius_transporter_label_generation.yaml
imports:
- { resource: "@ArobasesSyliusTransporterLabelGenerationPlugin/Resources/config/resources.yaml" }
override Shipment entity to include TransporterTrait
# Entity/Shipping/Shipment.php
/**
* @ORM\Entity
* @ORM\Table(name="sylius_shipment")
*/
class Shipment extends BaseShipment {
use TransporterTrait;
}
override Address entity to include PickupPointTrait
# Entity/Addressing/Address.php
/**
* @ORM\Entity
* @ORM\Table(name="sylius_address")
*/
class Address extends BaseAddress
{
use PickupPointTrait;
}
override Product entity to include HsCodeTrait and add the field to your form
# Entity/Product/Product.php
/**
* @ORM\Entity
* @ORM\Table(name="sylius_product")
*/
class Product extends BaseProduct {
use HsCodeTrait;
}
# Form/Extension/Product/ProductTypeExtension.php
->add('hsCode', TextType::class,[
'label' => "arobases_sylius_transporter_label_generation_plugin.form.product.hs_code",
'required' => false
])
# Product/Tab/_details.html.twig
{{ form_row(form.hsCode) }}
override OrderRepository or add it 'findByShipment'
# OrderRepository.php
public function findByShipment($transporterId): QueryBuilder
{
$qb = $this->createQueryBuilder('o')
->leftJoin('o.shipments', 'shipment')
->leftJoin('shipment.transporter', 'transporter')
->andWhere('transporter.id = :transporterId')
->andWhere('o.shippingState IN (:shippingState)')
->andWhere('o.paymentState IN (:paymentState)')
->setParameter('transporterId', $transporterId)
->setParameter('shippingState', ["ready", "shipped", "in_preparation"])
->setParameter('paymentState', ["paid"])
;
return $qb;
}
bin/console doctrine:migration:migrate
Don't forget to run those commands to generate your files
bin/console asset:install
bin/console sylius:theme:asset:install
!!! think to allow file writting for label generation (public/upload/label/colissimo) !!!
As things stand, you can add only Colissimo transporter. To add another one, override TransporterType and add more choices :
# TransporterType.php
->add('name', ChoiceType::class, [
'label' => 'sylius.ui.name',
'choices' => [
'Colissimo' => 'colissimo',
'another transporter' => 'another_transporter'
],
])
Create another connector service to looks like ColissimoRequest service and complete OrderLabelController.php to handle others transporters.