1

I am trying to override a file in controllers directory of the Amazon Payments module. I have followed several tutorials with no luck at overriding the controllers. I need to override _getOnepage() in Checkout.php.

Community Plugin Code

app/code/community/Amazon/Payments/etc/config.xml

<?xml version="1.0"?>
<!--
/**
 * @category    Amazon
 * @package     Amazon_Payments
 * @copyright   Copyright (c) 2014 Amazon.com
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
-->
<config>
    <modules>
        <Amazon_Payments>
            <version>1.3.0</version>
        </Amazon_Payments>
    </modules>
    <global>
        <blocks>
            <amazon_payments>
                <class>Amazon_Payments_Block</class>
            </amazon_payments>
        </blocks>
        <models>
            <amazon_payments>
                <class>Amazon_Payments_Model</class>
            </amazon_payments>
            <sales>
                <rewrite>
                    <order_creditmemo>Amazon_Payments_Model_Order_Creditmemo</order_creditmemo>
                </rewrite>
            </sales>
        </models>
        <helpers>
            <amazon_payments>
                <class>Amazon_Payments_Helper</class>
            </amazon_payments>
        </helpers>
        <template>
            <email>
               <amazon_payments_async_decline>
                   <label>Amazon Payments Async Decline</label>
                   <file>amazon_payments_async_decline.html</file>
                   <type>html</type>
               </amazon_payments_async_decline>
            </email>
        </template>
        <rewrite>
            <amazon_payments_checkout>
                <from><![CDATA[#^/checkout/amazon_payments#]]></from>
                <to>/amazon_payments/checkout</to>
            </amazon_payments_checkout>
        </rewrite>
        <resources>
            <payments_setup>
                <setup>
                    <module>Amazon_Payments</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </payments_setup>
        </resources>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Amazon_Payments after="Mage_Adminhtml">Amazon_Payments_Adminhtml</Amazon_Payments>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <tax>
                    <file>amazon_payments.xml</file>
                </tax>
            </updates>
        </layout>
        <events>
            <adminhtml_widget_container_html_before>
                <observers>
                    <amazon_payments>
                        <class>Amazon_Payments_Model_Observer_Adminhtml</class>
                        <method>addAsyncButton</method>
                    </amazon_payments>
                </observers>
            </adminhtml_widget_container_html_before>
            <sales_order_save_commit_after>
                <observers>
                    <amazon_payments_observer>
                        <class>Amazon_Payments_Model_Observer_Order</class>
                        <method>closeAmazonOrder</method>
                    </amazon_payments_observer>
                </observers>
            </sales_order_save_commit_after>
        </events>
    </adminhtml>
    <frontend>
        <secure_url>
            <cart_updatepost>/checkout/cart/updatePost</cart_updatepost>
            <checkout_amazon>/checkout/amazon_payments</checkout_amazon>
            <amazon_checkout>/amazon_payments/checkout</amazon_checkout>
        </secure_url>
        <routers>
            <amazon_payments>
                <use>standard</use>
                <args>
                    <module>Amazon_Payments</module>
                    <frontName>amazon_payments</frontName>
                </args>
            </amazon_payments>
        </routers>
        <layout>
            <updates>
                <amazon_payments>
                    <file>amazon_payments.xml</file>
                </amazon_payments>
            </updates>
        </layout>
        <events>
            <controller_action_layout_load_before>
                <observers>
                   <amazon_payments_observer>
                      <class>Amazon_Payments_Model_Observer_Onepage</class>
                      <method>beforeLoadLayout</method>
                   </amazon_payments_observer>
                </observers>
            </controller_action_layout_load_before>
            <sales_order_place_after>
                <observers>
                    <amazon_payments_observer>
                        <class>Amazon_Payments_Model_Observer_Order</class>
                        <method>updateCustomerAddress</method>
                    </amazon_payments_observer>
                </observers>
            </sales_order_place_after>
            <controller_action_predispatch_checkout_cart_index>
                <observers>
                    <amazon_payments_observer>
                        <class>Amazon_Payments_Model_Observer_Action</class>
                        <method>secureCart</method>
                    </amazon_payments_observer>
                </observers>
            </controller_action_predispatch_checkout_cart_index>
            <custom_quote_process>
                <observers>
                    <amazon_payments_observer>
                        <class>Amazon_Payments_Model_Observer_Onepage</class>
                        <method>clearShippingAddress</method>
                    </amazon_payments_observer>
                </observers>
            </custom_quote_process>
        </events>
    </frontend>
    <default>
        <payment>
            <amazon_payments>
                <title>Amazon Payments</title>
                <model>amazon_payments/paymentMethod</model>
                <payment_action>authorize_capture</payment_action>
                <show_pay_cart>1</show_pay_cart>
                <order_status>processing</order_status>
                <active>1</active>
                <secure_cart>1</secure_cart>
                <button_type>PwA</button_type>
                <button_color>Gold</button_color>
                <button_size>medium</button_size>
                <button_badge>1</button_badge>
            </amazon_payments>
        </payment>
    </default>
    <crontab>
        <jobs>
            <amazon_payments_async>
                <schedule><cron_expr>*/5 * * * *</cron_expr></schedule>
                <run><model>amazon_payments/async::cron</model></run>
            </amazon_payments_async>
        </jobs>
    </crontab>
</config>

app/code/community/Amazon/Payments/controllers/OnepageController.php

class Amazon_Payments_OnepageController extends Amazon_Payments_Controller_Checkout
{
    ...

    public function indexAction()
    {
        // placeholder required
    }

    ...
}

My Override Code

app/code/local/KNG/Amazon/Payments/controllers/OnepageController.php

require_once 'Amazon/Payments/controllers/OnepageController.php';
class KNG_Amazon_Payments_OnepageController extends Amazon_Payments_OnepageController 
{
    public function indexAction()
    {
        $this->_getOnepage()->savePayment(array(
                'method' => 'amazon_payments',
                'additional_information' => array(
                        'order_reference' => $this->getAmazonOrderReferenceId(),
                )
        ));
    }
}

app/code/local/KNG/Amazon/Payments/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <KNG_Amazon_Payments>
            <version>1.3.0.1</version>
        </KNG_Amazon_Payments>
    </modules>
    <frontend>
        <routers>
            <amazon_payments>
                <args>
                    <modules>
                        <KNG_Amazon_Payments before="Amazon_Payments">KNG_Amazon_Payments</KNG_Amazon_Payments>
                    </modules>
                </args>
            </amazon_payments>
        </routers>
    </frontend>
</config>

app/etc/modules/KNG_Amazon/Payments.xml

<?xml version="1.0"?>
<config>
    <modules>
        <KNG_Amazon_Payments>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Amazon_Payments />
            </depends>
        </KNG_Amazon_Payments>
    </modules>
</config>
0

controllers folders have to be 3 folders deep from code pool.

The controllers folder I am trying to get working is 4 folders deep in the code pool.

app/code/local/KNG/Amazon/Payments/controllers/OnepageController.php

  1. KNG
  2. Amazon
  3. Payments
  4. controllers

When I changed all the files to be under Amazonpayments and changed the path of my controller to path below, then everything worked, because now the controllers folder is only 3 folders deep from the code pool.

app/code/local/KNG/Amazonpayments/controllers/OnepageController.php

  1. KNG
  2. Amazonpayments
  3. controllers

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.