se/opentrans-bundle

This bundle integrates the opentrans library into Symfony2. Allows to create OpenTRANS compatible documents from PHP.

v0.1.3 2014-03-14 13:53 UTC

README

Latest Stable Version SensioLabsInsight

This bundle integrates the [opentrans] (https://github.com/sveneisenschmidt/opentrans) library into Symfony2.

Dev branch is master branch.

Build Status

Table of Contents

Installation

Configuration

Usage

Tests

Installation

The recommended way to install is through Composer.

{
    "require": {
        "se/opentrans-bundle": "dev-master"
    }
}

Add the bundle to your AppKernel.php file:

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new SE\Bundle\OpenTransBundle\SEOpenTransBundle(),
    // ...
);

Configuration

You can declare default documents in your app configuration. (i.e. app/config/config.yml)

se_open_trans:

  documents:

    my_default_order_document:
      type: order
      document:
        header:
          control_info:
            generator_info: "My Order Document"

    my_default_order_document_2:
      type: order
      document:
        header:
          control_info:
            generator_info: "My Order Document 2"
          order_info:
            custom_key: custom_var
            my_shop_id: Magento_1702

Usage

Your configured document builder is available as a member in se.opentrans.document_builder_manager service. Retrieve it by calling $manager->getDocumentBuilder($documentName).

$manager = $container->get('se.opentrans.document_builder_manager');
$builder = $manager->getDocumentBuilder('my_default_order_document');
$document = $builder->getDocument();

The document builder is created as a service aswell. So instead calling the document builder manager you can directly load the document builder from the container. The name is consisting of the base key se.opentrans.document_builder. plus the se_open_trans.documents key from your configuration. (i.e. my_default_order_document)

$builder = $container->get('se.opentrans.document_builder.my_default_order_document');
$document = $builder->getDocument();

Run tests

$> vendor/bin/phpunit