2

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!

  • Three tips: when developing use developer mode. When in doubt, use xmllint --noout path/to/xmlfile.xml. Any output you get from that command are errors (xmllint is in libxml2-utils on apt-based systems). And finally, n98-magerun has the command config:dump that can output the entire merged configuration xml or a section of it using a subset of Xpath. This is especially useful if your XML syntax is ok, but "nothing happens". Seeing how and where it's merged often leads to the solution. – Melvyn Aug 3 '14 at 13:34
2

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/

  • Hello, No, this is a part of the change I want. It works fine in the core controller itself. I am just trying to move the edit out of the core file. – Drewski22785 Jul 29 '14 at 16:27
  • clear cache from your magento dir/var/cache. and check file permission.... – Amit Bera Jul 29 '14 at 16:30
  • i have check your code,it has working ... for checking the by checking magento checkout/onepage/index.. it is workinng – Amit Bera Jul 29 '14 at 16:32
  • That part of the code was needed and it works fine in the original core file. I will try your other edits though. – Drewski22785 Jul 29 '14 at 16:42
  • I edited my config file to match what you configured and nothing. I also added the indexaction command and get nothing on my index page. – Drewski22785 Jul 29 '14 at 16:51
1

Try replacing this line in config.xml:

<PaypalExtended_OnepagePaypal_Checkout before="Mage_Checkout">PaypalExtended_OnepagePaypal_Checkout</PaypalExtended_OnepagePaypal_Checkout>

with this one

<PaypalExtended_OnepagePaypal before="Mage_Checkout">PaypalExtended_OnepagePaypal</PaypalExtended_OnepagePaypal>
  • Hello, thank you for the quick reply. What folder should my OnepageController be in? I have seen different variations of where to put it. I want to rewrite app/code/core/Mage/Checkout/controllers/OnepageController.php I was confused why some of the tutorials said to use that file structure, can you possible explain? Thanks! – Drewski22785 Jul 29 '14 at 15:12
  • Unfortunately this did not work. Any other ideas you would suggest? Thanks! – Drewski22785 Jul 29 '14 at 15:44
  • it should be in app/code/local/<Your_theme>/Checkout/controllers – Egregory Jul 29 '14 at 16:27
  • I just tried this and edited my controller code and config.xml code. Still nothing, i have no idea what i am doing wrong. – Drewski22785 Jul 29 '14 at 16:41
  • After all the moves described about when i go to /checkout/onepage/index I dont see my hello world on the index page – Drewski22785 Jul 29 '14 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.