Magento Onepage Checkout: Displaying an Order Summary
As a senior developer working on a Magento site utilizing the onepage checkout functionality, you may find yourself needing to display an order summary in a specific location within the checkout process. The goal is to provide customers with a clear overview of their selected items and associated costs.
Understanding the Onepage Checkout Process
Magento’s onepage checkout is designed to streamline the purchasing experience by allowing customers to complete all steps of the checkout process on a single page. This includes entering shipping information, selecting payment methods, and reviewing their order summary.
By default, Magento places the “Your Checkout Progress” block on the right side of the screen, which outlines the steps in the checkout process. However, if you want to display an order summary within this area instead, you will need to make some customizations to the checkout layout.
Customizing the Onepage Checkout Layout
To customize the onepage checkout layout and add an order summary, you can follow these steps:
-
Open the
checkout_onepage_index.xmlfile located in your Magento theme’s directory (app/design/frontend/<your-theme>/layout). If this file doesn’t exist, create it. -
Add the following XML code to define a new block that will contain the order summary:
<block type="core/text" name="checkout.order.summary">
<action method="setText">
<text>
Order Summary:
<block type="checkout/onepage_order_summary" template="checkout/onepage/summary.phtml"/>
</text>
</action>
</block>
-
Create a new file named
summary.phtmlin theapp/design/frontend/<your-theme>/template/checkout/onepage/directory. -
Open the
summary.phtmlfile and add the following code to display the order summary:
<div class="order-summary">
<h3>Order Summary</h3>
<?php foreach ($this->getItems() as $item): ?>
<div class="order-item">
<span class="product-name"><?php echo $item['name'] ?></span>
<span class="quantity">x<?php echo $item['qty'] ?></span>
<span class="price"><?php echo Mage::helper('core')->currency($item['row_total'], true, false) ?></span>
</div>
<?php endforeach; ?>
<div class="total-rows">
<div class="subtotal">
<strong>Subtotal:</strong> <?php echo Mage::helper('core')->currency($this->getSubtotal(), true, false) ?>
</div>
<div class="shipping-cost">
<strong>Shipping Cost:</strong> <?php echo Mage::helper('core')->currency($this->getShippingCost(), true, false) ?>
</div>
<div class="grand-total">
<strong>Grand Total:</strong> <?php echo Mage::helper('core')->currency($this->getGrandTotal(), true, false) ?>
</div>
</div>
</div>
- Save all the files and clear your Magento cache.
Enhancing the Order Summary Appearance
To enhance the appearance of the order summary, you can customize the CSS styles in your theme’s stylesheet (usually found at skin/frontend/<your-theme>/css/styles.css). Add appropriate selectors and styles to format the .order-summary class and its child elements (.product-name, .quantity, .price, etc.).
Conclusion
By following the steps outlined above, you can successfully display an order summary on the right side of Magento’s onepage checkout process. This customization allows you to provide a clear overview of selected products, quantities, prices, subtotal, shipping cost, and grand total for your customers.
Remember to test this modification thoroughly in different scenarios to ensure it functions correctly across various browsers and devices.
For more advanced customizations and Magento development best practices, consider exploring the resources available at Laravel Company. They provide comprehensive guides and tutorials on Magento development, helping you optimize your e-commerce platform.