我们在我们的Magento商店使用Payone。我们希望在用户的总金额过大而无法使用特定付款方式时向用户显示警告。
这就是为什么我要根据每种付款方式最大订单价值检查总金额。
但不知怎的,我无法获得正确的数据。
当我尝试通过Payones配置获取它们时:
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
我使用所有方法获得$methods = Mage::helper('payone_core/config')->getConfigPayment($store);
,但它们受到保护。所以我不能在我的购物车模块中使用它们。
获得Payones付款方式的简洁方法是什么(所有有效方法及其max_order_value)?
修改
我尝试了以下代码,但它仍然说:
致命错误:无法访问受保护的属性 Payone_Core_Model_Config_Payment :: $方法 第20行的/pathToClass/CtaB2c/Helper/Data.php
object->array
我知道,没有检查这种付款方式是否可用,但实际上我只想知道maxOrderTotal是否大于付款方式max_order_total。当然,我不需要这个额外的功能。我也可以在我的函数中调用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;
}
}
。
编辑2
这是我从parent::getConfigPayment($store)
得到的对象:
getConfigPayment()
答案 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();
}
}
以上内容允许您使用任何受保护的方法并获取您所追求的数据。
答案 1 :(得分:0)
希望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)
)
);
}
}
答案 2 :(得分:0)
在您的函数中获取Payone配置:
def threadPoolSize = 10
def threadPool = Executors.newFixedThreadPool(threadPoolSize)
def threadClosure = { myWork ->
def partialQuantity = 0
myWork.each { currDetail ->
MyTableDomainClass.findByCode(currDetail.myTableCode)
// Do some stuff
}
return partialQuantity
}
try{
def worksForThreads = new ArrayList<org.codehaus.groovy.grails.web.json.JSONArray>(10)
// Prepare works for thread
Integer x = 0
allWorks.each{ singleOrder ->
if(worksForThreads[x] == null)
worksForThreads[x] = new org.codehaus.groovy.grails.web.json.JSONArray()
worksForThreads[x].add(singleOrder)
x = (x+1) % threadPoolSize
}
List<Future> futures = worksForThreads.collect({ myWork ->
println "\t\tPrepare thread with ${myWork.size()} tasks"
threadPool.submit({ ->
threadClosure myWork
} as Callable )
})
//Start thread and collect result
futures.each{
def threadResult = it.get()
println "\t\tThread result ${threadResult}"
totQuantity = totQuantity+threadResult
}
}catch(Exception e){
println "Error during thread works ${e}"
}finally{
threadPool.shutdown()
}
在[pool-9-thread-2] [tenant 0] ERROR util.JDBCExceptionReporter - Table 'MySchema.MyTable' doesn't exist
中,您可以找到可以在Error during thread works java.util.concurrent.ExecutionException: org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query;
SQL [select this_.id as id24_0_, this_.code as code24_0_, this_.description as descript3_24_0_, this_.incr as incr24_0_, this_.is_default as is5_24_0_, this_.lang as lang24_0_, this_.last_updated as last7_24_0_, this_.min as min24_0_, this_.name as name24_0_, this_.ordasc as ordasc24_0_, this_.parent_id as parent11_24_0_, this_.parent_mult as parent12_24_0_, this_.prod_code as prod13_24_0_, this_.status as status24_0_, this_.unit_name as unit15_24_0_
from MyTable this_ where this_.code=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
上拨打的所有方法,例如$payoneConfig = Mage::helper('payone_core/config')->getConfigPayment($storeId);
。如果要添加更多功能,请覆盖Payone_Core_Model_Config_Payment
Magento方式。