Cash On Delivery activated Admin Only ( Not Frontend enabled ) - Magento?

北城余情 提交于 2019-11-30 14:01:25
Joseph at SwiftOtter

There are a number of ways to achieve this, but they require a familiarity with the Magento ecosystem. I would discourage using CSS to hide it from the end user, because someone that was slightly knowledgeable about CSS could easily unhide it and gain free access to purchase your products.

I also suggest not override core files (even if you are not editing them), as that will cause upgrade problems in the future.

The solid way:

My favorite method would be to enable to Check/Money order method, and create yourself a small module, like this. Neither of the previous considerations make any effect here.

/app/etc/modules/Company_Module.xml

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

/app/code/local/Company/Module/etc/config.xml

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

<global>
    <models>
        <Company_Module>
            <class>Company_Module_Model</class>
        </Company_Module>
    </models>
    <events>
        <payment_method_is_active>
            <observers>
                <company_module>
                    <type>singleton</type>
                    <class>Company_Module/Observer</class>
                    <method>paymentMethodIsActive</method>
                </company_module>
            </observers>
        </payment_method_is_active>
    </events>
</global>

</config>

/app/code/local/Company/Module/Model/Observer.php

<?php

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

        if ($instance->getCode() == "checkmo") {
            if (Mage::app()->getStore()->isAdmin()) {
                $result->isAvailable = true;
            } else {
                $result->isAvailable = false;
            }
        }
    }
}

To hide in the front end, you must be set to false to the protected $_canUseCheckout = false; to your payment method.

To display in the admin end, you must be set to true to the protected $_canUseInternal = true; to your payment method.

A very easy way, but maybe not the cleanest way you could do this:

  1. Enable Cash On Delivery for the store.
  2. Hide it from the front end using CSS.

Using CSS to achieve this would hide the option from the general public, but would not prevent a web developer who is knowledgable with CSS to go find it and place a cash on delivery order - though I cant think of any reason someone would purposely do this since they won't achieve much by placing the order.

EDIT :

To hide Cash On Delivery add this to your CSS:

input#p_method_cashondelivery { display: none; }
label[for=p_method_cashondelivery] { display: none; }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!