【发布时间】:2014-06-24 23:54:57
【问题描述】:
我正在开发一个将第三方 API 集成到 Magento 的扩展。包括的步骤是在我们的网站上填写表格。当用户点击提交时,API 会在他们的网站上预先填写一个表单,然后用户批准该表单。一些获取字符串变量被发送到我们网站上的页面,这会触发第二个 API 调用(在幕后)来检索令牌。创建令牌后,我会将令牌保存到第二个隐藏表单并通过此函数提交:
function submitAccount() {
var formId = 'form-payment-submit';
var myForm = new VarienForm(formId, true);
var postUrl = '<?php echo $this->getUrl('marketplacepayment/marketplaceaccount/paymentsetup/') ?>';
if (myForm.validator.validate()) {
new Ajax.Updater(
{ success:console.log("form success") }, postUrl, {
method:'post',
asynchronous:false,
evalScripts:false,
onComplete:function(request, json) {
//submitButtonOn();
alert('success!');
},
parameters: $(formId).serialize(true),
}
);
}
}
然后我模块中的函数处理将值保存到数据库:
public function paymentsetupAction(){
if(!(empty($_POST['access']))){
// save tokens to db
$collection = Mage::getModel('marketplace/userprofile')->getCollection();
$collection->addFieldToFilter('mageuserid',array('eq'=>$_POST['userid']));
foreach($collection as $row){
$id=$row->getAutoid();
}
$collectionload = Mage::getModel('marketplace/userprofile')->load($id);
$collectionload->setaccesstoken($_POST['access']);
$collectionload->setrefreshtoken($_POST['refresh']);
$collectionload->setstripekey($_POST['key']);
$collectionload->save();
Mage::getSingleton('core/session')->addSuccess( Mage::helper('marketplace')->__('Your payment information has been sucessfully saved.'));
$this->_redirect('marketplacepayment/marketplaceaccount/payment');
}
}
问题是令牌没有被保存但没有出现错误。我无法将任何信息写入页面,因为提交是通过 AJAX 进行的,所以我不知道如何调试。您是否立即发现 paymentsetupAction 有什么问题?或者有没有更简单的方法让我了解它为什么不起作用?
【问题讨论】: