Magento – Email-link Downloadable product linked with Configurable Product

configurable-productdownloadablemagento-1.8

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

Best Answer

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).

Related Topic