Magento成功页面上的小产品问题

时间:2016-06-06 07:00:17

标签: php magento magento-1.7 magento-1.9

我尝试在Magento 1.9中的结帐成功页面上获取产品详细信息,但我不知道为什么我会两次获得相同的产品。这是我在 app / design / frontend / base / default / template / checkout / success.phtml 文件中添加的内容

    <tbody>
        <?php
        foreach ($items as $item):
            $_product = Mage::getModel('catalog/product')->load($item->getProductId());
            $productType = $_product->getTypeId();
            $entityId = $_product->getEntityId();
            $options = $item->getProductOptions();
            if ($productType == "bundle") {
                $bundled_product = new Mage_Catalog_Model_Product();
                $bundled_product->load($entityId);
                $selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(            $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product );
                $bundled_items = array();
                foreach ($selectionCollection as $option) {
                    $bundled_items[] = $option->product_id;
                }?>
                <tr>
                    <td rowspan="1">
                        <img class="product_img" src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>" alt="product-img" />
                        <?php echo $item->getName();
                        $customOptions = $options['options'];
                        if (!empty($customOptions)) {
                            foreach ($customOptions as $option) {?>
                                <span class="bottom-align">
                                    <?php
                                    echo '<b>' . $option['label'] . '</b> :';
                                    echo $optionValue = $option['value'];
                                    ?>
                                </span>
                                <?php
                            }
                        }
                        ?>
                    </td>
                    <td><?php echo $this->helper('checkout')->formatPrice($item->getPrice()); ?></td>
                    <td><?php echo $item->getQtyOrdered(); ?></td>
                    <td><?php echo $item->getSku(); ?></td>
                    <td><?php echo $this->helper('checkout')->formatPrice($item->getRowTotal()); ?></td>
                </tr>
                <?php
            } else if (in_array($entityId, $bundled_items)) {

            } else {
                ?>
                <tr>
                    <td>
                        <img class="product_img" src="<?php echo Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(75); ?>" alt="product-img" />
                        <?php
                        echo $item->getName();

                        $customOptions = $options['options'];
                        if (!empty($customOptions)) {
                            foreach ($customOptions as $option) {
                                ?>
                                <span class="bottom-align">
                                    <?php
                                    echo '<b>' . $option['label'] . '</b> :';
                                    echo $optionValue = $option['value'];
                                    ?></span>                                
                                <?php
                            }
                        }
                        ?>
                    </td>
                    <td><?php echo $this->helper('checkout')->formatPrice($item->getPrice()); ?></td>
                    <td><?php echo $item->getQtyOrdered(); ?></td>
                    <td><?php echo $item->getSku(); ?></td>
                    <td><?php echo $this->helper('checkout')->formatPrice($item->getRowTotal()); ?></td>
                </tr>
                <?php
            }
            ?>
        <?php endforeach ?>
    </tbody>

enter image description here

1 个答案:

答案 0 :(得分:1)

这是预期的行为。复合产品的数据库中插入了几行:bundle,configurables。 在你的情况下,第一个是自己的捆绑产品,第二个是选择的简单产品。 您可以在模板中将onSystemUiVisibilityChange. 替换为} else {,以跳过子简单产品。