Thursday, December 30, 2010

Customizing Onepage Checkout - Remove shipping_method

Give our namespace name - “Digg“. So you have a folder in app/local/Digg for modules and module “Checkout”.

You must add next files to you module:

1.Block Digg/Checkout/Block/Onepage/Shipping/Method.php
2.Controller Digg/Checkout/controllers/OnepageController.php
3.Model Digg/Checkout/Model/Type/Onepage.php
4.Configuration Digg/Checkout/etc/config.xml

1. Block (Method.php)


To disable Shipping Method for checkout list, you must hide it. Our custom shipping method inherited from core Mage_Checkout_Block_Onepage_Shipping_Method class. Overload method isShow and return false:
class Digg_Checkout_Block_Onepage_Shipping_Method extends


2. Controller (OnepageController.php)


Important:Controllers have no autoloading so you must include it manualy. Overwrite the function saveShippingAction() and saveBillingAction() to skip shipping method to payment with the following code:

_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
$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->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
public function saveBillingAction()
{
if ($this->_expireAjax()) {
return;
}
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(Mage::helper('core')->jsonEncode($result));
}
}
}

?>




3. Model (Onepage.php)


The simplest way to ask magento to ignore shipping info is to change validation rule. Te following code overwriting validateOrder() method. I just removed part of original code that validate non-virtual products


getQuote()->getIsMultiShipping()) {
Mage::throwException($helper->__('Invalid checkout type.'));
}

$addressValidation = $this->getQuote()->getBillingAddress()->validate();
if ($addressValidation !== true) {
Mage::throwException($helper->__('Please check billing address information.'));
}

if (!($this->getQuote()->getPayment()->getMethod())) {
Mage::throwException($helper->__('Please select valid payment method.'));
}
}
}

?>



4. Configuration (config.xml)


Last step is configurate our module. The main idea is to ask Magento first searching action methods in our Digg module and if it didn’t found use core.





0.0.2






Digg_Checkout_Model_Type_Onepage






Digg_Checkout_Block_Onepage_Shipping_Method









Digg_Checkout








Don’t forget to register your module in app/etc/modules/Digg_All.xml:





true
local




For more information go here :

http://www.magentocommerce.com/wiki/5_-_modules_and_development/checkout/customizing_onepage_checkout_-_remove_shipping_method?do=show

No comments:

Post a Comment