列表项目选项在magento电子邮件模板


List item options in magento email template

基于http://www.webspeaks.in/2011/06/customize-new-order-email-template-in.html和http://www.magentocommerce.com/boards/viewthread/43928/我创建了一个自定义的电子邮件模板。

然而,几个小时后,我不知道如何让项目的自定义选项显示在电子邮件中。

在默认的电子邮件代码(位于'app'design'frontend'base'default'template'email'order'items'order'default.phtml)中有这些行:

    <?php if ($this->getItemOptions()): ?>
    <dl style="margin:0; padding:0;">
        <?php foreach ($this->getItemOptions() as $option): ?>
        <dt><strong><em><small><?php echo $option['label'] ?></small></em></strong></dt>
        <dd style="margin:0; padding:0 0 0 9px;">
            <?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?>
        </dd>
        <?php endforeach; ?>
    </dl>
    <?php endif; ?>

但是在我的。php中使用这些代码没有显示任何东西。

下面是我的代码:

<?php $_order = $this->getOrder() ?>
<?php $i=0; foreach ($_order->getAllItems() as $_item): ?><?php if($_item->getParentItem()) continue; else $i++; ?>
<?php echo $this->__('(') ?><?php echo $_item->getQtyOrdered()*1 ?><?php echo $this->__(') ') ?>
<strong><?php echo $this->htmlEscape($_item->getName()) ?></strong>
<?php echo $this->__('$') ?><?php echo number_format($_item->getRowTotal(), 2) ?>
<br />
    <?php if ($this->getItemOptions()): ?>
        <?php foreach ($this->getItemOptions() as $option): ?>
        <strong><em><small><?php echo $option['label'] ?></small></em></strong>
            <?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?>
        <?php endforeach; ?>
    <?php endif; ?>
<?php echo $this->__("-------------------") ?>
<br />
<?php endforeach; ?>
<br />
<?php echo $this->__('Subtotal: $') ?><?php echo number_format($_order->getSubtotal(), 2) ?>
<br />
<?php echo $this->__('Tax: $') ?><?php echo number_format($_order->getTaxAmount(), 2) ?>
<br />
<strong><?php echo $this->__('Grand Total: $') ?><?php echo number_format($_order->getGrandTotal(), 2) ?></strong>

我尝试使用$_item->getItemOptions()),但没有帮助。

如果有人能帮助我正确的语法,我将非常感激(我希望这就是我所缺少的)。

谢谢。

我知道这个问题已经回答了,但是,在我的情况下,它看起来像一个观察者干扰了$this->getItemOptions()方法。

尝试替换

中的以下代码块

app/设计/前端/[YOUR_PACKAGE]/[YOUR_THEME]/模板/电子邮件/订单/项目/订单/违约。phtml

<?php if ($this->getItemOptions()): ?>
<dl style="margin:0; padding:0;">
    <?php foreach ($this->getItemOptions() as $option): ?>
    <dt><strong><em><?php echo $option['label'] ?></em></strong></dt>
    <dd style="margin:0; padding:0 0 0 9px;">
        <?php echo nl2br($option['value']) ?>
    </dd>
    <?php endforeach; ?>
</dl>
<?php endif; ?>

    <?php if ($options = $_item->getProductOptions()): ?>
        <?php if (isset($options['options'])): ?>
            <dl style="margin:0; padding:0;">
            <?php foreach ($options['options'] as $option): ?>
                <dt><strong><em><small><?php echo $option['label'] ?></small></em></strong></dt>
                <dd><?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?></dd>
            <?php endforeach; ?>
            </dl>
        <?php endif; ?>
        <?php if (isset($options['additional_options'])): ?>
            <dl style="margin:0; padding:0;">
            <?php foreach ($options['additional_options'] as $option): ?>
                <dt><strong><em><small><?php echo $option['label'] ?></small></em></strong></dt>
                <dd><?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?></dd>
            <?php endforeach; ?>
            </dl>
        <?php endif; ?>
        <?php if (isset($options['attributes_info'])): ?>
            <dl style="margin:0; padding:0;">
            <?php foreach ($options['attributes_info'] as $option): ?>
                <dt><strong><em><small><?php echo $option['label'] ?></small></em></strong></dt>
                <dd><?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?></dd>
            <?php endforeach; ?>
            </dl>
        <?php endif; ?>
    <?php endif; ?>

经过一番研究,我找到了解决办法。

上面的原始代码片段使用函数getItemOptions(),在我的文件中我无法访问。因此,我找到了该函数的位置,正如您在这里看到的,它使用了getProductOption()函数。这是我的最终代码:

    <?php if ($options = $_item->getProductOptions()): ?>
    <?php if (isset($options['options'])): ?>
    <?php foreach ($options['options'] as $option): ?>
    <br /><strong><em><small><?php echo $option['label'] ?></small></em></strong>
        <br /><?php echo (isset($option['print_value']) ? $option['print_value'] : nl2br($this->escapeHtml($option['value']))) ?>
    <?php endforeach; ?>
    <?php endif; ?>
<?php endif; ?>

解释一下:在getproductopoptions()中有两个数组["info_buyRequest"]["options"]["options"]内有:["label"], ["value"], ["print_value"], ["option_id"], ["option_type"], ["option_value"] and ["custom_view"]。我通过var_dump($options)获得了这个信息。

我希望这能帮助到那些和我有同样问题的人。