0
votes

The client wants the checkout process to look like discrete pages for each step (login/register, billing, shipping, etc.), so I've modified the template to look like that and everything works fine. However, now they want to display the cart contents with every step.

I presume I would be able to use the shopping cart sidebar module, but I can't get it to display properly.

Partially I suspect this is because I don't understand some of the module/block configuration that Magento uses. I've tried reading up on it, but like everything Magento, it's remarkably unclear.

So, how would I insert the cart contents into the template at custom/template/checkout/onepage/billing.phtml? I'm sure there are multiple ways to do this, and I'm just looking for the simplest.

2

2 Answers

5
votes

This should work anywhere, not just in the billing phase:

$quote = Mage::helper('checkout')->getQuote();
foreach ($quote->getItemsCollection() as $item) {
    // output details of an item.
    echo $item->getName();
}

Each $item is a Mage_Sales_Model_Quote_Item.

PS.
It sounds like you're trying to recreate the old multishipping checkout that existed before onepage checkout was introduced. This can be reactivated with the first setting in System > Configuration > Checkout > Checkout Options.

2
votes

clockworkgeek got me started here with that answer, but I needed to also display product quantity, price and then the total cart price as well. The Magento documentation is dense at best, so after searching around, here is the answer to display cart contents in Magento with some table HTML for formatting:

<?php $quote = Mage::helper('checkout')->getQuote(); //gets the cart contents ?>
<table>
<thead>    
<th>Product</th>
<th>Quantity</th>
<th>Price/ea.</th>
<th>Total</th>
</thead>

<?php foreach ($quote->getItemsCollection() as $item) { ?>
<tr><td><?php echo $item->getName(); ?></td>
<td><?php echo $item->getQty(); ?></td> 
<td><?php echo $this->helper('checkout')->formatPrice($item->getPrice(), 2); ?></td>
<td><?php $floatQty = floatval($item->getQty());
$total = $floatQty * $item->getPrice();
echo $this->helper('checkout')->formatPrice($total, 2); //multiply the quantity by the price and convert/format ?></td>
</tr>       
<?php  } ?>

<tfoot>
<td></td>
<td></td>
<td></td>
<td><?php echo $this->helper('checkout')->formatPrice($quote->getGrandTotal()); ?></td>
</tfoot>
</table>

That may be some very ugly code, including the rough way to find the total for each $item, but it works. I'm sure there's a better way to get the $item total (calcRowTotal never seemed to work), but it gets the job done.

And thanks to clockworkgeek for sending me down the right path.