Seems like alot has changed since that time, no core changes are now required, you can overwrite code functionality with your own controllers, and etc.. Awesome! So lets move forward.
How would you disable shipping and payment steps for you Magento installation and apply changes in such manner that you wont have to worry about this when doing the next Magento upgrade?
Below is a step by step tutorial “copy paste” pretty much.
Now I don’t expect this that this solution will always work with next version of Magento, but unless they deprecate some existing functionality I’m sure you wont need to change anything.
NOTE: When doing copy paste make sure you wont end up with weird characters, such as single and double quotes.
STEP 1
First step would be to get a Magento extension called “LKC_ModularRouters” (ext. key: “magento-community/LKC_ModularRouters” to be used in MagentoConnect from admin tool)
After installation you can proceed to step 2, if you are using Magento v.1.3 if you are on a newer version you would need to make some tweaks to that module, since it has not been updated for the newer versions yet.
See how to do it…
STEP 2
Next, you would want to do is to create a project folder under /app/code/local
Lets say we name it “XYZ”
STEP 3
First, lets create a Bock that will overwrite existing Magento core block for onepage checkout /app/code/local/XYZ/Checkout/Block/Onepage.php
- class XYZ_Checkout_Block_Onepage extends Mage_Checkout_Block_Onepage {
- public function getSteps() {
- $steps = array();
- if (!$this->isCustomerLoggedIn()) {
- $steps['login'] = $this->getCheckout()->getStepData('login');
- }
- $stepCodes = array('billing', 'shipping', 'review');
- foreach ($stepCodes as $step) {
- $steps[$step] = $this->getCheckout()->getStepData($step);
- }
- return $steps;
- }
- }
Basically, this class will extend the core class. If you compare getSteps() function to the core file its pretty much identical, we just removed payment and shipping option steps.
STEP 4
Now this is the most intense part, We would have to tweak the default controllers for that page and make sure we assign a shipping method automatically and automatically select free shipping.
Create the following file /app/code/local/XYZ/Checkout/Controller/Onepage.php
- require_once 'Mage/Checkout/controllers/OnepageController.php';
- class XYZ_Checkout_Controller_Onepage extends Mage_Checkout_OnepageController
- {
- /**
- * Checkout page
- */
- public function indexAction()
- {
- if (!Mage::helper('checkout')->canOnepageCheckout()) {
- Mage::getSingleton('checkout/session')->addError($this->__('Sorry, Onepage Checkout is disabled.'));
- $this->_redirect('checkout/cart');
- return;
- }
- $quote = $this->getOnepage()->getQuote();
- if (!$quote->hasItems() || $quote->getHasError()) {
- $this->_redirect('checkout/cart');
- return;
- }
- if (!$quote->validateMinimumAmount()) {
- $error = Mage::getStoreConfig('sales/minimum_order/error_message');
- Mage::getSingleton('checkout/session')->addError($error);
- $this->_redirect('checkout/cart');
- return;
- }
- Mage::getSingleton('checkout/session')->setCartWasUpdated(false);
- Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());
- $this->getOnepage()->initCheckout();
- $this->loadLayout();
- $this->_initLayoutMessages('customer/session');
- $this->getLayout()->getBlock('head')->setTitle($this->__('Request a Quote'));
- $this->renderLayout();
- }
- 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'])) {
- if ($this->getOnepage()->getQuote()->isVirtual()) {
- $this->loadLayout('checkout_onepage_review');
- $result['goto_section'] = 'review';
- $result['update_section'] = array(
- 'name' => 'review',
- 'html' => $this->getLayout()->getBlock('root')->toHtml()
- );
- }
- elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
- $this->saveShippingMethodAction();
- $this->loadLayout('checkout_onepage_review');
- $result['goto_section'] = 'review';
- $result['update_section'] = array(
- 'name' => 'review',
- 'html' => $this->_getReviewHtml()
- );
- $result['allow_sections'] = array('shipping','review');
- $result['duplicateBillingInfo'] = 'true';
- }
- else {
- $result['goto_section'] = 'shipping';
- }
- }
- $this->getResponse()->setBody(Zend_Json::encode($result));
- }
- }
- public function saveShippingAction()
- {
- $this->_expireAjax();
- 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'])) {
- $this->saveShippingMethodAction();
- $this->loadLayout('checkout_onepage_review');
- $result['goto_section'] = 'review';
- $result['update_section'] = array(
- 'name' => 'review',
- 'html' => $this->_getReviewHtml()
- );
- }
- $this->getResponse()->setBody(Zend_Json::encode($result));
- }
- }
- public function saveShippingMethodAction()
- {
- $this->_expireAjax();
- if ($this->getRequest()->isPost()) {
- $this->savePaymentAction();
- $data = $this->getRequest()->getPost('shipping_method', 'freeshipping_freeshipping');
- $result = $this->getOnepage()->saveShippingMethod($data);
- $this->getResponse()->setBody(Zend_Json::encode($result));
- }
- }
- public function savePaymentAction()
- {
- $this->_expireAjax();
- if ($this->getRequest()->isPost()) {
- $data = $this->getRequest()->getPost('payment', array('method'=>'checkmo'));
- try {
- $result = $this->getOnepage()->savePayment($data);
- }
- catch (Mage_Payment_Exception $e) {
- if ($e->getFields()) {
- $result['fields'] = $e->getFields();
- }
- $result['error'] = $e->getMessage();
- }
- catch (Exception $e) {
- $result['error'] = $e->getMessage();
- }
- $redirectUrl = $this->getOnePage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
- if ($redirectUrl) {
- $result['redirect'] = $redirectUrl;
- }
- $this->getResponse()->setBody(Zend_Json::encode($result));
- }
- }
- }
STEP 5
Now that the code is in place we need to rewrite the core calls to custom classes we’ve created. To do so you create the file /app/code/local/XYZ/Checkout/etc/config.xml
- xml version="1.0"?>
- <config>
- <modules>
- <XYZ_Checkout>
- <version>0.1.0version>
- XYZ_Checkout>
- modules>
- <global>
- <controllers>
- <Mage_Checkout>
- <rewrite>
- <onepage>XYZ_Checkout_Controller_Onepageonepage>
- rewrite>
- Mage_Checkout>
- controllers>
- <blocks>
- <checkout>
- <rewrite>
- <onepage>XYZ_Checkout_Block_Onepageonepage>
- rewrite>
- checkout>
- blocks>
- global>
- config>
STEP 6
Now we would have to add a new XML config file for you XYZ module. This config file will tell Magento about your module and here you will enable all the code you wrote. /app/etc/modules/XYZ_All.xml
- xml version="1.0"?>
- <config>
- <modules>
- <XYZ_Checkout>
- <active>trueactive>
- <codePool>localcodePool>
- <<b style="color: white; background-color: rgb(136, 0, 0);">dependsb>>
- <Mage_Core />
- <Mage_Checkout />
- <LKC_ModularRouters />
- <b style="color: white; background-color: rgb(136, 0, 0);">dependsb>>
- XYZ_Checkout>
- modules>
- config>
STEP 7
Now that the tough part is done, we will just need to do some little tweaks to the AJAX JS file and tweak Magento configuration in the admin tool.
Now locate and open /skin/frontend/default/YOURSKIN/js/opcheckout.js where YOURSKIN is the skin you are using for your site. In most cases its ‘default’ but if you are using a separate skin that you might have created then it will be in a folder you’ve created.
Approximately on the line 721 you should find “var Review = Class.create();” which defines the Review class. Now if you skip to ’save’ function for that class you will find this line of code “var params = Form.serialize(payment.form);” We will have to tweak this because we are skipping payment. This variable wont be defined if we place the order. So I have changed that line to :
- //var params = Form.serialize(payment.form);
- var params = "color: black; background-color: rgb(255, 153, 153);">payment%5Bmethod%5D=checkmo";
- if (this.agreementsForm) {
- params += '&'+Form.serialize(this.agreementsForm);
- }
- params.save = true;
As you see we commented out the serialize call and hardcoding the parameter to reflect the free payment method
STEP 8
Now the last part: tweaking Magento configuration
- Go to the admin tool and go to System->Configuration->Shipping Methods and make sure “Free Shipping” is Enabled.
- Go to the admin tool and go to System->Configuration->Payment Methods and make sure “Check / Money order” payment option is Enabled.
- IMPORTANT! – When copying XML data make sure you don’t have any white-spaces before the first tag, which should be
That is it! Your comments and suggestions are welcome!
courtsy:Blog of Igor Krasnykh
1 comment:
Wow! You can steal informations from other people's blogs...
Post a Comment