Adding a download link to an email - xmpie-users/uStore-js GitHub Wiki

NOTE This work around is not needed for uStore v11 and later - the default uStore message template was updated and automatically includes the download link.

In uStore admin, it is possible to configure products to "Allow customer download after purchase". By Default, uStore does this by providing a link to download the product in the "My Account" -> "Order History" area of the storefront.

For most customers, this is not very use friendly, and it is much nicer to get an email saying that their product is now ready for download and giving them a link to click in the email itself rather than forcing the user to go back to uStore, login, find the order and then download.

Create a new trigger

  1. Login to the uStore admin back office.
  2. Click Presets -> Triggers -> New
  3. Setup your order state transition trigger as shown below. Select the store(s) that you want the trigger to apply to, and set relevant sender email address for your store. Click to duplicate the default message template:
    Alt
  4. Enter a descriptive name:
    Alt
  5. We will come back and edit the message in a moment. For now, just click the Save and Close button:
    Alt
  6. After saving the message template, click to save the new rule.

Identify the new message template ID

  1. Click Presets -> System Setup -> Message Template.
  2. Click to go to the last page and identify the ID of your new message template: Alt

Create a new message template SQL to get the output token id

  1. Click Presets -> System Setup -> Message Template SQL.
  2. Click Add new. Enter the ID of your new Message Template, and the following SQL query: Alt
exec('SELECT OP.OutputToken, PC.Name, CASE WHEN D.DownloadOutput = ''DefaultDownloadOutput'' THEN 1 ELSE 0 END AS IsDownloadProduct FROM OrderProduct AS OP INNER JOIN Product_Culture AS PC ON OP.ProductID = PC.ProductID INNER JOIN Doc AS D ON OP.ProductID = D.ProductID where op.OrderProductID = ' + @OrderProductId + ' and pc.CultureID = ' + @CultureId)
  1. Save the new message template SQL.

Edit the message template to include the link

  1. Click Presets -> Triggers
  2. Click to edit the new trigger you created at the start.
  3. At the bottom of the screen, next to the new email message template name, click the edit (pen) icon.
  4. Click to enter XSLT view.
  5. Locate the line: "Sincerely Yours,". Place the cursor at the start of this line, and paste in the following code:
    Alt
<a>
  <xsl:attribute name="href">http://<xsl:value-of select="//Sqls/StoreName/Row/LandingDomain" />/uStore/Controls/SDK/OrderOutputProxy.ashx?token=<xsl:value-of select="//Sqls/OutputToken/Row/OutputToken" />
  </xsl:attribute>Here is a link
</a>
to download the <xsl:value-of select="//Sqls/OutputToken/Row/Name" />.<br />
<br />
<xsl:if test="//Sqls/OutputToken/Row/IsDownloadProduct = '0'"> 
  <xsl:message terminate="yes">Email message was not sent - terminated because product was not a downloadable product.</xsl:message> 
</xsl:if> 
  1. Save and Close the template. Save the trigger.

Notes / Comments / Description

  • For the trigger to run, you will need to manually process the order product through the queues, or use triggers to move the order product automatically. When an order product hits the ready for delivery queue (and therefore the final PDF output is created and is ready for download) the trigger will fire.
  • The email message will look like this: Alt
  • You will have noted that the trigger will fire for all orders in the store - even if they are not configured for download by the customer. Therefore, the XSLT includes an extra tag that will terminate the email message if the order product is not supposed to be downloaded after order. When the trigger fires for a non-download product, you will see the following error logged in the uStore Common log (C:\XMPLogs\uStore\Common\uStore.log):
    Alt
⚠️ **GitHub.com Fallback** ⚠️