Php 如何获得Magento Payone主动付款方式?

Php 如何获得Magento Payone主动付款方式?,php,magento,payment-gateway,payment,magento-1.9,Php,Magento,Payment Gateway,Payment,Magento 1.9,我们在Magento商店使用Payone。我们希望在用户的购物车中显示警告,当他们的总金额对于某种支付方式来说太大时 这就是为什么我想根据每个付款方式的最大订单值检查总金额 但不知何故,我无法获得正确的数据 当我尝试通过Paynes配置获取它们时: $methods = Mage::helper('payone_core/config')->getConfigPayment($store); 我得到一个包含所有方法的对象->数组,但它们是受保护的。因此,我无法在购物车模块中使用它们 什么

我们在Magento商店使用Payone。我们希望在用户的购物车中显示警告,当他们的总金额对于某种支付方式来说太大时

这就是为什么我想根据每个付款方式的最大订单值检查总金额

但不知何故,我无法获得正确的数据

当我尝试通过Paynes配置获取它们时:

$methods = Mage::helper('payone_core/config')->getConfigPayment($store);
我得到一个包含所有方法的
对象->数组
,但它们是受保护的。因此,我无法在购物车模块中使用它们

什么是获得付款人付款方式(所有具有最大订单价值的活动方式)的干净方法

编辑:

我尝试了以下代码,但仍然显示:

致命错误:无法访问受保护的属性 付款人\核心\模型\配置\付款::$methods in /第20行的pathToClass/CtaB2c/Helper/Data.php


您始终可以扩展payne\u core/config类YourNameSpace\u Module\u Helper\u payne扩展payneMespace\u payne\u core\u config,基本上可以将任何方法公开

class YourNameSpace_Module_Helper_Payone extends ThePayOneNamespace_Payone_Core_Config

   public function someProtectedParentMethod()
   {
       return parent::someProtectedParentMethod();
   }
}

以上内容将允许您使用任何受保护的方法并获取所需的数据。

希望这是Magento获取有关付款人付款方式信息的方法。您应该在控制器中的某个位置调用
setPaymentRestrictionNoticeMessage()

class YourModule_Helper_Data extends Mage_Core_Helper_Abstract {
    /**
     * Returns array of methods that will not work with current max order value.
     * @return array
     */
    public function getPaymentsWithRestrictions() {
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $store = $quote->getStoreId();
        $total = $quote->getBaseGrandTotal();

        /**
         * @var Payone_Core_Model_Config_Payment $model
         */
        $model = Mage::helper('payone_core/config')->getConfigPayment($store);
        $methods = $model->getMethods();

        $restrictedMethods = array();

        foreach ($methods AS $mid => $method) {
            /**
             * @var Payone_Core_Model_Config_Payment_Method $method
             */
            $minTotal = $method->getMinOrderTotal();
            $maxTotal = $method->getMaxOrderTotal();
            $isEnabled = $method->getEnabled();

            if($isEnabled && ($minTotal > $total || $maxTotal < $total)) {
                $restrictedMethods[$mid] = $method;
            }
        }

        return $restrictedMethods;
    }

