In Venddor IO, a document signifies a collection of data designed to verify specific details or transactions. Examples of such documents include order invoices, packing slips, and gift certificates. The platform facilitates the customization of these document templates via its user-friendly interface. Navigate to Administration → Notifications → Documents within the admin panel to select and edit a desired document template.
Each document template is essentially an HTML layout, interlaced with dynamic components like variables and snippets. The rendering of these documents is orchestrated using the Twig template engine, enabling developers to harness its expansive feature set.
Venddor IO classifies documents into distinct types for organisational clarity. A comprehensive list of these document types is catalogued in the documents/types schema, found at app/schemas/documents/types.php.
Every type is characterised as an individual class that complies with the \Tygh\Template\Document\IType interface. These are duly recorded in the Tygh::$app container, following the structure:
Tygh::$app['template.document.[type].type']
Here, [type] refers to the document's type identifier, such as 'order'.
Certain document types can be augmented with additional functionalities by implementing specific interfaces:
One crucial aspect of Venddor IO's document management system is that the context framework remains consistent for documents belonging to the same type.
At present, Venddor IO has implemented various document types, including:
This system provides a coherent and efficient approach to handling diverse document types, ensuring that users and developers have an intuitive and streamlined experience in managing and customising them.
The context in Venddor IO represents the system's state and the prevailing data when the document is generated. For instance, the context for an order-related document is the order itself. It's pivotal to know the context structure for every document type to enable the integration of custom variables founded on the context.
Variables serve as the dynamic components of templates, accessing context and other relevant data. Every document type possesses unique variables, detailed in the schema at documents/[type], where [type] represents the document's type.
... (and so forth)
Venddor IO's document management process is made seamless and efficient with a range of classes:
... (and others)
Aided by these classes, Venddor IO offers a structured and modular approach to handling various document types, ensuring a coherent user and developer experience.
If you wish to introduce a new variable, it's simple. Formulate a variable class aligned with the \Tygh\Template\IVariable interface, and register this in the document schema.
For instance, to embed a barcode for orders, consider the following:
A file in app/addons/barcode/Tygh/Addons/Barcode/Documents/Order/BarcodeVariable.php is crafted as:
namespace Tygh\Addons\Barcode\Documents\Order;
use Tygh\Registry;
use Tygh\Template\Invoice\Order\Context;
use Tygh\Template\IVariable;
class BarcodeVariable implements IVariable {
public $image;
public function __construct(Context $context) {
// ...[implementation details]
}
}
To amplify the variable schema for order type documents, include the file /app/addons/barcode/schemas/documents/order.post.php.
$schema['barcode'] = array(
'class' => '\Tygh\Addons\Barcode\Documents\Order\BarcodeVariable'
);
return $schema;
Post this, a fresh variable, "barcode", with an "image" attribute will be available during document editing.
To incorporate new snippets, simply add them to the database for the specific document's template. This creates a linkage of the snippet type to the document type and its identifier.