Customizing Onepage Checkout - Remove shipping_method
This is an old revision of the document!
Summary |
Jeje: This method has a wrong solution, because you are editing magento core
This HowTo will show you which files you need to modify to remove the shipping_method block from OnepageCheckout. The customer will not be able to specify a shipping method and the order will be placed with “free shipping” by default.
Tested on Magento ver. 1.3.1
[Tried on Magento ver. 1.4: not 100% success, the section is gone, but the payment section now contains the shipping methods ...]
You will need to modify the following two core files and one template file, originally found in these locations:
- Block app/code/core/Mage/Checkout/Block/Onepage.php
- Controller app/code/core/Mage/Checkout/controllers/OnepageController.php
- Template design/frontend/default/default/template/checkout/onepage/progress.phtml
1. Block (Onepage.php) |
Overwrite the function getSteps() and replace the line:
- $stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'review');
with the following:
- $stepCodes = array('billing', 'shipping', 'payment', 'review');
2. Controller (OnepageController.php) |
Overwrite the function saveBillingAction() with the following code:
- public function saveBillingAction()
- {
- $this->_expireAjax();
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost('billing', array());
- $customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
- $result = $this->getOnepage()->saveBilling($data, $customerAddressId);
- if (!isset($result['error'])) {
- /* check quote for virtual */
- if ($this->getOnepage()->getQuote()->isVirtual()) {
- $result['goto_section'] = 'payment';
- $result['update_section'] = array(
- 'name' => 'payment-method',
- 'html' => $this->_getPaymentMethodsHtml()
- );
- }
- elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
- $result['goto_section'] = 'payment';
- $result['update_section'] = array(
- 'name' => 'payment-method',
- 'html' => $this->_getPaymentMethodsHtml()
- );
- }
- else {
- $result['goto_section'] = 'shipping';
- }
- }
- $this->getResponse()->setBody(Zend_Json::encode($result));
- }
- }
Overwrite the function saveShippingAction() with the following:
- public function saveShippingAction()
- {
- $this->_expireAjax();
- if ($this->getRequest()->isPost()) {
- $this->saveShippingMethodAction();
- $data = $this->getRequest()->getPost('shipping', array());
- $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
- $result = $this->getOnepage()->saveShipping($data, $customerAddressId);
- if (!isset($result['error'])) {
- $result['goto_section'] = 'payment';
- $result['update_section'] = array(
- 'name' => 'payment-method',
- 'html' => $this->_getPaymentMethodsHtml()
- );
- }
- // $this->loadLayout('checkout_onepage_shippingMethod');
- // $result['shipping_methods_html'] = $this->getLayout()->getBlock('root')->toHtml();
- // $result['shipping_methods_html'] = $this->_getShippingMethodsHtml();
- $this->getResponse()->setBody(Zend_Json::encode($result));
- }
- }
Overwrite the function saveShippingMethodAction() with the following code: Please Note: the shipping method “Free Shipping” must be enabled for this to work.
- public function saveShippingMethodAction()
- {
- $this->_expireAjax();
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost('shipping_method', 'freeshipping_freeshipping');
- $result = $this->getOnepage()->saveShippingMethod($data);
- /*
- $result will have erro data if shipping method is empty
- */
- if(!$result) {
- Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request'=>$this->getRequest(), 'quote'=>$this->getOnepage()->getQuote()));
- $this->getResponse()->setBody(Zend_Json::encode($result));
- $result['goto_section'] = 'payment';
- $result['update_section'] = array(
- 'name' => 'payment-method',
- 'html' => $this->_getPaymentMethodsHtml()
- );
- //$result['payment_methods_html'] = $this->_getPaymentMethodsHtml();
- }
- $this->getResponse()->setBody(Zend_Json::encode($result));
- }
- }
Overwrite function saveOrderAction() and insert a function call for saveShippingMethodAction() as shown below:
- public function saveOrderAction()
- {
- $this->_expireAjax();
- $this->saveShippingMethodAction();
- ...
- }
3. Template (progress.phtml) |
to not show the step to the customer, you need to comment out lines 60 to 89 (default template):
<?php if ($this->getCheckout()->getStepData('shipping_method', 'is_show')): ?>
<?php if ($this->getCheckout()->getStepData('shipping_method', 'complete')): ?>
<li>
<h4 class="complete"><?php echo $this->__('Shipping Method') ?> <span class="separator">|</span> <a href="#shipping_method" onclick="checkout.accordion.openSection('opc-shipping_method'); return false;"><?php echo $this->__('Change') ?></a></h4>
<div class="content">
<?php if ($this->getShippingMethod()): ?>
<?php echo $this->getShippingDescription(); ?>
<?php $_excl = $this->getShippingPriceExclTax(); ?>
<?php $_incl = $this->getShippingPriceInclTax(); ?>
<?php if ($this->helper('tax')->displayShippingPriceIncludingTax()): ?>
<?php echo $_incl; ?>
<?php else: ?>
<?php echo $_excl; ?>
<?php endif; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
<?php else: ?>
<?php echo $this->__('Shipping method has not been selected yet') ?>
<?php endif ?>
</div>
</li>
<?php else: ?>
<li>
<h4><?php echo $this->__('Shipping Method') ?></h4>
</li>
<?php endif; ?>
<?php endif; ?>


