Git Product home page Git Product logo

arobasessyliustransporterlabelgenerationplugin's Introduction

Arobases Sylius Transporter generation label plugin

banner_arobases

Installation

Step 1: Download the plugin

composer require arobases/sylius-transporter-label-generation-plugin

Step 2: Enable the plugin

<?php
# config/bundles.php

return [
    Arobases\SyliusTransporterLabelGenerationPlugin\ArobasesSyliusTransporterLabelGenerationPlugin::class => ['all' => true],
];

Step 3: Import Routes

# config/routes.yaml
arobases_sylius_transporter_label_generation_admin:
    resource: "@ArobasesSyliusTransporterLabelGenerationPlugin/Resources/config/admin_routing.yml"
    prefix: /admin

Step 4: Import config

# config/packages/arobases_sylius_transporter_label_generation.yaml
imports:
  - { resource: "@ArobasesSyliusTransporterLabelGenerationPlugin/Resources/config/resources.yaml" }

Step 5: Include Traits

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

Step 6: Update database

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

How it works

!!! think to allow file writting for label generation (public/upload/label/colissimo) !!!

Add a transporter

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.

arobasessyliustransporterlabelgenerationplugin's People

Contributors

arobases-e-commerce avatar costa-jeremy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.