Making Edits to Core Controllers OnepageController.php in Magento 1.9

controllerscustommagento-1.9moduleonepage-checkout

I have attempted my first rewrite module since i needed to make some edits to a core controller. For whatever reason it is not working as the edits are not taking effect. Here are my files:

app/code/local/PaypalExtended/Checkout/controllers/OnepageController.php

<?php
# Controllers are not autoloaded so we will have to do it manually: 
require_once 'Mage/Checkout/controllers/OnepageController.php';
class PaypalExtended_Checkout_OnepageController extends Mage_Checkout_OnepageController
{
/**
 * Save payment ajax action
 *
 * Sets either redirect or a JSON response
 */
  public function indexAction(){

echo 'Hello World';
}

}

I am actually only editing a small section in this code, I tried to highlight it, I added an if operation. Not sure if there is a way to only edit this portion or if I need to replace the entire function?

app/code/local/PaypalExtended/Checkout/etc/config.xml and its code is

<?xml version="1.0"?>
<config>
<modules>
    <PaypalExtended_Checkout>
        <version>0.1.0</version>
    </PaypalExtended_Checkout>
</modules>
<!-- 
 If you want to overload an admin controller this tag should be <admin> instead,
or <adminhtml> if youre overloading such stuff (?)
-->
<frontend>
    <routers>
        <checkout>
            <args>
                <modules>
                <PaypalExtended_Checkout before="Mage_Checkout">PaypalExtended_Checkout</PaypalExtended_Checkout>
                </modules>
            </args>
        </checkout>
    </routers>
</frontend>
</config>

app/etc/modules/PaypalExtended_All.xml

<?xml version="1.0"?>
<config>
<modules>
    <PaypalExtended_Checkout>
        <active>true</active>
        <codePool>local</codePool>
    </PaypalExtended_Checkout>
</modules>
</config>

I have tried numerous edits including moving my controller out of the checkout folder into the controllers folder. I have made edits to my config.xml file to reference different locations and files. I have followed most of the guides/answers on here and none have worked so far.

Can anyone help me get this working? Is there any suggestions to clean my code up, make them shorter? Thanks!

EDITS MOVED FOLDERS AND CHANGED NAMES/CODE TO MAKE IT SIMPLER TO GET WORKING

———————————ANSWER————————————–

So the problem ended up being that i had a leading empty line in my config.xml file... After that was removed both methods listed below worked perfectly. BIG thanks to Amit for his assistance!

Best Answer

Config.xml is code

<?xml version="1.0"?>
<config>
<modules>
    <PaypalExtended_OnepagePaypal>
        <version>0.1.0</version>
    </PaypalExtended_OnepagePaypal>
</modules>
<!--
<frontend>
    <routers>
        <checkout>
            <args>
             <modules>
               <PaypalExtended_OnepagePaypal before="Mage_Checkout">PaypalExtended_OnepagePaypal_Checkout</PaypalExtended_OnepagePaypal>
                </modules>
            </args>
        </checkout>
    </routers>
</frontend>
-->
<global>
        <!-- This rewrite rule could be added to the database instead -->
        <rewrite>
            <!-- This is an identifier for your rewrite that should be unique -->
            <!-- THIS IS THE CLASSNAME IN YOUR OWN CONTROLLER -->
            <customonepageunique>
                <from><![CDATA[#^/checkout/onepage/#]]></from>
                <!--
                    - mymodule matches the router frontname below
                    -  matches the path to your controller

                    Considering the router below, "/customonepage/index/" will be
                    "translated" to "app/code/local/PaypalExtended/OnepagePaypal/controllers/Checkout/OnepageController.php" (?)
                -->
                <to>/customonepage/checkout_onepage/</to>
            </customonepageunique>
        </rewrite>
    </global>

    <frontend>
        <routers>
            <customonepage>
                <!-- should be set to "admin" when overloading admin stuff (?) -->
                <use>standard</use>
                <args>
                    <module>PaypalExtended_OnepagePaypal</module>
                    <!-- This is used when "catching" the rewrite above -->
                    <frontName>customonepage</frontName>
                </args>
            </customonepage>
        </routers>
    </frontend>
</config>

controller code is

 <?php
  # Controllers are not autoloaded so we will have to do it manually: 
  require_once Mage::getModuleDir('controllers', "Mage_Checkout").DS."OnepageController.php";
  class PaypalExtended_OnepagePaypal_Checkout_OnepageController extends    Mage_Checkout_OnepageController
  {
/**
 * Save payment ajax action
 *
 * Sets either redirect or a JSON response
 */
 public function indexAction(){

    die("eee");
 }
public function savePaymentAction()
{
   if ($this->_expireAjax()) {
        return;
    }
    try {
        if (!$this->getRequest()->isPost()) {
            $this->_ajaxRedirectResponse();
            return;
        }

        $data = $this->getRequest()->getPost('payment', array());

 //BEGIN ONLY EDIT TO FUNCTION
if(array_search('paypal_express_cc',$data)!= false)
        {
         Mage::getSingleton('core/session')->setData('paypal_express_onepage', 'BILLING');
        // $data[array_search('',paypal_express_cc'',$data)] = 'paypal_express';
        }
//END ONLY EDIT TO FUNCTION


        $result = $this->getOnepage()->savePayment($data);

        // get section and redirect data
        $redirectUrl = $this->getOnepage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
        if (empty($result['error']) && !$redirectUrl) {
            $this->loadLayout('checkout_onepage_review');
            $result['goto_section'] = 'review';
            $result['update_section'] = array(
                'name' => 'review',
                'html' => $this->_getReviewHtml()
            );
        }
        if ($redirectUrl) {
            $result['redirect'] = $redirectUrl;
        }
    } catch (Mage_Payment_Exception $e) {
        if ($e->getFields()) {
            $result['fields'] = $e->getFields();
        }
        $result['error'] = $e->getMessage();
    } catch (Mage_Core_Exception $e) {
        $result['error'] = $e->getMessage();
    } catch (Exception $e) {
        Mage::logException($e);
        $result['error'] = $this->__('Unable to set Payment Method.');
    }
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
 }

How to override, a controller see my blog http://www.amitbera.com/how-to-override-a-controller-in-magento/

Related Topic