0

I wanted to summarize the purchase on the success page, as if it were a cart with all the products that the user bought, with the image, product name, quantity and price of it. From the code below I can see how many products are in the cart, but I can not get them and assemble the HTML portion of this summary.Thanks in advance.

$order = Mage::getSingleton('sales/order'); 
$order->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$_items = $order->getAllItems();
echo count($_items);
1

Try below code.

<?php 
    $order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId(); 
    $order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id); 
?>
    <table>
     <tr> 
        <th><?php echo $this->__('Description') ?></th
        <th><?php echo $this->__('Description') ?></th>
        <th><?php echo $this->__('Qty') ?></th>
        <th><?php echo $this->__('Unit Price') ?></th>
    </tr>

    <?php foreach($order_details->getAllVisibleItems() as $item): 
    $configItem = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku());
    ?> 
        <tr>
            <td><img src="<?php echo $this->helper('catalog/image')->init($configItem, 'small_image')->resize(200); ?>" width="200" height="200" class="media-object img-responsive" alt="<?php echo $this->getImageLabel($configItem, 'small_image'); ?>"/></td>
            <td><?php echo $item->getName() ?></td>
            <td><?php echo round($item->getQtyOrdered(), 0) ?></td>
            <td><?php echo Mage::helper("core")->currency($item->getPrice()) ?></td>
        </tr>
    <?php endforeach ?>
        </table>
0

Override /app/code/Mage/Checkout/Block/Onepage/Success.php with your local copy. and edit the following method below. This will include the items in the success block.

protected function _prepareLastOrder()
{
    $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
    if ($orderId) {
        $order = Mage::getModel('sales/order')->load($orderId);
        if ($order->getId()) {
            $isVisible = !in_array($order->getState(),
                Mage::getSingleton('sales/order_config')->getInvisibleOnFrontStates());
            $this->addData(array(
                'is_order_visible' => $isVisible,
                'view_order_id' => $this->getUrl('sales/order/view/', array('order_id' => $orderId)),
                'print_url' => $this->getUrl('sales/order/print', array('order_id'=> $orderId)),
                'can_print_order' => $isVisible,
                'can_view_order'  => Mage::getSingleton('customer/session')->isLoggedIn() && $isVisible,
                'order_id'  => $order->getIncrementId(),
                'all_items' => $order->getAllItems(),
            ));
        }
    }
}

You should notice the line 'all_items' => $order->getAllItems(),

And then in your success.phtml file, you can access all of the items in an order.

$items = array();
foreach ($this->getAllItems() as $item) {
    $items[]['id'] = $item->getProductId();
    $items[]['price'] = $item->getPrice();
    $items[]['quantity'] = $item->getQtyOrdered();
}

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.