Extending Magento Shopping Cart

Extending Magento Shopping Cart

September 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Extending Magento Shopping Cart

Extending Magento Shopping Cart: A Step-by-Step Guide

In this post, we’ll explore how to extend the Magento shopping cart to include an extra step for a store locator feature. This involves overwriting core controllers and blocks while ensuring proper tracking of user-selected options during checkout.

Overwriting Core Controllers and Blocks

The first step is to overwrite the Mage_Checkout_OnepageController controller and the Mage_Checkout_Block_Onepage block that handles the one-page checkout process in Magento. To do this, you’ll need to create your own version of these files and place them within your custom module’s directory.

Let’s assume we have a custom module named Company_Locator. We would create the following structure:

app/code/local/Company/Locator/
    controllers/
        OnepageController.php
    blocks/
        Onepage.php

The OnepageController.php file should extend the core controller and override specific actions, such as saveOrder or index, to include your store locator functionality.

class Company_Locator_OnepageController extends Mage_Checkout_OnepageController
{
    public function saveOrderAction()
    {
        // Override this action to handle the selected options from your custom step

        // Example: Save user's selected store location
        $storeLocation = (string)$this->getRequest()->getPost('store_location');
        Mage::getSingleton('core/session')->setStoreLocation($storeLocation);

        parent::saveOrderAction();
    }
}

Similarly, the Onepage.php block file should extend the core block and add your custom form fields for the store locator step.

class Company_Locator_Block_Onepage extends Mage_Checkout_Block_Onepage
{
    public function getSteps()
    {
        $steps = parent::getSteps();
        $steps[3] = 'Store Locator';

        return $steps;
    }

    // Add your custom form fields here, e.g., for the store locator step
}

Keeping Track of Extra Information

To keep track of the extra information (user’s selected options from your custom step), you can use Magento’s session management features.

Saving Data to Session

When the user selects their preferred store location in your custom step, save this data to a session variable using Mage::getSingleton('core/session')->setStoreLocation($storeLocation);.

Retrieving Data from Session

During subsequent checkout steps or when processing the order, you can retrieve the stored data by calling Mage::getSingleton('core/session')->getStoreLocation().

$selectedStoreLocation = Mage::getSingleton('core/session')->getStoreLocation();
if ($selectedStoreLocation) {
    // Process the selected store location as needed
}

Serializing and Deserializing Complex Data

If your custom data is complex (e.g., an array or object), you might need to serialize it before saving to the session. Similarly, deserialize it when retrieving from the session.

// Serialize complex data before storing in session
$complexData = serialize($yourComplexData);
Mage::getSingleton('core/session')->setComplexData($complexData);

// Deserialize complex data after retrieval from session
$deserializedData = unserialize(Mage::getSingleton('core/session')->getComplexData());

Conclusion

Extending the Magento shopping cart to include an extra step involves a deep understanding of the core controllers and blocks involved in the checkout process. By carefully overriding these components, you can integrate your custom store locator functionality while ensuring proper tracking of user-selected options using Magento’s session management.

Remember to follow best practices for module development, such as keeping your code organized and documenting your changes clearly. This will help maintain a clean and maintainable Magento installation.

For more detailed information on Magento core file structure and best practices, you can refer to the official documentation at https://laravelcompany.com/magento-core-file-structure.

Happy coding!

Checkout Extensions Orders

Our network