3

I have a Configurable Product with Associated Products (Downloadable product(s)). When I place an order I want to receive an email with the links to the Downloadable product(s).

How can I set this in Magento?

I have tried:

  • Changed the layout in the sales.xml app/design/frontend/base/default/layout/sales.xml
  • Changed the template in app/design/frontend/base/default/template/email/order/items/order/default.phtml
5

I just came across the same problem. If the product is not downloadable by itself, but is a configurable product with an associated child which is downloadable, then the link is not rendered in the mails. A quick fix to this problem is to copy the template email/order/invoice/items.phtml to your own theme and edit the following if condition:

<?php if($_item->getOrderItem()->getParentItem()) continue; else $i++; ?>

With this condition in place, the child items are not rendered. I added another condition to it, so that child items are rendered if they are downloadable:

<?php if($_item->getOrderItem()->getParentItem() && $_item->getOrderItem()->getProductType() != Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) continue; else $i++; ?>

With this change, the download link appears in the invoice mail. The disadvantage of this method is that the item is rendered twice:

enter image description here

I now also came up with a nicer solution. Therefore, I changed the email/order/invoice/items.phtml template like this:

<?php $_invoice = $this->getInvoice() ?>
<?php $_order   = $this->getOrder() ?>
<?php if ($_invoice && $_order): ?>
<table cellspacing="0" cellpadding="0" border="0" width="650" style="border:1px solid #EAEAEA;">
    <thead>
        <tr>
            <th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Item') ?></th>
            <th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Sku') ?></th>
            <th align="center" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Qty') ?></th>
            <th align="right" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"><?php echo $this->__('Subtotal') ?></th>
        </tr>
    </thead>

    <?php $i=0; foreach ($_invoice->getAllItems() as $_item): ?>
    <?php if($_item->getOrderItem()->getParentItem() && $_item->getOrderItem()->getProductType() != Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) continue; else $i++; ?>
    <?php // do not use a new colour for the download link ?>
    <?php if ($_item->getOrderItem()->getProductType() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) { $i++; } ?>
    <tbody<?php echo $i%2 ? ' bgcolor="#F6F6F6"' : '' ?>>
        <?php if ($_item->getOrderItem()->getProductType() != Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE): ?>
        <?php echo $this->getItemHtml($_item) ?>
        <?php else: ?>
        <?php // if this child is a download product, just print the download link as the product information is taken from the configurable product (the parent) ?>
        <?php $_downloadLink = ''; ?>
        <?php $_links = Mage::getModel('downloadable/link_purchased_item')->getCollection()->addFieldToFilter('order_item_id', $_item->getOrderItem()->getId()); ?>
        <?php foreach ($_links  as $_link): ?>
        <?php if ($_link->getProductId() == $_item->getOrderItem()->getProduct()->getId()): ?>
        <?php $_downloadLink = $this->getUrl('downloadable/download/link/', array('id' => $_link->getLinkHash())); ?>
        <?php endif; ?>
        <?php endforeach; ?>
        <?php if (!empty($_downloadLink)): ?>
        <tr>
            <td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;" colspan="4"><a href="<?php echo $_downloadLink; ?>">Download</a></td>
        </tr>
        <?php endif; ?>
        <?php endif; ?>
    </tbody>
    <?php endforeach; ?>

    <tfoot>
        <?php echo $this->getChildHtml('invoice_totals')?>
    </tfoot>
</table>
<?php endif; ?>

The result looks much nicer now:

enter image description here

This works for other mails accordingly (e.g. under email/order/items.phtml for the normal order mail).

| improve this answer | |
1

The template downloadable/sales/order/items/renderer/downloadable.phtml should do the displaying of downloadable items in the order process.

This is added as part of the renderer.

<sales_order_view>
    <reference name="order_items">
        <action method="addItemRender"><type>downloadable</type><block>downloadable/sales_order_item_renderer_downloadable</block><template>downloadable/sales/order/items/renderer/downloadable.phtml</template></action>
    </reference>
</sales_order_view>

This template should include the information and link to downloadable products. It definately works when the main product is downloadable but it might not work when the downloadable product is a child product.

| improve this answer | |
0

Magento2 version of Simon's solution:

  1. override /vendor/magento/module-sales/view/frontend/templates/email/items.phtml
  2. edit around line 30

    <?php foreach ($_items as $_item): ?>
        <?php  # fix for configurable's downloadable's link(s):
            if($_item->getParentItem() && $_item->getProduct()->getTypeId()!='downloadable'){
                continue;
            }
            /*  # magento's original code:
            if ($_item->getParentItem()) {
                continue;
            }
            */
        ?>
        <tbody>
            <?= $block->getItemHtml($_item) ?>
        </tbody>
    <?php endforeach; ?>
    

Works for my Magento2.1.7.

Explanation:

Magento only renders downloadable product link(s) when isolated. If they are encapsulated in configurable, this fix checks also if the subproduct is downloadable.

| improve this answer | |
  • This helps but does not completely solve the problem. With this solution another item is visible on the invoice that has price 0,- (the child item) and that also has the download link. Although this is definitely beter than no link at all, it's not very pretty either. Secondly the link does not get rendered in Magento 2.1.7 due to a bug in Magento\Downloadable\Block\Sales\Order\Email\Items\Downloadable::getLinks(). I just created a PR on Github (github.com/magento/magento2/pull/11024) for this – skymeissner Sep 25 '17 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.