« Builder Add-On » for dynamic Downloadable Product building

The configuration options are located in System » Configuration » Catalog » Downloadable Products Builder

Order Item Status to build Download

Allows to set the order status with which the product build shall be triggered.

Default Build Command Base Path

Allows to set a default Base Path setting that is used in the Build Command definition.

Allow Customer to request Build Update

Set to Yes to allow customers to request an update of their purchased downloadable product (if it is dynamically built).

Build Notification Email Sender

The Email identity to be used for the related Transactional Email Messages.

Email Template for notification on available Builds

The email template to use for the notification of the customer that his purchased Downloadable Product is available.

Email Template for notification on failed Builds

The email template to use for the notification of the customer that his purchased Downloadable Product is unavailable due to build errors.

Email Template for notification on updated Builds

The email template to use for the notification of the customer that the requested Update to his purchased Downloadable Product is available.

Email Template for notification on failed update Builds

The email template to use for the notification of the customer that the requested Update to his purchased Downloadable Product is unavailable due to build errors.

Schedule Build Run

Dynamic builds are put into a Build Event Queue, a Magento Cron-Job is regularly checking for open builds to perform. Define here the time in minutes when a build run shall be scheduled. To collect single Build Events for one customer into a single Transactional Email Message, have this time considerable lower than the following option.

Schedule Email Notifications

A Magento Cron-Job is regularly checking if there are build related Transactional Messages to be sent, define here the time in minuts when such a check shall be performed. To collect individual status updates of one customer order into a single message have this time higher than the option above.

Best is to have the Email Notification Schedule at odds with the Build Schedule (e.g. Build Schedule every 10mins, the Email Schedule every 25mins.) to prevent parallel execution of builds and emails.

Setup of a Magento CRON execution is required for this, see here for more on this. To monitor the Magento Job Execution this is a nice extension to monitor the stores scheduled activities.

Please set the required Magento CRON execution to a cycle at least equal or lesser than the Schedule Build Run to arrive at the desired cycle times for Build and Email Notifications.

Define Build Commands

Use System » Tools » Build Commands for Downloadable Products to define your build commands:

To add a new Build Command use Add Command, click one of the list entries to edit the related Build Command:

Build Title

Is the title of this Build Command, later used for selection to the related Downloadable Link.

Base Path

This path is available as template variable {{var base_path}} in the Commands area. Allows you to easily change a base path if required in your commands.

Commands

Shell commands to be executed in sequence (one command per line) with the following available template variables (same notation as used in the Email Templates):

Build Target

The target file for the shell commands, use it as command line parameter in your shell commands to generate the correct target file. The full pathname of the target file will be relative to the Magento Stores installation directory:

  media/downloadable/tmp/build/<Customer ID>/<Build Target>

The Add-On is checking if the related file is present after the command execution, and then moves the Target File to:

  media/downloadable/build/links/<Customer ID>/<Build Target>



Template Variables (for Build Commands and Target File Name)

The following template variables (the notation is the same as for the Transactional Email Templates) are available for the Build Commands and the Target File:

Data ObjectData available with example
customerAll data of the related Customer: {{var customer.name}}
orderAll data of the related Order: {{var order.increment_id}}
order_itemAll data of the related Order Item: {{var order_item.id}}
productAll data of the related Product: {{var product.sku}}
linkpurchasedAll data of the related purchased Link: {{var linkpurchased.section_title}}
linkAll data of the related Downloadable Link (from Product): {{var link.link_title}}
link_attributesThe related Custom Attributes for the Downloadable Link (see also here):
{{var link_attributes.downloadable_link_format}}
Use Custom Attributes if you want to sell different build options of the Downloadable Link.
The value of an Attribute is derived from its original Value all lowercase and all non-word Characters (spaces, etc.) are converted to hyphens ('-') to make the value command line compatible: e.g. Magento 1.8 will become magento-1.8, Hello World will become hello-world.
base_pathThe base path as defined for the Build Command: {{var build_path}}
targetThe target file name including path to media/tmp/build/<Customer ID> of the stores base directory



Example for Build Command
somescript.sh -option1 {{var product.sku}} -option2 {{var customer.email}} -option3 {{var link_attributes.downloadable_link_format}}
fmt -w 50 {{var base_path}}/LoremIpsum.txt > {{var target}}



Example for Target File Name
downloadable-purchase-{{var order.increment_id}}-{{var order_item.id}}.txt



Complex Build Commands

To write complex Build Commands, to process PHP-Code or data before the build commands are executed use a template block to do this. And call the related block inside of the Build Command, just like in the Transactional Email Template notation.

The following example is writing some data to a File, which us being used later in the Shell Scripts:

Build Command

{{block type='core/template' area='frontend' template='downloadplusbuilder/command/writetofile.phtml' event=$event file='buildinfo.txt'}}

In the Frontend “Default” template folder there is the related writetofile.phtml block located which executes the related code:

Template Block Example

<?php
/* EXAMPLE: Command Block to write content to a file before command processing */
$event = $this->getEvent();
$product = $event->getProduct();
$customer = $event->getCustomer();
$file = $this->getFile();
$path = Mage::getModel('downloadplusbuilder/product_type')->getBaseTmpPath($customer);
@mkdir($path, 0770, true);
 
file_put_contents($path.DS.$file, $product->getShortDescription());
?>

To send back a command to the Build Command script list, use echo and output the related part as template output.

Template Variables (for Transactional Emails)

The following template variables Transactional Email Templates:

Data ObjectData available with example
customerAll data of the related Customer: {{var customer.name}}
orderAll data of the related Order: {{var order.increment_id}}
order_itemsAll data of the related Order Items, requires its dedicated rendering block:
{{block type='downloadplusbuilder/email_order_items' area='frontend'}}
build_statusThe current build status: {{var build_status}}



This tab shows the Downloadable Products which currently use this Build Command. Deleting a Build Command is prevented as long as there are Downloadable Products configured that use the related Build Command:

Build Events

All build events are accessible from Sales » Custom build Downloadable Products:

Actions

The Build Event list allows the following actions:

Build

Restarts the build with the next scheduled build run.

Preview Email

Allows to preview the related Transactional Email. This may get used to test the related Transactional Email Template.

Select a Build Event list entry to access its details:

Restart Build will restart the build, this may get used if a build failed and related corrections have been made.

Downloadable Products

Select the Build Command for the Downloadable Link at the related Product from the Build drop-down selection, then that Downloadable Link will be automatically built after its purchase. To have optional build formats make create multiple Downloadable Links and use the Custom Attributes to define the related build options (and include the related Custom Attribute into the Build Command):

After adding the DownloadPlus Blocks to your Store Template, all views will also show build related information:

Product View Page

Shopping Cart

Customer Account Page: "Dashboard"

Customer Account Page: "My Downloadable Products"

See here for the related Store Template preparation...

To use the default list style type of display for the Downloadable Links with a “Rebuild” Link included these are the required template files changes:

downloadable.xml

<downloadable_customer_products translate="label">
   <label>Customer My Account Downloadable Items</label>
   <update handle="customer_account"/>
   <reference name="my.account.wrapper">
        <!-- Update the line below to replace the default page with the DownloadPlusBuilder List Style type page -->
        <block type="downloadplus/customer_products_list" name="downloadable_customer_products_list" template="downloadplusbuilder/customer/products/list.phtml" />
   </reference>
   <reference name="root">
       <action method="setHeaderTitle" translate="title" module="downloadable"><title>My Downloadable Products</title></action>
   </reference>
</downloadable_customer_products>