【问题标题】:Magento deactivate Payment method for GuestMagento 停用访客的付款方式
【发布时间】:2015-12-07 18:31:01
【问题描述】:

我尝试编写一个小扩展程序,以便在用户以访客用户身份访问结帐时停用付款方式(称为 IsrInvoice)。

/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

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

<frontend>
    <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>
</frontend>

</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;
                $result->save();
            } else {
                $result->isAvailable = true;
                $result->save();
            }
            $observer->setResult($result);
        }
    }
}

有谁知道我做错了什么,因为它不起作用!有没有办法测试加载的内容?

非常感谢您的建议, 斯蒂芬

【问题讨论】:

    标签: magento


    【解决方案1】:

    您无需编写代码即可停用客人结帐功能。它的magento内置功能。为此,您登录后转到左侧销售部分中的系统菜单>配置>结帐按钮>右侧的结帐选项面板。展开 Checkout Options 面板后,您会看到一个下拉菜单 Allow Guest Checkout;只需将其设置为否。一旦你这样做,一个下拉菜单将出现在它下面,标有要求客户登录到结帐;将其设置为是,然后单击右上角的保存配置按钮。

    【讨论】:

    • 这个想法不是为客人禁用结帐,而是如果您是客人,则允许/禁止付款方式!
    猜你喜欢
    • 2012-03-01
    • 2017-09-18
    • 2014-08-04
    • 2015-02-27
    • 2012-09-07
    • 2018-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多