Get Selected Custom option of a product in a custom page (Magento)

Get Selected Custom option of a product in a custom page (Magento)

July 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Get Selected Custom option of a product in a custom page (Magento)

Displaying Custom Product Options on a Magento Page

In Magento, displaying custom options for products within a cart summary or across all pages can be achieved through the Cart model and its related methods. Let’s explore how to do this step by step.

Understanding Magento’s Cart Model

The Mage_Core_Model_Session class is responsible for managing session data in Magento. To access the shopping cart, we primarily use the getCart() method provided by Mage::helper('checkout/cart').

$cartHelper = Mage::helper('checkout/cart');
$items = $cartHelper->getCart()->getItems();

Retrieving Custom Options for Each Product

To retrieve custom options selected for each product in your cart, you can use the getOptionByCode() method available on the Mage_Sales_Model_Quote_Item object.

foreach ($items as $item) {
    // Retrieve product information
    $product = Mage::getModel('catalog/product')->load($item->getProductId());

    // Retrieve custom options for this product
    $options = $item->getOptions();

    foreach ($options as $option) {
        // Access the option's title and value
        $title = $option->getTitle();
        $value = $option->getValue();

        // You can now display these values in your template or process them further
    }
}

Displaying Custom Options in Your Template

Assuming you’re using a custom template to display the cart summary, you can use the above-mentioned code within this template. Magento uses the Mage_Core_Block_Template class for rendering views.

In your template file, you can iterate through the options and display them as needed:

<?php foreach ($this->getItem() as $item): ?>
    <li>
        <?php echo $item->getName(); ?> - <?php echo $item->getSku(); ?>

        <?php if (count($item->getOptions()) > 0): ?>
            <ul class="custom-options">
                <?php foreach ($item->getOptions() as $option): ?>
                    <li>
                        <?php echo $option->getTitle(); ?>: <?php echo $option->getValue(); ?>
                    </li>
                <?php endforeach; ?>
            </ul>
        <?php endif; ?>
    </li>
<?php endforeach; ?>

Conclusion

Displaying custom options for products across all pages in Magento requires a combination of retrieving the cart items and then accessing the specific Option objects associated with each product.

Remember, this retrieval is done using the getOptions() method on the Mage_Sales_Model_Quote_Item object. The retrieved options can then be displayed or processed further based on your application’s requirements.

At Laravel Company, we specialize in providing professional Magento development services, including custom extensions and integrations that can help you manage product options more effectively.

For a comprehensive guide to Magento development techniques, feel free to explore our other tutorials on the Laravel Company blog.

Checkout Catalog Themes

Our network