    /**
     * Sets notification message with information about payment methods
     * that will not work.
     */
    public function setPaymentRestrictionNoticeMessage() {
        $restrictedMethodModels = $this->getPaymentsWithRestrictions();

        $restrictedMethods = array();

        foreach ($restrictedMethodModels AS $methodModel) {
            /**
             * @var Payone_Core_Model_Config_Payment_Method $methodModel
             */
            $restrictedMethods[] = $methodModel->getName();
        }

        Mage::getSingleton('core/session')->addNotice(
            Mage::helper('checkout')->__(
                'Your order value is too high for following payment methods: ' . implode(', ', $restrictedMethods)
            )
        );
    }
}
class YourModule\u Helper\u数据扩展了Mage\u Core\u Helper\u抽象{
/**
*返回不适用于当前最大顺序值的方法数组。
*@return数组
*/
公共函数getPaymentsWithRestrictions(){
$quote=Mage::getSingleton('checkout/session')->getQuote();
$store=$quote->getStoreId();
$total=$quote->getBaseGrandTotal();
/**
*@var Payone\u Core\u Model\u Config\u Payment$Model
*/
$model=Mage::helper('payone_core/config')->getConfigPayment($store);
$methods=$model->getMethods();
$restrictedMethods=array();
foreach($mid=>$method形式的方法){
/**
*@var Payone\u Core\u Model\u Config\u Payment\u Method$Method
*/
$minTotal=$method->getMinOrderTotal();
$maxTotal=$method->getMaxOrderTotal();
$isEnabled=$method->getEnabled();
如果($isEnabled&($minTotal>$total | |$maxTotal<$total)){
$restrictedMethods[$mid]=$method;
}
}
返回$restrictedMethods;
}
/**
*设置包含付款方式信息的通知消息
*那是行不通的。
*/
公共函数setPaymentRestrictionNoticeMessage(){
$restrictedMethodModels=$this->getPaymentswithRestricts();
$restrictedMethods=array();
foreach($restrictedMethodModels作为$methodModel){
/**
*@var Payone\u Core\u Model\u Config\u Payment\u Method$methodModel
*/
$restrictedMethods[]=$methodModel->getName();
}
Mage::getSingleton('core/session')->addNotice(
Mage::helper('checkout')->__(
“您的订单值对于以下付款方式太高:”。内爆(“,”,$restrictedMethods)
)
);
}
}

在函数中获取付款人配置:

$payoneConfig = Mage::helper('payone_core/config')->getConfigPayment($storeId);

Payone\u Core\u Model\u Config\u Payment
中,您可以找到可以调用
$payeneconfig
的所有方法,例如
getAvailableMethods()
。如果您想添加更多功能,请用Magento方式覆盖
Payone\u Core\u Model\u Config\u Payment

这不起作用。作为子类,我无法访问这些值。但是我必须检查对象-我猜它是一个模型,我需要从这个模型进行扩展?上面的解决方案将允许您从父类访问受保护的方法,您通常无法访问这些方法。在类的公共函数中,可以调用受保护的父方法并获取其数据。这将起作用,我不确定什么不起作用,但通过扩展父类的类访问受父类保护的方法是可能的。抱歉,我发现我没有使用正确的类进行扩展。但无论如何,我想那是错误的方式。正如你看到的我的编辑,我得到了一个完整的模型,所有的值都有getter和setter。你是说这就是答案吗?@Harry,这对我来说是有效的。但我仍然不知道这是否是Magento的正确方式。至少我使用了派恩方法。
class YourModule_Helper_Data extends Mage_Core_Helper_Abstract {
    /**
     * Returns array of methods that will not work with current max order value.
     * @return array
     */
    public function getPaymentsWithRestrictions() {
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $store = $quote->getStoreId();
        $total = $quote->getBaseGrandTotal();

        /**
         * @var Payone_Core_Model_Config_Payment $model
         */
        $model = Mage::helper('payone_core/config')->getConfigPayment($store);
        $methods = $model->getMethods();

        $restrictedMethods = array();

        foreach ($methods AS $mid => $method) {
            /**
             * @var Payone_Core_Model_Config_Payment_Method $method
             */
            $minTotal = $method->getMinOrderTotal();
            $maxTotal = $method->getMaxOrderTotal();
            $isEnabled = $method->getEnabled();

            if($isEnabled && ($minTotal > $total || $maxTotal < $total)) {
                $restrictedMethods[$mid] = $method;
            }
        }

        return $restrictedMethods;
    }

    /**
     * Sets notification message with information about payment methods
     * that will not work.
     */
    public function setPaymentRestrictionNoticeMessage() {
        $restrictedMethodModels = $this->getPaymentsWithRestrictions();

        $restrictedMethods = array();

        foreach ($restrictedMethodModels AS $methodModel) {
            /**
             * @var Payone_Core_Model_Config_Payment_Method $methodModel
             */
            $restrictedMethods[] = $methodModel->getName();
        }

        Mage::getSingleton('core/session')->addNotice(
            Mage::helper('checkout')->__(
                'Your order value is too high for following payment methods: ' . implode(', ', $restrictedMethods)
            )
        );
    }
}
$payoneConfig = Mage::helper('payone_core/config')->getConfigPayment($storeId);