Reordering Magento Product Page Sections
As a developer, I frequently work with Magento and its customization options. One common issue that arises is the need to rearrange the layout of product pages. Today, we’ll tackle the task of moving an ‘Event Snapshot’ section before the Director/Writer/Cast section on a Magento product page like this one: https://liff2013.com/screenings/blancanieves.html.
The Current Layout
The current layout calls the sections in a specific order based on the code structure. In your case, you have two relevant files: view.phtml and attributes.phtml.
In view.phtml, we find this section of code:
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html): ?>
<div class="box-collateral <?php echo "box-{$alias}"?>">
<?php if ($title = $this->getChildData($alias, 'title')): ?>
<h2><?php echo $this->escapeHtml($title); ?></h2>
<?php endif; ?>
<?php echo $html; ?>
</div>
<?php endforeach; ?>
This code iterates through the child blocks of detailed_info and displays them in order. The ‘Event Snapshot’ section is likely being processed after the ‘Director/Writer/Cast’ section, hence its current position.
Reordering Sections
To reorder these sections, we need to adjust how Magento processes the block groups. We can achieve this by editing your theme’s catalog.xml layout file (usually located in app/design/frontend/{package}/{theme}/layout).
Find or add the following XML section inside the <default> tag:
<reference name="content">
<block type="catalog/product_view_attributes" name="product.attributes" as="additional">
<action method="setTemplate">
<template>catalog/product/view/attributes.phtml</template>
</action>
</block>
<move element="product.attributes" destination="detailed_info" after="product.description" />
</reference>
This code does two things:
-
It defines a new block named
product.attributeswhich uses thecatalog/product_view_attributestype and has a template ofcatalog/product/view/attributes.phtml. This is essentially the ‘Event Snapshot’ section. -
The
<move>element indicates that we want to move this block into thedetailed_infogroup, but position it after theproduct.descriptionblock (which includes the Director/Writer/Cast details).
Updating the Files
After making these changes, you need to update your template files as well.
In view.phtml, ensure that the box-additional and box-description classes are defined correctly in your CSS file. The Magento theme typically has pre-defined styles for these boxes, but if not, you can define them yourself:
.box-additional {
// Add your custom styles here
}
.box-description {
// Add your custom styles here
}
Conclusion
Moving sections around on a Magento product page requires a combination of layout updates and template adjustments. By following the steps outlined above, you should be able to display the ‘Event Snapshot’ section before the Director/Writer/Cast details.
Remember to always backup your files before making changes and test thoroughly after each modification.
If you’re looking for more advanced Magento customization or need expert guidance on PHP development, feel free to reach out to us at Laravel Company. We specialize in building efficient, secure, and scalable web applications using Laravel and other modern technologies.