【问题标题】:How to get Magento Payone active payment methods?如何获得 Magento Payone 主动支付方式?
【发布时间】:2016-04-05 10:19:36
【问题描述】:

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

这就是为什么我要对照每种付款方式的最大订单价值检查总金额。

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

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

$methods = Mage::helper('payone_core/config')->getConfigPayment($store);

我得到一个包含所有方法的object->array,但它们受到保护。所以我不能在我的购物车模块中使用它们。

什么是获取 Payones 付款方式(所有活动方式及其 max_order_value)的干净方式?

编辑:

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

致命错误:无法访问受保护的属性 Payone_Core_Model_Config_Payment::$methods 在 /pathToClass/CtaB2c/Helper/Data.php 第 20 行

class CtaB2c_Helper_Data extends Payone_Core_Helper_Config {
    public function getConfigPayment($store) {
        return parent::getConfigPayment($store);
    }

    public function showPaymentRestrictions() {
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $store = $quote->getStoreId();
        $total = $quote->getBaseGrandTotal();
        $methods = $this->getConfigPayment($store);
        $methods = $methods->methods; //error occurs here: member has protected access

        $avaibleMethods = array();

        foreach ($methods AS $mid => $method) {
            $minTotal = $method->minOrderTotal;
            $maxTotal = $method->maxOrderTotal;

            if($minTotal <= $total && $maxTotal >= $total) {
                $avaibleMethods[$mid] = $method->code;
            }
        }

        return $avaibleMethods;
    }
}

我知道,没有检查这种付款方式是否可用,但实际上我只想知道 maxOrderTotal 是否大于付款方式 max_order_total。当然我不需要这个额外的功能。我也可以在我的函数中调用parent::getConfigPayment($store)

编辑 2 这是我从getConfigPayment()得到的对象:

object(Payone_Core_Model_Config_Payment)#<a number> (1) {
  ["methods":protected]=>
  array(6) {
    [<a number>]=>
    object(Payone_Core_Model_Config_Payment_Method)#<a number> (38) {
      ["id":protected]=>
      string(1) "a number"
      ["scope":protected]=>
      string(6) "stores"
      ["scope_id":protected]=>
      string(1) "<a number>"
      ["code":protected]=>
      string(15) "advance_payment"
      ["name":protected]=>
      string(8) "Vorkasse"
      ["sort_order":protected]=>
      string(1) "<a number>"
      ["enabled":protected]=>
      string(1) "<a number>"
      ["fee_config":protected]=>
      NULL
      ["mode":protected]=>
      string(4) "test"
      ["use_global":protected]=>
      string(1) "1"
      ["mid":protected]=>
      string(5) "<a number>"
      ["portalid":protected]=>
      string(7) "<a number>"
      ["aid":protected]=>
      string(5) "<a number>"
      ["key":protected]=>
      string(16) "<a key>"
      ["allowspecific":protected]=>
      string(1) "0"
      ["specificcountry":protected]=>
      array(0) {
      }
      ["allowedCountries":protected]=>
      array(2) {
        [0]=>
        string(2) "DE"
        [1]=>
        string(2) "AT"
      }
      ["request_type":protected]=>
      string(16) "preauthorization"
      ["invoice_transmit":protected]=>
      string(1) "0"
      ["types":protected]=>
      NULL
      ["klarna_config":protected]=>
      NULL
      ["klarna_campaign_code":protected]=>
      NULL
      ["paypal_express_image":protected]=>
      NULL
      ["check_cvc":protected]=>
      NULL
      ["check_bankaccount":protected]=>
      NULL
      ["bankaccountcheck_type":protected]=>
      NULL
      ["message_response_blocked":protected]=>
      NULL
      ["sepa_country":protected]=>
      NULL
      ["sepa_de_show_bank_data":protected]=>
      NULL
      ["sepa_mandate_enabled":protected]=>
      NULL
      ["sepa_mandate_download_enabled":protected]=>
      NULL
      ["customer_form_data_save":protected]=>
      NULL
      ["is_deleted":protected]=>
      string(1) "0"
      ["minValidityPeriod":protected]=>
      string(0) ""
      ["minOrderTotal":protected]=>
      string(1) "1"
      ["maxOrderTotal":protected]=>
      string(4) "1000"
      ["parent":protected]=>
      string(1) "<a number>"
      ["currency_convert":protected]=>
      string(1) "0"
    }

【问题讨论】:

    标签: php magento payment-gateway payment magento-1.9


    【解决方案1】:

    您始终可以扩展 payone_core/config 类 YourNameSpace_Module_Helper_Payone 扩展 ThePayOneNamespace_Payone_Core_Config 并且基本上可以公开任何方法

    class YourNameSpace_Module_Helper_Payone extends ThePayOneNamespace_Payone_Core_Config
    
       public function someProtectedParentMethod()
       {
           return parent::someProtectedParentMethod();
       }
    }
    

    以上将允许您使用任何受保护的方法并获取您想要的数据。

    【讨论】:

    • 这不起作用。作为一个子类,我无法访问这些值。但我必须检查对象 - 我猜它是一个模型,我需要从这个模型扩展?
    • 上述解决方案将允许您从无法正常访问的父类访问受保护的方法。在您的类的公共函数中,您可以调用受保护的父方法并获取它的数据。这会起作用,我不确定什么不起作用,但是可以通过扩展父级的类访问父级受保护的方法。
    • 对不起,我发现我没有使用正确的类来扩展。但无论如何 - 我想那将是错误的方式。如您所见,我返回了一个完整的模型,它具有所有值的 getter 和 setter。
    【解决方案2】:

    希望这是 Magento 获取有关 Payones 付款方式信息的方式。你应该在你的控制器的某个地方调用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)
                )
            );
        }
    }
    

    【讨论】:

    • 你说这就是答案吗?
    • @Harry 这对我有用。但我仍然不知道这是否是 Magento 的正确方式。至少我使用 Payones 方法。
    【解决方案3】:

    在您的函数中获取 Payone 配置:

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

    Payone_Core_Model_Config_Payment 中,您可以找到可以在$payoneConfig 上调用的所有方法,例如getAvailableMethods()。如果您想添加更多功能,请使用 Magento 方式覆盖 Payone_Core_Model_Config_Payment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-24
      • 2013-11-03
      • 2015-01-03
      • 2012-03-01
      • 2017-08-04
      • 2023-04-08
      • 2012-11-05
      • 2010-11-28
      相关资源
      最近更新 更多