0
votes

I try to get product details on my checkout success page in Magento 1.9, but I don't know why I get the same product for two times. This is what I add in the app/design/frontend/base/default/template/checkout/success.phtml file

    <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

1 Answers

1
votes

This is the expected behaviour. There are several rows inserted into database for composite products: bundles, configurables. In your case first one is a bundle product himself, second one is a selected simple product. You can replace } else { with } elseif (!$item->getParentId()) { in your template to skip child simple product.