我们在Magento商店使用Payone。当用户的总金额对于某种支付方式来说太大时,我们希望在他们的购物车中向用户显示警告。
这就是为什么我想对照每种支付方式的最大订单价值来检查总金额。
但不知何故,我无法获得正确的数据。
当我试图通过Payones配置获得它们时:
$methods = Mage::helper('payone_core/config')->getConfigPayment($store);
我得到了一个包含所有方法的object->array
,但它们是受保护的。所以我不能在我的购物车模块中使用它们。
什么是获得Payones支付方式的干净方法(所有活动方式的max_order_value)?
编辑:
我尝试了以下代码,但它仍然显示:
致命错误:无法访问受保护的属性Payone_Core_Model_Config_Payment::中的$methods/第20行上的pathToClass/CtaB2c/Helper/Data.php
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"
}
您可以始终扩展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();
}
}
以上内容将允许您使用任何受保护的方法并获取您想要的数据。
这有望成为获取Payones支付方式信息的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)
)
);
}
}
在函数中获取Payone配置:
$payoneConfig = Mage::helper('payone_core/config')->getConfigPayment($storeId);
在Payone_Core_Model_Config_Payment
中,您可以找到在$payoneConfig
上可以调用的所有方法,例如getAvailableMethods()
。如果您想添加更多功能,请以Magento方式覆盖Payone_Core_Model_Config_Payment
。