2016-04-05 6 views
0

私たちはMagentoショップでPayoneを使用しています。また、特定のお支払い方法の合計金額が大きすぎる場合、ユーザーの警告をカートに表示したいと考えています。Magento Payoneのアクティブなお支払い方法を取得するには?

私は、各支払い方法の最大注文額に対して合計金額を確認したいのです。

しかし、何とか正しいデータに到達できません。

私はPayones設定することによって、それらを取得しよう:

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

は、私はすべてのメソッドでobject->arrayを得るが、それらは保護されています。だから私はカートモジュールで使用することはできません。

Payonesの支払い方法(すべてのアクティブなメソッドのmax_order_value)を取得するにはどうすればよいですか?

編集:

私は、次のコードを試してみましたが、それはまだ書かれています:

Fatal error: Cannot access protected property Payone_Core_Model_Config_Payment::$methods in /pathToClass/CtaB2c/Helper/Data.php on line 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; 
    } 
} 

私が知っている、私は実際にそこに、この支払方法はavaibleであれば何のチェックはありませんが、 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" 
    } 

答えて

0

あなたは常に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(); 
    } 
} 
パブリックであることを得ることができます

上記のようにすれば、保護された方法を使用して、その後のデータを取得することができます。

+0

これは機能しません。子クラスとして私は値にアクセスできません。しかし、私はオブジェクトを確認する必要があります - 私はそれがモデルであり、私はこの1つから拡張する必要があると思いますか? – Jurik

+0

上記の解決方法では、親クラスの保護されたメソッドにアクセスして、正常にアクセスできなくなります。あなたのクラスのパブリック関数の中で、保護されている親メソッドを呼び出して、そのデータを取得することができます。それはうまくいくが、私は何がうまくいかないのか分からないが、親を拡張したクラスによって保護された親メソッドにアクセスできるようになる。 –

+0

申し訳ありませんが、私は正しいクラスを使用していないことを理解しました。しかし、とにかく - それは間違った方法だろうと思う。私の編集を見ると、モデル全体が返され、すべての値に対してgetterとsetterがあります。 – Jurik

0

これはうまくいけば、Payones支払い方法についての情報を得る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) 
      ) 
     ); 
    } 
} 
+0

これは答えなのですか? – Harry

+0

@ハリーそれは私のために働くものです。しかし、これがMagentoの正しい方法であるかどうかはまだ分かりません。少なくともPayonesメソッドを使用します。 – Jurik

0

あなたの関数でPayoneの設定を取得します:Payone_Core_Model_Config_Payment

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

をあなたが$payoneConfigに呼び出すことができるすべての方法を見つけることができ、例えばgetAvailableMethods()。機能を追加したい場合は、Magentoの方法でPayone_Core_Model_Config_Paymentを上書きしてください。

関連する問題