cancel
Showing results for 
Search instead for 
Did you mean: 

Deactivate Invoice as Guest User | own module

Deactivate Invoice as Guest User | own module

Dear Community

 

I do have a question about a small extension which I wrote. Would be great if anybody could tell me what I was doing wrong, that the Invoice Option still is displayed also when I'm using the checkout as guest.

 

/app/etc/modules/Shiftmint_Disable_GuestInvoice.xml

 

<?xml version="1.0"?>
<config>
    <modules>
        <Shiftmint_Disable_GuestInvoice>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Payment/>
            </depends>
        </Shiftmint_Disable_GuestInvoice>
    </modules>
</config>

 

 

/app/code/local/Shiftmint/Disable_GuestInvoice/etc/config.xml

I<?xml version="1.0"?>
<config>
<modules>
    <Shiftmint_Disable_GuestInvoice>
        <version>0.0.1</version>
    </Shiftmint_Disable_GuestInvoice>
</modules>

<global>
    <models>
        <Shiftmint_Disable_GuestInvoice>
            <class>Shiftmint_Disable_GuestInvoice_Model</class>
        </Shiftmint_Disable_GuestInvoice>
    </models>
    <events>
        <payment_method_is_active>
            <observers>
                <Shiftmint_Disable_GuestInvoice>
                    <type>singleton</type>
                    <class>Shiftmint_Disable_GuestInvoice/Observer</class>
                    <method>paymentMethodIsActive</method>
                </Shiftmint_Disable_GuestInvoice>
            </observers>
        </payment_method_is_active>
    </events>
</global>

</config>

/app/code/local/Shiftmint/Disable_GuestInvoice/Model/Observer.php

<?php

class Shiftmint_Disable_GuestInvoice_Model_Observer
{
    public function paymentMethodIsActive($observer)
    {
        $instance = $observer->getMethodInstance();
        $result = $observer->getResult();

        if ($instance->getCode() == "IsrInvoice") {
            if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                $result->isAvailable = false;
            } else {
                $result->isAvailable = true;
            }
        }
    }
}

Many thanks in advance!

 

Stefan

 

3 REPLIES

Re: Deactivate Invoice as Guest User | own module

Just guessing.. you didn't save the result, nor set new result object (after data modification) into your observer? Try right after:

$result->isAvailable = false;

or

$result->isAvailable = true;

save your result modifications:

$result->save();

and finally reset your observer's result object:

$observer->setResult($result);

 

Re: Deactivate Invoice as Guest User | own module

hmm.. did not change anything.

thx, anyway.

Re: Deactivate Invoice as Guest User | own module

Dear @shiftmint,

In function paymentMethodIsActive($observer), please try edit: "$result = $observer->getResult();" to $result = $observer->getEvent()->getResult();

 

 

www.advancedcheckout.com - www.stableaddon.com
One Step checkout extension - Social Login extension - Gift Card extension