自定义付款方式模块

时间:2016-08-24 11:12:37

标签: magento methods module payment

我正在创建一种基于问题/答案的付款方式,其中来自预定义问题池的随机问题的正确答案有效作为付款。

// 1) Here I take the question with ID = 1 cycle and the possible answers
foreach (Mage :: getModel ('emme_question / question') -> load (1) -> getSelectedAnswersCollection () as $ answer) {
// 2) for each control response if it is the correct one and if it has the same ID as the one chosen by the user
     if ($ answer-> getIsCorrect () && ($ answer-> getId () == $ _POST ['my_custom_answer'])) {
// 3) if so show a success message to the user
        Mage :: getSingleton (core / session ') -> addSuccess (' Correct answer ');
        // You should be able to go to the next step
     } Else {
// 4) in the event unleashed an exception to stop the negative checkout (and returning the user to the homepage)
         Mage :: ThrowException ('Wrong answer!');
     }
}

您帮助完成了代码吗?

1 个答案:

答案 0 :(得分:0)

我解决了

public function validate()
{
  foreach (Mage::getModel('emme_question/question')->load(1)->getSelectedAnswersCollection() as $answer) 
  {
    if ($answer->getIsCorrect()) 
    {
        if ($answer->getId() == $_POST['my_custom_answer']) 
        {
            Mage::getSingleton('core/session')->addSuccess('Risposta esatta');
        } else 
            {
                    Mage::throwException('Risposta sbagliata!');
            }
    }   
   }
}