如何隐藏购物车价格规则的付款方式?

时间:2014-06-04 11:59:59

标签: magento magento-1.7 magento-1.6 magento-1.8

如何隐藏购物车价格规则的付款方式?

2 个答案:

答案 0 :(得分:2)

实现此目的的另一种方法是使用观察者payment_method_is_active。见Disable payment options-only cash on delivery for particular product-magento

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

        $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
        $grandtotal = round($totals["grand_total"]->getValue())

        if ($instance->getCode() == "ccsave") {
            if(1500 > $grandtotal && !Mage::app()->getStore()->isAdmin())
                $result->isAvailable = false;
            }
            else{
                $result->isAvailable = true;
            }
        }
    }
}

答案 1 :(得分:1)

进入

app/design/frontend/base/default/template/checkout/onepage/payment/methods.php

将您的methods.php更改为此代码

<?php
$methods = $this->getMethods();
$oneMethod = count($methods) <= 1;
?>
<?php if (empty($methods)): ?>
<dt>
    <?php echo $this->__('No Payment Methods') ?>
</dt>
<?php else:
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
$grandtotal = round($totals["grand_total"]->getValue());

 foreach ($methods as $_method):
    $_code = $_method->getCode();

if($grandtotal > 1500)
{   
?>
 <dt>
 <?php if(!$oneMethod): ?>

    <input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->escapeHtml($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
<?php else: ?>
    <span class="no-display"><input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" checked="checked" class="radio" /></span>
    <?php $oneMethod = $_code; ?>
<?php endif; ?>
    <label for="p_method_<?php echo $_code ?>"><?php echo $this->escapeHtml($this->getMethodTitle($_method)) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?></label>
</dt>
<?php
}
else
{
        if($_code != 'ccsave')
        {
        ?>
            <dt>
            <?php if(!$oneMethod): ?>

                <input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->escapeHtml($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
            <?php else: ?>
                <span class="no-display"><input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" checked="checked" class="radio" /></span>
                <?php $oneMethod = $_code; ?>
            <?php endif; ?>
                <label for="p_method_<?php echo $_code ?>"><?php echo $this->escapeHtml($this->getMethodTitle($_method)) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?></label>
            </dt>
        <?php
        }
} 
?>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd>
    <?php echo $html; ?>
</dd>
<?php endif; ?>

<?php endforeach;

endif;
?>
<?php echo $this->getChildChildHtml('additional'); ?>
<script type="text/javascript">
//<![CDATA[
<?php echo $this->getChildChildHtml('scripts'); ?>
payment.init();
<?php if (is_string($oneMethod)): ?>
payment.switchMethod('<?php echo $oneMethod ?>');
    <?php endif; ?>
//]]>
</script>

修改: -

如果您想在模型中使用此条件,请转到

app/code/core/mage/payment/helper/Data.php

将此功能( getStoreMethods )替换为我的代码

 public function getStoreMethods($store = null, $quote = null)
 {
    $res = array();
    $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
    $grandtotal = round($totals["grand_total"]->getValue());
    if($grandtotal > 1500)
    {
    foreach ($this->getPaymentMethods($store) as $code => $methodConfig) {


        $prefix = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/';
        if (!$model = Mage::getStoreConfig($prefix . 'model', $store)) {
            continue;
        }
        $methodInstance = Mage::getModel($model);
        if (!$methodInstance) {
            continue;
        }
        $methodInstance->setStore($store);
        if (!$methodInstance->isAvailable($quote)) {
            /* if the payment method cannot be used at this time */
            continue;
        }
        $sortOrder = (int)$methodInstance->getConfigData('sort_order', $store);
        $methodInstance->setSortOrder($sortOrder);
        $res[] = $methodInstance;

    }
    }
    else
    {
     foreach ($this->getPaymentMethods($store) as $code => $methodConfig) {

        if($code != 'ccsave')
        {
        $prefix = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/';
        if (!$model = Mage::getStoreConfig($prefix . 'model', $store)) {
            continue;
        }
        $methodInstance = Mage::getModel($model);
        if (!$methodInstance) {
            continue;
        }
        $methodInstance->setStore($store);
        if (!$methodInstance->isAvailable($quote)) {
            /* if the payment method cannot be used at this time */
            continue;
        }
        $sortOrder = (int)$methodInstance->getConfigData('sort_order', $store);
        $methodInstance->setSortOrder($sortOrder);
        $res[] = $methodInstance;
        }

    }

    }   

    usort($res, array($this, '_sortMethods'));
    return $res;
}