Custom Magento Checkout Module: Removing Shipping Address and Method Steps
Introduction
Creating a custom checkout module for Magento involves modifying existing controllers, blocks, and models to achieve your desired functionality. In this case, you want to remove the shipping address and method steps from the one-page checkout process.
Understanding Your Current Configuration
Let’s break down what you’ve done so far:
- You have created an XML configuration file (
Mona_Test.xml) which enables your module in thelocalcode pool. - In
config.xml, you’re adding your module to the Magento modules list, defining version information, and setting up routing, blocks, and models for the checkout process.
The key changes include:
- Adding the
Mona_Testmodule beforeMage_Checkoutin the frontend router’scheckoutsection. - Rewriting the
onepage_abstractblock andtype_onepagemodel under Magento’scheckoutnamespace.
Analyzing Your Block and Controller Changes
OnepageAbstract.php
Your Abstract.php is extending Mage_Checkout_Block_Onepage_Abstract, which is a good start. You’ve overridden the _getStepCodes() method to return only four steps: login, billing, payment, and review.
However, this won’t remove the shipping address and method steps entirely; it just hides them from the step titles displayed on the checkout page.
OnepageController.php
In your controller file, you’ve overridden two actions:
saveBillingAction: This saves the billing information and, if the quote is virtual (meaning there are no physical products), directly goes to the payment method section. However, it doesn’t handle non-virtual quotes correctly.saveShippingAction: This attempts to save shipping information but fails to update the section with the new methods after saving.
The Issue: Unhandled Non-Virtual Quotes
The problem lies in your handling of non-virtual (physical) products. When you save the billing address, if there are physical items in the cart, you should go to the shipping method step next. However, in your saveBillingAction, you assume all quotes are virtual or immediately proceed to the payment section.
The Solution: Proper Address and Method Handling
To fix this issue, you need to modify your code as follows:
Updated saveBillingAction
public function saveBillingAction()
{
if ($this->getOnepage()->getQuote()->isVirtual()) {
// For virtual quotes, proceed directly to payment after saving billing info
$result = array(
'goto_section' => 'payment',
'update_section' => array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
)
);
} else {
// For physical products, proceed to shipping method section
$result = array(
'goto_section' => 'shipping_method',
'update_section' => array(
'name' => 'shipping-method',
'html' => $this->_getShippingMethodsHtml()
)
);
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
Removing Unnecessary saveShippingAction
You can remove the saveShippingAction entirely because you’re handling this in the updated saveBillingAction.
Conclusion
In summary, to create a custom Magento checkout module that removes the shipping address and method steps:
- Configure your module correctly using
config.xml. - Update your block and controller files to handle non-virtual quotes appropriately.
- Ensure you have properly configured routing and model rewrites.
Remember that modifying core Magento functionality requires careful testing, as it can lead to unexpected behavior or compatibility issues with other extensions.
For more advanced customizations like these, consider consulting professional Magento developers or using Laravel Company’s services for expert guidance. They specialize in creating robust, secure, and optimized Magento solutions tailored to your business needs.
This post provides a comprehensive overview of the process involved in creating a custom checkout module. With proper configuration and careful implementation, you can achieve your desired functionality while maintaining a seamless shopping experience for your customers.