2016-04-07 5 views
0

Я создаю новый способ оплаты. С помощью этого нового способа оплаты клиент будет покупать продукт только в том случае, если он правильно отвечает на заданный вопрос. Как проверить, что клиент выбирает ответ? Кроме того, кроме как ответ клиента для проверки позже, если он правильный?Как подтвердить выбор радио кнопки?

приложение/дизайн/интерфейс/базы/по умолчанию/шаблон/custompaymentmethod/форма/custompaymentmethod.phtml: Это файл шаблона, используемый для отображения пользовательской формы оплаты для нашего метода пользовательских платежей.

<?php 
$question = Mage::getModel('emme_question/question')->getCollection()->getLastItem(); 
$answers = $question->getSelectedAnswersCollection(); 
?> 
<div id="custompaymentmethod-question"> 
    <h4><?php echo $this->escapeHtml($question->getValue()); ?></h4> 
    <ul> 
    <?php foreach ($answers as $answer): ?> 
    <li> 
    <label><?php echo $this->escapeHtml($answer->getValue()) ?></label> 
    <input type="radio" name="my_custom_answer" value="<?php echo $answer->getId() ?>" required> 
    </li> 
    <?php endforeach ?> 
</div> 
<script> 
jQuery(function ($) { 
    $('#co-payment-form').on('change.mm', function() { 
    var is_question_active = ! $('#p_method_custompaymentmethod').is(':checked'); 
    $('#custompaymentmethod-question input').attr('disabled', is_question_active); 
    }) 
}) 
</script> 

приложение/код/​​местные/Envato/Custompaymentmethod/Модель/Paymentmethod.php: Это модель файла, используемый для проверки и сохранения информации о пользовательских платежей полей.

<?php 
// app/code/local/Envato/Custompaymentmethod/Model/Paymentmethod.php 
class Envato_Custompaymentmethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract { 
    protected $_code = 'custompaymentmethod'; 
    protected $_formBlockType = 'custompaymentmethod/form_custompaymentmethod'; 
    protected $_infoBlockType = 'custompaymentmethod/info_custompaymentmethod'; 

    public function getOrderPlaceRedirectUrl() 
    { 
    return Mage::getUrl('custompaymentmethod/payment/redirect', array('_secure' => false)); 
    } 
} 

Извините за мой плохой английский

ответ

0

Я решил

<?php 
// app/code/local/Envato/Custompaymentmethod/Model/Paymentmethod.php 
class Envato_Custompaymentmethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract { 
    protected $_code = 'custompaymentmethod'; 
    protected $_formBlockType = 'custompaymentmethod/form_custompaymentmethod'; 
    protected $_infoBlockType = 'custompaymentmethod/info_custompaymentmethod'; 

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!'); 
      } 
    } 
    } 
} 

    public function getOrderPlaceRedirectUrl() 
    { 
    return Mage::getUrl('custompaymentmethod/payment/redirect', array('_secure' => false)); 
    } 
} 
Смежные вопросы